github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/tables/jobs/flushdeletes.go (about) 1 // Copyright 2021 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package jobs 16 17 import ( 18 "context" 19 20 "github.com/matrixorigin/matrixone/pkg/common/moerr" 21 "github.com/matrixorigin/matrixone/pkg/perfcounter" 22 23 "github.com/matrixorigin/matrixone/pkg/objectio" 24 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/blockio" 25 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/common" 26 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/containers" 27 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/tasks" 28 ) 29 30 type flushDeletesTask struct { 31 *tasks.BaseTask 32 delta *containers.Batch 33 fs *objectio.ObjectFS 34 name objectio.ObjectName 35 blocks []objectio.BlockObject 36 } 37 38 func NewFlushDeletesTask( 39 ctx *tasks.Context, 40 fs *objectio.ObjectFS, 41 delta *containers.Batch, 42 ) *flushDeletesTask { 43 task := &flushDeletesTask{ 44 fs: fs, 45 delta: delta, 46 } 47 task.BaseTask = tasks.NewBaseTask(task, tasks.IOTask, ctx) 48 return task 49 } 50 51 func (task *flushDeletesTask) Scope() *common.ID { return nil } 52 53 func (task *flushDeletesTask) Execute(ctx context.Context) error { 54 name := objectio.BuildObjectName(objectio.NewSegmentid(), 0) 55 task.name = name 56 writer, err := blockio.NewBlockWriterNew(task.fs.Service, name, 0, nil) 57 if err != nil { 58 return err 59 } 60 cnBatch := containers.ToCNBatch(task.delta) 61 for _, vec := range cnBatch.Vecs { 62 if vec == nil { 63 // this task has been canceled 64 return nil 65 } 66 } 67 _, err = writer.WriteTombstoneBatch(cnBatch) 68 if err != nil { 69 return err 70 } 71 task.blocks, _, err = writer.Sync(ctx) 72 if v := ctx.Value(TestFlushBailoutPos2{}); v != nil { 73 err = moerr.NewInternalErrorNoCtx("test flush deletes bail out") 74 return err 75 } 76 77 perfcounter.Update(ctx, func(counter *perfcounter.CounterSet) { 78 counter.TAE.Block.Flush.Add(1) 79 }) 80 return err 81 }