model

package
v0.0.0-...-021fd64 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnknownKVClientType = iota
	EtcdKVClientType
	SQLKVClientType
	MockKVClientType
)

define client type

View Source
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

func GetPrefixRangeEnd(prefix string) string

GetPrefixRangeEnd gets the range end of the prefix. 'Get(foo, WithPrefix())' is equal to 'Get(foo, WithRange(GetPrefixRangeEnd(foo))'.

func IsOptsWithFromKey

func IsOptsWithFromKey(opts []OpOption) bool

IsOptsWithFromKey returns true if WithFromKey option is called in the given opts.

func IsOptsWithPrefix

func IsOptsWithPrefix(opts []OpOption) bool

IsOptsWithPrefix returns true if WithPrefix option is called in the given opts.

func IsOptsWithRange

func IsOptsWithRange(opts []OpOption) bool

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

func (*GetResponse) String

func (resp *GetResponse) String() string

String only for debug

type JobID

type JobID = model.JobID

JobID is the alias of model.JobID

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 KVClient

type KVClient interface {
	Client
	KV
}

KVClient combines Client interface and KV interface

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

func (*KeyValue) String

func (kv *KeyValue) String() string

String only for debug

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

var EmptyOp Op = Op{}

EmptyOp creates a global empty op

func NewOp

func NewOp() *Op

NewOp creates a new op instance

func OpDelete

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

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

func OpGet

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

OpGet returns "get" operation based on given key and operation options.

func OpPut

func OpPut(key, val string) Op

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

func OpTxn

func OpTxn(ops []Op) Op

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

func (*Op) ApplyOpts

func (op *Op) ApplyOpts(opts []OpOption)

ApplyOpts calls given option function one by one

func (Op) CheckValidOp

func (op Op) CheckValidOp() error

CheckValidOp checks whether op is valid

func (Op) IsDelete

func (op Op) IsDelete() bool

IsDelete returns true if the operation is a Delete.

func (Op) IsGet

func (op Op) IsGet() bool

IsGet returns true if the operation is a Get.

func (Op) IsOptsWithFromKey

func (op Op) IsOptsWithFromKey() bool

IsOptsWithFromKey returns true if WithFromKey option is called in the given opts.

func (Op) IsOptsWithPrefix

func (op Op) IsOptsWithPrefix() bool

IsOptsWithPrefix returns true if WithPrefix option is called in the given opts.

func (Op) IsOptsWithRange

func (op Op) IsOptsWithRange() bool

IsOptsWithRange returns true if WithRange option is called in the given opts.

func (Op) IsPut

func (op Op) IsPut() bool

IsPut returns true if the operation is a Put.

func (Op) IsTxn

func (op Op) IsTxn() bool

IsTxn returns true if the "Op" type is transaction.

func (Op) KeyBytes

func (op Op) KeyBytes() []byte

KeyBytes returns the byte slice holding the Op's key.

func (Op) RangeBytes

func (op Op) RangeBytes() []byte

RangeBytes returns the byte slice holding with the Op's range end, if any.

func (Op) Txn

func (op Op) Txn() []Op

Txn returns the operations.

func (Op) ValueBytes

func (op Op) ValueBytes() []byte

ValueBytes returns the byte slice holding the Op's value, if any.

func (*Op) WithKeyBytes

func (op *Op) WithKeyBytes(key []byte)

WithKeyBytes set the byte slice to the Op's key.

func (*Op) WithRangeBytes

func (op *Op) WithRangeBytes(end []byte)

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.

func WithRange

func WithRange(endKey string) OpOption

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

type OpResponse

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

OpResponse contains a list of put/get/del/txn response

func (OpResponse) Del

func (op OpResponse) Del() *DeleteResponse

Del returns a DelResponse

func (OpResponse) Get

func (op OpResponse) Get() *GetResponse

Get returns a GetResponse

func (OpResponse) Put

func (op OpResponse) Put() *PutResponse

Put returns a PutResponse

func (OpResponse) Txn

func (op OpResponse) Txn() *TxnResponse

Txn returns a TxnResponse

type ProjectID

type ProjectID = tenant.ProjectID

ProjectID is the alia of tenant.ProjectID

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

func (*ResponseHeader) String

func (h *ResponseHeader) String() string

String only for debug

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 StoreType

type StoreType = string

StoreType is the type of metastore

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

Jump to

Keyboard shortcuts

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