forked from TrueCloudLab/frostfs-node
[#5] writecache: Use generic LRU cache
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
8f61cc1dcc
commit
4155c1bdff
1 changed files with 8 additions and 8 deletions
|
@ -11,8 +11,8 @@ import (
|
||||||
"github.com/TrueCloudLab/frostfs-node/pkg/util"
|
"github.com/TrueCloudLab/frostfs-node/pkg/util"
|
||||||
apistatus "github.com/TrueCloudLab/frostfs-sdk-go/client/status"
|
apistatus "github.com/TrueCloudLab/frostfs-sdk-go/client/status"
|
||||||
oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id"
|
oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id"
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru/v2"
|
||||||
"github.com/hashicorp/golang-lru/simplelru"
|
"github.com/hashicorp/golang-lru/v2/simplelru"
|
||||||
"go.etcd.io/bbolt"
|
"go.etcd.io/bbolt"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
@ -23,7 +23,7 @@ type store struct {
|
||||||
maxFlushedMarksCount int
|
maxFlushedMarksCount int
|
||||||
maxRemoveBatchSize int
|
maxRemoveBatchSize int
|
||||||
|
|
||||||
flushed simplelru.LRUCache
|
flushed simplelru.LRUCache[string, bool]
|
||||||
db *bbolt.DB
|
db *bbolt.DB
|
||||||
|
|
||||||
dbKeysToRemove []string
|
dbKeysToRemove []string
|
||||||
|
@ -69,7 +69,7 @@ func (c *cache) openStore(readOnly bool) error {
|
||||||
// Write-cache can be opened multiple times during `SetMode`.
|
// Write-cache can be opened multiple times during `SetMode`.
|
||||||
// flushed map must not be re-created in this case.
|
// flushed map must not be re-created in this case.
|
||||||
if c.flushed == nil {
|
if c.flushed == nil {
|
||||||
c.flushed, _ = lru.NewWithEvict(c.maxFlushedMarksCount, c.removeFlushed)
|
c.flushed, _ = lru.NewWithEvict[string, bool](c.maxFlushedMarksCount, c.removeFlushed)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -78,12 +78,12 @@ func (c *cache) openStore(readOnly bool) error {
|
||||||
// To minimize interference with the client operations, the actual removal
|
// To minimize interference with the client operations, the actual removal
|
||||||
// is done in batches.
|
// is done in batches.
|
||||||
// It is not thread-safe and is used only as an evict callback to LRU cache.
|
// It is not thread-safe and is used only as an evict callback to LRU cache.
|
||||||
func (c *cache) removeFlushed(key, value interface{}) {
|
func (c *cache) removeFlushed(key string, value bool) {
|
||||||
fromDatabase := value.(bool)
|
fromDatabase := value
|
||||||
if fromDatabase {
|
if fromDatabase {
|
||||||
c.dbKeysToRemove = append(c.dbKeysToRemove, key.(string))
|
c.dbKeysToRemove = append(c.dbKeysToRemove, key)
|
||||||
} else {
|
} else {
|
||||||
c.fsKeysToRemove = append(c.fsKeysToRemove, key.(string))
|
c.fsKeysToRemove = append(c.fsKeysToRemove, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(c.dbKeysToRemove)+len(c.fsKeysToRemove) >= c.maxRemoveBatchSize {
|
if len(c.dbKeysToRemove)+len(c.fsKeysToRemove) >= c.maxRemoveBatchSize {
|
||||||
|
|
Loading…
Reference in a new issue