github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/tables/txnentries/compactblkcmd.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 "encoding/binary" 20 "fmt" 21 "io" 22 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 compactBlockCmd struct { 29 txnbase.BaseCmd 30 from *common.ID 31 to *common.ID 32 txn txnif.AsyncTxn 33 id uint32 34 } 35 36 func newCompactBlockCmd(from, to *common.ID, txn txnif.AsyncTxn, id uint32) *compactBlockCmd { 37 return &compactBlockCmd{ 38 txn: txn, 39 from: from, 40 to: to, 41 id: id, 42 } 43 } 44 func (cmd *compactBlockCmd) GetType() int16 { return CmdCompactBlock } 45 func (cmd *compactBlockCmd) WriteTo(w io.Writer) (n int64, err error) { 46 if err = binary.Write(w, binary.BigEndian, CmdCompactBlock); err != nil { 47 return 48 } 49 if err = binary.Write(w, binary.BigEndian, cmd.id); err != nil { 50 return 51 } 52 if err = binary.Write(w, binary.BigEndian, cmd.from.TableID); err != nil { 53 return 54 } 55 if err = binary.Write(w, binary.BigEndian, cmd.from.SegmentID); err != nil { 56 return 57 } 58 if err = binary.Write(w, binary.BigEndian, cmd.from.BlockID); err != nil { 59 return 60 } 61 62 if err = binary.Write(w, binary.BigEndian, cmd.to.TableID); err != nil { 63 return 64 } 65 if err = binary.Write(w, binary.BigEndian, cmd.to.SegmentID); err != nil { 66 return 67 } 68 if err = binary.Write(w, binary.BigEndian, cmd.to.BlockID); err != nil { 69 return 70 } 71 n = 2 + 4 + 8 + 8 + 8 + 8 + 8 + 8 72 return 73 } 74 func (cmd *compactBlockCmd) ReadFrom(r io.Reader) (n int64, err error) { 75 cmd.from = &common.ID{} 76 if err = binary.Read(r, binary.BigEndian, &cmd.id); err != nil { 77 return 78 } 79 if err = binary.Read(r, binary.BigEndian, &cmd.from.TableID); err != nil { 80 return 81 } 82 if err = binary.Read(r, binary.BigEndian, &cmd.from.SegmentID); err != nil { 83 return 84 } 85 if err = binary.Read(r, binary.BigEndian, &cmd.from.BlockID); err != nil { 86 return 87 } 88 cmd.to = &common.ID{} 89 if err = binary.Read(r, binary.BigEndian, &cmd.to.TableID); err != nil { 90 return 91 } 92 if err = binary.Read(r, binary.BigEndian, &cmd.to.SegmentID); err != nil { 93 return 94 } 95 if err = binary.Read(r, binary.BigEndian, &cmd.to.BlockID); err != nil { 96 return 97 } 98 n = 4 + 8 + 8 + 8 + 8 + 8 + 8 99 return 100 } 101 func (cmd *compactBlockCmd) Marshal() (buf []byte, err error) { 102 var bbuf bytes.Buffer 103 if _, err = cmd.WriteTo(&bbuf); err != nil { 104 return 105 } 106 buf = bbuf.Bytes() 107 return 108 } 109 func (cmd *compactBlockCmd) Unmarshal(buf []byte) (err error) { 110 bbuf := bytes.NewBuffer(buf) 111 _, err = cmd.ReadFrom(bbuf) 112 return 113 } 114 func (cmd *compactBlockCmd) Desc() string { 115 return fmt.Sprintf("CmdName=CPCT;CSN=%d;From=%s;To=%s", cmd.id, cmd.from.BlockString(), cmd.to.BlockString()) 116 } 117 func (cmd *compactBlockCmd) String() string { 118 return fmt.Sprintf("CmdName=CPCT;CSN=%d;From=%s;To=%s", cmd.id, cmd.from.BlockString(), cmd.to.BlockString()) 119 } 120 func (cmd *compactBlockCmd) VerboseString() string { 121 return fmt.Sprintf("CmdName=CPCT;CSN=%d;From=%s;To=%s", cmd.id, cmd.from.BlockString(), cmd.to.BlockString()) 122 } 123 func (cmd *compactBlockCmd) ApplyCommit() {} 124 func (cmd *compactBlockCmd) ApplyRollback() {} 125 func (cmd *compactBlockCmd) SetReplayTxn(_ txnif.AsyncTxn) {}