Remove allocation id from replica replication response (#25488)
The replica replication response object has an extra allocationId field that contains the allocation id of the replica on which the request was executed. As we are sending the allocation id with the actual replica replication request, and check when executing the replica replication action that the allocation id of the replica shard is what we expect, there is no need to communicate back the allocation id as part of the response object.
This commit is contained in:
parent
6ae4497c13
commit
bb23d3b2c5
|
@ -93,7 +93,7 @@ public class TransportResyncReplicationAction extends TransportWriteAction<Resyn
|
||||||
if (node.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) {
|
if (node.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) {
|
||||||
super.sendReplicaRequest(replicaRequest, node, listener);
|
super.sendReplicaRequest(replicaRequest, node, listener);
|
||||||
} else {
|
} else {
|
||||||
listener.onResponse(new ReplicaResponse(replicaRequest.getTargetAllocationID(), SequenceNumbersService.UNASSIGNED_SEQ_NO));
|
listener.onResponse(new ReplicaResponse(SequenceNumbersService.UNASSIGNED_SEQ_NO));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -187,7 +187,7 @@ public class ReplicationOperation<
|
||||||
public void onResponse(ReplicaResponse response) {
|
public void onResponse(ReplicaResponse response) {
|
||||||
successfulShards.incrementAndGet();
|
successfulShards.incrementAndGet();
|
||||||
try {
|
try {
|
||||||
primary.updateLocalCheckpointForShard(response.allocationId(), response.localCheckpoint());
|
primary.updateLocalCheckpointForShard(shard.allocationId().getId(), response.localCheckpoint());
|
||||||
} catch (final AlreadyClosedException e) {
|
} catch (final AlreadyClosedException e) {
|
||||||
// okay, the index was deleted or this shard was never activated after a relocation; fall through and finish normally
|
// okay, the index was deleted or this shard was never activated after a relocation; fall through and finish normally
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
|
@ -429,9 +429,6 @@ public class ReplicationOperation<
|
||||||
|
|
||||||
/** the local check point for the shard. see {@link org.elasticsearch.index.seqno.SequenceNumbersService#getLocalCheckpoint()} */
|
/** the local check point for the shard. see {@link org.elasticsearch.index.seqno.SequenceNumbersService#getLocalCheckpoint()} */
|
||||||
long localCheckpoint();
|
long localCheckpoint();
|
||||||
|
|
||||||
/** the allocation id of the replica shard */
|
|
||||||
String allocationId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class RetryOnPrimaryException extends ElasticsearchException {
|
public static class RetryOnPrimaryException extends ElasticsearchException {
|
||||||
|
|
|
@ -53,6 +53,7 @@ import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
|
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
|
||||||
import org.elasticsearch.index.IndexNotFoundException;
|
import org.elasticsearch.index.IndexNotFoundException;
|
||||||
import org.elasticsearch.index.IndexService;
|
import org.elasticsearch.index.IndexService;
|
||||||
|
import org.elasticsearch.index.seqno.SequenceNumbersService;
|
||||||
import org.elasticsearch.index.shard.IndexShard;
|
import org.elasticsearch.index.shard.IndexShard;
|
||||||
import org.elasticsearch.index.shard.IndexShardState;
|
import org.elasticsearch.index.shard.IndexShardState;
|
||||||
import org.elasticsearch.index.shard.ShardId;
|
import org.elasticsearch.index.shard.ShardId;
|
||||||
|
@ -523,8 +524,7 @@ public abstract class TransportReplicationAction<
|
||||||
try {
|
try {
|
||||||
final ReplicaResult replicaResult = shardOperationOnReplica(request, replica);
|
final ReplicaResult replicaResult = shardOperationOnReplica(request, replica);
|
||||||
releasable.close(); // release shard operation lock before responding to caller
|
releasable.close(); // release shard operation lock before responding to caller
|
||||||
final TransportReplicationAction.ReplicaResponse response =
|
final TransportReplicationAction.ReplicaResponse response = new ReplicaResponse(replica.getLocalCheckpoint());
|
||||||
new ReplicaResponse(replica.routingEntry().allocationId().getId(), replica.getLocalCheckpoint());
|
|
||||||
replicaResult.respond(new ResponseListener(response));
|
replicaResult.respond(new ResponseListener(response));
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
Releasables.closeWhileHandlingException(releasable); // release shard operation lock before responding to caller
|
Releasables.closeWhileHandlingException(releasable); // release shard operation lock before responding to caller
|
||||||
|
@ -1011,14 +1011,12 @@ public abstract class TransportReplicationAction<
|
||||||
|
|
||||||
public static class ReplicaResponse extends ActionResponse implements ReplicationOperation.ReplicaResponse {
|
public static class ReplicaResponse extends ActionResponse implements ReplicationOperation.ReplicaResponse {
|
||||||
private long localCheckpoint;
|
private long localCheckpoint;
|
||||||
private String allocationId;
|
|
||||||
|
|
||||||
ReplicaResponse() {
|
ReplicaResponse() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReplicaResponse(String allocationId, long localCheckpoint) {
|
public ReplicaResponse(long localCheckpoint) {
|
||||||
this.allocationId = allocationId;
|
|
||||||
this.localCheckpoint = localCheckpoint;
|
this.localCheckpoint = localCheckpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1027,9 +1025,9 @@ public abstract class TransportReplicationAction<
|
||||||
if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) {
|
if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) {
|
||||||
super.readFrom(in);
|
super.readFrom(in);
|
||||||
localCheckpoint = in.readZLong();
|
localCheckpoint = in.readZLong();
|
||||||
allocationId = in.readString();
|
|
||||||
} else {
|
} else {
|
||||||
// 5.x used to read empty responses, which don't really read anything off the stream, so just do nothing.
|
// 5.x used to read empty responses, which don't really read anything off the stream, so just do nothing.
|
||||||
|
localCheckpoint = SequenceNumbersService.UNASSIGNED_SEQ_NO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1038,7 +1036,6 @@ public abstract class TransportReplicationAction<
|
||||||
if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) {
|
if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) {
|
||||||
super.writeTo(out);
|
super.writeTo(out);
|
||||||
out.writeZLong(localCheckpoint);
|
out.writeZLong(localCheckpoint);
|
||||||
out.writeString(allocationId);
|
|
||||||
} else {
|
} else {
|
||||||
// we use to write empty responses
|
// we use to write empty responses
|
||||||
Empty.INSTANCE.writeTo(out);
|
Empty.INSTANCE.writeTo(out);
|
||||||
|
@ -1049,11 +1046,6 @@ public abstract class TransportReplicationAction<
|
||||||
public long localCheckpoint() {
|
public long localCheckpoint() {
|
||||||
return localCheckpoint;
|
return localCheckpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String allocationId() {
|
|
||||||
return allocationId;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class GlobalCheckpointSyncAction extends TransportReplicationAction<
|
||||||
if (node.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) {
|
if (node.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) {
|
||||||
super.sendReplicaRequest(replicaRequest, node, listener);
|
super.sendReplicaRequest(replicaRequest, node, listener);
|
||||||
} else {
|
} else {
|
||||||
listener.onResponse(new ReplicaResponse(replicaRequest.getTargetAllocationID(), SequenceNumbersService.UNASSIGNED_SEQ_NO));
|
listener.onResponse(new ReplicaResponse(SequenceNumbersService.UNASSIGNED_SEQ_NO));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -464,11 +464,9 @@ public class ReplicationOperationTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ReplicaResponse implements ReplicationOperation.ReplicaResponse {
|
static class ReplicaResponse implements ReplicationOperation.ReplicaResponse {
|
||||||
final String allocationId;
|
|
||||||
final long localCheckpoint;
|
final long localCheckpoint;
|
||||||
|
|
||||||
ReplicaResponse(String allocationId, long localCheckpoint) {
|
ReplicaResponse(long localCheckpoint) {
|
||||||
this.allocationId = allocationId;
|
|
||||||
this.localCheckpoint = localCheckpoint;
|
this.localCheckpoint = localCheckpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -476,11 +474,6 @@ public class ReplicationOperationTests extends ESTestCase {
|
||||||
public long localCheckpoint() {
|
public long localCheckpoint() {
|
||||||
return localCheckpoint;
|
return localCheckpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String allocationId() {
|
|
||||||
return allocationId;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class TestReplicaProxy implements ReplicationOperation.Replicas<Request> {
|
static class TestReplicaProxy implements ReplicationOperation.Replicas<Request> {
|
||||||
|
@ -515,7 +508,7 @@ public class ReplicationOperationTests extends ESTestCase {
|
||||||
final String allocationId = replica.allocationId().getId();
|
final String allocationId = replica.allocationId().getId();
|
||||||
Long existing = generatedLocalCheckpoints.put(allocationId, checkpoint);
|
Long existing = generatedLocalCheckpoints.put(allocationId, checkpoint);
|
||||||
assertNull(existing);
|
assertNull(existing);
|
||||||
listener.onResponse(new ReplicaResponse(allocationId, checkpoint));
|
listener.onResponse(new ReplicaResponse(checkpoint));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -636,8 +636,7 @@ public class TransportReplicationActionTests extends ESTestCase {
|
||||||
CapturingTransport.CapturedRequest[] captures = transport.getCapturedRequestsAndClear();
|
CapturingTransport.CapturedRequest[] captures = transport.getCapturedRequestsAndClear();
|
||||||
assertThat(captures, arrayWithSize(1));
|
assertThat(captures, arrayWithSize(1));
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
final TransportReplicationAction.ReplicaResponse response =
|
final TransportReplicationAction.ReplicaResponse response = new TransportReplicationAction.ReplicaResponse(randomLong());
|
||||||
new TransportReplicationAction.ReplicaResponse(randomAlphaOfLength(10), randomLong());
|
|
||||||
transport.handleResponse(captures[0].requestId, response);
|
transport.handleResponse(captures[0].requestId, response);
|
||||||
assertTrue(listener.isDone());
|
assertTrue(listener.isDone());
|
||||||
assertThat(listener.get(), equalTo(response));
|
assertThat(listener.get(), equalTo(response));
|
||||||
|
|
|
@ -286,8 +286,7 @@ public class TransportWriteActionTests extends ESTestCase {
|
||||||
CapturingTransport.CapturedRequest[] captures = transport.getCapturedRequestsAndClear();
|
CapturingTransport.CapturedRequest[] captures = transport.getCapturedRequestsAndClear();
|
||||||
assertThat(captures, arrayWithSize(1));
|
assertThat(captures, arrayWithSize(1));
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
final TransportReplicationAction.ReplicaResponse response =
|
final TransportReplicationAction.ReplicaResponse response = new TransportReplicationAction.ReplicaResponse(randomLong());
|
||||||
new TransportReplicationAction.ReplicaResponse(randomAlphaOfLength(10), randomLong());
|
|
||||||
transport.handleResponse(captures[0].requestId, response);
|
transport.handleResponse(captures[0].requestId, response);
|
||||||
assertTrue(listener.isDone());
|
assertTrue(listener.isDone());
|
||||||
assertThat(listener.get(), equalTo(response));
|
assertThat(listener.get(), equalTo(response));
|
||||||
|
|
|
@ -537,9 +537,7 @@ public abstract class ESIndexLevelReplicationTestCase extends IndexShardTestCase
|
||||||
try {
|
try {
|
||||||
performOnReplica(request, replica);
|
performOnReplica(request, replica);
|
||||||
releasable.close();
|
releasable.close();
|
||||||
listener.onResponse(
|
listener.onResponse(new ReplicaResponse(replica.getLocalCheckpoint()));
|
||||||
new ReplicaResponse(
|
|
||||||
replica.routingEntry().allocationId().getId(), replica.getLocalCheckpoint()));
|
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
Releasables.closeWhileHandlingException(releasable);
|
Releasables.closeWhileHandlingException(releasable);
|
||||||
listener.onFailure(e);
|
listener.onFailure(e);
|
||||||
|
|
Loading…
Reference in New Issue