fix recursion in initialization of FileBasedIndex on error recovery path of StubUpdatingIndex instantiation, correctly restore on stringenumerator corruption/version change on index creation

This commit is contained in:
Maxim.Mossienko
2012-06-06 23:57:54 +04:00
parent 868e1241ea
commit e829e7c7c7
3 changed files with 16 additions and 13 deletions
@@ -187,7 +187,8 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi
@NotNull
@Override
public UpdatableIndex<Integer, SerializedStubTree, FileContent> createIndexImplementation(final ID<Integer, SerializedStubTree> indexId, @NotNull final FileBasedIndex owner, @NotNull IndexStorage<Integer, SerializedStubTree> storage) {
public UpdatableIndex<Integer, SerializedStubTree, FileContent> createIndexImplementation(final ID<Integer, SerializedStubTree> indexId, @NotNull final FileBasedIndex owner, @NotNull IndexStorage<Integer, SerializedStubTree> storage)
throws StorageException {
if (storage instanceof MemoryIndexStorage) {
final MemoryIndexStorage<Integer, SerializedStubTree> memStorage = (MemoryIndexStorage<Integer, SerializedStubTree>)storage;
memStorage.addBufferingStateListsner(new MemoryIndexStorage.BufferingStateListener() {
@@ -229,15 +230,9 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi
private static class MyIndex extends MapReduceIndex<Integer, SerializedStubTree, FileContent> {
private StubIndexImpl myStubIndex;
public MyIndex(final ID<Integer, SerializedStubTree> indexId, final IndexStorage<Integer, SerializedStubTree> storage, final DataIndexer<Integer, SerializedStubTree, FileContent> indexer) {
public MyIndex(final ID<Integer, SerializedStubTree> indexId, final IndexStorage<Integer, SerializedStubTree> storage, final DataIndexer<Integer, SerializedStubTree, FileContent> indexer) throws StorageException {
super(indexId, indexer, storage);
try {
checkNameStorage();
}
catch (StorageException e) {
LOG.info(e);
FileBasedIndex.getInstance().requestRebuild(INDEX_ID);
}
checkNameStorage();
}
@Override
@@ -23,5 +23,6 @@ import org.jetbrains.annotations.NotNull;
public abstract class CustomImplementationFileBasedIndexExtension<K, V, I> extends FileBasedIndexExtension<K, V> {
@NotNull
public abstract UpdatableIndex<K, V, I> createIndexImplementation(final ID<K, V> indexId, @NotNull FileBasedIndex owner, @NotNull IndexStorage<K, V> storage);
public abstract UpdatableIndex<K, V, I> createIndexImplementation(final ID<K, V> indexId, @NotNull FileBasedIndex owner, @NotNull IndexStorage<K, V> storage)
throws StorageException;
}
@@ -386,9 +386,11 @@ public class FileBasedIndexImpl extends FileBasedIndex {
IndexInfrastructure.rewriteVersion(versionFile, version);
}
MapIndexStorage<K, V> storage = null;
for (int attempt = 0; attempt < 2; attempt++) {
try {
final MapIndexStorage<K, V> storage = new MapIndexStorage<K, V>(
storage = new MapIndexStorage<K, V>(
IndexInfrastructure.getStorageFile(name),
extension.getKeyDescriptor(),
extension.getValueExternalizer(),
@@ -413,8 +415,13 @@ public class FileBasedIndexImpl extends FileBasedIndex {
myNoLimitCheckTypes.addAll(extension.getFileTypesWithSizeLimitNotApplicable());
break;
}
catch (IOException e) {
catch (Exception e) {
LOG.info(e);
try {
if (storage != null) storage.close();
storage = null;
} catch (Exception ex) {}
FileUtil.delete(IndexInfrastructure.getIndexRootDir(name));
IndexInfrastructure.rewriteVersion(versionFile, version);
}
@@ -467,7 +474,7 @@ public class FileBasedIndexImpl extends FileBasedIndex {
}
@NotNull
private <K, V> UpdatableIndex<K, V, FileContent> createIndex(@NotNull final ID<K, V> indexId, @NotNull final FileBasedIndexExtension<K, V> extension, @NotNull final MemoryIndexStorage<K, V> storage) throws IOException {
private <K, V> UpdatableIndex<K, V, FileContent> createIndex(@NotNull final ID<K, V> indexId, @NotNull final FileBasedIndexExtension<K, V> extension, @NotNull final MemoryIndexStorage<K, V> storage) throws StorageException, IOException {
final MapReduceIndex<K, V, FileContent> index;
if (extension instanceof CustomImplementationFileBasedIndexExtension) {
final UpdatableIndex<K, V, FileContent> custom = ((CustomImplementationFileBasedIndexExtension<K, V, FileContent>)extension).createIndexImplementation(indexId, this, storage);