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-06-27 11:24:05 +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-06-25 11:16:02 +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"
|
2023-11-30 14:30:28 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/datanode/io"
|
2024-06-27 11:24:05 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/datanode/metacache"
|
|
|
|
"github.com/milvus-io/milvus/internal/datanode/util"
|
|
|
|
"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-06-27 11:24:05 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/storage"
|
2024-06-08 11:17:52 +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-06-27 11:24:05 +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"
|
2023-09-21 09:45:27 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/tsoutil"
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
metricType, err := metricsinfo.ParseMetricType(req.Request)
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("DataNode.GetMetrics failed to parse metric type",
|
2024-02-21 11:54:53 +08:00
|
|
|
zap.Int64("nodeID", node.GetNodeID()),
|
2022-12-12 10:57:22 +08:00
|
|
|
zap.String("req", req.Request),
|
|
|
|
zap.Error(err))
|
|
|
|
|
|
|
|
return &milvuspb.GetMetricsResponse{
|
2023-03-28 19:04:00 +08:00
|
|
|
Status: merr.Status(err),
|
2022-12-12 10:57:22 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if metricType == metricsinfo.SystemInfoMetrics {
|
|
|
|
systemInfoMetrics, err := node.getSystemInfoMetrics(ctx, req)
|
|
|
|
if 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
|
|
|
|
}
|
|
|
|
|
|
|
|
return systemInfoMetrics, nil
|
|
|
|
}
|
|
|
|
|
2023-01-04 17:39:35 +08:00
|
|
|
log.RatedWarn(60, "DataNode.GetMetrics failed, request metric type is not implemented yet",
|
2024-02-21 11:54:53 +08:00
|
|
|
zap.Int64("nodeID", node.GetNodeID()),
|
2022-12-12 10:57:22 +08:00
|
|
|
zap.String("req", req.Request),
|
|
|
|
zap.String("metric_type", metricType))
|
|
|
|
|
|
|
|
return &milvuspb.GetMetricsResponse{
|
2023-03-28 19:04:00 +08:00
|
|
|
Status: merr.Status(merr.WrapErrMetricNotFound(metricType)),
|
2022-12-12 10:57:22 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2024-06-25 20:22:03 +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-25 20:22:03 +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-06-25 20:22:03 +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-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-06-25 11:16:02 +08:00
|
|
|
var task compaction.Compactor
|
|
|
|
binlogIO := io.NewBinlogIO(node.chunkManager)
|
2023-11-30 14:30:28 +08:00
|
|
|
switch req.GetType() {
|
|
|
|
case datapb.CompactionType_Level0DeleteCompaction:
|
2024-06-25 11:16:02 +08:00
|
|
|
task = compaction.NewLevelZeroCompactionTask(
|
2024-01-23 10:37:00 +08:00
|
|
|
taskCtx,
|
2023-11-30 14:30:28 +08:00
|
|
|
binlogIO,
|
|
|
|
node.allocator,
|
2024-06-25 20:22:03 +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-06-25 11:16:02 +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
|
|
|
node.allocator,
|
|
|
|
req,
|
|
|
|
)
|
|
|
|
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
|
|
|
|
|
|
|
node.compactionExecutor.execute(task)
|
2023-10-11 21:01:35 +08:00
|
|
|
return merr.Success(), 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-07-01 19:32:07 +08:00
|
|
|
|
|
|
|
results := make([]*datapb.CompactionPlanResult, 0)
|
|
|
|
if req.GetPlanID() != 0 {
|
|
|
|
result := node.compactionExecutor.getCompactionResult(req.GetPlanID())
|
|
|
|
results = append(results, result)
|
|
|
|
} else {
|
|
|
|
results = node.compactionExecutor.getAllCompactionResults()
|
|
|
|
}
|
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-06-27 11:24:05 +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-06-27 11:24:05 +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 {
|
|
|
|
node.compactionExecutor.discardPlan(req.GetChannelName())
|
|
|
|
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{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
missingSegments := ds.metacache.DetectMissingSegments(allSegments)
|
|
|
|
|
|
|
|
newSegments := make([]*datapb.SyncSegmentInfo, 0, len(missingSegments))
|
|
|
|
futures := make([]*conc.Future[any], 0, len(missingSegments))
|
|
|
|
|
|
|
|
for _, segID := range missingSegments {
|
|
|
|
segID := segID
|
|
|
|
newSeg := req.GetSegmentInfos()[segID]
|
|
|
|
newSegments = append(newSegments, newSeg)
|
|
|
|
future := io.GetOrCreateStatsPool().Submit(func() (any, error) {
|
|
|
|
var val *metacache.BloomFilterSet
|
|
|
|
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 := util.LoadStats(ctx, node.chunkManager, ds.metacache.Schema(), newSeg.GetSegmentId(), []*datapb.FieldBinlog{newSeg.GetPkStatsLog()})
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("failed to load segment stats log", zap.Error(err))
|
|
|
|
return val, err
|
|
|
|
}
|
|
|
|
val = metacache.NewBloomFilterSet(pks...)
|
|
|
|
return val, nil
|
|
|
|
})
|
|
|
|
futures = append(futures, future)
|
|
|
|
}
|
|
|
|
|
|
|
|
err := conc.AwaitAll(futures...)
|
|
|
|
if err != nil {
|
|
|
|
return merr.Status(err), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
newSegmentsBF := lo.Map(futures, func(future *conc.Future[any], _ int) *metacache.BloomFilterSet {
|
|
|
|
return future.Value().(*metacache.BloomFilterSet)
|
|
|
|
})
|
|
|
|
|
|
|
|
ds.metacache.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-08 11:17:52 +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-08 11:17:52 +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-08 11:17:52 +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-08 11:17:52 +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-08 11:17:52 +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-08 11:17:52 +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-06-25 20:22:03 +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(),
|
|
|
|
NumSlots: Params.DataNodeCfg.SlotCap.GetAsInt64() - int64(node.compactionExecutor.executing.Len()),
|
|
|
|
}, nil
|
|
|
|
}
|