Version: v0.0.0-...-e1f8a17 Latest Latest

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

Go to latest
Published: Mar 7, 2019 License: Apache-2.0 Imports: 8 Imported by: 0




This section is empty.


This section is empty.


func IsShardInLocal

func IsShardInLocal(shardId int, selfServerId int, clusterSize int, replicationFactor int) bool

IsShardInLocal returns true if the tuple if shard should be on current server

func ShardListContains

func ShardListContains(shards []ClusterShard, targetShard ClusterShard) bool

ShardListContains check whether shards contains one target shard


type BootstrapPlan

type BootstrapPlan struct {
	// 1. bootstrapSource the shard should read missing data from.
	//   If a list of bootstrap, pickBestBootstrapSource determines whether it should pick the best, or read all and filter
	// 2. transitionalFollowSource the shard should follow these shards, with its filter(always use the follower's filter)
	BootstrapSource          []ClusterShard
	PickBestBootstrapSource  bool
	TransitionalFollowSource []ClusterShard
	FromClusterSize          int
	ToClusterSize            int

BootstrapPlan contains detailed plan to bootstrap one shard.

func BootstrapPlanWithTopoChange

func BootstrapPlanWithTopoChange(req *BootstrapRequest) (plan *BootstrapPlan)

BootstrapPlanWithTopoChange builds the bootstrap plan based on the bootstrap request.

func (*BootstrapPlan) String

func (plan *BootstrapPlan) String() string

type BootstrapRequest

type BootstrapRequest struct {
	ServerId          int
	ShardId           int
	FromClusterSize   int
	ToClusterSize     int
	ReplicationFactor int

BootstrapRequest is a request to bootstrap one shard.

type Cluster

type Cluster struct {
	// contains filtered or unexported fields

Cluster manages one cluster topology

func NewCluster

func NewCluster(keyspace string, expectedSize int, replicationFactor int) *Cluster

NewCluster creates a new cluster.

func (*Cluster) CurrentSize

func (cluster *Cluster) CurrentSize() int

CurrentSize returns the cluster current size

func (*Cluster) Debug

func (cluster *Cluster) Debug(prefix string)

Debug prints out the detailed info of the cluster.

func (*Cluster) ExpectedSize

func (cluster *Cluster) ExpectedSize() int

ExpectedSize returns the expected size of the cluster

func (*Cluster) FindShardId

func (cluster *Cluster) FindShardId(keyHash uint64) int

FindShardId calculates a Jump hash for the keyHash provided

func (*Cluster) GetAllShards

func (cluster *Cluster) GetAllShards() []LogicalShardGroup

GetAllShards returns a list of all logic shard groups.

func (*Cluster) GetNextCluster

func (cluster *Cluster) GetNextCluster() *Cluster

GetNextCluster returns the next cluster

func (*Cluster) GetNode

func (cluster *Cluster) GetNode(shardId int, replica int) (*pb.ClusterNode, bool)

GetNode returns the server having the shard. replica denotes the shard replica.

func (*Cluster) RemoveNextCluster

func (cluster *Cluster) RemoveNextCluster()

RemoveNextCluster clears the pointer to the next cluster

func (*Cluster) RemoveShard

func (cluster *Cluster) RemoveShard(store *pb.StoreResource, shard *pb.ShardInfo) (storeDeleted bool)

RemoveShard returns true if no other shards is on this store

func (*Cluster) RemoveStore

func (cluster *Cluster) RemoveStore(store *pb.StoreResource) (removedShards []*pb.ShardInfo)

RemoveStore removes the server from the cluster. It returns the shards which were on the server.

func (*Cluster) ReplaceShard

func (cluster *Cluster) ReplaceShard(newStore *pb.StoreResource, shard *pb.ShardInfo) (isReplaced bool)

ReplaceShard ReplaceShard the shardInfo on the server in the cluster. It returns true if the operation is successful.

func (*Cluster) ReplicationFactor

func (cluster *Cluster) ReplicationFactor() int

ReplicationFactor returns the replication factor of the cluster

func (*Cluster) SetExpectedSize

func (cluster *Cluster) SetExpectedSize(expectedSize int)

SetExpectedSize sets the expected size of the cluster

func (*Cluster) SetNextCluster

func (cluster *Cluster) SetNextCluster(expectedSize int, replicationFactor int) *Cluster

SetNextCluster creates a new cluster and sets the size and replication factor

func (*Cluster) SetReplicationFactor

func (cluster *Cluster) SetReplicationFactor(replicationFactor int)

SetReplicationFactor sets the replication factor of the cluster

func (*Cluster) SetShard

func (cluster *Cluster) SetShard(store *pb.StoreResource, shard *pb.ShardInfo) (oldShardInfo *pb.ShardInfo)

SetShard sets the tuple of server and shardInfo to the cluster. It returns the previous shardInfo if found.

func (*Cluster) String

func (cluster *Cluster) String() string

func (*Cluster) ToCluster

func (cluster *Cluster) ToCluster() *pb.Cluster

ToCluster converts the cluster into pb.Cluster object

func (*Cluster) WithConnection

func (cluster *Cluster) WithConnection(name string, serverId int, fn func(*pb.ClusterNode, *grpc.ClientConn) error) error

WithConnection dials a connection to a server in the cluster by serverId

type ClusterShard

type ClusterShard struct {
	ShardId  int
	ServerId int

ClusterShard has the tuple of server id and shard id in a cluster.

func LocalShards

func LocalShards(selfServerId int, clusterSize int, replicationFactor int) (shards []ClusterShard)

LocalShards list shards that local node should have

func PartitionShards

func PartitionShards(selfServerId int, selfShardId int, clusterSize int, replicationFactor int) (shards []ClusterShard)

PartitionShards list shards that belongs to the same partition

func PeerShards

func PeerShards(selfServerId int, selfShardId int, clusterSize int, replicationFactor int) (peers []ClusterShard)

PeerShards list peer shards that are on other cluster nodes

func (ClusterShard) String

func (shard ClusterShard) String() string

type LogicalShardGroup

type LogicalShardGroup []*pb.ClusterNode

LogicalShardGroup is a list of shards with the same shard id

func (LogicalShardGroup) String

func (shards LogicalShardGroup) String() string

type VastoNodes

type VastoNodes []*pb.ClusterNode

VastoNodes are the servers in a cluster

func (VastoNodes) WithConnection

func (nodes VastoNodes) WithConnection(name string, serverId int, fn func(*pb.ClusterNode, *grpc.ClientConn) error) error

WithConnection dials a connection to a server of the cluster nodes by serverId


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL