Skip to content

[CCR] Improve error when operations are missing #35179

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

Merged
merged 2 commits into from
Nov 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -6,6 +6,8 @@
package org.elasticsearch.xpack.ccr.action;

import org.apache.logging.log4j.message.ParameterizedMessage;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequestValidationException;
Expand All @@ -24,13 +26,15 @@
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.seqno.SeqNoStats;
import org.elasticsearch.index.shard.IndexShard;
import org.elasticsearch.index.shard.IndexShardNotStartedException;
import org.elasticsearch.index.shard.IndexShardState;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.translog.Translog;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;

Expand Down Expand Up @@ -362,6 +366,21 @@ protected void asyncShardOperation(
}
}

@Override
protected void doExecute(Task task, Request request, ActionListener<Response> listener) {
ActionListener<Response> wrappedListener = ActionListener.wrap(listener::onResponse, e -> {
Throwable cause = ExceptionsHelper.unwrapCause(e);
if (cause instanceof IllegalStateException && cause.getMessage().contains("Not all operations between from_seqno [")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with this change but I prefer to narrow the scope. How about catching and converting the exception with the existing try in ShardChangesAction#getOperations? I am thinking to have a dedicated exception so that we can access "fromSeqNo" and "toSeqNo" but maybe overkilled. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking to have a dedicated exception so that we can access "fromSeqNo" and "toSeqNo" but maybe overkilled.

We should not introduce that dedicated exception I think.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with this change but I prefer to narrow the scope. How about catching and converting the exception with the existing try in ShardChangesAction#getOperations

I think converting the exception there is premature. If a replica shard copy is queried, it may not have all the operations, but another shard may have it, so the shard changes api can retry it on another shard copy. Then the exception convertion was not needed, since the shard changes api was able to serve the request after all.

When we intercept the exception at the place were the exception conversion is now, we know that the shard changes has attempted the read the range of operations on all shard copies, but still wasn't able to satisfy the request.

I am thinking to have a dedicated exception so that we can access "fromSeqNo" and "toSeqNo" but maybe overkilled. WDYT?

I was considering this, because the way we detect this kind of error is weak (instance of IllegalStateException AND the exception message containing a specific message). What about throwing an EngineException with two headers (from and to seqno) in LuceneChangesSnapshot#rangeCheck(...)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation. Let's do it here. Since the error has an inner cause which provides from_seq_no and to_seq_no information, I think we are good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+100 to any way that doesn't rely on message strings. Thanks for iterating on this to get there!

String message = "Operations are no longer available for replicating. Maybe increase the retention setting [" +
IndexSettings.INDEX_SOFT_DELETES_RETENTION_OPERATIONS_SETTING.getKey() + "]?";
listener.onFailure(new ElasticsearchException(message, e));
} else {
listener.onFailure(e);
}
});
super.doExecute(task, request, wrappedListener);
}

private void globalCheckpointAdvanced(
final ShardId shardId,
final long globalCheckpoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*/
package org.elasticsearch.xpack.ccr.action;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
import org.elasticsearch.action.admin.indices.stats.ShardStats;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentType;
Expand Down Expand Up @@ -84,4 +87,33 @@ public void testGetOperationsBasedOnGlobalSequenceId() throws Exception {
assertThat(operation.id(), equalTo("5"));
}

public void testMissingOperations() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice test 👍

client().admin().indices().prepareCreate("index")
.setSettings(Settings.builder()
.put("index.soft_deletes.enabled", true)
.put("index.soft_deletes.retention.operations", 0)
.put("index.number_of_shards", 1)
.put("index.number_of_replicas", 0))
.get();

for (int i = 0; i < 16; i++) {
client().prepareIndex("index", "_doc", "1").setSource("{}", XContentType.JSON).get();
client().prepareDelete("index", "_doc", "1").get();
}
client().admin().indices().refresh(new RefreshRequest("index")).actionGet();
ForceMergeRequest forceMergeRequest = new ForceMergeRequest("index");
forceMergeRequest.maxNumSegments(1);
client().admin().indices().forceMerge(forceMergeRequest).actionGet();

ShardStats shardStats = client().admin().indices().prepareStats("index").get().getIndex("index").getShards()[0];
String historyUUID = shardStats.getCommitStats().getUserData().get(Engine.HISTORY_UUID_KEY);
ShardChangesAction.Request request = new ShardChangesAction.Request(shardStats.getShardRouting().shardId(), historyUUID);
request.setFromSeqNo(0L);
request.setMaxOperationCount(1);

Exception e = expectThrows(ElasticsearchException.class, () -> client().execute(ShardChangesAction.INSTANCE, request).actionGet());
assertThat(e.getMessage(), equalTo("Operations are no longer available for replicating. Maybe increase the retention setting " +
"[index.soft_deletes.retention.operations]?"));
}

}