github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/tables/txnentries/mergeobjectscmd.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 txnentries
    16  
    17  import (
    18  	"bytes"
    19  	"fmt"
    20  	"io"
    21  
    22  	"github.com/matrixorigin/matrixone/pkg/container/types"
    23  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/common"
    24  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/iface/txnif"
    25  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/txn/txnbase"
    26  )
    27  
    28  type mergeObjectsCmd struct {
    29  	txnbase.BaseCmd
    30  	tid         uint64
    31  	droppedObjs []*common.ID
    32  	createdObjs []*common.ID
    33  	txn         txnif.AsyncTxn
    34  	id          uint32
    35  }
    36  
    37  func newMergeBlocksCmd(
    38  	tid uint64,
    39  	droppedObjs, createdObjs []*common.ID,
    40  	txn txnif.AsyncTxn,
    41  	id uint32) *mergeObjectsCmd {
    42  	return &mergeObjectsCmd{
    43  		tid:         tid,
    44  		droppedObjs: droppedObjs,
    45  		createdObjs: createdObjs,
    46  		txn:         txn,
    47  		id:          id,
    48  	}
    49  }
    50  
    51  func (cmd *mergeObjectsCmd) GetType() uint16 { return IOET_WALTxnCommand_Merge }
    52  
    53  func (cmd *mergeObjectsCmd) WriteTo(w io.Writer) (n int64, err error) {
    54  	typ := IOET_WALTxnCommand_Merge
    55  	if _, err = w.Write(types.EncodeUint16(&typ)); err != nil {
    56  		return
    57  	}
    58  	n = 2
    59  	ver := IOET_WALTxnCommand_Merge_CurrVer
    60  	if _, err = w.Write(types.EncodeUint16(&ver)); err != nil {
    61  		return
    62  	}
    63  	n = 2
    64  	return
    65  }
    66  func (cmd *mergeObjectsCmd) ReadFrom(r io.Reader) (n int64, err error) {
    67  	return
    68  }
    69  func (cmd *mergeObjectsCmd) MarshalBinary() (buf []byte, err error) {
    70  	var bbuf bytes.Buffer
    71  	if _, err = cmd.WriteTo(&bbuf); err != nil {
    72  		return
    73  	}
    74  	buf = bbuf.Bytes()
    75  	return
    76  }
    77  func (cmd *mergeObjectsCmd) UnmarshalBinary(buf []byte) (err error) {
    78  	bbuf := bytes.NewBuffer(buf)
    79  	_, err = cmd.ReadFrom(bbuf)
    80  	return
    81  }
    82  
    83  func (cmd *mergeObjectsCmd) Desc() string {
    84  	s := "CmdName=MERGE;From=["
    85  	for _, blk := range cmd.droppedObjs {
    86  		s = fmt.Sprintf("%s %d", s, blk.BlockID)
    87  	}
    88  	s = fmt.Sprintf("%s ];To=[", s)
    89  	for _, blk := range cmd.createdObjs {
    90  		s = fmt.Sprintf("%s %d", s, blk.BlockID)
    91  	}
    92  	s = fmt.Sprintf("%s ]", s)
    93  	return s
    94  }
    95  
    96  func (cmd *mergeObjectsCmd) String() string {
    97  	s := "CmdName=MERGE;From=["
    98  	for _, blk := range cmd.droppedObjs {
    99  		s = fmt.Sprintf("%s %d", s, blk.BlockID)
   100  	}
   101  	s = fmt.Sprintf("%s ];To=[", s)
   102  	for _, blk := range cmd.createdObjs {
   103  		s = fmt.Sprintf("%s %d", s, blk.BlockID)
   104  	}
   105  	s = fmt.Sprintf("%s ]", s)
   106  	return s
   107  }
   108  func (cmd *mergeObjectsCmd) VerboseString() string {
   109  	s := "CmdName=MERGE;From=["
   110  	for _, blk := range cmd.droppedObjs {
   111  		s = fmt.Sprintf("%s %s", s, blk.BlockString())
   112  	}
   113  	s = fmt.Sprintf("%s ];To=[", s)
   114  	for _, blk := range cmd.createdObjs {
   115  		s = fmt.Sprintf("%s %s", s, blk.BlockString())
   116  	}
   117  	s = fmt.Sprintf("%s ]", s)
   118  	return s
   119  }
   120  func (cmd *mergeObjectsCmd) ApplyCommit()                  {}
   121  func (cmd *mergeObjectsCmd) ApplyRollback()                {}
   122  func (cmd *mergeObjectsCmd) SetReplayTxn(_ txnif.AsyncTxn) {}