Skip to content

Commit 4e05862

Browse files
authored
Merge branch 'main' into tsdb/ts-telemetry
2 parents 83236aa + f21c61c commit 4e05862

File tree

43 files changed

+610
-118
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+610
-118
lines changed

docs/changelog/135484.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 135484
2+
summary: Add origin to client in SLM task
3+
area: ILM+SLM
4+
type: bug
5+
issues: []

modules/data-streams/src/main/java/org/elasticsearch/datastreams/options/action/GetDataStreamOptionsAction.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
package org.elasticsearch.datastreams.options.action;
1010

11-
import org.elasticsearch.TransportVersions;
11+
import org.elasticsearch.TransportVersion;
1212
import org.elasticsearch.action.ActionRequestValidationException;
1313
import org.elasticsearch.action.ActionResponse;
1414
import org.elasticsearch.action.ActionType;
@@ -50,6 +50,10 @@ private GetDataStreamOptionsAction() {/* no instances */}
5050

5151
public static class Request extends LocalClusterStateRequest implements IndicesRequest.Replaceable {
5252

53+
private static final TransportVersion DATA_STREAM_OPTIONS_API_REMOVE_INCLUDE_DEFAULTS = TransportVersion.fromName(
54+
"data_stream_options_api_remove_include_defaults"
55+
);
56+
5357
private String[] names;
5458
private IndicesOptions indicesOptions = IndicesOptions.builder()
5559
.concreteTargetOptions(IndicesOptions.ConcreteTargetOptions.ERROR_WHEN_UNAVAILABLE_TARGETS)
@@ -95,7 +99,7 @@ public Request(StreamInput in) throws IOException {
9599
this.names = in.readOptionalStringArray();
96100
this.indicesOptions = IndicesOptions.readIndicesOptions(in);
97101
// This boolean was removed in 8.19
98-
if (in.getTransportVersion().isPatchFrom(TransportVersions.DATA_STREAM_OPTIONS_API_REMOVE_INCLUDE_DEFAULTS_8_19) == false) {
102+
if (in.getTransportVersion().supports(DATA_STREAM_OPTIONS_API_REMOVE_INCLUDE_DEFAULTS) == false) {
99103
in.readBoolean();
100104
}
101105
}

muted-tests.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,15 @@ tests:
615615
- class: org.elasticsearch.xpack.esql.qa.multi_node.GenerativeIT
616616
method: test
617617
issue: https://github.com/elastic/elasticsearch/issues/134407
618+
- class: org.elasticsearch.action.admin.cluster.stats.SearchUsageStatsTests
619+
method: testToXContent
620+
issue: https://github.com/elastic/elasticsearch/issues/135558
621+
- class: org.elasticsearch.search.ccs.SparseVectorQueryBuilderCrossClusterSearchIT
622+
method: testSparseVectorQueryWithCcsMinimizeRoundTripsFalse
623+
issue: https://github.com/elastic/elasticsearch/issues/135559
624+
- class: org.elasticsearch.cluster.routing.allocation.decider.RestoreInProgressAllocationDeciderTests
625+
method: testCanAllocatePrimaryExistingInRestoreInProgress
626+
issue: https://github.com/elastic/elasticsearch/issues/135566
618627

619628
# Examples:
620629
#

server/src/internalClusterTest/java/org/elasticsearch/snapshots/RestoreSnapshotIT.java

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import org.apache.logging.log4j.Level;
1313
import org.elasticsearch.action.ActionFuture;
1414
import org.elasticsearch.action.ActionRequestBuilder;
15+
import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest;
16+
import org.elasticsearch.action.admin.cluster.allocation.TransportClusterAllocationExplainAction;
1517
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
1618
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse;
1719
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
@@ -20,6 +22,8 @@
2022
import org.elasticsearch.cluster.block.ClusterBlocks;
2123
import org.elasticsearch.cluster.metadata.IndexMetadata;
2224
import org.elasticsearch.cluster.metadata.MappingMetadata;
25+
import org.elasticsearch.cluster.routing.allocation.decider.Decision;
26+
import org.elasticsearch.common.Strings;
2327
import org.elasticsearch.common.settings.Settings;
2428
import org.elasticsearch.common.unit.ByteSizeUnit;
2529
import org.elasticsearch.core.TimeValue;
@@ -41,6 +45,7 @@
4145
import java.util.List;
4246
import java.util.Locale;
4347
import java.util.Map;
48+
import java.util.Set;
4449
import java.util.concurrent.TimeUnit;
4550
import java.util.stream.Collectors;
4651
import java.util.stream.IntStream;
@@ -63,6 +68,7 @@
6368
import static org.hamcrest.Matchers.not;
6469
import static org.hamcrest.Matchers.notNullValue;
6570
import static org.hamcrest.Matchers.nullValue;
71+
import static org.hamcrest.Matchers.startsWith;
6672

6773
public class RestoreSnapshotIT extends AbstractSnapshotIntegTestCase {
6874

@@ -1025,4 +1031,75 @@ public void testNoWarningsOnRestoreOverClosedIndex() throws IllegalAccessExcepti
10251031
mockLog.assertAllExpectationsMatched();
10261032
}
10271033
}
1034+
1035+
public void testExplainUnassigableDuringRestore() {
1036+
final String repoName = "repo-" + randomIdentifier();
1037+
createRepository(repoName, FsRepository.TYPE);
1038+
final String indexName = "index-" + randomIdentifier();
1039+
createIndexWithContent(indexName);
1040+
final String snapshotName = "snapshot-" + randomIdentifier();
1041+
createSnapshot(repoName, snapshotName, List.of(indexName));
1042+
assertAcked(indicesAdmin().prepareDelete(indexName));
1043+
1044+
final RestoreSnapshotResponse restoreSnapshotResponse = clusterAdmin().prepareRestoreSnapshot(
1045+
TEST_REQUEST_TIMEOUT,
1046+
repoName,
1047+
snapshotName
1048+
)
1049+
.setIndices(indexName)
1050+
.setRestoreGlobalState(false)
1051+
.setWaitForCompletion(true)
1052+
.setIndexSettings(
1053+
Settings.builder().put(IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_PREFIX + "._name", "not-a-node-" + randomIdentifier())
1054+
)
1055+
.get();
1056+
1057+
logger.info("--> restoreSnapshotResponse: {}", Strings.toString(restoreSnapshotResponse, true, true));
1058+
assertThat(restoreSnapshotResponse.getRestoreInfo().failedShards(), greaterThan(0));
1059+
1060+
final var clusterExplainResponse1 = client().execute(
1061+
TransportClusterAllocationExplainAction.TYPE,
1062+
new ClusterAllocationExplainRequest(TEST_REQUEST_TIMEOUT).setIndex(indexName).setShard(0).setPrimary(true)
1063+
).actionGet();
1064+
1065+
logger.info("--> clusterExplainResponse1: {}", Strings.toString(clusterExplainResponse1, true, true));
1066+
for (var nodeDecision : clusterExplainResponse1.getExplanation()
1067+
.getShardAllocationDecision()
1068+
.getAllocateDecision()
1069+
.getNodeDecisions()) {
1070+
assertEquals(
1071+
Set.of("restore_in_progress", "filter"),
1072+
nodeDecision.getCanAllocateDecision().getDecisions().stream().map(Decision::label).collect(Collectors.toSet())
1073+
);
1074+
}
1075+
1076+
updateIndexSettings(Settings.builder().putNull(IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_PREFIX + "._name"), indexName);
1077+
1078+
final var clusterExplainResponse2 = client().execute(
1079+
TransportClusterAllocationExplainAction.TYPE,
1080+
new ClusterAllocationExplainRequest(TEST_REQUEST_TIMEOUT).setIndex(indexName).setShard(0).setPrimary(true)
1081+
).actionGet();
1082+
1083+
logger.info("--> clusterExplainResponse2: {}", Strings.toString(clusterExplainResponse2, true, true));
1084+
for (var nodeDecision : clusterExplainResponse2.getExplanation()
1085+
.getShardAllocationDecision()
1086+
.getAllocateDecision()
1087+
.getNodeDecisions()) {
1088+
assertEquals(
1089+
Set.of("restore_in_progress"),
1090+
nodeDecision.getCanAllocateDecision().getDecisions().stream().map(Decision::label).collect(Collectors.toSet())
1091+
);
1092+
assertEquals(
1093+
Set.of("restore_in_progress"),
1094+
nodeDecision.getCanAllocateDecision().getDecisions().stream().map(Decision::label).collect(Collectors.toSet())
1095+
);
1096+
assertThat(
1097+
nodeDecision.getCanAllocateDecision().getDecisions().get(0).getExplanation(),
1098+
startsWith(
1099+
"Restore from snapshot failed because the configured constraints prevented allocation on any of the available nodes. "
1100+
+ "Please check constraints applied in index and cluster settings, then retry the restore."
1101+
)
1102+
);
1103+
}
1104+
}
10281105
}

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,6 @@ static TransportVersion def(int id) {
182182
public static final TransportVersion ML_INFERENCE_VERTEXAI_CHATCOMPLETION_ADDED_8_19 = def(8_841_0_38);
183183
public static final TransportVersion INFERENCE_CUSTOM_SERVICE_ADDED_8_19 = def(8_841_0_39);
184184
public static final TransportVersion IDP_CUSTOM_SAML_ATTRIBUTES_ADDED_8_19 = def(8_841_0_40);
185-
public static final TransportVersion DATA_STREAM_OPTIONS_API_REMOVE_INCLUDE_DEFAULTS_8_19 = def(8_841_0_41);
186-
public static final TransportVersion JOIN_ON_ALIASES_8_19 = def(8_841_0_42);
187-
public static final TransportVersion ILM_ADD_SKIP_SETTING_8_19 = def(8_841_0_43);
188-
public static final TransportVersion ESQL_REGEX_MATCH_WITH_CASE_INSENSITIVITY_8_19 = def(8_841_0_44);
189-
public static final TransportVersion ESQL_QUERY_PLANNING_DURATION_8_19 = def(8_841_0_45);
190-
public static final TransportVersion SEARCH_SOURCE_EXCLUDE_VECTORS_PARAM_8_19 = def(8_841_0_46);
191-
public static final TransportVersion ML_INFERENCE_MISTRAL_CHAT_COMPLETION_ADDED_8_19 = def(8_841_0_47);
192-
public static final TransportVersion ML_INFERENCE_ELASTIC_RERANK_ADDED_8_19 = def(8_841_0_48);
193-
public static final TransportVersion NONE_CHUNKING_STRATEGY_8_19 = def(8_841_0_49);
194-
public static final TransportVersion IDP_CUSTOM_SAML_ATTRIBUTES_ALLOW_LIST_8_19 = def(8_841_0_50);
195185
public static final TransportVersion INITIAL_ELASTICSEARCH_9_0 = def(9_000_0_00);
196186
public static final TransportVersion REMOVE_SNAPSHOT_FAILURES_90 = def(9_000_0_01);
197187
public static final TransportVersion TRANSPORT_STATS_HANDLING_TIME_REQUIRED_90 = def(9_000_0_02);
@@ -251,11 +241,9 @@ static TransportVersion def(int id) {
251241
public static final TransportVersion REPO_ANALYSIS_COPY_BLOB = def(9_048_0_00);
252242
public static final TransportVersion AMAZON_BEDROCK_TASK_SETTINGS = def(9_049_0_00);
253243
public static final TransportVersion ESQL_REPORT_SHARD_PARTITIONING = def(9_050_0_00);
254-
public static final TransportVersion DEAD_ESQL_QUERY_PLANNING_DURATION = def(9_051_0_00);
255244
public static final TransportVersion DEAD_ESQL_DOCUMENTS_FOUND_AND_VALUES_LOADED = def(9_052_0_00);
256245
public static final TransportVersion DEAD_BATCHED_QUERY_EXECUTION_DELAYABLE_WRITABLE = def(9_053_0_00);
257246
public static final TransportVersion DEAD_SEARCH_INCREMENTAL_TOP_DOCS_NULL = def(9_054_0_00);
258-
public static final TransportVersion ESQL_QUERY_PLANNING_DURATION = def(9_055_0_00);
259247
public static final TransportVersion BATCHED_QUERY_EXECUTION_DELAYABLE_WRITABLE = def(9_057_0_00);
260248
public static final TransportVersion SEARCH_INCREMENTAL_TOP_DOCS_NULL = def(9_058_0_00);
261249
public static final TransportVersion COMPRESS_DELAYABLE_WRITEABLE = def(9_059_0_00);
@@ -282,18 +270,10 @@ static TransportVersion def(int id) {
282270
public static final TransportVersion ML_INFERENCE_VERTEXAI_CHATCOMPLETION_ADDED = def(9_083_0_00);
283271
public static final TransportVersion INFERENCE_CUSTOM_SERVICE_ADDED = def(9_084_0_00);
284272
public static final TransportVersion ESQL_LIMIT_ROW_SIZE = def(9_085_0_00);
285-
public static final TransportVersion ESQL_REGEX_MATCH_WITH_CASE_INSENSITIVITY = def(9_086_0_00);
286273
public static final TransportVersion IDP_CUSTOM_SAML_ATTRIBUTES = def(9_087_0_00);
287-
public static final TransportVersion JOIN_ON_ALIASES = def(9_088_0_00);
288-
public static final TransportVersion ILM_ADD_SKIP_SETTING = def(9_089_0_00);
289-
public static final TransportVersion ML_INFERENCE_MISTRAL_CHAT_COMPLETION_ADDED = def(9_090_0_00);
290-
public static final TransportVersion IDP_CUSTOM_SAML_ATTRIBUTES_ALLOW_LIST = def(9_091_0_00);
291-
public static final TransportVersion SEARCH_SOURCE_EXCLUDE_VECTORS_PARAM = def(9_092_0_00);
292274
public static final TransportVersion SNAPSHOT_INDEX_SHARD_STATUS_MISSING_STATS = def(9_093_0_00);
293-
public static final TransportVersion ML_INFERENCE_ELASTIC_RERANK = def(9_094_0_00);
294275
public static final TransportVersion SEARCH_LOAD_PER_INDEX_STATS = def(9_095_0_00);
295276
public static final TransportVersion HEAP_USAGE_IN_CLUSTER_INFO = def(9_096_0_00);
296-
public static final TransportVersion NONE_CHUNKING_STRATEGY = def(9_097_0_00);
297277
public static final TransportVersion PROJECT_DELETION_GLOBAL_BLOCK = def(9_098_0_00);
298278
public static final TransportVersion SECURITY_CLOUD_API_KEY_REALM_AND_TYPE = def(9_099_0_00);
299279
public static final TransportVersion STATE_PARAM_GET_SNAPSHOT = def(9_100_0_00);

server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/RestoreInProgressAllocationDecider.java

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
import org.elasticsearch.cluster.routing.RecoverySource;
1414
import org.elasticsearch.cluster.routing.RoutingNode;
1515
import org.elasticsearch.cluster.routing.ShardRouting;
16+
import org.elasticsearch.cluster.routing.UnassignedInfo;
1617
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
18+
import org.elasticsearch.common.ReferenceDocs;
1719

1820
/**
1921
* This {@link AllocationDecider} prevents shards that have failed to be
@@ -49,15 +51,34 @@ public Decision canAllocate(final ShardRouting shardRouting, final RoutingAlloca
4951
return allocation.decision(Decision.YES, NAME, "shard is currently being restored");
5052
}
5153
}
52-
return allocation.decision(
53-
Decision.NO,
54-
NAME,
55-
"shard has failed to be restored from the snapshot [%s] - manually close or delete the index [%s] in order to retry "
56-
+ "to restore the snapshot again or use the reroute API to force the allocation of an empty primary shard. Details: [%s]",
57-
source.snapshot(),
58-
shardRouting.getIndexName(),
59-
shardRouting.unassignedInfo().details()
60-
);
54+
55+
/**
56+
* POST: the RestoreInProgress.Entry is non-existent. This section differentiates between a restore that failed
57+
* because of a indexing fault (see {@link AllocationService.applyFailedShards}) or because of an allocation
58+
* failure.
59+
*/
60+
UnassignedInfo unassignedInfo = shardRouting.unassignedInfo();
61+
if (unassignedInfo.failedAllocations() > 0) {
62+
return allocation.decision(
63+
Decision.NO,
64+
NAME,
65+
"shard has failed to be restored from the snapshot [%s] - manually close or delete the index [%s] in order to retry "
66+
+ "to restore the snapshot again or use the reroute API to force the allocation of an empty primary shard. Check the "
67+
+ "logs for more information about the failure. Details: [%s]",
68+
source.snapshot(),
69+
shardRouting.getIndexName(),
70+
unassignedInfo.details()
71+
);
72+
} else {
73+
return allocation.decision(
74+
Decision.NO,
75+
NAME,
76+
"Restore from snapshot failed because the configured constraints prevented allocation on any of the available nodes. "
77+
+ "Please check constraints applied in index and cluster settings, then retry the restore. "
78+
+ "See [%s] for more details on using the allocation explain API.",
79+
ReferenceDocs.ALLOCATION_EXPLAIN_API
80+
);
81+
}
6182
}
6283

6384
@Override

server/src/main/java/org/elasticsearch/indices/IndicesQueryCache.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,19 @@ private static QueryCacheStats toQueryCacheStatsSafe(@Nullable Stats stats) {
8989
return stats == null ? new QueryCacheStats() : stats.toQueryCacheStats();
9090
}
9191

92-
private long getShareOfAdditionalRamBytesUsed(long cacheSize) {
92+
private long getShareOfAdditionalRamBytesUsed(long itemsInCacheForShard) {
9393
if (sharedRamBytesUsed == 0L) {
9494
return 0L;
9595
}
9696

97-
// We also have some shared ram usage that we try to distribute proportionally to the cache footprint of each shard.
97+
/*
98+
* We have some shared ram usage that we try to distribute proportionally to the number of segment-requests in the cache for each
99+
* shard.
100+
*/
98101
// TODO avoid looping over all local shards here - see https://github.com/elastic/elasticsearch/issues/97222
99-
long totalSize = 0L;
102+
long totalItemsInCache = 0L;
100103
int shardCount = 0;
101-
if (cacheSize == 0L) {
104+
if (itemsInCacheForShard == 0L) {
102105
for (final var stats : shardStats.values()) {
103106
shardCount += 1;
104107
if (stats.cacheSize > 0L) {
@@ -110,7 +113,7 @@ private long getShareOfAdditionalRamBytesUsed(long cacheSize) {
110113
// branchless loop for the common case
111114
for (final var stats : shardStats.values()) {
112115
shardCount += 1;
113-
totalSize += stats.cacheSize;
116+
totalItemsInCache += stats.cacheSize;
114117
}
115118
}
116119

@@ -121,12 +124,20 @@ private long getShareOfAdditionalRamBytesUsed(long cacheSize) {
121124
}
122125

123126
final long additionalRamBytesUsed;
124-
if (totalSize == 0) {
127+
if (totalItemsInCache == 0) {
125128
// all shards have zero cache footprint, so we apportion the size of the shared bytes equally across all shards
126129
additionalRamBytesUsed = Math.round((double) sharedRamBytesUsed / shardCount);
127130
} else {
128-
// some shards have nonzero cache footprint, so we apportion the size of the shared bytes proportionally to cache footprint
129-
additionalRamBytesUsed = Math.round((double) sharedRamBytesUsed * cacheSize / totalSize);
131+
/*
132+
* Some shards have nonzero cache footprint, so we apportion the size of the shared bytes proportionally to the number of
133+
* segment-requests in the cache for this shard (the number and size of documents associated with those requests is irrelevant
134+
* for this calculation).
135+
* Note that this was a somewhat arbitrary decision. Calculating it by number of documents might have been better. Calculating
136+
* it by number of documents weighted by size would also be good, but possibly more expensive. But the decision to attribute
137+
* memory proportionally to the number of segment-requests was made a long time ago, and we're sticking with that here for the
138+
* sake of consistency and backwards compatibility.
139+
*/
140+
additionalRamBytesUsed = Math.round((double) sharedRamBytesUsed * itemsInCacheForShard / totalItemsInCache);
130141
}
131142
assert additionalRamBytesUsed >= 0L : additionalRamBytesUsed;
132143
return additionalRamBytesUsed;

server/src/main/java/org/elasticsearch/search/fetch/subphase/FetchSourceContext.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
package org.elasticsearch.search.fetch.subphase;
1111

1212
import org.elasticsearch.TransportVersion;
13-
import org.elasticsearch.TransportVersions;
1413
import org.elasticsearch.common.ParsingException;
1514
import org.elasticsearch.common.Strings;
1615
import org.elasticsearch.common.io.stream.StreamInput;
@@ -46,6 +45,9 @@ public class FetchSourceContext implements Writeable, ToXContentObject {
4645
public static final ParseField INCLUDES_FIELD = new ParseField("includes", "include");
4746
public static final ParseField EXCLUDES_FIELD = new ParseField("excludes", "exclude");
4847

48+
private static final TransportVersion SEARCH_SOURCE_EXCLUDE_VECTORS_PARAM = TransportVersion.fromName(
49+
"search_source_exclude_vectors_param"
50+
);
4951
private static final TransportVersion SEARCH_SOURCE_EXCLUDE_INFERENCE_FIELDS_PARAM = TransportVersion.fromName(
5052
"search_source_exclude_inference_fields_param"
5153
);
@@ -157,8 +159,7 @@ public void writeTo(StreamOutput out) throws IOException {
157159
}
158160

159161
private static boolean isVersionCompatibleWithExcludeVectors(TransportVersion version) {
160-
return version.isPatchFrom(TransportVersions.SEARCH_SOURCE_EXCLUDE_VECTORS_PARAM_8_19)
161-
|| version.onOrAfter(TransportVersions.SEARCH_SOURCE_EXCLUDE_VECTORS_PARAM);
162+
return version.supports(SEARCH_SOURCE_EXCLUDE_VECTORS_PARAM);
162163
}
163164

164165
public boolean fetchSource() {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# We have taken a donor primary id from
2+
# another collapsed primary id since
3+
# we only have a patch id here given that
4+
# this feature was removed in 8.19.
5+
# This works because our donor was taken
6+
# prior to 9.1.0 release. So this still
7+
# honors bwc from 8.19 -> 9.1 and
8+
# 9.0 -> 9.x.
9+
9081000,8841041
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9055000,8841045

0 commit comments

Comments
 (0)