2024-06-10 21:34:08 +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.
|
|
|
|
|
2024-06-05 10:17:50 +08:00
|
|
|
package datacoord
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/cockroachdb/errors"
|
|
|
|
"github.com/samber/lo"
|
|
|
|
"go.opentelemetry.io/otel/trace"
|
2024-10-24 09:55:28 +08:00
|
|
|
"go.uber.org/atomic"
|
2024-06-05 10:17:50 +08:00
|
|
|
"go.uber.org/zap"
|
2024-10-08 11:23:23 +08:00
|
|
|
"google.golang.org/protobuf/proto"
|
2024-06-05 10:17:50 +08:00
|
|
|
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
|
2024-08-22 10:06:56 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/datacoord/allocator"
|
2024-08-22 16:02:56 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/datacoord/session"
|
2024-06-05 10:17:50 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
2024-07-11 21:39:36 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/common"
|
2024-06-05 10:17:50 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/log"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/merr"
|
2024-09-26 20:19:14 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
2024-06-05 10:17:50 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ CompactionTask = (*l0CompactionTask)(nil)
|
|
|
|
|
|
|
|
type l0CompactionTask struct {
|
2024-10-24 09:55:28 +08:00
|
|
|
taskProto atomic.Value // *datapb.CompactionTask
|
|
|
|
plan *datapb.CompactionPlan
|
|
|
|
result *datapb.CompactionPlanResult
|
2024-07-17 13:23:42 +08:00
|
|
|
|
|
|
|
span trace.Span
|
2024-08-22 10:06:56 +08:00
|
|
|
allocator allocator.Allocator
|
2024-08-22 16:02:56 +08:00
|
|
|
sessions session.DataNodeManager
|
2024-07-17 13:23:42 +08:00
|
|
|
meta CompactionMeta
|
2024-09-26 20:19:14 +08:00
|
|
|
|
|
|
|
slotUsage int64
|
|
|
|
}
|
|
|
|
|
2024-10-24 09:55:28 +08:00
|
|
|
func (t *l0CompactionTask) GetTaskProto() *datapb.CompactionTask {
|
|
|
|
task := t.taskProto.Load()
|
|
|
|
if task == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return task.(*datapb.CompactionTask)
|
|
|
|
}
|
|
|
|
|
2024-09-26 20:19:14 +08:00
|
|
|
func newL0CompactionTask(t *datapb.CompactionTask, allocator allocator.Allocator, meta CompactionMeta, session session.DataNodeManager) *l0CompactionTask {
|
2024-10-24 09:55:28 +08:00
|
|
|
task := &l0CompactionTask{
|
|
|
|
allocator: allocator,
|
|
|
|
meta: meta,
|
|
|
|
sessions: session,
|
|
|
|
slotUsage: paramtable.Get().DataCoordCfg.L0DeleteCompactionSlotUsage.GetAsInt64(),
|
2024-09-26 20:19:14 +08:00
|
|
|
}
|
2024-10-24 09:55:28 +08:00
|
|
|
task.taskProto.Store(t)
|
|
|
|
return task
|
2024-06-05 10:17:50 +08:00
|
|
|
}
|
|
|
|
|
2024-07-16 15:57:42 +08:00
|
|
|
// Note: return True means exit this state machine.
|
|
|
|
// ONLY return True for processCompleted or processFailed
|
2024-06-05 10:17:50 +08:00
|
|
|
func (t *l0CompactionTask) Process() bool {
|
2024-10-24 09:55:28 +08:00
|
|
|
switch t.GetTaskProto().GetState() {
|
2024-06-05 10:17:50 +08:00
|
|
|
case datapb.CompactionTaskState_pipelining:
|
|
|
|
return t.processPipelining()
|
|
|
|
case datapb.CompactionTaskState_executing:
|
|
|
|
return t.processExecuting()
|
|
|
|
case datapb.CompactionTaskState_meta_saved:
|
|
|
|
return t.processMetaSaved()
|
|
|
|
case datapb.CompactionTaskState_completed:
|
|
|
|
return t.processCompleted()
|
|
|
|
case datapb.CompactionTaskState_failed:
|
|
|
|
return t.processFailed()
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *l0CompactionTask) processPipelining() bool {
|
|
|
|
if t.NeedReAssignNodeID() {
|
|
|
|
return false
|
|
|
|
}
|
2024-07-11 21:39:36 +08:00
|
|
|
|
2024-10-24 09:55:28 +08:00
|
|
|
log := log.With(zap.Int64("triggerID", t.GetTaskProto().GetTriggerID()), zap.Int64("nodeID", t.GetTaskProto().GetNodeID()))
|
2024-06-05 10:17:50 +08:00
|
|
|
var err error
|
|
|
|
t.plan, err = t.BuildCompactionRequest()
|
|
|
|
if err != nil {
|
2024-07-11 21:39:36 +08:00
|
|
|
log.Warn("l0CompactionTask failed to build compaction request", zap.Error(err))
|
|
|
|
err = t.updateAndSaveTaskMeta(setState(datapb.CompactionTaskState_failed), setFailReason(err.Error()))
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("l0CompactionTask failed to updateAndSaveTaskMeta", zap.Error(err))
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return t.processFailed()
|
2024-06-05 10:17:50 +08:00
|
|
|
}
|
2024-07-11 21:39:36 +08:00
|
|
|
|
2024-10-24 09:55:28 +08:00
|
|
|
err = t.sessions.Compaction(context.TODO(), t.GetTaskProto().GetNodeID(), t.GetPlan())
|
2024-06-05 10:17:50 +08:00
|
|
|
if err != nil {
|
2024-10-24 09:55:28 +08:00
|
|
|
log.Warn("l0CompactionTask failed to notify compaction tasks to DataNode", zap.Int64("planID", t.GetTaskProto().GetPlanID()), zap.Error(err))
|
2024-06-25 10:08:03 +08:00
|
|
|
t.updateAndSaveTaskMeta(setState(datapb.CompactionTaskState_pipelining), setNodeID(NullNodeID))
|
2024-06-05 10:17:50 +08:00
|
|
|
return false
|
|
|
|
}
|
2024-07-11 21:39:36 +08:00
|
|
|
|
2024-06-05 10:17:50 +08:00
|
|
|
t.updateAndSaveTaskMeta(setState(datapb.CompactionTaskState_executing))
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *l0CompactionTask) processExecuting() bool {
|
2024-10-24 09:55:28 +08:00
|
|
|
log := log.With(zap.Int64("planID", t.GetTaskProto().GetPlanID()), zap.Int64("nodeID", t.GetTaskProto().GetNodeID()))
|
|
|
|
result, err := t.sessions.GetCompactionPlanResult(t.GetTaskProto().GetNodeID(), t.GetTaskProto().GetPlanID())
|
2024-06-05 10:17:50 +08:00
|
|
|
if err != nil || result == nil {
|
|
|
|
if errors.Is(err, merr.ErrNodeNotFound) {
|
2024-06-25 10:08:03 +08:00
|
|
|
t.updateAndSaveTaskMeta(setState(datapb.CompactionTaskState_pipelining), setNodeID(NullNodeID))
|
2024-06-05 10:17:50 +08:00
|
|
|
}
|
2024-07-11 21:39:36 +08:00
|
|
|
log.Warn("l0CompactionTask failed to get compaction result", zap.Error(err))
|
2024-06-05 10:17:50 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
switch result.GetState() {
|
2024-06-10 21:34:08 +08:00
|
|
|
case datapb.CompactionTaskState_completed:
|
2024-06-05 10:17:50 +08:00
|
|
|
t.result = result
|
2024-07-11 21:39:36 +08:00
|
|
|
if err := t.saveSegmentMeta(); err != nil {
|
|
|
|
log.Warn("l0CompactionTask failed to save segment meta", zap.Error(err))
|
2024-06-05 10:17:50 +08:00
|
|
|
return false
|
|
|
|
}
|
2024-07-11 21:39:36 +08:00
|
|
|
|
|
|
|
if err := t.updateAndSaveTaskMeta(setState(datapb.CompactionTaskState_meta_saved)); err != nil {
|
2024-07-29 10:53:48 +08:00
|
|
|
log.Warn("l0CompactionTask failed to save task meta_saved state", zap.Error(err))
|
2024-07-11 21:39:36 +08:00
|
|
|
return false
|
2024-06-05 10:17:50 +08:00
|
|
|
}
|
2024-07-11 21:39:36 +08:00
|
|
|
return t.processMetaSaved()
|
2024-06-10 21:34:08 +08:00
|
|
|
case datapb.CompactionTaskState_failed:
|
2024-07-11 21:39:36 +08:00
|
|
|
if err := t.updateAndSaveTaskMeta(setState(datapb.CompactionTaskState_failed)); err != nil {
|
2024-07-29 10:53:48 +08:00
|
|
|
log.Warn("l0CompactionTask failed to set task failed state", zap.Error(err))
|
2024-07-11 21:39:36 +08:00
|
|
|
return false
|
2024-06-10 21:34:08 +08:00
|
|
|
}
|
2024-07-11 21:39:36 +08:00
|
|
|
return t.processFailed()
|
2024-06-05 10:17:50 +08:00
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-08-09 14:24:18 +08:00
|
|
|
func (t *l0CompactionTask) processMetaSaved() bool {
|
|
|
|
err := t.updateAndSaveTaskMeta(setState(datapb.CompactionTaskState_completed))
|
|
|
|
if err != nil {
|
2024-10-24 09:55:28 +08:00
|
|
|
log.Warn("l0CompactionTask unable to processMetaSaved", zap.Int64("planID", t.GetTaskProto().GetPlanID()), zap.Error(err))
|
2024-08-09 14:24:18 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return t.processCompleted()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *l0CompactionTask) processCompleted() bool {
|
|
|
|
if t.hasAssignedWorker() {
|
2024-10-24 09:55:28 +08:00
|
|
|
err := t.sessions.DropCompactionPlan(t.GetTaskProto().GetNodeID(), &datapb.DropCompactionPlanRequest{
|
|
|
|
PlanID: t.GetTaskProto().GetPlanID(),
|
2024-08-09 14:24:18 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
2024-10-24 09:55:28 +08:00
|
|
|
log.Warn("l0CompactionTask unable to drop compaction plan", zap.Int64("planID", t.GetTaskProto().GetPlanID()), zap.Error(err))
|
2024-08-09 14:24:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t.resetSegmentCompacting()
|
|
|
|
UpdateCompactionSegmentSizeMetrics(t.result.GetSegments())
|
2024-10-24 09:55:28 +08:00
|
|
|
log.Info("l0CompactionTask processCompleted done", zap.Int64("planID", t.GetTaskProto().GetPlanID()))
|
2024-08-09 14:24:18 +08:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *l0CompactionTask) processFailed() bool {
|
|
|
|
if t.hasAssignedWorker() {
|
2024-10-24 09:55:28 +08:00
|
|
|
err := t.sessions.DropCompactionPlan(t.GetTaskProto().GetNodeID(), &datapb.DropCompactionPlanRequest{
|
|
|
|
PlanID: t.GetTaskProto().GetPlanID(),
|
2024-08-09 14:24:18 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
2024-10-24 09:55:28 +08:00
|
|
|
log.Warn("l0CompactionTask processFailed unable to drop compaction plan", zap.Int64("planID", t.GetTaskProto().GetPlanID()), zap.Error(err))
|
2024-08-09 14:24:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t.resetSegmentCompacting()
|
2024-10-17 18:05:23 +08:00
|
|
|
err := t.updateAndSaveTaskMeta(setState(datapb.CompactionTaskState_cleaned))
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("l0CompactionTask failed to updateAndSaveTaskMeta", zap.Error(err))
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-10-24 09:55:28 +08:00
|
|
|
log.Info("l0CompactionTask processFailed done", zap.Int64("taskID", t.GetTaskProto().GetTriggerID()), zap.Int64("planID", t.GetTaskProto().GetPlanID()))
|
2024-08-09 14:24:18 +08:00
|
|
|
return true
|
2024-06-05 10:17:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *l0CompactionTask) GetResult() *datapb.CompactionPlanResult {
|
|
|
|
return t.result
|
|
|
|
}
|
|
|
|
|
2024-08-09 14:24:18 +08:00
|
|
|
func (t *l0CompactionTask) SetResult(result *datapb.CompactionPlanResult) {
|
|
|
|
t.result = result
|
2024-06-05 10:17:50 +08:00
|
|
|
}
|
|
|
|
|
2024-08-09 14:24:18 +08:00
|
|
|
func (t *l0CompactionTask) SetTask(task *datapb.CompactionTask) {
|
2024-10-24 09:55:28 +08:00
|
|
|
t.taskProto.Store(task)
|
2024-06-05 10:17:50 +08:00
|
|
|
}
|
|
|
|
|
2024-08-09 14:24:18 +08:00
|
|
|
func (t *l0CompactionTask) GetSpan() trace.Span {
|
|
|
|
return t.span
|
2024-06-05 10:17:50 +08:00
|
|
|
}
|
|
|
|
|
2024-08-09 14:24:18 +08:00
|
|
|
func (t *l0CompactionTask) SetSpan(span trace.Span) {
|
|
|
|
t.span = span
|
2024-06-05 10:17:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *l0CompactionTask) EndSpan() {
|
|
|
|
if t.span != nil {
|
|
|
|
t.span.End()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-09 14:24:18 +08:00
|
|
|
func (t *l0CompactionTask) SetPlan(plan *datapb.CompactionPlan) {
|
|
|
|
t.plan = plan
|
2024-06-05 10:17:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *l0CompactionTask) GetPlan() *datapb.CompactionPlan {
|
|
|
|
return t.plan
|
|
|
|
}
|
|
|
|
|
2024-08-09 14:24:18 +08:00
|
|
|
func (t *l0CompactionTask) GetLabel() string {
|
2024-10-24 09:55:28 +08:00
|
|
|
return fmt.Sprintf("%d-%s", t.GetTaskProto().PartitionID, t.GetTaskProto().GetChannel())
|
2024-08-09 14:24:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *l0CompactionTask) NeedReAssignNodeID() bool {
|
2024-10-24 09:55:28 +08:00
|
|
|
return t.GetTaskProto().GetState() == datapb.CompactionTaskState_pipelining && (!t.hasAssignedWorker())
|
2024-06-05 10:17:50 +08:00
|
|
|
}
|
|
|
|
|
2024-08-09 14:24:18 +08:00
|
|
|
func (t *l0CompactionTask) ShadowClone(opts ...compactionTaskOpt) *datapb.CompactionTask {
|
2024-10-24 09:55:28 +08:00
|
|
|
taskClone := proto.Clone(t.GetTaskProto()).(*datapb.CompactionTask)
|
2024-08-09 14:24:18 +08:00
|
|
|
for _, opt := range opts {
|
|
|
|
opt(taskClone)
|
|
|
|
}
|
|
|
|
return taskClone
|
|
|
|
}
|
|
|
|
|
2024-06-05 10:17:50 +08:00
|
|
|
func (t *l0CompactionTask) BuildCompactionRequest() (*datapb.CompactionPlan, error) {
|
2024-08-22 10:06:56 +08:00
|
|
|
beginLogID, _, err := t.allocator.AllocN(1)
|
2024-07-17 13:23:42 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-10-24 09:55:28 +08:00
|
|
|
taskProto := t.taskProto.Load().(*datapb.CompactionTask)
|
2024-06-05 10:17:50 +08:00
|
|
|
plan := &datapb.CompactionPlan{
|
2024-10-24 09:55:28 +08:00
|
|
|
PlanID: taskProto.GetPlanID(),
|
|
|
|
StartTime: taskProto.GetStartTime(),
|
|
|
|
TimeoutInSeconds: taskProto.GetTimeoutInSeconds(),
|
|
|
|
Type: taskProto.GetType(),
|
|
|
|
Channel: taskProto.GetChannel(),
|
|
|
|
CollectionTtl: taskProto.GetCollectionTtl(),
|
|
|
|
TotalRows: taskProto.GetTotalRows(),
|
|
|
|
Schema: taskProto.GetSchema(),
|
2024-07-17 13:23:42 +08:00
|
|
|
BeginLogID: beginLogID,
|
2024-09-26 20:19:14 +08:00
|
|
|
SlotUsage: t.GetSlotUsage(),
|
2024-06-05 10:17:50 +08:00
|
|
|
}
|
|
|
|
|
2024-10-24 09:55:28 +08:00
|
|
|
log := log.With(zap.Int64("taskID", taskProto.GetTriggerID()), zap.Int64("planID", plan.GetPlanID()))
|
|
|
|
for _, segID := range taskProto.GetInputSegments() {
|
2024-11-26 19:46:34 +08:00
|
|
|
segInfo := t.meta.GetHealthySegment(context.TODO(), segID)
|
2024-06-05 10:17:50 +08:00
|
|
|
if segInfo == nil {
|
|
|
|
return nil, merr.WrapErrSegmentNotFound(segID)
|
|
|
|
}
|
|
|
|
plan.SegmentBinlogs = append(plan.SegmentBinlogs, &datapb.CompactionSegmentBinlogs{
|
|
|
|
SegmentID: segID,
|
|
|
|
CollectionID: segInfo.GetCollectionID(),
|
|
|
|
PartitionID: segInfo.GetPartitionID(),
|
|
|
|
Level: segInfo.GetLevel(),
|
|
|
|
InsertChannel: segInfo.GetInsertChannel(),
|
|
|
|
Deltalogs: segInfo.GetDeltalogs(),
|
2024-09-02 14:19:03 +08:00
|
|
|
IsSorted: segInfo.GetIsSorted(),
|
2024-06-05 10:17:50 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select sealed L1 segments for LevelZero compaction that meets the condition:
|
|
|
|
// dmlPos < triggerInfo.pos
|
2024-11-26 19:46:34 +08:00
|
|
|
sealedSegments := t.meta.SelectSegments(context.TODO(), WithCollection(taskProto.GetCollectionID()), SegmentFilterFunc(func(info *SegmentInfo) bool {
|
2024-10-24 09:55:28 +08:00
|
|
|
return (taskProto.GetPartitionID() == common.AllPartitionsID || info.GetPartitionID() == taskProto.GetPartitionID()) &&
|
2024-06-05 10:17:50 +08:00
|
|
|
info.GetInsertChannel() == plan.GetChannel() &&
|
|
|
|
isFlushState(info.GetState()) &&
|
|
|
|
!info.GetIsImporting() &&
|
|
|
|
info.GetLevel() != datapb.SegmentLevel_L0 &&
|
2024-10-24 09:55:28 +08:00
|
|
|
info.GetStartPosition().GetTimestamp() < taskProto.GetPos().GetTimestamp()
|
2024-06-05 10:17:50 +08:00
|
|
|
}))
|
|
|
|
|
|
|
|
if len(sealedSegments) == 0 {
|
2024-10-29 06:28:24 +08:00
|
|
|
// TODO fast finish l0 segment, just drop l0 segment
|
2024-06-05 10:17:50 +08:00
|
|
|
log.Info("l0Compaction available non-L0 Segments is empty ")
|
2024-10-24 09:55:28 +08:00
|
|
|
return nil, errors.Errorf("Selected zero L1/L2 segments for the position=%v", taskProto.GetPos())
|
2024-06-05 10:17:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sealedSegBinlogs := lo.Map(sealedSegments, func(info *SegmentInfo, _ int) *datapb.CompactionSegmentBinlogs {
|
|
|
|
return &datapb.CompactionSegmentBinlogs{
|
|
|
|
SegmentID: info.GetID(),
|
|
|
|
Field2StatslogPaths: info.GetStatslogs(),
|
|
|
|
InsertChannel: info.GetInsertChannel(),
|
|
|
|
Level: info.GetLevel(),
|
|
|
|
CollectionID: info.GetCollectionID(),
|
|
|
|
PartitionID: info.GetPartitionID(),
|
2024-09-02 14:19:03 +08:00
|
|
|
IsSorted: info.GetIsSorted(),
|
2024-06-05 10:17:50 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
plan.SegmentBinlogs = append(plan.SegmentBinlogs, sealedSegBinlogs...)
|
2024-07-16 15:57:42 +08:00
|
|
|
log.Info("l0CompactionTask refreshed level zero compaction plan",
|
2024-10-24 09:55:28 +08:00
|
|
|
zap.Any("target position", taskProto.GetPos()),
|
2024-06-05 10:17:50 +08:00
|
|
|
zap.Any("target segments count", len(sealedSegBinlogs)))
|
|
|
|
return plan, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *l0CompactionTask) resetSegmentCompacting() {
|
2024-11-26 19:46:34 +08:00
|
|
|
t.meta.SetSegmentsCompacting(context.TODO(), t.GetTaskProto().GetInputSegments(), false)
|
2024-06-05 10:17:50 +08:00
|
|
|
}
|
|
|
|
|
2024-08-09 14:24:18 +08:00
|
|
|
func (t *l0CompactionTask) hasAssignedWorker() bool {
|
2024-10-24 09:55:28 +08:00
|
|
|
return t.GetTaskProto().GetNodeID() != 0 && t.GetTaskProto().GetNodeID() != NullNodeID
|
2024-06-05 10:17:50 +08:00
|
|
|
}
|
|
|
|
|
2024-08-09 14:24:18 +08:00
|
|
|
func (t *l0CompactionTask) SetNodeID(id UniqueID) error {
|
|
|
|
return t.updateAndSaveTaskMeta(setNodeID(id))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *l0CompactionTask) SaveTaskMeta() error {
|
2024-10-24 09:55:28 +08:00
|
|
|
return t.saveTaskMeta(t.GetTaskProto())
|
2024-08-09 14:24:18 +08:00
|
|
|
}
|
|
|
|
|
2024-06-05 10:17:50 +08:00
|
|
|
func (t *l0CompactionTask) updateAndSaveTaskMeta(opts ...compactionTaskOpt) error {
|
|
|
|
task := t.ShadowClone(opts...)
|
|
|
|
err := t.saveTaskMeta(task)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-10-24 09:55:28 +08:00
|
|
|
t.SetTask(task)
|
2024-06-05 10:17:50 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *l0CompactionTask) saveTaskMeta(task *datapb.CompactionTask) error {
|
2024-11-26 19:46:34 +08:00
|
|
|
return t.meta.SaveCompactionTask(context.TODO(), task)
|
2024-06-05 10:17:50 +08:00
|
|
|
}
|
|
|
|
|
2024-07-11 21:39:36 +08:00
|
|
|
func (t *l0CompactionTask) saveSegmentMeta() error {
|
2024-06-05 10:17:50 +08:00
|
|
|
result := t.result
|
|
|
|
var operators []UpdateOperator
|
|
|
|
for _, seg := range result.GetSegments() {
|
2024-09-19 10:57:12 +08:00
|
|
|
operators = append(operators, AddBinlogsOperator(seg.GetSegmentID(), nil, nil, seg.GetDeltalogs(), nil))
|
2024-06-05 10:17:50 +08:00
|
|
|
}
|
|
|
|
|
2024-10-24 09:55:28 +08:00
|
|
|
for _, segID := range t.GetTaskProto().InputSegments {
|
2024-07-17 13:03:41 +08:00
|
|
|
operators = append(operators, UpdateStatusOperator(segID, commonpb.SegmentState_Dropped), UpdateCompactedOperator(segID))
|
2024-06-05 10:17:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Info("meta update: update segments info for level zero compaction",
|
2024-10-24 09:55:28 +08:00
|
|
|
zap.Int64("planID", t.GetTaskProto().GetPlanID()),
|
2024-06-05 10:17:50 +08:00
|
|
|
)
|
2024-07-11 21:39:36 +08:00
|
|
|
|
2024-11-26 19:46:34 +08:00
|
|
|
return t.meta.UpdateSegmentsInfo(context.TODO(), operators...)
|
2024-06-05 10:17:50 +08:00
|
|
|
}
|
2024-09-26 20:19:14 +08:00
|
|
|
|
|
|
|
func (t *l0CompactionTask) GetSlotUsage() int64 {
|
|
|
|
return t.slotUsage
|
|
|
|
}
|