From cf760cde67dc1e290bed915a95dccb5e8464b1ed Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Mon, 26 Jun 2023 14:57:00 +0700 Subject: [PATCH] save --- state/domain.go | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/state/domain.go b/state/domain.go index 3999dbb3d..97c4fe3d1 100644 --- a/state/domain.go +++ b/state/domain.go @@ -960,33 +960,33 @@ func (d *Domain) collate(ctx context.Context, step, txFrom, txTo uint64, roTx kv return Collation{}, err } pos++ + + if v, err = keysCursor.LastDup(); err != nil { + return Collation{}, fmt.Errorf("find last %s key for aggregation step k=[%x]: %w", d.filenameBase, k, err) + } + if ^binary.BigEndian.Uint64(v) != step { + continue + } + keySuffix := make([]byte, len(k)+8) + copy(keySuffix, k) + copy(keySuffix[len(k):], v) + v, err := roTx.GetOne(d.valsTable, keySuffix) + if err != nil { + return Collation{}, fmt.Errorf("find last %s value for aggregation step k=[%x]: %w", d.filenameBase, k, err) + } + if err = valuesComp.AddUncompressedWord(k); err != nil { + return Collation{}, fmt.Errorf("add %s values key [%x]: %w", d.filenameBase, k, err) + } + valuesCount++ // Only counting keys, not values + if err = valuesComp.AddUncompressedWord(v); err != nil { + return Collation{}, fmt.Errorf("add %s values val [%x]=>[%x]: %w", d.filenameBase, k, v, err) + } select { case <-ctx.Done(): d.logger.Warn("[snapshots] collate domain cancelled", "name", d.filenameBase, "err", ctx.Err()) return Collation{}, ctx.Err() default: } - - if v, err = keysCursor.LastDup(); err != nil { - return Collation{}, fmt.Errorf("find last %s key for aggregation step k=[%x]: %w", d.filenameBase, k, err) - } - s := ^binary.BigEndian.Uint64(v) - if s == step { - keySuffix := make([]byte, len(k)+8) - copy(keySuffix, k) - copy(keySuffix[len(k):], v) - v, err := roTx.GetOne(d.valsTable, keySuffix) - if err != nil { - return Collation{}, fmt.Errorf("find last %s value for aggregation step k=[%x]: %w", d.filenameBase, k, err) - } - if err = valuesComp.AddUncompressedWord(k); err != nil { - return Collation{}, fmt.Errorf("add %s values key [%x]: %w", d.filenameBase, k, err) - } - valuesCount++ // Only counting keys, not values - if err = valuesComp.AddUncompressedWord(v); err != nil { - return Collation{}, fmt.Errorf("add %s values val [%x]=>[%x]: %w", d.filenameBase, k, v, err) - } - } } if err != nil { return Collation{}, fmt.Errorf("iterate over %s keys cursor: %w", d.filenameBase, err)