|
@@ -16,6 +16,7 @@ import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.action.ActionListener;
|
|
|
import org.elasticsearch.action.ActionResponse;
|
|
|
import org.elasticsearch.action.ActionRunnable;
|
|
|
+import org.elasticsearch.action.SingleResultDeduplicator;
|
|
|
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
|
|
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
|
|
|
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
|
@@ -137,6 +138,8 @@ public class CcrRepository extends AbstractLifecycleComponent implements Reposit
|
|
|
|
|
|
private final CounterMetric throttledTime = new CounterMetric();
|
|
|
|
|
|
+ private final SingleResultDeduplicator<ClusterState> csDeduplicator;
|
|
|
+
|
|
|
public CcrRepository(RepositoryMetadata metadata, Client client, Settings settings, CcrSettings ccrSettings, ThreadPool threadPool) {
|
|
|
this.metadata = metadata;
|
|
|
this.ccrSettings = ccrSettings;
|
|
@@ -145,6 +148,17 @@ public class CcrRepository extends AbstractLifecycleComponent implements Reposit
|
|
|
this.remoteClusterAlias = Strings.split(metadata.name(), NAME_PREFIX)[1];
|
|
|
this.client = client;
|
|
|
this.threadPool = threadPool;
|
|
|
+ csDeduplicator = new SingleResultDeduplicator<>(
|
|
|
+ threadPool.getThreadContext(),
|
|
|
+ l -> getRemoteClusterClient().admin()
|
|
|
+ .cluster()
|
|
|
+ .prepareState()
|
|
|
+ .clear()
|
|
|
+ .setMetadata(true)
|
|
|
+ .setNodes(true)
|
|
|
+ .setMasterNodeTimeout(TimeValue.MAX_VALUE)
|
|
|
+ .execute(l.map(ClusterStateResponse::getState))
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -177,26 +191,22 @@ public class CcrRepository extends AbstractLifecycleComponent implements Reposit
|
|
|
assert snapshotIds.size() == 1 && SNAPSHOT_ID.equals(snapshotIds.iterator().next())
|
|
|
: "RemoteClusterRepository only supports " + SNAPSHOT_ID + " as the SnapshotId but saw " + snapshotIds;
|
|
|
try {
|
|
|
- getRemoteClusterClient().admin()
|
|
|
- .cluster()
|
|
|
- .prepareState()
|
|
|
- .clear()
|
|
|
- .setMetadata(true)
|
|
|
- .setNodes(true)
|
|
|
- // fork to the snapshot meta pool because the context expects to run on it and asserts that it does
|
|
|
- .execute(new ThreadedActionListener<>(logger, threadPool, ThreadPool.Names.SNAPSHOT_META, context.map(response -> {
|
|
|
- Metadata responseMetadata = response.getState().metadata();
|
|
|
+ csDeduplicator.execute(
|
|
|
+ new ThreadedActionListener<>(logger, threadPool, ThreadPool.Names.SNAPSHOT_META, context.map(response -> {
|
|
|
+ Metadata responseMetadata = response.metadata();
|
|
|
Map<String, IndexMetadata> indicesMap = responseMetadata.indices();
|
|
|
return new SnapshotInfo(
|
|
|
new Snapshot(this.metadata.name(), SNAPSHOT_ID),
|
|
|
List.copyOf(indicesMap.keySet()),
|
|
|
List.copyOf(responseMetadata.dataStreams().keySet()),
|
|
|
List.of(),
|
|
|
- response.getState().getNodes().getMaxNodeVersion(),
|
|
|
+ response.getNodes().getMaxNodeVersion(),
|
|
|
SnapshotState.SUCCESS
|
|
|
);
|
|
|
- }), false));
|
|
|
+ }), false)
|
|
|
+ );
|
|
|
} catch (Exception e) {
|
|
|
+ assert false : e;
|
|
|
context.onFailure(e);
|
|
|
}
|
|
|
}
|
|
@@ -255,8 +265,8 @@ public class CcrRepository extends AbstractLifecycleComponent implements Reposit
|
|
|
@Override
|
|
|
public void getRepositoryData(ActionListener<RepositoryData> listener) {
|
|
|
try {
|
|
|
- getRemoteClusterClient().admin().cluster().prepareState().clear().setMetadata(true).execute(listener.map(response -> {
|
|
|
- final Metadata remoteMetadata = response.getState().getMetadata();
|
|
|
+ csDeduplicator.execute(listener.map(response -> {
|
|
|
+ final Metadata remoteMetadata = response.getMetadata();
|
|
|
final String[] concreteAllIndices = remoteMetadata.getConcreteAllIndices();
|
|
|
final Map<String, SnapshotId> copiedSnapshotIds = Maps.newMapWithExpectedSize(concreteAllIndices.length);
|
|
|
final Map<String, RepositoryData.SnapshotDetails> snapshotsDetails = Maps.newMapWithExpectedSize(concreteAllIndices.length);
|
|
@@ -285,6 +295,7 @@ public class CcrRepository extends AbstractLifecycleComponent implements Reposit
|
|
|
);
|
|
|
}));
|
|
|
} catch (Exception e) {
|
|
|
+ assert false;
|
|
|
listener.onFailure(e);
|
|
|
}
|
|
|
}
|