You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Björn Ekengren <bj...@avanza.se> on 2006/08/23 13:04:23 UTC
Problem updating index while reader is open
If I try to add documents to an index while a reader is open I get en error message saying "Cannot delete C:\myindex\_3n.f0". I suspect that this is due to the fact that the windows fs won't allow deletion of a file when there is a filehandler connected to it. The solution I have at the moment is this:
boolean isWindows = System.getProperty("os.name").indexOf("indows")!=-1;
IndexReader reader = searcher.getIndexSearcher().getIndexReader();
try {
if(isWindows)
reader.close(); // Need to close reader on windows since the windows file system won't allow deletion of a file with an open filehandler
IIndexer indexer = searcher.getIndexer();
addedDocuments = indexer.rebuildIndex();
if(isWindows)
searcher.setIndexSearcher(new IndexSearcher(searcher.getIndexDir()));//restore index searcher
} catch (IOException e) {
e.printStackTrace();
}
However this means that I cannot search the index while updating it (or in this case rebuilding it completely). Are there any workaround for this ? Maybe you could rebuild the index into another place on the disk and when it is finished set the searcher to operate in the new place. This would lead to that it is not possible to query the new index until finished. Could you get around this if you build the new index as a RamDirectory which is flushed to disk when finished ?
--regards
/Bjorn
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Problem updating index while reader is open
Posted by Michael McCandless <lu...@mikemccandless.com>.
> If I try to add documents to an index while a reader is open I get en error message saying "Cannot delete C:\myindex\_3n.f0". I suspect that this is due to the fact that the windows fs won't allow deletion of a file when there is a filehandler connected to it. The solution I have at the moment is this:
You are correct: Lucene is trying to remove all previous index files
because you are doing a clean rebuild of your index.
Doing a clean rebuild (create=true on opening the IndexWriter) against
an index that's open for searching is not currently a supported use
case, and this is exactly the error you'll hit on Windows. As a
workaround, you could do a clean build into a fresh directory and then
restart your index searchers against this fresh directory (and remove
the old one)?
However, making incremental changes to an index (adding or deleting
docs) that's open for searching is a valid use case. You need to
ensure your locking directory (defaults to windows temp dir) is set to
the same [local, not remote NFS/Samba] directory for readers &
writers. Since you're using a single JVM (I think?) you probably have
that already. Are you also hitting an exception for that case?
Mike
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org