Skip to content

Commit

Permalink
Close Node/Segment detector when close ShardCluster (milvus-io#18476)
Browse files Browse the repository at this point in the history
Signed-off-by: Congqi Xia <[email protected]>
  • Loading branch information
congqixia authored Aug 1, 2022
1 parent 3871758 commit f0fe8da
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/querynode/shard_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,20 @@ type shardSegmentInfo struct {
inUse int32
}

// Closable interface for close.
type Closable interface {
Close()
}

// ShardNodeDetector provides method to detect node events
type ShardNodeDetector interface {
Closable
watchNodes(collectionID int64, replicaID int64, vchannelName string) ([]nodeEvent, <-chan nodeEvent)
}

// ShardSegmentDetector provides method to detect segment events
type ShardSegmentDetector interface {
Closable
watchSegments(collectionID int64, replicaID int64, vchannelName string) ([]segmentEvent, <-chan segmentEvent)
}

Expand Down Expand Up @@ -181,6 +188,13 @@ func (sc *ShardCluster) Close() {
log.Info("Close shard cluster")
sc.closeOnce.Do(func() {
sc.updateShardClusterState(unavailable)
if sc.nodeDetector != nil {
sc.nodeDetector.Close()
}
if sc.segmentDetector != nil {
sc.segmentDetector.Close()
}

close(sc.closeCh)
})
}
Expand Down
4 changes: 4 additions & 0 deletions internal/querynode/shard_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func (m *mockNodeDetector) watchNodes(collectionID int64, replicaID int64, vchan
return m.initNodes, m.evtCh
}

func (m *mockNodeDetector) Close() {}

type mockSegmentDetector struct {
initSegments []segmentEvent
evtCh chan segmentEvent
Expand All @@ -47,6 +49,8 @@ func (m *mockSegmentDetector) watchSegments(collectionID int64, replicaID int64,
return m.initSegments, m.evtCh
}

func (m *mockSegmentDetector) Close() {}

type mockShardQueryNode struct {
statisticResponse *internalpb.GetStatisticsResponse
statisticErr error
Expand Down

0 comments on commit f0fe8da

Please sign in to comment.