@@ -1351,6 +1351,18 @@ public SeqNoStats seqNoStats() {
13511351 return getEngine ().getSeqNoStats (replicationTracker .getGlobalCheckpoint ());
13521352 }
13531353
1354+ /**
1355+ * Returns a supplier that supplies the {@link SeqNoStats} of the engine that is referenced at the time this method is called.
1356+ * Uses this method in place where the current engine reference cannot be resolved directly.
1357+ *
1358+ * @return a supplier of {@link SeqNoStats}
1359+ * @throws AlreadyClosedException if shard is closed
1360+ */
1361+ public Supplier <SeqNoStats > getSeqNoStatsSupplier () {
1362+ var engine = getEngine ();
1363+ return () -> engine .getSeqNoStats (replicationTracker .getGlobalCheckpoint ());
1364+ }
1365+
13541366 public IndexingStats indexingStats () {
13551367 Engine engine = getEngineOrNull ();
13561368 final boolean throttled ;
@@ -2974,6 +2986,18 @@ public long getLocalCheckpoint() {
29742986 return getEngine ().getPersistedLocalCheckpoint ();
29752987 }
29762988
2989+ /**
2990+ * Returns a supplier that supplies the local checkpoint of the engine that is referenced at the time this method is called.
2991+ * Uses this method in place where the current engine reference cannot be resolved directly.
2992+ *
2993+ * @return a supplier of the local checkpoint
2994+ * @throws AlreadyClosedException if shard is closed
2995+ */
2996+ public Supplier <Long > getLocalCheckpointSupplier () {
2997+ var engine = getEngine ();
2998+ return () -> engine .getPersistedLocalCheckpoint ();
2999+ }
3000+
29773001 /**
29783002 * Returns the global checkpoint for the shard.
29793003 *
@@ -2990,6 +3014,18 @@ public long getLastSyncedGlobalCheckpoint() {
29903014 return getEngine ().getLastSyncedGlobalCheckpoint ();
29913015 }
29923016
3017+ /**
3018+ * Returns a supplier that supplies the latest global checkpoint of the engine that is referenced at the time this method is called.
3019+ * Uses this method in place where the current engine reference cannot be resolved directly.
3020+ *
3021+ * @return a supplier of the latest global checkpoint value that has been persisted in the underlying storage
3022+ * @throws AlreadyClosedException if shard is closed
3023+ */
3024+ public Supplier <Long > getLastSyncedGlobalCheckpointSupplier () {
3025+ var engine = getEngine ();
3026+ return () -> engine .getLastSyncedGlobalCheckpoint ();
3027+ }
3028+
29933029 /**
29943030 * Get the local knowledge of the global checkpoints for all in-sync allocation IDs.
29953031 *
@@ -3012,8 +3048,22 @@ public void maybeSyncGlobalCheckpoint(final String reason) {
30123048 return ;
30133049 }
30143050 assert assertPrimaryMode ();
3015- // only sync if there are no operations in flight, or when using async durability
30163051 final SeqNoStats stats = getEngine ().getSeqNoStats (replicationTracker .getGlobalCheckpoint ());
3052+ doMaybeSyncGlobalCheckpoint (reason , stats );
3053+ }
3054+
3055+ public void maybeSyncGlobalCheckpoint (final String reason , final SeqNoStats stats ) {
3056+ verifyNotClosed ();
3057+ assert shardRouting .primary () : "only call maybeSyncGlobalCheckpoint on primary shard" ;
3058+ if (replicationTracker .isPrimaryMode () == false ) {
3059+ return ;
3060+ }
3061+ assert assertPrimaryMode ();
3062+ doMaybeSyncGlobalCheckpoint (reason , stats );
3063+ }
3064+
3065+ private void doMaybeSyncGlobalCheckpoint (final String reason , final SeqNoStats stats ) {
3066+ // only sync if there are no operations in flight, or when using async durability
30173067 final boolean asyncDurability = indexSettings ().getTranslogDurability () == Translog .Durability .ASYNC ;
30183068 if (stats .getMaxSeqNo () == stats .getGlobalCheckpoint () || asyncDurability ) {
30193069 final var trackedGlobalCheckpointsNeedSync = replicationTracker .trackedGlobalCheckpointsNeedSync ();
0 commit comments