From 6c29142b91fe6582154e273a1e73632b2883551e Mon Sep 17 00:00:00 2001 From: kimchy Date: Tue, 24 Aug 2010 01:28:39 +0300 Subject: [PATCH] throw recovery failure if failing to parse all commit points --- .../index/gateway/CommitPoints.java | 2 +- .../blobstore/BlobStoreIndexGateway.java | 2 +- .../blobstore/BlobStoreIndexShardGateway.java | 21 +++++++++++++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/CommitPoints.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/CommitPoints.java index 3f2bf3d636f..86e9a3ea51c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/CommitPoints.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/CommitPoints.java @@ -162,7 +162,7 @@ public class CommitPoints implements Iterable { throw new IOException("Malformed commit, missing physical_name for [" + fileName + "]"); } if (size == -1) { - throw new IOException("Malformed commit, missing size for [" + fileName + "]"); + throw new IOException("Malformed commit, missing length for [" + fileName + "]"); } files.add(new CommitPoint.FileInfo(fileName, physicalName, size)); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/blobstore/BlobStoreIndexGateway.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/blobstore/BlobStoreIndexGateway.java index 6c400716306..343e7262b03 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/blobstore/BlobStoreIndexGateway.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/blobstore/BlobStoreIndexGateway.java @@ -78,7 +78,7 @@ public abstract class BlobStoreIndexGateway extends AbstractIndexComponent imple try { commitPointsList.add(CommitPoints.fromXContent(container.readBlobFully(name))); } catch (Exception e) { - logger.warn("failed to read commit point [{}]", name); + logger.warn("failed to read commit point [{}]", e, name); } } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/blobstore/BlobStoreIndexShardGateway.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/blobstore/BlobStoreIndexShardGateway.java index 75bed84569d..a5bc20b948d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/blobstore/BlobStoreIndexShardGateway.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/blobstore/BlobStoreIndexShardGateway.java @@ -347,7 +347,24 @@ public abstract class BlobStoreIndexShardGateway extends AbstractIndexShardCompo throw new IndexShardGatewayRecoveryException(shardId, "Failed to list content of gateway", e); } - CommitPoints commitPoints = buildCommitPoints(blobs); + List commitPointsList = Lists.newArrayList(); + boolean atLeastOneCommitPointExists = false; + for (String name : blobs.keySet()) { + if (name.startsWith("commit-")) { + atLeastOneCommitPointExists = true; + try { + commitPointsList.add(CommitPoints.fromXContent(blobContainer.readBlobFully(name))); + } catch (Exception e) { + logger.warn("failed to read commit point [{}]", e, name); + } + } + } + if (atLeastOneCommitPointExists && commitPointsList.isEmpty()) { + // no commit point managed to load, bail so we won't corrupt the index, will require manual intervention + throw new IndexShardGatewayRecoveryException(shardId, "Commit points exists but none could be loaded", null); + } + CommitPoints commitPoints = new CommitPoints(commitPointsList); + if (commitPoints.commits().isEmpty()) { recoveryStatus.index().startTime(System.currentTimeMillis()); recoveryStatus.index().time(System.currentTimeMillis() - recoveryStatus.index().startTime()); @@ -768,7 +785,7 @@ public abstract class BlobStoreIndexShardGateway extends AbstractIndexShardCompo try { commitPoints.add(CommitPoints.fromXContent(blobContainer.readBlobFully(name))); } catch (Exception e) { - logger.warn("failed to read commit point [{}]", name); + logger.warn("failed to read commit point [{}]", e, name); } } }