@@ -2216,15 +2216,10 @@ private void innerOpenEngineAndTranslog(LongSupplier globalCheckpointSupplier) t
22162216 synchronized (engineMutex ) {
22172217 assert getEngineOrNull () == null : "engine is running" ;
22182218 verifyNotClosed ();
2219- engineResetLock .readLock ().lock (); // prevent engine resets while closing
2220- try {
2221- // we must create a new engine under mutex (see IndexShard#snapshotStoreMetadata).
2222- final Engine newEngine = createEngine (config );
2223- onNewEngine (newEngine );
2224- getAndSetCurrentEngine (newEngine );
2225- } finally {
2226- engineResetLock .readLock ().unlock ();
2227- }
2219+ // we must create a new engine under mutex (see IndexShard#snapshotStoreMetadata).
2220+ final Engine newEngine = createEngine (config );
2221+ onNewEngine (newEngine );
2222+ getAndSetCurrentEngine (newEngine );
22282223 // We set active because we are now writing operations to the engine; this way,
22292224 // we can flush if we go idle after some time and become inactive.
22302225 active .set (true );
@@ -2306,12 +2301,7 @@ public void performRecoveryRestart() throws IOException {
23062301 assert assertNoEngineResetLock ();
23072302 synchronized (engineMutex ) {
23082303 assert refreshListeners .pendingCount () == 0 : "we can't restart with pending listeners" ;
2309- engineResetLock .readLock ().lock (); // prevent engine resets while closing
2310- try {
2311- IOUtils .close (getAndSetCurrentEngine (null ));
2312- } finally {
2313- engineResetLock .readLock ().unlock ();
2314- }
2304+ IOUtils .close (getAndSetCurrentEngine (null ));
23152305 resetRecoveryStage ();
23162306 }
23172307 }
@@ -3380,7 +3370,6 @@ private Engine getCurrentEngine(boolean allowNoEngine) {
33803370
33813371 private Engine getAndSetCurrentEngine (Engine newEngine ) {
33823372 assert Thread .holdsLock (engineMutex );
3383- assert engineResetLock .isReadLockedByCurrentThread () || engineResetLock .isWriteLockedByCurrentThread () /* for resets */ ;
33843373 return currentEngine .getAndSet (newEngine );
33853374 }
33863375
@@ -4545,7 +4534,7 @@ public void close() throws IOException {
45454534 assert assertNoEngineResetLock ();
45464535 synchronized (engineMutex ) {
45474536 newEngine = newEngineReference .get ();
4548- if (newEngine == getCurrentEngine ( true )) {
4537+ if (newEngine == getEngineOrNull ( )) {
45494538 // we successfully installed the new engine so do not close it.
45504539 newEngine = null ;
45514540 }
@@ -4569,12 +4558,7 @@ public void close() throws IOException {
45694558 newEngineReference .get ().refresh ("reset_engine" );
45704559 synchronized (engineMutex ) {
45714560 verifyNotClosed ();
4572- engineResetLock .readLock ().lock ();
4573- try {
4574- IOUtils .close (getAndSetCurrentEngine (newEngineReference .get ()));
4575- } finally {
4576- engineResetLock .readLock ().unlock ();
4577- }
4561+ IOUtils .close (getAndSetCurrentEngine (newEngineReference .get ()));
45784562 // We set active because we are now writing operations to the engine; this way,
45794563 // if we go idle after some time and become inactive, we still give sync'd flush a chance to run.
45804564 active .set (true );
0 commit comments