Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Open legacy indexes in read only mode in case database started in rea…
…d only mode. Using lucene index in write mode can cause index corruption/complete deletion in cases if user code use/rely on interrupts. To avoid such cases as much as possible indexes will be opened in read only mode in case if database was started in read only mode. As result after interruption lucene will raise ClosedByInterruptException exception as soon as we will try to get something from index again, but index itself will be untouched.
- Loading branch information
1 parent
229c37b
commit 782b764
Showing
14 changed files
with
1,108 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
.../lucene-index/src/main/java/org/neo4j/index/impl/lucene/legacy/IndexReferenceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,84 @@ | |||
/* | |||
* Copyright (c) 2002-2016 "Neo Technology," | |||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | |||
* | |||
* This file is part of Neo4j. | |||
* | |||
* Neo4j is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
package org.neo4j.index.impl.lucene.legacy; | |||
|
|||
import org.apache.lucene.index.IndexReader; | |||
import org.apache.lucene.search.IndexSearcher; | |||
import org.apache.lucene.store.Directory; | |||
|
|||
import java.io.File; | |||
import java.io.IOException; | |||
|
|||
/** | |||
* Factory that build appropriate (read only or writable) {@link IndexReference} for provided {@link IndexIdentifier} | |||
* or refresh previously constructed instance. | |||
*/ | |||
abstract class IndexReferenceFactory | |||
{ | |||
private final File baseStorePath; | |||
private final IndexTypeCache typeCache; | |||
private final LuceneDataSource.LuceneFilesystemFacade filesystemFacade; | |||
|
|||
IndexReferenceFactory( LuceneDataSource.LuceneFilesystemFacade filesystemFacade, File baseStorePath, | |||
IndexTypeCache typeCache ) | |||
{ | |||
this.filesystemFacade = filesystemFacade; | |||
this.baseStorePath = baseStorePath; | |||
this.typeCache = typeCache; | |||
} | |||
|
|||
/** | |||
* Create new {@link IndexReference} for provided {@link IndexIdentifier}. | |||
* @param indexIdentifier index identifier to build index for. | |||
* @return newly create {@link IndexReference} | |||
* | |||
* @throws IOException in case of exception during accessing lucene reader/writer. | |||
*/ | |||
abstract IndexReference createIndexReference( IndexIdentifier indexIdentifier ) throws IOException; | |||
|
|||
/** | |||
* Refresh previously constructed indexReference. | |||
* @param indexReference index reference to refresh | |||
* @return refreshed index reference | |||
*/ | |||
abstract IndexReference refresh( IndexReference indexReference ); | |||
|
|||
Directory getIndexDirectory( IndexIdentifier identifier ) throws IOException | |||
{ | |||
return filesystemFacade.getDirectory( baseStorePath, identifier ); | |||
} | |||
|
|||
IndexSearcher newIndexSearcher( IndexIdentifier identifier, IndexReader reader ) | |||
{ | |||
IndexSearcher searcher = new IndexSearcher( reader ); | |||
IndexType type = getType( identifier ); | |||
if ( type.getSimilarity() != null ) | |||
{ | |||
searcher.setSimilarity( type.getSimilarity() ); | |||
} | |||
return searcher; | |||
} | |||
|
|||
IndexType getType( IndexIdentifier identifier ) | |||
{ | |||
return typeCache.getIndexType( identifier, false ); | |||
} | |||
} | |||
|
Oops, something went wrong.