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

kvserver: factor out replica loading phase #96424

Merged
merged 5 commits into from
Feb 7, 2023

Conversation

pav-kv
Copy link
Collaborator

@pav-kv pav-kv commented Feb 2, 2023

This commit factors out Replica state loading and invariant checking so that it
is more consolidated rather than interleaved into Replica creation. Replica
creation path was loading this state, to post-factum assert that the in-memory
state matches the state in storage. Now this is a pre-requisite and input into
creating the Replica, and turning it from uninitialized to initialized state.

This change also eliminates the concept of "unloaded" Replica. Now the Replica
is created in a valid state (either initialized or uninitialized).

Touches #93898

@pav-kv pav-kv requested a review from tbg February 2, 2023 12:24
@pav-kv pav-kv requested a review from a team as a code owner February 2, 2023 12:24
@cockroach-teamcity
Copy link
Member

This change is Reviewable

pkg/kv/kvserver/replica_init.go Outdated Show resolved Hide resolved
pkg/kv/kvserver/replica_init.go Outdated Show resolved Hide resolved
pkg/kv/kvserver/replica_init.go Outdated Show resolved Hide resolved
pkg/kv/kvserver/store.go Outdated Show resolved Hide resolved
pkg/kv/kvserver/replica_init.go Outdated Show resolved Hide resolved
if r.mu.state.Lease.Sequence > 0 {
r.mu.minLeaseProposedTS = r.Clock().NowAsClockTimestamp()
}

r.assertStateRaftMuLockedReplicaMuRLocked(ctx, r.store.Engine())
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This line can probably go away. I didn't like the invariant break conditional to r.store.TestingKnobs().DisableEagerReplicaRemoval, but I think it should not be the case on replica creation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also, assertStateRaftMuLockedReplicaMuRLocked can be implemented using loadReplicaState now, but I'm not sure what to do about this invariant exception.

Copy link
Member

@tbg tbg left a comment

Choose a reason for hiding this comment

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

The code LGTM, but I need to understand better where the journey is going to understand if we are moving in the right direction.

pkg/kv/kvserver/replica_init.go Outdated Show resolved Hide resolved
pkg/kv/kvserver/replica_init.go Outdated Show resolved Hide resolved
}

// loadReplicaState loads the state necessary to create a Replica from storage.
func loadReplicaState(
Copy link
Member

Choose a reason for hiding this comment

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

Can you say here what desc is in the case of an united replica?

Copy link
Member

Choose a reason for hiding this comment

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

we could:

  • change stateloader.Load to take the StartKey of the desc instead of the desc
  • then load the desc from disk
  • then in this method, we don't have to take a desc, but we only take a FullRangeID and an optional StartKey
  • profit?

Doesn't have to happen now just wanted to put it into your head.

pkg/kv/kvserver/replica_init.go Outdated Show resolved Hide resolved
pkg/kv/kvserver/replica_init.go Outdated Show resolved Hide resolved
pkg/kv/kvserver/replica_init.go Outdated Show resolved Hide resolved
@pav-kv pav-kv requested a review from tbg February 2, 2023 15:36
Copy link
Member

@tbg tbg left a comment

Choose a reason for hiding this comment

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

Fix-up commit looks good. I think we should button this PR up and keep moving, perhaps adding a few more comments about things that are in flux in the code with a direction in which they should move. Mostly to document this in case we get pulled off the case for some reason or other.

I'm pretty interested in seeing the initialization transition cleaned up, since it's extremely brittle and verifying anything takes too much time. Let's discuss early next week.

@pav-kv pav-kv force-pushed the load_replica branch 4 times, most recently from 019b301 to 09563ae Compare February 6, 2023 19:17
@pav-kv pav-kv requested a review from tbg February 6, 2023 19:18
@pav-kv
Copy link
Collaborator Author

pav-kv commented Feb 6, 2023

@tbg I reverted things a bit, so that this PR is only about factoring out the loading phase. PTAL.
Also, moved things to kvstorage and started integrating with kvstorage.Replica.

@pav-kv pav-kv requested a review from a team as a code owner February 6, 2023 20:37
@pav-kv pav-kv requested a review from a team February 6, 2023 20:37
@pav-kv pav-kv requested a review from a team as a code owner February 6, 2023 20:37
@pav-kv pav-kv requested a review from jbowens February 6, 2023 20:37
This commit factors out Replica state loading and invariant checking so that it
is more consolidated rather than interleaved into Replica creation. Replica
creation path was loading this state, to post-factum assert that the in-memory
state matches the state in storage. Now this is a pre-requisite and input into
creating the Replica, and turning it from uninitialized to initialized state.

This change also eliminates the concept of "unloaded" Replica. Now the Replica
is created in a valid state (either initialized or uninitialized).

Release note: none
Epic: none
Copy link
Member

@tbg tbg left a comment

Choose a reason for hiding this comment

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

Nice! The comments don't need to be addressed in this PR.

pkg/kv/kvserver/store.go Outdated Show resolved Hide resolved
Release note: none
Epic: none
@pav-kv
Copy link
Collaborator Author

pav-kv commented Feb 7, 2023

bors r=tbg

@craig
Copy link
Contributor

craig bot commented Feb 7, 2023

Build failed (retrying...):

@pav-kv
Copy link
Collaborator Author

pav-kv commented Feb 7, 2023

bors retry

@craig
Copy link
Contributor

craig bot commented Feb 7, 2023

Already running a review

@pav-kv
Copy link
Collaborator Author

pav-kv commented Feb 7, 2023

bors retry

@craig
Copy link
Contributor

craig bot commented Feb 7, 2023

Already running a review

@pav-kv
Copy link
Collaborator Author

pav-kv commented Feb 7, 2023

bors cancel

@craig
Copy link
Contributor

craig bot commented Feb 7, 2023

Canceled.

@pav-kv
Copy link
Collaborator Author

pav-kv commented Feb 7, 2023

bors retry

@pav-kv
Copy link
Collaborator Author

pav-kv commented Feb 7, 2023

bors r=tbg

@craig craig bot merged commit 75eb88d into cockroachdb:master Feb 7, 2023
@craig
Copy link
Contributor

craig bot commented Feb 7, 2023

Build succeeded:

@pav-kv pav-kv deleted the load_replica branch February 7, 2023 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants