Sequence in to mdbx (#1370)

This commit is contained in:
Alex Sharov 2020-11-23 11:15:43 +07:00 committed by GitHub
parent 068463dff4
commit ccd1ad5832
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -359,10 +359,23 @@ func toMdbx(ctx context.Context, from, to string) error {
if b.Flags&dbutils.DupSort != 0 && !b.AutoDupSortKeysConversion {
appendFunc = c.(ethdb.CursorDupSort).AppendDup
}
if b.Flags&dbutils.DupFixed != 0 && !b.AutoDupSortKeysConversion {
appendFunc = c.(ethdb.CursorDupSort).AppendDup
}
}
}
// migrate bucket sequences to native mdbx implementation
currentID, err := srcTx.Sequence(name, 0)
if err != nil {
return err
}
_, err = dstTx.Sequence(name, currentID+1)
if err != nil {
return err
}
}
err := dstTx.Commit(context.Background())
if err != nil {
return err

View File

@ -719,6 +719,10 @@ func (tx *lmdbTx) Sequence(bucket string, amount uint64) (uint64, error) {
currentV = binary.BigEndian.Uint64(v)
}
if amount == 0 {
return currentV, nil
}
newVBytes := make([]byte, 8)
binary.BigEndian.PutUint64(newVBytes, currentV+amount)
err = c.Put([]byte(bucket), newVBytes)