Skip to content

Commit 0d7e44b

Browse files
authored
Merge branch 'main' into fork
2 parents cb4d29d + ad220c1 commit 0d7e44b

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed

muted-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ tests:
326326
- class: org.elasticsearch.xpack.esql.heap_attack.HeapAttackIT
327327
method: testEnrichExplosionManyMatches
328328
issue: https://github.com/elastic/elasticsearch/issues/122913
329+
- class: org.elasticsearch.xpack.search.AsyncSearchSecurityIT
330+
issue: https://github.com/elastic/elasticsearch/issues/122940
329331

330332
# Examples:
331333
#

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2925,7 +2925,7 @@ protected void commitIndexWriter(final IndexWriter writer, final Translog transl
29252925
* {@link IndexWriter#commit()} call flushes all documents, we defer computation of the maximum sequence number to the time
29262926
* of invocation of the commit data iterator (which occurs after all documents have been flushed to Lucene).
29272927
*/
2928-
final Map<String, String> extraCommitUserData = getCommitExtraUserData();
2928+
final Map<String, String> extraCommitUserData = getCommitExtraUserData(localCheckpoint);
29292929
final Map<String, String> commitData = Maps.newMapWithExpectedSize(8 + extraCommitUserData.size());
29302930
commitData.putAll(extraCommitUserData);
29312931
commitData.put(Translog.TRANSLOG_UUID_KEY, translog.getTranslogUUID());
@@ -2973,8 +2973,10 @@ protected void commitIndexWriter(final IndexWriter writer, final Translog transl
29732973
/**
29742974
* Allows InternalEngine extenders to return custom key-value pairs which will be included in the Lucene commit user-data. Custom user
29752975
* data keys can be overwritten by if their keys conflict keys used by InternalEngine.
2976+
*
2977+
* @param localCheckpoint the local checkpoint of the commit
29762978
*/
2977-
protected Map<String, String> getCommitExtraUserData() {
2979+
protected Map<String, String> getCommitExtraUserData(final long localCheckpoint) {
29782980
return Collections.emptyMap();
29792981
}
29802982

server/src/main/java/org/elasticsearch/index/shard/IndexShard.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4491,14 +4491,17 @@ public void waitForEngineOrClosedShard(ActionListener<Void> listener) {
44914491
}
44924492

44934493
/**
4494-
* Registers a listener for an event when the shard advances to the provided primary term and segment generation
4494+
* Registers a listener for an event when the shard advances to the provided primary term and segment generation.
4495+
* Completes the listener with a {@link IndexShardClosedException} if the shard is closed.
44954496
*/
44964497
public void waitForPrimaryTermAndGeneration(long primaryTerm, long segmentGeneration, ActionListener<Long> listener) {
4497-
waitForEngineOrClosedShard(
4498-
listener.delegateFailureAndWrap(
4499-
(l, ignored) -> getEngine().addPrimaryTermAndGenerationListener(primaryTerm, segmentGeneration, l)
4500-
)
4501-
);
4498+
waitForEngineOrClosedShard(listener.delegateFailureAndWrap((l, ignored) -> {
4499+
if (state == IndexShardState.CLOSED) {
4500+
l.onFailure(new IndexShardClosedException(shardId));
4501+
} else {
4502+
getEngine().addPrimaryTermAndGenerationListener(primaryTerm, segmentGeneration, l);
4503+
}
4504+
}));
45024505
}
45034506

45044507
/**

server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7327,7 +7327,7 @@ public void testExtraUserDataIsCommitted() throws IOException {
73277327
engine.close();
73287328
engine = new InternalEngine(engine.config()) {
73297329
@Override
7330-
protected Map<String, String> getCommitExtraUserData() {
7330+
protected Map<String, String> getCommitExtraUserData(final long localCheckpoint) {
73317331
return Map.of("userkey", "userdata", ES_VERSION, IndexVersions.ZERO.toString());
73327332
}
73337333
};

server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.lucene.util.BytesRef;
2828
import org.apache.lucene.util.Constants;
2929
import org.elasticsearch.ElasticsearchException;
30+
import org.elasticsearch.ExceptionsHelper;
3031
import org.elasticsearch.action.ActionListener;
3132
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
3233
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
@@ -3334,6 +3335,21 @@ public void testWaitForClosedListener() throws IOException {
33343335
assertThat("listener should have been called", called.get(), equalTo(true));
33353336
}
33363337

3338+
public void testWaitForPrimaryTermAndGenerationFailsForClosedShard() throws IOException {
3339+
Settings settings = indexSettings(IndexVersion.current(), 1, 1).build();
3340+
IndexMetadata metadata = IndexMetadata.builder("test").putMapping("""
3341+
{ "properties": { "foo": { "type": "text"}}}""").settings(settings).primaryTerm(0, 1).build();
3342+
IndexShard initializingShard = newShard(new ShardId(metadata.getIndex(), 0), true, "n1", metadata, null);
3343+
3344+
var future = new PlainActionFuture<Long>();
3345+
initializingShard.waitForPrimaryTermAndGeneration(0L, 0L, future);
3346+
3347+
assertFalse("waitForPrimaryTermAndGeneration should be waiting", future.isDone());
3348+
closeShards(initializingShard);
3349+
// Should bail out earlier without calling the engine
3350+
assertNotNull(ExceptionsHelper.unwrap(expectThrows(Exception.class, future::get), IndexShardClosedException.class));
3351+
}
3352+
33373353
public void testRecoverFromLocalShard() throws IOException {
33383354
Settings settings = indexSettings(IndexVersion.current(), 1, 1).build();
33393355
IndexMetadata metadata = IndexMetadata.builder("source")

0 commit comments

Comments
 (0)