key

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2021 License: Apache-2.0 Imports: 14 Imported by: 19

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 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 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 KeyRangeStartSmaller added in v0.8.0

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

KeyRangeStartSmaller returns true if right's keyrange start is _after_ left's 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 KeyspaceIDTypeString added in v0.10.0

func KeyspaceIDTypeString(id topodatapb.KeyspaceIdType) string

KeyspaceIDTypeString returns the string representation of a keyspace id type.

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. "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 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) 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) 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 DestinationKeyRanges

type DestinationKeyRanges []*topodatapb.KeyRange

DestinationKeyRanges is the destination for multiple KeyRanges. It implements 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) 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 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