-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Make Timestamps Returned by Snapshot APIs Consistent #43148
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
Changes from all commits
3333e30
9cae546
d4f95e4
cc995ee
6223466
8aa1a5d
7f555a2
dfbef32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -187,7 +187,8 @@ private SnapshotsStatusResponse buildResponse(SnapshotsStatusRequest request, Li | |
| shardStatusBuilder.add(shardStatus); | ||
| } | ||
| builder.add(new SnapshotStatus(entry.snapshot(), entry.state(), | ||
| Collections.unmodifiableList(shardStatusBuilder), entry.includeGlobalState())); | ||
| Collections.unmodifiableList(shardStatusBuilder), entry.includeGlobalState(), entry.startTime(), | ||
| Math.max(threadPool.absoluteTimeInMillis() - entry.startTime(), 0L))); | ||
| } | ||
| } | ||
| // Now add snapshots on disk that are not currently running | ||
|
|
@@ -240,8 +241,10 @@ private SnapshotsStatusResponse buildResponse(SnapshotsStatusRequest request, Li | |
| default: | ||
| throw new IllegalArgumentException("Unknown snapshot state " + snapshotInfo.state()); | ||
| } | ||
| final long startTime = snapshotInfo.startTime(); | ||
| builder.add(new SnapshotStatus(new Snapshot(repositoryName, snapshotId), state, | ||
| Collections.unmodifiableList(shardStatusBuilder), snapshotInfo.includeGlobalState())); | ||
| Collections.unmodifiableList(shardStatusBuilder), snapshotInfo.includeGlobalState(), | ||
| startTime, snapshotInfo.endTime() - startTime)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that SnapshotInfo guarantees that endTime > startTime, maybe we should be defensive here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well no it doesn't but this isn't a new issue is it? It just shows up in two places now instead of in one. If you have skewed clocks and a master failover during snapshotting the absolute timestamp stored in the CS won't work out. All that happens now is that we see the same issue in two places instead of one?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok |
||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.elasticsearch.snapshots; | ||
|
|
||
| import org.elasticsearch.Version; | ||
| import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; | ||
| import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotStatus; | ||
| import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest; | ||
| import org.elasticsearch.client.Client; | ||
| import org.elasticsearch.common.settings.Settings; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.hamcrest.Matchers.greaterThan; | ||
|
|
||
| public class SnapshotStatusApisIT extends AbstractSnapshotIntegTestCase { | ||
|
|
||
| public void testStatusApiConsistency() { | ||
| Client client = client(); | ||
|
|
||
| logger.info("--> creating repository"); | ||
| assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings( | ||
| Settings.builder().put("location", randomRepoPath()).build())); | ||
|
|
||
| createIndex("test-idx-1", "test-idx-2", "test-idx-3"); | ||
| ensureGreen(); | ||
|
|
||
| logger.info("--> indexing some data"); | ||
| for (int i = 0; i < 100; i++) { | ||
| index("test-idx-1", "_doc", Integer.toString(i), "foo", "bar" + i); | ||
| index("test-idx-2", "_doc", Integer.toString(i), "foo", "baz" + i); | ||
| index("test-idx-3", "_doc", Integer.toString(i), "foo", "baz" + i); | ||
| } | ||
| refresh(); | ||
|
|
||
| logger.info("--> snapshot"); | ||
| CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap") | ||
| .setWaitForCompletion(true).get(); | ||
| assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); | ||
| assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), | ||
| equalTo(createSnapshotResponse.getSnapshotInfo().totalShards())); | ||
|
|
||
| List<SnapshotInfo> snapshotInfos = | ||
| client.admin().cluster().prepareGetSnapshots("test-repo").get().getSnapshots("test-repo"); | ||
| assertThat(snapshotInfos.size(), equalTo(1)); | ||
| SnapshotInfo snapshotInfo = snapshotInfos.get(0); | ||
| assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS)); | ||
| assertThat(snapshotInfo.version(), equalTo(Version.CURRENT)); | ||
|
|
||
| final List<SnapshotStatus> snapshotStatus = client.admin().cluster().snapshotsStatus( | ||
| new SnapshotsStatusRequest("test-repo", new String[]{"test-snap"})).actionGet().getSnapshots(); | ||
| assertThat(snapshotStatus.size(), equalTo(1)); | ||
| final SnapshotStatus snStatus = snapshotStatus.get(0); | ||
| assertEquals(snStatus.getStats().getStartTime(), snapshotInfo.startTime()); | ||
| assertEquals(snStatus.getStats().getTime(), snapshotInfo.endTime() - snapshotInfo.startTime()); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we check that they are not < 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I don't think we need to I think :) We get these numbers from
org.elasticsearch.index.snapshots.IndexShardSnapshotStatuswhich does all the checks internally so we should be good here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍