Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.xcontent.ConstructingObjectParser;
import org.elasticsearch.xcontent.ParseField;
Expand Down Expand Up @@ -207,15 +208,22 @@ public static IndexReshardingMetadata newSplitByMultiple(int shardCount, int mul
return new IndexReshardingMetadata(IndexReshardingState.Split.newSplitByMultiple(shardCount, multiple));
}

public IndexReshardingMetadata transitionSplitTargetToHandoff(ShardId shardId) {
public static boolean isSplitTarget(ShardId shardId, @Nullable IndexReshardingMetadata reshardingMetadata) {
return reshardingMetadata != null && reshardingMetadata.isSplit() && reshardingMetadata.getSplit().isTargetShard(shardId.id());
}

public IndexReshardingMetadata transitionSplitTargetToNewState(
ShardId shardId,
IndexReshardingState.Split.TargetShardState newTargetState
) {
assert state instanceof IndexReshardingState.Split;
IndexReshardingState.Split splitState = (IndexReshardingState.Split) state;
IndexReshardingState.Split.TargetShardState[] newTargets = Arrays.copyOf(
splitState.targetShards(),
splitState.targetShards().length
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should make a builder to centralize the logic for creating a new state instead of mutating the existing one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you had already created one that I wasn't using. I just switched to that.

int i = shardId.getId() - state.shardCountBefore();
newTargets[i] = IndexReshardingState.Split.TargetShardState.HANDOFF;
newTargets[i] = newTargetState;
return new IndexReshardingMetadata(new IndexReshardingState.Split(splitState.sourceShards(), newTargets));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ public boolean inProgress() {
return false;
}

public boolean allTargetsSplit() {
return Arrays.stream(targetShards).allMatch(target -> target == TargetShardState.SPLIT);
}

/**
* Check whether all target shards for the given source shard are done.
* @param shardNum a source shard index greater than or equal to 0 and less than the original shard count
Expand Down