Skip to content

Commit c204dd7

Browse files
committed
Merge branch 'main' of https://github.com/elastic/elasticsearch into esql-inference-runner-refactoring
2 parents a4952a0 + 9ad04ff commit c204dd7

File tree

29 files changed

+331
-98
lines changed

29 files changed

+331
-98
lines changed

docs/reference/query-languages/esql/_snippets/functions/layout/categorize.md

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/layout/sample.md

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/layout/scalb.md

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/parameters/categorize.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/src/internalClusterTest/java/org/elasticsearch/indices/IndexingMemoryControllerIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ EngineConfig engineConfigWithLargerIndexingMemory(EngineConfig config) {
8989
config.isPromotableToPrimary(),
9090
config.getMapperService(),
9191
config.getEngineResetLock(),
92-
config.getMergeMetrics()
92+
config.getMergeMetrics(),
93+
config.getIndexDeletionPolicyWrapper()
9394
);
9495
}
9596

server/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ public boolean hasGlobalBlock(ClusterBlock block) {
165165
return global.contains(block);
166166
}
167167

168+
public boolean hasGlobalBlock(ProjectId projectId, ClusterBlock block) {
169+
return global(projectId).contains(block);
170+
}
171+
168172
public boolean hasGlobalBlockWithId(final int blockId) {
169173
for (ClusterBlock clusterBlock : global) {
170174
if (clusterBlock.id() == blockId) {

server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,28 @@ public <K, V> Map<K, V> readMapValues(final Writeable.Reader<V> valueReader, fin
802802
return map;
803803
}
804804

805+
/**
806+
* Reads a multiple {@code V}-values and then converts them to a {@code Map} using keyMapper.
807+
*
808+
* @param valueReader The value reader
809+
* @param keyMapper function to create a key from a value
810+
* @param constructor map constructor
811+
* @return Never {@code null}.
812+
*/
813+
public <K, V, M extends Map<K, V>> M readMapValues(
814+
final Writeable.Reader<V> valueReader,
815+
final Function<V, K> keyMapper,
816+
final IntFunction<M> constructor
817+
) throws IOException {
818+
final int size = readArraySize();
819+
final M map = constructor.apply(size);
820+
for (int i = 0; i < size; i++) {
821+
V value = valueReader.read(this);
822+
map.put(keyMapper.apply(value), value);
823+
}
824+
return map;
825+
}
826+
805827
/**
806828
* If the returned map contains any entries it will be mutable. If it is empty it might be immutable.
807829
*/

server/src/main/java/org/elasticsearch/common/lucene/FilterIndexCommit.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,11 @@ public Map<String, String> getUserData() throws IOException {
7171
public String toString() {
7272
return "FilterIndexCommit{" + "in=" + in + '}';
7373
}
74+
75+
public static IndexCommit unwrap(IndexCommit in) {
76+
while (in instanceof FilterIndexCommit) {
77+
in = ((FilterIndexCommit) in).getIndexCommit();
78+
}
79+
return in;
80+
}
7481
}

server/src/main/java/org/elasticsearch/index/engine/CombinedDeletionPolicy.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* In particular, this policy will delete index commits whose max sequence number is at most
3939
* the current global checkpoint except the index commit which has the highest max sequence number among those.
4040
*/
41-
public class CombinedDeletionPolicy extends IndexDeletionPolicy {
41+
public class CombinedDeletionPolicy extends ElasticsearchIndexDeletionPolicy {
4242
private final Logger logger;
4343
private final TranslogDeletionPolicy translogDeletionPolicy;
4444
private final SoftDeletesPolicy softDeletesPolicy;
@@ -48,13 +48,6 @@ public class CombinedDeletionPolicy extends IndexDeletionPolicy {
4848
// when checking for externally acquired index commits that haven't been released
4949
private final Set<IndexCommit> internallyAcquiredIndexCommits;
5050

51-
interface CommitsListener {
52-
53-
void onNewAcquiredCommit(IndexCommit commit, Set<String> additionalFiles);
54-
55-
void onDeletedCommit(IndexCommit commit);
56-
}
57-
5851
@Nullable
5952
private final CommitsListener commitsListener;
6053

@@ -187,7 +180,6 @@ private void deleteCommit(IndexCommit commit) throws IOException {
187180
assert commit.isDeleted() == false : "Index commit [" + commitDescription(commit) + "] is deleted twice";
188181
logger.debug("Delete index commit [{}]", commitDescription(commit));
189182
commit.delete();
190-
assert commit.isDeleted() : "Deletion commit [" + commitDescription(commit) + "] was suppressed";
191183
}
192184

193185
private void updateRetentionPolicy() throws IOException {
@@ -204,7 +196,8 @@ protected int getDocCountOfCommit(IndexCommit indexCommit) throws IOException {
204196
return SegmentInfos.readCommit(indexCommit.getDirectory(), indexCommit.getSegmentsFileName()).totalMaxDoc();
205197
}
206198

207-
SafeCommitInfo getSafeCommitInfo() {
199+
@Override
200+
public SafeCommitInfo getSafeCommitInfo() {
208201
return safeCommitInfo;
209202
}
210203

@@ -214,7 +207,8 @@ SafeCommitInfo getSafeCommitInfo() {
214207
*
215208
* @param acquiringSafeCommit captures the most recent safe commit point if true; otherwise captures the most recent commit point.
216209
*/
217-
synchronized IndexCommit acquireIndexCommit(boolean acquiringSafeCommit) {
210+
@Override
211+
public synchronized IndexCommit acquireIndexCommit(boolean acquiringSafeCommit) {
218212
return acquireIndexCommit(acquiringSafeCommit, false);
219213
}
220214

@@ -241,7 +235,8 @@ protected IndexCommit wrapCommit(IndexCommit indexCommit, boolean acquiredIntern
241235
*
242236
* @return true if the acquired commit can be clean up.
243237
*/
244-
synchronized boolean releaseCommit(final IndexCommit acquiredCommit) {
238+
@Override
239+
public synchronized boolean releaseIndexCommit(final IndexCommit acquiredCommit) {
245240
final SnapshotIndexCommit snapshotIndexCommit = (SnapshotIndexCommit) acquiredCommit;
246241
final IndexCommit releasingCommit = snapshotIndexCommit.getIndexCommit();
247242
assert acquiredIndexCommits.containsKey(releasingCommit)
@@ -316,7 +311,8 @@ private static Set<String> listOfNewFileNames(IndexCommit previous, IndexCommit
316311
/**
317312
* Checks whether the deletion policy is holding on to externally acquired index commits
318313
*/
319-
synchronized boolean hasAcquiredIndexCommitsForTesting() {
314+
@Override
315+
public synchronized boolean hasAcquiredIndexCommitsForTesting() {
320316
// We explicitly check only external commits and disregard internal commits acquired by the commits listener
321317
for (var e : acquiredIndexCommits.entrySet()) {
322318
if (internallyAcquiredIndexCommits.contains(e.getKey()) == false || e.getValue() > 1) {
@@ -329,7 +325,8 @@ synchronized boolean hasAcquiredIndexCommitsForTesting() {
329325
/**
330326
* Checks if the deletion policy can delete some index commits with the latest global checkpoint.
331327
*/
332-
boolean hasUnreferencedCommits() {
328+
@Override
329+
public boolean hasUnreferencedCommits() {
333330
return maxSeqNoOfNextSafeCommit <= globalCheckpointSupplier.getAsLong();
334331
}
335332

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* 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".
8+
*/
9+
10+
package org.elasticsearch.index.engine;
11+
12+
import org.apache.lucene.index.IndexCommit;
13+
import org.apache.lucene.index.IndexDeletionPolicy;
14+
15+
import java.util.Set;
16+
17+
public abstract class ElasticsearchIndexDeletionPolicy extends IndexDeletionPolicy {
18+
19+
/**
20+
* Captures the most recent commit point or the most recent safe commit point.
21+
* Index files of the capturing commit point won't be released until the commit reference is closed.
22+
*
23+
* @param acquiringSafeCommit captures the most recent safe commit point if true; otherwise captures the most recent commit point.
24+
*/
25+
public abstract IndexCommit acquireIndexCommit(boolean acquiringSafeCommit);
26+
27+
/**
28+
* Releases an index commit that was acquired by {@link #acquireIndexCommit(boolean)}.
29+
*
30+
* @return true if the acquired commit can be clean up.
31+
*/
32+
public abstract boolean releaseIndexCommit(IndexCommit acquiredIndexCommit);
33+
34+
/**
35+
* @return information about the safe commit
36+
*/
37+
public abstract SafeCommitInfo getSafeCommitInfo();
38+
39+
public abstract boolean hasAcquiredIndexCommitsForTesting();
40+
41+
public abstract boolean hasUnreferencedCommits();
42+
43+
public interface CommitsListener {
44+
45+
void onNewAcquiredCommit(IndexCommit commit, Set<String> additionalFiles);
46+
47+
void onDeletedCommit(IndexCommit commit);
48+
}
49+
}

0 commit comments

Comments
 (0)