crkv

package module
v0.0.0-...-c79b758 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2017 License: Apache-2.0 Imports: 11 Imported by: 0

README

GoDoc

crkv

crkv is a client for cockroach db, and treats it as a key value database.

Documentation

Overview

Package crkv is a client wrapping SQL interface, to provide a KV usage of cockroachdb

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AmbiguousCommitError

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

AmbiguousCommitError represents an error that left a transaction in an ambiguous state: unclear if it committed or not.

type By

type By func(kvp1, kvp2 KeyValuePair) bool

By is the type of a "less" function that defines the ordering of its KeyValuePair arguments.

func (By) Sort

func (by By) Sort(kvps []KeyValuePair)

type CRKVStore

type CRKVStore struct {
	*sql.DB
	// contains filtered or unexported fields
}

CRKVStore is a cockroachdb store to manipulate key/values.

func NewKVStore

func NewKVStore(url string, options ...Option) *CRKVStore

NewKVStore returns a new KVStore connecting to url, default isolation level is serializable.

func (*CRKVStore) Close

func (kv *CRKVStore) Close() error

Close closes database connections.

func (*CRKVStore) Connect

func (kv *CRKVStore) Connect(url string)

Connect connects to url.

func (*CRKVStore) CreateDatabase

func (kv *CRKVStore) CreateDatabase(database string) error

CreateDatabase creates a new database.

func (*CRKVStore) Del

func (kv *CRKVStore) Del(ctx context.Context, key interface{}) error

Del deletes a value for a key.

func (*CRKVStore) Get

func (kv *CRKVStore) Get(ctx context.Context, key interface{}) (Value, error)

Get retrieves the value for a key.

func (*CRKVStore) Put

func (kv *CRKVStore) Put(ctx context.Context, key interface{}, value interface{}) error

Put sets a value for a key.

func (*CRKVStore) Scan

func (kv *CRKVStore) Scan(ctx context.Context, begin, end interface{}, max int64) ([]KeyValuePair, error)

Scan retrieves the key/value pairs between begin (inclusive) and end (exclusive) in ascending order.

func (*CRKVStore) Txn

func (kv *CRKVStore) Txn(ctx context.Context, fn func(ctx context.Context, txn Txn) error) (err error)

Txn begins a txn running fn inside a transaction and retries it if needed. On non-retryable failures, the transaction is aborted and rolled back; on success, the transaction is committed. There are cases where the state of a transaction is inherently ambiguous: if we err on RELEASE with a communication error it's unclear if the transaction has been committed or not (similar to erroring on COMMIT in other databases). In that case, we return AmbiguousCommitError.

For more information about CockroachDB's transaction model see https://cockroachlabs.com/docs/transactions.html.

NOTE: the supplied exec closure should not have external side effects beyond changes to the database.

type CRTxn

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

CRTxn is an in-progress distributed database transaction.

func (*CRTxn) Del

func (txn *CRTxn) Del(ctx context.Context, key interface{}) error

Del deletes key.

func (*CRTxn) Get

func (txn *CRTxn) Get(ctx context.Context, key interface{}) (Value, error)

Get retrives a key.

func (*CRTxn) Put

func (txn *CRTxn) Put(ctx context.Context, key interface{}, value interface{}) error

Put sets a key.

type InmemKVStore

type InmemKVStore struct {
	*memdb.MemDB
	// contains filtered or unexported fields
}

InmemKVStore is based on github.com/ggaaooppeenngg/safemap key contains byte slice, it can not be a key in map, so use string instead as a key.

func (*InmemKVStore) Del

func (kv *InmemKVStore) Del(ctx context.Context, key interface{}) error

Del deletes a value for a key.

func (*InmemKVStore) Get

func (kv *InmemKVStore) Get(_ context.Context, key interface{}) (Value, error)

Get retrieves the value for a key.

func (*InmemKVStore) Put

func (kv *InmemKVStore) Put(_ context.Context, key interface{}, value interface{}) error

Put sets a value for a key.

func (*InmemKVStore) Scan

func (kv *InmemKVStore) Scan(ctx context.Context, begin, end interface{}, max int64) ([]KeyValuePair, error)

Scan retrieves the key/value pairs between begin (inclusive) and end (exclusive) in ascending order.

func (*InmemKVStore) Txn

func (kv *InmemKVStore) Txn(ctx context.Context, fn func(ctx context.Context, txn Txn) error) error

It is not pure trasaction currently, just locked, if any error happens, no rollback will be taken.

type InmemKeyValuePair

type InmemKeyValuePair struct {
	Key   string
	Value Value
}

type InmemTxn

type InmemTxn struct {
	*memdb.Txn
	// contains filtered or unexported fields
}

func (*InmemTxn) Del

func (txn *InmemTxn) Del(ctx context.Context, key interface{}) error

func (*InmemTxn) Get

func (txn *InmemTxn) Get(ctx context.Context, key interface{}) (Value, error)

func (*InmemTxn) Put

func (txn *InmemTxn) Put(ctx context.Context, key interface{}, value interface{}) error

type Key

type Key struct {
	RawBytes []byte
}

Key is bytes key.

func (*Key) String

func (k *Key) String() string

String returns string of underlying bytes.

type KeyValuePair

type KeyValuePair struct {
	Key
	Value
}

KeyValuePair represents a bytes key/valur pair.

type Option

type Option func(kv *CRKVStore)

Option is a function to set KVStore option.

func SetIsolationLevel

func SetIsolationLevel(isolationLeve string) Option

SetIsolationLevel sets default isolation level.

func SetMaxConns

func SetMaxConns(n int) Option

SetMaxConns sets connection pool size.

type Store

type Store interface {
	Put(ctx context.Context, key interface{}, value interface{}) error
	Del(ctx context.Context, key interface{}) error
	Get(ctx context.Context, key interface{}) (Value, error)
	Scan(ctx context.Context, begin, end interface{}, max int64) ([]KeyValuePair, error)
	Txn(ctx context.Context, fn func(ctx context.Context, txn Txn) error) (err error)
}

func NewInmemKVStore

func NewInmemKVStore() Store

type Txn

type Txn interface {
	Del(ctx context.Context, key interface{}) error
	Get(ctx context.Context, key interface{}) (Value, error)
	Put(ctx context.Context, key interface{}, value interface{}) error
}

type Value

type Value struct {
	RawBytes []byte
}

Value is bytes value.

func (*Value) String

func (v *Value) String() string

String returns string of underlying bytes.

func (*Value) ValueProto

func (v *Value) ValueProto(message proto.Message) error

ValueProto unmarshals bytes to protobuf message.

Jump to

Keyboard shortcuts

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