storage: Don't allow preemptive snapshots on initialized replicas #14261
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This prevents preemptive snapshots from silently succeeding, allowing a
replica GC to be intertwined with the creation of a new replica such
that the new replica has no local data.
Also add some verbose logging for replica ID changes.
This PR is honestly more questions than changes. The only real change is moving the
r.mu.replicaID > replicaID
check ahead of thereplicaID == 0
check, and beyond that it's just an extra log statement and questions. Even that change requires some more investigation as it's caused the test to start occasionally timing out due to a failure to ever GC the removed replica (withnot gc'able
messages in the logs), which may or may not be an existing issue that rejecting the preemptive snapshots exposes.I think we also need to do more than this since it's essentially just preventing preemptive snapshots from being applied to existing replicas, but I'm a little wary of making bigger modifications without fully understanding the reasoning/history behind why things are the way they are. In particular, the fact that a
MsgHeartbeat
can seemingly come in and create a replica that doesn't know its own key range which will then fail when it tries to process the heartbeat (as in #14231 (comment)) seems super dangerous, but there may be some reason for doing so that I haven't thought of.Once the questions are resolved, this will:
Fix #14193
Fix #14231
Fix #12574
@cockroachdb/stability
This change is