cluster

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AllocClusterIDPrefix = "ClusterID"
	AllocSchemaIDPrefix  = "SchemaID"
	AllocTableIDPrefix   = "TableID"
)
View Source
const (
	MinShardID = 0
)

Variables

View Source
var (
	ErrCreateCluster                = coderr.NewCodeError(coderr.BadRequest, "create cluster")
	ErrClusterAlreadyExists         = coderr.NewCodeError(coderr.ClusterAlreadyExists, "cluster already exists")
	ErrClusterStateInvalid          = coderr.NewCodeError(coderr.Internal, "cluster state invalid")
	ErrClusterNotFound              = coderr.NewCodeError(coderr.NotFound, "cluster not found")
	ErrClusterTopologyNotFound      = coderr.NewCodeError(coderr.NotFound, "cluster topology not found")
	ErrSchemaNotFound               = coderr.NewCodeError(coderr.NotFound, "schema not found")
	ErrTableNotFound                = coderr.NewCodeError(coderr.NotFound, "Table not found")
	ErrShardNotFound                = coderr.NewCodeError(coderr.NotFound, "shard not found")
	ErrNodeNotFound                 = coderr.NewCodeError(coderr.NotFound, "node not found")
	ErrNodeIsEmpty                  = coderr.NewCodeError(coderr.NotFound, "cluster nodes list is empty")
	ErrShardListIsEmpty             = coderr.NewCodeError(coderr.NotFound, "cluster shard list is empty")
	ErrNodeShardsIsEmpty            = coderr.NewCodeError(coderr.Internal, "node's shard list is empty")
	ErrGetShardTopology             = coderr.NewCodeError(coderr.Internal, "get shard topology")
	ErrTableAlreadyExists           = coderr.NewCodeError(coderr.Internal, "table already exists")
	ErrShardTopologyVersionNotMatch = coderr.NewCodeError(coderr.Internal, "shard topology version not match")
)

Functions

func ConvertNodeToPB added in v0.4.0

func ConvertNodeToPB(node *RegisteredNode) *clusterpb.Node

func ConvertShardsInfoToPB added in v0.4.0

func ConvertShardsInfoToPB(shard *ShardInfo) *metaservicepb.ShardInfo

func ConvertTableInfoToPB added in v0.4.0

func ConvertTableInfoToPB(table *TableInfo) *metaservicepb.TableInfo

Types

type Cluster

type Cluster struct {
	// contains filtered or unexported fields
}

func NewCluster

func NewCluster(meta *clusterpb.Cluster, storage storage.Storage, kv clientv3.KV, rootPath string, idAllocatorStep uint) *Cluster

func (*Cluster) AllocShardID added in v0.4.0

func (c *Cluster) AllocShardID(ctx context.Context) (uint32, error)

func (*Cluster) CreateShardTopologies added in v0.4.0

func (c *Cluster) CreateShardTopologies(ctx context.Context, state clusterpb.ClusterTopology_ClusterState, shardTopologies []*clusterpb.ShardTopology, shardView []*clusterpb.Shard) error

func (*Cluster) CreateTable added in v0.4.0

func (c *Cluster) CreateTable(ctx context.Context, nodeName string, schemaName string, tableName string) (*CreateTableResult, error)

func (*Cluster) DropTable

func (c *Cluster) DropTable(ctx context.Context, schemaName, tableName string) (*DropTableResult, error)

func (*Cluster) GetClusterID added in v0.4.0

func (c *Cluster) GetClusterID() uint32

func (*Cluster) GetClusterMinNodeCount added in v0.4.0

func (c *Cluster) GetClusterMinNodeCount() uint32

func (*Cluster) GetClusterShardView added in v0.4.0

func (c *Cluster) GetClusterShardView() ([]*clusterpb.Shard, error)

func (*Cluster) GetClusterState added in v0.4.0

func (c *Cluster) GetClusterState() clusterpb.ClusterTopology_ClusterState

func (*Cluster) GetClusterVersion added in v0.4.0

func (c *Cluster) GetClusterVersion() uint64

func (*Cluster) GetNodeShards added in v0.4.0

func (c *Cluster) GetNodeShards(_ context.Context) (*GetNodeShardsResult, error)

func (*Cluster) GetOrCreateSchema

func (c *Cluster) GetOrCreateSchema(ctx context.Context, schemaName string) (*Schema, bool, error)

GetOrCreateSchema the second output parameter bool: Returns true if the schema was newly created.

func (*Cluster) GetRegisteredNode added in v0.4.0

func (c *Cluster) GetRegisteredNode(nodeName string) (*RegisteredNode, bool)

func (*Cluster) GetRegisteredNodes added in v0.4.0

func (c *Cluster) GetRegisteredNodes() []*RegisteredNode

func (*Cluster) GetShardByID added in v0.4.0

func (c *Cluster) GetShardByID(id uint32) (*Shard, error)

GetShardByID return immutable `Shard`.

func (*Cluster) GetShardIDsByNode added in v0.4.0

func (c *Cluster) GetShardIDsByNode(nodeName string) ([]uint32, error)

func (*Cluster) GetTable

func (c *Cluster) GetTable(ctx context.Context, schemaName, tableName string) (*Table, bool, error)

func (*Cluster) GetTables

func (c *Cluster) GetTables(_ context.Context, shardIDs []uint32, nodeName string) (map[uint32]*ShardTablesWithRole, error)

func (*Cluster) GetTotalShardNum added in v0.4.0

func (c *Cluster) GetTotalShardNum() uint32

func (*Cluster) Load

func (c *Cluster) Load(ctx context.Context) error

Load data from storage to memory.

func (*Cluster) Name

func (c *Cluster) Name() string

func (*Cluster) RegisterNode

func (c *Cluster) RegisterNode(ctx context.Context, nodeInfo *metaservicepb.NodeInfo) error

func (*Cluster) RouteTables

func (c *Cluster) RouteTables(_ context.Context, schemaName string, tableNames []string) (*RouteTablesResult, error)

type CreateTableResult added in v0.4.0

type CreateTableResult struct {
	Table              *Table
	ShardVersionUpdate *ShardVersionUpdate
}

type DropTableResult added in v0.4.0

type DropTableResult struct {
	ShardVersionUpdate *ShardVersionUpdate
}

type GetNodeShardsResult added in v0.4.0

type GetNodeShardsResult struct {
	ClusterTopologyVersion uint64
	NodeShards             []*NodeShard
}

type Manager

type Manager interface {
	// Start must be called before manager is used.
	Start(ctx context.Context) error
	// Stop must be called before manager is dropped.
	Stop(ctx context.Context) error

	ListClusters(ctx context.Context) ([]*Cluster, error)
	CreateCluster(ctx context.Context, clusterName string, nodeCount, replicationFactor, shardTotal uint32) (*Cluster, error)
	GetCluster(ctx context.Context, clusterName string) (*Cluster, error)
	// AllocSchemaID means get or create schema.
	// The second output parameter bool: Returns true if the table was newly created.
	AllocSchemaID(ctx context.Context, clusterName, schemaName string) (uint32, bool, error)
	// AllocTableID means get or create table.
	// The second output parameter bool: Returns true if the table was newly created.
	AllocTableID(ctx context.Context, clusterName, schemaName, tableName, nodeName string) (*Table, bool, error)
	GetTables(ctx context.Context, clusterName, nodeName string, shardIDs []uint32) (map[uint32]*ShardTables, error)
	DropTable(ctx context.Context, clusterName, schemaName, tableName string) error
	GetShardIDs(ctx context.Context, clusterName, nodeName string) ([]uint32, error)
	RouteTables(ctx context.Context, clusterName, schemaName string, tableNames []string) (*RouteTablesResult, error)
	GetNodeShards(ctx context.Context, clusterName string) (*GetNodeShardsResult, error)

	RegisterNode(ctx context.Context, clusterName string, nodeInfo *metaservicepb.NodeInfo) error
	GetRegisteredNode(ctx context.Context, clusterName string, node string) (*metaservicepb.NodeInfo, error)
}

func NewManagerImpl

func NewManagerImpl(storage storage.Storage, kv clientv3.KV, rootPath string, idAllocatorStep uint) (Manager, error)

type NodeShard

type NodeShard struct {
	Endpoint  string
	ShardInfo *ShardInfo
}

type RegisteredNode added in v0.4.0

type RegisteredNode struct {
	// contains filtered or unexported fields
}

func NewRegisteredNode added in v0.4.0

func NewRegisteredNode(meta *clusterpb.Node, shardInfos []*ShardInfo) *RegisteredNode

func (*RegisteredNode) GetMeta added in v0.4.0

func (n *RegisteredNode) GetMeta() *clusterpb.Node

func (*RegisteredNode) GetShardInfos added in v0.4.0

func (n *RegisteredNode) GetShardInfos() []*ShardInfo

func (RegisteredNode) IsExpired added in v0.4.0

func (n RegisteredNode) IsExpired(now uint64, aliveThreshold uint64) bool

func (*RegisteredNode) IsOnline added in v0.4.0

func (n *RegisteredNode) IsOnline() bool

type RouteEntry

type RouteEntry struct {
	Table      *TableInfo
	NodeShards []*NodeShard
}

type RouteTablesResult

type RouteTablesResult struct {
	Version      uint64
	RouteEntries map[string]*RouteEntry
}

type Schema

type Schema struct {
	// contains filtered or unexported fields
}

func (*Schema) GetID

func (s *Schema) GetID() uint32

func (*Schema) GetName added in v0.4.0

func (s *Schema) GetName() string

type Shard

type Shard struct {
	// contains filtered or unexported fields
}

func (*Shard) FindShardByNode added in v0.4.0

func (s *Shard) FindShardByNode(nodeName string) (*clusterpb.Shard, bool)

FIXME: avoid returning *clusterpb.Shard.

func (*Shard) GetLeader added in v0.4.0

func (s *Shard) GetLeader() *clusterpb.Shard

func (*Shard) GetVersion added in v0.4.0

func (s *Shard) GetVersion() uint64

type ShardInfo

type ShardInfo struct {
	ID      uint32
	Role    clusterpb.ShardRole
	Version uint64
}

type ShardTables

type ShardTables struct {
	Shard  *ShardInfo
	Tables []*TableInfo
}

type ShardTablesWithRole

type ShardTablesWithRole struct {
	// contains filtered or unexported fields
}

type ShardVersionUpdate added in v0.4.0

type ShardVersionUpdate struct {
	ShardID     uint32
	CurrVersion uint64
	PrevVersion uint64
}

type ShardsOfNode added in v0.4.0

type ShardsOfNode struct {
	Endpoint string
	ShardIDs []uint32
}

type Table

type Table struct {
	// contains filtered or unexported fields
}

func (*Table) GetID

func (t *Table) GetID() uint64

func (*Table) GetInfo added in v0.4.0

func (t *Table) GetInfo() TableInfo

func (*Table) GetName

func (t *Table) GetName() string

func (*Table) GetSchemaID

func (t *Table) GetSchemaID() uint32

func (*Table) GetSchemaName

func (t *Table) GetSchemaName() string

func (*Table) GetShardID

func (t *Table) GetShardID() uint32

type TableInfo

type TableInfo struct {
	ID         uint64
	Name       string
	SchemaID   uint32
	SchemaName string
}

Jump to

Keyboard shortcuts

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