Skip to content
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

Simplify computation of whether a GCP sync is needed #84865

Conversation

DaveCTurner
Copy link
Contributor

We do a bunch of allocation simply to compute whether any replica's
global checkpoint lags behind the primary. With this commit we skip all
that jazz and just use a loop.

We do a bunch of allocation simply to compute whether any replica's
global checkpoint lags behind the primary. With this commit we skip all
that jazz and just use a loop.
@DaveCTurner DaveCTurner added :Distributed Indexing/CRUD A catch all label for issues around indexing, updating and getting a doc by id. Not search. >refactoring v8.2.0 labels Mar 10, 2022
@elasticmachine elasticmachine added the Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. label Mar 10, 2022
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

Copy link
Member

@original-brownbear original-brownbear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 questions but looks just fine overall :)

@@ -2690,17 +2689,15 @@ public void maybeSyncGlobalCheckpoint(final String reason) {
final SeqNoStats stats = getEngine().getSeqNoStats(replicationTracker.getGlobalCheckpoint());
final boolean asyncDurability = indexSettings().getTranslogDurability() == Translog.Durability.ASYNC;
if (stats.getMaxSeqNo() == stats.getGlobalCheckpoint() || asyncDurability) {
final ObjectLongMap<String> globalCheckpoints = getInSyncGlobalCheckpoints();
final long globalCheckpoint = replicationTracker.getGlobalCheckpoint();
final var trackedGlobalCheckpointsNeedSync = replicationTracker.trackedGlobalCheckpointsNeedSync();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make sense to keep this in line in the conditional since it's an OR so maybe we don't need to evaluate it all the time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ehh maybe, I didn't want to have to reason about whether the ordering between this and checking replication tracker.pendingInSync() was important. Still the expensive bit is getInSyncGlobalCheckpoints() which we did every time anyway, and asyncDurability is almost always false so I doubt it makes much difference.

/**
* @return true iff any tracked global checkpoint for an in-sync copy lags behind our global checkpoint
*/
public synchronized boolean trackedGlobalCheckpointsNeedSync() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to synchronize here when previously we didn't synchronize while running the same loop?
Was this a bug before?

Copy link
Contributor Author

@DaveCTurner DaveCTurner Mar 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously we were synchronized in the loop within ReplicationTracker#getInSyncGlobalCheckpoints() that iterates over ReplicationTracker#checkpoints.

Copy link
Member

@original-brownbear original-brownbear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, sorry for 2 stupid questions :)

@DaveCTurner DaveCTurner merged commit 4814da7 into elastic:master Mar 10, 2022
@DaveCTurner
Copy link
Contributor Author

😁 better than suppressing an insightful question tho...

@DaveCTurner DaveCTurner deleted the 2022-03-10-replication-tracker-trackedGlobalCheckpointsNeedSync branch March 10, 2022 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Indexing/CRUD A catch all label for issues around indexing, updating and getting a doc by id. Not search. >refactoring Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. v8.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants