Skip to content

Commit

Permalink
revert closer changes
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangchiqing committed Dec 12, 2024
1 parent d8f31c5 commit 24d65bc
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions storage/operation/reads.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TraverseByPrefix(r storage.Reader, prefix []byte, iterFunc IterationFunc, o
// When this returned function is executed (and only then), it will write into the `keyExists` whether
// the key exists.
// No errors are expected during normal operation.
func KeyExists(r storage.Reader, key []byte) (exist bool, errExit error) {
func KeyExists(r storage.Reader, key []byte) (bool, error) {
_, closer, err := r.Get(key)
if err != nil {
// the key does not exist in the database
Expand All @@ -140,9 +140,7 @@ func KeyExists(r storage.Reader, key []byte) (exist bool, errExit error) {
// exception while checking for the key
return false, irrecoverable.NewExceptionf("could not load data: %w", err)
}
defer func() {
errExit = closer.Close()
}()
defer closer.Close()

// the key does exist in the database
return true, nil
Expand All @@ -155,15 +153,13 @@ func KeyExists(r storage.Reader, key []byte) (exist bool, errExit error) {
// - storage.ErrNotFound if the key does not exist in the database
// - generic error in case of unexpected failure from the database layer, or failure
// to decode an existing database value
func RetrieveByKey(r storage.Reader, key []byte, entity interface{}) (errExit error) {
func RetrieveByKey(r storage.Reader, key []byte, entity interface{}) error {
val, closer, err := r.Get(key)
if err != nil {
return err
}

defer func() {
errExit = closer.Close()
}()
defer closer.Close()

err = msgpack.Unmarshal(val, entity)
if err != nil {
Expand All @@ -176,7 +172,7 @@ func RetrieveByKey(r storage.Reader, key []byte, entity interface{}) (errExit er
// keys with the format prefix` + `height` (where "+" denotes concatenation of binary strings). The height
// is encoded as Big-Endian (entries with numerically smaller height have lexicographically smaller key).
// The function finds the *highest* key with the given prefix and height equal to or below the given height.
func FindHighestAtOrBelowByPrefix(r storage.Reader, prefix []byte, height uint64, entity interface{}) (errExit error) {
func FindHighestAtOrBelowByPrefix(r storage.Reader, prefix []byte, height uint64, entity interface{}) error {
if len(prefix) == 0 {
return fmt.Errorf("prefix must not be empty")
}
Expand All @@ -186,9 +182,7 @@ func FindHighestAtOrBelowByPrefix(r storage.Reader, prefix []byte, height uint64
if err != nil {
return fmt.Errorf("can not create iterator: %w", err)
}
defer func() {
errExit = it.Close()
}()
defer it.Close()

var highestKey []byte

Expand All @@ -209,9 +203,7 @@ func FindHighestAtOrBelowByPrefix(r storage.Reader, prefix []byte, height uint64
return err
}

defer func() {
errExit = closer.Close()
}()
defer closer.Close()

err = msgpack.Unmarshal(val, entity)
if err != nil {
Expand Down

0 comments on commit 24d65bc

Please sign in to comment.