Allow mmap to run during head compaction

Signed-off-by: alanprot <alanprot@gmail.com>
This commit is contained in:
alanprot 2024-08-06 21:34:14 -07:00
parent b09eaf8acd
commit e16b7b3449

View file

@ -1057,9 +1057,26 @@ func (db *DB) Dir() string {
func (db *DB) run(ctx context.Context) {
defer close(db.donec)
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
defer wg.Done()
for {
select {
case <-db.stopc:
return
case <-time.After(1 * time.Minute):
// We attempt mmapping of head chunks regularly.
db.head.mmapHeadChunks()
}
}
}()
wg.Add(1)
go func() {
defer wg.Done()
backoff := time.Duration(0)
for {
select {
case <-db.stopc:
@ -1079,8 +1096,6 @@ func (db *DB) run(ctx context.Context) {
case db.compactc <- struct{}{}:
default:
}
// We attempt mmapping of head chunks regularly.
db.head.mmapHeadChunks()
case <-db.compactc:
db.metrics.compactionsTriggered.Inc()
@ -1100,6 +1115,9 @@ func (db *DB) run(ctx context.Context) {
return
}
}
}()
wg.Wait()
}
// Appender opens a new appender against the database.