Commit 0ef353be authored by Tommi Virtanen's avatar Tommi Virtanen

Dead code cleanup: remove Range support from blockstore

Nothing uses it, and offset+limit is a bad query mechanism for
mutating data.
parent e878e5c9
...@@ -33,9 +33,6 @@ type Blockstore interface { ...@@ -33,9 +33,6 @@ type Blockstore interface {
AllKeys(ctx context.Context) ([]u.Key, error) AllKeys(ctx context.Context) ([]u.Key, error)
AllKeysChan(ctx context.Context) (<-chan u.Key, error) AllKeysChan(ctx context.Context) (<-chan u.Key, error)
AllKeysRange(ctx context.Context, offset int, limit int) ([]u.Key, error)
AllKeysRangeChan(ctx context.Context, offset int, limit int) (<-chan u.Key, error)
} }
func NewBlockstore(d ds.ThreadSafeDatastore) Blockstore { func NewBlockstore(d ds.ThreadSafeDatastore) Blockstore {
...@@ -85,22 +82,13 @@ func (s *blockstore) DeleteBlock(k u.Key) error { ...@@ -85,22 +82,13 @@ func (s *blockstore) DeleteBlock(k u.Key) error {
return s.datastore.Delete(k.DsKey()) return s.datastore.Delete(k.DsKey())
} }
func (bs *blockstore) AllKeys(ctx context.Context) ([]u.Key, error) { // AllKeys runs a query for keys from the blockstore.
return bs.AllKeysRange(ctx, 0, 0)
}
func (bs *blockstore) AllKeysChan(ctx context.Context) (<-chan u.Key, error) {
return bs.AllKeysRangeChan(ctx, 0, 0)
}
// AllKeysRange runs a query for keys from the blockstore.
// this is very simplistic, in the future, take dsq.Query as a param? // this is very simplistic, in the future, take dsq.Query as a param?
// if offset and limit are 0, they are ignored.
// //
// AllKeysRange respects context // AllKeys respects context
func (bs *blockstore) AllKeysRange(ctx context.Context, offset int, limit int) ([]u.Key, error) { func (bs *blockstore) AllKeys(ctx context.Context) ([]u.Key, error) {
ch, err := bs.AllKeysRangeChan(ctx, offset, limit) ch, err := bs.AllKeysChan(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -112,15 +100,14 @@ func (bs *blockstore) AllKeysRange(ctx context.Context, offset int, limit int) ( ...@@ -112,15 +100,14 @@ func (bs *blockstore) AllKeysRange(ctx context.Context, offset int, limit int) (
return keys, nil return keys, nil
} }
// AllKeysRangeChan runs a query for keys from the blockstore. // AllKeysChan runs a query for keys from the blockstore.
// this is very simplistic, in the future, take dsq.Query as a param? // this is very simplistic, in the future, take dsq.Query as a param?
// if offset and limit are 0, they are ignored.
// //
// AllKeysRangeChan respects context // AllKeysChan respects context
func (bs *blockstore) AllKeysRangeChan(ctx context.Context, offset int, limit int) (<-chan u.Key, error) { func (bs *blockstore) AllKeysChan(ctx context.Context) (<-chan u.Key, error) {
// KeysOnly, because that would be _a lot_ of data. // KeysOnly, because that would be _a lot_ of data.
q := dsq.Query{KeysOnly: true, Offset: offset, Limit: limit} q := dsq.Query{KeysOnly: true}
res, err := bs.datastore.Query(q) res, err := bs.datastore.Query(q)
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -78,23 +78,6 @@ func TestAllKeysSimple(t *testing.T) { ...@@ -78,23 +78,6 @@ func TestAllKeysSimple(t *testing.T) {
expectMatches(t, keys, keys2) expectMatches(t, keys, keys2)
} }
func TestAllKeysOffsetAndLimit(t *testing.T) {
N := 30
bs, _ := newBlockStoreWithKeys(t, nil, N)
ctx := context.Background()
keys3, err := bs.AllKeysRange(ctx, N/3, N/3)
if err != nil {
t.Fatal(err)
}
for _, k3 := range keys3 {
t.Log("found ", k3.Pretty())
}
if len(keys3) != N/3 {
t.Errorf("keys3 should be: %d != %d", N/3, len(keys3))
}
}
func TestAllKeysRespectsContext(t *testing.T) { func TestAllKeysRespectsContext(t *testing.T) {
N := 100 N := 100
......
...@@ -46,17 +46,9 @@ func (w *writecache) Put(b *blocks.Block) error { ...@@ -46,17 +46,9 @@ func (w *writecache) Put(b *blocks.Block) error {
} }
func (w *writecache) AllKeys(ctx context.Context) ([]u.Key, error) { func (w *writecache) AllKeys(ctx context.Context) ([]u.Key, error) {
return w.blockstore.AllKeysRange(ctx, 0, 0) return w.blockstore.AllKeys(ctx)
} }
func (w *writecache) AllKeysChan(ctx context.Context) (<-chan u.Key, error) { func (w *writecache) AllKeysChan(ctx context.Context) (<-chan u.Key, error) {
return w.blockstore.AllKeysRangeChan(ctx, 0, 0) return w.blockstore.AllKeysChan(ctx)
}
func (w *writecache) AllKeysRange(ctx context.Context, offset int, limit int) ([]u.Key, error) {
return w.blockstore.AllKeysRange(ctx, offset, limit)
}
func (w *writecache) AllKeysRangeChan(ctx context.Context, offset int, limit int) (<-chan u.Key, error) {
return w.blockstore.AllKeysRangeChan(ctx, offset, limit)
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment