Skip to content

Commit

Permalink
Fix translog stats in testPrepareIndexForPeerRecovery (#46137)
Browse files Browse the repository at this point in the history
When recovering a shard locally, we use a translog snapshot from
newSnapshotFromGen which consists of all readers from a certain
generation. In the test, we use newSnapshotFromMinSeqNo for the
expectation. The snapshot of this method includes only readers
containing operations in the requesting range.

Closes #46022
  • Loading branch information
dnhatn authored Aug 30, 2019
1 parent 45268ec commit 0c27d0f
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.engine.NoOpEngine;
import org.elasticsearch.index.mapper.SourceToParse;
import org.elasticsearch.index.seqno.SeqNoStats;
Expand Down Expand Up @@ -173,8 +174,14 @@ public void testPrepareIndexForPeerRecovery() throws Exception {
long globalCheckpoint = populateRandomData(shard).getGlobalCheckpoint();
Optional<SequenceNumbers.CommitInfo> safeCommit = shard.store().findSafeIndexCommit(globalCheckpoint);
assertTrue(safeCommit.isPresent());
final Translog.TranslogGeneration recoveringTranslogGeneration;
try (Engine.IndexCommitRef commitRef = shard.acquireSafeIndexCommit()) {
recoveringTranslogGeneration = new Translog.TranslogGeneration(
commitRef.getIndexCommit().getUserData().get(Translog.TRANSLOG_UUID_KEY),
Long.parseLong(commitRef.getIndexCommit().getUserData().get(Translog.TRANSLOG_GENERATION_KEY)));
}
int expectedTotalLocal = 0;
try (Translog.Snapshot snapshot = getTranslog(shard).newSnapshotFromMinSeqNo(safeCommit.get().localCheckpoint + 1)) {
try (Translog.Snapshot snapshot = getTranslog(shard).newSnapshotFromGen(recoveringTranslogGeneration, globalCheckpoint)) {
Translog.Operation op;
while ((op = snapshot.next()) != null) {
if (op.seqNo() <= globalCheckpoint) {
Expand Down

0 comments on commit 0c27d0f

Please sign in to comment.