forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spanconfig: add Record constructor and validation
This change adds a constructor method that returns a new `spanconfig.Record` and conditionally performs some validation if the target is a SystemTarget. Informs: cockroachdb#73727 Release note: None Release justification: low-risk updates to new functionality
- Loading branch information
1 parent
71eb44f
commit 4077ffc
Showing
28 changed files
with
551 additions
and
288 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,52 @@ | ||
// 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 spanconfig | ||
|
||
import ( | ||
"github.com/cockroachdb/cockroach/pkg/roachpb" | ||
"github.com/cockroachdb/errors" | ||
) | ||
|
||
// Record ties a target to its corresponding config. | ||
type Record struct { | ||
// target specifies the target (keyspan(s)) the config applies over. | ||
target Target | ||
|
||
// config is the set of attributes that apply over the corresponding target. | ||
config roachpb.SpanConfig | ||
} | ||
|
||
// MakeRecord returns a Record with the specified Target and SpanConfig. If the | ||
// Record targets a SystemTarget, we also validate the SpanConfig. | ||
func MakeRecord(target Target, cfg roachpb.SpanConfig) (Record, error) { | ||
if target.IsSystemTarget() { | ||
if err := cfg.ValidateSystemTargetSpanConfig(); err != nil { | ||
return Record{}, | ||
errors.NewAssertionErrorWithWrappedErrf(err, "failed to validate SystemTarget SpanConfig") | ||
} | ||
} | ||
return Record{target: target, config: cfg}, nil | ||
} | ||
|
||
// IsEmpty returns true if the receiver is an empty Record. | ||
func (r *Record) IsEmpty() bool { | ||
return r.target.isEmpty() && r.config.IsEmpty() | ||
} | ||
|
||
// GetTarget returns the Record target. | ||
func (r *Record) GetTarget() Target { | ||
return r.target | ||
} | ||
|
||
// GetConfig returns the Record config. | ||
func (r *Record) GetConfig() roachpb.SpanConfig { | ||
return r.config | ||
} |
Oops, something went wrong.