Fix lastVersion not expire when there is only loadSegmentsTask (#20156)

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
pull/20153/head
congqixia 2022-10-28 13:05:31 +08:00 committed by GitHub
parent 121cf7fc7b
commit 6224b3c44c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 2 deletions

View File

@ -17,6 +17,8 @@
package querynode
import (
"fmt"
"strings"
"sync"
"go.uber.org/atomic"
@ -29,6 +31,20 @@ import (
// Provides some helper function to get segment allocation.
type SegmentsStatus map[int64]shardSegmentInfo
// String implements Stringer for log.
func (s SegmentsStatus) String() string {
// get nodeID => []segmentID
allocation := s.GetAllocations(nil)
var builder strings.Builder
builder.WriteRune('{')
for nodeID, segmentIDs := range allocation {
builder.WriteString(fmt.Sprintf("Node %d: %v ", nodeID, segmentIDs))
}
builder.WriteRune('}')
return builder.String()
}
// GetAllocations returns node to segments mappings.
func (s SegmentsStatus) GetAllocations(partitionIDs []int64) map[int64][]int64 {
result := make(map[int64][]int64) // nodeID => segmentIDs
@ -72,8 +88,14 @@ type ShardClusterVersion struct {
// NewShardClusterVersion creates a version with id and allocation.
func NewShardClusterVersion(vID int64, status SegmentsStatus, lastVersion *ShardClusterVersion) *ShardClusterVersion {
log.Info("Update shard cluster version", zap.Int64("newVersionID", vID),
zap.Any("newAllocation", status))
log.Info("Update shard cluster version",
zap.Int64("newVersionID", vID),
zap.String("newAllocation", status.String()),
)
if lastVersion != nil {
// ignore the expiration channel here
_ = lastVersion.Expire()
}
return &ShardClusterVersion{
versionID: vID,
segments: status,