[skip ci]Add global id comment (#8966)

Signed-off-by: godchen <qingxiang.chen@zilliz.com>
pull/9011/head
godchen 2021-10-01 10:24:31 +08:00 committed by GitHub
parent 9f21ce6a45
commit b03d534cdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -17,6 +17,10 @@ import (
"github.com/milvus-io/milvus/internal/util/typeutil"
)
// GIDAllocator is interface for GlobalIDAllocator.
// Alloc allocates the id of the count number.
// AllocOne allocates one id.
// UpdateID update timestamp of allocator.
type GIDAllocator interface {
Alloc(count uint32) (UniqueID, UniqueID, error)
AllocOne() (UniqueID, error)
@ -28,6 +32,7 @@ type GlobalIDAllocator struct {
allocator tso.Allocator
}
// NewGlobalIDAllocator creates GlobalIDAllocator for allocates ID.
func NewGlobalIDAllocator(key string, base kv.TxnKV) *GlobalIDAllocator {
allocator := tso.NewGlobalTSOAllocator(key, base)
allocator.SetLimitMaxLogic(false)
@ -53,6 +58,7 @@ func (gia *GlobalIDAllocator) Alloc(count uint32) (typeutil.UniqueID, typeutil.U
return idStart, idEnd, nil
}
// AllocOne allocates one id.
func (gia *GlobalIDAllocator) AllocOne() (typeutil.UniqueID, error) {
timestamp, err := gia.allocator.GenerateTSO(1)
if err != nil {
@ -62,6 +68,7 @@ func (gia *GlobalIDAllocator) AllocOne() (typeutil.UniqueID, error) {
return idStart, nil
}
// UpdateID update timestamp of allocator.
func (gia *GlobalIDAllocator) UpdateID() error {
return gia.allocator.UpdateTSO()
}