rawkv

package
v2.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: Apache-2.0 Imports: 16 Imported by: 41

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// MaxRawKVScanLimit is the maximum scan limit for rawkv Scan.
	MaxRawKVScanLimit = 10240
	// ErrMaxScanLimitExceeded is returned when the limit for rawkv Scan is to large.
	ErrMaxScanLimitExceeded = errors.New("limit should be less than MaxRawKVScanLimit")
)

Functions

This section is empty.

Types

type Client

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

Client is a client of TiKV server which is used as a key-value storage, only GET/PUT/DELETE commands are supported.

func NewClient

func NewClient(ctx context.Context, pdAddrs []string, security config.Security, opts ...pd.ClientOption) (*Client, error)

NewClient creates a client with PD cluster addrs.

func NewClientWithOpts added in v2.0.2

func NewClientWithOpts(ctx context.Context, pdAddrs []string, opts ...ClientOpt) (*Client, error)

NewClientWithOpts creates a client with PD cluster addrs and client options.

func (*Client) BatchDelete

func (c *Client) BatchDelete(ctx context.Context, keys [][]byte, options ...RawOption) error

BatchDelete deletes key-value pairs from TiKV.

func (*Client) BatchGet

func (c *Client) BatchGet(ctx context.Context, keys [][]byte, options ...RawOption) ([][]byte, error)

BatchGet queries values with the keys.

func (*Client) BatchPut

func (c *Client) BatchPut(ctx context.Context, keys, values [][]byte, options ...RawOption) error

BatchPut stores key-value pairs to TiKV.

func (*Client) BatchPutWithTTL

func (c *Client) BatchPutWithTTL(ctx context.Context, keys, values [][]byte, ttls []uint64, options ...RawOption) error

BatchPutWithTTL stores key-values pairs to TiKV with time-to-live durations.

func (*Client) Checksum added in v2.0.2

func (c *Client) Checksum(ctx context.Context, startKey, endKey []byte, options ...RawOption,
) (check RawChecksum, err error)

Checksum do checksum of continuous kv pairs in range [startKey, endKey). If endKey is empty, it means unbounded. If you want to exclude the startKey or include the endKey, push a '\0' to the key. For example, to scan (startKey, endKey], you can write: `Checksum(ctx, push(startKey, '\0'), push(endKey, '\0'))`.

func (*Client) Close

func (c *Client) Close() error

Close closes the client.

func (*Client) ClusterID

func (c *Client) ClusterID() uint64

ClusterID returns the TiKV cluster ID.

func (*Client) CompareAndSwap

func (c *Client) CompareAndSwap(ctx context.Context, key, previousValue, newValue []byte, options ...RawOption) ([]byte, bool, error)

CompareAndSwap results in an atomic compare-and-set operation for the given key while SetAtomicForCAS(true) If the value retrieved is equal to previousValue, newValue is written. It returns the previous value and whether the value is successfully swapped.

If SetAtomicForCAS(false), it will returns an error because CAS operations enforce the client should operate in atomic mode.

NOTE: This feature is experimental. It depends on the single-row transaction mechanism of TiKV which is conflict with the normal write operation in rawkv mode. If multiple clients exist, it's up to the clients the sync the atomic mode flag. If some clients write in atomic mode but the other don't, the linearizability of TiKV will be violated.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, key []byte, options ...RawOption) error

Delete deletes a key-value pair from TiKV.

func (*Client) DeleteRange

func (c *Client) DeleteRange(ctx context.Context, startKey []byte, endKey []byte, options ...RawOption) error

DeleteRange deletes all key-value pairs in the [startKey, endKey) range from TiKV.

func (*Client) Get

func (c *Client) Get(ctx context.Context, key []byte, options ...RawOption) ([]byte, error)

Get queries value with the key. When the key does not exist, it returns `nil, nil`.

func (*Client) GetKeyTTL

func (c *Client) GetKeyTTL(ctx context.Context, key []byte, options ...RawOption) (*uint64, error)

GetKeyTTL get the TTL of a raw key from TiKV if key exists

func (*Client) GetPDClient added in v2.0.2

func (c *Client) GetPDClient() pd.Client

GetPDClient returns the PD client.

func (*Client) Put

func (c *Client) Put(ctx context.Context, key, value []byte, options ...RawOption) error

Put stores a key-value pair to TiKV.

func (*Client) PutWithTTL

func (c *Client) PutWithTTL(ctx context.Context, key, value []byte, ttl uint64, options ...RawOption) error

PutWithTTL stores a key-value pair to TiKV with a time-to-live duration.

func (*Client) ReverseScan

func (c *Client) ReverseScan(ctx context.Context, startKey, endKey []byte, limit int, options ...RawOption) (keys [][]byte, values [][]byte, err error)

ReverseScan queries continuous kv pairs in range [endKey, startKey), up to limit pairs. The returned keys are in reversed lexicographical order. If endKey is empty, it means unbounded. If you want to include the startKey or exclude the endKey, push a '\0' to the key. For example, to scan (endKey, startKey], you can write: `ReverseScan(ctx, push(startKey, '\0'), push(endKey, '\0'), limit)`. It doesn't support Scanning from "", because locating the last Region is not yet implemented.

func (*Client) Scan

func (c *Client) Scan(ctx context.Context, startKey, endKey []byte, limit int, options ...RawOption,
) (keys [][]byte, values [][]byte, err error)

Scan queries continuous kv pairs in range [startKey, endKey), up to limit pairs. The returned keys are in lexicographical order. If endKey is empty, it means unbounded. If you want to exclude the startKey or include the endKey, push a '\0' to the key. For example, to scan (startKey, endKey], you can write: `Scan(ctx, push(startKey, '\0'), push(endKey, '\0'), limit)`.

func (*Client) SetAtomicForCAS

func (c *Client) SetAtomicForCAS(b bool) *Client

SetAtomicForCAS sets atomic mode for CompareAndSwap

func (*Client) SetColumnFamily added in v2.0.2

func (c *Client) SetColumnFamily(columnFamily string) *Client

SetColumnFamily sets columnFamily for client

type ClientOpt added in v2.0.2

type ClientOpt func(*option)

ClientOpt is factory to set the client options.

func WithAPIVersion added in v2.0.2

func WithAPIVersion(apiVersion kvrpcpb.APIVersion) ClientOpt

WithAPIVersion is used to set the api version.

func WithGRPCDialOptions added in v2.0.2

func WithGRPCDialOptions(opts ...grpc.DialOption) ClientOpt

WithGRPCDialOptions is used to set the grpc.DialOption.

func WithKeyspace added in v2.0.5

func WithKeyspace(name string) ClientOpt

WithKeyspace is used to set the keyspace Name.

func WithPDOptions added in v2.0.2

func WithPDOptions(opts ...pd.ClientOption) ClientOpt

WithPDOptions is used to set the pd.ClientOption

func WithSecurity added in v2.0.2

func WithSecurity(security config.Security) ClientOpt

WithSecurity is used to set the config.Security

type ClientProbe

type ClientProbe struct {
	*Client
}

ClientProbe wraps RawKVClient and exposes internal states for testing purpose.

func (ClientProbe) GetRegionCache

func (c ClientProbe) GetRegionCache() *locate.RegionCache

GetRegionCache returns the internal region cache container.

func (ClientProbe) SetPDClient

func (c ClientProbe) SetPDClient(client pd.Client)

SetPDClient resets the interval PD client.

func (ClientProbe) SetRPCClient

func (c ClientProbe) SetRPCClient(client client.Client)

SetRPCClient resets the internal RPC client.

func (ClientProbe) SetRegionCache

func (c ClientProbe) SetRegionCache(regionCache *locate.RegionCache)

SetRegionCache resets the internal region cache container.

type ConfigProbe

type ConfigProbe struct{}

ConfigProbe exposes configurations and global variables for testing purpose.

func (ConfigProbe) GetRawBatchPutSize

func (c ConfigProbe) GetRawBatchPutSize() int

GetRawBatchPutSize returns the raw batch put size config.

type RawChecksum added in v2.0.2

type RawChecksum struct {
	// Crc64Xor is the checksum result with crc64 algorithm
	Crc64Xor uint64
	// TotalKvs is the total number of kvpairs
	TotalKvs uint64
	// TotalBytes is the total bytes of kvpairs, including prefix in APIV2
	TotalBytes uint64
}

RawChecksum represents the checksum result of raw kv pairs in TiKV cluster.

type RawOption added in v2.0.2

type RawOption interface {
	// contains filtered or unexported methods
}

RawOption represents possible options that can be cotrolled by the user to tweak the API behavior.

Available options are: - ScanColumnFamily - ScanKeyOnly

func ScanKeyOnly

func ScanKeyOnly() RawOption

ScanKeyOnly is a rawkvOptions that tells the scanner to only returns keys and omit the values. It can work only in API scan().

func SetColumnFamily added in v2.0.2

func SetColumnFamily(cf string) RawOption

SetColumnFamily is a RawkvOption to only manipulate the k-v in specified column family

Jump to

Keyboard shortcuts

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