Documentation ¶
Overview ¶
Package agency provides an API to access the ArangoDB agency (it is unlikely that you need this package directly).
The Agency is fault-tolerant and highly-available key-value store that is used to store critical, low-level information about an ArangoDB cluster.
THIS API IS NOT USED FOR NORMAL DATABASE ACCESS.
Reasons for using this API are: - You want to make use of an indepent Agency as your own HA key-value store. - You want access to low-level information of your database. USE WITH GREAT CARE!
WARNING: Messing around in the Agency can quickly lead to a corrupt database!
Index ¶
- Variables
- func AreAgentsHealthy(ctx context.Context, clients []driver.Connection) error
- func IsAlreadyLocked(err error) bool
- func IsKeyNotFound(err error) bool
- func IsNotLocked(err error) bool
- func IsSameEndpoint(a, b string) bool
- func NewAgencyConnection(config http.ConnectionConfig) (driver.Connection, error)
- func WithAllowNoLeader(parent context.Context) context.Context
- type Agency
- type KeyNotFoundError
- type Lock
- type Logger
- type WriteCondition
Constants ¶
This section is empty.
Variables ¶
var ( // AlreadyLockedError indicates that the lock is already locked. AlreadyLockedError = errors.New("already locked") // NotLockedError indicates that the lock is not locked when trying to unlock. NotLockedError = errors.New("not locked") )
Functions ¶
func AreAgentsHealthy ¶
func AreAgentsHealthy(ctx context.Context, clients []driver.Connection) error
AreAgentsHealthy performs a health check on all given agents. Of the given agents, 1 must respond as leader and all others must redirect to the leader. The function returns nil when all agents are healthy or an error when something is wrong.
func IsAlreadyLocked ¶
IsAlreadyLocked returns true if the given error is or is caused by an AlreadyLockedError.
func IsKeyNotFound ¶
IsKeyNotFound returns true if the given error is (or is caused by) a KeyNotFoundError.
func IsNotLocked ¶
IsNotLocked returns true if the given error is or is caused by an NotLockedError.
func IsSameEndpoint ¶
IsSameEndpoint returns true when the 2 given endpoints refer to the same server.
func NewAgencyConnection ¶
func NewAgencyConnection(config http.ConnectionConfig) (driver.Connection, error)
NewAgencyConnection creates an agency connection for agents at the given endpoints. This type of connection differs from normal HTTP/VST connection in the way requests are executed. This type of connection makes use of the fact that only 1 agent will respond to requests at a time. All other agents will respond with an "I'm not the leader" error. A request will be send to all agents at the same time. The result of the first agent to respond with a normal response is used.
Types ¶
type Agency ¶
type Agency interface { // Connection returns the connection used by this api. Connection() driver.Connection // ReadKey reads the value of a given key in the agency. ReadKey(ctx context.Context, key []string, value interface{}) error // WriteKey writes the given value with the given key with a given TTL (unless TTL is zero). // If you pass a condition (only 1 allowed), this condition has to be true, // otherwise the write will fail with a ConditionFailed error. WriteKey(ctx context.Context, key []string, value interface{}, ttl time.Duration, condition ...WriteCondition) error // WriteKeyIfEmpty writes the given value with the given key only if the key was empty before. WriteKeyIfEmpty(ctx context.Context, key []string, value interface{}, ttl time.Duration) error // WriteKeyIfEqualTo writes the given new value with the given key only if the existing value for that key equals // to the given old value. WriteKeyIfEqualTo(ctx context.Context, key []string, newValue, oldValue interface{}, ttl time.Duration) error // RemoveKey removes the given key. // If you pass a condition (only 1 allowed), this condition has to be true, // otherwise the remove will fail with a ConditionFailed error. RemoveKey(ctx context.Context, key []string, condition ...WriteCondition) error // RemoveKeyIfEqualTo removes the given key only if the existing value for that key equals // to the given old value. RemoveKeyIfEqualTo(ctx context.Context, key []string, oldValue interface{}) error // Register a URL to receive notification callbacks when the value of the given key changes RegisterChangeCallback(ctx context.Context, key []string, cbURL string) error // Register a URL to receive notification callbacks when the value of the given key changes UnregisterChangeCallback(ctx context.Context, key []string, cbURL string) error }
Agency provides API implemented by the ArangoDB agency.
type KeyNotFoundError ¶
type KeyNotFoundError struct {
Key []string
}
KeyNotFoundError indicates that a key was not found.
func (KeyNotFoundError) Error ¶
func (e KeyNotFoundError) Error() string
Error returns a human readable error string
type Lock ¶
type Lock interface { // Lock tries to lock the lock. // If it is not possible to lock, an error is returned. // If the lock is already held by me, an error is returned. Lock(ctx context.Context) error // Unlock tries to unlock the lock. // If it is not possible to unlock, an error is returned. // If the lock is not held by me, an error is returned. Unlock(ctx context.Context) error // IsLocked return true if the lock is held by me. IsLocked() bool }
Lock is an agency backed exclusive lock.
type Logger ¶
type Logger interface {
Errorf(msg string, args ...interface{})
}
Logger abstracts a logger.
type WriteCondition ¶
type WriteCondition struct {
// contains filtered or unexported fields
}
WriteCondition is a precondition before a write is accepted.
func (WriteCondition) IfEmpty ¶
func (c WriteCondition) IfEmpty(key []string) WriteCondition
IfEmpty adds an "is empty" check on the given key to the given condition and returns the updated condition.
func (WriteCondition) IfEqualTo ¶
func (c WriteCondition) IfEqualTo(key []string, oldValue interface{}) WriteCondition
IfEqualTo adds an "value equals oldValue" check to given old value on the given key to the given condition and returns the updated condition.
func (WriteCondition) IfIsArray ¶
func (c WriteCondition) IfIsArray(key []string) WriteCondition
IfIsArray adds an "is-array" check on the given key to the given condition and returns the updated condition.