storage

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2021 License: Apache-2.0 Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Batch

type Batch struct {
	// SaveKeys save opts
	SaveKeys []string
	// SaveValues save opts
	SaveValues []string
	// RemoveKeys remove keys
	RemoveKeys []string
}

Batch batch opts

type KV

type KV interface {
	// Batch do batch
	Batch(batch *Batch) error
	// Save save key-value paire to storage
	Save(key, value string) error
	// Load load data of key
	Load(key string) (string, error)
	// Remove delete key from storage
	Remove(key string) error
	// LoadRange iterates all key-value pairs in the storage
	LoadRange(key, endKey string, limit int64) ([]string, []string, error)
	// CountRange count all key-value pairs in the storage
	CountRange(key, endKey string) (uint64, error)
	// AllocID allocate a id from kv
	AllocID() (uint64, error)
	// SaveIfNotExists put the value at path
	// returns true, nil, nil if created
	// returns false, exists, nil if not created
	SaveIfNotExists(key string, value string, batch *Batch) (bool, string, error)
	// RemoveIfValueMatched returns true if the expect value is and the exists value are matched
	RemoveIfValueMatched(key string, expect string) (bool, error)
}

KV is an abstract interface for load/save prophet cluster data.

func NewEtcdKV

func NewEtcdKV(rootPath string, client *clientv3.Client, leadship *election.Leadership) KV

NewEtcdKV returns a etcd kv

type Storage

type Storage interface {
	// KV return KV
	KV() KV

	// SaveConfig stores marshallable cfg to the configPath.
	SaveConfig(cfg interface{}) error
	// LoadConfig loads config from configPath then unmarshal it to cfg.
	LoadConfig(cfg interface{}) (bool, error)

	// SaveScheduleConfig saves the config of scheduler.
	SaveScheduleConfig(scheduleName string, data []byte) error
	// RemoveScheduleConfig removes the config of scheduler.
	RemoveScheduleConfig(scheduleName string) error
	// LoadScheduleConfig loads the config of scheduler.
	LoadScheduleConfig(scheduleName string) (string, error)
	// LoadAllScheduleConfig loads all schedulers' config.
	LoadAllScheduleConfig() ([]string, []string, error)

	// PutRule puts the meta to the storage
	PutRule(key string, rule interface{}) error
	// LoadRules load all rules
	LoadRules(limit int64, f func(k, v string) error) error
	// RemoveRule remove rule
	RemoveRule(key string) error

	// PutResource puts the meta to the storage
	PutRuleGroup(groupID string, group interface{}) error
	// RemoveRule remove rule group
	RemoveRuleGroup(groupID string) error
	// LoadResources load all rule groups
	LoadRuleGroups(limit int64, f func(k, v string) error) error

	// PutResource puts the meta to the storage
	PutResource(meta metadata.Resource) error
	// RemoveResource remove resource from storage
	RemoveResource(meta metadata.Resource) error
	// GetResource returns the spec resource
	GetResource(id uint64) (metadata.Resource, error)
	// LoadResources load all resources
	LoadResources(limit int64, do func(metadata.Resource)) error

	// PutContainer returns nil if container is add or update succ
	PutContainer(meta metadata.Container) error
	// RemoveContainer remove container from storage
	RemoveContainer(meta metadata.Container) error
	// GetContainer returns the spec container
	GetContainer(id uint64) (metadata.Container, error)
	// LoadContainers load all containers
	LoadContainers(limit int64, do func(meta metadata.Container, leaderWeight float64, resourceWeight float64)) error

	//PutContainerWeight saves a container's leader and resource weight to storage.
	PutContainerWeight(id uint64, leaderWeight, resourceWeight float64) error

	// PutTimestamp puts the timestamp to storage
	PutTimestamp(time.Time) error
	// GetTimestamp returns tso timestamp
	GetTimestamp() (time.Time, error)

	// AlreadyBootstrapped returns the cluster was already bootstrapped
	AlreadyBootstrapped() (bool, error)
	// PutBootstrapped put cluster is bootstrapped
	PutBootstrapped(container metadata.Container, resources ...metadata.Resource) (bool, error)
}

Storage meta storage

func NewStorage

func NewStorage(rootPath string, kv KV, adapter metadata.Adapter) Storage

NewStorage returns a metadata storage

func NewTestStorage

func NewTestStorage() Storage

NewTestStorage create test storage

Jump to

Keyboard shortcuts

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