Skip to content

Commit f2d2ca2

Browse files
Cleaner Handling of Store Refcount in BlobStoreRepository (#47560) (#47594)
If a shard gets closed we properly abort its snapshot before closing it. We should in thise case make sure to not throw a confusing exception about trying to increment the reference on an already closed shard in the async tasks if the snapshot is already aborted. Also, added an assertion to make sure that aborts are in fact the only situation in which we run into a concurrently closed store.
1 parent e47bdf7 commit f2d2ca2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,18 @@ public void snapshotShard(Store store, MapperService mapperService, SnapshotId s
11591159
protected void doRun() {
11601160
try {
11611161
if (alreadyFailed.get() == false) {
1162-
snapshotFile(snapshotFileInfo, indexId, shardId, snapshotId, snapshotStatus, store);
1162+
if (store.tryIncRef()) {
1163+
try {
1164+
snapshotFile(snapshotFileInfo, indexId, shardId, snapshotId, snapshotStatus, store);
1165+
} finally {
1166+
store.decRef();
1167+
}
1168+
} else if (snapshotStatus.isAborted()) {
1169+
throw new IndexShardSnapshotFailedException(shardId, "Aborted");
1170+
} else {
1171+
assert false : "Store was closed before aborting the snapshot";
1172+
throw new IllegalStateException("Store is closed already");
1173+
}
11631174
}
11641175
filesListener.onResponse(null);
11651176
} catch (IOException e) {
@@ -1360,7 +1371,6 @@ private void snapshotFile(BlobStoreIndexShardSnapshot.FileInfo fileInfo, IndexId
13601371
IndexShardSnapshotStatus snapshotStatus, Store store) throws IOException {
13611372
final BlobContainer shardContainer = shardContainer(indexId, shardId);
13621373
final String file = fileInfo.physicalName();
1363-
store.incRef();
13641374
try (IndexInput indexInput = store.openVerifyingInput(file, IOContext.READONCE, fileInfo.metadata())) {
13651375
for (int i = 0; i < fileInfo.numberOfParts(); i++) {
13661376
final long partBytes = fileInfo.partBytes(i);
@@ -1400,8 +1410,6 @@ private void checkAborted() {
14001410
failStoreIfCorrupted(store, t);
14011411
snapshotStatus.addProcessedFile(0);
14021412
throw t;
1403-
} finally {
1404-
store.decRef();
14051413
}
14061414
}
14071415

0 commit comments

Comments
 (0)