milvus/internal/datanode/cache.go
XuanYang-cn dea0a4e522 Idempotent of FlushSegment (#5746)
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
2021-06-15 16:36:36 +08:00

35 lines
476 B
Go

package datanode
import (
"sync"
)
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()
if _, ok := c.cacheMap[key]; !ok {
return false
}
return true
}
func (c *Cache) Cache(segID UniqueID) {
c.cacheMu.Lock()
defer c.cacheMu.Unlock()
c.cacheMap[segID] = true
}