From 99862330bcc807d5442ec4b4193f40ab9bb7d0b8 Mon Sep 17 00:00:00 2001 From: wesleydeng Date: Wed, 21 Aug 2019 14:09:17 +0800 Subject: [PATCH 1/2] do sync before closeIntoReader to make sure we move most of the data to disk outside of the lock --- .../main/java/org/elasticsearch/index/translog/Translog.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/index/translog/Translog.java b/server/src/main/java/org/elasticsearch/index/translog/Translog.java index b98f0f2b6438d..4804c57279d32 100644 --- a/server/src/main/java/org/elasticsearch/index/translog/Translog.java +++ b/server/src/main/java/org/elasticsearch/index/translog/Translog.java @@ -1641,6 +1641,10 @@ public TranslogGeneration getMinGenerationForSeqNo(final long seqNo) { * @throws IOException if an I/O exception occurred during any file operations */ public void rollGeneration() throws IOException { + //make sure we move most of the data to disk outside of the writeLock + //and then the time the lock is held can be reduced + sync(); + try (Releasable ignored = writeLock.acquire()) { try { final TranslogReader reader = current.closeIntoReader(); From 96e97417772f07db4b40b8c3c90f678339bdc416 Mon Sep 17 00:00:00 2001 From: wesleydeng Date: Wed, 21 Aug 2019 21:31:46 +0800 Subject: [PATCH 2/2] modify comments in Translog.rollGeneration --- .../main/java/org/elasticsearch/index/translog/Translog.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/translog/Translog.java b/server/src/main/java/org/elasticsearch/index/translog/Translog.java index 4804c57279d32..2faac1cb6671d 100644 --- a/server/src/main/java/org/elasticsearch/index/translog/Translog.java +++ b/server/src/main/java/org/elasticsearch/index/translog/Translog.java @@ -1641,10 +1641,9 @@ public TranslogGeneration getMinGenerationForSeqNo(final long seqNo) { * @throws IOException if an I/O exception occurred during any file operations */ public void rollGeneration() throws IOException { - //make sure we move most of the data to disk outside of the writeLock - //and then the time the lock is held can be reduced + // make sure we move most of the data to disk outside of the writeLock + // in order to reduce the time the lock is held since it's blocking all threads sync(); - try (Releasable ignored = writeLock.acquire()) { try { final TranslogReader reader = current.closeIntoReader();