ethdb/pebble: handle errors (#30367)
This commit is contained in:
parent
c4c2c4fb14
commit
7513966d6e
@ -293,7 +293,9 @@ func (d *Database) Has(key []byte) (bool, error) {
|
||||
} else if err != nil {
|
||||
return false, err
|
||||
}
|
||||
closer.Close()
|
||||
if err = closer.Close(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
@ -310,7 +312,9 @@ func (d *Database) Get(key []byte) ([]byte, error) {
|
||||
}
|
||||
ret := make([]byte, len(dat))
|
||||
copy(ret, dat)
|
||||
closer.Close()
|
||||
if err = closer.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
@ -519,14 +523,18 @@ type batch struct {
|
||||
|
||||
// Put inserts the given value into the batch for later committing.
|
||||
func (b *batch) Put(key, value []byte) error {
|
||||
b.b.Set(key, value, nil)
|
||||
if err := b.b.Set(key, value, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
b.size += len(key) + len(value)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete inserts the key removal into the batch for later committing.
|
||||
func (b *batch) Delete(key []byte) error {
|
||||
b.b.Delete(key, nil)
|
||||
if err := b.b.Delete(key, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
b.size += len(key)
|
||||
return nil
|
||||
}
|
||||
@ -558,19 +566,22 @@ func (b *batch) Replay(w ethdb.KeyValueWriter) error {
|
||||
for {
|
||||
kind, k, v, ok, err := reader.Next()
|
||||
if !ok || err != nil {
|
||||
break
|
||||
return err
|
||||
}
|
||||
// The (k,v) slices might be overwritten if the batch is reset/reused,
|
||||
// and the receiver should copy them if they are to be retained long-term.
|
||||
if kind == pebble.InternalKeyKindSet {
|
||||
w.Put(k, v)
|
||||
if err = w.Put(k, v); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if kind == pebble.InternalKeyKindDelete {
|
||||
w.Delete(k)
|
||||
if err = w.Delete(k); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("unhandled operation, keytype: %v", kind)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// pebbleIterator is a wrapper of underlying iterator in storage engine.
|
||||
|
Loading…
Reference in New Issue
Block a user