lmdb_is_not_friendly_to_empty_values (#795)

This commit is contained in:
Alex Sharov 2020-07-29 11:30:29 +07:00 committed by GitHub
parent c6f0f8897f
commit 47b7b2cf40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -63,25 +63,25 @@ func GetStorageModeFromDB(db Database) (StorageMode, error) {
if err != nil && !errors.Is(err, ErrKeyNotFound) {
return StorageMode{}, err
}
sm.History = len(v) > 0
sm.History = len(v) == 1 && v[0] == 1
v, err = db.Get(dbutils.DatabaseInfoBucket, dbutils.StorageModePreImages)
if err != nil && !errors.Is(err, ErrKeyNotFound) {
return StorageMode{}, err
}
sm.Preimages = len(v) > 0
sm.Preimages = len(v) == 1 && v[0] == 1
v, err = db.Get(dbutils.DatabaseInfoBucket, dbutils.StorageModeReceipts)
if err != nil && !errors.Is(err, ErrKeyNotFound) {
return StorageMode{}, err
}
sm.Receipts = len(v) > 0
sm.Receipts = len(v) == 1 && v[0] == 1
v, err = db.Get(dbutils.DatabaseInfoBucket, dbutils.StorageModeTxIndex)
if err != nil && !errors.Is(err, ErrKeyNotFound) {
return StorageMode{}, err
}
sm.TxIndex = len(v) > 0
sm.TxIndex = len(v) == 1 && v[0] == 1
return sm, nil
}
@ -119,7 +119,7 @@ func setModeOnEmpty(db Database, key []byte, currentValue bool) error {
return err
}
if errors.Is(err, ErrKeyNotFound) {
val := []byte{}
val := []byte{2}
if currentValue {
val = []byte{1}
}