key

package
v0.20.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2024 License: Apache-2.0 Imports: 13 Imported by: 40

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	KeyRangePattern = regexp.MustCompile(`^(0|([0-9a-fA-F]{2})*-([0-9a-fA-F]{2})*)$`)
)

Functions

func Compare added in v0.17.0

func Compare(a, b []byte) int

Compare compares two keyspace IDs while taking care to normalize them; returns -1 if a<b, 1 if a>b, 0 if equal.

func DestinationsString

func DestinationsString(destinations []Destination) string

DestinationsString returns a printed version of the destination array.

func Empty added in v0.17.0

func Empty(id []byte) bool

Empty returns true if id is an empty keyspace ID.

func Equal added in v0.17.0

func Equal(a, b []byte) bool

Equal returns true if a is equal to b.

func EvenShardsKeyRange

func EvenShardsKeyRange(i, n int) (*topodatapb.KeyRange, error)

EvenShardsKeyRange returns a key range definition for a shard at index "i", assuming range based sharding with "n" equal-width shards in total. i starts at 0.

Example: (1, 2) returns the second out of two shards in total i.e. "80-".

This function must not be used in the Vitess code base because Vitess also supports shards with different widths. In that case, the output of this function would be wrong.

Note: start and end values have trailing zero bytes omitted. For example, "80-" has only the first byte (0x80) set. We do this to produce the same KeyRange objects as ParseKeyRangeParts() does. Because it's using the Go hex methods, it's omitting trailing zero bytes as well.

func GenerateShardRanges added in v0.11.0

func GenerateShardRanges(shards int) ([]string, error)

GenerateShardRanges returns shard ranges assuming a keyspace with N shards.

func GetShardForKeyspaceID

func GetShardForKeyspaceID(allShards []*topodatapb.ShardReference, keyspaceID []byte) (string, error)

GetShardForKeyspaceID finds the right shard for a keyspace id.

func IsValidKeyRange added in v0.17.0

func IsValidKeyRange(keyRangeString string) bool

IsValidKeyRange returns true if the string represents a valid key range.

func KeyRangeAdd

func KeyRangeAdd(a, b *topodatapb.KeyRange) (*topodatapb.KeyRange, bool)

KeyRangeAdd adds two adjacent KeyRange values (in any order) into a single value. If the values are not adjacent, it returns false.

func KeyRangeCompare added in v0.17.0

func KeyRangeCompare(a, b *topodatapb.KeyRange) int

KeyRangeCompare compares two KeyRange values, taking into account both the Start and End fields and their field-specific comparison logic; returns -1 if a<b, 1 if a>b, 0 if equal. Specifically:

  • The Start-specific KeyRangeStartCompare and End-specific KeyRangeEndCompare are used for proper comparison of an empty value for either Start or End.
  • The Start is compared first and End is only compared if Start is equal.

func KeyRangeContains

func KeyRangeContains(keyRange *topodatapb.KeyRange, id []byte) bool

KeyRangeContains returns true if the provided id is in the keyrange.

func KeyRangeContainsKeyRange added in v0.17.0

func KeyRangeContainsKeyRange(a, b *topodatapb.KeyRange) bool

KeyRangeContainsKeyRange returns true if KeyRange a fully contains KeyRange b.

func KeyRangeContiguous added in v0.12.0

func KeyRangeContiguous(a, b *topodatapb.KeyRange) bool

KeyRangeContiguous returns true if the End of KeyRange a is equivalent to the Start of the KeyRange b, which means that they are contiguous.

func KeyRangeEndCompare added in v0.17.0

func KeyRangeEndCompare(a, b *topodatapb.KeyRange) int

KeyRangeEndCompare compares the End of two KeyRange values using semantics unique to End values where an empty End means the *maximum* value; returns -1 if a<b, 1 if a>b, 0 if equal.

func KeyRangeEndEqual

func KeyRangeEndEqual(a, b *topodatapb.KeyRange) bool

KeyRangeEndEqual returns true if both KeyRange values have the same End.

func KeyRangeEqual

func KeyRangeEqual(a, b *topodatapb.KeyRange) bool

KeyRangeEqual returns true if a and b are equal.

func KeyRangeIntersect added in v0.17.0

func KeyRangeIntersect(a, b *topodatapb.KeyRange) bool

KeyRangeIntersect returns true if some part of KeyRange a and b overlap, meaning that some keyspace ID values exist in both a and b.

func KeyRangeIsComplete added in v0.17.0

func KeyRangeIsComplete(keyRange *topodatapb.KeyRange) bool

KeyRangeIsComplete returns true if the KeyRange covers the entire keyspace.

func KeyRangeIsPartial

func KeyRangeIsPartial(keyRange *topodatapb.KeyRange) bool

KeyRangeIsPartial returns true if the KeyRange does not cover the entire keyspace.

func KeyRangeLess added in v0.17.0

func KeyRangeLess(a, b *topodatapb.KeyRange) bool

KeyRangeLess returns true if a is less than b.

func KeyRangeStartCompare added in v0.17.0

func KeyRangeStartCompare(a, b *topodatapb.KeyRange) int

KeyRangeStartCompare compares the Start of two KeyRange values using semantics unique to Start values where an empty Start means the *minimum* value; returns -1 if a<b, 1 if a>b, 0 if equal.

func KeyRangeStartEqual

func KeyRangeStartEqual(a, b *topodatapb.KeyRange) bool

KeyRangeStartEqual returns true if both KeyRange values have the same Start.

func KeyRangeString

func KeyRangeString(keyRange *topodatapb.KeyRange) string

KeyRangeString formats a topodatapb.KeyRange into a hex encoded string.

func Less added in v0.17.0

func Less(a, b []byte) bool

Less returns true if a is less than b.

func Normalize added in v0.17.0

func Normalize(id []byte) []byte

Normalize removes any trailing zero bytes from id. This allows two id values to be compared even if they are different lengths. From a key range perspective, -80 == 00-80 == 0000-8000 == 000000-800000, etc. and they should always be treated the same even if they are different lengths.

func ParseKeyRangeParts

func ParseKeyRangeParts(start, end string) (*topodatapb.KeyRange, error)

ParseKeyRangeParts parses a Start and End as hex encoded strings and builds a proto KeyRange.

func ParseShardingSpec

func ParseShardingSpec(spec string) ([]*topodatapb.KeyRange, error)

ParseShardingSpec parses a string that describes a sharding specification. a-b-c-d will be parsed as a-b, b-c, c-d. The empty string may serve both as the start and end of the keyspace: -a-b- will be parsed as start-a, a-b, b-end. "0" is treated as "-", to allow us to not have to special-case client code.

Types

type Destination

type Destination interface {
	// Resolve calls the callback for every shard Destination
	// resolves into, given the shards list.
	// The returned error must be generated by vterrors.
	Resolve([]*topodatapb.ShardReference, func(shard string) error) error

	// String returns a printable version of the Destination.
	String() string
}

Destination is an interface definition for a query destination, within a given Keyspace / Tablet Type. It is meant to be an internal data structure, with multiple possible implementations. The srvtopo package can resolve Destinations into actual Targets.

type DestinationAllShards

type DestinationAllShards struct{}

DestinationAllShards is the destination for all the shards in the keyspace. This usually maps to the first one in the list. It implements the Destination interface.

func (DestinationAllShards) Resolve

func (d DestinationAllShards) Resolve(allShards []*topodatapb.ShardReference, addShard func(shard string) error) error

Resolve is part of the Destination interface.

func (DestinationAllShards) String

func (d DestinationAllShards) String() string

String is part of the Destination interface.

type DestinationAnyShard

type DestinationAnyShard struct{}

DestinationAnyShard is the destination for any one shard in the keyspace. It implements the Destination interface.

func (DestinationAnyShard) Resolve

func (d DestinationAnyShard) Resolve(allShards []*topodatapb.ShardReference, addShard func(shard string) error) error

Resolve is part of the Destination interface.

func (DestinationAnyShard) String

func (d DestinationAnyShard) String() string

String is part of the Destination interface.

type DestinationAnyShardPicker

type DestinationAnyShardPicker interface {
	// PickShard picks a shard given a number of shards
	PickShard(shardCount int) int
}

DestinationAnyShardPicker exposes an interface that will pick an index given a number of available shards.

AnyShardPicker makes a choice on what shard to use when any shard will do. Used for testing.

type DestinationAnyShardPickerRandomShard

type DestinationAnyShardPickerRandomShard struct{}

DestinationAnyShardPickerRandomShard picks a random shard.

func (DestinationAnyShardPickerRandomShard) PickShard

func (dp DestinationAnyShardPickerRandomShard) PickShard(shardCount int) int

PickShard is DestinationAnyShardPickerRandomShard's implementation.

type DestinationExactKeyRange

type DestinationExactKeyRange struct {
	KeyRange *topodatapb.KeyRange
}

DestinationExactKeyRange is the destination for a single KeyRange. The KeyRange must map exactly to one or more shards, and cannot start or end in the middle of a shard. It implements the Destination interface. (it cannot be just a type *topodatapb.KeyRange, as then the receiver methods don't work. And it can't be topodatapb.KeyRange either, as then the methods are on *DestinationExactKeyRange, and the original KeyRange cannot be returned).

func (*DestinationExactKeyRange) CachedSize added in v0.10.0

func (cached *DestinationExactKeyRange) CachedSize(alloc bool) int64

func (DestinationExactKeyRange) Resolve

func (d DestinationExactKeyRange) Resolve(allShards []*topodatapb.ShardReference, addShard func(shard string) error) error

Resolve is part of the Destination interface.

func (DestinationExactKeyRange) String

func (d DestinationExactKeyRange) String() string

String is part of the Destination interface.

type DestinationKeyRange

type DestinationKeyRange struct {
	KeyRange *topodatapb.KeyRange
}

DestinationKeyRange is the destination for a single KeyRange. It implements the Destination interface. (it cannot be just a type *topodatapb.KeyRange, as then the receiver methods don't work. And it can't be topodatapb.KeyRange either, as then the methods are on *DestinationKeyRange, and the original KeyRange cannot be returned).

func (*DestinationKeyRange) CachedSize added in v0.10.0

func (cached *DestinationKeyRange) CachedSize(alloc bool) int64

func (DestinationKeyRange) Resolve

func (d DestinationKeyRange) Resolve(allShards []*topodatapb.ShardReference, addShard func(shard string) error) error

Resolve is part of the Destination interface.

func (DestinationKeyRange) String

func (d DestinationKeyRange) String() string

String is part of the Destination interface.

type DestinationKeyspaceID

type DestinationKeyspaceID []byte

DestinationKeyspaceID is the destination for a single KeyspaceID. It implements the Destination interface.

func (DestinationKeyspaceID) Resolve

func (d DestinationKeyspaceID) Resolve(allShards []*topodatapb.ShardReference, addShard func(shard string) error) error

Resolve is part of the Destination interface.

func (DestinationKeyspaceID) String

func (d DestinationKeyspaceID) String() string

String is part of the Destination interface.

type DestinationKeyspaceIDs

type DestinationKeyspaceIDs [][]byte

DestinationKeyspaceIDs is the destination for multiple KeyspaceIDs. It implements the Destination interface.

func (DestinationKeyspaceIDs) Resolve

func (d DestinationKeyspaceIDs) Resolve(allShards []*topodatapb.ShardReference, addShard func(shard string) error) error

Resolve is part of the Destination interface.

func (DestinationKeyspaceIDs) String

func (d DestinationKeyspaceIDs) String() string

String is part of the Destination interface.

type DestinationNone

type DestinationNone struct{}

DestinationNone is a destination that doesn't resolve to any shard. It implements the Destination interface.

func (DestinationNone) Resolve

func (d DestinationNone) Resolve(allShards []*topodatapb.ShardReference, addShard func(shard string) error) error

Resolve is part of the Destination interface.

func (DestinationNone) String

func (d DestinationNone) String() string

String is part of the Destination interface.

type DestinationShard

type DestinationShard string

DestinationShard is the destination for a single Shard. It implements the Destination interface.

func (DestinationShard) Resolve

func (d DestinationShard) Resolve(allShards []*topodatapb.ShardReference, addShard func(shard string) error) error

Resolve is part of the Destination interface.

func (DestinationShard) String

func (d DestinationShard) String() string

String is part of the Destination interface.

type DestinationShards

type DestinationShards []string

DestinationShards is the destination for multiple shards. It implements the Destination interface.

func (DestinationShards) Resolve

func (d DestinationShards) Resolve(allShards []*topodatapb.ShardReference, addShard func(shard string) error) error

Resolve is part of the Destination interface.

func (DestinationShards) String

func (d DestinationShards) String() string

String is part of the Destination interface.

type Uint64Key

type Uint64Key uint64

Uint64Key is a uint64 that can be converted into a keyspace id.

func (Uint64Key) Bytes

func (i Uint64Key) Bytes() []byte

Bytes returns the keyspace id (as bytes) associated with a Uint64Key.

func (Uint64Key) String

func (i Uint64Key) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL