From 25c6e8512d5fd7ed2138cad713f2714f52e881c7 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Thu, 15 Sep 2011 14:56:37 +0300 Subject: [PATCH] fix full flush when no changes happen in the index, so the updated trans id is not written --- .../index/engine/robin/RobinEngine.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java index fd34ab67825..cda00abf594 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java @@ -833,7 +833,19 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { long translogId = translogIdGenerator.incrementAndGet(); translog.newTransientTranslog(translogId); indexWriter.commit(MapBuilder.newMapBuilder().put(Translog.TRANSLOG_ID_KEY, Long.toString(translogId)).map()); - translog.makeTransientCurrent(); + if (flush.force()) { + // if we force, we might not have committed, we need to check that its the same id + Map commitUserData = IndexReader.getCommitUserData(store.directory()); + long committedTranslogId = Long.parseLong(commitUserData.get(Translog.TRANSLOG_ID_KEY)); + if (committedTranslogId != translogId) { + // we did not commit anything, revert to the old translog + translog.revertTransient(); + } else { + translog.makeTransientCurrent(); + } + } else { + translog.makeTransientCurrent(); + } } catch (Exception e) { translog.revertTransient(); throw new FlushFailedEngineException(shardId, e);