-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kvserver/gc: remove range tombstones during GC
Previously range tombstones were taken into account when doing point key GC, but were never removed themselves. This PR is adding support for removal of old range keys. This PR is extending GCRequest to include range tombstones. Range tombstones are populated by GC in requests sent after all the point keys under the GC threshold are deleted thus guaranteeing that point keys are not accidentally exposed. When processing GC range tombstone requests, replica does an addtional step to validate these assumptions and fail deletions if there's data still covered by range tombstones. Release note: None
- Loading branch information
1 parent
3c0dc6f
commit 285aead
Showing
20 changed files
with
2,048 additions
and
146 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2022 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package batcheval | ||
|
||
import "github.com/cockroachdb/cockroach/pkg/roachpb" | ||
|
||
// rangeTombstonePeekBounds returns the left and right bounds that | ||
// MVCCDeleteRangeUsingTombstone can read in order to detect adjacent range | ||
// tombstones to merge with or fragment. The bounds will be truncated to the | ||
// Raft range bounds if given. | ||
func rangeTombstonePeekBounds( | ||
startKey, endKey, rangeStart, rangeEnd roachpb.Key, | ||
) (roachpb.Key, roachpb.Key) { | ||
leftPeekBound := startKey.Prevish(roachpb.PrevishKeyLength) | ||
if len(rangeStart) > 0 && leftPeekBound.Compare(rangeStart) <= 0 { | ||
leftPeekBound = rangeStart | ||
} | ||
|
||
rightPeekBound := endKey.Next() | ||
if len(rangeEnd) > 0 && rightPeekBound.Compare(rangeEnd) >= 0 { | ||
rightPeekBound = rangeEnd | ||
} | ||
|
||
return leftPeekBound.Clone(), rightPeekBound.Clone() | ||
} |
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,117 @@ | ||
// Copyright 2022 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package batcheval | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/roachpb" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestMergeGCRangeBoundaries(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
|
||
gcr := func(start, end roachpb.Key) roachpb.GCRequest_GCRangeKey { | ||
return roachpb.GCRequest_GCRangeKey{ | ||
StartKey: start, | ||
EndKey: end, | ||
} | ||
} | ||
span := func(start, end roachpb.Key) roachpb.Span { | ||
return roachpb.Span{ | ||
Key: start, | ||
EndKey: end, | ||
} | ||
} | ||
key := func(k string) roachpb.Key { | ||
return roachpb.Key(k) | ||
} | ||
preKey := func(k string) roachpb.Key { | ||
l, _ := rangeTombstonePeekBounds(key(k), key(k+"zzzzzzz"), nil, nil) | ||
return l | ||
} | ||
postKey := func(k string) roachpb.Key { | ||
_, r := rangeTombstonePeekBounds(key(""), key(k), nil, nil) | ||
return r | ||
} | ||
|
||
for _, d := range []struct { | ||
name string | ||
rangeStart roachpb.Key | ||
rangeEnd roachpb.Key | ||
rangeKeys []roachpb.GCRequest_GCRangeKey | ||
spans []roachpb.Span | ||
}{ | ||
{ | ||
name: "empty", | ||
rangeStart: key("a"), | ||
rangeEnd: key("b"), | ||
rangeKeys: []roachpb.GCRequest_GCRangeKey{}, | ||
spans: nil, | ||
}, | ||
{ | ||
name: "full range", | ||
rangeStart: key("a"), | ||
rangeEnd: key("b"), | ||
rangeKeys: []roachpb.GCRequest_GCRangeKey{ | ||
gcr(key("a"), key("b")), | ||
}, | ||
spans: []roachpb.Span{ | ||
span(key("a"), key("b")), | ||
}, | ||
}, | ||
{ | ||
name: "sub range", | ||
rangeStart: key("a"), | ||
rangeEnd: key("z"), | ||
rangeKeys: []roachpb.GCRequest_GCRangeKey{ | ||
gcr(key("c"), key("d")), | ||
}, | ||
spans: []roachpb.Span{ | ||
span(preKey("c"), postKey("d")), | ||
}, | ||
}, | ||
{ | ||
name: "non adjacent", | ||
rangeStart: key("a"), | ||
rangeEnd: key("z"), | ||
rangeKeys: []roachpb.GCRequest_GCRangeKey{ | ||
gcr(key("c"), key("d")), | ||
gcr(key("e"), key("f")), | ||
}, | ||
spans: []roachpb.Span{ | ||
span(preKey("c"), postKey("d")), | ||
span(preKey("e"), postKey("f")), | ||
}, | ||
}, | ||
{ | ||
name: "merge adjacent", | ||
rangeStart: key("a"), | ||
rangeEnd: key("z"), | ||
rangeKeys: []roachpb.GCRequest_GCRangeKey{ | ||
gcr(key("a"), key("b")), | ||
gcr(key("b"), key("c")), | ||
gcr(key("c"), key("d")), | ||
}, | ||
spans: []roachpb.Span{ | ||
span(key("a"), postKey("d")), | ||
}, | ||
}, | ||
} { | ||
t.Run(d.name, func(t *testing.T) { | ||
spans := makeLookupBoundariesForGCRanges(d.rangeStart, d.rangeEnd, d.rangeKeys) | ||
merged := mergeAdjacentSpans(spans) | ||
require.Equal(t, d.spans, merged, "combined spans") | ||
}) | ||
} | ||
} |
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.