forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
storage: make RaftTombstoneKey unreplicated
RaftTombstoneKey was accidentally made a replicated key when it was first introduced, a problem we first realized existed when it was [included in snapshots]. At the time, we included workarounds to skip this key in various places (snapshot application, consistency checker) but of course we have failed to insert further hacks of the same kind elsewhere since (the one that prompting this PR being the stats recomputation on splits, which I'm looking into as part of cockroachdb#20181 -- unfortunately this commit doesn't seem to pertain to that problem) It feels sloppy that we didn't follow through back then, but luckily the damage appears to be limited; it is likely that the replicated existence of this key results in MVCCStats SysBytes inconsistencies, but as it happens, these stats are [already] [very] [inconsistent]. This commit does a few things: - renames the old tombstone key to `RaftIncorrectLegacyTombstoneKey` - introduces a (correctly unreplicated) `RaftTombstoneKey` - introduces a migration. Once activated, only the new tombstone is written, but both tombstones are checked. Additionally, as the node restarts, all legacy tombstones are replaced by correct non-legacy ones. - when applying a snapshot, forcibly delete any legacy tombstone contained within (even before the cluster version is bumped). This prevents new legacy tombstones to trickle on from other nodes. `RaftIncorrectLegacyTombstoneKey` can be purged from the codebase in binaries post v2.1, as at that point all peers have booted with a version that runs the migration. Thus, post v2.1, the replica consistency checker can stop skipping the legacy tombstone key. Fixes cockroachdb#12154. Release note: None [included in snapshots]: cockroachdb#12131 [already]: cockroachdb#20554 [very]: cockroachdb#20996 [inconsistent]: cockroachdb#21070
- Loading branch information
Showing
15 changed files
with
544 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright 2017 The Cockroach Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
// implied. See the License for the specific language governing | ||
// permissions and limitations under the License. | ||
|
||
package storage | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/keys" | ||
"github.com/cockroachdb/cockroach/pkg/roachpb" | ||
"github.com/cockroachdb/cockroach/pkg/storage/engine" | ||
"github.com/cockroachdb/cockroach/pkg/util/hlc" | ||
) | ||
|
||
// clearLegacyTombstone removes the legacy tombstone for the given rangeID, taking | ||
// care to do this without reading from the engine (as is required by one of the | ||
// callers). | ||
func clearLegacyTombstone(eng engine.Writer, rangeID roachpb.RangeID) error { | ||
return eng.Clear(engine.MakeMVCCMetadataKey(keys.RaftTombstoneIncorrectLegacyKey(rangeID))) | ||
} | ||
|
||
// migrateLegacyTombstones rewrites all legacy tombstones into the correct key. | ||
// It can be removed in binaries post v2.1. | ||
func migrateLegacyTombstones(ctx context.Context, eng engine.Engine) error { | ||
var tombstone roachpb.RaftTombstone | ||
handleTombstone := func(rangeID roachpb.RangeID) (more bool, _ error) { | ||
batch := eng.NewBatch() | ||
defer batch.Close() | ||
|
||
tombstoneKey := keys.RaftTombstoneKey(rangeID) | ||
|
||
{ | ||
// If there's already a new-style tombstone, pick the larger NextReplicaID | ||
// (this will be the new-style tombstone's). | ||
var exTombstone roachpb.RaftTombstone | ||
ok, err := engine.MVCCGetProto(ctx, batch, tombstoneKey, | ||
hlc.Timestamp{}, true, nil, &exTombstone) | ||
if err != nil { | ||
return false, err | ||
} | ||
if ok && exTombstone.NextReplicaID > tombstone.NextReplicaID { | ||
tombstone.NextReplicaID = exTombstone.NextReplicaID | ||
} | ||
} | ||
|
||
if err := engine.MVCCPutProto(ctx, batch, nil, tombstoneKey, | ||
hlc.Timestamp{}, nil, &tombstone); err != nil { | ||
return false, err | ||
} | ||
if err := clearLegacyTombstone(batch, rangeID); err != nil { | ||
return false, err | ||
} | ||
// Specify sync==false because we don't want to sync individually, | ||
// but see the end of the surrounding method where we sync explicitly. | ||
err := batch.Commit(false /* sync */) | ||
return err == nil, err | ||
} | ||
err := IterateIDPrefixKeys(ctx, eng, keys.RaftTombstoneIncorrectLegacyKey, &tombstone, | ||
handleTombstone) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Write a final bogus batch so that we get to do a sync commit, which | ||
// implicitly also syncs everything written before. | ||
batch := eng.NewBatch() | ||
defer batch.Close() | ||
|
||
if err := clearLegacyTombstone(batch, 1 /* rangeID */); err != nil { | ||
return err | ||
} | ||
return batch.Commit(true /* sync */) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.