Skip to content

Commit 181b2e7

Browse files
committed
Pass transient extra data on new commits
Relates ES-10718
1 parent b3959b6 commit 181b2e7

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,21 @@ public interface IndexCommitListener {
377377
* {@link IndexCommitRef} prevents the {@link IndexCommitRef} files to be deleted from disk until the reference is closed. As such,
378378
* the listener must close the reference as soon as it is done with it.
379379
*
380-
* @param shardId the {@link ShardId} of shard
381-
* @param store the index shard store
382-
* @param primaryTerm the shard's primary term value
383-
* @param indexCommitRef a reference on the newly created index commit
384-
* @param additionalFiles the set of filenames that are added by the new commit
380+
* @param shardId the {@link ShardId} of shard
381+
* @param store the index shard store
382+
* @param primaryTerm the shard's primary term value
383+
* @param indexCommitRef a reference on the newly created index commit
384+
* @param additionalFiles the set of filenames that are added by the new commit
385+
* @param extraTransientData extra transient data relevant to the new commit
385386
*/
386-
void onNewCommit(ShardId shardId, Store store, long primaryTerm, IndexCommitRef indexCommitRef, Set<String> additionalFiles);
387+
void onNewCommit(
388+
ShardId shardId,
389+
Store store,
390+
long primaryTerm,
391+
IndexCommitRef indexCommitRef,
392+
Set<String> additionalFiles,
393+
Map<String, String> extraTransientData
394+
);
387395

388396
/**
389397
* This method is invoked after the policy deleted the given {@link IndexCommit}. A listener is never notified of a deleted commit

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,14 @@ public void onNewAcquiredCommit(final IndexCommit commit, final Set<String> addi
395395
final IndexCommitRef indexCommitRef = acquireIndexCommitRef(() -> commit);
396396
var primaryTerm = config().getPrimaryTermSupplier().getAsLong();
397397
assert indexCommitRef.getIndexCommit() == commit;
398-
wrappedListener.onNewCommit(shardId, store, primaryTerm, indexCommitRef, additionalFiles);
398+
wrappedListener.onNewCommit(
399+
shardId,
400+
store,
401+
primaryTerm,
402+
indexCommitRef,
403+
additionalFiles,
404+
getCommitExtraTransientData()
405+
);
399406
}
400407

401408
@Override
@@ -416,7 +423,8 @@ public void onNewCommit(
416423
Store store,
417424
long primaryTerm,
418425
IndexCommitRef indexCommitRef,
419-
Set<String> additionalFiles
426+
Set<String> additionalFiles,
427+
Map<String, String> extraTransientData
420428
) {
421429
final long nextGen = indexCommitRef.getIndexCommit().getGeneration();
422430
final long prevGen = generation.getAndSet(nextGen);
@@ -427,7 +435,7 @@ public void onNewCommit(
427435
+ prevGen
428436
+ " for shard "
429437
+ shardId;
430-
listener.onNewCommit(shardId, store, primaryTerm, indexCommitRef, additionalFiles);
438+
listener.onNewCommit(shardId, store, primaryTerm, indexCommitRef, additionalFiles, extraTransientData);
431439
}
432440

433441
@Override
@@ -2980,6 +2988,14 @@ protected Map<String, String> getCommitExtraUserData(final long localCheckpoint)
29802988
return Collections.emptyMap();
29812989
}
29822990

2991+
/**
2992+
* Allows InternalEngine extenders to return custom key-value pairs for transient information, that is not stored in the commit, to be
2993+
* included in the {@link org.elasticsearch.index.engine.Engine.IndexCommitListener}'s new commit invocation.
2994+
*/
2995+
protected Map<String, String> getCommitExtraTransientData() {
2996+
return Collections.emptyMap();
2997+
}
2998+
29832999
final void ensureCanFlush() {
29843000
// translog recovery happens after the engine is fully constructed.
29853001
// If we are in this stage we have to prevent flushes from this

server/src/test/java/org/elasticsearch/index/IndexModuleTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,8 @@ public void onNewCommit(
686686
Store store,
687687
long primaryTerm,
688688
Engine.IndexCommitRef indexCommitRef,
689-
Set<String> additionalFiles
689+
Set<String> additionalFiles,
690+
Map<String, String> extraTransientData
690691
) {
691692
lastAcquiredPrimaryTerm.set(primaryTerm);
692693
lastAcquiredCommit.set(indexCommitRef);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7419,7 +7419,8 @@ public void onNewCommit(
74197419
Store store,
74207420
long primaryTerm,
74217421
Engine.IndexCommitRef indexCommitRef,
7422-
Set<String> additionalFiles
7422+
Set<String> additionalFiles,
7423+
Map<String, String> extraTransientData
74237424
) {
74247425
assertNotNull(store);
74257426
assertTrue(store.hasReferences());

0 commit comments

Comments
 (0)