Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions cmd/stellar-rpc/internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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))
Expand All @@ -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
}
Expand All @@ -99,9 +96,7 @@ func OpenSQLiteDB(dbFilePath string) (*DB, error) {
}
result := DB{
SessionInterface: session,
cache: &dbCache{
ledgerEntries: newTransactionalCache(),
},
cache: &dbCache{},
}
return &result, nil
}
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion cmd/stellar-rpc/internal/ingest/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}).
Expand Down
Loading