Only assert single commit iff index created on 6.2

We introduced a single commit assertion when opening an index but create
a new translog. However, this assertion is not held in this situation.

1. A replica with two commits c1 and c2 starts peer-recovery with c1
2. The recovery is sequence-based recovery but the primary is before 6.2 so
it sent true for “createNewTranslog”
3. Replica opens engine and create translog. We expect "open index and
create translog" have 1 commit but we have c1 and c2.

This commit makes sure to assert this iff the index was created on 6.2+.
This commit is contained in:
Nhat Nguyen 2018-01-24 10:41:15 -05:00
parent 80a7943d6a
commit 7847cded80

View File

@ -1298,8 +1298,11 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl
assert commitInfo.localCheckpoint >= globalCheckpoint : assert commitInfo.localCheckpoint >= globalCheckpoint :
"trying to create a shard whose local checkpoint [" + commitInfo.localCheckpoint + "] is < global checkpoint [" "trying to create a shard whose local checkpoint [" + commitInfo.localCheckpoint + "] is < global checkpoint ["
+ globalCheckpoint + "]"; + globalCheckpoint + "]";
final List<IndexCommit> existingCommits = DirectoryReader.listCommits(store.directory()); // This assertion is only guaranteed if all nodes are on 6.2+.
assert existingCommits.size() == 1 : "Open index create translog should have one commit, commits[" + existingCommits + "]"; if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_6_2_0)) {
final List<IndexCommit> existingCommits = DirectoryReader.listCommits(store.directory());
assert existingCommits.size() == 1 : "Open index create translog should have one commit, commits[" + existingCommits + "]";
}
} }
globalCheckpointTracker.updateGlobalCheckpointOnReplica(globalCheckpoint, "opening index with a new translog"); globalCheckpointTracker.updateGlobalCheckpointOnReplica(globalCheckpoint, "opening index with a new translog");
innerOpenEngineAndTranslog(EngineConfig.OpenMode.OPEN_INDEX_CREATE_TRANSLOG, forceNewHistoryUUID); innerOpenEngineAndTranslog(EngineConfig.OpenMode.OPEN_INDEX_CREATE_TRANSLOG, forceNewHistoryUUID);