From 86c6f32e5d64e2c9f93f8785bd06fcc0401366ff Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Thu, 24 Oct 2019 10:01:44 -0400 Subject: [PATCH 1/2] Do not ignore exception when trim unreferenced readers --- .../index/translog/Translog.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 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 e38880797785b..4d8556c9a96cd 100644 --- a/server/src/main/java/org/elasticsearch/index/translog/Translog.java +++ b/server/src/main/java/org/elasticsearch/index/translog/Translog.java @@ -1691,16 +1691,18 @@ public void trimUnreferencedReaders() throws IOException { break; } iterator.remove(); - IOUtils.closeWhileHandlingException(reader); - final Path translogPath = reader.path(); - logger.trace("delete translog file [{}], not referenced and not current anymore", translogPath); - // The checkpoint is used when opening the translog to know which files should be recovered from. - // We now update the checkpoint to ignore the file we are going to remove. - // Note that there is a provision in recoverFromFiles to allow for the case where we synced the checkpoint - // but crashed before we could delete the file. - // sync at once to make sure that there's at most one unreferenced generation. - current.sync(); - deleteReaderFiles(reader); + try { + reader.close(); + logger.trace("delete translog file [{}], not referenced and not current anymore", reader.path); + } finally { + // The checkpoint is used when opening the translog to know which files should be recovered from. + // We now update the checkpoint to ignore the file we are going to remove. + // Note that there is a provision in recoverFromFiles to allow for the case where we synced the checkpoint + // but crashed before we could delete the file. + // sync at once to make sure that there's at most one unreferenced generation. + current.sync(); + deleteReaderFiles(reader); + } } assert readers.isEmpty() == false || current.generation == minReferencedGen : "all readers were cleaned but the minReferenceGen [" + minReferencedGen + "] is not the current writer's gen [" + From ba7f7a2936069de16867c8d7f6b267555b24ea9a Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Thu, 24 Oct 2019 22:29:56 -0400 Subject: [PATCH 2/2] keep original exception --- .../index/translog/Translog.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 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 4d8556c9a96cd..d3e82896f18cd 100644 --- a/server/src/main/java/org/elasticsearch/index/translog/Translog.java +++ b/server/src/main/java/org/elasticsearch/index/translog/Translog.java @@ -1691,18 +1691,14 @@ public void trimUnreferencedReaders() throws IOException { break; } iterator.remove(); - try { - reader.close(); - logger.trace("delete translog file [{}], not referenced and not current anymore", reader.path); - } finally { - // The checkpoint is used when opening the translog to know which files should be recovered from. - // We now update the checkpoint to ignore the file we are going to remove. - // Note that there is a provision in recoverFromFiles to allow for the case where we synced the checkpoint - // but crashed before we could delete the file. - // sync at once to make sure that there's at most one unreferenced generation. - current.sync(); - deleteReaderFiles(reader); - } + logger.trace("delete translog file [{}], not referenced and not current anymore", reader.path); + // The checkpoint is used when opening the translog to know which files should be recovered from. + // We now update the checkpoint to ignore the file we are going to remove. + // Note that there is a provision in recoverFromFiles to allow for the case where we synced the checkpoint + // but crashed before we could delete the file. + // sync at once to make sure that there's at most one unreferenced generation. + IOUtils.close(reader, current::sync); + deleteReaderFiles(reader); } assert readers.isEmpty() == false || current.generation == minReferencedGen : "all readers were cleaned but the minReferenceGen [" + minReferencedGen + "] is not the current writer's gen [" +