Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Snapshot Resiliency Testing #39504

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
9aeebca
#38941 start reproducer
original-brownbear Feb 25, 2019
7bf2df7
writes work
original-brownbear Feb 25, 2019
dbf0e75
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Feb 25, 2019
3bce03b
works
original-brownbear Feb 25, 2019
8fd87e2
works
original-brownbear Feb 25, 2019
5a02f7e
step
original-brownbear Feb 25, 2019
2ee57a5
step
original-brownbear Feb 25, 2019
f8c6c47
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Feb 25, 2019
2c7f8a7
step
original-brownbear Feb 25, 2019
f3512ee
bck
original-brownbear Feb 25, 2019
d9df9cd
works
original-brownbear Feb 25, 2019
832a6f0
precommit passes
original-brownbear Feb 26, 2019
55b7862
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Feb 26, 2019
6c8e0d0
precommit passes
original-brownbear Feb 26, 2019
1fc8bdc
precommit passes
original-brownbear Feb 26, 2019
a2fff0d
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Feb 26, 2019
055f665
precommit passes
original-brownbear Feb 26, 2019
f3ff0cd
fix test
original-brownbear Feb 26, 2019
7490ed6
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Feb 26, 2019
4d099d3
tests pass
original-brownbear Feb 26, 2019
5f4b8f9
tests pass
original-brownbear Feb 26, 2019
5a2214a
fix test
original-brownbear Feb 26, 2019
769d23d
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Feb 26, 2019
2a4a242
nicer
original-brownbear Feb 26, 2019
1e6cf55
nicer
original-brownbear Feb 26, 2019
b4f822d
fix test
original-brownbear Feb 26, 2019
c1d0b7a
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Feb 26, 2019
03bcf92
nicer
original-brownbear Feb 26, 2019
581a033
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Feb 26, 2019
039bc60
good enough
original-brownbear Feb 27, 2019
fc25fbc
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Feb 27, 2019
ada915d
good enough
original-brownbear Feb 27, 2019
fe3463e
good enough
original-brownbear Feb 27, 2019
fda869b
good enough
original-brownbear Feb 27, 2019
391a56c
good enough
original-brownbear Feb 27, 2019
90d1aeb
good enough
original-brownbear Feb 27, 2019
d10e6df
good enough
original-brownbear Feb 27, 2019
284bfd5
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Feb 27, 2019
56dce09
nicer
original-brownbear Feb 27, 2019
2f92200
nicer
original-brownbear Feb 27, 2019
9d2d86f
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Feb 27, 2019
a87e5ad
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Feb 27, 2019
2092378
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Feb 27, 2019
8321625
nicer
original-brownbear Feb 27, 2019
5e35555
nicer
original-brownbear Feb 27, 2019
2ca4d9d
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Feb 27, 2019
46731a9
nicer
original-brownbear Feb 28, 2019
37312d2
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Feb 28, 2019
e4209ad
nicer
original-brownbear Feb 28, 2019
e82e612
nicer
original-brownbear Feb 28, 2019
6e997ad
nicer
original-brownbear Feb 28, 2019
098b085
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Feb 28, 2019
9bf228e
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Feb 28, 2019
944956a
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Feb 28, 2019
eb3a423
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Feb 28, 2019
1bce26a
fix wrong req. build
original-brownbear Feb 28, 2019
d54dca9
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Feb 28, 2019
7f0f696
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Feb 28, 2019
e6d5939
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Mar 4, 2019
a4c32bd
merge master in
original-brownbear Mar 4, 2019
95bee3a
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Mar 4, 2019
05ed8ed
fix mapping update ex handling
original-brownbear Mar 4, 2019
c8d7732
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Mar 4, 2019
2eb0bec
safer
original-brownbear Mar 4, 2019
120db72
maybe revert this
original-brownbear Mar 4, 2019
f53b20a
maybe revert this
original-brownbear Mar 4, 2019
58dc6ca
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Mar 4, 2019
ebfb3b4
fix ex. unwrapping
original-brownbear Mar 4, 2019
12f2fef
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Mar 4, 2019
f022bac
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Mar 5, 2019
9da2610
shorter
original-brownbear Mar 5, 2019
7027262
shorter diff
original-brownbear Mar 5, 2019
e02fb91
bring back assertion
original-brownbear Mar 5, 2019
8388f06
Merge remote-tracking branch 'elastic/master' into more-snapshot-resi…
original-brownbear Mar 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,18 @@ protected void acquireReplicaOperationPermit(final IndexShard replica,
}

@Override
protected PrimaryResult<ShardRequest, ReplicationResponse> shardOperationOnPrimary(final ShardRequest shardRequest,
final IndexShard primary) throws Exception {
executeShardOperation(shardRequest, primary);
return new PrimaryResult<>(shardRequest, new ReplicationResponse());
protected void shardOperationOnPrimary(final ShardRequest shardRequest, final IndexShard primary,
ActionListener<PrimaryResult<ShardRequest, ReplicationResponse>> listener) {
try {
executeShardOperation(shardRequest, primary);
listener.onResponse(new PrimaryResult<>(shardRequest, new ReplicationResponse()));
} catch (Exception e) {
listener.onFailure(e);
}
}

@Override
protected ReplicaResult shardOperationOnReplica(final ShardRequest shardRequest, final IndexShard replica) throws Exception {
protected ReplicaResult shardOperationOnReplica(final ShardRequest shardRequest, final IndexShard replica) {
executeShardOperation(shardRequest, replica);
return new ReplicaResult();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.action.admin.indices.flush;

import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.replication.ReplicationResponse;
import org.elasticsearch.action.support.replication.TransportReplicationAction;
Expand Down Expand Up @@ -51,11 +52,15 @@ protected ReplicationResponse newResponseInstance() {
}

@Override
protected PrimaryResult<ShardFlushRequest, ReplicationResponse> shardOperationOnPrimary(ShardFlushRequest shardRequest,
IndexShard primary) {
primary.flush(shardRequest.getRequest());
logger.trace("{} flush request executed on primary", primary.shardId());
return new PrimaryResult<ShardFlushRequest, ReplicationResponse>(shardRequest, new ReplicationResponse());
protected void shardOperationOnPrimary(ShardFlushRequest shardRequest, IndexShard primary,
ActionListener<PrimaryResult<ShardFlushRequest, ReplicationResponse>> listener) {
try {
primary.flush(shardRequest.getRequest());
logger.trace("{} flush request executed on primary", primary.shardId());
listener.onResponse(new PrimaryResult<>(shardRequest, new ReplicationResponse()));
} catch (Exception e) {
listener.onFailure(e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.action.admin.indices.refresh;

import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.replication.BasicReplicationRequest;
import org.elasticsearch.action.support.replication.ReplicationResponse;
Expand Down Expand Up @@ -53,10 +54,15 @@ protected ReplicationResponse newResponseInstance() {
}

@Override
protected PrimaryResult shardOperationOnPrimary(BasicReplicationRequest shardRequest, IndexShard primary) {
primary.refresh("api");
logger.trace("{} refresh request executed on primary", primary.shardId());
return new PrimaryResult(shardRequest, new ReplicationResponse());
protected void shardOperationOnPrimary(BasicReplicationRequest shardRequest, IndexShard primary,
ActionListener<PrimaryResult<BasicReplicationRequest, ReplicationResponse>> listener) {
try {
primary.refresh("api");
logger.trace("{} refresh request executed on primary", primary.shardId());
listener.onResponse(new PrimaryResult(shardRequest, new ReplicationResponse()));
} catch (Exception e) {
listener.onFailure(e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.action.bulk;

import org.elasticsearch.action.ActionListener;
import org.elasticsearch.index.mapper.Mapping;
import org.elasticsearch.index.shard.ShardId;

Expand All @@ -27,6 +28,6 @@ public interface MappingUpdatePerformer {
/**
* Update the mappings on the master.
*/
void updateMappings(Mapping update, ShardId shardId, String type);
void updateMappings(Mapping update, ShardId shardId, String type, ActionListener<Void> listener);

}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,30 @@ protected void doExecute(Task task, final Request request, final ActionListener<
}

@Override
protected WritePrimaryResult<Request, Response> shardOperationOnPrimary(
Request request, final IndexShard primary) throws Exception {
protected void shardOperationOnPrimary(
Request request, IndexShard primary, ActionListener<PrimaryResult<Request, Response>> listener) {
BulkItemRequest[] itemRequests = new BulkItemRequest[1];
WriteRequest.RefreshPolicy refreshPolicy = request.getRefreshPolicy();
request.setRefreshPolicy(WriteRequest.RefreshPolicy.NONE);
itemRequests[0] = new BulkItemRequest(0, ((DocWriteRequest<?>) request));
BulkShardRequest bulkShardRequest = new BulkShardRequest(request.shardId(), refreshPolicy, itemRequests);
WritePrimaryResult<BulkShardRequest, BulkShardResponse> bulkResult =
shardBulkAction.shardOperationOnPrimary(bulkShardRequest, primary);
assert bulkResult.finalResponseIfSuccessful.getResponses().length == 1 : "expected only one bulk shard response";
BulkItemResponse itemResponse = bulkResult.finalResponseIfSuccessful.getResponses()[0];
final Response response;
final Exception failure;
if (itemResponse.isFailed()) {
failure = itemResponse.getFailure().getCause();
response = null;
} else {
response = (Response) itemResponse.getResponse();
failure = null;
}
return new WritePrimaryResult<>(request, response, bulkResult.location, failure, primary, logger);
shardBulkAction.shardOperationOnPrimary(bulkShardRequest, primary,
ActionListener.map(listener, bulkResult -> {
assert bulkResult.finalResponseIfSuccessful.getResponses().length == 1 : "expected only one bulk shard response";
BulkItemResponse itemResponse = bulkResult.finalResponseIfSuccessful.getResponses()[0];
final Response response;
final Exception failure;
if (itemResponse.isFailed()) {
failure = itemResponse.getFailure().getCause();
response = null;
} else {
response = (Response) itemResponse.getResponse();
failure = null;
}
return new WritePrimaryResult<>(
request, response,
((WritePrimaryResult<BulkShardRequest, BulkShardResponse>) bulkResult).location, failure, primary, logger);
}));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,14 @@ public ClusterBlockLevel indexBlockLevel() {
}

@Override
protected WritePrimaryResult<ResyncReplicationRequest, ResyncReplicationResponse> shardOperationOnPrimary(
ResyncReplicationRequest request, IndexShard primary) throws Exception {
final ResyncReplicationRequest replicaRequest = performOnPrimary(request, primary);
return new WritePrimaryResult<>(replicaRequest, new ResyncReplicationResponse(), null, null, primary, logger);
protected void shardOperationOnPrimary(ResyncReplicationRequest request, IndexShard primary,
ActionListener<PrimaryResult<ResyncReplicationRequest, ResyncReplicationResponse>> listener) {
try {
final ResyncReplicationRequest replicaRequest = performOnPrimary(request, primary);
listener.onResponse(new WritePrimaryResult<>(replicaRequest, new ResyncReplicationResponse(), null, null, primary, logger));
} catch (Exception e) {
listener.onFailure(e);
}
}

public static ResyncReplicationRequest performOnPrimary(ResyncReplicationRequest request, IndexShard primary) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,33 +99,36 @@ public void execute() throws Exception {

totalShards.incrementAndGet();
pendingActions.incrementAndGet(); // increase by 1 until we finish all primary coordination
primaryResult = primary.perform(request);
primary.updateLocalCheckpointForShard(primaryRouting.allocationId().getId(), primary.localCheckpoint());
final ReplicaRequest replicaRequest = primaryResult.replicaRequest();
if (replicaRequest != null) {
if (logger.isTraceEnabled()) {
logger.trace("[{}] op [{}] completed on primary for request [{}]", primaryId, opType, request);
}
primary.perform(request, ActionListener.wrap(primaryResult -> {
this.primaryResult = primaryResult;
primary.updateLocalCheckpointForShard(primaryRouting.allocationId().getId(), primary.localCheckpoint());
final ReplicaRequest replicaRequest = primaryResult.replicaRequest();
if (replicaRequest != null) {
if (logger.isTraceEnabled()) {
logger.trace("[{}] op [{}] completed on primary for request [{}]", primaryId, opType, request);
}

// we have to get the replication group after successfully indexing into the primary in order to honour recovery semantics.
// we have to make sure that every operation indexed into the primary after recovery start will also be replicated
// to the recovery target. If we used an old replication group, we may miss a recovery that has started since then.
// we also have to make sure to get the global checkpoint before the replication group, to ensure that the global checkpoint
// is valid for this replication group. If we would sample in the reverse, the global checkpoint might be based on a subset
// of the sampled replication group, and advanced further than what the given replication group would allow it to.
// This would entail that some shards could learn about a global checkpoint that would be higher than its local checkpoint.
final long globalCheckpoint = primary.globalCheckpoint();
// we have to capture the max_seq_no_of_updates after this request was completed on the primary to make sure the value of
// max_seq_no_of_updates on replica when this request is executed is at least the value on the primary when it was executed on.
final long maxSeqNoOfUpdatesOrDeletes = primary.maxSeqNoOfUpdatesOrDeletes();
assert maxSeqNoOfUpdatesOrDeletes != SequenceNumbers.UNASSIGNED_SEQ_NO : "seqno_of_updates still uninitialized";
final ReplicationGroup replicationGroup = primary.getReplicationGroup();
markUnavailableShardsAsStale(replicaRequest, replicationGroup);
performOnReplicas(replicaRequest, globalCheckpoint, maxSeqNoOfUpdatesOrDeletes, replicationGroup);
}
// we have to get the replication group after successfully indexing into the primary in order to honour recovery semantics.
// we have to make sure that every operation indexed into the primary after recovery start will also be replicated
// to the recovery target. If we used an old replication group, we may miss a recovery that has started since then.
// we also have to make sure to get the global checkpoint before the replication group, to ensure that the global checkpoint
// is valid for this replication group. If we would sample in the reverse, the global checkpoint might be based on a subset
// of the sampled replication group, and advanced further than what the given replication group would allow it to.
// This would entail that some shards could learn about a global checkpoint that would be higher than its local checkpoint.
final long globalCheckpoint = primary.globalCheckpoint();
// we have to capture the max_seq_no_of_updates after this request was completed on the primary to make sure the value of
// max_seq_no_of_updates on replica when this request is executed is at least the value on the primary when it was executed
// on.
final long maxSeqNoOfUpdatesOrDeletes = primary.maxSeqNoOfUpdatesOrDeletes();
assert maxSeqNoOfUpdatesOrDeletes != SequenceNumbers.UNASSIGNED_SEQ_NO : "seqno_of_updates still uninitialized";
final ReplicationGroup replicationGroup = primary.getReplicationGroup();
markUnavailableShardsAsStale(replicaRequest, replicationGroup);
performOnReplicas(replicaRequest, globalCheckpoint, maxSeqNoOfUpdatesOrDeletes, replicationGroup);
}

successfulShards.incrementAndGet(); // mark primary as successful
decPendingAndFinishIfNeeded();
successfulShards.incrementAndGet(); // mark primary as successful
decPendingAndFinishIfNeeded();
}, resultListener::onFailure));
}

private void markUnavailableShardsAsStale(ReplicaRequest replicaRequest, ReplicationGroup replicationGroup) {
Expand Down Expand Up @@ -297,9 +300,9 @@ public interface Primary<
* also complete after. Deal with it.
*
* @param request the request to perform
* @return the request to send to the replicas
* @param listener result listener
*/
PrimaryResultT perform(RequestT request) throws Exception;
void perform(RequestT request, ActionListener<PrimaryResultT> listener);

/**
* Notifies the primary of a local checkpoint for the given allocation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.lucene.store.AlreadyClosedException;
import org.elasticsearch.Assertions;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.Version;
Expand Down Expand Up @@ -198,8 +199,8 @@ protected void resolveRequest(final IndexMetaData indexMetaData, final Request r
* @param shardRequest the request to the primary shard
* @param primary the primary shard to perform the operation on
*/
protected abstract PrimaryResult<ReplicaRequest, Response> shardOperationOnPrimary(
Request shardRequest, IndexShard primary) throws Exception;
protected abstract void shardOperationOnPrimary(Request shardRequest, IndexShard primary,
ActionListener<PrimaryResult<ReplicaRequest, Response>> listener);

/**
* Synchronously execute the specified replica operation. This is done under a permit from
Expand Down Expand Up @@ -480,7 +481,7 @@ protected ReplicationOperation<Request, ReplicaRequest, PrimaryResult<ReplicaReq
}
}

protected static class PrimaryResult<ReplicaRequest extends ReplicationRequest<ReplicaRequest>,
public static class PrimaryResult<ReplicaRequest extends ReplicationRequest<ReplicaRequest>,
Response extends ReplicationResponse>
implements ReplicationOperation.PrimaryResult<ReplicaRequest> {
final ReplicaRequest replicaRequest;
Expand Down Expand Up @@ -1030,11 +1031,15 @@ public void failShard(String reason, Exception e) {
}

@Override
public PrimaryResult perform(Request request) throws Exception {
PrimaryResult result = shardOperationOnPrimary(request, indexShard);
assert result.replicaRequest() == null || result.finalFailure == null : "a replica request [" + result.replicaRequest()
+ "] with a primary failure [" + result.finalFailure + "]";
return result;
public void perform(Request request, ActionListener<PrimaryResult<ReplicaRequest, Response>> listener) {
if (Assertions.ENABLED) {
listener = ActionListener.map(listener, result -> {
assert result.replicaRequest() == null || result.finalFailure == null : "a replica request [" + result.replicaRequest()
+ "] with a primary failure [" + result.finalFailure + "]";
return result;
});
}
shardOperationOnPrimary(request, indexShard, listener);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ protected ReplicationOperation.Replicas newReplicasProxy(long primaryTerm) {
/**
* Called on the primary with a reference to the primary {@linkplain IndexShard} to modify.
*
* @return the result of the operation on primary, including current translog location and operation response and failure
* async refresh is performed on the <code>primary</code> shard according to the <code>Request</code> refresh policy
* @param listener listener for the result of the operation on primary, including current translog location and operation response
* and failure async refresh is performed on the <code>primary</code> shard according to the <code>Request</code> refresh policy
*/
@Override
protected abstract WritePrimaryResult<ReplicaRequest, Response> shardOperationOnPrimary(
Request request, IndexShard primary) throws Exception;
protected abstract void shardOperationOnPrimary(
Request request, IndexShard primary, ActionListener<PrimaryResult<ReplicaRequest, Response>> listener);

/**
* Called once per replica with a reference to the replica {@linkplain IndexShard} to modify.
Expand Down
Loading