Skip to content

Commit

Permalink
Add methods for adding generation listeners with primary term (elasti…
Browse files Browse the repository at this point in the history
…c#100899)

Provide a facility to supply the primary term for the engine for a more precise comparison of generations. Deprecate existing `addSegmentGenerationListener` and `waitForSegmentGeneration` methods

Prerequisite for elastic#99752
  • Loading branch information
arteam authored Oct 27, 2023
1 parent 9f9d11e commit 3a806b4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/changelog/100899.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 100899
summary: Add methods for adding generation listeners with primary term
area: Store
type: enhancement
issues: []
12 changes: 12 additions & 0 deletions server/src/main/java/org/elasticsearch/index/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public abstract class Engine implements Closeable {
public static final String SEARCH_SOURCE = "search"; // TODO: Make source of search enum?
public static final String CAN_MATCH_SEARCH_SOURCE = "can_match";
protected static final String DOC_STATS_SOURCE = "doc_stats";
public static final long UNKNOWN_PRIMARY_TERM = -1L;

protected final ShardId shardId;
protected final Logger logger;
Expand Down Expand Up @@ -2114,8 +2115,19 @@ public final EngineConfig getEngineConfig() {

/**
* Allows registering a listener for when the index shard is on a segment generation >= minGeneration.
*
* @deprecated use {@link #addPrimaryTermAndGenerationListener(long, long, ActionListener)} instead.
*/
@Deprecated
public void addSegmentGenerationListener(long minGeneration, ActionListener<Long> listener) {
addPrimaryTermAndGenerationListener(UNKNOWN_PRIMARY_TERM, minGeneration, listener);
}

/**
* Allows registering a listener for when the index shard is on a primary term >= minPrimaryTerm
* and a segment generation >= minGeneration.
*/
public void addPrimaryTermAndGenerationListener(long minPrimaryTerm, long minGeneration, ActionListener<Long> listener) {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4173,7 +4173,18 @@ public String toString() {
return "IndexShard(shardRouting=" + shardRouting + ")";
}

/**
* @deprecated use {@link #waitForPrimaryTermAndGeneration(long, long, ActionListener)} instead.
*/
@Deprecated
public void waitForSegmentGeneration(long segmentGeneration, ActionListener<Long> listener) {
getEngine().addSegmentGenerationListener(segmentGeneration, listener);
waitForPrimaryTermAndGeneration(getOperationPrimaryTerm(), segmentGeneration, listener);
}

/**
* Registers a listener for an event when the shard advances to the provided primary term and segment generation
*/
public void waitForPrimaryTermAndGeneration(long primaryTerm, long segmentGeneration, ActionListener<Long> listener) {
getEngine().addPrimaryTermAndGenerationListener(primaryTerm, segmentGeneration, listener);
}
}

0 comments on commit 3a806b4

Please sign in to comment.