From b17aa538661aa7c7e449bf6b3e151cf2f5161859 Mon Sep 17 00:00:00 2001 From: milen <94537774+taratorio@users.noreply.github.com> Date: Wed, 17 Apr 2024 17:16:25 +0300 Subject: [PATCH] cmd/integration: log index stage sub command to reset only prune_at point (#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 --- cmd/integration/commands/flags.go | 5 +++++ cmd/integration/commands/stages.go | 4 ++++ core/rawdb/rawdbreset/reset_stages.go | 10 +++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cmd/integration/commands/flags.go b/cmd/integration/commands/flags.go index 2e7cbdd0e50..bf57f18a61c 100644 --- a/cmd/integration/commands/flags.go +++ b/cmd/integration/commands/flags.go @@ -17,6 +17,7 @@ var ( unwindEvery uint64 batchSizeStr string reset, warmup, noCommit bool + resetPruneAt bool bucket string datadirCli, toChaindata string migration string @@ -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") } diff --git a/cmd/integration/commands/stages.go b/cmd/integration/commands/stages.go index 1e5dbb46c2b..3368ae715db 100644 --- a/cmd/integration/commands/stages.go +++ b/cmd/integration/commands/stages.go @@ -563,6 +563,7 @@ func init() { withConfig(cmdLogIndex) withDataDir(cmdLogIndex) withReset(cmdLogIndex) + withResetPruneAt(cmdLogIndex) withBlock(cmdLogIndex) withUnwind(cmdLogIndex) withPruneTo(cmdLogIndex) @@ -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 diff --git a/core/rawdb/rawdbreset/reset_stages.go b/core/rawdb/rawdbreset/reset_stages.go index c2f45bf4a7c..780d7c1c303 100644 --- a/core/rawdb/rawdbreset/reset_stages.go +++ b/core/rawdb/rawdbreset/reset_stages.go @@ -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" @@ -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 { @@ -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] {