sharding

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: Apache-2.0 Imports: 24 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// LabelKubeVelaShardID label key for identify the shard id for the controller
	LabelKubeVelaShardID = "controller.core.oam.dev/shard-id"
	// LabelKubeVelaScheduledShardID label key for identify the scheduled shard id for the resource
	LabelKubeVelaScheduledShardID = "controller.core.oam.dev/scheduled-shard-id"
	// MasterShardID the master shard id
	MasterShardID = "master"
)

Variables

View Source
var (
	// ShardID the id of the shard
	ShardID = MasterShardID
	// EnableSharding whether enable sharding
	EnableSharding bool
	// SchedulableShards the shards for schedule
	SchedulableShards []string
	// DynamicDiscoverySchedulerResyncPeriod resync period for default dynamic discovery scheduler
	DynamicDiscoverySchedulerResyncPeriod = 5 * time.Minute
)
View Source
var DefaultScheduler = singleton.NewSingleton[Scheduler](func() Scheduler {
	SchedulableShards = velaslices.Filter(SchedulableShards, func(s string) bool { return len(s) > 0 })
	if len(SchedulableShards) > 0 {
		klog.Infof("staticScheduler initialized")
		return NewStaticScheduler(SchedulableShards)
	}
	klog.Infof("dynamicDiscoveryScheduler initialized")
	return NewDynamicDiscoveryScheduler(meta.Name, DynamicDiscoverySchedulerResyncPeriod)
})

DefaultScheduler default scheduler

Functions

func AddControllerFlags

func AddControllerFlags(fs *pflag.FlagSet)

AddControllerFlags add sharding controller flags

func AddFlags

func AddFlags(fs *pflag.FlagSet)

AddFlags add sharding flags

func AddSchedulerFlags

func AddSchedulerFlags(fs *pflag.FlagSet)

AddSchedulerFlags add sharding scheduler flags

func BuildCache

func BuildCache(scheme *runtime.Scheme, shardingObjects ...client.Object) cache.NewCacheFunc

BuildCache add shard-id label selector for given typed object

func BuildCacheWithOptions

func BuildCacheWithOptions(opts cache.Options, shardingObjects ...client.Object) cache.NewCacheFunc

BuildCacheWithOptions add shard-id label selector to sharding objects with options

func DelScheduledShardID

func DelScheduledShardID(o client.Object)

DelScheduledShardID delete shard-id from target object

func GetScheduledShardID

func GetScheduledShardID(o client.Object) (string, bool)

GetScheduledShardID return the scheduled shard-id of the object and if it is scheduled

func GetShardIDSuffix

func GetShardIDSuffix() string

GetShardIDSuffix return suffix for shard id if enabled

func IsMaster

func IsMaster() bool

IsMaster check if current instance is master

func PropagateScheduledShardIDLabel

func PropagateScheduledShardIDLabel(from client.Object, to client.Object)

PropagateScheduledShardIDLabel copy the shard-id from source obj to target obj, remove if not exist

func SetScheduledShardID

func SetScheduledShardID(o client.Object, id string)

SetScheduledShardID set shard-id to target object

Types

type Scheduler

type Scheduler interface {
	Start(context.Context)
	Schedule(client.Object) bool
}

Scheduler schedule shard-id for object

func NewDynamicDiscoveryScheduler

func NewDynamicDiscoveryScheduler(name string, resyncPeriod time.Duration) Scheduler

NewDynamicDiscoveryScheduler create a scheduler that allow dynamic discovery for available shards

func NewStaticScheduler

func NewStaticScheduler(shards []string) Scheduler

NewStaticScheduler create a scheduler that do not make update but only use predefined shards for allocate

Jump to

Keyboard shortcuts

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