Skip to content

Commit 60532c3

Browse files
authored
Merge branch 'main' into prune
2 parents a9d476f + fd626a2 commit 60532c3

File tree

10 files changed

+398
-208
lines changed

10 files changed

+398
-208
lines changed

docs/changelog/121392.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 121392
2+
summary: Include data streams when converting an existing resource to a system resource
3+
area: Infra/Core
4+
type: bug
5+
issues: []

modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/ScaledFloatFieldMapperTests.java

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@
3131
import org.elasticsearch.xcontent.XContentBuilder;
3232
import org.elasticsearch.xcontent.XContentFactory;
3333
import org.elasticsearch.xcontent.XContentType;
34-
import org.hamcrest.Matcher;
3534
import org.junit.AssumptionViolatedException;
3635

3736
import java.io.IOException;
3837
import java.util.Collection;
3938
import java.util.Collections;
4039
import java.util.List;
4140
import java.util.Map;
42-
import java.util.function.Function;
4341
import java.util.function.Supplier;
4442
import java.util.stream.Stream;
4543

@@ -48,7 +46,6 @@
4846
import static org.hamcrest.Matchers.empty;
4947
import static org.hamcrest.Matchers.equalTo;
5048
import static org.hamcrest.Matchers.is;
51-
import static org.hamcrest.Matchers.notANumber;
5249

5350
public class ScaledFloatFieldMapperTests extends NumberFieldMapperTests {
5451

@@ -382,7 +379,7 @@ public SyntheticSourceExample example(int maxValues) {
382379
if (randomBoolean()) {
383380
Value v = generateValue();
384381
if (v.malformedOutput == null) {
385-
return new SyntheticSourceExample(v.input, v.output, roundDocValues(v.output), this::mapping);
382+
return new SyntheticSourceExample(v.input, v.output, this::mapping);
386383
}
387384
return new SyntheticSourceExample(v.input, v.malformedOutput, null, this::mapping);
388385
}
@@ -396,9 +393,7 @@ public SyntheticSourceExample example(int maxValues) {
396393
List<Object> outList = Stream.concat(outputFromDocValues.stream(), malformedOutput).toList();
397394
Object out = outList.size() == 1 ? outList.get(0) : outList;
398395

399-
List<Double> outBlockList = outputFromDocValues.stream().map(this::roundDocValues).sorted().toList();
400-
Object outBlock = outBlockList.size() == 1 ? outBlockList.get(0) : outBlockList;
401-
return new SyntheticSourceExample(in, out, outBlock, this::mapping);
396+
return new SyntheticSourceExample(in, out, this::mapping);
402397
}
403398

404399
private record Value(Object input, Double output, Object malformedOutput) {}
@@ -442,16 +437,6 @@ private double round(double d) {
442437
return decoded;
443438
}
444439

445-
private double roundDocValues(double d) {
446-
// Special case due to rounding, see implementation.
447-
if (Math.abs(d) == Double.MAX_VALUE) {
448-
return d;
449-
}
450-
451-
long encoded = Math.round(d * scalingFactor);
452-
return encoded * (1 / scalingFactor);
453-
}
454-
455440
private void mapping(XContentBuilder b) throws IOException {
456441
b.field("type", "scaled_float");
457442
b.field("scaling_factor", scalingFactor);
@@ -475,14 +460,9 @@ public List<SyntheticSourceInvalidExample> invalidExample() throws IOException {
475460
}
476461
}
477462

478-
@Override
479-
protected Function<Object, Object> loadBlockExpected() {
480-
return v -> (Number) v;
481-
}
482-
483-
@Override
484-
protected Matcher<?> blockItemMatcher(Object expected) {
485-
return "NaN".equals(expected) ? notANumber() : equalTo(expected);
463+
protected BlockReaderSupport getSupportedReaders(MapperService mapper, String loaderFieldName) {
464+
assumeTrue("Disabled, tested by ScaledFloatFieldBlockLoaderTests instead", false);
465+
return null;
486466
}
487467

488468
@Override

muted-tests.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -332,18 +332,12 @@ tests:
332332
- class: org.elasticsearch.xpack.esql.action.CrossClusterQueryWithPartialResultsIT
333333
method: testPartialResults
334334
issue: https://github.com/elastic/elasticsearch/issues/123101
335-
- class: org.elasticsearch.index.mapper.extras.ScaledFloatFieldMapperTests
336-
method: testBlockLoaderFromRowStrideReader
337-
issue: https://github.com/elastic/elasticsearch/issues/123126
338-
- class: org.elasticsearch.index.mapper.extras.ScaledFloatFieldMapperTests
339-
method: testBlockLoaderFromRowStrideReaderWithSyntheticSource
340-
issue: https://github.com/elastic/elasticsearch/issues/123145
341335
- class: org.elasticsearch.xpack.esql.action.CrossClusterAsyncQueryStopIT
342336
method: testStopQueryLocal
343337
issue: https://github.com/elastic/elasticsearch/issues/121672
344-
- class: org.elasticsearch.index.mapper.extras.ScaledFloatFieldMapperTests
345-
method: testBlockLoaderFromColumnReaderWithSyntheticSource
346-
issue: https://github.com/elastic/elasticsearch/issues/123149
338+
- class: org.elasticsearch.upgrades.DataStreamsUpgradeIT
339+
method: testUpgradeDataStream
340+
issue: https://github.com/elastic/elasticsearch/issues/123189
347341

348342
# Examples:
349343
#

server/src/main/java/org/elasticsearch/cluster/metadata/DataStream.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,13 @@ public boolean isFailureStoreIndex(String indexName) {
301301
return failureIndices.containsIndex(indexName);
302302
}
303303

304+
/**
305+
* Returns true if the index name provided belongs to this data stream.
306+
*/
307+
public boolean containsIndex(String indexName) {
308+
return backingIndices.containsIndex(indexName) || failureIndices.containsIndex(indexName);
309+
}
310+
304311
public DataStreamOptions getDataStreamOptions() {
305312
return dataStreamOptions;
306313
}
@@ -782,8 +789,9 @@ public DataStream addBackingIndex(Metadata clusterMetadata, Index index) {
782789
// ensure that no aliases reference index
783790
ensureNoAliasesOnIndex(clusterMetadata, index);
784791

785-
List<Index> backingIndices = new ArrayList<>(this.backingIndices.indices);
786-
backingIndices.add(0, index);
792+
List<Index> backingIndices = new ArrayList<>(this.backingIndices.indices.size() + 1);
793+
backingIndices.add(index);
794+
backingIndices.addAll(this.backingIndices.indices);
787795
assert backingIndices.size() == this.backingIndices.indices.size() + 1;
788796
return copy().setBackingIndices(this.backingIndices.copy().setIndices(backingIndices).build())
789797
.setGeneration(generation + 1)
@@ -808,8 +816,9 @@ public DataStream addFailureStoreIndex(Metadata clusterMetadata, Index index) {
808816

809817
ensureNoAliasesOnIndex(clusterMetadata, index);
810818

811-
List<Index> updatedFailureIndices = new ArrayList<>(failureIndices.indices);
812-
updatedFailureIndices.add(0, index);
819+
List<Index> updatedFailureIndices = new ArrayList<>(failureIndices.indices.size() + 1);
820+
updatedFailureIndices.add(index);
821+
updatedFailureIndices.addAll(failureIndices.indices);
813822
assert updatedFailureIndices.size() == failureIndices.indices.size() + 1;
814823
return copy().setFailureIndices(failureIndices.copy().setIndices(updatedFailureIndices).build())
815824
.setGeneration(generation + 1)
@@ -1039,7 +1048,7 @@ private boolean isIndexOlderThan(
10391048
* we return false.
10401049
*/
10411050
public boolean isIndexManagedByDataStreamLifecycle(Index index, Function<String, IndexMetadata> indexMetadataSupplier) {
1042-
if (backingIndices.containsIndex(index.getName()) == false && failureIndices.containsIndex(index.getName()) == false) {
1051+
if (containsIndex(index.getName()) == false) {
10431052
return false;
10441053
}
10451054
IndexMetadata indexMetadata = indexMetadataSupplier.apply(index.getName());

0 commit comments

Comments
 (0)