From 934e65a4e602035a82d95471c3a6f27db9bd0a2e Mon Sep 17 00:00:00 2001 From: Dean Roker Date: Sat, 12 Oct 2024 11:18:04 +0100 Subject: [PATCH] moved metapath --- db.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/db.go b/db.go index 85256a2..94d55dd 100644 --- a/db.go +++ b/db.go @@ -145,6 +145,40 @@ func NewDB(path string) *DB { return db } +// NewDB returns a new instance of DB for a given path. +func NewLSDB(path string, metapath string) *DB { + _, file := filepath.Split(path) + + db := &DB{ + path: path, + metaPath: filepath.Join(metapath, "."+file+MetaDirSuffix), + notify: make(chan struct{}), + + MinCheckpointPageN: DefaultMinCheckpointPageN, + MaxCheckpointPageN: DefaultMaxCheckpointPageN, + TruncatePageN: DefaultTruncatePageN, + CheckpointInterval: DefaultCheckpointInterval, + MonitorInterval: DefaultMonitorInterval, + Logger: slog.With("db", path), + } + + db.dbSizeGauge = dbSizeGaugeVec.WithLabelValues(db.path) + db.walSizeGauge = walSizeGaugeVec.WithLabelValues(db.path) + db.totalWALBytesCounter = totalWALBytesCounterVec.WithLabelValues(db.path) + db.shadowWALIndexGauge = shadowWALIndexGaugeVec.WithLabelValues(db.path) + db.shadowWALSizeGauge = shadowWALSizeGaugeVec.WithLabelValues(db.path) + db.syncNCounter = syncNCounterVec.WithLabelValues(db.path) + db.syncErrorNCounter = syncErrorNCounterVec.WithLabelValues(db.path) + db.syncSecondsCounter = syncSecondsCounterVec.WithLabelValues(db.path) + db.checkpointNCounterVec = checkpointNCounterVec.MustCurryWith(prometheus.Labels{"db": db.path}) + db.checkpointErrorNCounterVec = checkpointErrorNCounterVec.MustCurryWith(prometheus.Labels{"db": db.path}) + db.checkpointSecondsCounterVec = checkpointSecondsCounterVec.MustCurryWith(prometheus.Labels{"db": db.path}) + + db.ctx, db.cancel = context.WithCancel(context.Background()) + + return db +} + // SQLDB returns a reference to the underlying sql.DB connection. func (db *DB) SQLDB() *sql.DB { return db.db