|
19 | 19 |
|
20 | 20 | package org.elasticsearch.cluster.routing;
|
21 | 21 |
|
| 22 | +import com.carrotsearch.hppc.IntSet; |
22 | 23 | import com.carrotsearch.hppc.cursors.IntCursor;
|
23 | 24 | import com.carrotsearch.hppc.cursors.IntObjectCursor;
|
24 | 25 | import com.google.common.collect.ImmutableList;
|
@@ -381,28 +382,33 @@ public Builder initializeAsRecovery(IndexMetaData indexMetaData) {
|
381 | 382 | /**
|
382 | 383 | * Initializes a new empty index, to be restored from a snapshot
|
383 | 384 | */
|
384 |
| - public Builder initializeAsNewRestore(IndexMetaData indexMetaData, RestoreSource restoreSource) { |
385 |
| - return initializeAsRestore(indexMetaData, restoreSource, true); |
| 385 | + public Builder initializeAsNewRestore(IndexMetaData indexMetaData, RestoreSource restoreSource, IntSet ignoreShards) { |
| 386 | + return initializeAsRestore(indexMetaData, restoreSource, ignoreShards, true); |
386 | 387 | }
|
387 | 388 |
|
388 | 389 | /**
|
389 | 390 | * Initializes an existing index, to be restored from a snapshot
|
390 | 391 | */
|
391 | 392 | public Builder initializeAsRestore(IndexMetaData indexMetaData, RestoreSource restoreSource) {
|
392 |
| - return initializeAsRestore(indexMetaData, restoreSource, false); |
| 393 | + return initializeAsRestore(indexMetaData, restoreSource, null, false); |
393 | 394 | }
|
394 | 395 |
|
395 | 396 | /**
|
396 | 397 | * Initializes an index, to be restored from snapshot
|
397 | 398 | */
|
398 |
| - private Builder initializeAsRestore(IndexMetaData indexMetaData, RestoreSource restoreSource, boolean asNew) { |
| 399 | + private Builder initializeAsRestore(IndexMetaData indexMetaData, RestoreSource restoreSource, IntSet ignoreShards, boolean asNew) { |
399 | 400 | if (!shards.isEmpty()) {
|
400 | 401 | throw new ElasticsearchIllegalStateException("trying to initialize an index with fresh shards, but already has shards created");
|
401 | 402 | }
|
402 | 403 | for (int shardId = 0; shardId < indexMetaData.numberOfShards(); shardId++) {
|
403 | 404 | IndexShardRoutingTable.Builder indexShardRoutingBuilder = new IndexShardRoutingTable.Builder(new ShardId(indexMetaData.index(), shardId), asNew ? false : true);
|
404 | 405 | for (int i = 0; i <= indexMetaData.numberOfReplicas(); i++) {
|
405 |
| - indexShardRoutingBuilder.addShard(new ImmutableShardRouting(index, shardId, null, null, i == 0 ? restoreSource : null, i == 0, ShardRoutingState.UNASSIGNED, 0)); |
| 406 | + if (asNew && ignoreShards.contains(shardId)) { |
| 407 | + // This shards wasn't completely snapshotted - restore it as new shard |
| 408 | + indexShardRoutingBuilder.addShard(new ImmutableShardRouting(index, shardId, null, i == 0, ShardRoutingState.UNASSIGNED, 0)); |
| 409 | + } else { |
| 410 | + indexShardRoutingBuilder.addShard(new ImmutableShardRouting(index, shardId, null, null, i == 0 ? restoreSource : null, i == 0, ShardRoutingState.UNASSIGNED, 0)); |
| 411 | + } |
406 | 412 | }
|
407 | 413 | shards.put(shardId, indexShardRoutingBuilder.build());
|
408 | 414 | }
|
|
0 commit comments