keyspace

package
v1.1.0-beta.0...-debceaf Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2025 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AllocStep set idAllocator's step when write persistent window boundary.
	// Use a lower value for denser idAllocation in the event of frequent pd leader change.
	AllocStep = uint64(100)

	// UserKindKey is the key for user kind in keyspace config.
	UserKindKey = "user_kind"
	// TSOKeyspaceGroupIDKey is the key for tso keyspace group id in keyspace config.
	// Note: Config[TSOKeyspaceGroupIDKey] is only used to judge whether there is keyspace group id.
	// It will not update the keyspace group id when merging or splitting.
	TSOKeyspaceGroupIDKey = "tso_keyspace_group_id"

	// If `gc_management_type` is `global_gc`, it means the current keyspace requires a tidb without 'keyspace-name'
	// configured to run a global gc worker to calculate a global gc safe point.
	// If `gc_management_type` is `keyspace_level_gc` it means the current keyspace can calculate gc safe point by its own.
	GCManagementType = "gc_management_type"
	// KeyspaceLevelGC is a type of gc_management_type used to indicate that this keyspace independently advances its own gc safe point.
	KeyspaceLevelGC = "keyspace_level_gc"
)

Variables

This section is empty.

Functions

func MakeKeyRanges

func MakeKeyRanges(id uint32) []any

MakeKeyRanges encodes keyspace ID to correct LabelRule data.

func MakeLabelRule

func MakeLabelRule(id uint32) *labeler.LabelRule

MakeLabelRule makes the label rule for the given keyspace id.

func MaskKeyspaceID

func MaskKeyspaceID(id uint32) uint32

MaskKeyspaceID is used to hash the spaceID inside the lockGroup. A simple mask is applied to spaceID to use its last byte as map key, limiting the maximum map length to 256. Since keyspaceID is sequentially allocated, this can also reduce the chance of collision when comparing with random hashes.

Types

type Config

type Config interface {
	GetPreAlloc() []string
	ToWaitRegionSplit() bool
	GetWaitRegionSplitTimeout() time.Duration
	GetCheckRegionSplitInterval() time.Duration
}

Config is the interface for keyspace config.

type CreateKeyspaceRequest

type CreateKeyspaceRequest struct {
	// Name of the keyspace to be created.
	// Using an existing name will result in error.
	Name   string
	Config map[string]string
	// CreateTime is the timestamp used to record creation time.
	CreateTime int64
	// IsPreAlloc indicates whether the keyspace is pre-allocated when the cluster starts.
	IsPreAlloc bool
}

CreateKeyspaceRequest represents necessary arguments to create a keyspace.

type GroupManager

type GroupManager struct {
	syncutil.RWMutex
	// contains filtered or unexported fields
}

GroupManager is the manager of keyspace group related data.

func NewKeyspaceGroupManager

func NewKeyspaceGroupManager(
	ctx context.Context,
	store endpoint.KeyspaceGroupStorage,
	client *clientv3.Client,
) *GroupManager

NewKeyspaceGroupManager creates a Manager of keyspace group related data.

func (*GroupManager) AllocNodesForKeyspaceGroup

func (m *GroupManager) AllocNodesForKeyspaceGroup(id uint32, existMembers map[string]struct{}, desiredReplicaCount int) ([]endpoint.KeyspaceGroupMember, error)

AllocNodesForKeyspaceGroup allocates nodes for the keyspace group.

func (*GroupManager) Bootstrap

func (m *GroupManager) Bootstrap(ctx context.Context) error

Bootstrap saves default keyspace group info and init group mapping in the memory.

func (*GroupManager) Close

func (m *GroupManager) Close()

Close closes the manager.

func (*GroupManager) CreateKeyspaceGroups

func (m *GroupManager) CreateKeyspaceGroups(keyspaceGroups []*endpoint.KeyspaceGroup) error

CreateKeyspaceGroups creates keyspace groups.

func (*GroupManager) DeleteKeyspaceGroupByID

func (m *GroupManager) DeleteKeyspaceGroupByID(id uint32) (*endpoint.KeyspaceGroup, error)

DeleteKeyspaceGroupByID deletes the keyspace group by ID.

func (*GroupManager) FinishMergeKeyspaceByID

func (m *GroupManager) FinishMergeKeyspaceByID(mergeTargetID uint32) error

FinishMergeKeyspaceByID finishes the merging keyspace group by the merge target ID.

func (*GroupManager) FinishSplitKeyspaceByID

func (m *GroupManager) FinishSplitKeyspaceByID(splitTargetID uint32) error

FinishSplitKeyspaceByID finishes the split keyspace group by the split target ID.

func (*GroupManager) GetGroupByKeyspaceID

func (m *GroupManager) GetGroupByKeyspaceID(id uint32) (uint32, error)

GetGroupByKeyspaceID returns the keyspace group ID for the given keyspace ID.

func (*GroupManager) GetKeyspaceConfigByKind

func (m *GroupManager) GetKeyspaceConfigByKind(userKind endpoint.UserKind) (map[string]string, error)

GetKeyspaceConfigByKind returns the keyspace config for the given user kind.

func (*GroupManager) GetKeyspaceGroupByID

func (m *GroupManager) GetKeyspaceGroupByID(id uint32) (*endpoint.KeyspaceGroup, error)

GetKeyspaceGroupByID returns the keyspace group by ID.

func (*GroupManager) GetKeyspaceGroupPrimaryByID

func (m *GroupManager) GetKeyspaceGroupPrimaryByID(id uint32) (string, error)

GetKeyspaceGroupPrimaryByID returns the primary node of the keyspace group by ID.

func (*GroupManager) GetKeyspaceGroups

func (m *GroupManager) GetKeyspaceGroups(startID uint32, limit int) ([]*endpoint.KeyspaceGroup, error)

GetKeyspaceGroups gets keyspace groups from the start ID with limit. If limit is 0, it will load all keyspace groups from the start ID.

func (*GroupManager) GetNodesCount

func (m *GroupManager) GetNodesCount() int

GetNodesCount returns the count of nodes.

func (*GroupManager) GetTSOServiceAddrs

func (m *GroupManager) GetTSOServiceAddrs() []string

GetTSOServiceAddrs gets all TSO service addresses.

func (*GroupManager) IsExistNode

func (m *GroupManager) IsExistNode(addr string) (bool, string)

IsExistNode checks if the node exists.

func (*GroupManager) MergeAllIntoDefaultKeyspaceGroup

func (m *GroupManager) MergeAllIntoDefaultKeyspaceGroup() error

MergeAllIntoDefaultKeyspaceGroup merges all other keyspace groups into the default keyspace group.

func (*GroupManager) MergeKeyspaceGroups

func (m *GroupManager) MergeKeyspaceGroups(mergeTargetID uint32, mergeList []uint32) error

MergeKeyspaceGroups merges the keyspace group in the list into the target keyspace group.

func (*GroupManager) SetNodesForKeyspaceGroup

func (m *GroupManager) SetNodesForKeyspaceGroup(id uint32, nodes []string) error

SetNodesForKeyspaceGroup sets the nodes for the keyspace group.

func (*GroupManager) SetPriorityForKeyspaceGroup

func (m *GroupManager) SetPriorityForKeyspaceGroup(id uint32, node string, priority int) error

SetPriorityForKeyspaceGroup sets the priority of node for the keyspace group.

func (*GroupManager) SplitKeyspaceGroupByID

func (m *GroupManager) SplitKeyspaceGroupByID(
	splitSourceID, splitTargetID uint32,
	keyspaces []uint32, keyspaceIDRange ...uint32,
) error

SplitKeyspaceGroupByID splits the keyspace group by ID into a new keyspace group with the given new ID. And the keyspaces in the old keyspace group will be moved to the new keyspace group.

func (*GroupManager) UpdateKeyspaceForGroup

func (m *GroupManager) UpdateKeyspaceForGroup(userKind endpoint.UserKind, groupID string, keyspaceID uint32, mutation int) error

UpdateKeyspaceForGroup updates the keyspace field for the keyspace group.

func (*GroupManager) UpdateKeyspaceGroup

func (m *GroupManager) UpdateKeyspaceGroup(oldGroupID, newGroupID string, oldUserKind, newUserKind endpoint.UserKind, keyspaceID uint32) error

UpdateKeyspaceGroup updates the keyspace group.

type Manager

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

Manager manages keyspace related data. It validates requests and provides concurrency control.

func NewKeyspaceManager

func NewKeyspaceManager(
	ctx context.Context,
	store endpoint.KeyspaceStorage,
	cluster core.ClusterInformer,
	idAllocator id.Allocator,
	config Config,
	kgm *GroupManager,
) *Manager

NewKeyspaceManager creates a Manager of keyspace related data.

func (*Manager) Bootstrap

func (manager *Manager) Bootstrap() error

Bootstrap saves default keyspace info.

func (*Manager) CreateKeyspace

func (manager *Manager) CreateKeyspace(request *CreateKeyspaceRequest) (*keyspacepb.KeyspaceMeta, error)

CreateKeyspace create a keyspace meta with given config and save it to storage.

func (*Manager) LoadKeyspace

func (manager *Manager) LoadKeyspace(name string) (*keyspacepb.KeyspaceMeta, error)

LoadKeyspace returns the keyspace specified by name. It returns error if loading or unmarshalling met error or if keyspace does not exist.

func (*Manager) LoadKeyspaceByID

func (manager *Manager) LoadKeyspaceByID(spaceID uint32) (*keyspacepb.KeyspaceMeta, error)

LoadKeyspaceByID returns the keyspace specified by id. It returns error if loading or unmarshalling met error or if keyspace does not exist.

func (*Manager) LoadRangeKeyspace

func (manager *Manager) LoadRangeKeyspace(startID uint32, limit int) ([]*keyspacepb.KeyspaceMeta, error)

LoadRangeKeyspace load up to limit keyspaces starting from keyspace with startID.

func (*Manager) PatrolKeyspaceAssignment

func (manager *Manager) PatrolKeyspaceAssignment(startKeyspaceID, endKeyspaceID uint32) error

PatrolKeyspaceAssignment is used to patrol all keyspaces and assign them to the keyspace groups.

func (*Manager) UpdateConfig

func (manager *Manager) UpdateConfig(cfg Config)

UpdateConfig update keyspace manager's config.

func (*Manager) UpdateKeyspaceConfig

func (manager *Manager) UpdateKeyspaceConfig(name string, mutations []*Mutation) (*keyspacepb.KeyspaceMeta, error)

UpdateKeyspaceConfig changes target keyspace's config in the order specified in mutations. It returns error if saving failed, operation not allowed, or if keyspace not exists.

func (*Manager) UpdateKeyspaceState

func (manager *Manager) UpdateKeyspaceState(name string, newState keyspacepb.KeyspaceState, now int64) (*keyspacepb.KeyspaceMeta, error)

UpdateKeyspaceState updates target keyspace to the given state if it's not already in that state. It returns error if saving failed, operation not allowed, or if keyspace not exists.

func (*Manager) UpdateKeyspaceStateByID

func (manager *Manager) UpdateKeyspaceStateByID(id uint32, newState keyspacepb.KeyspaceState, now int64) (*keyspacepb.KeyspaceMeta, error)

UpdateKeyspaceStateByID updates target keyspace to the given state if it's not already in that state. It returns error if saving failed, operation not allowed, or if keyspace not exists.

type Mutation

type Mutation struct {
	Op    OpType
	Key   string
	Value string
}

Mutation represents a single operation to be applied on keyspace config.

type OpType

type OpType int

OpType defines the type of keyspace config operation.

const (
	// OpPut denotes a put operation onto the given config.
	// If target key exists, it will put a new value,
	// otherwise, it creates a new config entry.
	OpPut OpType = iota + 1 // Operation type starts at 1.
	// OpDel denotes a deletion operation onto the given config.
	// Note: OpDel is idempotent, deleting a non-existing key
	// will not result in error.
	OpDel
)

type RegionBound

type RegionBound struct {
	RawLeftBound  []byte
	RawRightBound []byte
	TxnLeftBound  []byte
	TxnRightBound []byte
}

RegionBound represents the region boundary of the given keyspace. For a keyspace with id ['a', 'b', 'c'], it has four boundaries:

Lower bound for raw mode: ['r', 'a', 'b', 'c']
Upper bound for raw mode: ['r', 'a', 'b', 'c + 1']
Lower bound for txn mode: ['x', 'a', 'b', 'c']
Upper bound for txn mode: ['x', 'a', 'b', 'c + 1']

From which it shares the lower bound with keyspace with id ['a', 'b', 'c-1']. And shares upper bound with keyspace with id ['a', 'b', 'c + 1']. These repeated bound will not cause any problem, as repetitive bound will be ignored during rangeListBuild, but provides guard against hole in keyspace allocations should it occur.

func MakeRegionBound

func MakeRegionBound(id uint32) *RegionBound

MakeRegionBound constructs the correct region boundaries of the given keyspace.

Jump to

Keyboard shortcuts

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