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()