|
37 | 37 | import org.opensearch.Version;
|
38 | 38 | import org.opensearch.core.action.ActionListener;
|
39 | 39 | import org.opensearch.action.StepListener;
|
40 |
| -import org.opensearch.action.admin.cluster.remotestore.restore.RestoreRemoteStoreRequest; |
41 | 40 | import org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest;
|
42 | 41 | import org.opensearch.action.support.IndicesOptions;
|
43 | 42 | import org.opensearch.cluster.ClusterChangedEvent;
|
|
63 | 62 | import org.opensearch.cluster.metadata.MetadataIndexUpgradeService;
|
64 | 63 | import org.opensearch.cluster.metadata.RepositoriesMetadata;
|
65 | 64 | import org.opensearch.cluster.node.DiscoveryNode;
|
66 |
| -import org.opensearch.cluster.routing.IndexShardRoutingTable; |
67 | 65 | import org.opensearch.cluster.routing.RecoverySource;
|
68 | 66 | import org.opensearch.cluster.routing.RecoverySource.SnapshotRecoverySource;
|
69 |
| -import org.opensearch.cluster.routing.RecoverySource.RemoteStoreRecoverySource; |
70 | 67 | import org.opensearch.cluster.routing.RoutingChangesObserver;
|
71 | 68 | import org.opensearch.cluster.routing.RoutingTable;
|
72 | 69 | import org.opensearch.cluster.routing.ShardRouting;
|
@@ -221,107 +218,6 @@ public RestoreService(
|
221 | 218 |
|
222 | 219 | }
|
223 | 220 |
|
224 |
| - /** |
225 |
| - * Restores data from remote store for indices specified in the restore request. |
226 |
| - * |
227 |
| - * @param request restore request |
228 |
| - * @param listener restore listener |
229 |
| - */ |
230 |
| - public void restoreFromRemoteStore(RestoreRemoteStoreRequest request, final ActionListener<RestoreCompletionResponse> listener) { |
231 |
| - clusterService.submitStateUpdateTask("restore[remote_store]", new ClusterStateUpdateTask() { |
232 |
| - final String restoreUUID = UUIDs.randomBase64UUID(); |
233 |
| - RestoreInfo restoreInfo = null; |
234 |
| - |
235 |
| - @Override |
236 |
| - public ClusterState execute(ClusterState currentState) { |
237 |
| - // Updating cluster state |
238 |
| - ClusterState.Builder builder = ClusterState.builder(currentState); |
239 |
| - Metadata.Builder mdBuilder = Metadata.builder(currentState.metadata()); |
240 |
| - ClusterBlocks.Builder blocks = ClusterBlocks.builder().blocks(currentState.blocks()); |
241 |
| - RoutingTable.Builder rtBuilder = RoutingTable.builder(currentState.routingTable()); |
242 |
| - |
243 |
| - List<String> indicesToBeRestored = new ArrayList<>(); |
244 |
| - int totalShards = 0; |
245 |
| - for (String index : request.indices()) { |
246 |
| - IndexMetadata currentIndexMetadata = currentState.metadata().index(index); |
247 |
| - if (currentIndexMetadata == null) { |
248 |
| - // ToDo: Handle index metadata does not exist case. (GitHub #3457) |
249 |
| - logger.warn("Remote store restore is not supported for non-existent index. Skipping: {}", index); |
250 |
| - continue; |
251 |
| - } |
252 |
| - if (currentIndexMetadata.getSettings().getAsBoolean(SETTING_REMOTE_STORE_ENABLED, false)) { |
253 |
| - IndexMetadata updatedIndexMetadata = currentIndexMetadata; |
254 |
| - Map<ShardId, ShardRouting> activeInitializingShards = new HashMap<>(); |
255 |
| - if (request.restoreAllShards()) { |
256 |
| - if (currentIndexMetadata.getState() != IndexMetadata.State.CLOSE) { |
257 |
| - throw new IllegalStateException( |
258 |
| - "cannot restore index [" |
259 |
| - + index |
260 |
| - + "] because an open index " |
261 |
| - + "with same name already exists in the cluster. Close the existing index" |
262 |
| - ); |
263 |
| - } |
264 |
| - updatedIndexMetadata = IndexMetadata.builder(currentIndexMetadata) |
265 |
| - .state(IndexMetadata.State.OPEN) |
266 |
| - .version(1 + currentIndexMetadata.getVersion()) |
267 |
| - .mappingVersion(1 + currentIndexMetadata.getMappingVersion()) |
268 |
| - .settingsVersion(1 + currentIndexMetadata.getSettingsVersion()) |
269 |
| - .aliasesVersion(1 + currentIndexMetadata.getAliasesVersion()) |
270 |
| - .build(); |
271 |
| - } else { |
272 |
| - activeInitializingShards = currentState.routingTable() |
273 |
| - .index(index) |
274 |
| - .shards() |
275 |
| - .values() |
276 |
| - .stream() |
277 |
| - .map(IndexShardRoutingTable::primaryShard) |
278 |
| - .filter(shardRouting -> shardRouting.unassigned() == false) |
279 |
| - .collect(Collectors.toMap(ShardRouting::shardId, Function.identity())); |
280 |
| - } |
281 |
| - |
282 |
| - IndexId indexId = new IndexId(index, updatedIndexMetadata.getIndexUUID()); |
283 |
| - |
284 |
| - RemoteStoreRecoverySource recoverySource = new RemoteStoreRecoverySource( |
285 |
| - restoreUUID, |
286 |
| - updatedIndexMetadata.getCreationVersion(), |
287 |
| - indexId |
288 |
| - ); |
289 |
| - rtBuilder.addAsRemoteStoreRestore(updatedIndexMetadata, recoverySource, activeInitializingShards); |
290 |
| - blocks.updateBlocks(updatedIndexMetadata); |
291 |
| - mdBuilder.put(updatedIndexMetadata, true); |
292 |
| - indicesToBeRestored.add(index); |
293 |
| - totalShards += updatedIndexMetadata.getNumberOfShards(); |
294 |
| - } else { |
295 |
| - logger.warn("Remote store is not enabled for index: {}", index); |
296 |
| - } |
297 |
| - } |
298 |
| - |
299 |
| - restoreInfo = new RestoreInfo("remote_store", indicesToBeRestored, totalShards, totalShards); |
300 |
| - |
301 |
| - RoutingTable rt = rtBuilder.build(); |
302 |
| - ClusterState updatedState = builder.metadata(mdBuilder).blocks(blocks).routingTable(rt).build(); |
303 |
| - return allocationService.reroute(updatedState, "restored from remote store"); |
304 |
| - } |
305 |
| - |
306 |
| - @Override |
307 |
| - public void onFailure(String source, Exception e) { |
308 |
| - logger.warn("failed to restore from remote store", e); |
309 |
| - listener.onFailure(e); |
310 |
| - } |
311 |
| - |
312 |
| - @Override |
313 |
| - public TimeValue timeout() { |
314 |
| - return request.masterNodeTimeout(); |
315 |
| - } |
316 |
| - |
317 |
| - @Override |
318 |
| - public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) { |
319 |
| - listener.onResponse(new RestoreCompletionResponse(restoreUUID, null, restoreInfo)); |
320 |
| - } |
321 |
| - }); |
322 |
| - |
323 |
| - } |
324 |
| - |
325 | 221 | /**
|
326 | 222 | * Restores snapshot specified in the restore request.
|
327 | 223 | *
|
|
0 commit comments