shard

package
v0.15.0-rc.9 Latest Latest
Warning

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

Go to latest
Published: May 7, 2020 License: Apache-2.0 Imports: 6 Imported by: 55

Documentation

Index

Constants

View Source
const (
	// UnInitializedValue is the unintialized value used in proto.
	UnInitializedValue int64 = 0

	// DefaultShardCutoverNanos is the default shard-level cutover nanos
	// if the value is not set in the proto message.
	DefaultShardCutoverNanos int64 = 0

	// DefaultShardCutoffNanos is the default shard-level cutoff nanos
	// if the value is not set in the proto message.
	DefaultShardCutoffNanos int64 = math.MaxInt64
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Shard

type Shard interface {
	// ID returns the ID of the shard.
	ID() uint32

	// CutoverNanos returns when shard traffic is cut over.
	CutoverNanos() int64

	// SetCutoverNanos sets when shard traffic is cut over.
	SetCutoverNanos(value int64) Shard

	// CutoffNanos returns when shard traffic is cut off.
	CutoffNanos() int64

	// SetCutoffNanos sets when shard traffic is cut off.
	SetCutoffNanos(value int64) Shard

	// State returns the state of the shard.
	State() State

	// SetState sets the state of the shard.
	SetState(s State) Shard

	// Source returns the source of the shard.
	SourceID() string

	// SetSource sets the source of the shard.
	SetSourceID(sourceID string) Shard

	// Equals returns whether the shard equals to another shard.
	Equals(s Shard) bool

	// Proto returns the proto representation for the shard.
	Proto() (*placementpb.Shard, error)

	// Clone returns a clone of the Shard.
	Clone() Shard
}

A Shard represents a piece of data owned by the service.

func NewShard

func NewShard(id uint32) Shard

NewShard returns a new Shard

func NewShardFromProto

func NewShardFromProto(shard *placementpb.Shard) (Shard, error)

NewShardFromProto create a new shard from proto.

type Shards

type Shards interface {
	// All returns the shards sorted ascending.
	All() []Shard

	// AllIDs returns the shard IDs sorted ascending.
	AllIDs() []uint32

	// NumShards returns the number of the shards.
	NumShards() int

	// ShardsForState returns the shards in a certain state.
	ShardsForState(state State) []Shard

	// NumShardsForState returns the number of shards in a certain state.
	NumShardsForState(state State) int

	// Add adds a shard.
	Add(shard Shard)

	// Remove removes a shard.
	Remove(shard uint32)

	// Contains checks if a shard exists.
	Contains(shard uint32) bool

	// Shard returns the shard for the id.
	Shard(id uint32) (Shard, bool)

	// Equals returns whether the shards equals to another shards.
	Equals(s Shards) bool

	// String returns the string representation of the shards.
	String() string

	// Proto returns the proto representation for the shards.
	Proto() ([]*placementpb.Shard, error)

	// Clone returns a clone of the Shards.
	Clone() Shards
}

Shards is a collection of shards owned by one ServiceInstance.

func NewShards

func NewShards(ss []Shard) Shards

NewShards creates a new instance of Shards

func NewShardsFromProto

func NewShardsFromProto(shards []*placementpb.Shard) (Shards, error)

NewShardsFromProto creates a new set of shards from proto.

type SortableIDsAsc

type SortableIDsAsc []uint32

SortableIDsAsc are sortable shard IDs in ascending order

func (SortableIDsAsc) Len

func (s SortableIDsAsc) Len() int

func (SortableIDsAsc) Less

func (s SortableIDsAsc) Less(i, j int) bool

func (SortableIDsAsc) Swap

func (s SortableIDsAsc) Swap(i, j int)

type SortableShardProtosByIDAsc

type SortableShardProtosByIDAsc []*placementpb.Shard

SortableShardProtosByIDAsc sorts shard protos by their ids in ascending order.

func (SortableShardProtosByIDAsc) Len

func (SortableShardProtosByIDAsc) Less

func (su SortableShardProtosByIDAsc) Less(i, j int) bool

func (SortableShardProtosByIDAsc) Swap

func (su SortableShardProtosByIDAsc) Swap(i, j int)

type SortableShardsByIDAsc

type SortableShardsByIDAsc []Shard

SortableShardsByIDAsc are sortable shards by ID in ascending order

func (SortableShardsByIDAsc) Len

func (s SortableShardsByIDAsc) Len() int

func (SortableShardsByIDAsc) Less

func (s SortableShardsByIDAsc) Less(i, j int) bool

func (SortableShardsByIDAsc) Swap

func (s SortableShardsByIDAsc) Swap(i, j int)

type State

type State int

State represents the state of a shard.

const (
	// Unknown represents a shard in unknown state.
	Unknown State = iota
	// Initializing represents a shard newly assigned to an instance.
	Initializing
	// Available represents a shard bootstraped and ready to serve.
	Available
	// Leaving represents a shard that is intending to be removed.
	Leaving
)

func NewShardStateFromProto

func NewShardStateFromProto(state placementpb.ShardState) (State, error)

NewShardStateFromProto creates new shard state from proto.

func (State) Proto

func (s State) Proto() (placementpb.ShardState, error)

Proto returns the proto representation for the shard state.

func (State) String

func (i State) String() string

Jump to

Keyboard shortcuts

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