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,15 +3807,13 @@ public class InternalEngineTests extends EngineTestCase {
} }
TranslogDeletionPolicyFactory translogDeletionPolicyFactory = CustomTranslogDeletionPolicy::new; TranslogDeletionPolicyFactory translogDeletionPolicyFactory = CustomTranslogDeletionPolicy::new;
try (Store store = createStore()) {
EngineConfig config = engine.config(); EngineConfig config = engine.config();
EngineConfig configWithCustomTranslogDeletionPolicyFactory = new EngineConfig( EngineConfig configWithCustomTranslogDeletionPolicyFactory = new EngineConfig(
config.getShardId(), config.getShardId(),
config.getThreadPool(), config.getThreadPool(),
config.getIndexSettings(), config.getIndexSettings(),
config.getWarmer(), config.getWarmer(),
store, config.getStore(),
config.getMergePolicy(), config.getMergePolicy(),
config.getAnalyzer(), config.getAnalyzer(),
config.getSimilarity(), config.getSimilarity(),
@ -3835,11 +3833,10 @@ public class InternalEngineTests extends EngineTestCase {
config.getPrimaryTermSupplier(), config.getPrimaryTermSupplier(),
config.getTombstoneDocSupplier() config.getTombstoneDocSupplier()
); );
try (InternalEngine engine = createEngine(configWithCustomTranslogDeletionPolicyFactory)) { engine.close();
engine = createEngine(configWithCustomTranslogDeletionPolicyFactory);
assertTrue(engine.getTranslog().getDeletionPolicy() instanceof CustomTranslogDeletionPolicy); assertTrue(engine.getTranslog().getDeletionPolicy() instanceof CustomTranslogDeletionPolicy);
} }
}
}
public void testShardNotAvailableExceptionWhenEngineClosedConcurrently() throws IOException, InterruptedException { public void testShardNotAvailableExceptionWhenEngineClosedConcurrently() throws IOException, InterruptedException {
AtomicReference<Exception> exception = new AtomicReference<>(); AtomicReference<Exception> exception = new AtomicReference<>();