Compare commits
3 Commits
422-fix-li
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 934e65a4e6 | |||
|
|
5be467a478 | ||
|
|
5e1c112468 |
36
db.go
36
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
|
||||
@@ -1305,7 +1339,7 @@ func (db *DB) Checkpoint(ctx context.Context, mode string) (err error) {
|
||||
return db.checkpoint(ctx, generation, mode)
|
||||
}
|
||||
|
||||
// checkpointAndInit performs a checkpoint on the WAL file and initializes a
|
||||
// checkpoint performs a checkpoint on the WAL file and initializes a
|
||||
// new shadow WAL file.
|
||||
func (db *DB) checkpoint(ctx context.Context, generation, mode string) error {
|
||||
// Try getting a checkpoint lock, will fail during snapshots.
|
||||
|
||||
@@ -136,12 +136,12 @@ func (c *ReplicaClient) findBucketRegion(ctx context.Context, bucket string) (st
|
||||
|
||||
// Fetch bucket location, if possible. Must be bucket owner.
|
||||
// This call can return a nil location which means it's in us-east-1.
|
||||
if out, err := s3.New(sess).GetBucketLocation(&s3.GetBucketLocationInput{
|
||||
if out, err := s3.New(sess).HeadBucketWithContext(ctx, &s3.HeadBucketInput{
|
||||
Bucket: aws.String(bucket),
|
||||
}); err != nil {
|
||||
return "", err
|
||||
} else if out.LocationConstraint != nil {
|
||||
return *out.LocationConstraint, nil
|
||||
} else if out.BucketRegion != nil {
|
||||
return *out.BucketRegion, nil
|
||||
}
|
||||
return DefaultRegion, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user