File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed
core/src/main/java/org/elasticsearch/index/shard Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change 131131import java .util .Objects ;
132132import java .util .Set ;
133133import java .util .concurrent .CopyOnWriteArrayList ;
134+ import java .util .concurrent .CountDownLatch ;
134135import java .util .concurrent .TimeUnit ;
135136import java .util .concurrent .TimeoutException ;
136137import java .util .concurrent .atomic .AtomicBoolean ;
@@ -361,14 +362,17 @@ public void updatePrimaryTerm(final long newPrimaryTerm) {
361362 "primary terms can only go up; current term [" + primaryTerm + "], new term [" + newPrimaryTerm + "]" ;
362363 /*
363364 * Before this call returns, we are guaranteed that all future operations are delayed and so this happens before we
364- * increment the primary term.
365+ * increment the primary term. The latch is needed to ensure that we do not unblock operations before the primary term is
366+ * incremented.
365367 */
368+ final CountDownLatch latch = new CountDownLatch (1 );
366369 indexShardOperationPermits .asyncBlockOperations (
367370 30 ,
368371 TimeUnit .MINUTES ,
369- () -> {} ,
372+ latch :: await ,
370373 e -> failShard ("exception during primary term transition" , e ));
371374 primaryTerm = newPrimaryTerm ;
375+ latch .countDown ();
372376 }
373377 }
374378 }
You can’t perform that action at this time.
0 commit comments