Build the shared indexed reader early (before commit)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4832 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Andrew Hind
2007-01-15 15:39:14 +00:00
parent 91875aa76c
commit 1746843e34

View File

@@ -69,11 +69,7 @@ import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.store.RAMDirectory;
/** /**
* The information that makes up an index. * The information that makes up an index. IndexInfoVersion Repeated information of the form
*
* IndexInfoVersion
*
* Repeated information of the form
* <ol> * <ol>
* <li> Index Type. * <li> Index Type.
* <li> sub-directory name. * <li> sub-directory name.
@@ -84,17 +80,12 @@ import org.apache.lucene.store.RAMDirectory;
* <li>Overlay: Transaction status * <li>Overlay: Transaction status
* </ol> * </ol>
* </ol> * </ol>
* * Merges always take place to new indexes so we can detect merge failure or partial merges. Or we do not know what has
* Merges always take place to new indexes so we can detect merge failure or partial merges. Or we do not know what has merged. * merged. Incomplete delete merging does not matter - the overlay would still exist and be treated as such. So a
* * document may be deleted in the index as well as in the applied overlay. It is still correctly deleted. NOTE: Public
* Incomplete delete merging does not matter - the overlay would still exist and be treated as such. So a document may be deleted in the index as well as in the applied overlay. It * methods lock as required, the private methods assume that the appropriate locks have been obtained. TODO: Write
* is still correctly deleted. * element status into individual directories. This would be enough for recovery if both index files are lost or
* * corrupted. TODO: Tidy up index status at start up or after some time. How long would you leave a merge to run?
* NOTE: Public methods lock as required, the private methods assume that the appropriate locks have been obtained.
*
* TODO: Write element status into individual directories. This would be enough for recovery if both index files are lost or corrupted.
*
* TODO: Tidy up index status at start up or after some time. How long would you leave a merge to run?
* *
* @author Andy Hind * @author Andy Hind
*/ */
@@ -155,7 +146,8 @@ public class IndexInfo
private long version = -1; private long version = -1;
/** /**
* The index entries that make up this index. Map entries are looked up by name. These are maintained in order so document order is maintained. * The index entries that make up this index. Map entries are looked up by name. These are maintained in order so
* document order is maintained.
*/ */
private LinkedHashMap<String, IndexEntry> indexEntries = new LinkedHashMap<String, IndexEntry>(); private LinkedHashMap<String, IndexEntry> indexEntries = new LinkedHashMap<String, IndexEntry>();
@@ -442,7 +434,6 @@ public class IndexInfo
cleanerThread.start(); cleanerThread.start();
} }
if (enableMergerThread) if (enableMergerThread)
{ {
mergerThread = new Thread(merger); mergerThread = new Thread(merger);
@@ -888,6 +879,12 @@ public class IndexInfo
throw new IndexerException("\"null\" is not a valid identifier for a transaction"); throw new IndexerException("\"null\" is not a valid identifier for a transaction");
} }
final Transition transition = getTransition(state); final Transition transition = getTransition(state);
getReadLock();
try
{
transition.beforeWithReadLock(id, toDelete, read);
releaseReadLock();
getWriteLock(); getWriteLock();
try try
{ {
@@ -930,9 +927,15 @@ public class IndexInfo
} }
finally finally
{ {
getReadLock();
releaseWriteLock(); releaseWriteLock();
} }
} }
finally
{
releaseReadLock();
}
}
// //
// Internal support for status management // Internal support for status management
@@ -967,6 +970,8 @@ public class IndexInfo
private interface Transition private interface Transition
{ {
void beforeWithReadLock(String id, Set<Term> toDelete, Set<Term> read) throws IOException;
void transition(String id, Set<Term> toDelete, Set<Term> read) throws IOException; void transition(String id, Set<Term> toDelete, Set<Term> read) throws IOException;
boolean requiresFileLock(); boolean requiresFileLock();
@@ -974,6 +979,11 @@ public class IndexInfo
private class PreparingTransition implements Transition private class PreparingTransition implements Transition
{ {
public void beforeWithReadLock(String id, Set<Term> toDelete, Set<Term> read) throws IOException
{
}
public void transition(String id, Set<Term> toDelete, Set<Term> read) throws IOException public void transition(String id, Set<Term> toDelete, Set<Term> read) throws IOException
{ {
IndexEntry entry = indexEntries.get(id); IndexEntry entry = indexEntries.get(id);
@@ -1001,6 +1011,11 @@ public class IndexInfo
private class PreparedTransition implements Transition private class PreparedTransition implements Transition
{ {
public void beforeWithReadLock(String id, Set<Term> toDelete, Set<Term> read) throws IOException
{
}
public void transition(String id, Set<Term> toDelete, Set<Term> read) throws IOException public void transition(String id, Set<Term> toDelete, Set<Term> read) throws IOException
{ {
IndexEntry entry = indexEntries.get(id); IndexEntry entry = indexEntries.get(id);
@@ -1066,6 +1081,11 @@ public class IndexInfo
private class CommittingTransition implements Transition private class CommittingTransition implements Transition
{ {
public void beforeWithReadLock(String id, Set<Term> toDelete, Set<Term> read) throws IOException
{
}
public void transition(String id, Set<Term> toDelete, Set<Term> read) throws IOException public void transition(String id, Set<Term> toDelete, Set<Term> read) throws IOException
{ {
IndexEntry entry = indexEntries.get(id); IndexEntry entry = indexEntries.get(id);
@@ -1093,6 +1113,14 @@ public class IndexInfo
private class CommittedTransition implements Transition private class CommittedTransition implements Transition
{ {
public void beforeWithReadLock(String id, Set<Term> toDelete, Set<Term> read) throws IOException
{
// Make sure we have set up the reader for the data
// ... and close it so we do not up the ref count
getReferenceCountingIndexReader(id).close();
}
public void transition(String id, Set<Term> toDelete, Set<Term> read) throws IOException public void transition(String id, Set<Term> toDelete, Set<Term> read) throws IOException
{ {
IndexEntry entry = indexEntries.get(id); IndexEntry entry = indexEntries.get(id);
@@ -1129,6 +1157,7 @@ public class IndexInfo
merger.notify(); merger.notify();
} }
} }
} }
else else
{ {
@@ -1145,6 +1174,11 @@ public class IndexInfo
private class RollingBackTransition implements Transition private class RollingBackTransition implements Transition
{ {
public void beforeWithReadLock(String id, Set<Term> toDelete, Set<Term> read) throws IOException
{
}
public void transition(String id, Set<Term> toDelete, Set<Term> read) throws IOException public void transition(String id, Set<Term> toDelete, Set<Term> read) throws IOException
{ {
IndexEntry entry = indexEntries.get(id); IndexEntry entry = indexEntries.get(id);
@@ -1173,6 +1207,11 @@ public class IndexInfo
private class RolledBackTransition implements Transition private class RolledBackTransition implements Transition
{ {
public void beforeWithReadLock(String id, Set<Term> toDelete, Set<Term> read) throws IOException
{
}
public void transition(String id, Set<Term> toDelete, Set<Term> read) throws IOException public void transition(String id, Set<Term> toDelete, Set<Term> read) throws IOException
{ {
IndexEntry entry = indexEntries.get(id); IndexEntry entry = indexEntries.get(id);
@@ -1201,6 +1240,11 @@ public class IndexInfo
private class DeletableTransition implements Transition private class DeletableTransition implements Transition
{ {
public void beforeWithReadLock(String id, Set<Term> toDelete, Set<Term> read) throws IOException
{
}
public void transition(String id, Set<Term> toDelete, Set<Term> read) throws IOException public void transition(String id, Set<Term> toDelete, Set<Term> read) throws IOException
{ {
IndexEntry entry = indexEntries.get(id); IndexEntry entry = indexEntries.get(id);
@@ -1234,6 +1278,11 @@ public class IndexInfo
private class ActiveTransition implements Transition private class ActiveTransition implements Transition
{ {
public void beforeWithReadLock(String id, Set<Term> toDelete, Set<Term> read) throws IOException
{
}
public void transition(String id, Set<Term> toDelete, Set<Term> read) throws IOException public void transition(String id, Set<Term> toDelete, Set<Term> read) throws IOException
{ {
IndexEntry entry = indexEntries.get(id); IndexEntry entry = indexEntries.get(id);
@@ -1862,6 +1911,7 @@ public class IndexInfo
catch (InterruptedException e) catch (InterruptedException e)
{ {
runnable = false; runnable = false;
s_logger.warn("Cleaner thread for " + indexDirectory + "stopped by interruption.");
} }
} }
} }
@@ -1899,31 +1949,14 @@ public class IndexInfo
} }
/** /**
* Supported by one thread. * Supported by one thread. 1) If the first index is a delta we can just change it to an index. There is now here to
* * apply the deletions 2) Merge indexes Combine indexes together according to the target index merge strategy. This
* 1) If the first index is a delta we can just change it to an index. * is a trade off to make an optimised index but not spend too much time merging and optimising small merges. 3)
* * Apply next deletion set to indexes Apply the deletions for the first delta to all the other indexes. Deletes can
* There is now here to apply the deletions * be applied with relative impunity. If any are applied they take effect as required. 1) 2) and 3) are mutually
* * exclusive try in order This could be supported in another thread 4) Merge deltas Merge two index deltas together.
* 2) Merge indexes * Starting at the end. Several merges can be going on at once. a) Find merge b) Set state c) apply deletions to the
* * previous delta d) update state e) add deletions to the previous delta deletion list f) update state
* Combine indexes together according to the target index merge strategy. This is a trade off to make an optimised index but not spend too much time merging and optimising
* small merges.
*
* 3) Apply next deletion set to indexes
*
* Apply the deletions for the first delta to all the other indexes. Deletes can be applied with relative impunity. If any are applied they take effect as required.
*
* 1) 2) and 3) are mutually exclusive try in order
*
* This could be supported in another thread
*
* 4) Merge deltas
*
* Merge two index deltas together. Starting at the end. Several merges can be going on at once.
*
* a) Find merge b) Set state c) apply deletions to the previous delta d) update state e) add deletions to the previous delta deletion list f) update state
*
*/ */
private enum MergeAction private enum MergeAction
@@ -2830,5 +2863,4 @@ public class IndexInfo
this.writerUseCompoundFile = writerUseCompoundFile; this.writerUseCompoundFile = writerUseCompoundFile;
} }
} }