Skip to content

Commit 41d3eb3

Browse files
committed
Revert "Sync translog without lock when trim unreferenced readers (#46203)"
Unfortunately, with this change, we won't clean up all unreferenced generations when reopening. We assume that there's at most one unreferenced generation when reopening translog. The previous implementation guarantees this assumption by syncing translog every time after we remove a translog reader. This change, however, only syncs translog once after we have removed all unreferenced readers (can be more than one) and breaks the assumption. Closes #46267 This reverts commit fd8183e.
1 parent a4ed7b1 commit 41d3eb3

File tree

1 file changed

+9
-20
lines changed
  • server/src/main/java/org/elasticsearch/index/translog

1 file changed

+9
-20
lines changed

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

+9-20
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,6 @@ public void rollGeneration() throws IOException {
16701670
* required generation
16711671
*/
16721672
public void trimUnreferencedReaders() throws IOException {
1673-
List<TranslogReader> toDeleteReaderList = new ArrayList<>();
16741673
try (ReleasableLock ignored = writeLock.acquire()) {
16751674
if (closed.get()) {
16761675
// we're shutdown potentially on some tragic event, don't delete anything
@@ -1684,14 +1683,22 @@ public void trimUnreferencedReaders() throws IOException {
16841683
"deletion policy requires a minReferenceGen of [" + minReferencedGen + "] which is higher than the current generation ["
16851684
+ currentFileGeneration() + "]";
16861685

1686+
16871687
for (Iterator<TranslogReader> iterator = readers.iterator(); iterator.hasNext(); ) {
16881688
TranslogReader reader = iterator.next();
16891689
if (reader.getGeneration() >= minReferencedGen) {
16901690
break;
16911691
}
16921692
iterator.remove();
1693-
toDeleteReaderList.add(reader);
16941693
IOUtils.closeWhileHandlingException(reader);
1694+
final Path translogPath = reader.path();
1695+
logger.trace("delete translog file [{}], not referenced and not current anymore", translogPath);
1696+
// The checkpoint is used when opening the translog to know which files should be recovered from.
1697+
// We now update the checkpoint to ignore the file we are going to remove.
1698+
// Note that there is a provision in recoverFromFiles to allow for the case where we synced the checkpoint
1699+
// but crashed before we could delete the file.
1700+
current.sync();
1701+
deleteReaderFiles(reader);
16951702
}
16961703
assert readers.isEmpty() == false || current.generation == minReferencedGen :
16971704
"all readers were cleaned but the minReferenceGen [" + minReferencedGen + "] is not the current writer's gen [" +
@@ -1700,24 +1707,6 @@ public void trimUnreferencedReaders() throws IOException {
17001707
closeOnTragicEvent(ex);
17011708
throw ex;
17021709
}
1703-
// Do sync outside the writeLock to avoid blocking all writing thread.
1704-
if (toDeleteReaderList.isEmpty() == false) {
1705-
try {
1706-
// The checkpoint is used when opening the translog to know which files should be recovered from.
1707-
// We now update the checkpoint to ignore the file we are going to remove.
1708-
// Note that there is a provision in recoverFromFiles to allow for the case where we synced the checkpoint
1709-
// but crashed before we could delete the file.
1710-
sync();
1711-
for (TranslogReader reader : toDeleteReaderList) {
1712-
final Path translogPath = reader.path();
1713-
logger.trace("delete translog file [{}], not referenced and not current anymore", translogPath);
1714-
deleteReaderFiles(reader);
1715-
}
1716-
} catch (final Exception ex) {
1717-
closeOnTragicEvent(ex);
1718-
throw ex;
1719-
}
1720-
}
17211710
}
17221711

17231712
/**

0 commit comments

Comments
 (0)