github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/catalog/tablemvccnode.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 catalog
    16  
    17  import (
    18  	"fmt"
    19  	"io"
    20  	"sync/atomic"
    21  )
    22  
    23  type TableMVCCNode struct {
    24  	// history schema
    25  	Schema *Schema
    26  }
    27  
    28  func NewEmptyTableMVCCNode() *TableMVCCNode {
    29  	return &TableMVCCNode{}
    30  }
    31  
    32  func (e *TableMVCCNode) CloneAll() *TableMVCCNode {
    33  	return &TableMVCCNode{
    34  		Schema: e.Schema.Clone(),
    35  	}
    36  }
    37  
    38  func (e *TableMVCCNode) CloneData() *TableMVCCNode {
    39  	return e.CloneAll()
    40  }
    41  
    42  func (e *TableMVCCNode) String() string {
    43  	return fmt.Sprintf("schema.v%d.s%d.c%d", e.Schema.Version, e.Schema.Extra.NextColSeqnum, len(e.Schema.ColDefs))
    44  }
    45  
    46  // for create drop in one txn
    47  func (e *TableMVCCNode) Update(un *TableMVCCNode) {
    48  	e.Schema = un.Schema
    49  }
    50  
    51  func (e *TableMVCCNode) IdempotentUpdate(un *TableMVCCNode) {
    52  	e.Schema = un.Schema
    53  }
    54  func (e *TableMVCCNode) WriteTo(w io.Writer) (n int64, err error) {
    55  	var schemaBuf []byte
    56  	if schemaBuf, err = e.Schema.Marshal(); err != nil {
    57  		return
    58  	}
    59  	if _, err = w.Write(schemaBuf); err != nil {
    60  		return
    61  	}
    62  	n += int64(len(schemaBuf))
    63  	return
    64  }
    65  
    66  func (e *TableMVCCNode) ReadFromWithVersion(r io.Reader, ver uint16) (n int64, err error) {
    67  	e.Schema = NewEmptySchema("")
    68  	if n, err = e.Schema.ReadFromWithVersion(r, ver); err != nil {
    69  		return
    70  	}
    71  	return
    72  }
    73  
    74  type TableNode struct {
    75  	// The latest schema. A shortcut to the schema in the last mvvcnode.
    76  	schema atomic.Pointer[Schema]
    77  }
    78  
    79  func (node *TableNode) WriteTo(w io.Writer) (n int64, err error) {
    80  	// do not writeTo inherit from mvvcnode in replay phrase
    81  	// reference: function onReplayCreateTable and onReplayUpdateTable
    82  	return
    83  }
    84  
    85  func (node *TableNode) ReadFrom(r io.Reader) (n int64, err error) {
    86  	// do not readFrom, inherit from mvvcnode in replay phrase
    87  	// reference: function onReplayCreateTable and onReplayUpdateTable
    88  	return
    89  }