-
Notifications
You must be signed in to change notification settings - Fork 1
/
fs_mgr.go
57 lines (43 loc) · 984 Bytes
/
fs_mgr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package storage
import (
"sync"
"github.com/m3db/m3/src/x/clock"
"go.uber.org/zap"
)
type databaseFileSystemManager interface {
// Run attempts to flush the database if deemed necessary.
Run() bool
}
type runStatus int
// nolint:deadcode,megacheck,varcheck
const (
runNotStarted runStatus = iota
runInProgress
)
type fileSystemManager struct {
sync.Mutex
database database
opts *Options
logger *zap.SugaredLogger
nowFn clock.NowFn
status runStatus
}
func newFileSystemManager(database database, opts *Options) *fileSystemManager {
return &fileSystemManager{
database: database,
opts: opts,
logger: opts.InstrumentOptions().Logger().Sugar(),
nowFn: opts.ClockOptions().NowFn(),
}
}
func (mgr *fileSystemManager) Run() bool {
mgr.Lock()
defer mgr.Unlock()
if mgr.status == runInProgress {
return false
}
mgr.status = runInProgress
// TODO(xichen): Add background compaction here.
mgr.status = runNotStarted
return true
}