[#1523] writecache: Simplify logic
1. Remove in-memory cache. It doesn't persist objects and if we want more speed, `NoSync` option can be used for the bolt DB. 2. Put to the metabase in a synchronous fashion. This considerably simplifies overall logic and plays nicely with the metabase bolt DB batch settings. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
4176b2a1bc
commit
ddaed283e9
9 changed files with 140 additions and 328 deletions
|
@ -23,13 +23,6 @@ func (c *cache) SetMode(m mode.Mode) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
if !c.readOnly() {
|
||||
// Because modeMtx is taken no new objects will arrive an all other modifying
|
||||
// operations are completed.
|
||||
// 1. Persist objects already in memory on disk.
|
||||
c.persistMemoryCache()
|
||||
}
|
||||
|
||||
if c.db != nil {
|
||||
if err := c.db.Close(); err != nil {
|
||||
return fmt.Errorf("can't close write-cache database: %w", err)
|
||||
|
@ -37,13 +30,10 @@ func (c *cache) SetMode(m mode.Mode) error {
|
|||
c.db = nil
|
||||
}
|
||||
|
||||
// 2. Suspend producers to ensure there are channel send operations in fly.
|
||||
// metaCh and directCh can be populated either during Put or in background memory persist thread.
|
||||
// Former possibility is eliminated by taking `modeMtx` mutex and
|
||||
// latter by explicit persist in the previous step.
|
||||
// flushCh is populated by `flush` with `modeMtx` is also taken.
|
||||
// Thus all producers are shutdown and we only need to wait until all channels are empty.
|
||||
for len(c.metaCh) != 0 || len(c.directCh) != 0 || len(c.flushCh) != 0 {
|
||||
// Suspend producers to ensure there are channel send operations in fly.
|
||||
// flushCh is populated by `flush` with `modeMtx` taken, thus waiting until it is empty
|
||||
// guarantees that there are no in-fly operations.
|
||||
for len(c.flushCh) != 0 {
|
||||
c.log.Info("waiting for channels to flush")
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue