package writecachebitcask import ( "errors" "fmt" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" ) // SetLogger sets logger. It is used after the shard ID was generated to use it in logs. func (c *cache) SetLogger(l *logger.Logger) { c.log = l } func (c *cache) DumpInfo() writecache.Info { return writecache.Info{ Path: c.path, } } func (c *cache) Open(readOnly bool) error { // Validate if c.bucketCount&(c.bucketCount-1) != 0 { return fmt.Errorf("numBuckets must be a power of 2: got %d", c.bucketCount) } if c.regionCount&(c.regionCount-1) != 0 { return fmt.Errorf("numRegions must be a power of 2: got %d", c.regionCount) } if c.regionCount >= c.bucketCount { return errors.New("numBuckets must be greater than numRegions") } // Create regions c.regions = make([]*region, c.regionCount) for i := 0; i < c.regionCount; i++ { c.regions[i] = ®ion{ opts: &c.options, index: i, keyDir: make([][]*entry, c.bucketCount/c.regionCount), flushCh: make(chan uint32, c.maxPendingLogFileFlush), } } if readOnly { _ = c.SetMode(mode.ReadOnly) } else { _ = c.SetMode(mode.ReadWrite) } return nil } func (c *cache) Init() error { for _, r := range c.regions { go r.flushWorker() if err := r.init(); err != nil { r.close() return err } } return nil } func (c *cache) Close() error { var lastErr error if !c.closed.Swap(true) { for _, r := range c.regions { if err := r.close(); err != nil { lastErr = err } } } return lastErr } func (c *cache) SetMode(m mode.Mode) error { c.mode.Store(uint32(m)) return nil }