server+htlcswitch: auto compact sphinx DB too

This commit is contained in:
Oliver Gugger
2020-11-09 10:21:30 +01:00
parent a8ef4fc158
commit 32ee527f6b
3 changed files with 37 additions and 30 deletions

View File

@@ -51,7 +51,7 @@ type DecayedLog struct {
started int32 // To be used atomically.
stopped int32 // To be used atomically.
dbPath string
cfg *kvdb.BoltBackendConfig
db kvdb.Backend
@@ -64,16 +64,24 @@ type DecayedLog struct {
// NewDecayedLog creates a new DecayedLog, which caches recently seen hash
// shared secrets. Entries are evicted as their cltv expires using block epochs
// from the given notifier.
func NewDecayedLog(dbPath string,
func NewDecayedLog(dbPath, dbFileName string, boltCfg *kvdb.BoltConfig,
notifier chainntnfs.ChainNotifier) *DecayedLog {
cfg := &kvdb.BoltBackendConfig{
DBPath: dbPath,
DBFileName: dbFileName,
NoFreelistSync: true,
AutoCompact: boltCfg.AutoCompact,
AutoCompactMinAge: boltCfg.AutoCompactMinAge,
}
// Use default path for log database
if dbPath == "" {
dbPath = defaultDbDirectory
cfg.DBPath = defaultDbDirectory
}
return &DecayedLog{
dbPath: dbPath,
cfg: cfg,
notifier: notifier,
quit: make(chan struct{}),
}
@@ -89,9 +97,7 @@ func (d *DecayedLog) Start() error {
// Open the boltdb for use.
var err error
d.db, err = kvdb.Create(
kvdb.BoltBackendName, d.dbPath, true,
)
d.db, err = kvdb.GetBoltBackend(d.cfg)
if err != nil {
return fmt.Errorf("could not open boltdb: %v", err)
}