Skip to content

Commit 7904e3e

Browse files
authored
Prevent auto-sharding for data streams in LOOKUP index mode (#131429) (#132079)
* Prevent auto-sharding for data streams in LOOKUP index mode * Update docs/changelog/131429.yaml * Reduce test duplication (cherry picked from commit ea22dff) # Conflicts: # server/src/main/java/org/elasticsearch/action/datastreams/autosharding/DataStreamAutoShardingService.java # server/src/test/java/org/elasticsearch/action/datastreams/autosharding/DataStreamAutoShardingServiceTests.java
1 parent 5f67192 commit 7904e3e

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

docs/changelog/131429.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 131429
2+
summary: Prevent auto-sharding for data streams in LOOKUP index mode
3+
area: Data streams
4+
type: bug
5+
issues: []

server/src/main/java/org/elasticsearch/action/datastreams/autosharding/DataStreamAutoShardingService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.elasticsearch.core.Nullable;
2525
import org.elasticsearch.core.TimeValue;
2626
import org.elasticsearch.index.Index;
27+
import org.elasticsearch.index.IndexMode;
2728

2829
import java.util.List;
2930
import java.util.Objects;
@@ -166,6 +167,11 @@ public AutoShardingResult calculate(ClusterState state, DataStream dataStream, @
166167
return NOT_APPLICABLE_RESULT;
167168
}
168169

170+
if (dataStream.getIndexMode() == IndexMode.LOOKUP) {
171+
logger.debug("Data stream [{}] has indexing mode LOOKUP; auto-sharding is not applicable.", dataStream.getName());
172+
return NOT_APPLICABLE_RESULT;
173+
}
174+
169175
if (writeIndexLoad == null) {
170176
logger.debug(
171177
"Data stream auto sharding service cannot compute the optimal number of shards for data stream [{}] as the write index "

server/src/test/java/org/elasticsearch/action/datastreams/autosharding/DataStreamAutoShardingServiceTests.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,4 +692,38 @@ private IndexWriteLoad getWriteLoad(int numberOfShards, double shardWriteLoad) {
692692
return builder.build();
693693
}
694694

695+
public void testCalculateReturnsNotApplicableForLookupIndexMode() {
696+
Metadata.Builder builder = Metadata.builder();
697+
DataStream dataStream = createLookupModeDataStream(builder);
698+
ClusterState state = createClusterStateWithDataStream(builder);
699+
700+
AutoShardingResult autoShardingResult = service.calculate(state, dataStream, 1.0);
701+
assertThat(autoShardingResult, is(NOT_APPLICABLE_RESULT));
702+
}
703+
704+
public void testCalculateReturnsNotApplicableForLookupIndexModeWithNullWriteLoad() {
705+
Metadata.Builder builder = Metadata.builder();
706+
DataStream dataStream = createLookupModeDataStream(builder);
707+
ClusterState state = createClusterStateWithDataStream(builder);
708+
709+
AutoShardingResult autoShardingResult = service.calculate(state, dataStream, null);
710+
assertThat(autoShardingResult, is(NOT_APPLICABLE_RESULT));
711+
}
712+
713+
private DataStream createLookupModeDataStream(Metadata.Builder builder) {
714+
DataStream dataStream = DataStream.builder(dataStreamName, List.of(new Index("test-index", randomUUID())))
715+
.setGeneration(1)
716+
.setIndexMode(IndexMode.LOOKUP)
717+
.build();
718+
builder.put(dataStream);
719+
return dataStream;
720+
}
721+
722+
private ClusterState createClusterStateWithDataStream(Metadata.Builder builder) {
723+
return ClusterState.builder(ClusterName.DEFAULT)
724+
.nodes(DiscoveryNodes.builder().add(DiscoveryNodeUtils.create("n1")))
725+
.metadata(builder.build())
726+
.build();
727+
}
728+
695729
}

0 commit comments

Comments
 (0)