erigon-pulse/ethdb/bitmapdb/dbutils_test.go
Alex Sharov e02d6acc7d
bitmap indices for logs (#1124)
* save progress

* try now

* don't create bloom inside rlpDecode

* don't create bloom inside ApplyTransaction

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* rename method

* print timings

* print timings

* print timings

* sort before flush

* fix err lint

* clean

* move tests to transactions

* compressed version

* up bound

* up bound

* more tests

* more tests

* more tests

* more tests

* better removal

* clean

* better performance of get/put methods

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* optimize rpcdaemon

* fix test

* fix rpcdaemon

* fix test

* simplify

* simplify

* fix nil pointer

* clean

* revert some changes

* add some logs

* clean

* try without optimize

* clean

* clean

* clean

* clean

* try

* move log_index to own stage

* move log_index to own stage

* integration add log_index stage

* integration add log_index stage

* clean

* clean

* print timing

* remove duplicates at unwind

* extract truncateBitmaps func

* try detect

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* add blackList of topics

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* clean

* sharding 1

* sharded 2

* sharded 2

* sharded 2

* sharded 2

* sharded 2

* sharded 2

* sharded 2

* sharded 2

* sharded 2

* sharded 2

* sharded 2

* sharded 2

* sharded 2

* sharded 2

* sharded 2

* sharded 2

* sharded 3

* sharded 3

* sharded 3

* speedup things by putCurrent and putReserve

* clean

* optimize trim

* clean

* remove blacklist

* add more info to err

* ?

* clean

* clean

* clean

* clean

* clean

* working version

* switch to cgo version of roaring bitmaps

* clean

* clean

* clean

* clean

* more docs

* clean

* clean

* fix logs bloom field

* Fix debug_getModifiedAccountsByNumber

* Try to fix crash

* fix problem with "absent block"

* fix problem with "absent block"

* remove optimize method call

* remove roaring iterator

* fix problem with rebuild indicess

* remove debug prints

* tests for eth_getLogs involving topics

* add tests for new stage, speparate topics into 2 buckets

* version up

* remove debug logs

* remove debug logs

* remove bloom filter implementation

* Optimisation

* Optimisatin not required, make rpctest lenient to geth errors

* Lenient to geth failures

Co-authored-by: Alexey Akhunov <akhounov@gmail.com>
2020-09-28 18:18:36 +01:00

74 lines
1.8 KiB
Go

package bitmapdb_test
import (
"context"
"testing"
"github.com/RoaringBitmap/gocroaring"
"github.com/ledgerwatch/turbo-geth/common/dbutils"
"github.com/ledgerwatch/turbo-geth/ethdb"
"github.com/ledgerwatch/turbo-geth/ethdb/bitmapdb"
"github.com/stretchr/testify/require"
)
func TestSharding(t *testing.T) {
db := ethdb.NewMemDatabase()
defer db.Close()
tx, err := db.Begin(context.Background())
require.NoError(t, err)
defer tx.Rollback()
c := tx.(ethdb.HasTx).Tx().Cursor(dbutils.LogTopicIndex)
{
k := []byte{1}
// Write/Read large bitmap works expected
for i := uint32(0); i < 3_000_000; i += 5_000 {
bm1 := gocroaring.New()
for j := i; j < i+5_000; j += 2 {
bm1.Add(j)
}
err := bitmapdb.AppendMergeByOr(c, k, bm1)
require.NoError(t, err)
}
fromDb, err := bitmapdb.Get(c, k)
require.NoError(t, err)
expect := gocroaring.New()
for i := uint32(0); i < 3_000_000; i += 5_000 {
for j := i; j < i+5_000; j += 2 {
expect.Add(j)
}
}
expect.Xor(fromDb)
require.Equal(t, 0, int(expect.GetCardinality()))
// TruncateRange can remove large part
err = bitmapdb.TruncateRange(c, k, 2_000_000, 3_000_000) // [from, to)
require.NoError(t, err)
fromDb, err = bitmapdb.Get(c, k)
require.NoError(t, err)
expect = gocroaring.New()
for i := uint32(0); i < 2_000_000; i += 100_000 {
for j := uint32(0); j < i+100_000; j += 2 {
expect.Add(j)
}
}
expect.Xor(fromDb)
require.Equal(t, 0, int(expect.GetCardinality()))
// check that TruncateRange will preserve right interval: [from, to)
max := fromDb.Maximum()
err = bitmapdb.TruncateRange(c, k, 0, uint64(fromDb.Maximum())) // [from, to)
require.NoError(t, err)
fromDb, err = bitmapdb.Get(c, k)
require.NoError(t, err)
require.Equal(t, 1, int(fromDb.GetCardinality()))
require.Equal(t, int(max), int(fromDb.Maximum()))
}
}