lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hostetter <hossman_luc...@fucit.org>
Subject Re: factoring the merge policy
Date Wed, 14 Mar 2007 21:35:08 GMT

There is very little about IndexWriter that I understand, but i am very
much in favor of the spirit of your idea (your message is one of the
things that prompted me to polish/open LUCENE-831 for a correlary issue
about IndexReader caching)

:   void merge( SegmentInfos segmentInfos )
:                 throws CorruptIndexException, IOException;
:   void optimize( SegmentInfos segmentInfos )
:                 throws CorruptIndexException, IOException;

: The merge policy gets created with an IndexWriter and then called via
: merge or optimize with the relevant segmentInfos. It in turn calls back
: to the IndexWriter for each primitive merge operation:
:
:   	int merge( MergePolicy.MergeSpecification m )

: returns normally. Obviously this means IndexWriter#merge isn't
: synchronized and, at least in this case, should only be called via the
: merge policy. The only thing IndexWriter#merge really needs is the

one way to approach this would be to leave that method out of the public
IndexWriter API, and create anew "Mergable" callback API passed to the
MergePolicy when it's registered...

class IndexWriter { ...
  private int doMerge(MergePolicy.MergeSpecification m ) { ... }
  public void setMergePolicy(MergePolicy mp) {
     this.mergePolicy.close();
     this.mergePolicy = mp;
     this.mergePolicy.setMergable(new Mergable() {
       public int merge(MergePolicy.MergeSpecification m ) {
         return IndexWriter.this.merge(m)
       }
     }
   }

...now you are gaurnteed that no one besides the MergePolicy the
IndexWriter is using can ever trigger the logic in doMerge.

Note also that i assumed a MergePolicy.close() method .. this may be
important for people that want to implement MergePolicies that spin up
background threads to monitor things.

You also might want to consider a passing the IndexWriter a
MergePolicyFactory instead of specific MergePolicy instances ... the
factory can not only ensure that a Mergable is specified (ie: that
IndexWriter doesn't forget to set it)



-Hoss


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


Mime
View raw message