File tree 1 file changed +12
-16
lines changed
server/src/main/java/org/elasticsearch/index/shard
1 file changed +12
-16
lines changed Original file line number Diff line number Diff line change @@ -1606,21 +1606,19 @@ private void innerOpenEngineAndTranslog(LongSupplier globalCheckpointSupplier) t
1606
1606
synchronized (engineMutex ) {
1607
1607
// we must create a new engine under mutex (see IndexShard#snapshotStoreMetadata).
1608
1608
final Engine newEngine = engineFactory .newReadWriteEngine (config );
1609
- boolean success = false ;
1610
- try {
1611
- synchronized (mutex ) {
1609
+ synchronized (mutex ) {
1610
+ try {
1612
1611
verifyNotClosed ();
1613
1612
assert currentEngineReference .get () == null : "engine is running" ;
1614
1613
onNewEngine (newEngine );
1615
1614
currentEngineReference .set (newEngine );
1616
1615
// We set active because we are now writing operations to the engine; this way,
1617
1616
// if we go idle after some time and become inactive, we still give sync'd flush a chance to run.
1618
1617
active .set (true );
1619
- success = true ;
1620
- }
1621
- } finally {
1622
- if (success == false ) {
1623
- newEngine .close ();
1618
+ } finally {
1619
+ if (currentEngineReference .get () != newEngine ) {
1620
+ newEngine .close ();
1621
+ }
1624
1622
}
1625
1623
}
1626
1624
}
@@ -3372,16 +3370,14 @@ public void close() throws IOException {
3372
3370
IOUtils .close (super ::close , newEngine );
3373
3371
}
3374
3372
};
3375
- boolean success = false ;
3376
- try {
3377
- synchronized (mutex ) {
3373
+ synchronized (mutex ) {
3374
+ try {
3378
3375
verifyNotClosed ();
3379
3376
IOUtils .close (currentEngineReference .getAndSet (readOnlyEngine ));
3380
- success = true ;
3381
- }
3382
- } finally {
3383
- if (success == false ) {
3384
- readOnlyEngine .close ();
3377
+ } finally {
3378
+ if (currentEngineReference .get () != readOnlyEngine ) {
3379
+ readOnlyEngine .close ();
3380
+ }
3385
3381
}
3386
3382
}
3387
3383
newEngineReference .set (engineFactory .newReadWriteEngine (newEngineConfig (replicationTracker )));
You can’t perform that action at this time.
0 commit comments