Merge pull request #532 from drew-richardson/master
Avoid calls that can panic when handling errors
This commit is contained in:
commit
be873001cc
|
@ -65,7 +65,10 @@ func windowSize(start int64) int64 {
|
|||
func (hca highContentionAllocator) allocate(tr fdb.Transaction, s subspace.Subspace) (subspace.Subspace, error) {
|
||||
for {
|
||||
rr := tr.Snapshot().GetRange(hca.counters, fdb.RangeOptions{Limit: 1, Reverse: true})
|
||||
kvs := rr.GetSliceOrPanic()
|
||||
kvs, e := rr.GetSliceWithError()
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
|
||||
var start int64
|
||||
var window int64
|
||||
|
@ -135,7 +138,10 @@ func (hca highContentionAllocator) allocate(tr fdb.Transaction, s subspace.Subsp
|
|||
|
||||
allocatorMutex.Unlock()
|
||||
|
||||
kvs = latestCounter.GetSliceOrPanic()
|
||||
kvs, e = latestCounter.GetSliceWithError()
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
if len(kvs) > 0 {
|
||||
t, e := hca.counters.Unpack(kvs[0].Key)
|
||||
if e != nil {
|
||||
|
|
|
@ -102,8 +102,10 @@ func (dl directoryLayer) createOrOpen(rtr fdb.ReadTransaction, tr *fdb.Transacti
|
|||
return nil, errors.New("the directory already exists")
|
||||
}
|
||||
|
||||
if layer != nil && bytes.Compare(existingNode._layer.MustGet(), layer) != 0 {
|
||||
return nil, errors.New("the directory was created with an incompatible layer")
|
||||
if layer != nil {
|
||||
if l, e := existingNode._layer.Get(); e != nil || bytes.Compare(l, layer) != 0 {
|
||||
return nil, errors.New("the directory was created with an incompatible layer")
|
||||
}
|
||||
}
|
||||
|
||||
return existingNode.getContents(dl, nil)
|
||||
|
@ -325,7 +327,11 @@ func (dl directoryLayer) Move(t fdb.Transactor, oldPath []string, newPath []stri
|
|||
|
||||
dl.removeFromParent(tr, oldPath)
|
||||
|
||||
return dl.contentsOfNode(oldNode.subspace, newPath, oldNode._layer.MustGet())
|
||||
l, e := oldNode._layer.Get()
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return dl.contentsOfNode(oldNode.subspace, newPath, l)
|
||||
})
|
||||
if e != nil {
|
||||
return nil, e
|
||||
|
@ -415,7 +421,10 @@ func (dl directoryLayer) subdirNames(rtr fdb.ReadTransaction, node subspace.Subs
|
|||
var ret []string
|
||||
|
||||
for ri.Advance() {
|
||||
kv := ri.MustGet()
|
||||
kv, e := ri.Get()
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
|
||||
p, e := sd.Unpack(kv.Key)
|
||||
if e != nil {
|
||||
|
@ -453,7 +462,10 @@ func (dl directoryLayer) nodeContainingKey(rtr fdb.ReadTransaction, key []byte)
|
|||
bk, _ := dl.nodeSS.FDBRangeKeys()
|
||||
kr := fdb.KeyRange{bk, fdb.Key(append(dl.nodeSS.Pack(tuple.Tuple{key}), 0x00))}
|
||||
|
||||
kvs := rtr.GetRange(kr, fdb.RangeOptions{Reverse: true, Limit: 1}).GetSliceOrPanic()
|
||||
kvs, e := rtr.GetRange(kr, fdb.RangeOptions{Reverse: true, Limit: 1}).GetSliceWithError()
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
if len(kvs) == 1 {
|
||||
pp, e := dl.nodeSS.Unpack(kvs[0].Key)
|
||||
if e != nil {
|
||||
|
@ -495,7 +507,10 @@ func (dl directoryLayer) isPrefixFree(rtr fdb.ReadTransaction, prefix []byte) (b
|
|||
}
|
||||
|
||||
func (dl directoryLayer) checkVersion(rtr fdb.ReadTransaction, tr *fdb.Transaction) error {
|
||||
version := rtr.Get(dl.rootNode.Sub([]byte("version"))).MustGet()
|
||||
version, err := rtr.Get(dl.rootNode.Sub([]byte("version"))).Get()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if version == nil {
|
||||
if tr != nil {
|
||||
|
|
|
@ -67,5 +67,9 @@ func (n *node) getPartitionSubpath() []string {
|
|||
}
|
||||
|
||||
func (n *node) getContents(dl directoryLayer, tr *fdb.Transaction) (DirectorySubspace, error) {
|
||||
return dl.contentsOfNode(n.subspace, n.path, n._layer.MustGet())
|
||||
l, err := n._layer.Get()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dl.contentsOfNode(n.subspace, n.path, l)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue