2023-03-27 00:42:00 +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
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
package segments
|
|
|
|
|
|
|
|
/*
|
|
|
|
#cgo pkg-config: milvus_segcore
|
|
|
|
|
|
|
|
#include "segcore/collection_c.h"
|
|
|
|
#include "segcore/segment_c.h"
|
|
|
|
*/
|
|
|
|
import "C"
|
2023-04-06 19:14:32 +08:00
|
|
|
|
2023-03-27 00:42:00 +08:00
|
|
|
import (
|
2023-08-29 15:46:27 +08:00
|
|
|
"context"
|
2023-03-27 00:42:00 +08:00
|
|
|
"fmt"
|
|
|
|
"sync"
|
|
|
|
|
2023-09-21 09:45:27 +08:00
|
|
|
"go.uber.org/zap"
|
2024-02-27 20:58:40 +08:00
|
|
|
"golang.org/x/sync/singleflight"
|
2023-09-21 09:45:27 +08:00
|
|
|
|
2024-03-13 20:15:03 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
|
2023-11-07 01:44:18 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
2023-03-27 00:42:00 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
2024-04-10 10:55:17 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/querynodev2/segments/metricsutil"
|
2024-05-24 15:31:42 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/common"
|
2023-07-25 17:23:01 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/eventlog"
|
2023-08-11 11:21:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/log"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/metrics"
|
2024-02-27 20:58:40 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/cache"
|
2023-08-16 18:38:17 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/merr"
|
2024-05-07 19:13:35 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/metautil"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
2024-03-13 20:15:03 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/typeutil"
|
2023-03-27 00:42:00 +08:00
|
|
|
)
|
|
|
|
|
2024-05-07 19:13:35 +08:00
|
|
|
// TODO maybe move to manager and change segment constructor
|
|
|
|
var channelMapper = metautil.NewDynChannelMapper()
|
|
|
|
|
2024-03-13 20:15:03 +08:00
|
|
|
// SegmentFilter is the interface for segment selection criteria.
|
|
|
|
type SegmentFilter interface {
|
|
|
|
Filter(segment Segment) bool
|
|
|
|
SegmentType() (SegmentType, bool)
|
|
|
|
SegmentIDs() ([]int64, bool)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SegmentFilterFunc is a type wrapper for `func(Segment) bool` to SegmentFilter.
|
|
|
|
type SegmentFilterFunc func(segment Segment) bool
|
|
|
|
|
|
|
|
func (f SegmentFilterFunc) Filter(segment Segment) bool {
|
|
|
|
return f(segment)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f SegmentFilterFunc) SegmentType() (SegmentType, bool) {
|
|
|
|
return commonpb.SegmentState_SegmentStateNone, false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s SegmentFilterFunc) SegmentIDs() ([]int64, bool) {
|
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
|
|
|
|
// SegmentIDFilter is the specific segment filter for SegmentID only.
|
|
|
|
type SegmentIDFilter int64
|
|
|
|
|
|
|
|
func (f SegmentIDFilter) Filter(segment Segment) bool {
|
|
|
|
return segment.ID() == int64(f)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f SegmentIDFilter) SegmentType() (SegmentType, bool) {
|
|
|
|
return commonpb.SegmentState_SegmentStateNone, false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f SegmentIDFilter) SegmentIDs() ([]int64, bool) {
|
|
|
|
return []int64{int64(f)}, true
|
|
|
|
}
|
|
|
|
|
|
|
|
type SegmentTypeFilter SegmentType
|
|
|
|
|
|
|
|
func (f SegmentTypeFilter) Filter(segment Segment) bool {
|
|
|
|
return segment.Type() == SegmentType(f)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f SegmentTypeFilter) SegmentType() (SegmentType, bool) {
|
|
|
|
return SegmentType(f), true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f SegmentTypeFilter) SegmentIDs() ([]int64, bool) {
|
|
|
|
return nil, false
|
|
|
|
}
|
2023-03-27 00:42:00 +08:00
|
|
|
|
2023-10-15 16:10:04 +08:00
|
|
|
func WithSkipEmpty() SegmentFilter {
|
2024-03-13 20:15:03 +08:00
|
|
|
return SegmentFilterFunc(func(segment Segment) bool {
|
2023-10-15 16:10:04 +08:00
|
|
|
return segment.InsertCount() > 0
|
2024-03-13 20:15:03 +08:00
|
|
|
})
|
2023-10-15 16:10:04 +08:00
|
|
|
}
|
|
|
|
|
2024-03-13 20:15:03 +08:00
|
|
|
func WithPartition(partitionID typeutil.UniqueID) SegmentFilter {
|
|
|
|
return SegmentFilterFunc(func(segment Segment) bool {
|
2023-03-27 00:42:00 +08:00
|
|
|
return segment.Partition() == partitionID
|
2024-03-13 20:15:03 +08:00
|
|
|
})
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func WithChannel(channel string) SegmentFilter {
|
2024-05-07 19:13:35 +08:00
|
|
|
ac, err := metautil.ParseChannel(channel, channelMapper)
|
|
|
|
if err != nil {
|
|
|
|
return SegmentFilterFunc(func(segment Segment) bool {
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
}
|
2024-03-13 20:15:03 +08:00
|
|
|
return SegmentFilterFunc(func(segment Segment) bool {
|
2024-05-07 19:13:35 +08:00
|
|
|
return segment.Shard().Equal(ac)
|
2024-03-13 20:15:03 +08:00
|
|
|
})
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func WithType(typ SegmentType) SegmentFilter {
|
2024-03-13 20:15:03 +08:00
|
|
|
return SegmentTypeFilter(typ)
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func WithID(id int64) SegmentFilter {
|
2024-03-13 20:15:03 +08:00
|
|
|
return SegmentIDFilter(id)
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
|
2023-11-21 18:24:22 +08:00
|
|
|
func WithLevel(level datapb.SegmentLevel) SegmentFilter {
|
2024-03-13 20:15:03 +08:00
|
|
|
return SegmentFilterFunc(func(segment Segment) bool {
|
2023-11-21 18:24:22 +08:00
|
|
|
return segment.Level() == level
|
2024-03-13 20:15:03 +08:00
|
|
|
})
|
2023-11-21 18:24:22 +08:00
|
|
|
}
|
|
|
|
|
2023-08-29 15:46:27 +08:00
|
|
|
type SegmentAction func(segment Segment) bool
|
|
|
|
|
|
|
|
func IncreaseVersion(version int64) SegmentAction {
|
|
|
|
return func(segment Segment) bool {
|
|
|
|
log := log.Ctx(context.Background()).With(
|
|
|
|
zap.Int64("segmentID", segment.ID()),
|
|
|
|
zap.String("type", segment.Type().String()),
|
|
|
|
zap.Int64("segmentVersion", segment.Version()),
|
|
|
|
zap.Int64("updateVersion", version),
|
|
|
|
)
|
|
|
|
for oldVersion := segment.Version(); oldVersion < version; {
|
|
|
|
if segment.CASVersion(oldVersion, version) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Warn("segment version cannot go backwards, skip update")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-27 00:42:00 +08:00
|
|
|
type Manager struct {
|
|
|
|
Collection CollectionManager
|
|
|
|
Segment SegmentManager
|
2024-02-27 20:58:40 +08:00
|
|
|
DiskCache cache.Cache[int64, Segment]
|
2024-03-25 15:43:07 +08:00
|
|
|
Loader Loader
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewManager() *Manager {
|
2024-05-07 16:33:30 +08:00
|
|
|
diskCap := paramtable.Get().QueryNodeCfg.DiskCacheCapacityLimit.GetAsSize()
|
2024-02-27 20:58:40 +08:00
|
|
|
|
|
|
|
segMgr := NewSegmentManager()
|
|
|
|
sf := singleflight.Group{}
|
2024-03-13 10:49:04 +08:00
|
|
|
manager := &Manager{
|
2023-03-27 00:42:00 +08:00
|
|
|
Collection: NewCollectionManager(),
|
2024-02-27 20:58:40 +08:00
|
|
|
Segment: segMgr,
|
2024-03-13 10:49:04 +08:00
|
|
|
}
|
2024-02-27 20:58:40 +08:00
|
|
|
|
2024-03-21 18:57:07 +08:00
|
|
|
manager.DiskCache = cache.NewCacheBuilder[int64, Segment]().WithLazyScavenger(func(key int64) int64 {
|
2024-05-06 20:29:30 +08:00
|
|
|
segment := segMgr.GetWithType(key, SegmentTypeSealed)
|
|
|
|
if segment == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return int64(segment.ResourceUsageEstimate().DiskSize)
|
|
|
|
}, diskCap).WithLoader(func(ctx context.Context, key int64) (Segment, error) {
|
2024-06-10 21:34:08 +08:00
|
|
|
log := log.Ctx(ctx)
|
2024-03-21 14:33:06 +08:00
|
|
|
log.Debug("cache missed segment", zap.Int64("segmentID", key))
|
2024-05-06 20:29:30 +08:00
|
|
|
segment := segMgr.GetWithType(key, SegmentTypeSealed)
|
|
|
|
if segment == nil {
|
2024-03-21 14:33:06 +08:00
|
|
|
// the segment has been released, just ignore it
|
2024-05-06 20:29:30 +08:00
|
|
|
log.Warn("segment is not found when loading", zap.Int64("segmentID", key))
|
|
|
|
return nil, merr.ErrSegmentNotFound
|
2024-03-21 14:33:06 +08:00
|
|
|
}
|
|
|
|
info := segment.LoadInfo()
|
2024-04-10 10:55:17 +08:00
|
|
|
_, err, _ := sf.Do(fmt.Sprint(segment.ID()), func() (nop interface{}, err error) {
|
|
|
|
cacheLoadRecord := metricsutil.NewCacheLoadRecord(getSegmentMetricLabel(segment))
|
|
|
|
cacheLoadRecord.WithBytes(segment.ResourceUsageEstimate().DiskSize)
|
|
|
|
defer func() {
|
|
|
|
cacheLoadRecord.Finish(err)
|
|
|
|
}()
|
|
|
|
|
2024-03-21 14:33:06 +08:00
|
|
|
collection := manager.Collection.Get(segment.Collection())
|
|
|
|
if collection == nil {
|
|
|
|
return nil, merr.WrapErrCollectionNotLoaded(segment.Collection(), "failed to load segment fields")
|
2024-03-13 10:49:04 +08:00
|
|
|
}
|
2024-05-06 20:29:30 +08:00
|
|
|
|
2024-07-10 10:18:12 +08:00
|
|
|
err = manager.Loader.LoadLazySegment(ctx, segment, info)
|
2024-03-21 14:33:06 +08:00
|
|
|
return nil, err
|
2024-03-13 10:49:04 +08:00
|
|
|
})
|
2024-03-21 14:33:06 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Warn("cache sealed segment failed", zap.Error(err))
|
2024-05-06 20:29:30 +08:00
|
|
|
return nil, err
|
2024-03-21 14:33:06 +08:00
|
|
|
}
|
2024-05-06 20:29:30 +08:00
|
|
|
return segment, nil
|
|
|
|
}).WithFinalizer(func(ctx context.Context, key int64, segment Segment) error {
|
2024-06-10 21:34:08 +08:00
|
|
|
log := log.Ctx(ctx)
|
|
|
|
log.Debug("evict segment from cache", zap.Int64("segmentID", key))
|
2024-04-10 10:55:17 +08:00
|
|
|
cacheEvictRecord := metricsutil.NewCacheEvictRecord(getSegmentMetricLabel(segment))
|
|
|
|
cacheEvictRecord.WithBytes(segment.ResourceUsageEstimate().DiskSize)
|
|
|
|
defer cacheEvictRecord.Finish(nil)
|
2024-05-06 20:29:30 +08:00
|
|
|
segment.Release(ctx, WithReleaseScope(ReleaseScopeData))
|
2024-03-21 14:33:06 +08:00
|
|
|
return nil
|
2024-05-06 20:29:30 +08:00
|
|
|
}).WithReloader(func(ctx context.Context, key int64) (Segment, error) {
|
2024-06-10 21:34:08 +08:00
|
|
|
log := log.Ctx(ctx)
|
2024-05-06 20:29:30 +08:00
|
|
|
segment := segMgr.GetWithType(key, SegmentTypeSealed)
|
|
|
|
if segment == nil {
|
|
|
|
// the segment has been released, just ignore it
|
|
|
|
log.Debug("segment is not found when reloading", zap.Int64("segmentID", key))
|
|
|
|
return nil, merr.ErrSegmentNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
localSegment := segment.(*LocalSegment)
|
|
|
|
err := manager.Loader.LoadIndex(ctx, localSegment, segment.LoadInfo(), segment.NeedUpdatedVersion())
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("reload segment failed", zap.Int64("segmentID", key), zap.Error(err))
|
|
|
|
return nil, merr.ErrSegmentLoadFailed
|
|
|
|
}
|
|
|
|
if err := localSegment.RemoveUnusedFieldFiles(); err != nil {
|
|
|
|
log.Warn("remove unused field files failed", zap.Int64("segmentID", key), zap.Error(err))
|
|
|
|
return nil, merr.ErrSegmentReduplicate
|
|
|
|
}
|
|
|
|
|
|
|
|
return segment, nil
|
2024-03-21 14:33:06 +08:00
|
|
|
}).Build()
|
2024-05-06 20:29:30 +08:00
|
|
|
|
|
|
|
segMgr.registerReleaseCallback(func(s Segment) {
|
|
|
|
if s.Type() == SegmentTypeSealed {
|
2024-05-10 19:17:30 +08:00
|
|
|
// !!! We cannot use ctx of request to call Remove,
|
|
|
|
// Once context canceled, the segment will be leak in cache forever.
|
|
|
|
// Because it has been cleaned from segment manager.
|
|
|
|
manager.DiskCache.Remove(context.Background(), s.ID())
|
2024-05-06 20:29:30 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-03-13 10:49:04 +08:00
|
|
|
return manager
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
|
2024-03-25 15:43:07 +08:00
|
|
|
func (mgr *Manager) SetLoader(loader Loader) {
|
|
|
|
mgr.Loader = loader
|
|
|
|
}
|
|
|
|
|
2023-03-27 00:42:00 +08:00
|
|
|
type SegmentManager interface {
|
|
|
|
// Put puts the given segments in,
|
|
|
|
// and increases the ref count of the corresponding collection,
|
|
|
|
// dup segments will not increase the ref count
|
2024-05-06 20:29:30 +08:00
|
|
|
Put(ctx context.Context, segmentType SegmentType, segments ...Segment)
|
2023-11-07 01:44:18 +08:00
|
|
|
UpdateBy(action SegmentAction, filters ...SegmentFilter) int
|
2024-03-13 20:15:03 +08:00
|
|
|
Get(segmentID typeutil.UniqueID) Segment
|
|
|
|
GetWithType(segmentID typeutil.UniqueID, typ SegmentType) Segment
|
2023-03-27 00:42:00 +08:00
|
|
|
GetBy(filters ...SegmentFilter) []Segment
|
2023-08-16 18:38:17 +08:00
|
|
|
// Get segments and acquire the read locks
|
|
|
|
GetAndPinBy(filters ...SegmentFilter) ([]Segment, error)
|
|
|
|
GetAndPin(segments []int64, filters ...SegmentFilter) ([]Segment, error)
|
|
|
|
Unpin(segments []Segment)
|
2023-08-29 15:46:27 +08:00
|
|
|
|
2024-03-13 20:15:03 +08:00
|
|
|
GetSealed(segmentID typeutil.UniqueID) Segment
|
|
|
|
GetGrowing(segmentID typeutil.UniqueID) Segment
|
2023-06-30 17:28:23 +08:00
|
|
|
Empty() bool
|
|
|
|
|
2023-03-27 00:42:00 +08:00
|
|
|
// Remove removes the given segment,
|
|
|
|
// and decreases the ref count of the corresponding collection,
|
|
|
|
// will not decrease the ref count if the given segment not exists
|
2024-05-06 20:29:30 +08:00
|
|
|
Remove(ctx context.Context, segmentID typeutil.UniqueID, scope querypb.DataScope) (int, int)
|
|
|
|
RemoveBy(ctx context.Context, filters ...SegmentFilter) (int, int)
|
|
|
|
Clear(ctx context.Context)
|
2024-06-14 15:35:56 +08:00
|
|
|
|
|
|
|
// Deprecated: quick fix critical issue: #30857
|
|
|
|
// TODO: All Segment assigned to querynode should be managed by SegmentManager, including loading or releasing to perform a transaction.
|
|
|
|
Exist(segmentID typeutil.UniqueID, typ SegmentType) bool
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ SegmentManager = (*segmentManager)(nil)
|
|
|
|
|
|
|
|
// Manager manages all collections and segments
|
|
|
|
type segmentManager struct {
|
|
|
|
mu sync.RWMutex // guards all
|
|
|
|
|
2024-03-13 20:15:03 +08:00
|
|
|
growingSegments map[typeutil.UniqueID]Segment
|
|
|
|
sealedSegments map[typeutil.UniqueID]Segment
|
2024-05-06 20:29:30 +08:00
|
|
|
|
|
|
|
// releaseCallback is the callback function when a segment is released.
|
|
|
|
releaseCallback func(s Segment)
|
2024-06-14 15:35:56 +08:00
|
|
|
|
|
|
|
growingOnReleasingSegments typeutil.UniqueSet
|
|
|
|
sealedOnReleasingSegments typeutil.UniqueSet
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewSegmentManager() *segmentManager {
|
2024-06-14 15:35:56 +08:00
|
|
|
return &segmentManager{
|
|
|
|
growingSegments: make(map[int64]Segment),
|
|
|
|
sealedSegments: make(map[int64]Segment),
|
|
|
|
growingOnReleasingSegments: typeutil.NewUniqueSet(),
|
|
|
|
sealedOnReleasingSegments: typeutil.NewUniqueSet(),
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-06 20:29:30 +08:00
|
|
|
func (mgr *segmentManager) Put(ctx context.Context, segmentType SegmentType, segments ...Segment) {
|
2023-08-30 11:37:00 +08:00
|
|
|
var replacedSegment []Segment
|
2023-03-27 00:42:00 +08:00
|
|
|
mgr.mu.Lock()
|
|
|
|
defer mgr.mu.Unlock()
|
2023-09-19 10:05:22 +08:00
|
|
|
var targetMap map[int64]Segment
|
2023-03-27 00:42:00 +08:00
|
|
|
switch segmentType {
|
|
|
|
case SegmentTypeGrowing:
|
|
|
|
targetMap = mgr.growingSegments
|
|
|
|
case SegmentTypeSealed:
|
|
|
|
targetMap = mgr.sealedSegments
|
|
|
|
default:
|
|
|
|
panic("unexpected segment type")
|
|
|
|
}
|
2024-05-06 20:29:30 +08:00
|
|
|
log := log.Ctx(ctx)
|
2023-03-27 00:42:00 +08:00
|
|
|
for _, segment := range segments {
|
2023-08-11 11:21:32 +08:00
|
|
|
oldSegment, ok := targetMap[segment.ID()]
|
|
|
|
|
2023-08-30 11:37:00 +08:00
|
|
|
if ok {
|
|
|
|
if oldSegment.Version() >= segment.Version() {
|
|
|
|
log.Warn("Invalid segment distribution changed, skip it",
|
|
|
|
zap.Int64("segmentID", segment.ID()),
|
|
|
|
zap.Int64("oldVersion", oldSegment.Version()),
|
|
|
|
zap.Int64("newVersion", segment.Version()),
|
|
|
|
)
|
|
|
|
// delete redundant segment
|
2024-05-06 20:29:30 +08:00
|
|
|
segment.Release(ctx)
|
2023-08-30 11:37:00 +08:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
replacedSegment = append(replacedSegment, oldSegment)
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
targetMap[segment.ID()] = segment
|
2023-08-11 11:21:32 +08:00
|
|
|
|
2023-08-30 11:37:00 +08:00
|
|
|
eventlog.Record(eventlog.NewRawEvt(eventlog.Level_Info, fmt.Sprintf("Segment %d[%d] loaded", segment.ID(), segment.Collection())))
|
|
|
|
metrics.QueryNodeNumSegments.WithLabelValues(
|
|
|
|
fmt.Sprint(paramtable.GetNodeID()),
|
|
|
|
fmt.Sprint(segment.Collection()),
|
|
|
|
fmt.Sprint(segment.Partition()),
|
|
|
|
segment.Type().String(),
|
|
|
|
fmt.Sprint(len(segment.Indexes())),
|
2023-12-07 14:34:35 +08:00
|
|
|
segment.Level().String(),
|
2023-08-30 11:37:00 +08:00
|
|
|
).Inc()
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
mgr.updateMetric()
|
2023-08-30 11:37:00 +08:00
|
|
|
|
|
|
|
// release replaced segment
|
|
|
|
if len(replacedSegment) > 0 {
|
|
|
|
go func() {
|
|
|
|
for _, segment := range replacedSegment {
|
2024-06-14 15:35:56 +08:00
|
|
|
mgr.release(ctx, segment)
|
2023-08-30 11:37:00 +08:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
|
2023-11-07 01:44:18 +08:00
|
|
|
func (mgr *segmentManager) UpdateBy(action SegmentAction, filters ...SegmentFilter) int {
|
2023-08-29 15:46:27 +08:00
|
|
|
mgr.mu.RLock()
|
|
|
|
defer mgr.mu.RUnlock()
|
2023-08-11 11:21:32 +08:00
|
|
|
|
2023-08-29 15:46:27 +08:00
|
|
|
updated := 0
|
2024-03-13 20:15:03 +08:00
|
|
|
mgr.rangeWithFilter(func(_ int64, _ SegmentType, segment Segment) bool {
|
|
|
|
if action(segment) {
|
|
|
|
updated++
|
2023-08-29 15:46:27 +08:00
|
|
|
}
|
2024-03-13 20:15:03 +08:00
|
|
|
return true
|
|
|
|
}, filters...)
|
2023-08-29 15:46:27 +08:00
|
|
|
return updated
|
2023-08-11 11:21:32 +08:00
|
|
|
}
|
|
|
|
|
2024-06-14 15:35:56 +08:00
|
|
|
// Deprecated:
|
|
|
|
// TODO: All Segment assigned to querynode should be managed by SegmentManager, including loading or releasing to perform a transaction.
|
|
|
|
func (mgr *segmentManager) Exist(segmentID typeutil.UniqueID, typ SegmentType) bool {
|
|
|
|
mgr.mu.RLock()
|
|
|
|
defer mgr.mu.RUnlock()
|
|
|
|
switch typ {
|
|
|
|
case SegmentTypeGrowing:
|
|
|
|
if _, ok := mgr.growingSegments[segmentID]; ok {
|
|
|
|
return true
|
|
|
|
} else if mgr.growingOnReleasingSegments.Contain(segmentID) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
case SegmentTypeSealed:
|
|
|
|
if _, ok := mgr.sealedSegments[segmentID]; ok {
|
|
|
|
return true
|
|
|
|
} else if mgr.sealedOnReleasingSegments.Contain(segmentID) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-03-13 20:15:03 +08:00
|
|
|
func (mgr *segmentManager) Get(segmentID typeutil.UniqueID) Segment {
|
2023-03-27 00:42:00 +08:00
|
|
|
mgr.mu.RLock()
|
|
|
|
defer mgr.mu.RUnlock()
|
|
|
|
|
|
|
|
if segment, ok := mgr.growingSegments[segmentID]; ok {
|
|
|
|
return segment
|
|
|
|
} else if segment, ok = mgr.sealedSegments[segmentID]; ok {
|
|
|
|
return segment
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-03-13 20:15:03 +08:00
|
|
|
func (mgr *segmentManager) GetWithType(segmentID typeutil.UniqueID, typ SegmentType) Segment {
|
2023-03-27 00:42:00 +08:00
|
|
|
mgr.mu.RLock()
|
|
|
|
defer mgr.mu.RUnlock()
|
|
|
|
|
|
|
|
switch typ {
|
|
|
|
case SegmentTypeSealed:
|
|
|
|
return mgr.sealedSegments[segmentID]
|
|
|
|
case SegmentTypeGrowing:
|
|
|
|
return mgr.growingSegments[segmentID]
|
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mgr *segmentManager) GetBy(filters ...SegmentFilter) []Segment {
|
|
|
|
mgr.mu.RLock()
|
|
|
|
defer mgr.mu.RUnlock()
|
|
|
|
|
2024-03-13 20:15:03 +08:00
|
|
|
var ret []Segment
|
|
|
|
mgr.rangeWithFilter(func(id int64, _ SegmentType, segment Segment) bool {
|
|
|
|
ret = append(ret, segment)
|
|
|
|
return true
|
|
|
|
}, filters...)
|
2023-03-27 00:42:00 +08:00
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2023-08-16 18:38:17 +08:00
|
|
|
func (mgr *segmentManager) GetAndPinBy(filters ...SegmentFilter) ([]Segment, error) {
|
|
|
|
mgr.mu.RLock()
|
|
|
|
defer mgr.mu.RUnlock()
|
|
|
|
|
2024-03-13 20:15:03 +08:00
|
|
|
var ret []Segment
|
2023-08-16 18:38:17 +08:00
|
|
|
var err error
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
for _, segment := range ret {
|
2024-04-08 17:09:16 +08:00
|
|
|
segment.Unpin()
|
2023-08-16 18:38:17 +08:00
|
|
|
}
|
2024-05-10 19:17:30 +08:00
|
|
|
ret = nil
|
2023-08-16 18:38:17 +08:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2024-03-13 20:15:03 +08:00
|
|
|
mgr.rangeWithFilter(func(id int64, _ SegmentType, segment Segment) bool {
|
|
|
|
if segment.Level() == datapb.SegmentLevel_L0 {
|
|
|
|
return true
|
2023-08-16 18:38:17 +08:00
|
|
|
}
|
2024-04-08 17:09:16 +08:00
|
|
|
err = segment.PinIfNotReleased()
|
2024-03-13 20:15:03 +08:00
|
|
|
if err != nil {
|
|
|
|
return false
|
2023-08-16 18:38:17 +08:00
|
|
|
}
|
2024-03-13 20:15:03 +08:00
|
|
|
ret = append(ret, segment)
|
|
|
|
return true
|
|
|
|
}, filters...)
|
|
|
|
|
2024-05-10 19:17:30 +08:00
|
|
|
return ret, err
|
2023-08-16 18:38:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mgr *segmentManager) GetAndPin(segments []int64, filters ...SegmentFilter) ([]Segment, error) {
|
|
|
|
mgr.mu.RLock()
|
|
|
|
defer mgr.mu.RUnlock()
|
|
|
|
|
|
|
|
lockedSegments := make([]Segment, 0, len(segments))
|
|
|
|
var err error
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
for _, segment := range lockedSegments {
|
2024-04-08 17:09:16 +08:00
|
|
|
segment.Unpin()
|
2023-08-16 18:38:17 +08:00
|
|
|
}
|
2024-05-10 19:17:30 +08:00
|
|
|
lockedSegments = nil
|
2023-08-16 18:38:17 +08:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
for _, id := range segments {
|
|
|
|
growing, growingExist := mgr.growingSegments[id]
|
|
|
|
sealed, sealedExist := mgr.sealedSegments[id]
|
|
|
|
|
2023-11-20 17:26:23 +08:00
|
|
|
// L0 Segment should not be queryable.
|
|
|
|
if sealedExist && sealed.Level() == datapb.SegmentLevel_L0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2023-08-16 18:38:17 +08:00
|
|
|
growingExist = growingExist && filter(growing, filters...)
|
|
|
|
sealedExist = sealedExist && filter(sealed, filters...)
|
|
|
|
|
|
|
|
if growingExist {
|
2024-04-08 17:09:16 +08:00
|
|
|
err = growing.PinIfNotReleased()
|
2023-08-16 18:38:17 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
lockedSegments = append(lockedSegments, growing)
|
|
|
|
}
|
|
|
|
if sealedExist {
|
2024-04-08 17:09:16 +08:00
|
|
|
err = sealed.PinIfNotReleased()
|
2023-08-16 18:38:17 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
lockedSegments = append(lockedSegments, sealed)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !growingExist && !sealedExist {
|
|
|
|
err = merr.WrapErrSegmentNotLoaded(id, "segment not found")
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
2024-02-27 20:58:40 +08:00
|
|
|
|
2023-08-16 18:38:17 +08:00
|
|
|
return lockedSegments, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mgr *segmentManager) Unpin(segments []Segment) {
|
|
|
|
for _, segment := range segments {
|
2024-04-08 17:09:16 +08:00
|
|
|
segment.Unpin()
|
2023-08-16 18:38:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-13 20:15:03 +08:00
|
|
|
func (mgr *segmentManager) rangeWithFilter(process func(id int64, segType SegmentType, segment Segment) bool, filters ...SegmentFilter) {
|
|
|
|
var segType SegmentType
|
|
|
|
var hasSegType, hasSegIDs bool
|
|
|
|
segmentIDs := typeutil.NewSet[int64]()
|
|
|
|
|
|
|
|
otherFilters := make([]SegmentFilter, 0, len(filters))
|
|
|
|
for _, filter := range filters {
|
|
|
|
if sType, ok := filter.SegmentType(); ok {
|
|
|
|
segType = sType
|
|
|
|
hasSegType = true
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if segIDs, ok := filter.SegmentIDs(); ok {
|
|
|
|
hasSegIDs = true
|
|
|
|
segmentIDs.Insert(segIDs...)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
otherFilters = append(otherFilters, filter)
|
|
|
|
}
|
|
|
|
|
|
|
|
mergedFilter := func(info Segment) bool {
|
|
|
|
for _, filter := range otherFilters {
|
|
|
|
if !filter.Filter(info) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
var candidates map[SegmentType]map[int64]Segment
|
|
|
|
switch segType {
|
|
|
|
case SegmentTypeSealed:
|
|
|
|
candidates = map[SegmentType]map[int64]Segment{SegmentTypeSealed: mgr.sealedSegments}
|
|
|
|
case SegmentTypeGrowing:
|
|
|
|
candidates = map[SegmentType]map[int64]Segment{SegmentTypeGrowing: mgr.growingSegments}
|
|
|
|
default:
|
|
|
|
if !hasSegType {
|
|
|
|
candidates = map[SegmentType]map[int64]Segment{
|
|
|
|
SegmentTypeSealed: mgr.sealedSegments,
|
|
|
|
SegmentTypeGrowing: mgr.growingSegments,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for segType, candidate := range candidates {
|
|
|
|
if hasSegIDs {
|
|
|
|
for id := range segmentIDs {
|
|
|
|
segment, has := candidate[id]
|
|
|
|
if has && mergedFilter(segment) {
|
|
|
|
if !process(id, segType, segment) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for id, segment := range candidate {
|
|
|
|
if mergedFilter(segment) {
|
|
|
|
if !process(id, segType, segment) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-27 00:42:00 +08:00
|
|
|
func filter(segment Segment, filters ...SegmentFilter) bool {
|
|
|
|
for _, filter := range filters {
|
2024-03-13 20:15:03 +08:00
|
|
|
if !filter.Filter(segment) {
|
2023-03-27 00:42:00 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-03-13 20:15:03 +08:00
|
|
|
func (mgr *segmentManager) GetSealed(segmentID typeutil.UniqueID) Segment {
|
2023-03-27 00:42:00 +08:00
|
|
|
mgr.mu.RLock()
|
|
|
|
defer mgr.mu.RUnlock()
|
|
|
|
|
|
|
|
if segment, ok := mgr.sealedSegments[segmentID]; ok {
|
|
|
|
return segment
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-03-13 20:15:03 +08:00
|
|
|
func (mgr *segmentManager) GetGrowing(segmentID typeutil.UniqueID) Segment {
|
2023-03-27 00:42:00 +08:00
|
|
|
mgr.mu.RLock()
|
|
|
|
defer mgr.mu.RUnlock()
|
|
|
|
|
|
|
|
if segment, ok := mgr.growingSegments[segmentID]; ok {
|
|
|
|
return segment
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-06-30 17:28:23 +08:00
|
|
|
func (mgr *segmentManager) Empty() bool {
|
|
|
|
mgr.mu.RLock()
|
|
|
|
defer mgr.mu.RUnlock()
|
|
|
|
|
|
|
|
return len(mgr.growingSegments)+len(mgr.sealedSegments) == 0
|
|
|
|
}
|
|
|
|
|
2023-07-14 10:28:30 +08:00
|
|
|
// returns true if the segment exists,
|
|
|
|
// false otherwise
|
2024-05-06 20:29:30 +08:00
|
|
|
func (mgr *segmentManager) Remove(ctx context.Context, segmentID typeutil.UniqueID, scope querypb.DataScope) (int, int) {
|
2023-03-27 00:42:00 +08:00
|
|
|
mgr.mu.Lock()
|
|
|
|
|
2023-07-14 10:28:30 +08:00
|
|
|
var removeGrowing, removeSealed int
|
2023-09-09 10:35:16 +08:00
|
|
|
var growing, sealed Segment
|
2023-03-27 00:42:00 +08:00
|
|
|
switch scope {
|
|
|
|
case querypb.DataScope_Streaming:
|
2023-08-18 15:28:18 +08:00
|
|
|
growing = mgr.removeSegmentWithType(SegmentTypeGrowing, segmentID)
|
|
|
|
if growing != nil {
|
2023-07-14 10:28:30 +08:00
|
|
|
removeGrowing = 1
|
|
|
|
}
|
2023-03-27 00:42:00 +08:00
|
|
|
|
|
|
|
case querypb.DataScope_Historical:
|
2023-08-18 15:28:18 +08:00
|
|
|
sealed = mgr.removeSegmentWithType(SegmentTypeSealed, segmentID)
|
|
|
|
if sealed != nil {
|
2023-07-14 10:28:30 +08:00
|
|
|
removeSealed = 1
|
|
|
|
}
|
2023-03-27 00:42:00 +08:00
|
|
|
|
|
|
|
case querypb.DataScope_All:
|
2023-08-18 15:28:18 +08:00
|
|
|
growing = mgr.removeSegmentWithType(SegmentTypeGrowing, segmentID)
|
|
|
|
if growing != nil {
|
2023-07-14 10:28:30 +08:00
|
|
|
removeGrowing = 1
|
|
|
|
}
|
2023-08-18 15:28:18 +08:00
|
|
|
|
|
|
|
sealed = mgr.removeSegmentWithType(SegmentTypeSealed, segmentID)
|
|
|
|
if sealed != nil {
|
2023-07-14 10:28:30 +08:00
|
|
|
removeSealed = 1
|
|
|
|
}
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
mgr.updateMetric()
|
2023-08-18 15:28:18 +08:00
|
|
|
mgr.mu.Unlock()
|
|
|
|
|
|
|
|
if growing != nil {
|
2024-06-14 15:35:56 +08:00
|
|
|
mgr.release(ctx, growing)
|
2023-08-18 15:28:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if sealed != nil {
|
2024-06-14 15:35:56 +08:00
|
|
|
mgr.release(ctx, sealed)
|
2023-08-18 15:28:18 +08:00
|
|
|
}
|
|
|
|
|
2023-07-14 10:28:30 +08:00
|
|
|
return removeGrowing, removeSealed
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
|
2024-03-13 20:15:03 +08:00
|
|
|
func (mgr *segmentManager) removeSegmentWithType(typ SegmentType, segmentID typeutil.UniqueID) Segment {
|
2023-08-18 15:28:18 +08:00
|
|
|
switch typ {
|
|
|
|
case SegmentTypeGrowing:
|
|
|
|
s, ok := mgr.growingSegments[segmentID]
|
|
|
|
if ok {
|
|
|
|
delete(mgr.growingSegments, segmentID)
|
2024-06-14 15:35:56 +08:00
|
|
|
mgr.growingOnReleasingSegments.Insert(segmentID)
|
2023-09-09 10:35:16 +08:00
|
|
|
return s
|
2023-08-18 15:28:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case SegmentTypeSealed:
|
|
|
|
s, ok := mgr.sealedSegments[segmentID]
|
|
|
|
if ok {
|
|
|
|
delete(mgr.sealedSegments, segmentID)
|
2024-06-14 15:35:56 +08:00
|
|
|
mgr.sealedOnReleasingSegments.Insert(segmentID)
|
2023-09-09 10:35:16 +08:00
|
|
|
return s
|
2023-08-18 15:28:18 +08:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-05-06 20:29:30 +08:00
|
|
|
func (mgr *segmentManager) RemoveBy(ctx context.Context, filters ...SegmentFilter) (int, int) {
|
2023-03-27 00:42:00 +08:00
|
|
|
mgr.mu.Lock()
|
|
|
|
|
2024-03-13 20:15:03 +08:00
|
|
|
var removeSegments []Segment
|
|
|
|
var removeGrowing, removeSealed int
|
2023-03-27 00:42:00 +08:00
|
|
|
|
2024-03-13 20:15:03 +08:00
|
|
|
mgr.rangeWithFilter(func(id int64, segType SegmentType, segment Segment) bool {
|
|
|
|
s := mgr.removeSegmentWithType(segType, id)
|
|
|
|
if s != nil {
|
|
|
|
removeSegments = append(removeSegments, s)
|
|
|
|
switch segType {
|
|
|
|
case SegmentTypeGrowing:
|
|
|
|
removeGrowing++
|
|
|
|
case SegmentTypeSealed:
|
|
|
|
removeSealed++
|
2023-08-18 15:28:18 +08:00
|
|
|
}
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
2024-03-13 20:15:03 +08:00
|
|
|
return true
|
|
|
|
}, filters...)
|
2023-03-27 00:42:00 +08:00
|
|
|
mgr.updateMetric()
|
2023-08-18 15:28:18 +08:00
|
|
|
mgr.mu.Unlock()
|
|
|
|
|
2024-03-13 20:15:03 +08:00
|
|
|
for _, s := range removeSegments {
|
2024-06-14 15:35:56 +08:00
|
|
|
mgr.release(ctx, s)
|
2023-08-18 15:28:18 +08:00
|
|
|
}
|
2024-03-13 20:15:03 +08:00
|
|
|
return removeGrowing, removeSealed
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
|
2024-05-06 20:29:30 +08:00
|
|
|
func (mgr *segmentManager) Clear(ctx context.Context) {
|
2023-06-30 17:28:23 +08:00
|
|
|
mgr.mu.Lock()
|
|
|
|
|
2024-06-14 15:35:56 +08:00
|
|
|
for id := range mgr.growingSegments {
|
|
|
|
mgr.growingOnReleasingSegments.Insert(id)
|
2023-06-30 17:28:23 +08:00
|
|
|
}
|
2024-06-14 15:35:56 +08:00
|
|
|
growingWaitForRelease := mgr.growingSegments
|
|
|
|
mgr.growingSegments = make(map[int64]Segment)
|
2023-06-30 17:28:23 +08:00
|
|
|
|
2024-06-14 15:35:56 +08:00
|
|
|
for id := range mgr.sealedSegments {
|
|
|
|
mgr.sealedOnReleasingSegments.Insert(id)
|
2023-06-30 17:28:23 +08:00
|
|
|
}
|
2024-06-14 15:35:56 +08:00
|
|
|
sealedWaitForRelease := mgr.sealedSegments
|
|
|
|
mgr.sealedSegments = make(map[int64]Segment)
|
2023-06-30 17:28:23 +08:00
|
|
|
mgr.updateMetric()
|
2024-06-14 15:35:56 +08:00
|
|
|
mgr.mu.Unlock()
|
|
|
|
|
|
|
|
for _, segment := range growingWaitForRelease {
|
|
|
|
mgr.release(ctx, segment)
|
|
|
|
}
|
|
|
|
for _, segment := range sealedWaitForRelease {
|
|
|
|
mgr.release(ctx, segment)
|
|
|
|
}
|
2023-06-30 17:28:23 +08:00
|
|
|
}
|
|
|
|
|
2024-05-06 20:29:30 +08:00
|
|
|
// registerReleaseCallback registers the callback function when a segment is released.
|
|
|
|
// TODO: bad implementation for keep consistency with DiskCache, need to be refactor.
|
|
|
|
func (mgr *segmentManager) registerReleaseCallback(callback func(s Segment)) {
|
|
|
|
mgr.releaseCallback = callback
|
|
|
|
}
|
|
|
|
|
2023-03-27 00:42:00 +08:00
|
|
|
func (mgr *segmentManager) updateMetric() {
|
|
|
|
// update collection and partiation metric
|
2024-03-13 20:15:03 +08:00
|
|
|
collections, partiations := make(typeutil.Set[int64]), make(typeutil.Set[int64])
|
2023-03-27 00:42:00 +08:00
|
|
|
for _, seg := range mgr.growingSegments {
|
|
|
|
collections.Insert(seg.Collection())
|
2024-05-24 15:31:42 +08:00
|
|
|
if seg.Partition() != common.AllPartitionsID {
|
|
|
|
partiations.Insert(seg.Partition())
|
|
|
|
}
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
for _, seg := range mgr.sealedSegments {
|
|
|
|
collections.Insert(seg.Collection())
|
2024-05-24 15:31:42 +08:00
|
|
|
if seg.Partition() != common.AllPartitionsID {
|
|
|
|
partiations.Insert(seg.Partition())
|
|
|
|
}
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
metrics.QueryNodeNumCollections.WithLabelValues(fmt.Sprint(paramtable.GetNodeID())).Set(float64(collections.Len()))
|
|
|
|
metrics.QueryNodeNumPartitions.WithLabelValues(fmt.Sprint(paramtable.GetNodeID())).Set(float64(partiations.Len()))
|
|
|
|
}
|
|
|
|
|
2024-06-14 15:35:56 +08:00
|
|
|
func (mgr *segmentManager) release(ctx context.Context, segment Segment) {
|
2024-05-06 20:29:30 +08:00
|
|
|
if mgr.releaseCallback != nil {
|
|
|
|
mgr.releaseCallback(segment)
|
2024-05-10 19:17:30 +08:00
|
|
|
log.Ctx(ctx).Info("remove segment from cache", zap.Int64("segmentID", segment.ID()))
|
2024-05-06 20:29:30 +08:00
|
|
|
}
|
2024-05-10 19:17:30 +08:00
|
|
|
segment.Release(ctx)
|
2023-03-27 00:42:00 +08:00
|
|
|
|
|
|
|
metrics.QueryNodeNumSegments.WithLabelValues(
|
|
|
|
fmt.Sprint(paramtable.GetNodeID()),
|
|
|
|
fmt.Sprint(segment.Collection()),
|
|
|
|
fmt.Sprint(segment.Partition()),
|
|
|
|
segment.Type().String(),
|
|
|
|
fmt.Sprint(len(segment.Indexes())),
|
2023-12-07 14:34:35 +08:00
|
|
|
segment.Level().String(),
|
2023-03-27 00:42:00 +08:00
|
|
|
).Dec()
|
2024-01-05 18:24:47 +08:00
|
|
|
|
2024-06-14 15:35:56 +08:00
|
|
|
mgr.mu.Lock()
|
|
|
|
defer mgr.mu.Unlock()
|
|
|
|
|
|
|
|
switch segment.Type() {
|
|
|
|
case SegmentTypeGrowing:
|
|
|
|
mgr.growingOnReleasingSegments.Remove(segment.ID())
|
|
|
|
case SegmentTypeSealed:
|
|
|
|
mgr.sealedOnReleasingSegments.Remove(segment.ID())
|
|
|
|
}
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|