2022-12-12 10:57:22 +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 datanode implements data persistence logic.
|
|
|
|
//
|
|
|
|
// Data node persists insert logs into persistent storage like minIO/S3.
|
|
|
|
package datanode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2024-05-30 13:37:44 +08:00
|
|
|
"github.com/samber/lo"
|
2023-03-04 23:21:50 +08:00
|
|
|
"go.uber.org/zap"
|
2023-02-26 11:31:49 +08:00
|
|
|
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
|
2024-05-23 09:53:40 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/datanode/compaction"
|
2024-01-31 20:45:04 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/datanode/importv2"
|
2024-08-02 18:30:23 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/flushcommon/io"
|
2024-08-22 19:42:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/flushcommon/metacache/pkoracle"
|
2024-05-30 13:37:44 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/metastore/kv/binlog"
|
2022-12-12 10:57:22 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
2024-05-30 13:37:44 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/storage"
|
2024-06-07 14:17:20 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/importutilv2"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/common"
|
|
|
|
"github.com/milvus-io/milvus/pkg/log"
|
|
|
|
"github.com/milvus-io/milvus/pkg/metrics"
|
2024-01-30 10:09:03 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/tracer"
|
2024-05-30 13:37:44 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/conc"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/merr"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/metricsinfo"
|
2024-10-28 10:13:29 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
2023-09-21 09:45:27 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/tsoutil"
|
2024-10-28 10:13:29 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/typeutil"
|
2022-12-12 10:57:22 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// WatchDmChannels is not in use
|
|
|
|
func (node *DataNode) WatchDmChannels(ctx context.Context, in *datapb.WatchDmChannelsRequest) (*commonpb.Status, error) {
|
|
|
|
log.Warn("DataNode WatchDmChannels is not in use")
|
|
|
|
|
2023-03-28 19:04:00 +08:00
|
|
|
// TODO ERROR OF GRPC NOT IN USE
|
2023-10-11 21:01:35 +08:00
|
|
|
return merr.Success(), nil
|
2022-12-12 10:57:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetComponentStates will return current state of DataNode
|
2023-09-26 09:57:25 +08:00
|
|
|
func (node *DataNode) GetComponentStates(ctx context.Context, req *milvuspb.GetComponentStatesRequest) (*milvuspb.ComponentStates, error) {
|
2022-12-12 10:57:22 +08:00
|
|
|
nodeID := common.NotRegisteredID
|
2023-11-22 09:12:22 +08:00
|
|
|
state := node.stateCode.Load().(commonpb.StateCode)
|
|
|
|
log.Debug("DataNode current state", zap.String("State", state.String()))
|
2023-01-12 19:49:40 +08:00
|
|
|
if node.GetSession() != nil && node.session.Registered() {
|
|
|
|
nodeID = node.GetSession().ServerID
|
2022-12-12 10:57:22 +08:00
|
|
|
}
|
|
|
|
states := &milvuspb.ComponentStates{
|
|
|
|
State: &milvuspb.ComponentInfo{
|
|
|
|
// NodeID: Params.NodeID, // will race with DataNode.Register()
|
|
|
|
NodeID: nodeID,
|
|
|
|
Role: node.Role,
|
|
|
|
StateCode: node.stateCode.Load().(commonpb.StateCode),
|
|
|
|
},
|
|
|
|
SubcomponentStates: make([]*milvuspb.ComponentInfo, 0),
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2022-12-12 10:57:22 +08:00
|
|
|
}
|
|
|
|
return states, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (node *DataNode) FlushSegments(ctx context.Context, req *datapb.FlushSegmentsRequest) (*commonpb.Status, error) {
|
2024-04-01 16:55:19 +08:00
|
|
|
serverID := node.GetNodeID()
|
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.Int64("nodeID", serverID),
|
|
|
|
zap.Int64("collectionID", req.GetCollectionID()),
|
|
|
|
zap.String("channelName", req.GetChannelName()),
|
|
|
|
zap.Int64s("segmentIDs", req.GetSegmentIDs()),
|
|
|
|
)
|
|
|
|
log.Info("receive FlushSegments request")
|
2023-10-11 21:01:35 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2024-04-01 16:55:19 +08:00
|
|
|
log.Warn("failed to FlushSegments", zap.Error(err))
|
2023-03-28 19:04:00 +08:00
|
|
|
return merr.Status(err), nil
|
2022-12-12 10:57:22 +08:00
|
|
|
}
|
|
|
|
|
2023-01-12 19:49:40 +08:00
|
|
|
if req.GetBase().GetTargetID() != serverID {
|
2024-04-01 16:55:19 +08:00
|
|
|
log.Warn("faled to FlushSegments, target node not match", zap.Int64("targetID", req.GetBase().GetTargetID()))
|
2023-03-28 19:04:00 +08:00
|
|
|
return merr.Status(merr.WrapErrNodeNotMatch(req.GetBase().GetTargetID(), serverID)), nil
|
2022-12-12 10:57:22 +08:00
|
|
|
}
|
|
|
|
|
2024-04-01 16:55:19 +08:00
|
|
|
err := node.writeBufferManager.SealSegments(ctx, req.GetChannelName(), req.GetSegmentIDs())
|
2023-11-15 15:24:18 +08:00
|
|
|
if err != nil {
|
2024-04-01 16:55:19 +08:00
|
|
|
log.Warn("failed to FlushSegments", zap.Error(err))
|
2023-11-15 15:24:18 +08:00
|
|
|
return merr.Status(err), nil
|
2022-12-12 10:57:22 +08:00
|
|
|
}
|
|
|
|
|
2024-04-01 16:55:19 +08:00
|
|
|
log.Info("success to FlushSegments")
|
2023-10-11 21:01:35 +08:00
|
|
|
return merr.Success(), nil
|
2022-12-12 10:57:22 +08:00
|
|
|
}
|
|
|
|
|
2023-10-16 10:26:09 +08:00
|
|
|
// ResendSegmentStats . ResendSegmentStats resend un-flushed segment stats back upstream to DataCoord by resending DataNode time tick message.
|
2022-12-12 10:57:22 +08:00
|
|
|
// It returns a list of segments to be sent.
|
2023-10-16 10:26:09 +08:00
|
|
|
// Deprecated in 2.3.2, reversed it just for compatibility during rolling back
|
2022-12-12 10:57:22 +08:00
|
|
|
func (node *DataNode) ResendSegmentStats(ctx context.Context, req *datapb.ResendSegmentStatsRequest) (*datapb.ResendSegmentStatsResponse, error) {
|
|
|
|
return &datapb.ResendSegmentStatsResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-10-16 10:26:09 +08:00
|
|
|
SegResent: make([]int64, 0),
|
2022-12-12 10:57:22 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetTimeTickChannel currently do nothing
|
2023-09-26 09:57:25 +08:00
|
|
|
func (node *DataNode) GetTimeTickChannel(ctx context.Context, req *internalpb.GetTimeTickChannelRequest) (*milvuspb.StringResponse, error) {
|
2022-12-12 10:57:22 +08:00
|
|
|
return &milvuspb.StringResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2022-12-12 10:57:22 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetStatisticsChannel currently do nothing
|
2023-09-26 09:57:25 +08:00
|
|
|
func (node *DataNode) GetStatisticsChannel(ctx context.Context, req *internalpb.GetStatisticsChannelRequest) (*milvuspb.StringResponse, error) {
|
2022-12-12 10:57:22 +08:00
|
|
|
return &milvuspb.StringResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2022-12-12 10:57:22 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ShowConfigurations returns the configurations of DataNode matching req.Pattern
|
|
|
|
func (node *DataNode) ShowConfigurations(ctx context.Context, req *internalpb.ShowConfigurationsRequest) (*internalpb.ShowConfigurationsResponse, error) {
|
|
|
|
log.Debug("DataNode.ShowConfigurations", zap.String("pattern", req.Pattern))
|
2023-10-11 21:01:35 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2024-02-21 11:54:53 +08:00
|
|
|
log.Warn("DataNode.ShowConfigurations failed", zap.Int64("nodeId", node.GetNodeID()), zap.Error(err))
|
2022-12-12 10:57:22 +08:00
|
|
|
|
|
|
|
return &internalpb.ShowConfigurationsResponse{
|
2023-03-28 19:04:00 +08:00
|
|
|
Status: merr.Status(err),
|
2022-12-12 10:57:22 +08:00
|
|
|
Configuations: nil,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
configList := make([]*commonpb.KeyValuePair, 0)
|
2023-01-13 15:31:41 +08:00
|
|
|
for key, value := range Params.GetComponentConfigurations("datanode", req.Pattern) {
|
2022-12-12 10:57:22 +08:00
|
|
|
configList = append(configList,
|
|
|
|
&commonpb.KeyValuePair{
|
|
|
|
Key: key,
|
|
|
|
Value: value,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return &internalpb.ShowConfigurationsResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2022-12-12 10:57:22 +08:00
|
|
|
Configuations: configList,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetMetrics return datanode metrics
|
|
|
|
func (node *DataNode) GetMetrics(ctx context.Context, req *milvuspb.GetMetricsRequest) (*milvuspb.GetMetricsResponse, error) {
|
2023-10-11 21:01:35 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2024-02-21 11:54:53 +08:00
|
|
|
log.Warn("DataNode.GetMetrics failed", zap.Int64("nodeId", node.GetNodeID()), zap.Error(err))
|
2022-12-12 10:57:22 +08:00
|
|
|
|
|
|
|
return &milvuspb.GetMetricsResponse{
|
2023-03-28 19:04:00 +08:00
|
|
|
Status: merr.Status(err),
|
2022-12-12 10:57:22 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2024-10-28 10:13:29 +08:00
|
|
|
resp := &milvuspb.GetMetricsResponse{
|
|
|
|
Status: merr.Success(),
|
|
|
|
ComponentName: metricsinfo.ConstructComponentName(typeutil.DataNodeRole,
|
|
|
|
paramtable.GetNodeID()),
|
2022-12-12 10:57:22 +08:00
|
|
|
}
|
|
|
|
|
2024-10-28 10:13:29 +08:00
|
|
|
ret, err := node.metricsRequest.ExecuteMetricsRequest(ctx, req)
|
|
|
|
if err != nil {
|
|
|
|
resp.Status = merr.Status(err)
|
|
|
|
return resp, nil
|
2022-12-12 10:57:22 +08:00
|
|
|
}
|
|
|
|
|
2024-10-28 10:13:29 +08:00
|
|
|
resp.Response = ret
|
|
|
|
return resp, nil
|
2022-12-12 10:57:22 +08:00
|
|
|
}
|
|
|
|
|
2024-06-16 22:07:57 +08:00
|
|
|
// CompactionV2 handles compaction request from DataCoord
|
2022-12-12 10:57:22 +08:00
|
|
|
// returns status as long as compaction task enqueued or invalid
|
2024-06-16 22:07:57 +08:00
|
|
|
func (node *DataNode) CompactionV2(ctx context.Context, req *datapb.CompactionPlan) (*commonpb.Status, error) {
|
2023-12-04 19:06:40 +08:00
|
|
|
log := log.Ctx(ctx).With(zap.Int64("planID", req.GetPlanID()))
|
2023-10-11 21:01:35 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2024-02-21 11:54:53 +08:00
|
|
|
log.Warn("DataNode.Compaction failed", zap.Int64("nodeId", node.GetNodeID()), zap.Error(err))
|
2023-03-28 19:04:00 +08:00
|
|
|
return merr.Status(err), nil
|
2022-12-12 10:57:22 +08:00
|
|
|
}
|
|
|
|
|
2024-05-24 09:07:41 +08:00
|
|
|
if len(req.GetSegmentBinlogs()) == 0 {
|
|
|
|
log.Info("no segments to compact")
|
|
|
|
return merr.Success(), nil
|
2023-12-04 19:06:40 +08:00
|
|
|
}
|
|
|
|
|
2024-07-17 13:23:42 +08:00
|
|
|
if req.GetBeginLogID() == 0 {
|
|
|
|
return merr.Status(merr.WrapErrParameterInvalidMsg("invalid beginLogID")), nil
|
|
|
|
}
|
|
|
|
|
2024-01-30 10:09:03 +08:00
|
|
|
/*
|
|
|
|
spanCtx := trace.SpanContextFromContext(ctx)
|
2024-01-23 10:37:00 +08:00
|
|
|
|
2024-01-30 10:09:03 +08:00
|
|
|
taskCtx := trace.ContextWithSpanContext(node.ctx, spanCtx)*/
|
|
|
|
taskCtx := tracer.Propagate(ctx, node.ctx)
|
2024-01-23 10:37:00 +08:00
|
|
|
|
2024-05-23 09:53:40 +08:00
|
|
|
var task compaction.Compactor
|
2024-06-06 14:33:52 +08:00
|
|
|
binlogIO := io.NewBinlogIO(node.chunkManager)
|
2023-11-30 14:30:28 +08:00
|
|
|
switch req.GetType() {
|
|
|
|
case datapb.CompactionType_Level0DeleteCompaction:
|
2024-06-06 14:33:52 +08:00
|
|
|
task = compaction.NewLevelZeroCompactionTask(
|
2024-01-23 10:37:00 +08:00
|
|
|
taskCtx,
|
2023-11-30 14:30:28 +08:00
|
|
|
binlogIO,
|
2024-05-17 17:25:36 +08:00
|
|
|
node.chunkManager,
|
2023-11-30 14:30:28 +08:00
|
|
|
req,
|
|
|
|
)
|
2024-02-01 14:25:04 +08:00
|
|
|
case datapb.CompactionType_MixCompaction:
|
2024-09-01 17:09:01 +08:00
|
|
|
if req.GetPreAllocatedSegmentIDs() == nil || req.GetPreAllocatedSegmentIDs().GetBegin() == 0 {
|
2024-07-17 13:23:42 +08:00
|
|
|
return merr.Status(merr.WrapErrParameterInvalidMsg("invalid pre-allocated segmentID range")), nil
|
|
|
|
}
|
2024-05-23 09:53:40 +08:00
|
|
|
task = compaction.NewMixCompactionTask(
|
2024-01-23 10:37:00 +08:00
|
|
|
taskCtx,
|
2024-02-20 14:38:51 +08:00
|
|
|
binlogIO,
|
2023-11-30 14:30:28 +08:00
|
|
|
req,
|
|
|
|
)
|
2024-06-10 21:34:08 +08:00
|
|
|
case datapb.CompactionType_ClusteringCompaction:
|
2024-09-01 17:09:01 +08:00
|
|
|
if req.GetPreAllocatedSegmentIDs() == nil || req.GetPreAllocatedSegmentIDs().GetBegin() == 0 {
|
2024-07-17 13:23:42 +08:00
|
|
|
return merr.Status(merr.WrapErrParameterInvalidMsg("invalid pre-allocated segmentID range")), nil
|
|
|
|
}
|
2024-06-10 21:34:08 +08:00
|
|
|
task = compaction.NewClusteringCompactionTask(
|
|
|
|
taskCtx,
|
|
|
|
binlogIO,
|
|
|
|
req,
|
|
|
|
)
|
2023-11-30 14:30:28 +08:00
|
|
|
default:
|
|
|
|
log.Warn("Unknown compaction type", zap.String("type", req.GetType().String()))
|
|
|
|
return merr.Status(merr.WrapErrParameterInvalidMsg("Unknown compaction type: %v", req.GetType().String())), nil
|
|
|
|
}
|
2022-12-12 10:57:22 +08:00
|
|
|
|
2024-07-18 10:27:41 +08:00
|
|
|
succeed, err := node.compactionExecutor.Execute(task)
|
|
|
|
if succeed {
|
|
|
|
return merr.Success(), nil
|
|
|
|
} else {
|
|
|
|
return merr.Status(err), nil
|
|
|
|
}
|
2022-12-12 10:57:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetCompactionState called by DataCoord
|
|
|
|
// return status of all compaction plans
|
|
|
|
func (node *DataNode) GetCompactionState(ctx context.Context, req *datapb.CompactionStateRequest) (*datapb.CompactionStateResponse, error) {
|
2023-10-11 21:01:35 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2024-02-21 11:54:53 +08:00
|
|
|
log.Warn("DataNode.GetCompactionState failed", zap.Int64("nodeId", node.GetNodeID()), zap.Error(err))
|
2022-12-12 10:57:22 +08:00
|
|
|
return &datapb.CompactionStateResponse{
|
2023-03-28 19:04:00 +08:00
|
|
|
Status: merr.Status(err),
|
2022-12-12 10:57:22 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2024-06-05 10:17:50 +08:00
|
|
|
|
2024-06-14 14:34:01 +08:00
|
|
|
results := node.compactionExecutor.GetResults(req.GetPlanID())
|
2022-12-12 10:57:22 +08:00
|
|
|
return &datapb.CompactionStateResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2022-12-12 10:57:22 +08:00
|
|
|
Results: results,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SyncSegments called by DataCoord, sync the compacted segments' meta between DC and DN
|
|
|
|
func (node *DataNode) SyncSegments(ctx context.Context, req *datapb.SyncSegmentsRequest) (*commonpb.Status, error) {
|
2024-03-01 11:31:00 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2022-12-12 10:57:22 +08:00
|
|
|
zap.Int64("planID", req.GetPlanID()),
|
2024-03-01 11:31:00 +08:00
|
|
|
zap.Int64("nodeID", node.GetNodeID()),
|
2024-05-30 13:37:44 +08:00
|
|
|
zap.Int64("collectionID", req.GetCollectionId()),
|
|
|
|
zap.Int64("partitionID", req.GetPartitionId()),
|
|
|
|
zap.String("channel", req.GetChannelName()),
|
2022-12-12 10:57:22 +08:00
|
|
|
)
|
|
|
|
|
2024-03-01 11:31:00 +08:00
|
|
|
log.Info("DataNode receives SyncSegments")
|
|
|
|
|
2023-10-11 21:01:35 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2024-03-01 11:31:00 +08:00
|
|
|
log.Warn("DataNode.SyncSegments failed", zap.Error(err))
|
2023-03-28 19:04:00 +08:00
|
|
|
return merr.Status(err), nil
|
2022-12-12 10:57:22 +08:00
|
|
|
}
|
|
|
|
|
2024-05-30 13:37:44 +08:00
|
|
|
if len(req.GetSegmentInfos()) <= 0 {
|
|
|
|
log.Info("sync segments is empty, skip it")
|
|
|
|
return merr.Success(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
ds, ok := node.flowgraphManager.GetFlowgraphService(req.GetChannelName())
|
|
|
|
if !ok {
|
2024-06-14 14:34:01 +08:00
|
|
|
node.compactionExecutor.DiscardPlan(req.GetChannelName())
|
2024-05-30 13:37:44 +08:00
|
|
|
err := merr.WrapErrChannelNotFound(req.GetChannelName())
|
|
|
|
log.Warn("failed to get flow graph service", zap.Error(err))
|
|
|
|
return merr.Status(err), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
allSegments := make(map[int64]struct{})
|
|
|
|
for segID := range req.GetSegmentInfos() {
|
|
|
|
allSegments[segID] = struct{}{}
|
|
|
|
}
|
|
|
|
|
2024-07-01 14:46:07 +08:00
|
|
|
missingSegments := ds.GetMetaCache().DetectMissingSegments(allSegments)
|
2024-05-30 13:37:44 +08:00
|
|
|
|
|
|
|
newSegments := make([]*datapb.SyncSegmentInfo, 0, len(missingSegments))
|
|
|
|
futures := make([]*conc.Future[any], 0, len(missingSegments))
|
|
|
|
|
|
|
|
for _, segID := range missingSegments {
|
2024-06-17 10:09:57 +08:00
|
|
|
newSeg := req.GetSegmentInfos()[segID]
|
2024-07-03 17:52:09 +08:00
|
|
|
switch newSeg.GetLevel() {
|
|
|
|
case datapb.SegmentLevel_L0:
|
|
|
|
log.Warn("segment level is L0, may be the channel has not been successfully watched yet", zap.Int64("segmentID", segID))
|
|
|
|
case datapb.SegmentLevel_Legacy:
|
|
|
|
log.Warn("segment level is legacy, please check", zap.Int64("segmentID", segID))
|
|
|
|
default:
|
|
|
|
if newSeg.GetState() == commonpb.SegmentState_Flushed {
|
|
|
|
log.Info("segment loading PKs", zap.Int64("segmentID", segID))
|
|
|
|
newSegments = append(newSegments, newSeg)
|
|
|
|
future := io.GetOrCreateStatsPool().Submit(func() (any, error) {
|
2024-08-22 19:42:57 +08:00
|
|
|
var val *pkoracle.BloomFilterSet
|
2024-07-03 17:52:09 +08:00
|
|
|
var err error
|
|
|
|
err = binlog.DecompressBinLog(storage.StatsBinlog, req.GetCollectionId(), req.GetPartitionId(), newSeg.GetSegmentId(), []*datapb.FieldBinlog{newSeg.GetPkStatsLog()})
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("failed to DecompressBinLog", zap.Error(err))
|
|
|
|
return val, err
|
|
|
|
}
|
|
|
|
pks, err := compaction.LoadStats(ctx, node.chunkManager, ds.GetMetaCache().Schema(), newSeg.GetSegmentId(), []*datapb.FieldBinlog{newSeg.GetPkStatsLog()})
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("failed to load segment stats log", zap.Error(err))
|
|
|
|
return val, err
|
|
|
|
}
|
2024-08-22 19:42:57 +08:00
|
|
|
val = pkoracle.NewBloomFilterSet(pks...)
|
2024-07-03 17:52:09 +08:00
|
|
|
return val, nil
|
|
|
|
})
|
|
|
|
futures = append(futures, future)
|
2024-05-30 13:37:44 +08:00
|
|
|
}
|
2024-07-03 17:52:09 +08:00
|
|
|
}
|
2024-05-30 13:37:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
err := conc.AwaitAll(futures...)
|
|
|
|
if err != nil {
|
|
|
|
return merr.Status(err), nil
|
|
|
|
}
|
|
|
|
|
2024-08-22 19:42:57 +08:00
|
|
|
newSegmentsBF := lo.Map(futures, func(future *conc.Future[any], _ int) *pkoracle.BloomFilterSet {
|
|
|
|
return future.Value().(*pkoracle.BloomFilterSet)
|
2024-05-30 13:37:44 +08:00
|
|
|
})
|
|
|
|
|
2024-07-01 14:46:07 +08:00
|
|
|
ds.GetMetaCache().UpdateSegmentView(req.GetPartitionId(), newSegments, newSegmentsBF, allSegments)
|
2023-10-11 21:01:35 +08:00
|
|
|
return merr.Success(), nil
|
2022-12-12 10:57:22 +08:00
|
|
|
}
|
|
|
|
|
2023-09-25 14:05:27 +08:00
|
|
|
func (node *DataNode) NotifyChannelOperation(ctx context.Context, req *datapb.ChannelOperationsRequest) (*commonpb.Status, error) {
|
2023-12-27 16:00:48 +08:00
|
|
|
log.Ctx(ctx).Info("DataNode receives NotifyChannelOperation",
|
|
|
|
zap.Int("operation count", len(req.GetInfos())))
|
|
|
|
|
2024-05-07 15:49:30 +08:00
|
|
|
if node.channelManager == nil {
|
|
|
|
log.Warn("DataNode NotifyChannelOperation failed due to nil channelManager")
|
|
|
|
return merr.Status(merr.WrapErrServiceInternal("channelManager is nil! Ignore if you are upgrading datanode/coord to rpc based watch")), nil
|
|
|
|
}
|
|
|
|
|
2023-12-27 16:00:48 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2024-02-21 11:54:53 +08:00
|
|
|
log.Warn("DataNode.NotifyChannelOperation failed", zap.Int64("nodeId", node.GetNodeID()), zap.Error(err))
|
2023-12-27 16:00:48 +08:00
|
|
|
return merr.Status(err), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, info := range req.GetInfos() {
|
|
|
|
err := node.channelManager.Submit(info)
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("Submit error", zap.Error(err))
|
|
|
|
return merr.Status(err), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return merr.Status(nil), nil
|
2023-09-25 14:05:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (node *DataNode) CheckChannelOperationProgress(ctx context.Context, req *datapb.ChannelWatchInfo) (*datapb.ChannelOperationProgressResponse, error) {
|
2023-12-27 16:00:48 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.String("channel", req.GetVchan().GetChannelName()),
|
|
|
|
zap.String("operation", req.GetState().String()),
|
|
|
|
)
|
|
|
|
|
|
|
|
log.Info("DataNode receives CheckChannelOperationProgress")
|
2024-05-07 15:49:30 +08:00
|
|
|
|
|
|
|
if node.channelManager == nil {
|
|
|
|
log.Warn("DataNode CheckChannelOperationProgress failed due to nil channelManager")
|
|
|
|
return &datapb.ChannelOperationProgressResponse{
|
|
|
|
Status: merr.Status(merr.WrapErrServiceInternal("channelManager is nil! Ignore if you are upgrading datanode/coord to rpc based watch")),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-12-27 16:00:48 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2024-02-21 11:54:53 +08:00
|
|
|
log.Warn("DataNode.CheckChannelOperationProgress failed", zap.Int64("nodeId", node.GetNodeID()), zap.Error(err))
|
2023-12-27 16:00:48 +08:00
|
|
|
return &datapb.ChannelOperationProgressResponse{
|
|
|
|
Status: merr.Status(err),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
return node.channelManager.GetProgress(req), nil
|
2023-09-25 14:05:27 +08:00
|
|
|
}
|
|
|
|
|
2023-09-12 21:07:19 +08:00
|
|
|
func (node *DataNode) FlushChannels(ctx context.Context, req *datapb.FlushChannelsRequest) (*commonpb.Status, error) {
|
2024-04-24 14:27:23 +08:00
|
|
|
metrics.DataNodeFlushReqCounter.WithLabelValues(fmt.Sprint(node.GetNodeID()), metrics.TotalLabel).Inc()
|
2024-02-21 11:54:53 +08:00
|
|
|
log := log.Ctx(ctx).With(zap.Int64("nodeId", node.GetNodeID()),
|
2024-04-24 14:27:23 +08:00
|
|
|
zap.Uint64("flushTs", req.GetFlushTs()),
|
|
|
|
zap.Time("flushTs in Time", tsoutil.PhysicalTime(req.GetFlushTs())),
|
2023-09-16 00:41:20 +08:00
|
|
|
zap.Strings("channels", req.GetChannels()))
|
2023-09-12 21:07:19 +08:00
|
|
|
|
|
|
|
log.Info("DataNode receives FlushChannels request")
|
2023-10-11 21:01:35 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2023-09-12 21:07:19 +08:00
|
|
|
log.Warn("DataNode.FlushChannels failed", zap.Error(err))
|
|
|
|
return merr.Status(err), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, channel := range req.GetChannels() {
|
2023-11-15 15:24:18 +08:00
|
|
|
err := node.writeBufferManager.FlushChannel(ctx, channel, req.GetFlushTs())
|
|
|
|
if err != nil {
|
2024-04-24 14:27:23 +08:00
|
|
|
log.Warn("WriteBufferManager failed to flush channel", zap.String("channel", channel), zap.Error(err))
|
2023-11-15 15:24:18 +08:00
|
|
|
return merr.Status(err), nil
|
2023-09-12 21:07:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-24 14:27:23 +08:00
|
|
|
metrics.DataNodeFlushReqCounter.WithLabelValues(fmt.Sprint(node.GetNodeID()), metrics.SuccessLabel).Inc()
|
|
|
|
log.Info("success to FlushChannels")
|
2023-10-11 21:01:35 +08:00
|
|
|
return merr.Success(), nil
|
2023-09-12 21:07:19 +08:00
|
|
|
}
|
|
|
|
|
2023-12-04 19:56:35 +08:00
|
|
|
func (node *DataNode) PreImport(ctx context.Context, req *datapb.PreImportRequest) (*commonpb.Status, error) {
|
2024-01-31 20:45:04 +08:00
|
|
|
log := log.Ctx(ctx).With(zap.Int64("taskID", req.GetTaskID()),
|
|
|
|
zap.Int64("jobID", req.GetJobID()),
|
|
|
|
zap.Int64("collectionID", req.GetCollectionID()),
|
|
|
|
zap.Int64s("partitionIDs", req.GetPartitionIDs()),
|
|
|
|
zap.Strings("vchannels", req.GetVchannels()),
|
|
|
|
zap.Any("files", req.GetImportFiles()))
|
|
|
|
|
|
|
|
log.Info("datanode receive preimport request")
|
|
|
|
|
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
|
|
|
}
|
|
|
|
|
2024-06-07 14:17:20 +08:00
|
|
|
var task importv2.Task
|
|
|
|
if importutilv2.IsL0Import(req.GetOptions()) {
|
|
|
|
task = importv2.NewL0PreImportTask(req, node.importTaskMgr, node.chunkManager)
|
|
|
|
} else {
|
|
|
|
task = importv2.NewPreImportTask(req, node.importTaskMgr, node.chunkManager)
|
|
|
|
}
|
2024-04-01 20:09:13 +08:00
|
|
|
node.importTaskMgr.Add(task)
|
2024-01-31 20:45:04 +08:00
|
|
|
|
|
|
|
log.Info("datanode added preimport task")
|
|
|
|
return merr.Success(), nil
|
2023-12-04 19:56:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (node *DataNode) ImportV2(ctx context.Context, req *datapb.ImportRequest) (*commonpb.Status, error) {
|
2024-01-31 20:45:04 +08:00
|
|
|
log := log.Ctx(ctx).With(zap.Int64("taskID", req.GetTaskID()),
|
|
|
|
zap.Int64("jobID", req.GetJobID()),
|
|
|
|
zap.Int64("collectionID", req.GetCollectionID()),
|
|
|
|
zap.Any("segments", req.GetRequestSegments()),
|
|
|
|
zap.Any("files", req.GetFiles()))
|
|
|
|
|
|
|
|
log.Info("datanode receive import request")
|
|
|
|
|
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
|
|
|
}
|
2024-06-07 14:17:20 +08:00
|
|
|
var task importv2.Task
|
|
|
|
if importutilv2.IsL0Import(req.GetOptions()) {
|
|
|
|
task = importv2.NewL0ImportTask(req, node.importTaskMgr, node.syncMgr, node.chunkManager)
|
|
|
|
} else {
|
|
|
|
task = importv2.NewImportTask(req, node.importTaskMgr, node.syncMgr, node.chunkManager)
|
|
|
|
}
|
2024-04-01 20:09:13 +08:00
|
|
|
node.importTaskMgr.Add(task)
|
2024-01-31 20:45:04 +08:00
|
|
|
|
|
|
|
log.Info("datanode added import task")
|
|
|
|
return merr.Success(), nil
|
2023-12-04 19:56:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (node *DataNode) QueryPreImport(ctx context.Context, req *datapb.QueryPreImportRequest) (*datapb.QueryPreImportResponse, error) {
|
2024-01-31 20:45:04 +08:00
|
|
|
log := log.Ctx(ctx).With(zap.Int64("taskID", req.GetTaskID()),
|
|
|
|
zap.Int64("jobID", req.GetJobID()))
|
|
|
|
|
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return &datapb.QueryPreImportResponse{Status: merr.Status(err)}, nil
|
|
|
|
}
|
|
|
|
status := merr.Success()
|
2024-04-01 20:09:13 +08:00
|
|
|
task := node.importTaskMgr.Get(req.GetTaskID())
|
2024-06-07 14:17:20 +08:00
|
|
|
if task == nil {
|
|
|
|
status = merr.Status(importv2.WrapTaskNotFoundError(req.GetTaskID()))
|
2024-01-31 20:45:04 +08:00
|
|
|
}
|
2024-03-01 18:31:02 +08:00
|
|
|
log.RatedInfo(10, "datanode query preimport", zap.String("state", task.GetState().String()),
|
2024-01-31 20:45:04 +08:00
|
|
|
zap.String("reason", task.GetReason()))
|
|
|
|
return &datapb.QueryPreImportResponse{
|
2024-06-07 14:17:20 +08:00
|
|
|
Status: status,
|
|
|
|
TaskID: task.GetTaskID(),
|
|
|
|
State: task.GetState(),
|
|
|
|
Reason: task.GetReason(),
|
|
|
|
FileStats: task.(interface {
|
|
|
|
GetFileStats() []*datapb.ImportFileStats
|
|
|
|
}).GetFileStats(),
|
2024-01-31 20:45:04 +08:00
|
|
|
}, nil
|
2023-12-04 19:56:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (node *DataNode) QueryImport(ctx context.Context, req *datapb.QueryImportRequest) (*datapb.QueryImportResponse, error) {
|
2024-01-31 20:45:04 +08:00
|
|
|
log := log.Ctx(ctx).With(zap.Int64("taskID", req.GetTaskID()),
|
|
|
|
zap.Int64("jobID", req.GetJobID()))
|
|
|
|
|
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return &datapb.QueryImportResponse{Status: merr.Status(err)}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
status := merr.Success()
|
|
|
|
|
|
|
|
// query slot
|
|
|
|
if req.GetQuerySlot() {
|
|
|
|
return &datapb.QueryImportResponse{
|
|
|
|
Status: status,
|
2024-04-01 20:09:13 +08:00
|
|
|
Slots: node.importScheduler.Slots(),
|
2024-01-31 20:45:04 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// query import
|
2024-04-01 20:09:13 +08:00
|
|
|
task := node.importTaskMgr.Get(req.GetTaskID())
|
2024-06-07 14:17:20 +08:00
|
|
|
if task == nil {
|
|
|
|
status = merr.Status(importv2.WrapTaskNotFoundError(req.GetTaskID()))
|
2024-01-31 20:45:04 +08:00
|
|
|
}
|
2024-03-01 18:31:02 +08:00
|
|
|
log.RatedInfo(10, "datanode query import", zap.String("state", task.GetState().String()),
|
2024-01-31 20:45:04 +08:00
|
|
|
zap.String("reason", task.GetReason()))
|
|
|
|
return &datapb.QueryImportResponse{
|
2024-06-07 14:17:20 +08:00
|
|
|
Status: status,
|
|
|
|
TaskID: task.GetTaskID(),
|
|
|
|
State: task.GetState(),
|
|
|
|
Reason: task.GetReason(),
|
|
|
|
ImportSegmentsInfo: task.(interface {
|
|
|
|
GetSegmentsInfo() []*datapb.ImportSegmentInfo
|
|
|
|
}).GetSegmentsInfo(),
|
2024-01-31 20:45:04 +08:00
|
|
|
}, nil
|
2023-12-04 19:56:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (node *DataNode) DropImport(ctx context.Context, req *datapb.DropImportRequest) (*commonpb.Status, error) {
|
2024-01-31 20:45:04 +08:00
|
|
|
log := log.Ctx(ctx).With(zap.Int64("taskID", req.GetTaskID()),
|
|
|
|
zap.Int64("jobID", req.GetJobID()))
|
|
|
|
|
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
|
|
|
}
|
|
|
|
|
2024-04-01 20:09:13 +08:00
|
|
|
node.importTaskMgr.Remove(req.GetTaskID())
|
2024-01-31 20:45:04 +08:00
|
|
|
|
|
|
|
log.Info("datanode drop import done")
|
|
|
|
|
|
|
|
return merr.Success(), nil
|
2023-12-04 19:56:35 +08:00
|
|
|
}
|
2024-05-17 18:19:38 +08:00
|
|
|
|
|
|
|
func (node *DataNode) QuerySlot(ctx context.Context, req *datapb.QuerySlotRequest) (*datapb.QuerySlotResponse, error) {
|
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return &datapb.QuerySlotResponse{
|
|
|
|
Status: merr.Status(err),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return &datapb.QuerySlotResponse{
|
|
|
|
Status: merr.Success(),
|
2024-06-14 14:34:01 +08:00
|
|
|
NumSlots: node.compactionExecutor.Slots(),
|
2024-05-17 18:19:38 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2024-06-05 20:27:51 +08:00
|
|
|
|
|
|
|
func (node *DataNode) DropCompactionPlan(ctx context.Context, req *datapb.DropCompactionPlanRequest) (*commonpb.Status, error) {
|
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
|
|
|
}
|
|
|
|
|
2024-06-14 14:34:01 +08:00
|
|
|
node.compactionExecutor.RemoveTask(req.GetPlanID())
|
2024-06-05 20:27:51 +08:00
|
|
|
log.Ctx(ctx).Info("DropCompactionPlans success", zap.Int64("planID", req.GetPlanID()))
|
|
|
|
return merr.Success(), nil
|
|
|
|
}
|