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
5 changes: 5 additions & 0 deletions docs/changelog/131429.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 131429
summary: Prevent auto-sharding for data streams in LOOKUP index mode
area: Data streams
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexMode;
import org.elasticsearch.index.shard.IndexingStats;

import java.util.Arrays;
Expand Down Expand Up @@ -371,6 +372,7 @@ public String toString() {
* there'll be no new auto sharding event)
*/
public AutoShardingResult calculate(ProjectState state, DataStream dataStream, @Nullable IndexStats writeIndexStats) {

if (isAutoShardingEnabled == false) {
logger.debug("Data stream auto-sharding service is not enabled.");
return NOT_APPLICABLE_RESULT;
Expand All @@ -385,6 +387,11 @@ public AutoShardingResult calculate(ProjectState state, DataStream dataStream, @
return NOT_APPLICABLE_RESULT;
}

if (dataStream.getIndexMode() == IndexMode.LOOKUP) {
logger.debug("Data stream [{}] has indexing mode LOOKUP; auto-sharding is not applicable.", dataStream.getName());
return NOT_APPLICABLE_RESULT;
}

if (writeIndexStats == null) {
logger.debug(
"Data stream auto-sharding service cannot compute the optimal number of shards for data stream [{}] as the write index "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1343,4 +1343,46 @@ private static Decision.Inputs createDecisionInputsForPeriodLoggerTests(int writ
3
);
}

public void testCalculateReturnsNotApplicableForLookupIndexMode() {
var projectId = randomProjectIdOrDefault();
ProjectMetadata.Builder builder = ProjectMetadata.builder(projectId);
DataStream dataStream = createLookupModeDataStream(builder);
ClusterState state = createClusterStateWithDataStream(builder);

AutoShardingResult autoShardingResult = service.calculate(
state.projectState(projectId),
dataStream,
createIndexStats(1, 1.0, 1.0, 1.0)
);
assertThat(autoShardingResult, is(NOT_APPLICABLE_RESULT));
assertThat(decisionsLogged, hasSize(0));
}

public void testCalculateReturnsNotApplicableForLookupIndexModeWithNullStats() {
var projectId = randomProjectIdOrDefault();
ProjectMetadata.Builder builder = ProjectMetadata.builder(projectId);
DataStream dataStream = createLookupModeDataStream(builder);
ClusterState state = createClusterStateWithDataStream(builder);

AutoShardingResult autoShardingResult = service.calculate(state.projectState(projectId), dataStream, null);
assertThat(autoShardingResult, is(NOT_APPLICABLE_RESULT));
assertThat(decisionsLogged, hasSize(0));
}

private DataStream createLookupModeDataStream(ProjectMetadata.Builder builder) {
DataStream dataStream = DataStream.builder(dataStreamName, List.of(new Index("test-index", randomUUID())))
.setGeneration(1)
.setIndexMode(IndexMode.LOOKUP)
.build();
builder.put(dataStream);
return dataStream;
}

private ClusterState createClusterStateWithDataStream(ProjectMetadata.Builder builder) {
return ClusterState.builder(ClusterName.DEFAULT)
.nodes(DiscoveryNodes.builder().add(DiscoveryNodeUtils.create("n1")))
.putProjectMetadata(builder.build())
.build();
}
}
Loading