Remove snappy compression migration for attestation history (#8238)

* Remove snappy compression migration for attestation history

* gofmt

* remove more snappy stuff

* revert validator/db/kv/historical_attestations.go
This commit is contained in:
Preston Van Loon
2021-01-11 09:28:34 -08:00
committed by GitHub
parent 9a1866b735
commit 97320a0a8e
5 changed files with 3 additions and 121 deletions

View File

@@ -11,7 +11,6 @@ go_library(
"genesis.go",
"historical_attestations.go",
"migration.go",
"migration_snappy_history.go",
"proposal_history_v2.go",
"prune_attester_protection.go",
"schema.go",
@@ -24,7 +23,6 @@ go_library(
"//shared/featureconfig:go_default_library",
"//shared/fileutil:go_default_library",
"//shared/params:go_default_library",
"@com_github_golang_snappy//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
@@ -44,7 +42,6 @@ go_test(
"db_test.go",
"genesis_test.go",
"historical_attestations_test.go",
"migration_snappy_history_test.go",
"proposal_history_v2_test.go",
"prune_attester_protection_test.go",
],
@@ -54,7 +51,6 @@ go_test(
"//shared/params:go_default_library",
"//shared/testutil/assert:go_default_library",
"//shared/testutil/require:go_default_library",
"@com_github_golang_snappy//:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@io_etcd_go_bbolt//:go_default_library",
],

View File

@@ -3,7 +3,6 @@ package kv
import (
"context"
"github.com/golang/snappy"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
bolt "go.etcd.io/bbolt"
@@ -49,11 +48,7 @@ func (store *Store) AttestationHistoryForPubKeyV2(ctx context.Context, publicKey
if len(enc) == 0 {
attestationHistory = NewAttestationHistoryArray(0)
} else {
data, err := snappy.Decode(nil /*dst*/, enc)
if err != nil {
return err
}
attestationHistory = data
attestationHistory = enc
}
return nil
})
@@ -71,8 +66,7 @@ func (store *Store) SaveAttestationHistoryForPubKeyV2(ctx context.Context, pubKe
defer span.End()
err := store.update(func(tx *bolt.Tx) error {
bucket := tx.Bucket(historicAttestationsBucket)
enc := snappy.Encode(nil /*dst*/, history)
return bucket.Put(pubKey[:], enc)
return bucket.Put(pubKey[:], history)
})
if !featureconfig.Get().DisableAttestingHistoryDBCache {
store.lock.Lock()

View File

@@ -10,9 +10,7 @@ var migrationCompleted = []byte("done")
type migration func(*bolt.Tx) error
var migrations = []migration{
migrateSnappyAttestationHistory,
}
var migrations = []migration{}
// RunMigrations defined in the migrations array.
func (s *Store) RunMigrations(ctx context.Context) error {

View File

@@ -1,32 +0,0 @@
package kv
import (
"bytes"
"github.com/golang/snappy"
bolt "go.etcd.io/bbolt"
)
var migrationSnappyAttestationHistory0Key = []byte("snappy_attestation_history_0")
// Migrate the attestation history data to use snappy compression on disk. This paradigm will
// significantly reduce disk I/O at the cost of a slightly increased CPU usage. Early benchmarks and
// tests indicate that this compression saves 25% on disk I/O and storage.
func migrateSnappyAttestationHistory(tx *bolt.Tx) error {
mb := tx.Bucket(migrationsBucket)
if b := mb.Get(migrationSnappyAttestationHistory0Key); bytes.Equal(b, migrationCompleted) {
return nil // Migration already completed.
}
bkt := tx.Bucket(historicAttestationsBucket)
// Compress all attestation history data.
if err := bkt.ForEach(func(k, v []byte) error {
enc := snappy.Encode(nil /*dst*/, v)
return bkt.Put(k, enc)
}); err != nil {
return err
}
return mb.Put(migrationSnappyAttestationHistory0Key, migrationCompleted)
}

View File

@@ -1,74 +0,0 @@
package kv
import (
"bytes"
"testing"
"github.com/golang/snappy"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
bolt "go.etcd.io/bbolt"
)
func Test_migrateSnappyAttestationHistory(t *testing.T) {
tests := []struct {
name string
setup func(t *testing.T, db *bolt.DB)
eval func(t *testing.T, db *bolt.DB)
}{
{
name: "only runs once",
setup: func(t *testing.T, db *bolt.DB) {
if err := db.Update(func(tx *bolt.Tx) error {
if err := tx.Bucket(historicAttestationsBucket).Put([]byte("foo"), []byte{1, 1, 1, 1, 1, 1, 1, 1, 1}); err != nil {
return err
}
return tx.Bucket(migrationsBucket).Put(migrationSnappyAttestationHistory0Key, migrationCompleted)
}); err != nil {
t.Fatal(err)
}
},
eval: func(t *testing.T, db *bolt.DB) {
if err := db.View(func(tx *bolt.Tx) error {
data := tx.Bucket(historicAttestationsBucket).Get([]byte("foo"))
expected := []byte{1, 1, 1, 1, 1, 1, 1, 1, 1} // unchanged
if !bytes.Equal(data, expected) {
t.Fatalf("expected data did not match reality. Got %x wanted %x", data, expected)
}
return nil
}); err != nil {
t.Fatal(err)
}
},
},
{
name: "compresses data",
setup: func(t *testing.T, db *bolt.DB) {
if err := db.Update(func(tx *bolt.Tx) error {
return tx.Bucket(historicAttestationsBucket).Put([]byte("foo"), []byte{1, 1, 1, 1, 1, 1, 1, 1, 1})
}); err != nil {
t.Fatal(err)
}
},
eval: func(t *testing.T, db *bolt.DB) {
if err := db.View(func(tx *bolt.Tx) error {
data := tx.Bucket(historicAttestationsBucket).Get([]byte("foo"))
expected := snappy.Encode(nil /*dst*/, []byte{1, 1, 1, 1, 1, 1, 1, 1, 1})
if !bytes.Equal(data, expected) {
t.Fatalf("expected data did not match reality. Got %x wanted %x", data, expected)
}
return nil
}); err != nil {
t.Fatal(err)
}
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
db := setupDB(t, nil).db
tt.setup(t, db)
assert.NoError(t, db.Update(migrateSnappyAttestationHistory), "migrateSnappyAttestationHistory(tx) error")
tt.eval(t, db)
})
}
}