Skip to content

Use withEngine in IndexShard#seqNoStats #129748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,7 @@ public CommitStats commitStats() {
* @throws AlreadyClosedException if shard is closed
*/
public SeqNoStats seqNoStats() {
return getEngine().getSeqNoStats(replicationTracker.getGlobalCheckpoint());
return withEngine(engine -> engine.getSeqNoStats(getLastKnownGlobalCheckpoint()));
}

public IndexingStats indexingStats() {
Expand Down Expand Up @@ -3061,7 +3061,7 @@ public void maybeSyncGlobalCheckpoint(final String reason) {
}
assert assertPrimaryMode();
// only sync if there are no operations in flight, or when using async durability
final SeqNoStats stats = getEngine().getSeqNoStats(replicationTracker.getGlobalCheckpoint());
final SeqNoStats stats = seqNoStats();
final boolean asyncDurability = indexSettings().getTranslogDurability() == Translog.Durability.ASYNC;
if (stats.getMaxSeqNo() == stats.getGlobalCheckpoint() || asyncDurability) {
final var trackedGlobalCheckpointsNeedSync = replicationTracker.trackedGlobalCheckpointsNeedSync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Index getIndex() {
}

long maxSeqNo() {
return shard.getEngine().getSeqNoStats(-1).getMaxSeqNo();
return shard.withEngine(engine -> engine.getSeqNoStats(-1)).getMaxSeqNo();
}

long maxUnsafeAutoIdTimestamp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,13 @@ protected void asyncShardOperation(final Request request, final ShardId shardId,
throws IOException {
final IndexService indexService = indicesService.indexServiceSafe(request.getShard().getIndex());
final IndexShard indexShard = indexService.getShard(request.getShard().id());
final SeqNoStats seqNoStats = indexShard.seqNoStats();
final long lastKnownGlobalCheckpoint = indexShard.getLastKnownGlobalCheckpoint();

if (request.getFromSeqNo() > seqNoStats.getGlobalCheckpoint()) {
if (request.getFromSeqNo() > lastKnownGlobalCheckpoint) {
logger.trace(
"{} waiting for global checkpoint advancement from [{}] to [{}]",
shardId,
seqNoStats.getGlobalCheckpoint(),
lastKnownGlobalCheckpoint,
request.getFromSeqNo()
);
indexShard.addGlobalCheckpointListener(request.getFromSeqNo(), new GlobalCheckpointListeners.GlobalCheckpointListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected static void getGlobalCheckpoints(
Arrays.fill(seqNumbers, SequenceNumbers.UNASSIGNED_SEQ_NO);
return seqNumbers;
});
checkpointsByIndexOfThisNode.get(shardId.getIndexName())[shardId.getId()] = indexShard.seqNoStats().getGlobalCheckpoint();
checkpointsByIndexOfThisNode.get(shardId.getIndexName())[shardId.getId()] = indexShard.getLastKnownGlobalCheckpoint();
++numProcessedShards;
} catch (Exception e) {
logger.atDebug()
Expand Down