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 131
131
import java .util .Objects ;
132
132
import java .util .Set ;
133
133
import java .util .concurrent .CopyOnWriteArrayList ;
134
+ import java .util .concurrent .CountDownLatch ;
134
135
import java .util .concurrent .TimeUnit ;
135
136
import java .util .concurrent .TimeoutException ;
136
137
import java .util .concurrent .atomic .AtomicBoolean ;
@@ -361,14 +362,17 @@ public void updatePrimaryTerm(final long newPrimaryTerm) {
361
362
"primary terms can only go up; current term [" + primaryTerm + "], new term [" + newPrimaryTerm + "]" ;
362
363
/*
363
364
* 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.
365
367
*/
368
+ final CountDownLatch latch = new CountDownLatch (1 );
366
369
indexShardOperationPermits .asyncBlockOperations (
367
370
30 ,
368
371
TimeUnit .MINUTES ,
369
- () -> {} ,
372
+ latch :: await ,
370
373
e -> failShard ("exception during primary term transition" , e ));
371
374
primaryTerm = newPrimaryTerm ;
375
+ latch .countDown ();
372
376
}
373
377
}
374
378
}
You can’t perform that action at this time.
0 commit comments