mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-01 03:18:29 +08:00
376d39fa02
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
45 lines
866 B
Go
45 lines
866 B
Go
package datanode
|
|
|
|
import (
|
|
"sync"
|
|
)
|
|
|
|
// Cache stores flusing segments' ids to prevent flushing the same segment again and again.
|
|
// Once the segment is flushed, its id will be removed from the cache.
|
|
type Cache struct {
|
|
cacheMu sync.RWMutex
|
|
cacheMap map[UniqueID]bool
|
|
}
|
|
|
|
func newCache() *Cache {
|
|
return &Cache{
|
|
cacheMap: make(map[UniqueID]bool),
|
|
}
|
|
}
|
|
|
|
func (c *Cache) checkIfCached(key UniqueID) bool {
|
|
c.cacheMu.Lock()
|
|
defer c.cacheMu.Unlock()
|
|
|
|
_, ok := c.cacheMap[key]
|
|
return ok
|
|
}
|
|
|
|
// Cache caches a specific segment ID into the cache
|
|
func (c *Cache) Cache(segID UniqueID) {
|
|
c.cacheMu.Lock()
|
|
defer c.cacheMu.Unlock()
|
|
|
|
c.cacheMap[segID] = true
|
|
}
|
|
|
|
// Remove removes a set of segment IDs from the cache
|
|
func (c *Cache) Remove(segIDs ...UniqueID) {
|
|
c.cacheMu.Lock()
|
|
defer c.cacheMu.Unlock()
|
|
|
|
for _, id := range segIDs {
|
|
delete(c.cacheMap, id)
|
|
}
|
|
}
|