Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decrease store refcount on any failure to create NRTReplicationEngine #9796

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.opensearch.index.seqno.SeqNoStats;
import org.opensearch.index.seqno.SequenceNumbers;
import org.opensearch.index.translog.Translog;
import org.opensearch.index.translog.TranslogCorruptedException;
import org.opensearch.index.translog.TranslogDeletionPolicy;
import org.opensearch.index.translog.TranslogException;
import org.opensearch.index.translog.TranslogManager;
Expand Down Expand Up @@ -71,6 +72,7 @@ public NRTReplicationEngine(EngineConfig engineConfig) {
store.incRef();
NRTReplicationReaderManager readerManager = null;
WriteOnlyTranslogManager translogManagerRef = null;
boolean success = false;
try {
this.replicaFileTracker = new ReplicaFileTracker(store::deleteQuiet);
this.lastCommittedSegmentInfos = store.readLastCommittedSegmentsInfo();
Expand Down Expand Up @@ -124,9 +126,17 @@ public void onAfterTranslogSync() {
engineConfig.getPrimaryModeSupplier()
);
this.translogManager = translogManagerRef;
} catch (IOException e) {
IOUtils.closeWhileHandlingException(store::decRef, readerManager, translogManagerRef);
success = true;
} catch (IOException | TranslogCorruptedException e) {
throw new EngineCreationFailureException(shardId, "failed to create engine", e);
} finally {
if (success == false) {
IOUtils.closeWhileHandlingException(readerManager, translogManagerRef);
if (isClosed.get() == false) {
// failure, we need to dec the store reference
store.decRef();
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,28 @@ public void testCreateEngine() throws IOException {
}
}

public void testCreateEngineWithException() throws IOException {
final AtomicLong globalCheckpoint = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED);
final Store nrtEngineStore = createStore(INDEX_SETTINGS, newDirectory());
try {
// Passing null translogPath to induce failure
final EngineConfig replicaConfig = config(
defaultSettings,
nrtEngineStore,
null,
NoMergePolicy.INSTANCE,
null,
null,
globalCheckpoint::get
);
new NRTReplicationEngine(replicaConfig);
} catch (Exception e) {
// Ignore as engine creation will fail
}
assertEquals(1, nrtEngineStore.refCount());
nrtEngineStore.close();
}

public void testEngineWritesOpsToTranslog() throws Exception {
final AtomicLong globalCheckpoint = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED);

Expand Down