-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add CcrRestoreSourceService to track sessions #36578
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 5 commits
b1ee4fd
2479f94
9fac474
7b79a5e
fe3ef84
e85bfa1
71db9aa
8d1a151
500350c
5f9c1f3
17a5f24
be2e6e8
e275823
6e4a59d
592bdc0
d0798ca
8a6ae8d
b781cb0
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 |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.ccr.action.repositories; | ||
|
|
||
| import org.elasticsearch.action.Action; | ||
| import org.elasticsearch.action.ActionResponse; | ||
| import org.elasticsearch.action.support.ActionFilters; | ||
| import org.elasticsearch.action.support.single.shard.TransportSingleShardAction; | ||
| import org.elasticsearch.cluster.ClusterState; | ||
| import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
| import org.elasticsearch.cluster.routing.IndexShardRoutingTable; | ||
| import org.elasticsearch.cluster.routing.ShardsIterator; | ||
| import org.elasticsearch.cluster.service.ClusterService; | ||
| import org.elasticsearch.common.inject.Inject; | ||
| import org.elasticsearch.index.shard.IndexShard; | ||
| import org.elasticsearch.index.shard.ShardId; | ||
| import org.elasticsearch.index.shard.ShardNotFoundException; | ||
| import org.elasticsearch.indices.IndicesService; | ||
| import org.elasticsearch.threadpool.ThreadPool; | ||
| import org.elasticsearch.transport.TransportService; | ||
| import org.elasticsearch.xpack.ccr.repository.CcrRestoreSourceService; | ||
|
|
||
| public class DeleteCcrRestoreSessionAction extends Action<DeleteCcrRestoreSessionAction.DeleteCcrRestoreSessionResponse> { | ||
|
|
||
| public static final DeleteCcrRestoreSessionAction INSTANCE = new DeleteCcrRestoreSessionAction(); | ||
| private static final String NAME = "internal:admin/ccr/restore/session/delete"; | ||
|
|
||
| private DeleteCcrRestoreSessionAction() { | ||
| super(NAME); | ||
| } | ||
|
|
||
| @Override | ||
| public DeleteCcrRestoreSessionResponse newResponse() { | ||
| return new DeleteCcrRestoreSessionResponse(); | ||
| } | ||
|
|
||
| public static class TransportDeleteCcrRestoreSessionAction | ||
| extends TransportSingleShardAction<DeleteCcrRestoreSessionRequest, DeleteCcrRestoreSessionResponse> { | ||
|
|
||
| private final IndicesService indicesService; | ||
|
||
| private final CcrRestoreSourceService ccrRestoreService; | ||
|
|
||
| @Inject | ||
| public TransportDeleteCcrRestoreSessionAction(ThreadPool threadPool, ClusterService clusterService, ActionFilters actionFilters, | ||
| IndexNameExpressionResolver resolver, TransportService transportService, | ||
| IndicesService indicesService, CcrRestoreSourceService ccrRestoreService) { | ||
| super(NAME, threadPool, clusterService, transportService, actionFilters, resolver, DeleteCcrRestoreSessionRequest::new, | ||
| ThreadPool.Names.GENERIC); | ||
| this.indicesService = indicesService; | ||
| this.ccrRestoreService = ccrRestoreService; | ||
| } | ||
|
|
||
| @Override | ||
| protected DeleteCcrRestoreSessionResponse shardOperation(DeleteCcrRestoreSessionRequest request, ShardId shardId) { | ||
| IndexShard indexShard = indicesService.getShardOrNull(shardId); | ||
| if (indexShard == null) { | ||
| throw new ShardNotFoundException(shardId); | ||
| } | ||
| ccrRestoreService.closeSession(request.getSessionUUID(), indexShard); | ||
| return new DeleteCcrRestoreSessionResponse(); | ||
| } | ||
|
|
||
| @Override | ||
| protected DeleteCcrRestoreSessionResponse newResponse() { | ||
| return new DeleteCcrRestoreSessionResponse(); | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean resolveIndex(DeleteCcrRestoreSessionRequest request) { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| protected ShardsIterator shards(ClusterState state, InternalRequest request) { | ||
| final ShardId shardId = request.request().getShardId(); | ||
| // The index uuid is not correct if we restore with a rename | ||
Tim-Brooks marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| IndexShardRoutingTable shardRoutingTable = state.routingTable().shardRoutingTable(shardId.getIndexName(), shardId.id()); | ||
| return shardRoutingTable.primaryShardIt(); | ||
| } | ||
| } | ||
|
|
||
| public static class DeleteCcrRestoreSessionResponse extends ActionResponse { | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.ccr.action.repositories; | ||
|
|
||
| import org.elasticsearch.action.ActionRequestValidationException; | ||
| import org.elasticsearch.action.support.single.shard.SingleShardRequest; | ||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.index.shard.ShardId; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class DeleteCcrRestoreSessionRequest extends SingleShardRequest<DeleteCcrRestoreSessionRequest> { | ||
|
|
||
| private String sessionUUID; | ||
| private ShardId shardId; | ||
|
|
||
| DeleteCcrRestoreSessionRequest() { | ||
| } | ||
|
|
||
| public DeleteCcrRestoreSessionRequest(String sessionUUID, ShardId shardId) { | ||
| super(shardId.getIndexName()); | ||
| this.sessionUUID = sessionUUID; | ||
| this.shardId = shardId; | ||
| } | ||
|
|
||
| @Override | ||
| public ActionRequestValidationException validate() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void readFrom(StreamInput streamInput) throws IOException { | ||
| super.readFrom(streamInput); | ||
| sessionUUID = streamInput.readString(); | ||
| shardId = ShardId.readShardId(streamInput); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput streamOutput) throws IOException { | ||
| super.writeTo(streamOutput); | ||
| streamOutput.writeString(sessionUUID); | ||
| shardId.writeTo(streamOutput); | ||
| } | ||
|
|
||
| public String getSessionUUID() { | ||
| return sessionUUID; | ||
| } | ||
|
|
||
| public ShardId getShardId() { | ||
| return shardId; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.ccr.action.repositories; | ||
|
|
||
| import org.elasticsearch.action.Action; | ||
| import org.elasticsearch.action.ActionResponse; | ||
| import org.elasticsearch.action.support.ActionFilters; | ||
| import org.elasticsearch.action.support.single.shard.TransportSingleShardAction; | ||
| import org.elasticsearch.cluster.ClusterState; | ||
| import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
| import org.elasticsearch.cluster.routing.IndexShardRoutingTable; | ||
| import org.elasticsearch.cluster.routing.ShardsIterator; | ||
| import org.elasticsearch.cluster.service.ClusterService; | ||
| import org.elasticsearch.common.inject.Inject; | ||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.common.io.stream.Writeable; | ||
| import org.elasticsearch.index.shard.IndexShard; | ||
| import org.elasticsearch.index.shard.ShardId; | ||
| import org.elasticsearch.index.shard.ShardNotFoundException; | ||
| import org.elasticsearch.index.store.Store; | ||
| import org.elasticsearch.index.store.StoreFileMetaData; | ||
| import org.elasticsearch.indices.IndicesService; | ||
| import org.elasticsearch.threadpool.ThreadPool; | ||
| import org.elasticsearch.transport.TransportService; | ||
| import org.elasticsearch.xpack.ccr.repository.CcrRestoreSourceService; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class PutCcrRestoreSessionAction extends Action<PutCcrRestoreSessionAction.PutCcrRestoreSessionResponse> { | ||
|
|
||
| public static final PutCcrRestoreSessionAction INSTANCE = new PutCcrRestoreSessionAction(); | ||
| private static final String NAME = "internal:admin/ccr/restore/session/put"; | ||
|
|
||
| private PutCcrRestoreSessionAction() { | ||
| super(NAME); | ||
| } | ||
|
|
||
| @Override | ||
| public PutCcrRestoreSessionResponse newResponse() { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| @Override | ||
| public Writeable.Reader<PutCcrRestoreSessionAction.PutCcrRestoreSessionResponse> getResponseReader() { | ||
| return PutCcrRestoreSessionAction.PutCcrRestoreSessionResponse::new; | ||
| } | ||
|
|
||
| public static class TransportPutCcrRestoreSessionAction | ||
| extends TransportSingleShardAction<PutCcrRestoreSessionRequest, PutCcrRestoreSessionResponse> { | ||
|
|
||
| private final IndicesService indicesService; | ||
| private final CcrRestoreSourceService ccrRestoreService; | ||
|
|
||
| @Inject | ||
| public TransportPutCcrRestoreSessionAction(ThreadPool threadPool, ClusterService clusterService, ActionFilters actionFilters, | ||
| IndexNameExpressionResolver resolver, TransportService transportService, | ||
| IndicesService indicesService, CcrRestoreSourceService ccrRestoreService) { | ||
| super(NAME, threadPool, clusterService, transportService, actionFilters, resolver, PutCcrRestoreSessionRequest::new, | ||
| ThreadPool.Names.GENERIC); | ||
| this.indicesService = indicesService; | ||
| this.ccrRestoreService = ccrRestoreService; | ||
| } | ||
|
|
||
| @Override | ||
| protected PutCcrRestoreSessionResponse shardOperation(PutCcrRestoreSessionRequest request, ShardId shardId) throws IOException { | ||
| IndexShard indexShard = indicesService.getShardOrNull(shardId); | ||
| if (indexShard == null) { | ||
| throw new ShardNotFoundException(shardId); | ||
| } | ||
| Store.MetadataSnapshot sourceMetaData = ccrRestoreService.openSession(request.getSessionUUID(), indexShard); | ||
| Store.RecoveryDiff recoveryDiff = sourceMetaData.recoveryDiff(request.getMetaData()); | ||
|
|
||
| ArrayList<StoreFileMetaData> filesToRecover = new ArrayList<>(recoveryDiff.different); | ||
| filesToRecover.addAll(recoveryDiff.missing); | ||
| return new PutCcrRestoreSessionResponse(indexShard.routingEntry().currentNodeId(), recoveryDiff.identical, filesToRecover); | ||
| } | ||
|
|
||
| @Override | ||
| protected PutCcrRestoreSessionResponse newResponse() { | ||
| return new PutCcrRestoreSessionResponse(); | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean resolveIndex(PutCcrRestoreSessionRequest request) { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| protected ShardsIterator shards(ClusterState state, InternalRequest request) { | ||
| final ShardId shardId = request.request().getShardId(); | ||
| // The index uuid is not correct if we restore with a rename | ||
| IndexShardRoutingTable shardRoutingTable = state.routingTable().shardRoutingTable(shardId.getIndexName(), shardId.id()); | ||
| return shardRoutingTable.primaryShardIt(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| public static class PutCcrRestoreSessionResponse extends ActionResponse { | ||
|
|
||
| private String nodeId; | ||
|
Contributor
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. can this be made final? I see that you both implemented a constructor with StreamInput and the readFrom method?
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. I don't think so. Unfortunately you must implement this: on |
||
| private List<StoreFileMetaData> identicalFiles; | ||
| private List<StoreFileMetaData> filesToRecover; | ||
Tim-Brooks marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| PutCcrRestoreSessionResponse() { | ||
| } | ||
|
|
||
| PutCcrRestoreSessionResponse(String nodeId, List<StoreFileMetaData> identicalFiles, List<StoreFileMetaData> filesToRecover) { | ||
| this.nodeId = nodeId; | ||
| this.identicalFiles = identicalFiles; | ||
| this.filesToRecover = filesToRecover; | ||
| } | ||
|
|
||
| PutCcrRestoreSessionResponse(StreamInput streamInput) throws IOException { | ||
| super(streamInput); | ||
| nodeId = streamInput.readString(); | ||
| identicalFiles = streamInput.readList(StoreFileMetaData::new); | ||
| filesToRecover = streamInput.readList(StoreFileMetaData::new); | ||
| } | ||
|
|
||
| @Override | ||
| public void readFrom(StreamInput streamInput) throws IOException { | ||
| super.readFrom(streamInput); | ||
| nodeId = streamInput.readString(); | ||
| identicalFiles = streamInput.readList(StoreFileMetaData::new); | ||
| filesToRecover = streamInput.readList(StoreFileMetaData::new); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput streamOutput) throws IOException { | ||
| super.writeTo(streamOutput); | ||
| streamOutput.writeString(nodeId); | ||
| streamOutput.writeList(identicalFiles); | ||
| streamOutput.writeList(filesToRecover); | ||
| } | ||
|
|
||
| public String getNodeId() { | ||
| return nodeId; | ||
| } | ||
|
|
||
| public List<StoreFileMetaData> getIdenticalFiles() { | ||
| return identicalFiles; | ||
| } | ||
|
|
||
| public List<StoreFileMetaData> getFilesToRecover() { | ||
| return filesToRecover; | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.