On Montag 13 März 2006 22:24, Bill Janssen wrote: > The default value isn't magic. The appropriate value is > context-specific. I've got some people using Lucene on machines with > slow disks, and we need to be able to increase the WRITE_LOCK_TIMEOUT > to prevent entirely random lossage.
Here's a patch (I hope it gets through). Let me know if it's okay, I will commit it then. Regards Daniel -- http://www.danielnaber.de
Index: /home/dnaber/workspace/LuceneSVN/src/java/org/apache/lucene/index/IndexWriter.java =================================================================== --- /home/dnaber/workspace/LuceneSVN/src/java/org/apache/lucene/index/IndexWriter.java (revision 382146) +++ /home/dnaber/workspace/LuceneSVN/src/java/org/apache/lucene/index/IndexWriter.java (working copy) @@ -63,6 +63,8 @@ */ public final static long WRITE_LOCK_TIMEOUT = 1000; + private long writeLockTimeout = WRITE_LOCK_TIMEOUT; + /** * Default value is 10,000. */ @@ -68,6 +70,8 @@ */ public final static long COMMIT_LOCK_TIMEOUT = 10000; + private long commitLockTimeout = COMMIT_LOCK_TIMEOUT; + public static final String WRITE_LOCK_NAME = "write.lock"; public static final String COMMIT_LOCK_NAME = "commit.lock"; @@ -252,7 +256,7 @@ analyzer = a; Lock writeLock = directory.makeLock(IndexWriter.WRITE_LOCK_NAME); - if (!writeLock.obtain(WRITE_LOCK_TIMEOUT)) // obtain write lock + if (!writeLock.obtain(writeLockTimeout)) // obtain write lock throw new IOException("Index locked for write: " + writeLock); this.writeLock = writeLock; // save it @@ -257,7 +261,7 @@ this.writeLock = writeLock; // save it synchronized (directory) { // in- & inter-process sync - new Lock.With(directory.makeLock(IndexWriter.COMMIT_LOCK_NAME), COMMIT_LOCK_TIMEOUT) { + new Lock.With(directory.makeLock(IndexWriter.COMMIT_LOCK_NAME), commitLockTimeout) { public Object doBody() throws IOException { if (create) segmentInfos.write(directory); @@ -370,6 +374,23 @@ return infoStream; } + + public void setCommitLockTimeout(long commitLockTimeout) { + this.commitLockTimeout = commitLockTimeout; + } + + public long getCommitLockTimeout() { + return commitLockTimeout; + } + + public void setWriteLockTimeout(long writeLockTimeout) { + this.writeLockTimeout = writeLockTimeout; + } + + public long getWriteLockTimeout() { + return writeLockTimeout; + } + /** Flushes all changes to an index and closes all associated files. */ public synchronized void close() throws IOException { flushRamSegments(); @@ -585,7 +606,7 @@ sReader.close(); synchronized (directory) { // in- & inter-process sync - new Lock.With(directory.makeLock(COMMIT_LOCK_NAME), COMMIT_LOCK_TIMEOUT) { + new Lock.With(directory.makeLock(COMMIT_LOCK_NAME), commitLockTimeout) { public Object doBody() throws IOException { segmentInfos.write(directory); // commit changes deleteSegments(segmentsToDelete); // delete now-unused segments @@ -597,7 +618,7 @@ if (useCompoundFile) { final Vector filesToDelete = merger.createCompoundFile(mergedName + ".tmp"); synchronized (directory) { // in- & inter-process sync - new Lock.With(directory.makeLock(COMMIT_LOCK_NAME), COMMIT_LOCK_TIMEOUT) { + new Lock.With(directory.makeLock(COMMIT_LOCK_NAME), commitLockTimeout) { public Object doBody() throws IOException { // make compound file visible for SegmentReaders directory.renameFile(mergedName + ".tmp", mergedName + ".cfs"); @@ -693,7 +714,7 @@ merger.closeReaders(); synchronized (directory) { // in- & inter-process sync - new Lock.With(directory.makeLock(COMMIT_LOCK_NAME), COMMIT_LOCK_TIMEOUT) { + new Lock.With(directory.makeLock(COMMIT_LOCK_NAME), commitLockTimeout) { public Object doBody() throws IOException { segmentInfos.write(directory); // commit before deleting deleteSegments(segmentsToDelete); // delete now-unused segments @@ -705,7 +726,7 @@ if (useCompoundFile) { final Vector filesToDelete = merger.createCompoundFile(mergedName + ".tmp"); synchronized (directory) { // in- & inter-process sync - new Lock.With(directory.makeLock(COMMIT_LOCK_NAME), COMMIT_LOCK_TIMEOUT) { + new Lock.With(directory.makeLock(COMMIT_LOCK_NAME), commitLockTimeout) { public Object doBody() throws IOException { // make compound file visible for SegmentReaders directory.renameFile(mergedName + ".tmp", mergedName + ".cfs");
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]