Documentation
¶
Index ¶
- Constants
- Variables
- func ConvertShardsInfoToPB(shard ShardInfo) *metaservicepb.ShardInfo
- func ConvertTableInfoToPB(table TableInfo) *metaservicepb.TableInfo
- type Cluster
- func (c *Cluster) AllocShardID(ctx context.Context) (uint32, error)
- func (c *Cluster) CreateShardViews(ctx context.Context, views []CreateShardView) error
- func (c *Cluster) CreateTable(ctx context.Context, nodeName string, schemaName string, tableName string, ...) (CreateTableResult, error)
- func (c *Cluster) DropTable(ctx context.Context, schemaName, tableName string) (DropTableResult, error)
- func (c *Cluster) GetClusterID() storage.ClusterID
- func (c *Cluster) GetClusterMinNodeCount() uint32
- func (c *Cluster) GetClusterState() storage.ClusterState
- func (c *Cluster) GetClusterViewVersion() uint64
- func (c *Cluster) GetNodeShards(_ context.Context) (GetNodeShardsResult, error)
- func (c *Cluster) GetOrCreateSchema(ctx context.Context, schemaName string) (storage.Schema, bool, error)
- func (c *Cluster) GetRegisteredNodeByName(nodeName string) (RegisteredNode, bool)
- func (c *Cluster) GetRegisteredNodes() []RegisteredNode
- func (c *Cluster) GetShardNodeByTableIDs(tableIDs []storage.TableID) (GetShardNodesByTableIDsResult, error)
- func (c *Cluster) GetShardNodesByShardID(id storage.ShardID) ([]storage.ShardNode, error)
- func (c *Cluster) GetShardTables(shardIDs []storage.ShardID, nodeName string) map[storage.ShardID]ShardTables
- func (c *Cluster) GetTable(schemaName, tableName string) (storage.Table, bool, error)
- func (c *Cluster) GetTotalShardNum() uint32
- func (c *Cluster) Name() string
- func (c *Cluster) RegisterNode(ctx context.Context, registeredNode RegisteredNode) error
- func (c *Cluster) RouteTables(_ context.Context, schemaName string, tableNames []string) (RouteTablesResult, error)
- func (c *Cluster) UpdateClusterView(ctx context.Context, state storage.ClusterState, ...) error
- func (c *Cluster) UpdateShardTables(ctx context.Context, shardTablesArr []ShardTables) error
- type CreateClusterOpts
- type CreateShardView
- type CreateTableResult
- type DropTableResult
- type GetNodeShardsResult
- type GetShardNodesByTableIDsResult
- type GetShardNodesResult
- type GetShardTablesByNodeResult
- type Manager
- type RegisteredNode
- type RouteEntry
- type RouteTablesResult
- type ShardInfo
- type ShardNodeWithVersion
- type ShardTableIDs
- type ShardTables
- type ShardVersionUpdate
- type TableInfo
- type TableManager
- type TableManagerImpl
- func (m *TableManagerImpl) CreateTable(ctx context.Context, schemaName string, tableName string, partitioned bool) (storage.Table, error)
- func (m *TableManagerImpl) DropTable(ctx context.Context, schemaName string, tableName string) error
- func (m *TableManagerImpl) GetOrCreateSchema(ctx context.Context, schemaName string) (storage.Schema, bool, error)
- func (m *TableManagerImpl) GetSchemaByName(schemaName string) (storage.Schema, bool)
- func (m *TableManagerImpl) GetSchemas() []storage.Schema
- func (m *TableManagerImpl) GetTable(schemaName, tableName string) (storage.Table, bool, error)
- func (m *TableManagerImpl) GetTablesByIDs(tableIDs []storage.TableID) []storage.Table
- func (m *TableManagerImpl) Load(ctx context.Context) error
- type Tables
- type TopologyManager
- type TopologyManagerImpl
- func (m *TopologyManagerImpl) AddTable(ctx context.Context, nodeName string, table storage.Table) (ShardVersionUpdate, error)
- func (m *TopologyManagerImpl) CreateShardViews(ctx context.Context, createShardViews []CreateShardView) error
- func (m *TopologyManagerImpl) GetClusterState() storage.ClusterState
- func (m *TopologyManagerImpl) GetShardNodes() GetShardNodesResult
- func (m *TopologyManagerImpl) GetShardNodesByID(shardID storage.ShardID) ([]storage.ShardNode, error)
- func (m *TopologyManagerImpl) GetShardNodesByTableIDs(tableIDs []storage.TableID) (GetShardNodesByTableIDsResult, error)
- func (m *TopologyManagerImpl) GetTableIDs(shardIDs []storage.ShardID, nodeName string) map[storage.ShardID]ShardTableIDs
- func (m *TopologyManagerImpl) GetVersion() uint64
- func (m *TopologyManagerImpl) InitClusterView(ctx context.Context) error
- func (m *TopologyManagerImpl) Load(ctx context.Context) error
- func (m *TopologyManagerImpl) RemoveTable(ctx context.Context, tableID storage.TableID) (ShardVersionUpdate, error)
- func (m *TopologyManagerImpl) UpdateClusterView(ctx context.Context, state storage.ClusterState, ...) error
- func (m *TopologyManagerImpl) UpdateShardView(ctx context.Context, shardView storage.ShardView) (ShardVersionUpdate, error)
- type UpdateShardTablesResult
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") 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") )
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 Cluster ¶
type Cluster struct {
// contains filtered or unexported fields
}
func NewCluster ¶
func (*Cluster) AllocShardID ¶ added in v0.4.0
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 (*Cluster) GetClusterID ¶ added in v0.4.0
func (*Cluster) GetClusterMinNodeCount ¶ added in v0.4.0
func (*Cluster) GetClusterState ¶ added in v0.4.0
func (c *Cluster) GetClusterState() storage.ClusterState
func (*Cluster) GetClusterViewVersion ¶ added in v1.0.0
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 (*Cluster) GetShardTables ¶ added in v1.0.0
func (*Cluster) GetTable ¶
GetTable the second output parameter bool: returns true if the table exists.
func (*Cluster) GetTotalShardNum ¶ added in v0.4.0
func (*Cluster) RegisterNode ¶
func (c *Cluster) RegisterNode(ctx context.Context, registeredNode RegisteredNode) error
func (*Cluster) RouteTables ¶
func (*Cluster) UpdateClusterView ¶ added in v1.0.0
func (*Cluster) UpdateShardTables ¶
func (c *Cluster) UpdateShardTables(ctx context.Context, shardTablesArr []ShardTables) error
type CreateClusterOpts ¶ added in v1.0.0
type CreateShardView ¶ added in v1.0.0
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 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)
}
type RegisteredNode ¶ added in v0.4.0
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 ShardTableIDs ¶ added in v1.0.0
type ShardTables ¶
type ShardVersionUpdate ¶ added in v0.4.0
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, partitioned bool) (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.
type TableManagerImpl ¶ added in v1.0.0
type TableManagerImpl struct {
// contains filtered or unexported fields
}
func (*TableManagerImpl) CreateTable ¶ added in v1.0.0
func (*TableManagerImpl) GetOrCreateSchema ¶ added in v1.0.0
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) GetTablesByIDs ¶ added in v1.0.0
func (m *TableManagerImpl) GetTablesByIDs(tableIDs []storage.TableID) []storage.Table
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, nodeName string, table storage.Table) (ShardVersionUpdate, error)
// RemoveTable remove table from cluster topology.
RemoveTable(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
// UpdateShardView update shardView.
UpdateShardView(ctx context.Context, shardView storage.ShardView) (ShardVersionUpdate, error)
}
TopologyManager manages the cluster topology, including the mapping relationship between shards, nodes, and tables.
func NewTopologyManagerImpl ¶ added in v1.0.0
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, nodeName string, table storage.Table) (ShardVersionUpdate, error)
func (*TopologyManagerImpl) CreateShardViews ¶ added in v1.0.0
func (m *TopologyManagerImpl) CreateShardViews(ctx context.Context, createShardViews []CreateShardView) 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 (*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 (m *TopologyManagerImpl) Load(ctx context.Context) error
func (*TopologyManagerImpl) RemoveTable ¶ added in v1.0.0
func (m *TopologyManagerImpl) RemoveTable(ctx context.Context, tableID 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
func (*TopologyManagerImpl) UpdateShardView ¶
func (m *TopologyManagerImpl) UpdateShardView(ctx context.Context, shardView storage.ShardView) (ShardVersionUpdate, error)
type UpdateShardTablesResult ¶
type UpdateShardTablesResult struct {
ShardVersionUpdate ShardVersionUpdate
}
Click to show internal directories.
Click to hide internal directories.