cluster

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

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

Variables

View Source
var (
	ErrCreateCluster        = coderr.NewCodeError(coderr.BadRequest, "create cluster")
	ErrClusterAlreadyExists = coderr.NewCodeError(coderr.ClusterAlreadyExists, "cluster already exists")
	ErrClusterNotFound      = coderr.NewCodeError(coderr.NotFound, "cluster not found")
	ErrClusterStateInvalid  = coderr.NewCodeError(coderr.Internal, "cluster state invalid")
	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, "NodeName not found")
	ErrTableAlreadyExists   = coderr.NewCodeError(coderr.Internal, "table already exists")
	ErrOpenTable            = coderr.NewCodeError(coderr.Internal, "open table")
)

Functions

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 CloseTableRequest added in v1.0.0

type CloseTableRequest struct {
	SchemaName string
	TableName  string
	ShardID    storage.ShardID
	NodeName   string
}

type Cluster

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

func NewCluster

func NewCluster(meta storage.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) CloseTable added in v1.0.0

func (c *Cluster) CloseTable(ctx context.Context, request CloseTableRequest) (ShardVersionUpdate, error)

func (*Cluster) CreateShardViews added in v1.0.0

func (c *Cluster) CreateShardViews(ctx context.Context, views []CreateShardView) error

func (*Cluster) CreateTable added in v0.4.0

func (c *Cluster) CreateTable(ctx context.Context, request CreateTableRequest) (CreateTableResult, error)

func (*Cluster) DropTable

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

DropTable will drop table metadata and all mapping of this table. If the table to be dropped has been opened multiple times, all its mapping will be dropped.

func (*Cluster) GetClusterID added in v0.4.0

func (c *Cluster) GetClusterID() storage.ClusterID

func (*Cluster) GetClusterMinNodeCount added in v0.4.0

func (c *Cluster) GetClusterMinNodeCount() uint32

func (*Cluster) GetClusterState added in v0.4.0

func (c *Cluster) GetClusterState() storage.ClusterState

func (*Cluster) GetClusterViewVersion added in v1.0.0

func (c *Cluster) GetClusterViewVersion() 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) (storage.Schema, bool, error)

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

func (*Cluster) GetRegisteredNodeByName added in v1.0.0

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

func (*Cluster) GetRegisteredNodes added in v0.4.0

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

func (*Cluster) GetShardNodeByTableIDs added in v1.0.0

func (c *Cluster) GetShardNodeByTableIDs(tableIDs []storage.TableID) (GetShardNodesByTableIDsResult, error)

func (*Cluster) GetShardNodesByShardID added in v1.0.0

func (c *Cluster) GetShardNodesByShardID(id storage.ShardID) ([]storage.ShardNode, error)

func (*Cluster) GetShardTables added in v1.0.0

func (c *Cluster) GetShardTables(shardIDs []storage.ShardID, nodeName string) map[storage.ShardID]ShardTables

func (*Cluster) GetTable

func (c *Cluster) GetTable(schemaName, tableName string) (storage.Table, bool, error)

GetTable the second output parameter bool: returns true if the table exists.

func (*Cluster) GetTotalShardNum added in v0.4.0

func (c *Cluster) GetTotalShardNum() uint32

func (*Cluster) MigrateTable added in v1.0.0

func (c *Cluster) MigrateTable(ctx context.Context, request MigrateTableRequest) error

MigrateTable used to migrate tables from old shard to new shard. The mapping relationship between table and shard will be modified.

func (*Cluster) Name

func (c *Cluster) Name() string

func (*Cluster) OpenTable added in v1.0.0

func (c *Cluster) OpenTable(ctx context.Context, request OpenTableRequest) (ShardVersionUpdate, error)

OpenTable will open an existing table on the specified shard. The table to be opened must have been created.

func (*Cluster) RegisterNode

func (c *Cluster) RegisterNode(ctx context.Context, registeredNode RegisteredNode) error

func (*Cluster) RouteTables

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

func (*Cluster) UpdateClusterView added in v1.0.0

func (c *Cluster) UpdateClusterView(ctx context.Context, state storage.ClusterState, shardNodes []storage.ShardNode) error

type CreateClusterOpts added in v1.0.0

type CreateClusterOpts struct {
	NodeCount         uint32
	ReplicationFactor uint32
	ShardTotal        uint32
}

type CreateShardView added in v1.0.0

type CreateShardView struct {
	ShardID storage.ShardID
	Tables  []storage.TableID
}

type CreateTableRequest added in v1.0.0

type CreateTableRequest struct {
	ShardID       storage.ShardID
	SchemaName    string
	TableName     string
	PartitionInfo storage.PartitionInfo
}

type CreateTableResult added in v0.4.0

type CreateTableResult struct {
	Table              storage.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             []ShardNodeWithVersion
}

type GetShardNodesByTableIDsResult added in v1.0.0

type GetShardNodesByTableIDsResult struct {
	ShardNodes map[storage.TableID][]storage.ShardNode
	Version    map[storage.ShardID]uint64
}

type GetShardNodesResult added in v1.0.0

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

type GetShardTablesByNodeResult added in v1.0.0

type GetShardTablesByNodeResult struct {
	ShardTableIDs map[storage.ShardID]ShardTableIDs
}

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, opts CreateClusterOpts) (*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) (storage.SchemaID, bool, error)
	GetTables(clusterName, nodeName string, shardIDs []storage.ShardID) (map[storage.ShardID]ShardTables, error)
	DropTable(ctx context.Context, clusterName, schemaName, tableName string) 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, registeredNode RegisteredNode) error
	GetRegisteredNode(ctx context.Context, clusterName string, node string) (RegisteredNode, error)
}

func NewManagerImpl

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

type MigrateTableRequest added in v1.0.0

type MigrateTableRequest struct {
	SchemaName string
	TableNames []string
	OldShardID storage.ShardID
	NewShardID storage.ShardID
}

type OpenTableRequest added in v1.0.0

type OpenTableRequest struct {
	SchemaName string
	TableName  string
	ShardID    storage.ShardID
	NodeName   string
}

type RegisteredNode added in v0.4.0

type RegisteredNode struct {
	Node       storage.Node
	ShardInfos []ShardInfo
}

func NewRegisteredNode added in v0.4.0

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

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 []ShardNodeWithVersion
}

type RouteTablesResult

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

type ShardInfo

type ShardInfo struct {
	ID   storage.ShardID
	Role storage.ShardRole
	// ShardViewVersion
	Version uint64
}

func ConvertShardsInfoPB added in v1.0.0

func ConvertShardsInfoPB(shard *metaservicepb.ShardInfo) ShardInfo

type ShardNodeWithVersion added in v1.0.0

type ShardNodeWithVersion struct {
	ShardInfo ShardInfo
	ShardNode storage.ShardNode
}

type ShardTableIDs added in v1.0.0

type ShardTableIDs struct {
	ShardNode storage.ShardNode
	TableIDs  []storage.TableID
	Version   uint64
}

type ShardTables

type ShardTables struct {
	Shard  ShardInfo
	Tables []TableInfo
}

type ShardVersionUpdate added in v0.4.0

type ShardVersionUpdate struct {
	ShardID     storage.ShardID
	CurrVersion uint64
	PrevVersion uint64
}

type TableInfo

type TableInfo struct {
	ID            storage.TableID
	Name          string
	SchemaID      storage.SchemaID
	SchemaName    string
	PartitionInfo storage.PartitionInfo
}

type TableManager added in v1.0.0

type TableManager interface {
	// Load load table meta data from storage.
	Load(ctx context.Context) error
	// GetTable get table with schemaName and tableName, the second output parameter bool: returns true if the table exists.
	GetTable(schemaName string, tableName string) (storage.Table, bool, error)
	// GetTablesByIDs get tables with tableIDs.
	GetTablesByIDs(tableIDs []storage.TableID) []storage.Table
	// CreateTable create table with schemaName and tableName.
	CreateTable(ctx context.Context, schemaName string, tableName string, partitionInfo storage.PartitionInfo) (storage.Table, error)
	// DropTable drop table with schemaName and tableName.
	DropTable(ctx context.Context, schemaName string, tableName string) error
	// GetSchemaByName get schema with schemaName.
	GetSchemaByName(schemaName string) (storage.Schema, bool)
	// GetSchemas get all schemas in cluster.
	GetSchemas() []storage.Schema
	// GetOrCreateSchema get or create schema with schemaName.
	GetOrCreateSchema(ctx context.Context, schemaName string) (storage.Schema, bool, error)
}

TableManager manages table metadata by schema.

func NewTableManagerImpl added in v1.0.0

func NewTableManagerImpl(storage storage.Storage, clusterID storage.ClusterID, schemaIDAlloc id.Allocator, tableIDAlloc id.Allocator) TableManager

type TableManagerImpl added in v1.0.0

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

func (*TableManagerImpl) CreateTable added in v1.0.0

func (m *TableManagerImpl) CreateTable(ctx context.Context, schemaName string, tableName string, partitionInfo storage.PartitionInfo) (storage.Table, error)

func (*TableManagerImpl) DropTable added in v1.0.0

func (m *TableManagerImpl) DropTable(ctx context.Context, schemaName string, tableName string) error

func (*TableManagerImpl) GetOrCreateSchema added in v1.0.0

func (m *TableManagerImpl) GetOrCreateSchema(ctx context.Context, schemaName string) (storage.Schema, bool, error)

func (*TableManagerImpl) GetSchemaByName added in v1.0.0

func (m *TableManagerImpl) GetSchemaByName(schemaName string) (storage.Schema, bool)

func (*TableManagerImpl) GetSchemas added in v1.0.0

func (m *TableManagerImpl) GetSchemas() []storage.Schema

func (*TableManagerImpl) GetTable added in v1.0.0

func (m *TableManagerImpl) GetTable(schemaName, tableName string) (storage.Table, bool, error)

func (*TableManagerImpl) GetTablesByIDs added in v1.0.0

func (m *TableManagerImpl) GetTablesByIDs(tableIDs []storage.TableID) []storage.Table

func (*TableManagerImpl) Load added in v1.0.0

func (m *TableManagerImpl) Load(ctx context.Context) error

type Tables added in v1.0.0

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

type TopologyManager added in v1.0.0

type TopologyManager interface {
	// Load load cluster topology from storage.
	Load(ctx context.Context) error
	// GetVersion get cluster view version.
	GetVersion() uint64
	// GetClusterState get cluster view state.
	GetClusterState() storage.ClusterState
	// GetTableIDs get shardNode and tablesIDs with shardID and nodeName.
	GetTableIDs(shardIDs []storage.ShardID, nodeName string) map[storage.ShardID]ShardTableIDs
	// AddTable add table to cluster topology.
	AddTable(ctx context.Context, shardID storage.ShardID, tables []storage.Table) (ShardVersionUpdate, error)
	// RemoveTable remove table on target shards from cluster topology.
	RemoveTable(ctx context.Context, shardID storage.ShardID, tableIDs []storage.TableID) (ShardVersionUpdate, error)
	// EvictTable evict table from cluster topology.
	EvictTable(ctx context.Context, tableID storage.TableID) ([]ShardVersionUpdate, error)
	// GetShardNodesByID get shardNodes with shardID.
	GetShardNodesByID(shardID storage.ShardID) ([]storage.ShardNode, error)
	// GetShardNodesByTableIDs get shardNodes with tableIDs.
	GetShardNodesByTableIDs(tableID []storage.TableID) (GetShardNodesByTableIDsResult, error)
	// GetShardNodes get all shardNodes in cluster topology.
	GetShardNodes() GetShardNodesResult
	// InitClusterView init cluster view when create new cluster.
	InitClusterView(ctx context.Context) error
	// UpdateClusterView update cluster view with shardNodes.
	UpdateClusterView(ctx context.Context, state storage.ClusterState, shardNodes []storage.ShardNode) error
	// CreateShardViews create shardViews.
	CreateShardViews(ctx context.Context, shardViews []CreateShardView) error
}

TopologyManager manages the cluster topology, including the mapping relationship between shards, nodes, and tables.

func NewTopologyManagerImpl added in v1.0.0

func NewTopologyManagerImpl(storage storage.Storage, clusterID storage.ClusterID, shardIDAlloc id.Allocator) TopologyManager

type TopologyManagerImpl added in v1.0.0

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

func (*TopologyManagerImpl) AddTable added in v1.0.0

func (m *TopologyManagerImpl) AddTable(ctx context.Context, shardID storage.ShardID, tables []storage.Table) (ShardVersionUpdate, error)

func (*TopologyManagerImpl) CreateShardViews added in v1.0.0

func (m *TopologyManagerImpl) CreateShardViews(ctx context.Context, createShardViews []CreateShardView) error

func (*TopologyManagerImpl) EvictTable added in v1.0.0

func (m *TopologyManagerImpl) EvictTable(ctx context.Context, tableID storage.TableID) ([]ShardVersionUpdate, error)

func (*TopologyManagerImpl) GetClusterState added in v1.0.0

func (m *TopologyManagerImpl) GetClusterState() storage.ClusterState

func (*TopologyManagerImpl) GetShardNodes added in v1.0.0

func (m *TopologyManagerImpl) GetShardNodes() GetShardNodesResult

func (*TopologyManagerImpl) GetShardNodesByID added in v1.0.0

func (m *TopologyManagerImpl) GetShardNodesByID(shardID storage.ShardID) ([]storage.ShardNode, error)

func (*TopologyManagerImpl) GetShardNodesByTableIDs added in v1.0.0

func (m *TopologyManagerImpl) GetShardNodesByTableIDs(tableIDs []storage.TableID) (GetShardNodesByTableIDsResult, error)

func (*TopologyManagerImpl) GetTableIDs added in v1.0.0

func (m *TopologyManagerImpl) GetTableIDs(shardIDs []storage.ShardID, nodeName string) map[storage.ShardID]ShardTableIDs

func (*TopologyManagerImpl) GetVersion added in v1.0.0

func (m *TopologyManagerImpl) GetVersion() uint64

func (*TopologyManagerImpl) InitClusterView added in v1.0.0

func (m *TopologyManagerImpl) InitClusterView(ctx context.Context) error

func (*TopologyManagerImpl) Load added in v1.0.0

func (*TopologyManagerImpl) RemoveTable added in v1.0.0

func (m *TopologyManagerImpl) RemoveTable(ctx context.Context, shardID storage.ShardID, tableIDs []storage.TableID) (ShardVersionUpdate, error)

func (*TopologyManagerImpl) UpdateClusterView added in v1.0.0

func (m *TopologyManagerImpl) UpdateClusterView(ctx context.Context, state storage.ClusterState, shardNodes []storage.ShardNode) error

Jump to

Keyboard shortcuts

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