Skip to content

Commit d18958f

Browse files
authored
Merge branch 'main' into unmute-test-87695d2
2 parents 1a61717 + 99ff870 commit d18958f

File tree

24 files changed

+290
-39
lines changed

24 files changed

+290
-39
lines changed

muted-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,9 @@ tests:
528528
- class: org.elasticsearch.cluster.ClusterInfoServiceIT
529529
method: testMaxQueueLatenciesInClusterInfo
530530
issue: https://github.com/elastic/elasticsearch/issues/134088
531+
- class: org.elasticsearch.xpack.esql.ccq.MultiClusterSpecIT
532+
method: test {csv-spec:fork.ForkBeforeStats}
533+
issue: https://github.com/elastic/elasticsearch/issues/134100
531534

532535
# Examples:
533536
#

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ static TransportVersion def(int id) {
130130
public static final TransportVersion ESQL_SKIP_ES_INDEX_SERIALIZATION = def(8_827_0_00);
131131
public static final TransportVersion ADD_INDEX_BLOCK_TWO_PHASE = def(8_828_0_00);
132132
public static final TransportVersion RESOLVE_CLUSTER_NO_INDEX_EXPRESSION = def(8_829_0_00);
133+
public static final TransportVersion ML_ROLLOVER_LEGACY_INDICES = def(8_830_0_00);
133134
public static final TransportVersion ADD_INCLUDE_FAILURE_INDICES_OPTION = def(8_831_0_00);
134135
public static final TransportVersion ESQL_RESPONSE_PARTIAL = def(8_832_0_00);
135136
public static final TransportVersion RANK_DOC_OPTIONAL_METADATA_FOR_EXPLAIN = def(8_833_0_00);
@@ -146,7 +147,6 @@ static TransportVersion def(int id) {
146147
public static final TransportVersion INITIAL_ELASTICSEARCH_8_18_2 = def(8_840_0_04);
147148
public static final TransportVersion INITIAL_ELASTICSEARCH_8_18_3 = def(8_840_0_05);
148149
public static final TransportVersion INITIAL_ELASTICSEARCH_8_18_4 = def(8_840_0_06);
149-
public static final TransportVersion INITIAL_ELASTICSEARCH_8_18_6 = def(8_840_0_08);
150150
public static final TransportVersion INITIAL_ELASTICSEARCH_8_18_7 = def(8_840_0_09);
151151
public static final TransportVersion INITIAL_ELASTICSEARCH_8_19 = def(8_841_0_00);
152152
public static final TransportVersion COHERE_BIT_EMBEDDING_TYPE_SUPPORT_ADDED_BACKPORT_8_X = def(8_841_0_01);
@@ -210,17 +210,16 @@ static TransportVersion def(int id) {
210210
public static final TransportVersion ML_INFERENCE_COHERE_API_VERSION_8_19 = def(8_841_0_60);
211211
public static final TransportVersion ESQL_DOCUMENTS_FOUND_AND_VALUES_LOADED_8_19 = def(8_841_0_61);
212212
public static final TransportVersion ESQL_PROFILE_INCLUDE_PLAN_8_19 = def(8_841_0_62);
213+
public static final TransportVersion ESQL_SPLIT_ON_BIG_VALUES_8_19 = def(8_841_0_63);
213214
public static final TransportVersion ESQL_FIXED_INDEX_LIKE_8_19 = def(8_841_0_64);
214215
public static final TransportVersion INITIAL_ELASTICSEARCH_8_19_1 = def(8_841_0_65);
215216
public static final TransportVersion INITIAL_ELASTICSEARCH_8_19_2 = def(8_841_0_66);
216-
public static final TransportVersion INITIAL_ELASTICSEARCH_8_19_3 = def(8_841_0_67);
217217
public static final TransportVersion INITIAL_ELASTICSEARCH_8_19_4 = def(8_841_0_68);
218218
public static final TransportVersion V_9_0_0 = def(9_000_0_09);
219219
public static final TransportVersion INITIAL_ELASTICSEARCH_9_0_1 = def(9_000_0_10);
220220
public static final TransportVersion INITIAL_ELASTICSEARCH_9_0_2 = def(9_000_0_11);
221221
public static final TransportVersion INITIAL_ELASTICSEARCH_9_0_3 = def(9_000_0_12);
222222
public static final TransportVersion INITIAL_ELASTICSEARCH_9_0_4 = def(9_000_0_13);
223-
public static final TransportVersion INITIAL_ELASTICSEARCH_9_0_6 = def(9_000_0_15);
224223
public static final TransportVersion INITIAL_ELASTICSEARCH_9_0_7 = def(9_000_0_16);
225224
public static final TransportVersion COHERE_BIT_EMBEDDING_TYPE_SUPPORT_ADDED = def(9_001_0_00);
226225
public static final TransportVersion REMOVE_SNAPSHOT_FAILURES = def(9_002_0_00);
@@ -333,15 +332,16 @@ static TransportVersion def(int id) {
333332
public static final TransportVersion ML_INFERENCE_COHERE_API_VERSION = def(9_110_0_00);
334333
public static final TransportVersion ESQL_PROFILE_INCLUDE_PLAN = def(9_111_0_00);
335334
public static final TransportVersion MAPPINGS_IN_DATA_STREAMS = def(9_112_0_00);
335+
public static final TransportVersion ESQL_SPLIT_ON_BIG_VALUES_9_1 = def(9_112_0_01);
336336
public static final TransportVersion ESQL_FIXED_INDEX_LIKE_9_1 = def(9_112_0_02);
337337
public static final TransportVersion ESQL_SAMPLE_OPERATOR_STATUS_9_1 = def(9_112_0_03);
338338
public static final TransportVersion INITIAL_ELASTICSEARCH_9_1_1 = def(9_112_0_04);
339339
public static final TransportVersion INITIAL_ELASTICSEARCH_9_1_2 = def(9_112_0_05);
340-
public static final TransportVersion INITIAL_ELASTICSEARCH_9_1_3 = def(9_112_0_06);
341340
public static final TransportVersion INITIAL_ELASTICSEARCH_9_1_4 = def(9_112_0_07);
342341
public static final TransportVersion PROJECT_STATE_REGISTRY_RECORDS_DELETIONS = def(9_113_0_00);
343342
public static final TransportVersion ESQL_SERIALIZE_TIMESERIES_FIELD_TYPE = def(9_114_0_00);
344343
public static final TransportVersion ML_INFERENCE_IBM_WATSONX_COMPLETION_ADDED = def(9_115_0_00);
344+
public static final TransportVersion ESQL_SPLIT_ON_BIG_VALUES = def(9_116_0_00);
345345
public static final TransportVersion ESQL_LOCAL_RELATION_WITH_NEW_BLOCKS = def(9_117_0_00);
346346
public static final TransportVersion ML_INFERENCE_CUSTOM_SERVICE_EMBEDDING_TYPE = def(9_118_0_00);
347347
public static final TransportVersion ESQL_FIXED_INDEX_LIKE = def(9_119_0_00);

server/src/main/java/org/elasticsearch/cluster/ClusterModule.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import org.elasticsearch.cluster.routing.allocation.AllocationStatsService;
3838
import org.elasticsearch.cluster.routing.allocation.ExistingShardsAllocator;
3939
import org.elasticsearch.cluster.routing.allocation.NodeAllocationStatsAndWeightsCalculator;
40+
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
41+
import org.elasticsearch.cluster.routing.allocation.ShardAllocationDecision;
4042
import org.elasticsearch.cluster.routing.allocation.WriteLoadForecaster;
4143
import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
4244
import org.elasticsearch.cluster.routing.allocation.allocator.BalancerSettings;
@@ -107,6 +109,8 @@
107109
import java.util.Objects;
108110
import java.util.function.Supplier;
109111

112+
import static org.elasticsearch.cluster.routing.allocation.allocator.DesiredBalanceShardsAllocator.ShardAllocationExplainer;
113+
110114
/**
111115
* Configures classes and services that affect the entire cluster.
112116
*/
@@ -171,7 +175,8 @@ public ClusterModule(
171175
this::reconcile,
172176
writeLoadForecaster,
173177
telemetryProvider,
174-
nodeAllocationStatsAndWeightsCalculator
178+
nodeAllocationStatsAndWeightsCalculator,
179+
this::explainShardAllocation
175180
);
176181
this.clusterService = clusterService;
177182
this.indexNameExpressionResolver = new IndexNameExpressionResolver(threadPool.getThreadContext(), systemIndices, projectResolver);
@@ -237,6 +242,10 @@ private ClusterState reconcile(ClusterState clusterState, RerouteStrategy rerout
237242
return allocationService.executeWithRoutingAllocation(clusterState, "reconcile-desired-balance", rerouteStrategy);
238243
}
239244

245+
private ShardAllocationDecision explainShardAllocation(ShardRouting shardRouting, RoutingAllocation allocation) {
246+
return allocationService.explainShardAllocation(shardRouting, allocation);
247+
}
248+
240249
public static List<Entry> getNamedWriteables() {
241250
List<Entry> entries = new ArrayList<>();
242251
// Cluster State
@@ -489,7 +498,8 @@ private static ShardsAllocator createShardsAllocator(
489498
DesiredBalanceReconcilerAction reconciler,
490499
WriteLoadForecaster writeLoadForecaster,
491500
TelemetryProvider telemetryProvider,
492-
NodeAllocationStatsAndWeightsCalculator nodeAllocationStatsAndWeightsCalculator
501+
NodeAllocationStatsAndWeightsCalculator nodeAllocationStatsAndWeightsCalculator,
502+
ShardAllocationExplainer shardAllocationExplainer
493503
) {
494504
Map<String, Supplier<ShardsAllocator>> allocators = new HashMap<>();
495505
allocators.put(
@@ -505,7 +515,8 @@ private static ShardsAllocator createShardsAllocator(
505515
clusterService,
506516
reconciler,
507517
telemetryProvider,
508-
nodeAllocationStatsAndWeightsCalculator
518+
nodeAllocationStatsAndWeightsCalculator,
519+
shardAllocationExplainer
509520
)
510521
);
511522

server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceComputer.java

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@
1717
import org.elasticsearch.cluster.routing.ShardRouting;
1818
import org.elasticsearch.cluster.routing.UnassignedInfo;
1919
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
20+
import org.elasticsearch.cluster.routing.allocation.ShardAllocationDecision;
21+
import org.elasticsearch.cluster.routing.allocation.allocator.DesiredBalanceShardsAllocator.ShardAllocationExplainer;
2022
import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand;
2123
import org.elasticsearch.cluster.routing.allocation.decider.Decision;
2224
import org.elasticsearch.common.metrics.MeanMetric;
2325
import org.elasticsearch.common.settings.ClusterSettings;
2426
import org.elasticsearch.common.settings.Setting;
2527
import org.elasticsearch.common.time.TimeProvider;
2628
import org.elasticsearch.common.util.Maps;
29+
import org.elasticsearch.common.xcontent.ChunkedToXContentHelper;
2730
import org.elasticsearch.core.Strings;
2831
import org.elasticsearch.core.TimeValue;
2932
import org.elasticsearch.index.shard.ShardId;
@@ -39,6 +42,7 @@
3942
import java.util.TreeMap;
4043
import java.util.TreeSet;
4144
import java.util.function.Predicate;
45+
import java.util.stream.Stream;
4246

4347
import static java.util.stream.Collectors.toUnmodifiableSet;
4448

@@ -48,9 +52,13 @@
4852
public class DesiredBalanceComputer {
4953

5054
private static final Logger logger = LogManager.getLogger(DesiredBalanceComputer.class);
55+
private static final Logger allocationExplainLogger = LogManager.getLogger(
56+
DesiredBalanceComputer.class.getCanonicalName() + ".allocation_explain"
57+
);
5158

5259
private final ShardsAllocator delegateAllocator;
5360
private final TimeProvider timeProvider;
61+
private final ShardAllocationExplainer shardAllocationExplainer;
5462

5563
// stats
5664
protected final MeanMetric iterations = new MeanMetric();
@@ -77,10 +85,17 @@ public class DesiredBalanceComputer {
7785
private long lastConvergedTimeMillis;
7886
private long lastNotConvergedLogMessageTimeMillis;
7987
private Level convergenceLogMsgLevel;
88+
private ShardRouting lastTrackedUnassignedShard;
8089

81-
public DesiredBalanceComputer(ClusterSettings clusterSettings, TimeProvider timeProvider, ShardsAllocator delegateAllocator) {
90+
public DesiredBalanceComputer(
91+
ClusterSettings clusterSettings,
92+
TimeProvider timeProvider,
93+
ShardsAllocator delegateAllocator,
94+
ShardAllocationExplainer shardAllocationExplainer
95+
) {
8296
this.delegateAllocator = delegateAllocator;
8397
this.timeProvider = timeProvider;
98+
this.shardAllocationExplainer = shardAllocationExplainer;
8499
this.numComputeCallsSinceLastConverged = 0;
85100
this.numIterationsSinceLastConverged = 0;
86101
this.lastConvergedTimeMillis = timeProvider.relativeTimeInMillis();
@@ -462,10 +477,59 @@ public DesiredBalance compute(
462477
);
463478
}
464479

480+
maybeLogAllocationExplainForUnassigned(finishReason, routingNodes, routingAllocation);
481+
465482
long lastConvergedIndex = hasChanges ? previousDesiredBalance.lastConvergedIndex() : desiredBalanceInput.index();
466483
return new DesiredBalance(lastConvergedIndex, assignments, routingNodes.getBalanceWeightStatsPerNode(), finishReason);
467484
}
468485

486+
private void maybeLogAllocationExplainForUnassigned(
487+
DesiredBalance.ComputationFinishReason finishReason,
488+
RoutingNodes routingNodes,
489+
RoutingAllocation routingAllocation
490+
) {
491+
if (allocationExplainLogger.isDebugEnabled()) {
492+
if (lastTrackedUnassignedShard != null) {
493+
if (Stream.concat(routingNodes.unassigned().stream(), routingNodes.unassigned().ignored().stream())
494+
.noneMatch(shardRouting -> shardRouting.equals(lastTrackedUnassignedShard))) {
495+
allocationExplainLogger.debug("previously tracked unassigned shard [{}] is now assigned", lastTrackedUnassignedShard);
496+
lastTrackedUnassignedShard = null;
497+
} else {
498+
return; // The last tracked unassigned shard is still unassigned, keep tracking it
499+
}
500+
}
501+
502+
assert lastTrackedUnassignedShard == null : "unexpected non-null lastTrackedUnassignedShard " + lastTrackedUnassignedShard;
503+
if (routingNodes.hasUnassignedShards() && finishReason == DesiredBalance.ComputationFinishReason.CONVERGED) {
504+
final Predicate<ShardRouting> predicate = routingNodes.hasUnassignedPrimaries() ? ShardRouting::primary : shard -> true;
505+
lastTrackedUnassignedShard = Stream.concat(routingNodes.unassigned().stream(), routingNodes.unassigned().ignored().stream())
506+
.filter(predicate)
507+
.findFirst()
508+
.orElseThrow();
509+
510+
final var originalDebugMode = routingAllocation.getDebugMode();
511+
routingAllocation.setDebugMode(RoutingAllocation.DebugMode.EXCLUDE_YES_DECISIONS);
512+
final ShardAllocationDecision shardAllocationDecision;
513+
try {
514+
shardAllocationDecision = shardAllocationExplainer.explain(lastTrackedUnassignedShard, routingAllocation);
515+
} finally {
516+
routingAllocation.setDebugMode(originalDebugMode);
517+
}
518+
allocationExplainLogger.debug(
519+
"unassigned shard [{}] with allocation decision {}",
520+
lastTrackedUnassignedShard,
521+
org.elasticsearch.common.Strings.toString(
522+
p -> ChunkedToXContentHelper.object("node_allocation_decision", shardAllocationDecision.toXContentChunked(p))
523+
)
524+
);
525+
}
526+
} else {
527+
if (lastTrackedUnassignedShard != null) {
528+
lastTrackedUnassignedShard = null;
529+
}
530+
}
531+
}
532+
469533
// visible for testing
470534
boolean hasEnoughIterations(int currentIteration) {
471535
return true;

server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceShardsAllocator.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,26 @@ public interface DesiredBalanceReconcilerAction {
109109
ClusterState apply(ClusterState clusterState, RerouteStrategy rerouteStrategy);
110110
}
111111

112+
@FunctionalInterface
113+
public interface ShardAllocationExplainer {
114+
ShardAllocationDecision explain(ShardRouting shard, RoutingAllocation allocation);
115+
}
116+
112117
public DesiredBalanceShardsAllocator(
113118
ClusterSettings clusterSettings,
114119
ShardsAllocator delegateAllocator,
115120
ThreadPool threadPool,
116121
ClusterService clusterService,
117122
DesiredBalanceReconcilerAction reconciler,
118123
TelemetryProvider telemetryProvider,
119-
NodeAllocationStatsAndWeightsCalculator nodeAllocationStatsAndWeightsCalculator
124+
NodeAllocationStatsAndWeightsCalculator nodeAllocationStatsAndWeightsCalculator,
125+
ShardAllocationExplainer shardAllocationExplainer
120126
) {
121127
this(
122128
delegateAllocator,
123129
threadPool,
124130
clusterService,
125-
new DesiredBalanceComputer(clusterSettings, threadPool, delegateAllocator),
131+
new DesiredBalanceComputer(clusterSettings, threadPool, delegateAllocator, shardAllocationExplainer),
126132
reconciler,
127133
telemetryProvider,
128134
nodeAllocationStatsAndWeightsCalculator

server/src/main/resources/transport/definitions/referable/esql_split_on_big_values.csv

Lines changed: 0 additions & 1 deletion
This file was deleted.

server/src/main/resources/transport/definitions/referable/ml_rollover_legacy_indices.csv

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8840008
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8841067
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9000015

0 commit comments

Comments
 (0)