Skip to content

Commit

Permalink
Fix RFGIT#testReusePeerRecovery test bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jasontedor committed Jan 25, 2017
1 parent 76f8807 commit adafa21
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,9 @@ class FilesInfoRequestHandler implements TransportRequestHandler<RecoveryFilesIn
public void messageReceived(RecoveryFilesInfoRequest request, TransportChannel channel) throws Exception {
try (RecoveryRef recoveryRef = onGoingRecoveries.getRecoverySafe(request.recoveryId(), request.shardId()
)) {
recoveryRef.target().receiveFileInfo(request.phase1FileNames, request.phase1FileSizes, request.phase1ExistingFileNames,
final RecoveryTarget target = recoveryRef.target();
target.state().setSequenceNumberBasedRecovery(false);
target.receiveFileInfo(request.phase1FileNames, request.phase1FileSizes, request.phase1ExistingFileNames,
request.phase1ExistingFileSizes, request.totalTranslogOps);
channel.sendResponse(TransportResponse.Empty.INSTANCE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.indices.recovery;

import org.elasticsearch.Version;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.routing.RecoverySource;
import org.elasticsearch.cluster.routing.ShardRouting;
Expand Down Expand Up @@ -110,6 +111,7 @@ public static Stage fromId(byte id) {
private DiscoveryNode sourceNode;
private DiscoveryNode targetNode;
private boolean primary = false;
private boolean sequenceNumberBasedRecovery = true;

private RecoveryState() {
}
Expand Down Expand Up @@ -219,6 +221,14 @@ public boolean getPrimary() {
return primary;
}

public boolean getSequenceNumberBasedRecovery() {
return sequenceNumberBasedRecovery;
}

public void setSequenceNumberBasedRecovery(final boolean sequenceNumberBasedRecovery) {
this.sequenceNumberBasedRecovery = sequenceNumberBasedRecovery;
}

public static RecoveryState readRecoveryState(StreamInput in) throws IOException {
RecoveryState recoveryState = new RecoveryState();
recoveryState.readFrom(in);
Expand All @@ -237,6 +247,11 @@ public synchronized void readFrom(StreamInput in) throws IOException {
translog.readFrom(in);
verifyIndex.readFrom(in);
primary = in.readBoolean();
if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) {
sequenceNumberBasedRecovery = in.readBoolean();
} else {
sequenceNumberBasedRecovery = false;
}
}

@Override
Expand All @@ -251,6 +266,9 @@ public void writeTo(StreamOutput out) throws IOException {
translog.writeTo(out);
verifyIndex.writeTo(out);
out.writeBoolean(primary);
if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) {
out.writeBoolean(sequenceNumberBasedRecovery);
}
}

@Override
Expand All @@ -260,6 +278,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.field(Fields.TYPE, recoverySource.getType());
builder.field(Fields.STAGE, stage.toString());
builder.field(Fields.PRIMARY, primary);
builder.field(Fields.SEQUENCE_NUMBER_BASED_RECOVERY, sequenceNumberBasedRecovery);
builder.dateField(Fields.START_TIME_IN_MILLIS, Fields.START_TIME, timer.startTime);
if (timer.stopTime > 0) {
builder.dateField(Fields.STOP_TIME_IN_MILLIS, Fields.STOP_TIME, timer.stopTime);
Expand Down Expand Up @@ -308,6 +327,7 @@ static final class Fields {
static final String TYPE = "type";
static final String STAGE = "stage";
static final String PRIMARY = "primary";
static final String SEQUENCE_NUMBER_BASED_RECOVERY = "sequence_number_based_recovery";
static final String START_TIME = "start_time";
static final String START_TIME_IN_MILLIS = "start_time_in_millis";
static final String STOP_TIME = "stop_time";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
Expand Down Expand Up @@ -385,8 +386,6 @@ public void testLatestVersionLoaded() throws Exception {
assertThat(state.metaData().index("test").getAliases().get("test_alias").filter(), notNullValue());
}

// test fails with seed FE6770A74885D66E
@TestLogging("org.elasticsearch.indices.recovery:TRACE,org.elasticsearch.index.shard.StoreRecovery:TRACE")
public void testReusePeerRecovery() throws Exception {
final Settings settings = Settings.builder()
.put(MockFSIndexStore.INDEX_CHECK_INDEX_ON_CLOSE_SETTING.getKey(), false)
Expand Down Expand Up @@ -465,7 +464,9 @@ public void testReusePeerRecovery() throws Exception {
recovered += file.length();
}
}
if (!recoveryState.getPrimary() && (useSyncIds == false)) {
if (recoveryState.getSequenceNumberBasedRecovery()) {
assertThat(recoveryState.getTranslog().recoveredOperations(), greaterThanOrEqualTo(0));
} else if (!recoveryState.getPrimary() && (useSyncIds == false)) {
logger.info("--> replica shard {} recovered from {} to {}, recovered {}, reuse {}",
recoveryState.getShardId().getId(), recoveryState.getSourceNode().getName(), recoveryState.getTargetNode().getName(),
recoveryState.getIndex().recoveredBytes(), recoveryState.getIndex().reusedBytes());
Expand Down

0 comments on commit adafa21

Please sign in to comment.