Documentation ¶
Index ¶
- Constants
- func GenerateDSNByParams(storeConf *StoreConfig, pairs map[string]string) (string, error)
- func GetPrefixRangeEnd(prefix string) string
- func IsOptsWithFromKey(opts []OpOption) bool
- func IsOptsWithPrefix(opts []OpOption) bool
- func IsOptsWithRange(opts []OpOption) bool
- type AuthConfParams
- type Client
- type ClientConn
- type ClientType
- type DeleteResponse
- type Error
- type GetResponse
- type JobID
- type KV
- type KVClient
- type KeyValue
- type Op
- func (op *Op) ApplyOpts(opts []OpOption)
- func (op Op) CheckValidOp() error
- func (op Op) IsDelete() bool
- func (op Op) IsGet() bool
- func (op Op) IsOptsWithFromKey() bool
- func (op Op) IsOptsWithPrefix() bool
- func (op Op) IsOptsWithRange() bool
- func (op Op) IsPut() bool
- func (op Op) IsTxn() bool
- func (op Op) KeyBytes() []byte
- func (op Op) RangeBytes() []byte
- func (op Op) Txn() []Op
- func (op Op) ValueBytes() []byte
- func (op *Op) WithKeyBytes(key []byte)
- func (op *Op) WithRangeBytes(end []byte)
- type OpOption
- type OpResponse
- type ProjectID
- type PutResponse
- type ResponseHeader
- type ResponseOp
- type ResponseOpResponseDelete
- type ResponseOpResponseGet
- type ResponseOpResponsePut
- type ResponseOpResponseTxn
- type StoreConfig
- type StoreType
- type Txn
- type TxnResponse
Constants ¶
const ( UnknownKVClientType = iota EtcdKVClientType SQLKVClientType MockKVClientType )
define client type
const ( // StoreTypeEtcd is the store type string for etcd StoreTypeEtcd = "etcd" // StoreTypeMySQL is the store type string for MySQL StoreTypeMySQL = "mysql" // StoreTypeSQLite is the store type string for SQLite // Only for test now StoreTypeSQLite = "sqlite" // StoreTypeMockKV is a specific store type which can generate // a mock kvclient (using map as backend) // Only for test now StoreTypeMockKV = "mock-kv" )
Variables ¶
This section is empty.
Functions ¶
func GenerateDSNByParams ¶
func GenerateDSNByParams(storeConf *StoreConfig, pairs map[string]string) (string, error)
GenerateDSNByParams generates a dsn string. dsn format: [username[:password]@][protocol[(address)]]/
func GetPrefixRangeEnd ¶
GetPrefixRangeEnd gets the range end of the prefix. 'Get(foo, WithPrefix())' is equal to 'Get(foo, WithRange(GetPrefixRangeEnd(foo))'.
func IsOptsWithFromKey ¶
IsOptsWithFromKey returns true if WithFromKey option is called in the given opts.
func IsOptsWithPrefix ¶
IsOptsWithPrefix returns true if WithPrefix option is called in the given opts.
func IsOptsWithRange ¶
IsOptsWithRange returns true if WithRange option is called in the given opts.
Types ¶
type AuthConfParams ¶
type AuthConfParams struct { User string `toml:"user" json:"user"` Passwd string `toml:"passwd" json:"passwd"` }
AuthConfParams is basic authentication configurations
type Client ¶
type Client interface { // Close is the method to close the client and release inner resources Close() error // GenEpoch generate the increasing epoch for user GenEpoch(ctx context.Context) (int64, error) }
Client defines some basic method used as a meta client
type ClientConn ¶
type ClientConn interface { // StoreType returns the type of connection StoreType() StoreType // GetConn gets the underlying connection object // For the fisrt return param if no error happens: // For StoreTypeEtcd, it returns *clientv3.Client // For StoreTypeMySQL/StoreTypeSQLite, it returns *sql.DB GetConn() (interface{}, error) // Close closes the underlying connection and releases some resources Close() error }
ClientConn is the common method for different connection HOPE to reuse the common underlying connection pool
type ClientType ¶
type ClientType int
ClientType indicates the kvclient type
func ToClientType ¶
func ToClientType(storeType StoreType) ClientType
ToClientType translates store type to client type
func (ClientType) String ¶
func (t ClientType) String() string
String implements the Stringer interface
type DeleteResponse ¶
type DeleteResponse struct {
Header *ResponseHeader
}
DeleteResponse .
func (*DeleteResponse) OpResponse ¶
func (resp *DeleteResponse) OpResponse() OpResponse
OpResponse generates a delete OpResponse from DeleteResponse
type Error ¶
type Error interface { error // IsRetryable returns true if this error may be gone if retried. IsRetryable() bool }
Error defines the interface used in KV interface
type GetResponse ¶
type GetResponse struct { Header *ResponseHeader // kvs is the list of key-value pairs matched by the range request. Kvs []*KeyValue }
GetResponse .
func (*GetResponse) OpResponse ¶
func (resp *GetResponse) OpResponse() OpResponse
OpResponse generates a get OpResponse from GetResponse
type KV ¶
type KV interface { // Put puts a key-value pair into metastore. // Note that key,value can be plain bytes array and string is // an immutable representation of that bytes array. // To get a string of bytes, do string([]byte{0x10, 0x20}). // or do nothing on vice verse. // Length of key is restricted to 2KB Put(ctx context.Context, key, val string) (*PutResponse, Error) // Get retrieves keys with newest revision. // By default, Get will return the value for "key", if any. // When WithRange(end) is passed, Get will return the keys in the range [key, end). // When WithFromKey() is passed, Get returns keys greater than or equal to key. // When WithPrefix() is passed, Get returns keys with prefix. // WARN: WithRange(), WithFromKey(), WithPrefix() can't be used at the same time Get(ctx context.Context, key string, opts ...OpOption) (*GetResponse, Error) // Delete deletes a key, or optionally using WithRange(end), [key, end). // WARN: WithRange(end), WithFromKey(), WithPrefix() can't be used at the same time Delete(ctx context.Context, key string, opts ...OpOption) (*DeleteResponse, Error) // Txn creates a transaction. Txn(ctx context.Context) Txn }
KV defines a key value access interface, which is quite similar to etcd KV API
type KeyValue ¶
type KeyValue struct { // Key is the key in bytes. An empty key is not allowed. Key []byte `gorm:"column:meta_key;type:varbinary(2048) not null;uniqueIndex:uidx_jk,priority:2"` // Value is the value held by the key, in bytes. Value []byte `gorm:"column:meta_value;type:longblob"` }
KeyValue defines a key value byte slice pair
type Op ¶
type Op struct { T opType // contains filtered or unexported fields }
Op represents an Operation that kv can execute. Support Key Range/From Key/Key Prefix attributes
func (Op) IsOptsWithFromKey ¶
IsOptsWithFromKey returns true if WithFromKey option is called in the given opts.
func (Op) IsOptsWithPrefix ¶
IsOptsWithPrefix returns true if WithPrefix option is called in the given opts.
func (Op) IsOptsWithRange ¶
IsOptsWithRange returns true if WithRange option is called in the given opts.
func (Op) RangeBytes ¶
RangeBytes returns the byte slice holding with the Op's range end, if any.
func (Op) ValueBytes ¶
ValueBytes returns the byte slice holding the Op's value, if any.
func (*Op) WithKeyBytes ¶
WithKeyBytes set the byte slice to the Op's key.
func (*Op) WithRangeBytes ¶
WithRangeBytes set the byte slice to the Op's range end
type OpOption ¶
type OpOption func(*Op)
OpOption configures Operations like Get, Put, Delete.
func WithFromKey ¶
func WithFromKey() OpOption
WithFromKey specifies the range of 'Get', 'Delete' requests to be equal or greater than the key in the argument.
func WithPrefix ¶
func WithPrefix() OpOption
WithPrefix enables 'Get', 'Delete' requests to operate on the keys with matching prefix. For example, 'Get(foo, WithPrefix())' can return 'foo1', 'foo2', and so on.
type OpResponse ¶
type OpResponse struct {
// contains filtered or unexported fields
}
OpResponse contains a list of put/get/del/txn response
type PutResponse ¶
type PutResponse struct {
Header *ResponseHeader
}
PutResponse .
func (*PutResponse) OpResponse ¶
func (resp *PutResponse) OpResponse() OpResponse
OpResponse generates a put OpResponse from PutResponse
type ResponseHeader ¶
type ResponseHeader struct { // ClusterId is the ID of the cluster which sent the response. // Framework will generate uuid for every newcoming metastore ClusterID string }
ResponseHeader is common response header
type ResponseOp ¶
type ResponseOp struct { // response is a union of response types returned by a transaction. // // Types that are valid to be assigned to Response: // *ResponseOp_ResponseRange // *ResponseOp_ResponsePut // *ResponseOp_ResponseDeleteRange // *ResponseOp_ResponseTxn Response isResponseOpResponse }
ResponseOp defines a response operation, the op is one of get/put/delete/txn
func (*ResponseOp) GetResponse ¶
func (m *ResponseOp) GetResponse() isResponseOpResponse
GetResponse returns an isResponseOpResponse interface
func (*ResponseOp) GetResponseDelete ¶
func (m *ResponseOp) GetResponseDelete() *DeleteResponse
GetResponseDelete returns a ResponseDelete if it matches
func (*ResponseOp) GetResponseGet ¶
func (m *ResponseOp) GetResponseGet() *GetResponse
GetResponseGet returns a ResponseGet if it matches
func (*ResponseOp) GetResponsePut ¶
func (m *ResponseOp) GetResponsePut() *PutResponse
GetResponsePut returns a ResponsePut if it matches
func (*ResponseOp) GetResponseTxn ¶
func (m *ResponseOp) GetResponseTxn() *TxnResponse
GetResponseTxn returns a ResponseTxn if it matches
type ResponseOpResponseDelete ¶
type ResponseOpResponseDelete struct {
ResponseDelete *DeleteResponse
}
ResponseOpResponseDelete defines an op that wraps DeleteResponse
type ResponseOpResponseGet ¶
type ResponseOpResponseGet struct {
ResponseGet *GetResponse
}
ResponseOpResponseGet defines an op that wraps GetResponse
type ResponseOpResponsePut ¶
type ResponseOpResponsePut struct {
ResponsePut *PutResponse
}
ResponseOpResponsePut defines an op that wraps PutResponse
type ResponseOpResponseTxn ¶
type ResponseOpResponseTxn struct {
ResponseTxn *TxnResponse
}
ResponseOpResponseTxn defines an op that wraps TxnResponse
type StoreConfig ¶
type StoreConfig struct { // StoreID is the unique readable identifier for a store StoreID string `toml:"store-id" json:"store-id"` // StoreType supports 'etcd' or 'mysql', default is 'mysql' StoreType StoreType `toml:"store-type" json:"store-type"` Endpoints []string `toml:"endpoints" json:"endpoints"` User string `toml:"user" json:"user"` Password string `toml:"password" json:"password"` // Schema is the predefine schema name for mysql-compatible metastore // 1.It needs to stay UNCHANGED for one dataflow engine cluster // 2.It needs be different between any two dataflow engine clusters // 3.Naming rule: https://dev.mysql.com/doc/refman/5.7/en/identifiers.html Schema string `toml:"schema" json:"schema"` ReadTimeout string `toml:"read-timeout" json:"read-timeout"` WriteTimeout string `toml:"write-timeout" json:"write-timeout"` DialTimeout string `toml:"dial-timeout" json:"dial-timeout"` // DBConf is the db config for mysql-compatible metastore DBConf *dbutil.DBConfig `toml:"dbconfs" json:"dbconfs"` Security *security.Credential `toml:"security" json:"security"` }
StoreConfig is metastore connection configurations
func DefaultStoreConfig ¶
func DefaultStoreConfig() *StoreConfig
DefaultStoreConfig return a default *StoreConfig
func (*StoreConfig) SetEndpoints ¶
func (s *StoreConfig) SetEndpoints(endpoints string)
SetEndpoints sets endpoints to StoreConfig
func (StoreConfig) Validate ¶
func (s StoreConfig) Validate() error
Validate implements the validation.Validatable interface
type Txn ¶
type Txn interface { // Do cache Ops in the Txn // Same op limit with KV Put/Get/Delete interface // Using snapshot isolation Do(ops ...Op) Txn // Commit tries to commit the transaction. // Any Op fail will cause entire txn rollback and return error Commit() (*TxnResponse, Error) }
Txn doesn't support nested txn
type TxnResponse ¶
type TxnResponse struct { Header *ResponseHeader // Responses is a list of responses corresponding to the results from applying // success if succeeded is true or failure if succeeded is false. Responses []ResponseOp }
TxnResponse .
func (*TxnResponse) OpResponse ¶
func (resp *TxnResponse) OpResponse() OpResponse
OpResponse generates a txn OpResponse from TxnResponse