client

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PermRead      = xlineapi.Permission_READ
	PermWrite     = xlineapi.Permission_WRITE
	PermReadWrite = xlineapi.Permission_READWRITE
)
View Source
const DEFAULT_SESSION_TTL int64 = 60
View Source
const DefaultInitialRetryTimeout = 50 * time.Millisecond
View Source
const DefaultMaxRetryTimeout = 10000 * time.Millisecond
View Source
const DefaultProposeTimeout = 1 * time.Second
View Source
const DefaultRetryCount = 3
View Source
const DefaultWaitSyncedTimeout = 2 * time.Second

Variables

View Source
var (
	ErrShuttingDown        = errors.New("Curp Server is shutting down")
	ErrWrongClusterVersion = errors.New("Wrong cluster version")
	ErrTimeout             = errors.New("Request timeout")
)
View Source
var DefaultUseBackoff = &t

Functions

func BuildCurpClientFromAddrs

func BuildCurpClientFromAddrs(addrs []string, config *ClientConfig) (*protocolClient, error)

Build client from addresses, this method will fetch all members from servers

func Connect

func Connect(allMembers []string, options ...ClientOptions) (*client, error)

func NewCluster

func NewCluster(conn *grpc.ClientConn) *clusterClient

Create a new cluster client

func NewErrInternalError added in v0.1.1

func NewErrInternalError(err error) error

Types

type Auth

type Auth interface {
	// AuthEnable enables auth of an etcd cluster.
	AuthEnable() (*AuthEnableResponse, error)

	// AuthDisable disables auth of an etcd cluster.
	AuthDisable() (*AuthDisableResponse, error)

	// AuthStatus returns the status of auth of an etcd cluster.
	AuthStatus() (*AuthStatusResponse, error)

	// Authenticate login and get token
	Authenticate(name string, password string) (*AuthenticateResponse, error)

	// UserAdd adds a new user to an etcd cluster.
	UserAdd(name string, password string) (*AuthUserAddResponse, error)

	// UserAddWithOptions adds a new user to an etcd cluster with some options.
	UserAddWithOptions(name string, password string, opt *UserAddOptions) (*AuthUserAddResponse, error)

	// UserGet gets a detailed information of a user.
	UserGet(name string) (*AuthUserGetResponse, error)

	// UserList gets a list of all users.
	UserList() (*AuthUserListResponse, error)

	// UserDelete deletes a user from an etcd cluster.
	UserDelete(name string) (*AuthUserDeleteResponse, error)

	// UserChangePassword changes a password of a user.
	UserChangePassword(name string, password string) (*AuthUserChangePasswordResponse, error)

	// UserGrantRole grants a role to a user.
	UserGrantRole(user string, role string) (*AuthUserGrantRoleResponse, error)

	// UserRevokeRole revokes a role of a user.
	UserRevokeRole(name string, role string) (*AuthUserRevokeRoleResponse, error)

	// RoleAdd adds a new role to an etcd cluster.
	RoleAdd(name string) (*AuthRoleAddResponse, error)

	// RoleGet gets a detailed information of a role.
	RoleGet(role string) (*AuthRoleGetResponse, error)

	// RoleList gets a list of all roles.
	RoleList() (*AuthRoleListResponse, error)

	// RoleDelete deletes a role.
	RoleDelete(role string) (*AuthRoleDeleteResponse, error)

	// RoleGrantPermission grants a permission to a role.
	RoleGrantPermission(name string, key, rangeEnd []byte, permType PermissionType) (*AuthRoleGrantPermissionResponse, error)

	// RoleRevokePermission revokes a permission from a role.
	RoleRevokePermission(role string, key, rangeEnd []byte) (*AuthRoleRevokePermissionResponse, error)
}

func NewAuth

func NewAuth(curpClient Curp, token string) Auth

Creates a new `AuthClient`

type AuthDisableResponse

type AuthDisableResponse xlineapi.AuthDisableResponse

type AuthEnableResponse

type AuthEnableResponse xlineapi.AuthEnableResponse

type AuthRoleAddResponse

type AuthRoleAddResponse xlineapi.AuthRoleAddResponse

type AuthRoleDeleteResponse

type AuthRoleDeleteResponse xlineapi.AuthRoleDeleteResponse

type AuthRoleGetResponse

type AuthRoleGetResponse xlineapi.AuthRoleGetResponse

type AuthRoleGrantPermissionResponse

type AuthRoleGrantPermissionResponse xlineapi.AuthRoleGrantPermissionResponse

type AuthRoleListResponse

type AuthRoleListResponse xlineapi.AuthRoleListResponse

type AuthRoleRevokePermissionResponse

type AuthRoleRevokePermissionResponse xlineapi.AuthRoleRevokePermissionResponse

type AuthStatusResponse

type AuthStatusResponse xlineapi.AuthStatusResponse

type AuthUserAddResponse

type AuthUserAddResponse xlineapi.AuthUserAddResponse

type AuthUserChangePasswordResponse

type AuthUserChangePasswordResponse xlineapi.AuthUserChangePasswordResponse

type AuthUserDeleteResponse

type AuthUserDeleteResponse xlineapi.AuthUserDeleteResponse

type AuthUserGetResponse

type AuthUserGetResponse xlineapi.AuthUserGetResponse

type AuthUserGrantRoleResponse

type AuthUserGrantRoleResponse xlineapi.AuthUserGrantRoleResponse

type AuthUserListResponse

type AuthUserListResponse xlineapi.AuthUserListResponse

type AuthUserRevokeRoleResponse

type AuthUserRevokeRoleResponse xlineapi.AuthUserRevokeRoleResponse

type AuthenticateResponse

type AuthenticateResponse xlineapi.AuthenticateResponse

type ClientConfig

type ClientConfig struct {
	// Curp client wait sync timeout
	WaitSyncedTimeout time.Duration

	// Curp client propose request timeout
	ProposeTimeout time.Duration

	// Curp client initial retry interval
	InitialRetryTimeout time.Duration

	// Curp client max retry interval
	MaxRetryTimeout time.Duration

	// Curp client retry interval
	RetryCount int

	// Whether to use exponential backoff in retries
	UseBackoff *bool
}

type ClientOptions

type ClientOptions struct {
	// User is a pair values of name and password
	User UserCredentials
	// Timeout settings for the curp client
	CurpTimeout ClientConfig
}

Options for a client connection

type Cluster

type Cluster interface {
	// MemberList lists the current cluster membership.
	MemberList(ctx context.Context) (*MemberListResponse, error)

	// MemberAdd adds a new member into the cluster.
	MemberAdd(ctx context.Context, peerAddrs []string) (*MemberAddResponse, error)

	// MemberAddAsLearner adds a new learner member into the cluster.
	MemberAddAsLearner(ctx context.Context, peerAddrs []string) (*MemberAddResponse, error)

	// MemberRemove removes an existing member from the cluster.
	MemberRemove(ctx context.Context, id uint64) (*MemberRemoveResponse, error)

	// MemberUpdate updates the peer addresses of the member.
	MemberUpdate(ctx context.Context, id uint64, peerAddrs []string) (*MemberUpdateResponse, error)

	// MemberPromote promotes a member from raft learner (non-voting) to raft voting member.
	MemberPromote(ctx context.Context, id uint64) (*MemberPromoteResponse, error)
}

type Cmp

type Cmp xlineapi.Compare

func Compare

func Compare(cmp Cmp, result string, v interface{}) Cmp

nolint: govet

func CreateRevision

func CreateRevision(key []byte) Cmp

func LeaseValue

func LeaseValue(key []byte) Cmp

LeaseValue compares a key's LeaseID to a value of your choosing. The empty LeaseID is 0, otherwise known as `NoLease`.

func ModRevision

func ModRevision(key []byte) Cmp

func Value

func Value(key []byte) Cmp

func Version

func Version(key []byte) Cmp

func (Cmp) WithPrefix

func (cmp Cmp) WithPrefix() Cmp

nolint: govet WithPrefix sets the comparison to scan all keys prefixed by the key.

func (Cmp) WithRange

func (cmp Cmp) WithRange(end []byte) Cmp

nolint: govet WithRange sets the comparison to scan the range [key, end).

type CommandError

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

func (*CommandError) Error

func (e *CommandError) Error() string

type CompactResponse

type CompactResponse xlineapi.CompactionResponse

type CompareResult

type CompareResult int

type CompareTarget

type CompareTarget int
const (
	CompareVersion CompareTarget = iota
	CompareCreated
	CompareModified
	CompareValue
)

type Curp

type Curp interface {
	// Propose the request to servers, if use_fast_path is false, it will wait for the synced index
	Propose(cmd *xlineapi.Command, useFastPath bool) (*proposeRes, error)

	// Generate a propose id
	GenProposeID() (*curpapi.ProposeId, error)
}

type DeleteResponse

type DeleteResponse xlineapi.DeleteRangeResponse

type KV

type KV interface {
	// Put puts a key-value pair into xline.
	// When passed WithLease(), Put will attaches a lease ID to a key in 'Put' request.
	// When passed WithPrevKV(), Put will returns the previous key-value pair before the event happens.
	// When passed WithIgnoreValue(), Put will updates the key using its current value.
	// When passed WithIgnoreLease(), Put will updates the key using its current lease.
	Put(key, val []byte, opts ...OpOption) (*PutResponse, error)

	// Range retrieves keys.
	// By default, Range will return the value for "key", if any.
	// When passed WithRange(), Range will returns the keys in the range [key, end).
	// When passed WithFromKey(), Range will returns keys greater than or equal to the key.
	// When passed WithPrefix(), Range will returns keys that begin with the key.
	// When passed WithLimit(), Range will returns keys is bounded by limit.
	// When passed WithRev() with rev > 0, Range will returns key at the given revision.
	// When passed WithSort(), Range will returns keys be sorted.
	// When passed WithSerializable(), Range will makes 'Range' request serializable. By default, it's linearizable.
	// When passed WithKeysOnly(), Range will returns only the keys and the corresponding values will be omitted.
	// When passed WithCountOnly(), Range will returns only the count of keys.
	// When passed WithMinModRev(), Range will returns keys with modification revisions less than the given revision.
	// When passed WithMaxModRev(), Range will returns keys with modification revisions greater than the given revision.
	// When passed WithMinCreateRev(), Range will returns keys with creation revisions less than the given revision.
	// When passed WithMaxCreateRev(), Range will returns keys with creation revisions greater than the given revision.
	Range(key []byte, opts ...OpOption) (*RangeResponse, error)

	// Delete deletes a key, or optionally using WithRange(end), [key, end).
	// When passed WithPrevKV(), Delete will returns the previous key-value pair before the event happens.
	Delete(key string, opts ...OpOption) (*DeleteResponse, error)

	// Txn creates a transaction.
	Txn() Txn

	// Compact compacts xline KV history before the given rev.
	// When passed WithPhysical(), Compact will wait until all compacted entries are removed from the etcd server's storage.
	Compact(rev int64, opts ...OpOption) (*CompactResponse, error)
}

func NewKV

func NewKV(curpClient Curp, token string) KV

New `KvClient`

type Lease

type Lease interface {
	// Grant creates a new lease.
	// When passed WithID(), Grant will used to specify the lease ID, otherwise it is automatically generated.
	Grant(ttl int64, opts ...LeaseOption) (*LeaseGrantResponse, error)

	// Revoke revokes the given lease.
	Revoke(id int64) (*LeaseRevokeResponse, error)

	// KeepAlive attempts to keep the given lease alive forever.
	KeepAlive(ctx context.Context, id int64) (<-chan *LeaseKeepAliveResponse, error)

	// KeepAliveOnce renews the lease once. The response corresponds to the first message from calling KeepAlive.
	// In most of the cases, Keepalive should be used instead of KeepAliveOnce.
	KeepAliveOnce(id int64) (*LeaseKeepAliveResponse, error)

	// TimeToLive retrieves the lease information of the given lease ID.
	// When passed WithAttachedKeys(), TimeToLive will list the keys attached to the given lease ID.
	TimeToLive(id int64, opts ...LeaseOption) (*LeaseTimeToLiveResponse, error)

	// Leases retrieves all leases.
	Leases() (*LeaseLeasesResponse, error)
}

func NewLease

func NewLease(
	curpClient Curp,
	conn *grpc.ClientConn,
	token string,
	idGen leaseIdGenerator,
) Lease

Creates a new `LeaseClient`

type LeaseGrantResponse

type LeaseGrantResponse xlineapi.LeaseGrantResponse

type LeaseKeepAliveResponse

type LeaseKeepAliveResponse xlineapi.LeaseKeepAliveResponse

type LeaseLeasesResponse

type LeaseLeasesResponse xlineapi.LeaseLeasesResponse

type LeaseOp

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

LeaseOp represents an Operation that lease can execute.

type LeaseOption

type LeaseOption func(*LeaseOp)

LeaseOption configures lease operations.

func WithAttachedKeys

func WithAttachedKeys() LeaseOption

WithAttachedKeys makes TimeToLive list the keys attached to the given lease ID.

func WithID

func WithID(id int64) LeaseOption

WithID is used to specify the lease ID, otherwise it is automatically generated.

type LeaseRevokeResponse

type LeaseRevokeResponse xlineapi.LeaseRevokeResponse

type LeaseTimeToLiveResponse

type LeaseTimeToLiveResponse xlineapi.LeaseTimeToLiveResponse

type Lock

type Lock interface {
	// Acquires a distributed shared lock on a given named lock.
	// On success, it will return a unique key that exists so long as the
	// lock is held by the caller. This key can be used in conjunction with
	// transactions to safely ensure updates to Xline only occur while holding
	// lock ownership. The lock is held until Unlock is called on the key or the
	// lease associate with the owner expires.
	Lock(request LockRequest) (*xlineapi.LockResponse, error)

	// Takes a key returned by Lock and releases the hold on lock. The
	// next Lock caller waiting for the lock will then be woken up and given
	// ownership of the lock.
	UnLock(request *xlineapi.UnlockRequest) (*xlineapi.UnlockResponse, error)
}

func NewLock

func NewLock(
	curpClient Curp,
	innerLeaseClient Lease,
	innerWatchClient Watch,
	token string,
) Lock

Creates a new `LockClient`

type LockRequest

type LockRequest struct {
	// The Inner request
	Inner *xlineapi.LockRequest
	// The TTL of the lease that attached to the lock
	TTL int64
}

Request for `Lock`

type Maintenance

type Maintenance interface {
	// Gets a snapshot over a stream
	Snapshot() (SnapshotClient, error)
}

func NewMaintenance

func NewMaintenance(conn *grpc.ClientConn) Maintenance

Creates a new maintenance client

type Member

type Member xlineapi.Member

type MemberAddResponse

type MemberAddResponse xlineapi.MemberAddResponse

type MemberListResponse

type MemberListResponse xlineapi.MemberListResponse

type MemberPromoteResponse

type MemberPromoteResponse xlineapi.MemberPromoteResponse

type MemberRemoveResponse

type MemberRemoveResponse xlineapi.MemberRemoveResponse

type MemberUpdateResponse

type MemberUpdateResponse xlineapi.MemberUpdateResponse

type Op

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

Op represents an Operation that kv can execute.

func OpCompact

func OpCompact(rev int64, opts ...OpOption) Op

OpCompact returns "compact" operation based on given rev and operation options.

func OpDelete

func OpDelete(key string, opts ...OpOption) Op

OpDelete returns "delete" operation based on given key and operation options.

func OpPut

func OpPut(key, val []byte, opts ...OpOption) Op

OpPut returns "put" operation based on given key-value and operation options.

func OpRange

func OpRange(key []byte, opts ...OpOption) Op

OpRange returns "range" operation based on given key and operation options.

func OpTxn

func OpTxn(cmps []Cmp, thenOps []Op, elseOps []Op) Op

OpTxn returns "txn" operation based on given transaction conditions.

type OpOption

type OpOption func(*Op)

OpOption configures Operations like Get, Put, Delete.

func WithCountOnly

func WithCountOnly() OpOption

WithCountOnly makes the 'Range' request return only the count of keys.

func WithFromKey

func WithFromKey() OpOption

WithFromKey specifies the range of 'Get', 'Delete', 'Watch' requests to be equal or greater than the key in the argument.

func WithIgnoreLease

func WithIgnoreLease() OpOption

WithIgnoreLease updates the key using its current lease. This option can not be combined with WithLease. Returns an error if the key does not exist.

func WithIgnoreValue

func WithIgnoreValue() OpOption

WithIgnoreValue updates the key using its current value. This option can not be combined with non-empty values. Returns an error if the key does not exist.

func WithKeysOnly

func WithKeysOnly() OpOption

WithKeysOnly makes the 'Range' request return only the keys and the corresponding values will be omitted.

func WithLease

func WithLease(leaseID int64) OpOption

WithLease attaches a lease ID to a key in 'Put' request.

func WithLimit

func WithLimit(n int64) OpOption

WithLimit limits the number of results to return from 'Range' request. If WithLimit is given a 0 limit, it is treated as no limit.

func WithMaxCreateRev

func WithMaxCreateRev(rev int64) OpOption

WithMaxCreateRev filters out keys for Range with creation revisions greater than the given revision.

func WithMaxModRev

func WithMaxModRev(rev int64) OpOption

WithMaxModRev filters out keys for Range with modification revisions greater than the given revision.

func WithMinCreateRev

func WithMinCreateRev(rev int64) OpOption

WithMinCreateRev filters out keys for Range with creation revisions less than the given revision.

func WithMinModRev

func WithMinModRev(rev int64) OpOption

WithMinModRev filters out keys for Range with modification revisions less than the given revision.

func WithPhysical

func WithPhysical() OpOption

WithPhysical makes Compact wait until all compacted entries are removed from the etcd server's storage.

func WithPrefix

func WithPrefix() OpOption

WithPrefix enables 'Get', 'Delete', or 'Watch' requests to operate on the keys with matching prefix. For example, 'Get(foo, WithPrefix())' can return 'foo1', 'foo2', and so on.

func WithPrevKV

func WithPrevKV() OpOption

WithPrevKV gets the previous key-value pair before the event happens. If the previous KV is already compacted, nothing will be returned.

func WithRange

func WithRange(endKey []byte) OpOption

WithRange specifies the range of 'Get', 'Delete', 'Watch' requests. For example, 'Get' requests with 'WithRange(end)' returns the keys in the range [key, end). endKey must be lexicographically greater than start key.

func WithRev

func WithRev(rev int64) OpOption

WithRev specifies the store revision for 'Range' request. Or the start revision of 'Watch' request.

func WithSerializable

func WithSerializable() OpOption

WithSerializable makes 'Range' request serializable. By default, it's linearizable. Serializable requests are better for lower latency requirement.

func WithSort

func WithSort(target SortTarget, order SortOrder) OpOption

WithSort specifies the ordering in 'Range' request. It requires 'WithRange' and/or 'WithPrefix' to be specified too. 'target' specifies the target to sort by: key, version, revisions, value. 'order' can be either 'SortNone', 'SortAscend', 'SortDescend'.

type PermissionType

type PermissionType xlineapi.Permission_Type

type PutResponse

type PutResponse xlineapi.PutResponse

type RangeResponse

type RangeResponse xlineapi.RangeResponse

type ServerId

type ServerId = uint64

Server ID

type SnapshotClient

type SnapshotClient xlineapi.Maintenance_SnapshotClient

type SortOption

type SortOption struct {
	Target SortTarget
	Order  SortOrder
}

type SortOrder

type SortOrder int
const (
	SortNone SortOrder = iota
	SortAscend
	SortDescend
)

type SortTarget

type SortTarget int
const (
	SortByKey SortTarget = iota
	SortByVersion
	SortByCreateRevision
	SortByModRevision
	SortByValue
)

type Txn

type Txn interface {
	// When takes a list of comparison. When all comparisons passed in succeed,
	// the operations passed into Then() will be executed. Or the operations
	// passed into Else() will be executed.
	When(cs ...Cmp) Txn

	// AndThen takes a list of operations. The Ops list will be executed, if the
	// comparisons passed in If() succeed.
	AndThen(ops ...Op) Txn

	// OrElse takes a list of operations. The Ops list will be executed, if the
	// comparisons passed in If() fail.
	OrElse(ops ...Op) Txn

	// Commit tries to commit the transaction.
	Commit() (*TxnResponse, error)
}

type TxnResponse

type TxnResponse xlineapi.TxnResponse

type UserAddOptions

type UserAddOptions xlineapi.UserAddOptions

type UserCredentials

type UserCredentials struct {
	// Username
	Name string
	// Password
	Password string
}

Options for a user

type Watch

type Watch interface {
	// Watches for events happening or that have happened.
	Watch(ctx context.Context, key []byte) (<-chan *WatchResponse, error)
}

func NewWatch

func NewWatch(conn *grpc.ClientConn) Watch

Creates a new maintenance client

type WatchResponse

type WatchResponse xlineapi.WatchResponse

Jump to

Keyboard shortcuts

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