|
@@ -39,6 +39,9 @@ type store struct {
|
|
|
|
|
|
|
|
tmu sync.Mutex // protect the tnxID field
|
|
tmu sync.Mutex // protect the tnxID field
|
|
|
tnxID int64 // tracks the current tnxID to verify tnx operations
|
|
tnxID int64 // tracks the current tnxID to verify tnx operations
|
|
|
|
|
+
|
|
|
|
|
+ wg sync.WaitGroup
|
|
|
|
|
+ stopc chan struct{}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func newStore(path string) *store {
|
|
func newStore(path string) *store {
|
|
@@ -47,6 +50,7 @@ func newStore(path string) *store {
|
|
|
kvindex: newTreeIndex(),
|
|
kvindex: newTreeIndex(),
|
|
|
currentRev: reversion{},
|
|
currentRev: reversion{},
|
|
|
compactMainRev: -1,
|
|
compactMainRev: -1,
|
|
|
|
|
+ stopc: make(chan struct{}),
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
tx := s.b.BatchTx()
|
|
tx := s.b.BatchTx()
|
|
@@ -161,6 +165,7 @@ func (s *store) Compact(rev int64) error {
|
|
|
|
|
|
|
|
keep := s.kvindex.Compact(rev)
|
|
keep := s.kvindex.Compact(rev)
|
|
|
|
|
|
|
|
|
|
+ s.wg.Add(1)
|
|
|
go s.scheduleCompaction(rev, keep)
|
|
go s.scheduleCompaction(rev, keep)
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
@@ -226,6 +231,9 @@ func (s *store) Restore() error {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (s *store) Close() error {
|
|
func (s *store) Close() error {
|
|
|
|
|
+ close(s.stopc)
|
|
|
|
|
+ s.wg.Wait()
|
|
|
|
|
+ s.b.ForceCommit()
|
|
|
return s.b.Close()
|
|
return s.b.Close()
|
|
|
}
|
|
}
|
|
|
|
|
|