Skip to content

Commit a591de8

Browse files
Merge remote-tracking branch 'upstream/main' into convert-processor-tests-and-docs
2 parents 7ec8b13 + 92d69b5 commit a591de8

File tree

25 files changed

+705
-131
lines changed

25 files changed

+705
-131
lines changed

build-tools/src/main/java/org/elasticsearch/gradle/LazyFileOutputStream.java

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
* or more contributor license agreements. Licensed under the "Elastic License
44
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
55
* Public License v 1"; you may not use this file except in compliance with, at
6-
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7-
* License v3.0 only", or the "Server Side Public License, v 1".
6+
* your election, the "Server Side Public License v3.0 only", or the "Server Side Public License, v 1".
87
*/
98

109
package org.elasticsearch.gradle;
@@ -18,48 +17,58 @@
1817
* An outputstream to a File that is lazily opened on the first write.
1918
*/
2019
class LazyFileOutputStream extends OutputStream {
21-
private OutputStream delegate;
20+
private final File file;
21+
private volatile OutputStream delegate;
22+
private volatile boolean initialized = false;
23+
private final Object lock = new Object();
2224

2325
LazyFileOutputStream(File file) {
24-
// use an initial dummy delegate to avoid doing a conditional on every write
25-
this.delegate = new OutputStream() {
26-
private void bootstrap() throws IOException {
27-
file.getParentFile().mkdirs();
28-
delegate = new FileOutputStream(file);
29-
}
30-
31-
@Override
32-
public void write(int b) throws IOException {
33-
bootstrap();
34-
delegate.write(b);
35-
}
36-
37-
@Override
38-
public void write(byte b[], int off, int len) throws IOException {
39-
bootstrap();
40-
delegate.write(b, off, len);
41-
}
26+
this.file = file;
27+
}
4228

43-
@Override
44-
public void write(byte b[]) throws IOException {
45-
bootstrap();
46-
delegate.write(b);
29+
private void ensureInitialized() throws IOException {
30+
if (initialized == false) {
31+
synchronized (lock) {
32+
if (initialized == false) {
33+
file.getParentFile().mkdirs();
34+
delegate = new FileOutputStream(file);
35+
initialized = true;
36+
}
4737
}
48-
};
38+
}
4939
}
5040

5141
@Override
5242
public void write(int b) throws IOException {
43+
ensureInitialized();
5344
delegate.write(b);
5445
}
5546

5647
@Override
5748
public void write(byte b[], int off, int len) throws IOException {
49+
ensureInitialized();
5850
delegate.write(b, off, len);
5951
}
6052

53+
@Override
54+
public void write(byte b[]) throws IOException {
55+
ensureInitialized();
56+
delegate.write(b);
57+
}
58+
6159
@Override
6260
public void close() throws IOException {
63-
delegate.close();
61+
synchronized (lock) {
62+
if (initialized && delegate != null) {
63+
delegate.close();
64+
}
65+
}
66+
}
67+
68+
@Override
69+
public void flush() throws IOException {
70+
if (initialized && delegate != null) {
71+
delegate.flush();
72+
}
6473
}
6574
}

docs/changelog/132922.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 132922
2+
summary: Change GeoIpCache and EnrichCache to LongAdder
3+
area: Ingest Node
4+
type: bug
5+
issues: []

docs/changelog/133188.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 133188
2+
summary: Don't fail search if bottom doc can't be formatted
3+
area: Search
4+
type: bug
5+
issues:
6+
- 125321

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public class TransportUpdateDataStreamSettingsAction extends TransportMasterNode
5454
UpdateDataStreamSettingsAction.Request,
5555
UpdateDataStreamSettingsAction.Response> {
5656
private static final Logger logger = LogManager.getLogger(TransportUpdateDataStreamSettingsAction.class);
57-
private static final Set<String> APPLY_TO_BACKING_INDICES = Set.of(
57+
private static final Set<String> APPLY_TO_WRITE_INDEX = Set.of("index.number_of_replicas");
58+
private static final Set<String> APPLY_TO_ALL_BACKING_INDICES = Set.of(
5859
"index.lifecycle.name",
5960
IndexSettings.PREFER_ILM,
6061
"index.refresh_interval"
@@ -158,7 +159,9 @@ private void updateSingleDataStream(
158159
logger.debug("updating settings for {}", dataStreamName);
159160
Set<String> settingsToReject = new HashSet<>();
160161
for (String settingName : settingsOverrides.keySet()) {
161-
if (APPLY_TO_BACKING_INDICES.contains(settingName) == false && APPLY_TO_DATA_STREAM_ONLY.contains(settingName) == false) {
162+
if (APPLY_TO_WRITE_INDEX.contains(settingName) == false
163+
&& APPLY_TO_ALL_BACKING_INDICES.contains(settingName) == false
164+
&& APPLY_TO_DATA_STREAM_ONLY.contains(settingName) == false) {
162165
settingsToReject.add(settingName);
163166
}
164167
}
@@ -223,19 +226,26 @@ private void updateSettingsOnIndices(
223226
TimeValue ackTimeout,
224227
ActionListener<UpdateDataStreamSettingsAction.DataStreamSettingsResponse> listener
225228
) {
226-
Map<String, Object> settingsToApply = new HashMap<>();
229+
Map<String, Object> settingsToApplyToNonWriteIndices = new HashMap<>();
230+
Map<String, Object> settingsToApplyToWriteIndex = new HashMap<>();
227231
List<String> appliedToDataStreamOnly = new ArrayList<>();
232+
List<String> appliedToDataStreamAndWriteIndexOnly = new ArrayList<>();
228233
List<String> appliedToDataStreamAndBackingIndices = new ArrayList<>();
229234
Settings effectiveSettings = dataStream.getEffectiveSettings(projectResolver.getProjectMetadata(clusterService.state()));
230235
for (String settingName : requestSettings.keySet()) {
231-
if (APPLY_TO_BACKING_INDICES.contains(settingName)) {
232-
settingsToApply.put(settingName, effectiveSettings.get(settingName));
236+
if (APPLY_TO_WRITE_INDEX.contains(settingName)) {
237+
settingsToApplyToWriteIndex.put(settingName, effectiveSettings.get(settingName));
238+
appliedToDataStreamAndWriteIndexOnly.add(settingName);
239+
} else if (APPLY_TO_ALL_BACKING_INDICES.contains(settingName)) {
240+
settingsToApplyToWriteIndex.put(settingName, effectiveSettings.get(settingName));
241+
settingsToApplyToNonWriteIndices.put(settingName, effectiveSettings.get(settingName));
233242
appliedToDataStreamAndBackingIndices.add(settingName);
234243
} else if (APPLY_TO_DATA_STREAM_ONLY.contains(settingName)) {
235244
appliedToDataStreamOnly.add(settingName);
236245
}
237246
}
238247
final List<Index> concreteIndices = dataStream.getIndices();
248+
final Index writeIndex = dataStream.getWriteIndex();
239249
final List<UpdateDataStreamSettingsAction.DataStreamSettingsResponse.IndexSettingError> indexSettingErrors = new ArrayList<>();
240250

241251
CountDownActionListener indexCountDownListener = new CountDownActionListener(
@@ -250,6 +260,7 @@ private void updateSettingsOnIndices(
250260
settingsFilter.filter(effectiveSettings),
251261
new UpdateDataStreamSettingsAction.DataStreamSettingsResponse.IndicesSettingsResult(
252262
appliedToDataStreamOnly,
263+
appliedToDataStreamAndWriteIndexOnly,
253264
appliedToDataStreamAndBackingIndices,
254265
indexSettingErrors
255266
)
@@ -259,11 +270,13 @@ private void updateSettingsOnIndices(
259270
);
260271

261272
indexCountDownListener.onResponse(null); // handles the case where there were zero indices
262-
Settings applyToIndexSettings = builder().loadFromMap(settingsToApply).build();
273+
Settings applyToNonWriteIndexSettings = builder().loadFromMap(settingsToApplyToNonWriteIndices).build();
274+
Settings applyToWriteIndexSettings = builder().loadFromMap(settingsToApplyToWriteIndex).build();
263275
for (Index index : concreteIndices) {
276+
Settings settings = index.equals(writeIndex) ? applyToWriteIndexSettings : applyToNonWriteIndexSettings;
264277
updateSettingsOnSingleIndex(
265278
index,
266-
applyToIndexSettings,
279+
settings,
267280
dryRun,
268281
masterNodeTimeout,
269282
ackTimeout,

modules/data-streams/src/yamlRestTest/resources/rest-api-spec/test/data_stream/240_data_stream_settings.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,3 +495,98 @@ setup:
495495
index: my-component-only-data-stream-1
496496
- match: { .$idx0name.settings.index.lifecycle.name: "my-policy" }
497497
- match: { .$idx0name.settings.index.lifecycle.prefer_ilm: null }
498+
499+
---
500+
"Test write index only setting":
501+
- requires:
502+
cluster_features: [ "logs_stream" ]
503+
reason: requires setting 'logs_stream' to get or set data stream settings
504+
- do:
505+
allowed_warnings:
506+
- "index template [my-template] has index patterns [my-data-stream-*] matching patterns from existing older templates [global] with patterns (global => [*]); this template [my-template] will take precedence during new index creation"
507+
indices.put_index_template:
508+
name: my-template
509+
body:
510+
index_patterns: [ my-data-stream-* ]
511+
data_stream: { }
512+
template:
513+
settings:
514+
number_of_replicas: 0
515+
lifecycle.name: my-policy
516+
517+
- do:
518+
indices.create_data_stream:
519+
name: my-data-stream-1
520+
521+
- do:
522+
cluster.health:
523+
index: "my-data-stream-1"
524+
wait_for_status: green
525+
526+
- do:
527+
indices.get_data_stream_settings:
528+
name: my-data-stream-1
529+
- match: { data_streams.0.name: my-data-stream-1 }
530+
- match: { data_streams.0.settings: {} }
531+
- match: { data_streams.0.effective_settings.index.number_of_shards: null }
532+
- match: { data_streams.0.effective_settings.index.number_of_replicas: "0" }
533+
534+
- do:
535+
indices.rollover:
536+
alias: "my-data-stream-1"
537+
538+
- do:
539+
cluster.health:
540+
index: "my-data-stream-1"
541+
wait_for_status: green
542+
543+
- do:
544+
indices.put_data_stream_settings:
545+
name: my-data-stream-1
546+
body:
547+
index:
548+
number_of_replicas: 1
549+
- match: { data_streams.0.name: my-data-stream-1 }
550+
- match: { data_streams.0.applied_to_data_stream: true }
551+
- match: { data_streams.0.index_settings_results.applied_to_data_stream_only: []}
552+
- match: { data_streams.0.index_settings_results.applied_to_data_stream_and_backing_indices: []}
553+
- length: { data_streams.0.index_settings_results.applied_to_data_stream_and_write_indices: 1 }
554+
- match: { data_streams.0.effective_settings.index.number_of_replicas: "1" }
555+
556+
- do:
557+
indices.rollover:
558+
alias: "my-data-stream-1"
559+
560+
- do:
561+
cluster.health:
562+
index: "my-data-stream-1"
563+
wait_for_status: yellow
564+
565+
- do:
566+
indices.get_data_stream_settings:
567+
name: my-data-stream-1
568+
- match: { data_streams.0.name: my-data-stream-1 }
569+
- match: { data_streams.0.effective_settings.index.number_of_replicas: "1" }
570+
571+
- do:
572+
indices.get_data_stream:
573+
name: my-data-stream-1
574+
- match: { data_streams.0.name: my-data-stream-1 }
575+
- match: { data_streams.0.settings.index.number_of_replicas: "1" }
576+
- match: { data_streams.0.effective_settings: null }
577+
578+
- do:
579+
indices.get_data_stream:
580+
name: my-data-stream-1
581+
- set: { data_streams.0.indices.0.index_name: idx0name }
582+
- set: { data_streams.0.indices.1.index_name: idx1name }
583+
- set: { data_streams.0.indices.2.index_name: idx2name }
584+
585+
# We expect that index.number_of_replicas only gets updated on the current write index and any future indices. We have
586+
# done one rollover since setting the setting, so it ought to be updated in the two most recent indices only:
587+
- do:
588+
indices.get_settings:
589+
index: my-data-stream-1
590+
- match: { .$idx0name.settings.index.number_of_replicas: "0" }
591+
- match: { .$idx1name.settings.index.number_of_replicas: "1" }
592+
- match: { .$idx2name.settings.index.number_of_replicas: "1" }

modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpCache.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import org.elasticsearch.ingest.geoip.stats.CacheStats;
1818

1919
import java.nio.file.Path;
20-
import java.util.concurrent.atomic.AtomicLong;
20+
import java.util.concurrent.atomic.LongAdder;
2121
import java.util.function.Function;
2222
import java.util.function.LongSupplier;
2323

@@ -44,8 +44,8 @@ public String toString() {
4444

4545
private final LongSupplier relativeNanoTimeProvider;
4646
private final Cache<CacheKey, Object> cache;
47-
private final AtomicLong hitsTimeInNanos = new AtomicLong(0);
48-
private final AtomicLong missesTimeInNanos = new AtomicLong(0);
47+
private final LongAdder hitsTimeInNanos = new LongAdder();
48+
private final LongAdder missesTimeInNanos = new LongAdder();
4949

5050
// package private for testing
5151
GeoIpCache(long maxSize, LongSupplier relativeNanoTimeProvider) {
@@ -80,9 +80,9 @@ <RESPONSE> RESPONSE putIfAbsent(ProjectId projectId, String ip, String databaseP
8080
// store the result or no-result in the cache
8181
cache.put(cacheKey, response);
8282
long databaseRequestAndCachePutTime = relativeNanoTimeProvider.getAsLong() - retrieveStart;
83-
missesTimeInNanos.addAndGet(cacheRequestTime + databaseRequestAndCachePutTime);
83+
missesTimeInNanos.add(cacheRequestTime + databaseRequestAndCachePutTime);
8484
} else {
85-
hitsTimeInNanos.addAndGet(cacheRequestTime);
85+
hitsTimeInNanos.add(cacheRequestTime);
8686
}
8787

8888
if (response == NO_RESULT) {
@@ -126,8 +126,8 @@ public CacheStats getCacheStats() {
126126
stats.getHits(),
127127
stats.getMisses(),
128128
stats.getEvictions(),
129-
TimeValue.nsecToMSec(hitsTimeInNanos.get()),
130-
TimeValue.nsecToMSec(missesTimeInNanos.get())
129+
TimeValue.nsecToMSec(hitsTimeInNanos.sum()),
130+
TimeValue.nsecToMSec(missesTimeInNanos.sum())
131131
);
132132
}
133133

muted-tests.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,18 @@ tests:
621621
- class: org.elasticsearch.xpack.esql.action.RandomizedTimeSeriesIT
622622
method: testGroupBySubset
623623
issue: https://github.com/elastic/elasticsearch/issues/133220
624+
- class: org.elasticsearch.index.codec.tsdb.es819.ES819TSDBDocValuesFormatTests
625+
method: testSortedDocValuesSingleUniqueValue
626+
issue: https://github.com/elastic/elasticsearch/issues/133221
627+
- class: org.elasticsearch.index.codec.tsdb.es819.ES819TSDBDocValuesFormatTests
628+
method: testSortedNumberMergeAwayAllValuesWithSkipper
629+
issue: https://github.com/elastic/elasticsearch/issues/133223
630+
- class: org.elasticsearch.index.codec.tsdb.es819.ES819TSDBDocValuesFormatTests
631+
method: testSortedSetDocValuesWithSkipperSmall
632+
issue: https://github.com/elastic/elasticsearch/issues/133224
633+
- class: org.elasticsearch.xpack.esql.action.RandomizedTimeSeriesIT
634+
method: testGroupByNothing
635+
issue: https://github.com/elastic/elasticsearch/issues/133225
624636

625637
# Examples:
626638
#

0 commit comments

Comments
 (0)