Close first engine instance before creating second (#1457)

When creating the second instance of an InternalEngine using the same
translog config of the default InternalEngine instance, the second
instance will attempt to delete all the existing translog files. I found
a deterministic test failure when running with the seed
`E3E6AAD95ABD299B`.

As opposed to creating a second engine instance with a different
translog location, just close the first one before creating the second.

Signed-off-by: Andrew Ross <andrross@amazon.com>
This commit is contained in:
Andrew Ross 2021-10-28 03:11:05 -05:00 committed by GitHub
parent 37ac3788a3
commit 12789f89a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 32 deletions

View File

@ -3807,38 +3807,35 @@ public class InternalEngineTests extends EngineTestCase {
}
TranslogDeletionPolicyFactory translogDeletionPolicyFactory = CustomTranslogDeletionPolicy::new;
try (Store store = createStore()) {
EngineConfig config = engine.config();
EngineConfig configWithCustomTranslogDeletionPolicyFactory = new EngineConfig(
config.getShardId(),
config.getThreadPool(),
config.getIndexSettings(),
config.getWarmer(),
store,
config.getMergePolicy(),
config.getAnalyzer(),
config.getSimilarity(),
new CodecService(null, logger),
config.getEventListener(),
config.getQueryCache(),
config.getQueryCachingPolicy(),
config.getTranslogConfig(),
translogDeletionPolicyFactory,
config.getFlushMergesAfter(),
config.getExternalRefreshListener(),
config.getInternalRefreshListener(),
config.getIndexSort(),
config.getCircuitBreakerService(),
config.getGlobalCheckpointSupplier(),
config.retentionLeasesSupplier(),
config.getPrimaryTermSupplier(),
config.getTombstoneDocSupplier()
);
try (InternalEngine engine = createEngine(configWithCustomTranslogDeletionPolicyFactory)) {
assertTrue(engine.getTranslog().getDeletionPolicy() instanceof CustomTranslogDeletionPolicy);
}
}
EngineConfig config = engine.config();
EngineConfig configWithCustomTranslogDeletionPolicyFactory = new EngineConfig(
config.getShardId(),
config.getThreadPool(),
config.getIndexSettings(),
config.getWarmer(),
config.getStore(),
config.getMergePolicy(),
config.getAnalyzer(),
config.getSimilarity(),
new CodecService(null, logger),
config.getEventListener(),
config.getQueryCache(),
config.getQueryCachingPolicy(),
config.getTranslogConfig(),
translogDeletionPolicyFactory,
config.getFlushMergesAfter(),
config.getExternalRefreshListener(),
config.getInternalRefreshListener(),
config.getIndexSort(),
config.getCircuitBreakerService(),
config.getGlobalCheckpointSupplier(),
config.retentionLeasesSupplier(),
config.getPrimaryTermSupplier(),
config.getTombstoneDocSupplier()
);
engine.close();
engine = createEngine(configWithCustomTranslogDeletionPolicyFactory);
assertTrue(engine.getTranslog().getDeletionPolicy() instanceof CustomTranslogDeletionPolicy);
}
public void testShardNotAvailableExceptionWhenEngineClosedConcurrently() throws IOException, InterruptedException {