Skip to content

Commit c6253d2

Browse files
dengweisysudnhatn
authored andcommitted
Sync translog without lock before trim unreferenced readers (#47790)
This commit is similar to the optimization made in #45765. With this change, we fsync most of the data of the current generation without holding writeLock when trimming unreferenced readers. Relates #45765
1 parent e4e396e commit c6253d2

File tree

1 file changed

+3
-0
lines changed
  • server/src/main/java/org/elasticsearch/index/translog

1 file changed

+3
-0
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,8 @@ public void rollGeneration() throws IOException {
16781678
* required generation
16791679
*/
16801680
public void trimUnreferencedReaders() throws IOException {
1681+
// move most of the data to disk to reduce the time the lock is held
1682+
sync();
16811683
try (ReleasableLock ignored = writeLock.acquire()) {
16821684
if (closed.get()) {
16831685
// we're shutdown potentially on some tragic event, don't delete anything
@@ -1705,6 +1707,7 @@ public void trimUnreferencedReaders() throws IOException {
17051707
// We now update the checkpoint to ignore the file we are going to remove.
17061708
// Note that there is a provision in recoverFromFiles to allow for the case where we synced the checkpoint
17071709
// but crashed before we could delete the file.
1710+
// sync at once to make sure that there's at most one unreferenced generation.
17081711
current.sync();
17091712
deleteReaderFiles(reader);
17101713
}

0 commit comments

Comments
 (0)