Skip to content

Commit 5950d22

Browse files
authored
Merge branch 'main' into fix-123657
2 parents 969c68c + afff39e commit 5950d22

File tree

68 files changed

+245
-152
lines changed

Some content is hidden

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

68 files changed

+245
-152
lines changed

docs/changelog/122933.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 122933
2+
summary: Run XPack usage actions on local node
3+
area: Stats
4+
type: enhancement
5+
issues: []

server/src/main/java/org/elasticsearch/action/admin/indices/diskusage/IndexDiskUsageAnalyzer.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,17 @@ void analyzeDocValues(SegmentReader reader, IndexDiskUsageStats stats) throws IO
289289
throw new IllegalStateException("Unknown docValues type [" + dvType + "]");
290290
}
291291
}
292+
switch (field.docValuesSkipIndexType()) {
293+
case NONE -> {
294+
}
295+
case RANGE -> {
296+
var skipper = docValuesReader.getSkipper(field);
297+
while (skipper.maxDocID(0) != DocIdSetIterator.NO_MORE_DOCS) {
298+
skipper.advance(skipper.maxDocID(skipper.numLevels() - 1) + 1);
299+
}
300+
}
301+
default -> throw new IllegalStateException("Unknown skipper type [" + field.docValuesSkipIndexType() + "]");
302+
}
292303
stats.addDocValues(field.name, directory.getBytesRead());
293304
}
294305
}

server/src/main/java/org/elasticsearch/action/support/local/TransportLocalClusterStateAction.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ protected abstract void localClusterStateOperation(Task task, Request request, C
6666

6767
@Override
6868
protected final void doExecute(Task task, Request request, ActionListener<Response> listener) {
69+
if (task != null) {
70+
request.setParentTask(clusterService.localNode().getId(), task.getId());
71+
}
6972
final var state = clusterService.state();
7073
final var clusterBlockException = checkBlock(request, state);
7174
if (clusterBlockException != null) {

server/src/main/java/org/elasticsearch/cluster/coordination/LeaderChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class LeaderChecker {
6060

6161
private static final Logger logger = LogManager.getLogger(LeaderChecker.class);
6262

63-
static final String LEADER_CHECK_ACTION_NAME = "internal:coordination/fault_detection/leader_check";
63+
public static final String LEADER_CHECK_ACTION_NAME = "internal:coordination/fault_detection/leader_check";
6464

6565
// the time between checks sent to the leader
6666
public static final Setting<TimeValue> LEADER_CHECK_INTERVAL_SETTING = Setting.timeSetting(

server/src/test/java/org/elasticsearch/action/admin/indices/diskusage/IndexDiskUsageAnalyzerTests.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,21 @@ public void testMixedFields() throws Exception {
405405
}
406406
}
407407

408+
public void testDocValuesFieldWithDocValueSkippers() throws Exception {
409+
try (Directory dir = createNewDirectory()) {
410+
var codecMode = randomFrom(CodecMode.values());
411+
indexRandomly(dir, codecMode, between(100, 1000), doc -> addRandomDocValuesField(doc, true));
412+
final IndexDiskUsageStats stats = IndexDiskUsageAnalyzer.analyze(testShardId(), lastCommit(dir), () -> {});
413+
logger.info("--> stats {}", stats);
414+
try (Directory perFieldDir = createNewDirectory()) {
415+
rewriteIndexWithPerFieldCodec(dir, codecMode, perFieldDir);
416+
final IndexDiskUsageStats perFieldStats = collectPerFieldStats(perFieldDir);
417+
assertStats(stats, perFieldStats);
418+
assertStats(IndexDiskUsageAnalyzer.analyze(testShardId(), lastCommit(perFieldDir), () -> {}), perFieldStats);
419+
}
420+
}
421+
}
422+
408423
private static void addFieldsToDoc(Document doc, IndexableField[] fields) {
409424
for (IndexableField field : fields) {
410425
doc.add(field);
@@ -442,23 +457,27 @@ static void indexRandomly(Directory directory, CodecMode codecMode, int numDocs,
442457
}
443458
}
444459

445-
static void addRandomDocValuesField(Document doc) {
460+
static void addRandomDocValuesField(Document doc, boolean indexed) {
446461
if (randomBoolean()) {
447-
doc.add(new NumericDocValuesField("ndv", random().nextInt(1024)));
462+
int val = random().nextInt(1024);
463+
doc.add(indexed ? NumericDocValuesField.indexedField("ndv", val) : new NumericDocValuesField("ndv", val));
448464
}
449-
if (randomBoolean()) {
465+
if (randomBoolean() && indexed == false) {
450466
doc.add(new BinaryDocValuesField("bdv", new BytesRef(randomAlphaOfLength(3))));
451467
}
452468
if (randomBoolean()) {
453-
doc.add(new SortedDocValuesField("sdv", new BytesRef(randomAlphaOfLength(3))));
469+
var value = new BytesRef(randomAlphaOfLength(3));
470+
doc.add(indexed ? SortedDocValuesField.indexedField("sdv", value) : new SortedDocValuesField("sdv", value));
454471
}
455472
int numValues = random().nextInt(5);
456473
for (int i = 0; i < numValues; ++i) {
457-
doc.add(new SortedSetDocValuesField("ssdv", new BytesRef(randomAlphaOfLength(3))));
474+
var value = new BytesRef(randomAlphaOfLength(3));
475+
doc.add(indexed ? SortedSetDocValuesField.indexedField("ssdv", value) : new SortedSetDocValuesField("ssdv", value));
458476
}
459477
numValues = random().nextInt(5);
460478
for (int i = 0; i < numValues; ++i) {
461-
doc.add(new SortedNumericDocValuesField("sndv", random().nextInt(1024)));
479+
int value = random().nextInt(1024);
480+
doc.add(indexed ? SortedNumericDocValuesField.indexedField("sndv", value) : new SortedNumericDocValuesField("sndv", value));
462481
}
463482
}
464483

@@ -535,7 +554,7 @@ private static float[] randomVector(int dimension) {
535554

536555
static void addRandomFields(Document doc) {
537556
if (randomBoolean()) {
538-
addRandomDocValuesField(doc);
557+
addRandomDocValuesField(doc, false);
539558
}
540559
if (randomBoolean()) {
541560
addRandomPostings(doc);

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@
134134
import static java.util.Collections.unmodifiableList;
135135
import static org.elasticsearch.client.RestClient.IGNORE_RESPONSE_CODES_PARAM;
136136
import static org.elasticsearch.cluster.ClusterState.VERSION_INTRODUCING_TRANSPORT_VERSIONS;
137+
import static org.elasticsearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_ACTION_NAME;
138+
import static org.elasticsearch.cluster.coordination.LeaderChecker.LEADER_CHECK_ACTION_NAME;
137139
import static org.elasticsearch.core.Strings.format;
138140
import static org.elasticsearch.test.MapMatcher.assertMap;
139141
import static org.elasticsearch.test.MapMatcher.matchesMap;
@@ -258,6 +260,8 @@ public static boolean hasXPack() {
258260
*/
259261
private static RestClient cleanupClient;
260262

263+
private static boolean multiProjectEnabled;
264+
261265
public enum ProductFeature {
262266
XPACK,
263267
ILM,
@@ -368,6 +372,7 @@ public void initClient() throws IOException {
368372
availableFeatures = EnumSet.of(ProductFeature.LEGACY_TEMPLATES);
369373
Set<String> versions = new HashSet<>();
370374
boolean serverless = false;
375+
String multiProjectPluginVariant = null;
371376

372377
for (Map<?, ?> nodeInfo : getNodesInfo(adminClient).values()) {
373378
var nodeVersion = nodeInfo.get("version").toString();
@@ -397,6 +402,11 @@ public void initClient() throws IOException {
397402
if (moduleName.startsWith("serverless-")) {
398403
serverless = true;
399404
}
405+
if (moduleName.contains("test-multi-project")) {
406+
multiProjectPluginVariant = "test";
407+
} else if (moduleName.contains("serverless-multi-project")) {
408+
multiProjectPluginVariant = "serverless";
409+
}
400410
}
401411
if (serverless) {
402412
availableFeatures.removeAll(
@@ -418,6 +428,18 @@ public void initClient() throws IOException {
418428
.collect(Collectors.toSet());
419429
assert semanticNodeVersions.isEmpty() == false || serverless;
420430

431+
if (multiProjectPluginVariant != null) {
432+
final Request settingRequest = new Request(
433+
"GET",
434+
"/_cluster/settings?include_defaults&filter_path=*." + multiProjectPluginVariant + ".multi_project.enabled"
435+
);
436+
settingRequest.setOptions(RequestOptions.DEFAULT.toBuilder().setWarningsHandler(WarningsHandler.PERMISSIVE));
437+
final var response = entityAsMap(adminClient.performRequest(settingRequest));
438+
multiProjectEnabled = Boolean.parseBoolean(
439+
ObjectPath.evaluate(response, "defaults." + multiProjectPluginVariant + ".multi_project.enabled")
440+
);
441+
}
442+
421443
testFeatureService = createTestFeatureService(getClusterStateFeatures(adminClient), semanticNodeVersions);
422444
}
423445

@@ -677,6 +699,8 @@ public static void waitForPendingTasks(final RestClient restClient, final Predic
677699
final String taskName = line.split("\\s+")[0];
678700
if (taskName.startsWith(TransportListTasksAction.TYPE.name())
679701
|| taskName.startsWith(HealthNode.TASK_NAME)
702+
|| taskName.startsWith(LEADER_CHECK_ACTION_NAME)
703+
|| taskName.startsWith(FOLLOWER_CHECK_ACTION_NAME)
680704
|| taskFilter.test(taskName)) {
681705
continue;
682706
}
@@ -2376,6 +2400,9 @@ public void ensurePeerRecoveryRetentionLeasesRenewedAndSynced(String index) thro
23762400
protected static Map<String, Set<String>> getClusterStateFeatures(RestClient adminClient) throws IOException {
23772401
final Request request = new Request("GET", "_cluster/state");
23782402
request.addParameter("filter_path", "nodes_features");
2403+
if (multiProjectEnabled) {
2404+
request.addParameter("multi_project", "true");
2405+
}
23792406

23802407
final Response response = adminClient.performRequest(request);
23812408

x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/action/AnalyticsUsageTransportAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public AnalyticsUsageTransportAction(
3838
}
3939

4040
@Override
41-
protected void masterOperation(
41+
protected void localClusterStateOperation(
4242
Task task,
4343
XPackUsageRequest request,
4444
ClusterState state,

x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/action/AnalyticsInfoTransportActionTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void testAvailable() throws Exception {
7373
client
7474
);
7575
PlainActionFuture<XPackUsageFeatureResponse> future = new PlainActionFuture<>();
76-
usageAction.masterOperation(task, null, clusterState, future);
76+
usageAction.localClusterStateOperation(task, null, clusterState, future);
7777
XPackFeatureUsage usage = future.get().getUsage();
7878
assertThat(usage.available(), is(true));
7979

@@ -100,7 +100,7 @@ public void testEnabled() throws Exception {
100100
client
101101
);
102102
PlainActionFuture<XPackUsageFeatureResponse> future = new PlainActionFuture<>();
103-
usageAction.masterOperation(task, null, clusterState, future);
103+
usageAction.localClusterStateOperation(task, null, clusterState, future);
104104
XPackFeatureUsage usage = future.get().getUsage();
105105
assertTrue(usage.enabled());
106106

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/CCRUsageTransportAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public CCRUsageTransportAction(
4848
}
4949

5050
@Override
51-
protected void masterOperation(
51+
protected void localClusterStateOperation(
5252
Task task,
5353
XPackUsageRequest request,
5454
ClusterState state,

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CCRInfoTransportActionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void testUsageStats() throws Exception {
152152
licenseState
153153
);
154154
PlainActionFuture<XPackUsageFeatureResponse> future = new PlainActionFuture<>();
155-
usageAction.masterOperation(null, null, clusterState, future);
155+
usageAction.localClusterStateOperation(null, null, clusterState, future);
156156
CCRInfoTransportAction.Usage ccrUsage = (CCRInfoTransportAction.Usage) future.get().getUsage();
157157
assertThat(ccrUsage.enabled(), equalTo(true));
158158
assertThat(ccrUsage.available(), equalTo(false));

0 commit comments

Comments
 (0)