Skip to content

Commit 152cae7

Browse files
committed
Fix ordering of checking/locks
1 parent cabd994 commit 152cae7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

core/src/main/java/org/elasticsearch/index/translog/Translog.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,10 @@ public Location add(final Operation operation) throws IOException {
425425
ensureOpen();
426426
location = current.add(bytes, operation.seqNo());
427427
}
428-
try (ReleasableLock ignored = writeLock.acquire()) {
429-
if (shouldFoldGeneration(this) && foldingGeneration.compareAndSet(false, true)) {
430-
// we have to check the condition again lest we could fold twice in a race
431-
if (shouldFoldGeneration(this)) {
428+
if (shouldFoldGeneration(this) && foldingGeneration.compareAndSet(false, true)) {
429+
// we have to check the condition again lest we could fold twice in a race
430+
if (shouldFoldGeneration(this)) {
431+
try (ReleasableLock ignored = writeLock.acquire()) {
432432
this.foldGeneration(current.getGeneration());
433433
}
434434
final boolean wasFoldingGeneration = foldingGeneration.getAndSet(false);

0 commit comments

Comments
 (0)