Skip to content

Commit

Permalink
prune active set from ballot blob (#5032)
Browse files Browse the repository at this point in the history
## Motivation
Closes #4985

## Changes
- actually prune active set from ballot blobs in db
- use a empty migration to facilitate the pruning. 
  we only want to prune/vacuum/checkpoint once per software upgrade
  the code allow any upgrade from migration <=4 to 5 to
  - extract active set from ballots
  - prune active set from blob
  - vacuum and checkpoint

the final size of the state should be < 1GB
  • Loading branch information
countvonzero committed Sep 25, 2023
1 parent 0b084e9 commit 9a8e957
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ In order to enable provide following configuration:
Ephemeral data are deleted and state compacted at the time of upgrade. In steady-state, data is pruned periodically.
* [#5021](https://github.com/spacemeshos/go-spacemesh/pull/5021) Drop support for old certificate sync protocol.
* [#5024](https://github.com/spacemeshos/go-spacemesh/pull/5024) Active set will be saved in state separately from ballots.
* [#5032](https://github.com/spacemeshos/go-spacemesh/pull/5032) Ativeset data pruned from ballots.
* [#5035](https://github.com/spacemeshos/go-spacemesh/pull/5035) Fix possible nil pointer panic when node fails to persist nipost builder state.

## v1.1.5
Expand Down
10 changes: 5 additions & 5 deletions sql/ballots/util/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"

"github.com/spacemeshos/go-spacemesh/codec"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/log"
"github.com/spacemeshos/go-spacemesh/sql"
Expand Down Expand Up @@ -42,11 +43,10 @@ func ExtractActiveSet(db sql.Executor) error {
} else if err == nil {
unique++
}
// TODO: prune ballot active set after migration 4 is released
//b.ActiveSet = nil
//if err := ballots.UpdateBlob(db, b.ID(), codec.MustEncode(b)); err != nil {
// return fmt.Errorf("update ballot %s: %w", b.ID().String(), err)
//}
b.ActiveSet = nil
if err := ballots.UpdateBlob(db, b.ID(), codec.MustEncode(b)); err != nil {
return fmt.Errorf("update ballot %s: %w", b.ID().String(), err)
}
extracted++
}
}
Expand Down
4 changes: 1 addition & 3 deletions sql/ballots/util/extract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ func TestExtractActiveSet(t *testing.T) {
for _, b := range blts {
got, err := ballots.Get(db, b.ID())
require.NoError(t, err)
if b.Layer%3 != 2 {
require.NotEmpty(t, got.ActiveSet)
}
require.Nil(t, got.ActiveSet)
}
for i, h := range hashes {
got, err := activesets.Get(db, h)
Expand Down
8 changes: 2 additions & 6 deletions sql/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,8 @@ func Open(uri string, opts ...Opt) (*Database, error) {
if err != nil {
return nil, err
}
after, err := version(db)
if err != nil {
return nil, err
}
if before <= 4 && after == 5 && config.v5Migration != nil {
// v5 migration (active set extraction) needs the 4rd migration to execute first
if before <= 4 && config.v5Migration != nil {
// v5 migration (active set extraction) needs the 3rd migration to execute first
if err := config.v5Migration(db); err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion sql/migrations/0004_v1.1.7.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CREATE INDEX ballots_by_atx_by_layer ON ballots (atx, layer asc);
CREATE INDEX ballots_by_atx_by_layer ON ballots (atx, layer asc);
2 changes: 1 addition & 1 deletion sql/migrations/0005_next.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
DELETE FROM proposals;
DELETE FROM proposal_transactions;
UPDATE certificates SET cert = NULL WHERE layer < 19000;
UPDATE certificates SET cert = NULL WHERE layer < 20000;

0 comments on commit 9a8e957

Please sign in to comment.