From 6ad1e61c8d691910efed556c379b94c2365fe884 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Mon, 8 Jul 2024 18:35:42 +0200 Subject: [PATCH] Revert "Refine logging of migrations and tx ingestion (#237)" This reverts commit 556d53504e2e1ccbb479f779ae99303ef558a6e1. --- cmd/soroban-rpc/internal/daemon/daemon.go | 10 +++------- cmd/soroban-rpc/internal/db/ledger.go | 1 - cmd/soroban-rpc/internal/db/migration.go | 20 +++++--------------- cmd/soroban-rpc/internal/db/transaction.go | 2 +- 4 files changed, 9 insertions(+), 24 deletions(-) diff --git a/cmd/soroban-rpc/internal/daemon/daemon.go b/cmd/soroban-rpc/internal/daemon/daemon.go index c6d287c6..ab8ec8a0 100644 --- a/cmd/soroban-rpc/internal/daemon/daemon.go +++ b/cmd/soroban-rpc/internal/daemon/daemon.go @@ -296,11 +296,7 @@ func (d *Daemon) mustInitializeStorage(cfg *config.Config) (*feewindow.FeeWindow cfg.NetworkPassphrase, cfg.HistoryRetentionWindow, ) - feewindows := feewindow.NewFeeWindows( - cfg.ClassicFeeStatsLedgerRetentionWindow, - cfg.SorobanFeeStatsLedgerRetentionWindow, - cfg.NetworkPassphrase, - ) + feewindows := feewindow.NewFeeWindows(cfg.ClassicFeeStatsLedgerRetentionWindow, cfg.SorobanFeeStatsLedgerRetentionWindow, cfg.NetworkPassphrase) readTxMetaCtx, cancelReadTxMeta := context.WithTimeout(context.Background(), cfg.IngestionTimeout) defer cancelReadTxMeta() @@ -319,7 +315,7 @@ func (d *Daemon) mustInitializeStorage(cfg *config.Config) (*feewindow.FeeWindow initialSeq = currentSeq d.logger.WithFields(supportlog.F{ "seq": currentSeq, - }).Info("initializing in-memory store and applying DB data migrations") + }).Info("initializing in-memory store") } else if (currentSeq-initialSeq)%inMemoryInitializationLedgerLogPeriod == 0 { d.logger.WithFields(supportlog.F{ "seq": currentSeq, @@ -350,7 +346,7 @@ func (d *Daemon) mustInitializeStorage(cfg *config.Config) (*feewindow.FeeWindow if currentSeq != 0 { d.logger.WithFields(supportlog.F{ "seq": currentSeq, - }).Info("finished initializing in-memory store and applying DB data migrations") + }).Info("finished initializing in-memory store") } return feewindows, eventStore diff --git a/cmd/soroban-rpc/internal/db/ledger.go b/cmd/soroban-rpc/internal/db/ledger.go index 39e43b83..7c547693 100644 --- a/cmd/soroban-rpc/internal/db/ledger.go +++ b/cmd/soroban-rpc/internal/db/ledger.go @@ -5,7 +5,6 @@ import ( "fmt" sq "github.com/Masterminds/squirrel" - "github.com/stellar/go/xdr" "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/ledgerbucketwindow" diff --git a/cmd/soroban-rpc/internal/db/migration.go b/cmd/soroban-rpc/internal/db/migration.go index e3df2070..dbe07ab5 100644 --- a/cmd/soroban-rpc/internal/db/migration.go +++ b/cmd/soroban-rpc/internal/db/migration.go @@ -115,13 +115,9 @@ type guardedMigration struct { db *DB migration MigrationApplier alreadyMigrated bool - logger *log.Entry - applyLogged bool } -func newGuardedDataMigration( - ctx context.Context, uniqueMigrationName string, logger *log.Entry, factory migrationApplierFactory, db *DB, -) (Migration, error) { +func newGuardedDataMigration(ctx context.Context, uniqueMigrationName string, factory migrationApplierFactory, db *DB) (Migration, error) { migrationDB := &DB{ cache: db.cache, SessionInterface: db.SessionInterface.Clone(), @@ -136,7 +132,7 @@ func newGuardedDataMigration( return nil, err } latestLedger, err := NewLedgerEntryReader(db).GetLatestLedgerSequence(ctx) - if errors.Is(err, ErrEmptyDB) { + if err != nil && err != ErrEmptyDB { err = errors.Join(err, migrationDB.Rollback()) return nil, fmt.Errorf("failed to get latest ledger sequence: %w", err) } @@ -150,7 +146,6 @@ func newGuardedDataMigration( db: migrationDB, migration: applier, alreadyMigrated: previouslyMigrated, - logger: logger, } return guardedMigration, nil } @@ -161,10 +156,6 @@ func (g *guardedMigration) Apply(ctx context.Context, meta xdr.LedgerCloseMeta) // but, just in case. return nil } - if !g.applyLogged { - g.logger.WithField("ledger", meta.LedgerSequence()).Info("applying migration") - g.applyLogged = true - } return g.migration.Apply(ctx, meta) } @@ -186,20 +177,19 @@ func (g *guardedMigration) Commit(ctx context.Context) error { return g.db.Commit() } -func (g *guardedMigration) Rollback(_ context.Context) error { +func (g *guardedMigration) Rollback(ctx context.Context) error { return g.db.Rollback() } func BuildMigrations(ctx context.Context, logger *log.Entry, db *DB, cfg *config.Config) (Migration, error) { migrationName := "TransactionsTable" - logger = logger.WithField("migration", migrationName) factory := newTransactionTableMigration( ctx, - logger, + logger.WithField("migration", migrationName), cfg.HistoryRetentionWindow, cfg.NetworkPassphrase, ) - m, err := newGuardedDataMigration(ctx, migrationName, logger, factory, db) + m, err := newGuardedDataMigration(ctx, migrationName, factory, db) if err != nil { return nil, fmt.Errorf("creating guarded transaction migration: %w", err) } diff --git a/cmd/soroban-rpc/internal/db/transaction.go b/cmd/soroban-rpc/internal/db/transaction.go index 8bccc58e..0a7c85a9 100644 --- a/cmd/soroban-rpc/internal/db/transaction.go +++ b/cmd/soroban-rpc/internal/db/transaction.go @@ -111,7 +111,7 @@ func (txn *transactionHandler) InsertTransactions(lcm xdr.LedgerCloseMeta) error _, err = query.RunWith(txn.stmtCache).Exec() L.WithField("duration", time.Since(start)). - Debugf("Ingested %d transaction lookups", len(transactions)) + Infof("Ingested %d transaction lookups", len(transactions)) return err }