Skip to content

Commit

Permalink
update ledger file path and migration (#1042)
Browse files Browse the repository at this point in the history
  • Loading branch information
shiqizng authored Jun 22, 2022
1 parent a6c85a4 commit 5f5c7fe
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
14 changes: 12 additions & 2 deletions cmd/algorand-indexer/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/ledger/ledgercore"
"github.com/algorand/go-algorand/logging"
"github.com/algorand/go-algorand/protocol"
"github.com/algorand/go-algorand/rpcs"
Expand Down Expand Up @@ -240,8 +241,17 @@ var daemonCmd = &cobra.Command{
maybeFail(err, "Error getting DB round")
if nextDBRound > 0 {
if catchpoint != "" {
err = localledger.RunMigrationFastCatchup(logging.NewLogger(), catchpoint, &opts)
maybeFail(err, "Error running ledger migration in fast catchup mode")
round, _, err := ledgercore.ParseCatchpointLabel(catchpoint)
if err != nil {
maybeFail(err, "catchpoint error")
}
if uint64(round) >= nextDBRound {
logger.Warnf("round for given catchpoint is ahead of db round. skip fast catchup")
} else {
err = localledger.RunMigrationFastCatchup(logging.NewLogger(), catchpoint, &opts)
maybeFail(err, "Error running ledger migration in fast catchup mode")
}

}
err = localledger.RunMigrationSimple(nextDBRound-1, &opts)
maybeFail(err, "Error running ledger migration")
Expand Down
4 changes: 4 additions & 0 deletions migrations/local_ledger/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func RunMigrationSimple(round uint64, opts *idb.IndexerDbOptions) error {
if err != nil {
return fmt.Errorf("RunMigration() err: %w", err)
}
// ledger and db states are in sync
if proc.NextRoundToProcess()-1 == round {
return nil
}
bot.SetNextRound(proc.NextRoundToProcess())
handler := blockHandler(round, proc, cf, 1*time.Second)
bot.SetBlockHandler(handler)
Expand Down
7 changes: 3 additions & 4 deletions migrations/local_ledger/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package localledger
import (
"fmt"
"os"
"path"
"path/filepath"
"testing"

Expand Down Expand Up @@ -59,7 +58,7 @@ func TestRunMigration(t *testing.T) {
dname, err := os.MkdirTemp("", "indexer")
defer os.RemoveAll(dname)
opts := idb.IndexerDbOptions{
IndexerDatadir: dname + "/",
IndexerDatadir: dname,
AlgodAddr: "localhost",
AlgodToken: "AAAAA",
}
Expand All @@ -69,7 +68,7 @@ func TestRunMigration(t *testing.T) {
assert.NoError(t, err)
initState, err := util.CreateInitState(&genesis)
assert.NoError(t, err)
l, err := ledger.OpenLedger(logging.NewLogger(), filepath.Join(path.Dir(opts.IndexerDatadir), "ledger"), false, initState, algodConfig.GetDefaultLocal())
l, err := ledger.OpenLedger(logging.NewLogger(), filepath.Join(opts.IndexerDatadir, "ledger"), false, initState, algodConfig.GetDefaultLocal())
assert.NoError(t, err)
// check 3 rounds written to ledger
assert.Equal(t, uint64(3), uint64(l.Latest()))
Expand All @@ -79,7 +78,7 @@ func TestRunMigration(t *testing.T) {
err = RunMigrationSimple(6, &opts)
assert.NoError(t, err)

l, err = ledger.OpenLedger(logging.NewLogger(), filepath.Join(path.Dir(opts.IndexerDatadir), "ledger"), false, initState, algodConfig.GetDefaultLocal())
l, err = ledger.OpenLedger(logging.NewLogger(), filepath.Join(opts.IndexerDatadir, "ledger"), false, initState, algodConfig.GetDefaultLocal())
assert.NoError(t, err)
assert.Equal(t, uint64(6), uint64(l.Latest()))
l.Close()
Expand Down
3 changes: 1 addition & 2 deletions processor/blockprocessor/block_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package blockprocessor

import (
"fmt"
"path"
"path/filepath"

"github.com/algorand/go-algorand/config"
Expand Down Expand Up @@ -45,7 +44,7 @@ func MakeProcessor(genesis *bookkeeping.Genesis, dbRound uint64, datadir string,
if err != nil {
return nil, fmt.Errorf("MakeProcessor() err: %w", err)
}
l, err := ledger.OpenLedger(logging.NewLogger(), filepath.Join(path.Dir(datadir), prefix), false, initState, algodConfig.GetDefaultLocal())
l, err := ledger.OpenLedger(logging.NewLogger(), filepath.Join(datadir, prefix), false, initState, algodConfig.GetDefaultLocal())
if err != nil {
return nil, fmt.Errorf("MakeProcessor() err: %w", err)
}
Expand Down

0 comments on commit 5f5c7fe

Please sign in to comment.