storage: initial kv api

release-2.1
Xiang Li 2015-05-21 12:03:58 -07:00
parent 9be6a7c8fd
commit 7bb388ed52
1 changed files with 31 additions and 0 deletions

View File

@ -16,9 +16,40 @@ var (
keyBucketName = []byte("key")
)
type KV interface {
// Range gets the keys in the range at rangeIndex.
// If rangeIndex <=0, range gets the keys at currentIndex.
// If `end` is nil, the request returns the key.
// If `end` is not nil, it gets the keys in range [key, range_end).
// Limit limits the number of keys returned.
Range(key, end []byte, limit, rangeIndex int64) (kvs []storagepb.KeyValue, index int64)
// Put puts the given key,value into the store.
// A put also increases the index of the store, and generates one event in the event history.
Put(key, value []byte) (index int64)
// DeleteRange deletes the given range from the store.
// A deleteRange increases the index of the store if any key in the range exists.
// The number of key deleted will be returned.
// It also generates one event for each key delete in the event history.
// if the `end` is nil, deleteRange deletes the key.
// if the `end` is not nil, deleteRange deletes the keys in range [key, range_end).
DeleteRange(key, end []byte) (n, index int64)
// TnxBegin begins a tnx. Only Tnx prefixed operation can be executed, others will be blocked
// until tnx ends. Only one on-going tnx is allowed.
TnxBegin()
// TnxEnd ends the on-going tnx.
TnxEnd()
TnxRange(key, end []byte, limit, rangeIndex int64) (kvs []storagepb.KeyValue, index int64)
TnxPut(key, value []byte) (index int64)
TnxDeleteRange(key, end []byte) (n, index int64)
}
type store struct {
// read operation MUST hold read lock
// write opeartion MUST hold write lock
// tnx operation MUST hold write lock
sync.RWMutex
b backend.Backend