Skip to content

Commit f749bac

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 c74527e commit f749bac

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,8 @@ public void rollGeneration() throws IOException {
16701670
* required generation
16711671
*/
16721672
public void trimUnreferencedReaders() throws IOException {
1673+
// move most of the data to disk to reduce the time the lock is held
1674+
sync();
16731675
try (ReleasableLock ignored = writeLock.acquire()) {
16741676
if (closed.get()) {
16751677
// we're shutdown potentially on some tragic event, don't delete anything
@@ -1697,6 +1699,7 @@ public void trimUnreferencedReaders() throws IOException {
16971699
// We now update the checkpoint to ignore the file we are going to remove.
16981700
// Note that there is a provision in recoverFromFiles to allow for the case where we synced the checkpoint
16991701
// but crashed before we could delete the file.
1702+
// sync at once to make sure that there's at most one unreferenced generation.
17001703
current.sync();
17011704
deleteReaderFiles(reader);
17021705
}

0 commit comments

Comments
 (0)