diff --git a/cmd/stellar-rpc/internal/db/db.go b/cmd/stellar-rpc/internal/db/db.go index fe5c24fc..c79455f5 100644 --- a/cmd/stellar-rpc/internal/db/db.go +++ b/cmd/stellar-rpc/internal/db/db.go @@ -49,7 +49,6 @@ type WriteTx interface { type dbCache struct { latestLedgerSeq uint32 latestLedgerCloseTime int64 - ledgerEntries transactionalCache // Just like the DB: compress-encoded ledger key -> ledger entry XDR sync.RWMutex } @@ -60,8 +59,8 @@ type DB struct { func openSQLiteDB(dbFilePath string) (*db.Session, error) { // 1. Use Write-Ahead Logging (WAL). - // 2. Disable WAL auto-checkpointing (we will do the checkpointing ourselves with wal_checkpoint pragmas - // after every write transaction). + // 2. Disable WAL auto-checkpointing (we will do the checkpointing ourselves + // with wal_checkpoint pragmas after every write transaction). // 3. Use synchronous=NORMAL, which is faster and still safe in WAL mode. session, err := db.Open("sqlite3", fmt.Sprintf("file:%s?_journal_mode=WAL&_wal_autocheckpoint=0&_synchronous=NORMAL", dbFilePath)) @@ -85,9 +84,7 @@ func OpenSQLiteDBWithPrometheusMetrics(dbFilePath string, namespace string, sub } result := DB{ SessionInterface: db.RegisterMetrics(session, namespace, sub, registry), - cache: &dbCache{ - ledgerEntries: newTransactionalCache(), - }, + cache: &dbCache{}, } return &result, nil } @@ -99,9 +96,7 @@ func OpenSQLiteDB(dbFilePath string) (*DB, error) { } result := DB{ SessionInterface: session, - cache: &dbCache{ - ledgerEntries: newTransactionalCache(), - }, + cache: &dbCache{}, } return &result, nil } @@ -241,13 +236,20 @@ func (rw *readWriter) NewTx(ctx context.Context) (WriteTx, error) { postCommit: func(durationMetrics map[string]time.Duration) error { // TODO: this is sqlite-only, it shouldn't be here startTime := time.Now() - _, err := db.ExecRaw(ctx, "PRAGMA wal_checkpoint(TRUNCATE)") - if err != nil { + if _, err := db.ExecRaw(ctx, "PRAGMA wal_checkpoint(TRUNCATE);"); err != nil { return err } if durationMetrics != nil { durationMetrics["wal_checkpoint"] = time.Since(startTime) } + + startTime = time.Now() + if _, err := db.ExecRaw(ctx, "PRAGMA optimize;"); err != nil { + return err + } + if durationMetrics != nil { + durationMetrics["db_optimize"] = time.Since(startTime) + } return nil }, tx: txSession, diff --git a/cmd/stellar-rpc/internal/ingest/service.go b/cmd/stellar-rpc/internal/ingest/service.go index 3963abfa..62e6492a 100644 --- a/cmd/stellar-rpc/internal/ingest/service.go +++ b/cmd/stellar-rpc/internal/ingest/service.go @@ -219,7 +219,7 @@ func (s *Service) ingest(ctx context.Context, sequence uint32) error { s.logger. WithField("duration", time.Since(startTime).Seconds()). - Debugf("Ingested ledger %d", sequence) + Infof("Ingested ledger %d", sequence) s.metrics.ingestionDurationMetric. With(prometheus.Labels{"type": "total"}).