Propagate exception during recovery if segement info can not be opended but should

This commit is contained in:
Simon Willnauer 2013-01-25 13:37:28 +01:00
parent 1be84c273b
commit a7bb3c29f2
2 changed files with 9 additions and 16 deletions

View File

@ -88,18 +88,6 @@ public class Lucene {
return defaultVersion;
}
/**
* Reads the segments infos, returning null if it doesn't exists
*/
@Nullable
public static SegmentInfos readSegmentInfosIfExists(Directory directory) {
try {
return readSegmentInfos(directory);
} catch (IOException e) {
return null;
}
}
/**
* Reads the segments infos, failing if it fails to load
*/
@ -108,7 +96,7 @@ public class Lucene {
sis.read(directory);
return sis;
}
public static long count(IndexSearcher searcher, Query query) throws IOException {
TotalHitCountCollector countCollector = new TotalHitCountCollector();
// we don't need scores, so wrap it in a constant score query

View File

@ -100,7 +100,14 @@ public class LocalIndexShardGateway extends AbstractIndexShardComponent implemen
long version = -1;
long translogId = -1;
try {
SegmentInfos si = Lucene.readSegmentInfosIfExists(indexShard.store().directory());
SegmentInfos si = null;
try {
si = Lucene.readSegmentInfos(indexShard.store().directory());
} catch (IOException e) {
if (indexShouldExists && indexShard.store().indexStore().persistent()) {
throw new IndexShardGatewayRecoveryException(shardId(), "shard allocated for local recovery (post api), should exists, but doesn't", e);
}
}
if (si != null) {
if (indexShouldExists) {
version = si.getVersion();
@ -117,8 +124,6 @@ public class LocalIndexShardGateway extends AbstractIndexShardComponent implemen
IndexWriter writer = new IndexWriter(indexShard.store().directory(), new IndexWriterConfig(Lucene.VERSION, Lucene.STANDARD_ANALYZER).setOpenMode(IndexWriterConfig.OpenMode.CREATE));
writer.close();
}
} else if (indexShouldExists && indexShard.store().indexStore().persistent()) {
throw new IndexShardGatewayRecoveryException(shardId(), "shard allocated for local recovery (post api), should exists, but doesn't");
}
} catch (IOException e) {
throw new IndexShardGatewayRecoveryException(shardId(), "Failed to fetch index version after copying it over", e);