[skip-ci]Add comment for Cache and allocator (#7924)

Signed-off-by: yangxuan <xuan.yang@zilliz.com>
pull/7939/head
XuanYang-cn 2021-09-15 10:33:37 +08:00 committed by GitHub
parent cf1d773259
commit 376d39fa02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View File

@ -40,6 +40,7 @@ func newAllocator(s types.RootCoord) *allocator {
}
}
// allocID allocat one ID from rootCoord
func (alloc *allocator) allocID() (UniqueID, error) {
ctx := context.TODO()
resp, err := alloc.rootCoord.AllocID(ctx, &rootcoordpb.AllocIDRequest{

View File

@ -4,6 +4,8 @@ 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
@ -23,6 +25,7 @@ func (c *Cache) checkIfCached(key UniqueID) bool {
return ok
}
// Cache caches a specific segment ID into the cache
func (c *Cache) Cache(segID UniqueID) {
c.cacheMu.Lock()
defer c.cacheMu.Unlock()
@ -30,6 +33,7 @@ func (c *Cache) Cache(segID UniqueID) {
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()