keyspace

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: Apache-2.0 Imports: 28 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)
	// AllocLabel is used to label keyspace idAllocator's metrics.
	AllocLabel = "keyspace-idAlloc"
	// DefaultKeyspaceName is the name reserved for default keyspace.
	DefaultKeyspaceName = "DEFAULT"
	// DefaultKeyspaceID is the id of default keyspace.
	DefaultKeyspaceID = uint32(0)

	// 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.
	TSOKeyspaceGroupIDKey = "tso_keyspace_group_id"
)

Variables

View Source
var (
	// ErrKeyspaceNotFound is used to indicate target keyspace does not exist.
	ErrKeyspaceNotFound = errors.New("keyspace does not exist")
	// ErrKeyspaceExists indicates target keyspace already exists.
	// It's used when creating a new keyspace.
	ErrKeyspaceExists = errors.New("keyspace already exists")
	// ErrKeyspaceGroupExists indicates target keyspace group already exists.
	ErrKeyspaceGroupExists = errors.New("keyspace group already exists")
	// ErrKeyspaceGroupNotExists is used to indicate target keyspace group does not exist.
	ErrKeyspaceGroupNotExists = errors.New("keyspace group does not exist")
	// ErrKeyspaceGroupInSplit is used to indicate target keyspace group is in split state.
	ErrKeyspaceGroupInSplit = errors.New("keyspace group is in split state")
	// ErrKeyspaceGroupNotInSplit is used to indicate target keyspace group is not in split state.
	ErrKeyspaceGroupNotInSplit = errors.New("keyspace group is not in split state")
	// ErrKeyspaceNotInKeyspaceGroup is used to indicate target keyspace is not in this keyspace group.
	ErrKeyspaceNotInKeyspaceGroup = errors.New("keyspace is not in this keyspace group")
	// ErrNoAvailableNode is used to indicate no available node in the keyspace group.
	ErrNoAvailableNode = errors.New("no available node")
)

Functions

This section is empty.

Types

type Config

type Config interface {
	GetPreAlloc() []string
}

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
}

CreateKeyspaceRequest represents necessary arguments to create a keyspace.

type GroupManager

type GroupManager struct {

	// the lock for the groups
	sync.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, clusterID uint64) *GroupManager

NewKeyspaceGroupManager creates a Manager of keyspace group related data.

func (*GroupManager) AllocNodesForKeyspaceGroup

func (m *GroupManager) AllocNodesForKeyspaceGroup(id uint32, replica int) ([]endpoint.KeyspaceGroupMember, error)

AllocNodesForKeyspaceGroup allocates nodes for the keyspace group.

func (*GroupManager) Bootstrap

func (m *GroupManager) Bootstrap() 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) FinishSplitKeyspaceByID

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

FinishSplitKeyspaceByID finishes the split keyspace group by the split target 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) 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) GetNodesNum

func (m *GroupManager) GetNodesNum() int

GetNodesNum returns the number of nodes.

func (*GroupManager) SplitKeyspaceGroupByID

func (m *GroupManager) SplitKeyspaceGroupByID(splitSourceID, splitTargetID uint32, keyspaces []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(store endpoint.KeyspaceStorage,
	cluster schedule.Cluster,
	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) 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
)

Jump to

Keyboard shortcuts

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