[ 
https://issues.apache.org/jira/browse/LUCENE-2320?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12845490#action_12845490
 ] 

Shai Erera commented on LUCENE-2320:
------------------------------------

The thing is that we were at that position already, before I changed it so that 
MP requires writer up front. The reason was, like Mike mentioned, that writer 
had to be passed on all method calls, for really no good reason. A MP is 
usually coupled w/ an IW instance and I don't think we should opt for 
decoupling them.

Most of this patch removes MP setting from IW to IWC (and hence changes test 
code to use the new API). The SetOnce juggling is done only to ensure an IW is 
set exactly once on MP, and allows us to resolve that circular dependency. We 
can do two things:
# Continue w/ SetOnce as introduced in this patch.
# Introduce a setIndexWriter on MP which anyone can call, even more than once.

With (1) I don't think we complicate anything, and SetOnce can be useful in 
other places as well. (2) is really like passing writer on all method calls, so 
let's at least not have it as part of all methods signature. I prefer (1) 
slightly over (2) but am fine w/ (2) as well. I wouldn't want to change MP back 
to require IW on all its methods.

> Add MergePolicy to IndexWriterConfig
> ------------------------------------
>
>                 Key: LUCENE-2320
>                 URL: https://issues.apache.org/jira/browse/LUCENE-2320
>             Project: Lucene - Java
>          Issue Type: Improvement
>          Components: Index
>            Reporter: Shai Erera
>            Assignee: Michael McCandless
>             Fix For: 3.1
>
>         Attachments: LUCENE-2320.patch
>
>
> Now that IndexWriterConfig is in place, I'd like to move MergePolicy to it as 
> well. The change is not straightforward and so I've kept it for a separate 
> issue. MergePolicy requires in its ctor an IndexWriter, however none can be 
> passed to it before an IndexWriter actually exists. And today IW may create 
> an MP just for it to be overridden by the application one line afterwards. I 
> don't want to make iw member of MP non-final, or settable by extending 
> classes, however it needs to remain protected so they can access it directly. 
> So the proposed changes are:
> * Add a SetOnce object (to o.a.l.util), or Immutable, which can only be set 
> once (hence its name). It'll have the signature SetOnce<T> w/ *synchronized 
> set<T>* and *T get()*. T will be declared volatile, so that get() won't be 
> synchronized.
> * MP will define a *protected final SetOnce<IndexWriter> writer* instead of 
> the current writer. *NOTE: this is a bw break*. any suggestions are welcomed.
> * MP will offer a public default ctor, together with a set(IndexWriter).
> * IndexWriter will set itself on MP using set(this). Note that if set will be 
> called more than once, it will throw an exception (AlreadySetException - or 
> does someone have a better suggestion, preferably an already existing Java 
> exception?).
> That's the core idea. I'd like to post a patch soon, so I'd appreciate your 
> review and proposals.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-dev-h...@lucene.apache.org

Reply via email to