Skip to content

Commit

Permalink
kv: add API for kv.Client
Browse files Browse the repository at this point in the history
  • Loading branch information
coocood committed Mar 21, 2016
1 parent 3c6bc80 commit ec06184
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
49 changes: 49 additions & 0 deletions kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

package kv

import "io"

const (
// PresumeKeyNotExists directives that when dealing with a Get operation but failing to read data from cache,
// we presume that the key does not exist in Store. The actual existence will be checked before the
Expand Down Expand Up @@ -76,6 +78,53 @@ type Transaction interface {
DelOption(opt Option)
// IsReadOnly checks if the transaction has only performed read operations.
IsReadOnly() bool
// GetClient gets a client instance.
GetClient() Client
// StartTS returns the transaction start timestamp.
StartTS() int64
}

// Client is used to send request to KV layer.
type Client interface {
// Send sends request to KV layer, returns a Response.
Send(req *Request) Response

// SupportRequestType checks if reqType and subType is supported.
SupportRequestType(reqType, subType int64) bool
}

// ReqTypes.
const (
ReqTypeSelect = 101
ReqTypeIndex = 102
)

// KeyRange represents a range where StartKey <= key < EndKey.
type KeyRange struct {
StartKey Key
EndKey Key
}

// Request represents a kv request.
type Request struct {
// The request type.
Tp int64
Data []byte
// Key Ranges
KeyRanges []KeyRange
// If desc is true, the request is sent in descending order.
Desc bool
// If concurrency is 1, it only sends the request to a single storage unit when
// ResponseIterator.Next is called. If concurrency is greater than 1, the request will be
// sent to multiple storage units concurrently.
Concurrency int
}

// Response represents the response returned from KV layer.
type Response interface {
// Next returns a resultSubset from a single storage unit.
// When full result set is returned, nil is returned.
Next() (resultSubset io.ReadCloser, err error)
}

// Snapshot defines the interface for the snapshot fetched from KV store.
Expand Down
19 changes: 19 additions & 0 deletions store/hbase/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,22 @@ func (txn *hbaseTxn) LockKeys(keys ...kv.Key) error {
func (txn *hbaseTxn) IsReadOnly() bool {
return !txn.dirty
}

func (txn *hbaseTxn) StartTS() int64 {
return int64(txn.tid)
}

func (txn *hbaseTxn) GetClient() kv.Client {
return nil
}

type hbaseClient struct {
}

func (c *hbaseClient) SupportRequestType(reqType, subType int64) bool {
return false
}

func (c *hbaseClient) Send(req *kv.Request) kv.Response {
return nil
}
19 changes: 19 additions & 0 deletions store/localstore/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,22 @@ func (txn *dbTxn) LockKeys(keys ...kv.Key) error {
func (txn *dbTxn) IsReadOnly() bool {
return !txn.dirty
}

func (txn *dbTxn) StartTS() int64 {
return int64(txn.tid)
}

func (txn *dbTxn) GetClient() kv.Client {
return nil
}

type dbClient struct {
}

func (c *dbClient) SupportRequestType(reqType, subType int64) bool {
return false
}

func (c *dbClient) Send(req *kv.Request) kv.Response {
return nil
}

0 comments on commit ec06184

Please sign in to comment.