Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -205,10 +205,27 @@ public static IndexReshardingMetadata newSplitByMultiple(int shardCount, int mul
return new IndexReshardingMetadata(IndexReshardingState.Split.newSplitByMultiple(shardCount, multiple));
}

/**
* @return the split state of this metadata block, or throw IllegalArgumentException if this metadata doesn't represent a split
*/
public IndexReshardingState.Split getSplit() {
return switch (state) {
case IndexReshardingState.Noop ignored -> throw new IllegalArgumentException("resharding metadata is not a split");
case IndexReshardingState.Split s -> s;
};
}

/**
* @return the number of shards the index has at the start of this operation
*/
public int shardCountBefore() {
return state.shardCountBefore();
}

/**
* @return the number of shards that the index will have when resharding completes
*/
public int shardCountAfter() {
return state.shardCountAfter();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
* concrete subclasses for the operations that are currently defined (which is only split for now).
*/
public abstract sealed class IndexReshardingState implements Writeable, ToXContentFragment {
/**
* @return the number of shards the index has at the start of this operation
*/
public abstract int shardCountBefore();

/**
* @return the number of shards that the index will have when resharding completes
*/
public abstract int shardCountAfter();

// This class exists only so that tests can check that IndexReshardingMetadata can support more than one kind of operation.
// When we have another real operation such as Shrink this can be removed.
public static final class Noop extends IndexReshardingState {
Expand Down Expand Up @@ -64,6 +74,16 @@ public boolean equals(Object other) {
public int hashCode() {
return 0;
}

@Override
public int shardCountBefore() {
return 1;
}

@Override
public int shardCountAfter() {
return 1;
}
}

public static final class Split extends IndexReshardingState {
Expand Down Expand Up @@ -210,13 +230,13 @@ public int hashCode() {
return Objects.hash(Arrays.hashCode(sourceShards), Arrays.hashCode(targetShards));
}

// visible for testing
int oldShardCount() {
@Override
public int shardCountBefore() {
return oldShardCount;
}

// visible for testing
int newShardCount() {
@Override
public int shardCountAfter() {
return newShardCount;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public void testSplit() {
var split = metadata.getSplit();

// starting state is as expected
assert split.oldShardCount() == numShards;
assert split.newShardCount() == numShards * multiple;
assert metadata.shardCountBefore() == numShards;
assert metadata.shardCountAfter() == numShards * multiple;
for (int i = 0; i < numShards; i++) {
assert split.getSourceShardState(i) == IndexReshardingState.Split.SourceShardState.SOURCE;
}
Expand Down