Skip to content

Commit 3b7f546

Browse files
Merge branch 'main' into svilen/127208
2 parents a20fb5b + 08d8224 commit 3b7f546

File tree

43 files changed

+869
-402
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

+869
-402
lines changed

docs/changelog/131817.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 131817
2+
summary: Change equals and hashcode for `ConstantNullBlock`
3+
area: ES|QL
4+
type: bug
5+
issues: []

docs/changelog/131917.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 131917
2+
summary: Fix NPE on empty to_lower/to_upper call
3+
area: ES|QL
4+
type: bug
5+
issues:
6+
- 131913

libs/simdvec/src/main/java/org/elasticsearch/simdvec/ES91Int4VectorsScorer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ public float applyCorrections(
161161
float qcDist
162162
) {
163163
float ax = lowerInterval;
164-
// Here we assume `lx` is simply bit vectors, so the scaling isn't necessary
165-
float lx = upperInterval - ax;
164+
float lx = (upperInterval - ax) * FOUR_BIT_SCALE;
166165
float ay = queryLowerInterval;
167166
float ly = (queryUpperInterval - ay) * FOUR_BIT_SCALE;
168167
float y1 = queryComponentSum;

libs/simdvec/src/main21/java/org/elasticsearch/simdvec/internal/vectorization/MemorySegmentES91Int4VectorsScorer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ private void applyCorrectionsBulk(
354354
memorySegment,
355355
offset + 4 * BULK_SIZE + i * Float.BYTES,
356356
ByteOrder.LITTLE_ENDIAN
357-
).sub(ax);
357+
).sub(ax).mul(FOUR_BIT_SCALE);
358358
var targetComponentSums = ShortVector.fromMemorySegment(
359359
SHORT_SPECIES,
360360
memorySegment,

libs/simdvec/src/test/java/org/elasticsearch/simdvec/internal/vectorization/ES91Int4VectorScorerTests.java

Lines changed: 72 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
import org.elasticsearch.simdvec.ES91Int4VectorsScorer;
2121
import org.elasticsearch.simdvec.ES91OSQVectorsScorer;
2222

23-
import static org.hamcrest.Matchers.lessThan;
23+
import java.io.IOException;
24+
25+
import static org.hamcrest.Matchers.greaterThan;
2426

2527
public class ES91Int4VectorScorerTests extends BaseVectorizationTests {
2628

@@ -130,31 +132,59 @@ public void testInt4ScoreBulk() throws Exception {
130132
// only even dimensions are supported
131133
final int dimensions = random().nextInt(1, 1000) * 2;
132134
final int numVectors = random().nextInt(1, 10) * ES91Int4VectorsScorer.BULK_SIZE;
133-
final byte[] vector = new byte[ES91Int4VectorsScorer.BULK_SIZE * dimensions];
134-
final byte[] corrections = new byte[ES91Int4VectorsScorer.BULK_SIZE * 14];
135+
final float[][] vectors = new float[numVectors][dimensions];
136+
final int[] quantizedScratch = new int[dimensions];
137+
final byte[] quantizeVector = new byte[dimensions];
138+
final float[] centroid = new float[dimensions];
139+
VectorSimilarityFunction similarityFunction = randomFrom(VectorSimilarityFunction.values());
140+
for (int i = 0; i < dimensions; i++) {
141+
centroid[i] = random().nextFloat();
142+
}
143+
if (similarityFunction != VectorSimilarityFunction.EUCLIDEAN) {
144+
VectorUtil.l2normalize(centroid);
145+
}
146+
147+
OptimizedScalarQuantizer quantizer = new OptimizedScalarQuantizer(similarityFunction);
135148
try (Directory dir = new MMapDirectory(createTempDir())) {
136149
try (IndexOutput out = dir.createOutput("tests.bin", IOContext.DEFAULT)) {
150+
OptimizedScalarQuantizer.QuantizationResult[] results =
151+
new OptimizedScalarQuantizer.QuantizationResult[ES91Int4VectorsScorer.BULK_SIZE];
137152
for (int i = 0; i < numVectors; i += ES91Int4VectorsScorer.BULK_SIZE) {
138-
for (int j = 0; j < ES91Int4VectorsScorer.BULK_SIZE * dimensions; j++) {
139-
vector[j] = (byte) random().nextInt(16); // 4-bit quantization
153+
for (int j = 0; j < ES91Int4VectorsScorer.BULK_SIZE; j++) {
154+
for (int k = 0; k < dimensions; k++) {
155+
vectors[i + j][k] = random().nextFloat();
156+
}
157+
if (similarityFunction != VectorSimilarityFunction.EUCLIDEAN) {
158+
VectorUtil.l2normalize(vectors[i + j]);
159+
}
160+
results[j] = quantizer.scalarQuantize(vectors[i + j].clone(), quantizedScratch, (byte) 4, centroid);
161+
for (int k = 0; k < dimensions; k++) {
162+
quantizeVector[k] = (byte) quantizedScratch[k];
163+
}
164+
out.writeBytes(quantizeVector, 0, dimensions);
140165
}
141-
out.writeBytes(vector, 0, vector.length);
142-
random().nextBytes(corrections);
143-
out.writeBytes(corrections, 0, corrections.length);
166+
writeCorrections(results, out);
144167
}
145168
}
146-
final byte[] query = new byte[dimensions];
169+
final float[] query = new float[dimensions];
170+
final byte[] quantizeQuery = new byte[dimensions];
147171
for (int j = 0; j < dimensions; j++) {
148-
query[j] = (byte) random().nextInt(16); // 4-bit quantization
172+
query[j] = random().nextFloat();
149173
}
150-
OptimizedScalarQuantizer.QuantizationResult queryCorrections = new OptimizedScalarQuantizer.QuantizationResult(
151-
random().nextFloat(),
152-
random().nextFloat(),
153-
random().nextFloat(),
154-
Short.toUnsignedInt((short) random().nextInt())
174+
if (similarityFunction != VectorSimilarityFunction.EUCLIDEAN) {
175+
VectorUtil.l2normalize(query);
176+
}
177+
OptimizedScalarQuantizer.QuantizationResult queryCorrections = quantizer.scalarQuantize(
178+
query.clone(),
179+
quantizedScratch,
180+
(byte) 4,
181+
centroid
155182
);
156-
float centroidDp = random().nextFloat();
157-
VectorSimilarityFunction similarityFunction = randomFrom(VectorSimilarityFunction.values());
183+
for (int j = 0; j < dimensions; j++) {
184+
quantizeQuery[j] = (byte) quantizedScratch[j];
185+
}
186+
float centroidDp = VectorUtil.dotProduct(centroid, centroid);
187+
158188
try (IndexInput in = dir.openInput("tests.bin", IOContext.DEFAULT)) {
159189
// Work on a slice that has just the right number of bytes to make the test fail with an
160190
// index-out-of-bounds in case the implementation reads more than the allowed number of
@@ -166,7 +196,7 @@ public void testInt4ScoreBulk() throws Exception {
166196
float[] scoresPanama = new float[ES91Int4VectorsScorer.BULK_SIZE];
167197
for (int i = 0; i < numVectors; i += ES91Int4VectorsScorer.BULK_SIZE) {
168198
defaultScorer.scoreBulk(
169-
query,
199+
quantizeQuery,
170200
queryCorrections.lowerInterval(),
171201
queryCorrections.upperInterval(),
172202
queryCorrections.quantizedComponentSum(),
@@ -176,7 +206,7 @@ public void testInt4ScoreBulk() throws Exception {
176206
scoresDefault
177207
);
178208
panamaScorer.scoreBulk(
179-
query,
209+
quantizeQuery,
180210
queryCorrections.lowerInterval(),
181211
queryCorrections.upperInterval(),
182212
queryCorrections.quantizedComponentSum(),
@@ -186,29 +216,34 @@ public void testInt4ScoreBulk() throws Exception {
186216
scoresPanama
187217
);
188218
for (int j = 0; j < ES91OSQVectorsScorer.BULK_SIZE; j++) {
189-
if (scoresDefault[j] == scoresPanama[j]) {
190-
continue;
191-
}
192-
if (scoresDefault[j] > (1000 * Byte.MAX_VALUE)) {
193-
float diff = Math.abs(scoresDefault[j] - scoresPanama[j]);
194-
assertThat(
195-
"defaultScores: " + scoresDefault[j] + " bulkScores: " + scoresPanama[j],
196-
diff / scoresDefault[j],
197-
lessThan(1e-5f)
198-
);
199-
assertThat(
200-
"defaultScores: " + scoresDefault[j] + " bulkScores: " + scoresPanama[j],
201-
diff / scoresPanama[j],
202-
lessThan(1e-5f)
203-
);
204-
} else {
205-
assertEquals(scoresDefault[j], scoresPanama[j], 1e-2f);
206-
}
219+
assertEquals(scoresDefault[j], scoresPanama[j], 1e-2f);
220+
float realSimilarity = similarityFunction.compare(vectors[i + j], query);
221+
float accuracy = realSimilarity > scoresDefault[j]
222+
? scoresDefault[j] / realSimilarity
223+
: realSimilarity / scoresDefault[j];
224+
assertThat(accuracy, greaterThan(0.90f));
207225
}
208226
assertEquals(in.getFilePointer(), slice.getFilePointer());
209227
}
210228
assertEquals((long) (dimensions + 14) * numVectors, in.getFilePointer());
211229
}
212230
}
213231
}
232+
233+
private static void writeCorrections(OptimizedScalarQuantizer.QuantizationResult[] corrections, IndexOutput out) throws IOException {
234+
for (OptimizedScalarQuantizer.QuantizationResult correction : corrections) {
235+
out.writeInt(Float.floatToIntBits(correction.lowerInterval()));
236+
}
237+
for (OptimizedScalarQuantizer.QuantizationResult correction : corrections) {
238+
out.writeInt(Float.floatToIntBits(correction.upperInterval()));
239+
}
240+
for (OptimizedScalarQuantizer.QuantizationResult correction : corrections) {
241+
int targetComponentSum = correction.quantizedComponentSum();
242+
assert targetComponentSum >= 0 && targetComponentSum <= 0xffff;
243+
out.writeShort((short) targetComponentSum);
244+
}
245+
for (OptimizedScalarQuantizer.QuantizationResult correction : corrections) {
246+
out.writeInt(Float.floatToIntBits(correction.additionalCorrection()));
247+
}
248+
}
214249
}

modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamsSnapshotsIT.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.elasticsearch.search.SearchHit;
4848
import org.elasticsearch.snapshots.AbstractSnapshotIntegTestCase;
4949
import org.elasticsearch.snapshots.RestoreInfo;
50+
import org.elasticsearch.snapshots.Snapshot;
5051
import org.elasticsearch.snapshots.SnapshotId;
5152
import org.elasticsearch.snapshots.SnapshotInProgressException;
5253
import org.elasticsearch.snapshots.SnapshotInfo;
@@ -1394,7 +1395,7 @@ public void testWarningHeaderOnRestoreWithoutTemplates() throws Exception {
13941395
.get();
13951396

13961397
RestStatus status = createSnapshotResponse.getSnapshotInfo().status();
1397-
SnapshotId snapshotId = createSnapshotResponse.getSnapshotInfo().snapshotId();
1398+
Snapshot snapshot = createSnapshotResponse.getSnapshotInfo().snapshot();
13981399
assertEquals(RestStatus.OK, status);
13991400

14001401
assertEquals(Collections.singletonList(dsBackingIndexName), getSnapshot(REPO, SNAPSHOT).indices());
@@ -1423,7 +1424,7 @@ public void testWarningHeaderOnRestoreWithoutTemplates() throws Exception {
14231424
client,
14241425
request,
14251426
"Snapshot ["
1426-
+ snapshotId
1427+
+ snapshot
14271428
+ "] contains data stream ["
14281429
+ datastreamName
14291430
+ "] but custer does not have a matching index "

modules/kibana/src/main/java/org/elasticsearch/kibana/KibanaPlugin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class KibanaPlugin extends Plugin implements SystemIndexPlugin {
4343
.setDescription("Onechat system index")
4444
.setType(Type.EXTERNAL_UNMANAGED)
4545
.setAllowedElasticProductOrigins(KIBANA_PRODUCT_ORIGIN)
46+
.setAllowsTemplates()
4647
.build();
4748

4849
public static final SystemIndexDescriptor APM_AGENT_CONFIG_INDEX_DESCRIPTOR = SystemIndexDescriptor.builder()

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,6 @@ tests:
274274
- class: org.elasticsearch.cli.keystore.AddStringKeyStoreCommandTests
275275
method: testStdinWithMultipleValues
276276
issue: https://github.com/elastic/elasticsearch/issues/126882
277-
- class: org.elasticsearch.xpack.remotecluster.CrossClusterEsqlRCS2EnrichUnavailableRemotesIT
278-
method: testEsqlEnrichWithSkipUnavailable
279-
issue: https://github.com/elastic/elasticsearch/issues/127368
280277
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
281278
method: test {p0=ml/data_frame_analytics_cat_apis/Test cat data frame analytics all jobs with header}
282279
issue: https://github.com/elastic/elasticsearch/issues/127625

server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/TransportRestoreSnapshotAction.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.elasticsearch.cluster.ClusterState;
1717
import org.elasticsearch.cluster.block.ClusterBlockException;
1818
import org.elasticsearch.cluster.block.ClusterBlockLevel;
19+
import org.elasticsearch.cluster.project.ProjectResolver;
1920
import org.elasticsearch.cluster.service.ClusterService;
2021
import org.elasticsearch.injection.guice.Inject;
2122
import org.elasticsearch.snapshots.RestoreService;
@@ -29,14 +30,16 @@
2930
public class TransportRestoreSnapshotAction extends TransportMasterNodeAction<RestoreSnapshotRequest, RestoreSnapshotResponse> {
3031
public static final ActionType<RestoreSnapshotResponse> TYPE = new ActionType<>("cluster:admin/snapshot/restore");
3132
private final RestoreService restoreService;
33+
private final ProjectResolver projectResolver;
3234

3335
@Inject
3436
public TransportRestoreSnapshotAction(
3537
TransportService transportService,
3638
ClusterService clusterService,
3739
ThreadPool threadPool,
3840
RestoreService restoreService,
39-
ActionFilters actionFilters
41+
ActionFilters actionFilters,
42+
ProjectResolver projectResolver
4043
) {
4144
super(
4245
TYPE.name(),
@@ -49,13 +52,15 @@ public TransportRestoreSnapshotAction(
4952
threadPool.executor(ThreadPool.Names.SNAPSHOT_META)
5053
);
5154
this.restoreService = restoreService;
55+
this.projectResolver = projectResolver;
5256
}
5357

5458
@Override
5559
protected ClusterBlockException checkBlock(RestoreSnapshotRequest request, ClusterState state) {
5660
// Restoring a snapshot might change the global state and create/change an index,
5761
// so we need to check for METADATA_WRITE and WRITE blocks
58-
ClusterBlockException blockException = state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
62+
ClusterBlockException blockException = state.blocks()
63+
.globalBlockedException(projectResolver.getProjectId(), ClusterBlockLevel.METADATA_WRITE);
5964
if (blockException != null) {
6065
return blockException;
6166
}
@@ -70,17 +75,21 @@ protected void masterOperation(
7075
final ClusterState state,
7176
final ActionListener<RestoreSnapshotResponse> listener
7277
) {
73-
restoreService.restoreSnapshot(request, listener.delegateFailure((delegatedListener, restoreCompletionResponse) -> {
74-
if (restoreCompletionResponse.restoreInfo() == null && request.waitForCompletion()) {
75-
RestoreClusterStateListener.createAndRegisterListener(
76-
clusterService,
77-
restoreCompletionResponse,
78-
delegatedListener,
79-
threadPool.getThreadContext()
80-
);
81-
} else {
82-
delegatedListener.onResponse(new RestoreSnapshotResponse(restoreCompletionResponse.restoreInfo()));
83-
}
84-
}));
78+
restoreService.restoreSnapshot(
79+
projectResolver.getProjectId(),
80+
request,
81+
listener.delegateFailure((delegatedListener, restoreCompletionResponse) -> {
82+
if (restoreCompletionResponse.restoreInfo() == null && request.waitForCompletion()) {
83+
RestoreClusterStateListener.createAndRegisterListener(
84+
clusterService,
85+
restoreCompletionResponse,
86+
delegatedListener,
87+
threadPool.getThreadContext()
88+
);
89+
} else {
90+
delegatedListener.onResponse(new RestoreSnapshotResponse(restoreCompletionResponse.restoreInfo()));
91+
}
92+
})
93+
);
8594
}
8695
}

server/src/main/java/org/elasticsearch/action/admin/indices/recovery/TransportRecoveryAction.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.elasticsearch.cluster.block.ClusterBlockException;
1717
import org.elasticsearch.cluster.block.ClusterBlockLevel;
1818
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
19+
import org.elasticsearch.cluster.project.ProjectResolver;
1920
import org.elasticsearch.cluster.routing.ShardRouting;
2021
import org.elasticsearch.cluster.routing.ShardsIterator;
2122
import org.elasticsearch.cluster.service.ClusterService;
@@ -43,14 +44,16 @@
4344
public class TransportRecoveryAction extends TransportBroadcastByNodeAction<RecoveryRequest, RecoveryResponse, RecoveryState> {
4445

4546
private final IndicesService indicesService;
47+
private final ProjectResolver projectResolver;
4648

4749
@Inject
4850
public TransportRecoveryAction(
4951
ClusterService clusterService,
5052
TransportService transportService,
5153
IndicesService indicesService,
5254
ActionFilters actionFilters,
53-
IndexNameExpressionResolver indexNameExpressionResolver
55+
IndexNameExpressionResolver indexNameExpressionResolver,
56+
ProjectResolver projectResolver
5457
) {
5558
super(
5659
RecoveryAction.NAME,
@@ -62,6 +65,7 @@ public TransportRecoveryAction(
6265
transportService.getThreadPool().executor(ThreadPool.Names.MANAGEMENT)
6366
);
6467
this.indicesService = indicesService;
68+
this.projectResolver = projectResolver;
6569
}
6670

6771
@Override
@@ -110,16 +114,16 @@ protected void shardOperation(RecoveryRequest request, ShardRouting shardRouting
110114

111115
@Override
112116
protected ShardsIterator shards(ClusterState state, RecoveryRequest request, String[] concreteIndices) {
113-
return state.routingTable().allShardsIncludingRelocationTargets(concreteIndices);
117+
return state.routingTable(projectResolver.getProjectId()).allShardsIncludingRelocationTargets(concreteIndices);
114118
}
115119

116120
@Override
117121
protected ClusterBlockException checkGlobalBlock(ClusterState state, RecoveryRequest request) {
118-
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ);
122+
return state.blocks().globalBlockedException(projectResolver.getProjectId(), ClusterBlockLevel.METADATA_READ);
119123
}
120124

121125
@Override
122126
protected ClusterBlockException checkRequestBlock(ClusterState state, RecoveryRequest request, String[] concreteIndices) {
123-
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, concreteIndices);
127+
return state.blocks().indicesBlockedException(projectResolver.getProjectId(), ClusterBlockLevel.METADATA_READ, concreteIndices);
124128
}
125129
}

0 commit comments

Comments
 (0)