Skip to content

Commit

Permalink
cmd/integration: log index stage sub command to reset only prune_at p…
Browse files Browse the repository at this point in the history
…oint (#9971)

--reset clears all the tables associated with a stage, while we just
want to reset the prune_at progress to 0 for some situations
  • Loading branch information
taratorio committed Apr 17, 2024
1 parent 4a578ba commit b17aa53
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cmd/integration/commands/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var (
unwindEvery uint64
batchSizeStr string
reset, warmup, noCommit bool
resetPruneAt bool
bucket string
datadirCli, toChaindata string
migration string
Expand Down Expand Up @@ -102,6 +103,10 @@ func withReset(cmd *cobra.Command) {
cmd.Flags().BoolVar(&warmup, "warmup", false, "warmup relevant tables by parallel random reads")
}

func withResetPruneAt(cmd *cobra.Command) {
cmd.Flags().BoolVar(&resetPruneAt, "resetPruneAt", false, "reset prune_at to 0 for a given stage")
}

func withBucket(cmd *cobra.Command) {
cmd.Flags().StringVar(&bucket, "bucket", "", "reset given stage")
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/integration/commands/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ func init() {
withConfig(cmdLogIndex)
withDataDir(cmdLogIndex)
withReset(cmdLogIndex)
withResetPruneAt(cmdLogIndex)
withBlock(cmdLogIndex)
withUnwind(cmdLogIndex)
withPruneTo(cmdLogIndex)
Expand Down Expand Up @@ -1168,6 +1169,9 @@ func stageLogIndex(db kv.RwDB, ctx context.Context, logger log.Logger) error {
if reset {
return reset2.Reset(ctx, db, stages.LogIndex)
}
if resetPruneAt {
return reset2.ResetPruneAt(ctx, db, stages.LogIndex)
}
tx, err := db.BeginRw(ctx)
if err != nil {
return err
Expand Down
10 changes: 9 additions & 1 deletion core/rawdb/rawdbreset/reset_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"

"github.com/ledgerwatch/log/v3"

"github.com/ledgerwatch/erigon-lib/chain"
"github.com/ledgerwatch/erigon-lib/common/datadir"
"github.com/ledgerwatch/erigon-lib/kv"
Expand All @@ -17,7 +19,6 @@ import (
"github.com/ledgerwatch/erigon/eth/stagedsync"
"github.com/ledgerwatch/erigon/eth/stagedsync/stages"
"github.com/ledgerwatch/erigon/turbo/services"
"github.com/ledgerwatch/log/v3"
)

func ResetState(db kv.RwDB, ctx context.Context, chain string, tmpDir string, logger log.Logger) error {
Expand Down Expand Up @@ -241,6 +242,13 @@ func Reset(ctx context.Context, db kv.RwDB, stagesList ...stages.SyncStage) erro
return nil
})
}

func ResetPruneAt(ctx context.Context, db kv.RwDB, stage stages.SyncStage) error {
return db.Update(ctx, func(tx kv.RwTx) error {
return stages.SaveStagePruneProgress(tx, stage, 0)
})
}

func Warmup(ctx context.Context, db kv.RwDB, lvl log.Lvl, stList ...stages.SyncStage) error {
for _, st := range stList {
for _, tbl := range Tables[st] {
Expand Down

0 comments on commit b17aa53

Please sign in to comment.