mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-08 01:58:34 +08:00
Fix version not deleted if expired by loadSegment (#20361)
Signed-off-by: Congqi Xia <congqi.xia@zilliz.com> Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
parent
d7ebb25701
commit
6e4509d0fc
@ -151,7 +151,6 @@ type ShardCluster struct {
|
|||||||
currentVersion *ShardClusterVersion // current serving segment state version
|
currentVersion *ShardClusterVersion // current serving segment state version
|
||||||
nextVersionID *atomic.Int64
|
nextVersionID *atomic.Int64
|
||||||
segmentCond *sync.Cond // segment state change condition
|
segmentCond *sync.Cond // segment state change condition
|
||||||
rcCond *sync.Cond // segment rc change condition
|
|
||||||
|
|
||||||
closeOnce sync.Once
|
closeOnce sync.Once
|
||||||
closeCh chan struct{}
|
closeCh chan struct{}
|
||||||
@ -180,8 +179,6 @@ func NewShardCluster(collectionID int64, replicaID int64, vchannelName string,
|
|||||||
|
|
||||||
m := sync.Mutex{}
|
m := sync.Mutex{}
|
||||||
sc.segmentCond = sync.NewCond(&m)
|
sc.segmentCond = sync.NewCond(&m)
|
||||||
m2 := sync.Mutex{}
|
|
||||||
sc.rcCond = sync.NewCond(&m2)
|
|
||||||
|
|
||||||
sc.init()
|
sc.init()
|
||||||
|
|
||||||
@ -610,17 +607,16 @@ func (sc *ShardCluster) segmentAllocations(partitionIDs []int64) (map[int64][]in
|
|||||||
|
|
||||||
// finishUsage decreases the inUse count of provided segments
|
// finishUsage decreases the inUse count of provided segments
|
||||||
func (sc *ShardCluster) finishUsage(versionID int64) {
|
func (sc *ShardCluster) finishUsage(versionID int64) {
|
||||||
defer func() {
|
|
||||||
sc.rcCond.L.Lock()
|
|
||||||
sc.rcCond.Broadcast()
|
|
||||||
sc.rcCond.L.Unlock()
|
|
||||||
}()
|
|
||||||
|
|
||||||
v, ok := sc.versions.Load(versionID)
|
v, ok := sc.versions.Load(versionID)
|
||||||
if ok {
|
if !ok {
|
||||||
version := v.(*ShardClusterVersion)
|
return
|
||||||
version.FinishUsage()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
version := v.(*ShardClusterVersion)
|
||||||
|
version.FinishUsage()
|
||||||
|
|
||||||
|
// cleanup version if expired
|
||||||
|
sc.cleanupVersion(version)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadSegments loads segments with shardCluster.
|
// LoadSegments loads segments with shardCluster.
|
||||||
@ -680,9 +676,11 @@ func (sc *ShardCluster) LoadSegments(ctx context.Context, req *querypb.LoadSegme
|
|||||||
allocations[info.SegmentID] = shardSegmentInfo{nodeID: req.DstNodeID, segmentID: info.SegmentID, partitionID: info.PartitionID, state: segmentStateLoaded}
|
allocations[info.SegmentID] = shardSegmentInfo{nodeID: req.DstNodeID, segmentID: info.SegmentID, partitionID: info.PartitionID, state: segmentStateLoaded}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastVersion := sc.currentVersion
|
||||||
version := NewShardClusterVersion(sc.nextVersionID.Inc(), allocations, sc.currentVersion)
|
version := NewShardClusterVersion(sc.nextVersionID.Inc(), allocations, sc.currentVersion)
|
||||||
sc.versions.Store(version.versionID, version)
|
sc.versions.Store(version.versionID, version)
|
||||||
sc.currentVersion = version
|
sc.currentVersion = version
|
||||||
|
sc.cleanupVersion(lastVersion)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -703,7 +701,7 @@ func (sc *ShardCluster) ReleaseSegments(ctx context.Context, req *querypb.Releas
|
|||||||
offlineSegments.Insert(req.GetSegmentIDs()...)
|
offlineSegments.Insert(req.GetSegmentIDs()...)
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastVersionID int64
|
var lastVersion *ShardClusterVersion
|
||||||
var err error
|
var err error
|
||||||
func() {
|
func() {
|
||||||
sc.mutVersion.Lock()
|
sc.mutVersion.Lock()
|
||||||
@ -729,7 +727,7 @@ func (sc *ShardCluster) ReleaseSegments(ctx context.Context, req *querypb.Releas
|
|||||||
if sc.currentVersion != nil {
|
if sc.currentVersion != nil {
|
||||||
// wait for last version search done
|
// wait for last version search done
|
||||||
<-sc.currentVersion.Expire()
|
<-sc.currentVersion.Expire()
|
||||||
lastVersionID = sc.currentVersion.versionID
|
lastVersion = sc.currentVersion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -762,7 +760,7 @@ func (sc *ShardCluster) ReleaseSegments(ctx context.Context, req *querypb.Releas
|
|||||||
err = fmt.Errorf("follower %d failed to release segment, reason %s", req.NodeID, resp.GetReason())
|
err = fmt.Errorf("follower %d failed to release segment, reason %s", req.NodeID, resp.GetReason())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
sc.cleanupVersion(lastVersionID)
|
sc.cleanupVersion(lastVersion)
|
||||||
|
|
||||||
sc.mut.Lock()
|
sc.mut.Lock()
|
||||||
// do not delete segment if data scope is streaming
|
// do not delete segment if data scope is streaming
|
||||||
@ -784,14 +782,18 @@ func (sc *ShardCluster) ReleaseSegments(ctx context.Context, req *querypb.Releas
|
|||||||
}
|
}
|
||||||
|
|
||||||
// cleanupVersion clean up version from map
|
// cleanupVersion clean up version from map
|
||||||
func (sc *ShardCluster) cleanupVersion(versionID int64) {
|
func (sc *ShardCluster) cleanupVersion(version *ShardClusterVersion) {
|
||||||
sc.mutVersion.RLock()
|
// last version nil, just return
|
||||||
defer sc.mutVersion.RUnlock()
|
if version == nil {
|
||||||
// prevent clean up current version
|
|
||||||
if sc.currentVersion != nil && sc.currentVersion.versionID == versionID {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sc.versions.Delete(versionID)
|
|
||||||
|
// if version is still current one or still in use, return
|
||||||
|
if version.current.Load() || version.inUse.Load() > 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
sc.versions.Delete(version.versionID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// waitSegmentsOnline waits until all provided segments is loaded.
|
// waitSegmentsOnline waits until all provided segments is loaded.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user