-
Notifications
You must be signed in to change notification settings - Fork 2
/
needed.go
39 lines (33 loc) · 990 Bytes
/
needed.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package stored
import (
"github.com/apple/foundationdb/bindings/go/src/fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb/subspace"
)
type needObject struct {
object *Object
rangeResult fdb.RangeResult
subspace subspace.Subspace
}
func (n *needObject) need(tr fdb.ReadTransaction, sub subspace.Subspace) {
//fmt.Println("need sub", sub)
//start, end := sub.FDBRangeKeys()
//r := fdb.KeyRange{Begin: start, End: end}
start := sub.FDBKey()
end := append(start, uint8(255))
r := fdb.KeyRange{Begin: start, End: end}
//fmt.Println("fetching range", start, end)
n.rangeResult = tr.GetRange(r, fdb.RangeOptions{Mode: fdb.StreamingModeWantAll})
}
func (n *needObject) fetch() (*Value, error) {
rows, err := n.rangeResult.GetSliceWithError()
if err != nil {
return nil, err
}
if len(rows) == 0 {
// problem is here so shouldbe checked
return nil, ErrNotFound
}
value := Value{object: n.object}
value.FromKeyValue(n.subspace, rows)
return &value, nil
}