Skip to content

Commit

Permalink
kv: remove RangePrefetch and RangeGet
Browse files Browse the repository at this point in the history
  • Loading branch information
disksing committed Dec 24, 2015
1 parent 42d999f commit e9298e4
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 126 deletions.
16 changes: 0 additions & 16 deletions kv/cache_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,6 @@ func (c *cacheSnapshot) BatchGet(keys []Key) (map[string][]byte, error) {
return m, nil
}

// RangeGet gets values from snapshot and saves them in cache.
// The range should be [start, end] as Snapshot.RangeGet() indicated.
func (c *cacheSnapshot) RangeGet(start, end Key, limit int) (map[string][]byte, error) {
values, err := c.snapshot.RangeGet(start, end, limit)
if err != nil {
return nil, errors.Trace(err)
}
for k, v := range values {
err = cachePut(c.cache, []byte(k), v)
if err != nil {
return nil, errors.Trace(err)
}
}
return values, nil
}

// Seek creates an iterator of snapshot.
func (c *cacheSnapshot) Seek(k Key) (Iterator, error) {
cacheIter, err := c.cache.Seek(k)
Expand Down
42 changes: 0 additions & 42 deletions kv/cache_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,6 @@ func (s *testCacheSnapshotSuite) TestBatchGet(c *C) {
c.Assert(exist, IsFalse)
}

func (s *testCacheSnapshotSuite) TestRangeGet(c *C) {
s.store.Set([]byte("1"), []byte("1"))
s.store.Set([]byte("2"), []byte("2"))
s.store.Set([]byte("3"), []byte("3"))

m, err := s.cache.RangeGet([]byte("1"), []byte("2"), 100)
c.Assert(err, IsNil)
c.Assert(m, HasLen, 2)
c.Assert(m["1"], BytesEquals, []byte("1"))
c.Assert(m["2"], BytesEquals, []byte("2"))

// result should be saved in cache
s.store.Set([]byte("1"), []byte("4"))
v, err := s.cache.Get([]byte("1"))
c.Assert(err, IsNil)
c.Assert(v, BytesEquals, []byte("1"))
}

type mockSnapshot struct {
store MemBuffer
}
Expand All @@ -122,30 +104,6 @@ func (s *mockSnapshot) BatchGet(keys []Key) (map[string][]byte, error) {
return m, nil
}

func (s *mockSnapshot) RangeGet(start, end Key, limit int) (map[string][]byte, error) {
m := make(map[string][]byte)
it, err := s.Seek(start)
if err != nil {
return nil, errors.Trace(err)
}
defer it.Close()
endKey := string(end)
for i := 0; i < limit; i++ {
if !it.Valid() {
break
}
if it.Key() > endKey {
break
}
m[string(it.Key())] = it.Value()
err := it.Next()
if err != nil {
return nil, err
}
}
return m, nil
}

func (s *mockSnapshot) Seek(k Key) (Iterator, error) {
return s.store.Seek(k)
}
Expand Down
6 changes: 0 additions & 6 deletions kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ type Transaction interface {
RetrieverMutator
// BatchPrefetch fetches values from KV storage to cache for later use.
BatchPrefetch(keys []Key) error
// RangePrefetch fetches values in the range [start, end] from KV storage
// to cache for later use. Maximum number of values is up to limit.
RangePrefetch(start, end Key, limit int) error
// Commit commits the transaction operations to KV store.
Commit() error
// Rollback undoes the transaction operations to KV store.
Expand All @@ -83,9 +80,6 @@ type Snapshot interface {
Retriever
// BatchGet gets a batch of values from snapshot.
BatchGet(keys []Key) (map[string][]byte, error)
// RangeGet gets values in the range [start, end] from snapshot. Maximum
// number of values is up to limit.
RangeGet(start, end Key, limit int) (map[string][]byte, error)
// Release releases the snapshot to store.
Release()
}
Expand Down
9 changes: 0 additions & 9 deletions kv/union_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ type UnionStore interface {
CheckLazyConditionPairs() error
// BatchPrefetch fetches values from KV storage to cache for later use.
BatchPrefetch(keys []Key) error
// RangePrefetch fetches values in the range [start, end] from KV storage
// to cache for later use. Maximum number of values is up to limit.
RangePrefetch(start, end Key, limit int) error
// WalkBuffer iterates all buffered kv pairs.
WalkBuffer(f func(k Key, v []byte) error) error
// SetOption sets an option with a value, when val is nil, uses the default
Expand Down Expand Up @@ -133,12 +130,6 @@ func (us *unionStore) BatchPrefetch(keys []Key) error {
return errors.Trace(err)
}

// RangePrefetch implements the UnionStore interface.
func (us *unionStore) RangePrefetch(start, end Key, limit int) error {
_, err := us.snapshot.RangeGet(start, end, limit)
return errors.Trace(err)
}

// CheckLazyConditionPairs implements the UnionStore interface.
func (us *unionStore) CheckLazyConditionPairs() error {
var keys []Key
Expand Down
21 changes: 0 additions & 21 deletions store/hbase/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,6 @@ func (s *hbaseSnapshot) BatchGet(keys []kv.Key) (map[string][]byte, error) {
return m, nil
}

// RangeGet implements kv.Snapshot.RangeGet interface.
// The range should be [start, end] as Snapshot.RangeGet() indicated.
func (s *hbaseSnapshot) RangeGet(start, end kv.Key, limit int) (map[string][]byte, error) {
scanner := s.txn.GetScanner([]byte(s.storeName), start, end, limit)
defer scanner.Close()

m := make(map[string][]byte)
for i := 0; i < limit; i++ {
r := scanner.Next()
if r != nil && len(r.Columns) > 0 {
k := string(r.Row)
v := r.Columns[hbaseFmlAndQual].Value
m[k] = v
} else {
break
}
}

return m, nil
}

func internalGet(s *hbaseSnapshot, g *hbase.Get) ([]byte, error) {
r, err := s.txn.Get(s.storeName, g)
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions store/hbase/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ func (txn *hbaseTxn) BatchPrefetch(keys []kv.Key) error {
return txn.us.BatchPrefetch(keys)
}

func (txn *hbaseTxn) RangePrefetch(start, end kv.Key, limit int) error {
return txn.us.RangePrefetch(start, end, limit)
}

func (txn *hbaseTxn) SetOption(opt kv.Option, val interface{}) {
txn.us.SetOption(opt, val)
}
Expand Down
24 changes: 0 additions & 24 deletions store/localstore/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,30 +120,6 @@ func (s *dbSnapshot) BatchGet(keys []kv.Key) (map[string][]byte, error) {
return m, nil
}

func (s *dbSnapshot) RangeGet(start, end kv.Key, limit int) (map[string][]byte, error) {
m := make(map[string][]byte)
it, err := s.Seek(start)
if err != nil {
return nil, errors.Trace(err)
}
defer it.Close()
endKey := string(end)
for i := 0; i < limit; i++ {
if !it.Valid() {
break
}
if it.Key() > endKey {
break
}
m[it.Key()] = it.Value()
err := it.Next()
if err != nil {
return nil, err
}
}
return m, nil
}

func (s *dbSnapshot) Seek(k kv.Key) (kv.Iterator, error) {
it, err := newDBIter(s, k)
return it, errors.Trace(err)
Expand Down
4 changes: 0 additions & 4 deletions store/localstore/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ func (txn *dbTxn) BatchPrefetch(keys []kv.Key) error {
return txn.us.BatchPrefetch(keys)
}

func (txn *dbTxn) RangePrefetch(start, end kv.Key, limit int) error {
return txn.us.RangePrefetch(start, end, limit)
}

func (txn *dbTxn) SetOption(opt kv.Option, val interface{}) {
txn.us.SetOption(opt, val)
}
Expand Down

0 comments on commit e9298e4

Please sign in to comment.