Skip to content

Commit 7e18c51

Browse files
committed
Address feedback
1 parent 42dd895 commit 7e18c51

File tree

8 files changed

+17
-21
lines changed

8 files changed

+17
-21
lines changed

server/src/main/java/org/elasticsearch/cluster/routing/ExpectedShardSizeEstimator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static boolean shouldReserveSpaceForInitializingShard(ShardRouting shard,
5858
// shrink/split/clone operation is going to clone existing locally placed shards using file system hard links
5959
// so no additional space is going to be used until future merges
6060
case LOCAL_SHARDS -> false;
61-
case RESHARD_SPLIT_TARGET -> false;
61+
case RESHARD_SPLIT -> false;
6262
};
6363
}
6464

server/src/main/java/org/elasticsearch/cluster/routing/RecoverySource.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* - {@link PeerRecoverySource} recovery from a primary on another node
3333
* - {@link SnapshotRecoverySource} recovery from a snapshot
3434
* - {@link LocalShardsRecoverySource} recovery from other shards of another index on the same node
35-
* - {@link ReshardSplitTargetRecoverySource} recovery of a shard that is created as a result of a resharding split
35+
* - {@link ReshardSplitRecoverySource} recovery of a shard that is created as a result of a resharding split
3636
*/
3737
public abstract class RecoverySource implements Writeable, ToXContentObject {
3838

@@ -52,16 +52,14 @@ public void addAdditionalFields(XContentBuilder builder, ToXContent.Params param
5252
}
5353

5454
public static RecoverySource readFrom(StreamInput in) throws IOException {
55-
// TODO is transport version check needed?
56-
5755
Type type = Type.values()[in.readByte()];
5856
return switch (type) {
5957
case EMPTY_STORE -> EmptyStoreRecoverySource.INSTANCE;
6058
case EXISTING_STORE -> ExistingStoreRecoverySource.read(in);
6159
case PEER -> PeerRecoverySource.INSTANCE;
6260
case SNAPSHOT -> new SnapshotRecoverySource(in);
6361
case LOCAL_SHARDS -> LocalShardsRecoverySource.INSTANCE;
64-
case RESHARD_SPLIT_TARGET -> new ReshardSplitTargetRecoverySource(in);
62+
case RESHARD_SPLIT -> new ReshardSplitRecoverySource(in);
6563
};
6664
}
6765

@@ -84,7 +82,7 @@ public enum Type {
8482
PEER,
8583
SNAPSHOT,
8684
LOCAL_SHARDS,
87-
RESHARD_SPLIT_TARGET
85+
RESHARD_SPLIT
8886
}
8987

9088
public abstract Type getType();
@@ -330,20 +328,20 @@ public boolean expectEmptyRetentionLeases() {
330328
* Recovery of a shard that is created as a result of a resharding split.
331329
* Not to be confused with _split API.
332330
*/
333-
public static class ReshardSplitTargetRecoverySource extends RecoverySource {
331+
public static class ReshardSplitRecoverySource extends RecoverySource {
334332
private final ShardId sourceShardId;
335333

336-
public ReshardSplitTargetRecoverySource(ShardId sourceShardId) {
334+
public ReshardSplitRecoverySource(ShardId sourceShardId) {
337335
this.sourceShardId = sourceShardId;
338336
}
339337

340-
ReshardSplitTargetRecoverySource(StreamInput in) throws IOException {
338+
ReshardSplitRecoverySource(StreamInput in) throws IOException {
341339
sourceShardId = new ShardId(in);
342340
}
343341

344342
@Override
345343
public Type getType() {
346-
return Type.RESHARD_SPLIT_TARGET;
344+
return Type.RESHARD_SPLIT;
347345
}
348346

349347
public ShardId getSourceShardId() {

server/src/main/java/org/elasticsearch/index/shard/IndexShard.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3501,7 +3501,7 @@ public void startRecovery(
35013501
// }
35023502
assert recoveryState.getRecoverySource().equals(shardRouting.recoverySource());
35033503
switch (recoveryState.getRecoverySource().getType()) {
3504-
case EMPTY_STORE, EXISTING_STORE, RESHARD_SPLIT_TARGET -> executeRecovery(
3504+
case EMPTY_STORE, EXISTING_STORE, RESHARD_SPLIT -> executeRecovery(
35053505
"from store",
35063506
recoveryState,
35073507
recoveryListener,

server/src/main/java/org/elasticsearch/index/shard/StoreRecovery.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ void recoverFromStore(final IndexShard indexShard, ActionListener<Boolean> liste
9191
RecoverySource.Type recoveryType = indexShard.recoveryState().getRecoverySource().getType();
9292
assert recoveryType == RecoverySource.Type.EMPTY_STORE
9393
|| recoveryType == RecoverySource.Type.EXISTING_STORE
94-
|| recoveryType == RecoverySource.Type.RESHARD_SPLIT_TARGET
95-
: "expected one of store recovery types but was: " + recoveryType;
94+
|| recoveryType == RecoverySource.Type.RESHARD_SPLIT : "expected one of store recovery types but was: " + recoveryType;
9695
logger.debug("starting recovery from store ...");
9796
final var recoveryListener = recoveryListener(indexShard, listener);
9897
try {

server/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,9 @@ private void createShard(ShardRouting shardRouting, ClusterState state) {
702702
logger.trace("ignoring initializing shard {} - no source node can be found.", shardId);
703703
return;
704704
}
705-
} else if (shardRouting.recoverySource().getType() == Type.RESHARD_SPLIT_TARGET) {
706-
ShardId sourceShardId = ((RecoverySource.ReshardSplitTargetRecoverySource) shardRouting.recoverySource())
707-
.getSourceShardId();
708-
sourceNode = findSourceNodeForSplitTargetRecovery(state.routingTable(project.id()), state.nodes(), sourceShardId);
705+
} else if (shardRouting.recoverySource() instanceof RecoverySource.ReshardSplitRecoverySource reshardSplitRecoverySource) {
706+
ShardId sourceShardId = reshardSplitRecoverySource.getSourceShardId();
707+
sourceNode = findSourceNodeForReshardSplitRecovery(state.routingTable(project.id()), state.nodes(), sourceShardId);
709708
if (sourceNode == null) {
710709
logger.trace("ignoring initializing reshard target shard {} - no source node can be found.", shardId);
711710
return;
@@ -997,7 +996,7 @@ private static DiscoveryNode findSourceNodeForPeerRecovery(RoutingTable routingT
997996
return sourceNode;
998997
}
999998

1000-
private static DiscoveryNode findSourceNodeForSplitTargetRecovery(
999+
private static DiscoveryNode findSourceNodeForReshardSplitRecovery(
10011000
RoutingTable routingTable,
10021001
DiscoveryNodes nodes,
10031002
ShardId sourceShardId

server/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public RecoveryState(ShardRouting shardRouting, DiscoveryNode targetNode, @Nulla
112112
assert shardRouting.initializing() : "only allow initializing shard routing to be recovered: " + shardRouting;
113113
assert shardRouting.recoverySource().getType() != RecoverySource.Type.PEER || sourceNode != null
114114
: "peer recovery requires source node but it is null";
115-
assert shardRouting.recoverySource().getType() != RecoverySource.Type.RESHARD_SPLIT_TARGET || sourceNode != null
115+
assert shardRouting.recoverySource().getType() != RecoverySource.Type.RESHARD_SPLIT || sourceNode != null
116116
: "reshard split target recovery requires source node but it is null";
117117
timer.start();
118118
}

server/src/test/java/org/elasticsearch/cluster/routing/RecoverySourceTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void testRecoverySourceTypeOrder() {
3434
assertEquals(RecoverySource.Type.PEER.ordinal(), 2);
3535
assertEquals(RecoverySource.Type.SNAPSHOT.ordinal(), 3);
3636
assertEquals(RecoverySource.Type.LOCAL_SHARDS.ordinal(), 4);
37-
assertEquals(RecoverySource.Type.RESHARD_SPLIT_TARGET.ordinal(), 5);
37+
assertEquals(RecoverySource.Type.RESHARD_SPLIT.ordinal(), 5);
3838
// check exhaustiveness
3939
for (RecoverySource.Type type : RecoverySource.Type.values()) {
4040
assertThat(type.ordinal(), greaterThanOrEqualTo(0));

test/framework/src/main/java/org/elasticsearch/cluster/routing/TestShardRouting.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public static RecoverySource buildRecoverySource() {
276276
IndexVersion.current(),
277277
new IndexId("some_index", randomUUID())
278278
),
279-
new RecoverySource.ReshardSplitTargetRecoverySource(new ShardId("some_index", randomUUID(), randomIntBetween(0, 1000)))
279+
new RecoverySource.ReshardSplitRecoverySource(new ShardId("some_index", randomUUID(), randomIntBetween(0, 1000)))
280280
);
281281
}
282282
}

0 commit comments

Comments
 (0)