Skip to content

Commit

Permalink
diffs: no overflow pages (#12756)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Nov 19, 2024
1 parent fe4a11f commit 3b596d4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
1 change: 1 addition & 0 deletions erigon-lib/kv/mdbx/kv_mdbx.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func (opts MdbxOpts) InMem(tmpDir string) MdbxOpts {
opts.dirtySpace = uint64(64 * datasize.MB)
opts.shrinkThreshold = 0 // disable
opts.label = kv.InMem
opts.pageSize = 4096
return opts
}

Expand Down
13 changes: 6 additions & 7 deletions erigon-lib/state/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,19 +881,18 @@ func generateKV(tb testing.TB, tmp string, keySize, valueSize, keyCount int, log
return compPath
}

func testDbAndAggregatorv3(t *testing.T, aggStep uint64) (kv.RwDB, *Aggregator) {
t.Helper()
require := require.New(t)
dirs := datadir.New(t.TempDir())
logger := log.New()
func testDbAndAggregatorv3(tb testing.TB, aggStep uint64) (kv.RwDB, *Aggregator) {
tb.Helper()
require, logger := require.New(tb), log.New()
dirs := datadir.New(tb.TempDir())
db := mdbx.NewMDBX(logger).InMem(dirs.Chaindata).GrowthStep(32 * datasize.MB).MapSize(2 * datasize.GB).WithTableCfg(func(defaultBuckets kv.TableCfg) kv.TableCfg {
return kv.ChaindataTablesCfg
}).MustOpen()
t.Cleanup(db.Close)
tb.Cleanup(db.Close)

agg, err := NewAggregator(context.Background(), dirs, aggStep, db, logger)
require.NoError(err)
t.Cleanup(agg.Close)
tb.Cleanup(agg.Close)
err = agg.OpenFolder()
require.NoError(err)
agg.DisableFsync()
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/state/squeeze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type testAggConfig struct {
func testDbAggregatorWithFiles(tb testing.TB, cfg *testAggConfig) (kv.RwDB, *Aggregator) {
tb.Helper()

db, agg := testDbAndAggregatorv3(tb.(*testing.T), cfg.stepSize)
db, agg := testDbAndAggregatorv3(tb, cfg.stepSize)
agg.commitmentValuesTransform = !cfg.disableCommitmentBranchTransform
agg.d[kv.CommitmentDomain].replaceKeysInValues = agg.commitmentValuesTransform

Expand Down
3 changes: 2 additions & 1 deletion erigon-lib/state/state_changeset.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ func DeserializeKeys(in []byte) [kv.DomainLen][]DomainEntryDiff {
return ret
}

const diffChunkKeyLen = 48
const diffChunkLen = 4*1024 - 32

func WriteDiffSet(tx kv.RwTx, blockNumber uint64, blockHash common.Hash, diffSet *StateChangeSet) error {
Expand All @@ -281,7 +282,7 @@ func WriteDiffSet(tx kv.RwTx, blockNumber uint64, blockHash common.Hash, diffSet
return err
}

key := make([]byte, 48)
key := make([]byte, diffChunkKeyLen)
for i := 0; i < chunkCount; i++ {
start := i * diffChunkLen
end := (i + 1) * diffChunkLen
Expand Down
22 changes: 22 additions & 0 deletions erigon-lib/state/state_changeset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,34 @@
package state

import (
"context"
"fmt"
"testing"

"github.com/erigontech/erigon-lib/kv"
"github.com/erigontech/erigon-lib/kv/mdbx"
"github.com/stretchr/testify/require"
)

func TestOverflowPages(t *testing.T) {
db, _ := testDbAndAggregatorv3(t, 10)
ctx := context.Background()
tx, err := db.BeginRw(ctx)
require.NoError(t, err)
defer tx.Rollback()
k, v := make([]byte, diffChunkKeyLen), make([]byte, diffChunkLen)
k[0] = 0
_ = tx.Put(kv.ChangeSets3, k, v)
k[0] = 1
_ = tx.Put(kv.ChangeSets3, k, v)
st, err := tx.(*mdbx.MdbxTx).BucketStat(kv.ChangeSets3)
require.NoError(t, err)
require.Equal(t, 2, int(st.OverflowPages))
require.Equal(t, 1, int(st.LeafPages))
require.Equal(t, 2, int(st.Entries))
require.Equal(t, 2, int(st.Entries))
}

func TestSerializeDeserializeDiff(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 3b596d4

Please sign in to comment.