key

package
v0.16.3 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DestinationsString

func DestinationsString(destinations []Destination) string

DestinationsString returns a printed version of the destination array.

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 GetShardForKeyspaceID

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

GetShardForKeyspaceID finds the right shard for a keyspace id.

func IsKeyRange

func IsKeyRange(kr string) bool

IsKeyRange returns true if the string represents a keyrange.

func KeyRangeAdd

func KeyRangeAdd(first, second *topodatapb.KeyRange) (*topodatapb.KeyRange, bool)

KeyRangeAdd adds two adjacent keyranges into a single value. If the values are not adjacent, it returns false.

func KeyRangeContains

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

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

func KeyRangeEndEqual

func KeyRangeEndEqual(left, right *topodatapb.KeyRange) bool

KeyRangeEndEqual returns true if both key ranges have the same end

func KeyRangeEqual

func KeyRangeEqual(left, right *topodatapb.KeyRange) bool

KeyRangeEqual returns true if both key ranges cover the same area

func KeyRangeIncludes

func KeyRangeIncludes(big, small *topodatapb.KeyRange) bool

KeyRangeIncludes returns true if the first provided KeyRange, big, contains the second KeyRange, small. If they intersect, but small spills out, this returns false.

func KeyRangeIsPartial

func KeyRangeIsPartial(kr *topodatapb.KeyRange) bool

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

func KeyRangeStartEqual

func KeyRangeStartEqual(left, right *topodatapb.KeyRange) bool

KeyRangeStartEqual returns true if both key ranges have the same start

func KeyRangeString

func KeyRangeString(k *topodatapb.KeyRange) string

KeyRangeString prints a topodatapb.KeyRange

func KeyRangesIntersect

func KeyRangesIntersect(first, second *topodatapb.KeyRange) bool

KeyRangesIntersect returns true if some Keyspace values exist in both ranges.

func KeyRangesOverlap

func KeyRangesOverlap(first, second *topodatapb.KeyRange) (*topodatapb.KeyRange, error)

KeyRangesOverlap returns the overlap between two KeyRanges. They need to overlap, otherwise an error is returned.

func ParseKeyRangeParts

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

ParseKeyRangeParts parses a start and end hex values and build a proto KeyRange

func ParseKeyspaceIDType

func ParseKeyspaceIDType(param string) (topodatapb.KeyspaceIdType, error)

ParseKeyspaceIDType parses the keyspace id type into the enum

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.

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

	// IsUnique returns true if this is a single destination.
	// It returns false if this type can map to multiple destinations.
	//
	// TODO(alainjobart) That is just a method I think will be useful.
	// Mainly, in v3, once we Map(), each returned result should
	// be IsUnique=true for a Unique vindex.
	IsUnique() bool

	// 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) IsUnique

func (d DestinationAllShards) IsUnique() bool

IsUnique is part of 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) IsUnique

func (d DestinationAnyShard) IsUnique() bool

IsUnique is part of 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) IsUnique

func (d DestinationExactKeyRange) IsUnique() bool

IsUnique is part of the Destination interface.

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 DestinationExactKeyRanges

type DestinationExactKeyRanges []*topodatapb.KeyRange

DestinationExactKeyRanges is the destination for multiple KeyRanges. The KeyRanges must map exactly to one or more shards, and cannot start or end in the middle of a shard. It implements the Destination interface.

func (DestinationExactKeyRanges) IsUnique

func (d DestinationExactKeyRanges) IsUnique() bool

IsUnique is part of the Destination interface.

func (DestinationExactKeyRanges) Resolve

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

Resolve is part of the Destination interface.

func (DestinationExactKeyRanges) String

func (d DestinationExactKeyRanges) 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) IsUnique

func (d DestinationKeyRange) IsUnique() bool

IsUnique is part of the Destination interface.

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 DestinationKeyRanges

type DestinationKeyRanges []*topodatapb.KeyRange

DestinationKeyRanges is the destination for multiple KeyRanges. It implements the Destination interface.

func (DestinationKeyRanges) IsUnique

func (d DestinationKeyRanges) IsUnique() bool

IsUnique is part of the Destination interface.

func (DestinationKeyRanges) Resolve

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

Resolve is part of the Destination interface.

func (DestinationKeyRanges) String

func (d DestinationKeyRanges) 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) IsUnique

func (d DestinationKeyspaceID) IsUnique() bool

IsUnique is part of 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) IsUnique

func (d DestinationKeyspaceIDs) IsUnique() bool

IsUnique is part of 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) IsUnique

func (d DestinationNone) IsUnique() bool

IsUnique is part of 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) IsUnique

func (d DestinationShard) IsUnique() bool

IsUnique is part of 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) IsUnique

func (d DestinationShards) IsUnique() bool

IsUnique is part of 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 KeyspaceId.

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