Documentation ¶
Index ¶
- Constants
- Variables
- func BuildCurpClientFromAddrs(addrs []string, config *ClientConfig) (*protocolClient, error)
- func Connect(allMembers []string, options ...ClientOptions) (*client, error)
- func NewCluster(conn *grpc.ClientConn) *clusterClient
- func NewErrInternalError(err error) error
- type Auth
- type AuthDisableResponse
- type AuthEnableResponse
- type AuthRoleAddResponse
- type AuthRoleDeleteResponse
- type AuthRoleGetResponse
- type AuthRoleGrantPermissionResponse
- type AuthRoleListResponse
- type AuthRoleRevokePermissionResponse
- type AuthStatusResponse
- type AuthUserAddResponse
- type AuthUserChangePasswordResponse
- type AuthUserDeleteResponse
- type AuthUserGetResponse
- type AuthUserGrantRoleResponse
- type AuthUserListResponse
- type AuthUserRevokeRoleResponse
- type AuthenticateResponse
- type ClientConfig
- type ClientOptions
- type Cluster
- type Cmp
- type CommandError
- type CompactResponse
- type CompareResult
- type CompareTarget
- type Curp
- type DeleteResponse
- type KV
- type Lease
- type LeaseGrantResponse
- type LeaseKeepAliveResponse
- type LeaseLeasesResponse
- type LeaseOp
- type LeaseOption
- type LeaseRevokeResponse
- type LeaseTimeToLiveResponse
- type Lock
- type LockRequest
- type Maintenance
- type Member
- type MemberAddResponse
- type MemberListResponse
- type MemberPromoteResponse
- type MemberRemoveResponse
- type MemberUpdateResponse
- type Op
- type OpOption
- func WithCountOnly() OpOption
- func WithFromKey() OpOption
- func WithIgnoreLease() OpOption
- func WithIgnoreValue() OpOption
- func WithKeysOnly() OpOption
- func WithLease(leaseID int64) OpOption
- func WithLimit(n int64) OpOption
- func WithMaxCreateRev(rev int64) OpOption
- func WithMaxModRev(rev int64) OpOption
- func WithMinCreateRev(rev int64) OpOption
- func WithMinModRev(rev int64) OpOption
- func WithPhysical() OpOption
- func WithPrefix() OpOption
- func WithPrevKV() OpOption
- func WithRange(endKey []byte) OpOption
- func WithRev(rev int64) OpOption
- func WithSerializable() OpOption
- func WithSort(target SortTarget, order SortOrder) OpOption
- type PermissionType
- type PutResponse
- type RangeResponse
- type ServerId
- type SnapshotClient
- type SortOption
- type SortOrder
- type SortTarget
- type Txn
- type TxnResponse
- type UserAddOptions
- type UserCredentials
- type Watch
- type WatchResponse
Constants ¶
const ( PermRead = xlineapi.Permission_READ PermWrite = xlineapi.Permission_WRITE PermReadWrite = xlineapi.Permission_READWRITE )
const DEFAULT_SESSION_TTL int64 = 60
const DefaultInitialRetryTimeout = 50 * time.Millisecond
const DefaultMaxRetryTimeout = 10000 * time.Millisecond
const DefaultProposeTimeout = 1 * time.Second
const DefaultRetryCount = 3
const DefaultWaitSyncedTimeout = 2 * time.Second
Variables ¶
var ( ErrShuttingDown = errors.New("Curp Server is shutting down") ErrWrongClusterVersion = errors.New("Wrong cluster version") ErrTimeout = errors.New("Request timeout") )
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 NewErrInternalError ¶ added in v0.1.1
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) }
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 CreateRevision ¶
func LeaseValue ¶
LeaseValue compares a key's LeaseID to a value of your choosing. The empty LeaseID is 0, otherwise known as `NoLease`.
func ModRevision ¶
func (Cmp) WithPrefix ¶
nolint: govet WithPrefix sets the comparison to scan all keys prefixed by the key.
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 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) }
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) }
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) }
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 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.
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 WithLimit ¶
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 ¶
WithMaxCreateRev filters out keys for Range with creation revisions greater than the given revision.
func WithMaxModRev ¶
WithMaxModRev filters out keys for Range with modification revisions greater than the given revision.
func WithMinCreateRev ¶
WithMinCreateRev filters out keys for Range with creation revisions less than the given revision.
func WithMinModRev ¶
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 ¶
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 ¶
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 SnapshotClient ¶
type SnapshotClient xlineapi.Maintenance_SnapshotClient
type SortOption ¶
type SortOption struct { Target SortTarget Order SortOrder }
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 ¶
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) }
type WatchResponse ¶
type WatchResponse xlineapi.WatchResponse