2021-12-02 22:26:45 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
2021-10-11 15:40:38 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-12-02 22:26:45 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-10-11 15:40:38 +08:00
|
|
|
//
|
2021-12-02 22:26:45 +08:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2021-10-11 15:40:38 +08:00
|
|
|
|
|
|
|
package querynode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
2021-12-24 18:08:39 +08:00
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2021-11-06 16:54:59 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
2021-10-11 15:40:38 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
|
|
|
)
|
|
|
|
|
2021-12-25 23:16:40 +08:00
|
|
|
// globalSealedSegmentManager manages the globalSealedSegments
|
2021-10-11 15:40:38 +08:00
|
|
|
type globalSealedSegmentManager struct {
|
|
|
|
collectionID UniqueID
|
|
|
|
mu sync.Mutex // guards globalSealedSegments
|
|
|
|
globalSealedSegments map[UniqueID]*querypb.SegmentInfo // map[segmentID]SegmentInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
func newGlobalSealedSegmentManager(collectionID UniqueID) *globalSealedSegmentManager {
|
|
|
|
return &globalSealedSegmentManager{
|
|
|
|
collectionID: collectionID,
|
|
|
|
globalSealedSegments: make(map[UniqueID]*querypb.SegmentInfo),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-17 12:13:10 +08:00
|
|
|
func (g *globalSealedSegmentManager) addGlobalSegmentInfo(segmentInfo *querypb.SegmentInfo) {
|
2021-10-11 15:40:38 +08:00
|
|
|
g.mu.Lock()
|
|
|
|
defer g.mu.Unlock()
|
|
|
|
if segmentInfo.CollectionID != g.collectionID {
|
2021-11-17 12:13:10 +08:00
|
|
|
log.Warn("Find mismatch collectionID when addGlobalSegmentInfo",
|
2021-11-06 16:54:59 +08:00
|
|
|
zap.Any("manager collectionID", g.collectionID),
|
|
|
|
zap.Any("segmentInfo collectionID", segmentInfo.CollectionID),
|
|
|
|
)
|
2021-10-11 15:40:38 +08:00
|
|
|
}
|
|
|
|
g.globalSealedSegments[segmentInfo.SegmentID] = segmentInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *globalSealedSegmentManager) getGlobalSegmentIDs() []UniqueID {
|
|
|
|
g.mu.Lock()
|
|
|
|
defer g.mu.Unlock()
|
|
|
|
resIDs := make([]UniqueID, 0)
|
|
|
|
for _, v := range g.globalSealedSegments {
|
|
|
|
resIDs = append(resIDs, v.SegmentID)
|
|
|
|
}
|
|
|
|
return resIDs
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *globalSealedSegmentManager) getGlobalSegmentIDsByPartitionIds(partitionIDs []UniqueID) []UniqueID {
|
|
|
|
g.mu.Lock()
|
|
|
|
defer g.mu.Unlock()
|
|
|
|
resIDs := make([]UniqueID, 0)
|
|
|
|
for _, v := range g.globalSealedSegments {
|
|
|
|
for _, partitionID := range partitionIDs {
|
|
|
|
if v.PartitionID == partitionID {
|
|
|
|
resIDs = append(resIDs, v.SegmentID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return resIDs
|
|
|
|
}
|
|
|
|
|
2021-11-17 12:13:10 +08:00
|
|
|
func (g *globalSealedSegmentManager) hasGlobalSealedSegment(segmentID UniqueID) bool {
|
2021-10-20 17:54:43 +08:00
|
|
|
g.mu.Lock()
|
|
|
|
defer g.mu.Unlock()
|
|
|
|
_, ok := g.globalSealedSegments[segmentID]
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2021-11-17 12:13:10 +08:00
|
|
|
func (g *globalSealedSegmentManager) removeGlobalSealedSegmentInfo(segmentID UniqueID) {
|
2021-10-11 15:40:38 +08:00
|
|
|
g.mu.Lock()
|
|
|
|
defer g.mu.Unlock()
|
|
|
|
delete(g.globalSealedSegments, segmentID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *globalSealedSegmentManager) removeGlobalSegmentIDsByPartitionIds(partitionIDs []UniqueID) {
|
|
|
|
g.mu.Lock()
|
|
|
|
defer g.mu.Unlock()
|
|
|
|
for _, v := range g.globalSealedSegments {
|
|
|
|
for _, partitionID := range partitionIDs {
|
|
|
|
if v.PartitionID == partitionID {
|
|
|
|
delete(g.globalSealedSegments, v.SegmentID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *globalSealedSegmentManager) close() {
|
|
|
|
g.mu.Lock()
|
|
|
|
defer g.mu.Unlock()
|
|
|
|
g.globalSealedSegments = make(map[UniqueID]*querypb.SegmentInfo)
|
|
|
|
}
|