Documentation
¶
Overview ¶
Package etcdadpt is the abstraction of kv database operator
Index ¶
- Constants
- Variables
- func Delete(ctx context.Context, key string, opts ...OpOption) (bool, error)
- func DeleteMany(ctx context.Context, opts ...OpOptions) (bool, error)
- func Exist(ctx context.Context, key string) (bool, error)
- func Get(ctx context.Context, key string) (*mvccpb.KeyValue, error)
- func GetClusterURL(clusterName, clusterURLs, managerURLs string) []string
- func Init(cfg Config) error
- func Insert(ctx context.Context, key, value string, opts ...OpOption) (bool, error)
- func InsertBytes(ctx context.Context, key string, value []byte, opts ...OpOption) (bool, error)
- func Install(pluginImplName string, newFunc newClientFunc)
- func List(ctx context.Context, key string, opts ...OpOption) ([]*mvccpb.KeyValue, int64, error)
- func Put(ctx context.Context, key string, value string, opts ...OpOption) error
- func PutBytes(ctx context.Context, key string, value []byte, opts ...OpOption) error
- func Txn(ctx context.Context, opts []OpOptions) error
- type Action
- type CacheMode
- type Client
- type Clusters
- type CmpOption
- type CmpOptions
- func EqualCreateRev(key string, v interface{}) CmpOptions
- func EqualModRev(key string, v interface{}) CmpOptions
- func EqualVal(key string, v interface{}) CmpOptions
- func EqualVer(key string, v interface{}) CmpOptions
- func ExistKey(key string) CmpOptions
- func GreaterCreateRev(key string, v interface{}) CmpOptions
- func GreaterModRev(key string, v interface{}) CmpOptions
- func If(opts ...CmpOptions) []CmpOptions
- func LessCreateRev(key string, v interface{}) CmpOptions
- func LessModRev(key string, v interface{}) CmpOptions
- func NotEqualCreateRev(key string, v interface{}) CmpOptions
- func NotEqualModRev(key string, v interface{}) CmpOptions
- func NotEqualVal(key string, v interface{}) CmpOptions
- func NotEqualVer(key string, v interface{}) CmpOptions
- func NotExistKey(key string) CmpOptions
- type CmpResult
- type CmpType
- type Config
- type DLock
- type OpOption
- func WatchPrefixOpOptions(key string) []OpOption
- func WithAscendOrder() OpOption
- func WithCacheOnly() OpOption
- func WithCountOnly() OpOption
- func WithDescendOrder() OpOption
- func WithEndKey(key []byte) OpOption
- func WithGlobal() OpOption
- func WithIgnoreLease() OpOption
- func WithKey(key []byte) OpOption
- func WithKeyOnly() OpOption
- func WithLease(leaseID int64) OpOption
- func WithLimit(i int64) OpOption
- func WithNoCache() OpOption
- func WithNoneOrder() OpOption
- func WithOffset(i int64) OpOption
- func WithPrefix() OpOption
- func WithPrevKv() OpOption
- func WithRev(revision int64) OpOption
- func WithStrEndKey(key string) OpOption
- func WithStrKey(key string) OpOption
- func WithStrValue(value string) OpOption
- func WithValue(value []byte) OpOption
- func WithWatchCallback(f WatchCallback) OpOption
- type OpOptions
- type Operation
- type Response
- func ListAndDelete(ctx context.Context, key string, opts ...OpOption) (*Response, error)
- func ListAndDeleteMany(ctx context.Context, opts ...OpOptions) (*Response, error)
- func PutBytesAndGet(ctx context.Context, key string, value []byte, opts ...OpOption) (*Response, error)
- func TxnWithCmp(ctx context.Context, opts []OpOptions, cmp []CmpOptions, fail []OpOptions) (resp *Response, err error)
- type SortOrder
- type SortTarget
- type StatusResponse
- type WatchCallback
Constants ¶
const ( // MaxTxnNumberOneTime the same as v3rpc.MaxOpsPerTxn = 128 MaxTxnNumberOneTime = 128 // DefaultPageCount grpc does not allow to transport a large body more then 4MB in a request DefaultPageCount = 4096 // DefaultDialTimeout the timeout dial to etcd DefaultDialTimeout = 10 * time.Second DefaultRequestTimeout = 30 * time.Second DefaultCompactInterval = time.Hour DefaultClusterName = "default" )
const ( DefaultLockTTL = 60 DefaultRetryTimes = 3 DefaultLock = "/lock" OperationGlobalLock = "GLOBAL_LOCK" )
Variables ¶
var ErrLeaseIDNotExists = errors.New("leaseID is nil")
var (
ErrLeaseNotFound = errors.New(rpctypes.ErrLeaseNotFound.Error())
)
var ErrLockKeyFail = errors.New("fail to lock key")
var (
ErrNoPlugin = errors.New("required etcd adapter implement, please import the pkg")
)
var (
IsDebug bool
)
Functions ¶
func GetClusterURL ¶
func InsertBytes ¶
InsertBytes insert a new kv, return false if the key exist
func Install ¶
func Install(pluginImplName string, newFunc newClientFunc)
Install load plugins configuration into plugins
Types ¶
type Client ¶
type Client interface {
Err() <-chan error
Ready() <-chan struct{}
Do(ctx context.Context, opts ...OpOption) (*Response, error)
Txn(ctx context.Context, ops []OpOptions) (*Response, error)
TxnWithCmp(ctx context.Context, success []OpOptions, cmp []CmpOptions, fail []OpOptions) (*Response, error)
LeaseGrant(ctx context.Context, TTL int64) (leaseID int64, err error)
LeaseRenew(ctx context.Context, leaseID int64) (TTL int64, err error)
LeaseRevoke(ctx context.Context, leaseID int64) error
// Watch block util:
// 1. connection error
// 2. call send function failed
// 3. response.Err()
// 4. time out to watch, but return nil
Watch(ctx context.Context, opts ...OpOption) error
Compact(ctx context.Context, reserve int64) error
Close()
ListCluster(ctx context.Context) (Clusters, error)
Status(ctx context.Context) (*StatusResponse, error)
}
Client is an abstraction of kv database operator Support etcd by default
func NewInstance ¶
type Clusters ¶
func ParseClusters ¶
ParseClusters convert the cluster url string to Clusters type. The clusterURLs format like 'sc-0=http(s)://host1:port1,http(s)://host2:port2,sc-1=http(s)://host3:port3', managerURLs is optional, set the result value with the key clusterName
type CmpOption ¶
type CmpOption func(op *CmpOptions)
type CmpOptions ¶
func EqualCreateRev ¶
func EqualCreateRev(key string, v interface{}) CmpOptions
func EqualModRev ¶
func EqualModRev(key string, v interface{}) CmpOptions
func EqualVal ¶
func EqualVal(key string, v interface{}) CmpOptions
func EqualVer ¶
func EqualVer(key string, v interface{}) CmpOptions
func ExistKey ¶ added in v0.3.1
func ExistKey(key string) CmpOptions
func GreaterCreateRev ¶
func GreaterCreateRev(key string, v interface{}) CmpOptions
func GreaterModRev ¶
func GreaterModRev(key string, v interface{}) CmpOptions
func LessCreateRev ¶
func LessCreateRev(key string, v interface{}) CmpOptions
func LessModRev ¶
func LessModRev(key string, v interface{}) CmpOptions
func NotEqualCreateRev ¶
func NotEqualCreateRev(key string, v interface{}) CmpOptions
func NotEqualModRev ¶
func NotEqualModRev(key string, v interface{}) CmpOptions
func NotEqualVal ¶
func NotEqualVal(key string, v interface{}) CmpOptions
func NotEqualVer ¶
func NotEqualVer(key string, v interface{}) CmpOptions
func NotExistKey ¶ added in v0.3.1
func NotExistKey(key string) CmpOptions
func (CmpOptions) String ¶
func (op CmpOptions) String() string
type Config ¶
type Config struct {
// Kind plugin kind, can be 'etcd' or 'embedded_etcd'
Kind string `json:"-"`
// Logger logger for adapter, by default use openlog.GetLogger()
Logger openlog.Logger `json:"-"`
SslEnabled bool `json:"-"`
TLSConfig *tls.Config `json:"-"`
// ErrorFunc called when connection error occurs
ErrorFunc func(err error) `json:"-"`
// ConnectedFunc called when connected
ConnectedFunc func() `json:"-"`
// ManagerAddress optional, the list of cluster manager endpoints
ManagerAddress string `json:"manageAddress,omitempty"`
// ClusterName required when Kind = 'embedded_etcd'
ClusterName string `json:"manageName,omitempty"`
// ClusterAddresses required, the list of cluster client endpoints
ClusterAddresses string `json:"manageClusters,omitempty"` // the raw string of cluster configuration
DialTimeout time.Duration `json:"connectTimeout"`
RequestTimeOut time.Duration `json:"registryTimeout"`
// AutoSyncInterval optional, then duration of auto sync the cluster members and check them health
AutoSyncInterval time.Duration `json:"autoSyncInterval"`
// CompactInterval optional, set DefaultCompactInterval if value equal to 0
CompactInterval time.Duration `json:"-"`
CompactIndexDelta int64 `json:"-"`
}
type DLock ¶ added in v0.3.0
type DLock struct {
// contains filtered or unexported fields
}
func Lock ¶ added in v0.3.0
Lock func will lock the key, and retry three times if it fails. ttl unit is second.
type OpOption ¶
type OpOption func(*OpOptions)
var DEL OpOption = func(op *OpOptions) { op.Action = ActionDelete }
func WatchPrefixOpOptions ¶
func WithAscendOrder ¶
func WithAscendOrder() OpOption
func WithCacheOnly ¶
func WithCacheOnly() OpOption
func WithCountOnly ¶
func WithCountOnly() OpOption
func WithDescendOrder ¶
func WithDescendOrder() OpOption
func WithEndKey ¶
func WithGlobal ¶
func WithGlobal() OpOption
func WithIgnoreLease ¶
func WithIgnoreLease() OpOption
func WithKeyOnly ¶
func WithKeyOnly() OpOption
func WithNoCache ¶
func WithNoCache() OpOption
func WithNoneOrder ¶
func WithNoneOrder() OpOption
func WithOffset ¶
func WithPrefix ¶
func WithPrefix() OpOption
func WithPrevKv ¶
func WithPrevKv() OpOption
func WithStrEndKey ¶
func WithStrKey ¶
func WithStrValue ¶
func WithWatchCallback ¶
func WithWatchCallback(f WatchCallback) OpOption
type OpOptions ¶
type OpOptions struct {
Action Action
Key []byte
// EndKey must be lexicographically greater than Key.
EndKey []byte
Value []byte
Prefix bool
PrevKV bool
Lease int64
KeyOnly bool
CountOnly bool
OrderBy SortTarget
SortOrder SortOrder
Revision int64
IgnoreLease bool
Mode CacheMode
WatchCallback WatchCallback
Offset int64
Limit int64
Global bool
}
func OptionsToOp ¶
func (OpOptions) LargeRequestPaging ¶ added in v0.1.3
type Response ¶
type Response struct {
Action Action
Kvs []*mvccpb.KeyValue
Count int64
Revision int64
Succeeded bool
}
func ListAndDelete ¶
ListAndDelete delete key and return the deleted key
func ListAndDeleteMany ¶
ListAndDeleteMany delete key and return the deleted key
func PutBytesAndGet ¶
func PutBytesAndGet(ctx context.Context, key string, value []byte, opts ...OpOption) (*Response, error)
PutBytesAndGet insert/update kv and return it
func TxnWithCmp ¶
func (*Response) MaxModRevision ¶
type SortTarget ¶
type SortTarget int
const ( OrderByKey SortTarget = iota OrderByCreate OrderByMod OrderByVer )
func (SortTarget) String ¶
func (st SortTarget) String() string
type StatusResponse ¶ added in v0.5.0
type StatusResponse struct {
DBSize int64
}