-
Type:
Bug
-
Status: Closed
-
Priority:
Trivial
-
Resolution: Not A Problem
-
Affects Version/s: 3.4
-
Fix Version/s: None
-
Component/s: search
-
Labels:None
If the directory where the index is stored gets somehow corrupted, and it becomes empty or the segments files are deleted, any attempt to access the Solr server (via /select, /update, etc..) will throw the following exception:
org.apache.lucene.index.IndexNotFoundException: no segments* file found in org.apache.lucene.store.NIOFSDirectory@/index_dir
The only workaround we have found is to stop the server, remove the /index directory, and start again.
We have found more useful to create a new implementation of the IndexReaderFactory (that extends StandardIndexReaderFactory), that, in case of a IndexNotFoundException, it tries to "fix" the index directory by opening an IndexWriter on it and doing a commit:
@Override public IndexReader newReader(Directory indexDir, boolean readOnly) throws IOException { try { return super.newReader(indexDir, readOnly); } catch (IndexNotFoundException e) { logger.warn( "Warning: Trying to get a new reader threw an exception. Trying to create a writer first, and then get the reader", e); IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_34, new WhitespaceAnalyzer( Version.LUCENE_34)); config.setOpenMode(OpenMode.CREATE_OR_APPEND); IndexWriter writer = new IndexWriter(indexDir, config); writer.commit(); writer.close(); try { return super.newReader(indexDir, readOnly); } catch (IndexNotFoundException e2) { logger.error( "Trying to commit in the writer didn't work, as the reader is still throwing an exception :(. Re-throwing exception", e2); throw e2; } } }
Would it make sense to add something like this to the StandardIndexReaderFactory?