[#1825] writecache: Flush cache when moving to the DEGRADED mode

Degraded mode allows us to operate without an SSD,
thus writecache should be unavailable in this mode.

Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
Evgenii Stratonikov 2022-09-30 13:41:37 +03:00 committed by fyrchik
parent 236414df49
commit 8b3b16fe62
5 changed files with 50 additions and 11 deletions

View file

@ -18,9 +18,11 @@ func (c *cache) SetMode(m mode.Mode) error {
c.modeMtx.Lock()
defer c.modeMtx.Unlock()
if m.ReadOnly() == c.readOnly() {
c.mode = m
return nil
if m.NoMetabase() && !c.mode.NoMetabase() {
err := c.flush(true)
if err != nil {
return err
}
}
if c.db != nil {
@ -37,6 +39,11 @@ func (c *cache) SetMode(m mode.Mode) error {
time.Sleep(time.Second)
}
if m.NoMetabase() {
c.mode = m
return nil
}
if err := c.openStore(m.ReadOnly()); err != nil {
return err
}