Skip to content

Commit

Permalink
Handling No file exception due to absence of remote metadata file
Browse files Browse the repository at this point in the history
  • Loading branch information
vikasvb90 committed Oct 11, 2024
1 parent c23774f commit 9136d86
Showing 1 changed file with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

import java.io.Closeable;
import java.io.IOException;
import java.nio.file.NoSuchFileException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -133,26 +134,17 @@ protected void innerRecoveryToTarget(ActionListener<RecoveryResponse> listener,
resources.addAll(delayedStaleCommitDeleteOps);
GatedCloseable<Long> translogRetentionLock = sourceShard.acquireRetentionLockWithMinGen();
resources.add(translogRetentionLock);
// Make sure that all operations before acquired translog generation are present in the last commit.
// In remote store replication mode refreshed but not flushed ops are also trimmed from translog and hence,
// a flush is required to ensure that all operations before the acquired translog are present in the local commit.
// Also, a refresh is done as part of flush and therefore, we can expect commit to be present in remote store
// as well.
sourceShard.flush(new FlushRequest().waitIfOngoing(true).force(true));

Releasable releaseStore = acquireStore(sourceShard.store());
resources.add(releaseStore);
GatedCloseable<IndexCommit> lastCommit = acquireLastCommit(sourceShard,false);
resources.add(lastCommit);

Tuple<String, RemoteSegmentMetadata> fetchedMetadataTuple = null;
if (sourceShard.remoteStore() != null) {
fetchedMetadataTuple = sourceShard.getMetadataContentForCommit(
sourceShard.getOperationPrimaryTerm(),
lastCommit.get().getGeneration());
ensureMetadataHasAllSegmentsFromCommit(lastCommit.get(), fetchedMetadataTuple.v2());
GatedCloseable<IndexCommit> lastCommit;
try {
lastCommit = acquireCommitAndFetchMetadata(translogRetentionLock);
} catch (NoSuchFileException ex) {
// Handling of a known issue in remote store flow https://github.com/opensearch-project/OpenSearch/pull/10341
logger.warn("Exception while acquiring commit and fetching metadata", ex);
lastCommit = acquireCommitAndFetchMetadata(translogRetentionLock);
}
splitCommitMetadata.set(new SplitCommitMetadata(translogRetentionLock.get(), fetchedMetadataTuple));

final StepListener<SendFileResult> sendFileStep = new StepListener<>();
final StepListener<TimeValue> prepareEngineStep = new StepListener<>();
Expand Down Expand Up @@ -205,6 +197,28 @@ protected void innerRecoveryToTarget(ActionListener<RecoveryResponse> listener,
finalizeStepAndCompleteFuture(startingSeqNo, sendSnapshotStep, sendFileStepWithEmptyResult(), prepareEngineStep, finalizeStep, onFailure);
}

private GatedCloseable<IndexCommit> acquireCommitAndFetchMetadata(GatedCloseable<Long> translogRetentionLock) throws IOException {
// Make sure that all operations before acquired translog generation are present in the last commit.
// In remote store replication mode refreshed but not flushed ops are also trimmed from translog and hence,
// a flush is required to ensure that all operations before the acquired translog are present in the local commit.
// Also, a refresh is done as part of flush and therefore, we can expect commit to be present in remote store
// as well.
sourceShard.flush(new FlushRequest().waitIfOngoing(true).force(true));

GatedCloseable<IndexCommit> lastCommit = acquireLastCommit(sourceShard,false);
resources.add(lastCommit);

Tuple<String, RemoteSegmentMetadata> fetchedMetadataTuple = null;
if (sourceShard.remoteStore() != null) {
fetchedMetadataTuple = sourceShard.getMetadataContentForCommit(
sourceShard.getOperationPrimaryTerm(),
lastCommit.get().getGeneration());
ensureMetadataHasAllSegmentsFromCommit(lastCommit.get(), fetchedMetadataTuple.v2());
}
splitCommitMetadata.set(new SplitCommitMetadata(translogRetentionLock.get(), fetchedMetadataTuple));
return lastCommit;
}

private void ensureMetadataHasAllSegmentsFromCommit(IndexCommit indexCommit, RemoteSegmentMetadata metadata) throws IOException {
List<String> missingFiles = new ArrayList<>();
for (String file : indexCommit.getFileNames()) {
Expand Down

0 comments on commit 9136d86

Please sign in to comment.