kvscheduler

package
v2.3.0-alpha+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2019 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DependencyRelation identifies dependency relation for the graph.
	DependencyRelation = "depends-on"

	// DerivesRelation identifies relation of value derivation for the graph.
	DerivesRelation = "derives"
)
View Source
const (

	// LastUpdateFlagName is the name of the LastUpdate flag.
	LastUpdateFlagName = "last-update"
	// LastUpdateFlagIndex is the Index of the LastUpdate flag.
	LastUpdateFlagIndex = 0

	// ErrorFlagName is the name of the Error flag.
	ErrorFlagName = "error"
	// ErrorFlagIndex is the Index of the ErrorFlag flag.
	ErrorFlagIndex = 1

	// ValueStateFlagName is the name of the Value-State flag.
	ValueStateFlagName = "value-state"
	// ValueStateFlagIndex is the index of the Value-State flag.
	ValueStateFlagIndex = 2

	// UnavailValueFlagName is the name of the Unavailable-Value flag.
	UnavailValueFlagName = "unavailable"
	// UnavailValueFlagIndex is the index of the Unavailable-Value flag.
	UnavailValueFlagIndex = 3

	// DescriptorFlagName is the name of the Descriptor flag.
	DescriptorFlagName = "descriptor"
	// DescriptorFlagIndex is the index of the Descriptor flag.
	DescriptorFlagIndex = 4

	// DerivedFlagName is the name of the Derived flag.
	DerivedFlagName = "derived"
	// DerivedFlagIndex is the index of the Derived flag.
	DerivedFlagIndex = 5
)

Variables

View Source
var DefaultPlugin = *NewPlugin()

DefaultPlugin is a default instance of Plugin.

Functions

func NewDotCluster

func NewDotCluster(id string) *dotCluster

func WriteDot

func WriteDot(w io.Writer, g *dotGraph) error

Types

type Config

type Config struct {
	RecordTransactionHistory      bool   `json:"record-transaction-history"`
	TransactionHistoryAgeLimit    uint32 `json:"transaction-history-age-limit"`    // in minutes
	PermanentlyRecordedInitPeriod uint32 `json:"permanently-recorded-init-period"` // in minutes
	EnableTxnSimulation           bool   `json:"enable-txn-simulation"`
	PrintTxnSummary               bool   `json:"print-txn-summary"`
}

Config holds the KVScheduler configuration.

type Deps

type Deps struct {
	infra.PluginDeps
	HTTPHandlers rest.HTTPHandlers
}

Deps lists dependencies of the scheduler.

type DerivedFlag

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

DerivedFlag is used to mark derived values.

func (*DerivedFlag) GetIndex

func (flag *DerivedFlag) GetIndex() int

GetIndex returns 5.

func (*DerivedFlag) GetName

func (flag *DerivedFlag) GetName() string

GetName return name of the Derived flag.

func (*DerivedFlag) GetValue

func (flag *DerivedFlag) GetValue() string

GetValue returns the key of the base value from which the given derived value is derived from (directly or transitively).

type DescriptorFlag

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

DescriptorFlag is used to lookup values by their descriptor. Not assigned to properties and UNIMPLEMENTED values.

func (*DescriptorFlag) GetIndex

func (flag *DescriptorFlag) GetIndex() int

GetIndex returns 4.

func (*DescriptorFlag) GetName

func (flag *DescriptorFlag) GetName() string

GetName return name of the Descriptor flag.

func (*DescriptorFlag) GetValue

func (flag *DescriptorFlag) GetValue() string

GetValue returns the descriptor name.

type ErrorFlag

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

ErrorFlag is used to store error returned from the last operation, including validation errors.

func (*ErrorFlag) GetIndex

func (flag *ErrorFlag) GetIndex() int

GetIndex returns 1.

func (*ErrorFlag) GetName

func (flag *ErrorFlag) GetName() string

GetName return name of the Origin flag.

func (*ErrorFlag) GetValue

func (flag *ErrorFlag) GetValue() string

GetValue returns the error as string.

type LastUpdateFlag

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

LastUpdateFlag is set to remember the last transaction which has changed/updated the value. Not set to values just discovered by refresh (state = DISCOVERED).

func (*LastUpdateFlag) GetIndex

func (flag *LastUpdateFlag) GetIndex() int

GetIndex returns 0.

func (*LastUpdateFlag) GetName

func (flag *LastUpdateFlag) GetName() string

GetName return name of the LastUpdate flag.

func (*LastUpdateFlag) GetValue

func (flag *LastUpdateFlag) GetValue() string

GetValue describes the last update (txn-seq number only).

type Option

type Option func(*Scheduler)

Option is a function that can be used in NewPlugin to customize Plugin.

func UseDeps

func UseDeps(cb func(*Deps)) Option

UseDeps returns Option that can inject custom dependencies.

type Scheduler

type Scheduler struct {
	Deps
	// contains filtered or unexported fields
}

Scheduler is a CN-infra plugin implementing KVScheduler. Detailed documentation can be found in the "api" and "docs" sub-folders.

func NewPlugin

func NewPlugin(opts ...Option) *Scheduler

NewPlugin creates a new Plugin with the provided Options.

func (*Scheduler) Close

func (s *Scheduler) Close() error

Close stops all the go routines.

func (*Scheduler) DumpValuesByDescriptor

func (s *Scheduler) DumpValuesByDescriptor(descriptor string, view kvs.View) (values []kvs.KVWithMetadata, err error)

DumpValuesByDescriptor dumps values associated with the given descriptor as viewed from either NB (what was requested to be applied), SB (what is actually applied) or from the inside (what kvscheduler's cached view of SB is).

func (*Scheduler) DumpValuesByKeyPrefix

func (s *Scheduler) DumpValuesByKeyPrefix(keyPrefix string, view kvs.View) (values []kvs.KVWithMetadata, err error)

DumpValuesByKeyPrefix like DumpValuesByDescriptor returns a dump of values, but the descriptor is selected based on the key prefix.

func (*Scheduler) GetMetadataMap

func (s *Scheduler) GetMetadataMap(descriptor string) idxmap.NamedMapping

GetMetadataMap returns (read-only) map associating value label with value metadata of a given descriptor. Returns nil if the descriptor does not expose metadata.

func (*Scheduler) GetRecordedTransaction

func (s *Scheduler) GetRecordedTransaction(SeqNum uint64) (txn *kvs.RecordedTxn)

GetRecordedTransaction returns record of a transaction referenced by the sequence number.

func (*Scheduler) GetRegisteredNBKeyPrefixes

func (s *Scheduler) GetRegisteredNBKeyPrefixes() []string

GetRegisteredNBKeyPrefixes returns a list of key prefixes from NB with values described by registered descriptors and therefore managed by the scheduler.

func (*Scheduler) GetTransactionHistory

func (s *Scheduler) GetTransactionHistory(since, until time.Time) (history kvs.RecordedTxns)

GetTransactionHistory returns history of transactions started within the specified time window, or the full recorded history if the timestamps are zero values.

func (*Scheduler) GetValueStatus

func (s *Scheduler) GetValueStatus(key string) *kvs.BaseValueStatus

GetValueStatus returns the status of a non-derived value with the given key.

func (*Scheduler) Init

func (s *Scheduler) Init() error

Init initializes the scheduler. Single go routine is started that will process all the transactions synchronously.

func (*Scheduler) PushSBNotification

func (s *Scheduler) PushSBNotification(notif ...kvs.KVWithMetadata) error

PushSBNotification notifies about a spontaneous value change(s) in the SB plane (i.e. not triggered by NB transaction).

func (*Scheduler) RegisterKVDescriptor

func (s *Scheduler) RegisterKVDescriptor(descriptors ...*kvs.KVDescriptor) error

RegisterKVDescriptor registers descriptor(s) for a set of selected keys. It should be called in the Init phase of agent plugins. Every key-value pair must have at most one descriptor associated with it (none for derived values expressing properties).

func (*Scheduler) StartNBTransaction

func (s *Scheduler) StartNBTransaction() kvs.Txn

StartNBTransaction starts a new transaction from NB to SB plane. The enqueued actions are scheduled for execution by Txn.Commit().

func (*Scheduler) TransactionBarrier

func (s *Scheduler) TransactionBarrier()

TransactionBarrier ensures that all notifications received prior to the call are associated with transactions that have already finalized.

func (*Scheduler) WatchValueStatus

func (s *Scheduler) WatchValueStatus(channel chan<- *kvs.BaseValueStatus, keySelector kvs.KeySelector)

WatchValueStatus allows to watch for changes in the status of non-derived values with keys selected by the selector (all if keySelector==nil).

type SchedulerTxn

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

SchedulerTxn implements transaction for the KV scheduler.

func (*SchedulerTxn) Commit

func (txn *SchedulerTxn) Commit(ctx context.Context) (txnSeqNum uint64, err error)

Commit orders scheduler to execute enqueued operations. Operations with unmet dependencies will get postponed and possibly executed later.

func (*SchedulerTxn) SetValue

func (txn *SchedulerTxn) SetValue(key string, value proto.Message) kvs.Txn

SetValue changes (non-derived) value. If <value> is nil, the value will get deleted.

type Stats

type Stats struct {
	TxnStats       TxnStats
	GraphMethods   StructStats
	AllDescriptors StructStats
	Descriptors    map[string]*StructStats
}

func GetStats

func GetStats() *Stats

type StructStats

type StructStats struct {
	Methods metrics.Calls `json:"-,omitempty"`
}

func (*StructStats) MarshalJSON

func (s *StructStats) MarshalJSON() ([]byte, error)

type TxnStats

type TxnStats struct {
	TotalProcessed  uint64
	OperationCount  map[string]uint64
	ValueStateCount map[string]uint64
	ErrorCount      uint64
	Methods         metrics.Calls
}

type UnavailValueFlag

type UnavailValueFlag struct {
}

UnavailValueFlag is used to mark NB values which should not be considered when resolving dependencies of other values (for various possible reasons).

func (*UnavailValueFlag) GetIndex

func (flag *UnavailValueFlag) GetIndex() int

GetIndex returns 3.

func (*UnavailValueFlag) GetName

func (flag *UnavailValueFlag) GetName() string

GetName return name of the UnavailValue flag.

func (*UnavailValueFlag) GetValue

func (flag *UnavailValueFlag) GetValue() string

GetValue return empty string (presence of the flag is the only information).

type ValueStateFlag

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

ValueStateFlag stores current state of the value. Assigned to every value.

func (*ValueStateFlag) GetIndex

func (flag *ValueStateFlag) GetIndex() int

GetIndex returns 2.

func (*ValueStateFlag) GetName

func (flag *ValueStateFlag) GetName() string

GetName returns name of the ValueState flag.

func (*ValueStateFlag) GetValue

func (flag *ValueStateFlag) GetValue() string

GetValue returns the string representation of the state.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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