kv

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEtcdKVBase

func NewEtcdKVBase(client *clientv3.Client, rootPath string) *etcdKVBase

NewEtcdKVBase creates a new etcd kv.

func NewSlowLogTxn

func NewSlowLogTxn(client *clientv3.Client) clientv3.Txn

NewSlowLogTxn create a SlowLogTxn.

Types

type Base

type Base interface {
	Txn
	// RunInTxn runs the user provided function in a Transaction.
	// If user provided function f returns a non-nil error, then
	// transaction will not be committed, the same error will be
	// returned by RunInTxn.
	// Otherwise, it returns the error occurred during the
	// transaction.
	// Note that transaction are not committed until RunInTxn returns nil.
	// Note:
	// 1. Load and LoadRange operations provides only stale read.
	// Values saved/ removed during transaction will not be immediately
	// observable in the same transaction.
	// 2. Only when storage is etcd, does RunInTxn checks that
	// values loaded during transaction has not been modified before commit.
	RunInTxn(ctx context.Context, f func(txn Txn) error) error
}

Base is an abstract interface for load/save pd cluster data.

func NewMemoryKV

func NewMemoryKV() Base

NewMemoryKV returns an in-memory kvBase for testing.

type LevelDBKV

type LevelDBKV struct {
	*leveldb.DB
}

LevelDBKV is a kv store using LevelDB.

func NewLevelDBKV

func NewLevelDBKV(path string) (*LevelDBKV, error)

NewLevelDBKV is used to store regions information.

func (*LevelDBKV) Load

func (kv *LevelDBKV) Load(key string) (string, error)

Load gets a value for a given key.

func (*LevelDBKV) LoadRange

func (kv *LevelDBKV) LoadRange(startKey, endKey string, limit int) ([]string, []string, error)

LoadRange gets a range of value for a given key range.

func (*LevelDBKV) Remove

func (kv *LevelDBKV) Remove(key string) error

Remove deletes a key-value pair for a given key.

func (*LevelDBKV) RunInTxn

func (kv *LevelDBKV) RunInTxn(ctx context.Context, f func(txn Txn) error) error

RunInTxn runs user provided function f in a transaction. If user provided function returns error, then transaction will not be committed.

func (*LevelDBKV) Save

func (kv *LevelDBKV) Save(key, value string) error

Save stores a key-value pair.

type SlowLogTxn

type SlowLogTxn struct {
	clientv3.Txn
	// contains filtered or unexported fields
}

SlowLogTxn wraps etcd transaction and log slow one.

func (*SlowLogTxn) Commit

func (t *SlowLogTxn) Commit() (*clientv3.TxnResponse, error)

Commit implements Txn Commit interface.

func (*SlowLogTxn) If

func (t *SlowLogTxn) If(cs ...clientv3.Cmp) clientv3.Txn

If takes a list of comparison. If all comparisons passed in succeed, the operations passed into Then() will be executed. Or the operations passed into Else() will be executed.

func (*SlowLogTxn) Then

func (t *SlowLogTxn) Then(ops ...clientv3.Op) clientv3.Txn

Then takes a list of operations. The Ops list will be executed, if the comparisons passed in If() succeed.

type Txn

type Txn interface {
	Save(key, value string) error
	Remove(key string) error
	Load(key string) (string, error)
	LoadRange(key, endKey string, limit int) (keys []string, values []string, err error)
}

Txn bundles multiple operations into a single executable unit. It enables kv to atomically apply a set of updates.

Jump to

Keyboard shortcuts

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