-
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.
70287: spanconfig: introduce spanconfig.StoreWriter (and its impl) r=irfansharif a=irfansharif In #69172 we introduced a spanconfig.StoreReader interface to abstract away the gossiped system config span. We motivated that PR by teasing a future implementation of the same interface, an in-memory data structure to maintain a mapping between between spans and configs (powered through a view over system.span_configurations introduced in [#69047](69047)). This PR introduces just that. Intended (future) usages: - [#69614](69614) introduces the KVWatcher interface, listening in on system.span_configurations. The updates generated by it will be used to populate per-store instantiations of this data structure, with an eye towards providing a "drop-in" replacement of the gossiped system config span (conveniently implementing the sibling spanconfig.StoreReader interface). - [#69661](69661) introduces the SQLWatcher interface, listening in on changes to system.{descriptor,zones} and generating denormalized span config updates for every descriptor/zone config change. These updates will need to be diffed against a spanconfig.StoreWriter populated with the existing contents of KVAccessor to generate the "targeted" diffs KVAccessor expects. Release note: None Co-authored-by: irfan sharif <[email protected]>
- Loading branch information
Showing
15 changed files
with
1,075 additions
and
19 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
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,35 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") | ||
|
||
go_library( | ||
name = "spanconfigstore", | ||
srcs = [ | ||
"shadow.go", | ||
"store.go", | ||
], | ||
importpath = "github.com/cockroachdb/cockroach/pkg/spanconfig/spanconfigstore", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/keys", | ||
"//pkg/roachpb:with-mocks", | ||
"//pkg/spanconfig", | ||
"//pkg/util/interval", | ||
"//pkg/util/log", | ||
"//pkg/util/syncutil", | ||
"@com_github_cockroachdb_errors//:errors", | ||
], | ||
) | ||
|
||
go_test( | ||
name = "spanconfigstore_test", | ||
srcs = ["store_test.go"], | ||
data = glob(["testdata/**"]), | ||
embed = [":spanconfigstore"], | ||
deps = [ | ||
"//pkg/roachpb:with-mocks", | ||
"//pkg/spanconfig", | ||
"//pkg/util/leaktest", | ||
"//pkg/util/randutil", | ||
"@com_github_cockroachdb_datadriven//:datadriven", | ||
"@com_github_stretchr_testify//require", | ||
], | ||
) |
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,91 @@ | ||
// Copyright 2021 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 spanconfigstore | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/roachpb" | ||
"github.com/cockroachdb/cockroach/pkg/spanconfig" | ||
"github.com/cockroachdb/cockroach/pkg/util/log" | ||
"github.com/cockroachdb/errors" | ||
) | ||
|
||
// ShadowReader wraps around two spanconfig.StoreReaders and logs warnings (if | ||
// expensive logging is enabled) when there are divergent results from the two. | ||
type ShadowReader struct { | ||
new, old spanconfig.StoreReader | ||
} | ||
|
||
// NewShadowReader instantiates a new shadow reader. | ||
func NewShadowReader(new, old spanconfig.StoreReader) *ShadowReader { | ||
return &ShadowReader{ | ||
new: new, | ||
old: old, | ||
} | ||
} | ||
|
||
var _ = NewShadowReader // defeat the unused linter. | ||
|
||
var _ spanconfig.StoreReader = &ShadowReader{} | ||
|
||
// NeedsSplit is part of the spanconfig.StoreReader interface. | ||
func (s *ShadowReader) NeedsSplit(ctx context.Context, start, end roachpb.RKey) bool { | ||
newResult := s.new.NeedsSplit(ctx, start, end) | ||
if log.ExpensiveLogEnabled(ctx, 1) { | ||
oldResult := s.old.NeedsSplit(ctx, start, end) | ||
if newResult != oldResult { | ||
log.Warningf(ctx, "needs split: mismatched responses between old result (%t) and new (%t) for start=%s end=%s", | ||
oldResult, newResult, start.String(), end.String()) | ||
} | ||
} | ||
|
||
return newResult | ||
} | ||
|
||
// ComputeSplitKey is part of the spanconfig.StoreReader interface. | ||
func (s *ShadowReader) ComputeSplitKey(ctx context.Context, start, end roachpb.RKey) roachpb.RKey { | ||
newResult := s.new.ComputeSplitKey(ctx, start, end) | ||
if log.ExpensiveLogEnabled(ctx, 1) { | ||
oldResult := s.old.ComputeSplitKey(ctx, start, end) | ||
if !newResult.Equal(oldResult) { | ||
str := func(k roachpb.RKey) string { | ||
if len(k) == 0 { | ||
return "" | ||
} | ||
return k.String() | ||
} | ||
|
||
log.Warningf(ctx, "compute split key: mismatched responses between old result (%s) and new (%s) for start=%s end=%s", | ||
str(oldResult), str(newResult), str(start), str(end)) | ||
} | ||
} | ||
return newResult | ||
} | ||
|
||
// GetSpanConfigForKey is part of the spanconfig.StoreReader interface. | ||
func (s *ShadowReader) GetSpanConfigForKey( | ||
ctx context.Context, key roachpb.RKey, | ||
) (roachpb.SpanConfig, error) { | ||
newResult, errNew := s.new.GetSpanConfigForKey(ctx, key) | ||
if log.ExpensiveLogEnabled(ctx, 1) { | ||
oldResult, errOld := s.old.GetSpanConfigForKey(ctx, key) | ||
if !newResult.Equal(oldResult) { | ||
log.Warningf(ctx, "get span config for key: mismatched responses between old result (%s) and new(%s) for key=%s", | ||
oldResult.String(), newResult.String(), key.String()) | ||
} | ||
if !errors.Is(errNew, errOld) { | ||
log.Warningf(ctx, "get span config for key: mismatched errors between old result (%s) and new (%s) for key=%s", | ||
errOld, errNew, key.String()) | ||
} | ||
} | ||
return newResult, errNew | ||
} |
Oops, something went wrong.