From 376d39fa02244ef53a7d35e62d4dbc6291e1b50f Mon Sep 17 00:00:00 2001 From: XuanYang-cn Date: Wed, 15 Sep 2021 10:33:37 +0800 Subject: [PATCH] [skip-ci]Add comment for Cache and allocator (#7924) Signed-off-by: yangxuan --- internal/datanode/allocator.go | 1 + internal/datanode/cache.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/internal/datanode/allocator.go b/internal/datanode/allocator.go index 0339be2e85..4db8f53d89 100644 --- a/internal/datanode/allocator.go +++ b/internal/datanode/allocator.go @@ -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{ diff --git a/internal/datanode/cache.go b/internal/datanode/cache.go index c8dfd18fa7..eea6a223e0 100644 --- a/internal/datanode/cache.go +++ b/internal/datanode/cache.go @@ -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()