github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/logstore/store/partialckp.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 store 16 17 import ( 18 "fmt" 19 "io" 20 21 "github.com/RoaringBitmap/roaring" 22 "github.com/matrixorigin/matrixone/pkg/common/moerr" 23 "github.com/matrixorigin/matrixone/pkg/container/types" 24 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/logstore/entry" 25 ) 26 27 type partialCkpInfo struct { 28 size uint32 29 ckps *roaring.Bitmap 30 } 31 32 func newPartialCkpInfo(size uint32) *partialCkpInfo { 33 return &partialCkpInfo{ 34 ckps: &roaring.Bitmap{}, 35 size: size, 36 } 37 } 38 39 func (info *partialCkpInfo) String() string { 40 return fmt.Sprintf("%s/%d", info.ckps.String(), info.size) 41 } 42 43 func (info *partialCkpInfo) IsAllCheckpointed() bool { 44 return info.size == uint32(info.ckps.GetCardinality()) 45 } 46 47 func (info *partialCkpInfo) MergePartialCkpInfo(o *partialCkpInfo) { 48 if info.size != o.size { 49 panic(moerr.NewInternalErrorNoCtx("logic error %d != %d", info.size, o.size)) 50 } 51 info.ckps.Or(o.ckps) 52 } 53 54 func (info *partialCkpInfo) MergeCommandInfos(cmds *entry.CommandInfo) { 55 if info.size != cmds.Size { 56 panic(moerr.NewInternalErrorNoCtx("logic error %d != %d", info.size, cmds.Size)) 57 } 58 for _, csn := range cmds.CommandIds { 59 info.ckps.Add(csn) 60 } 61 } 62 63 func (info *partialCkpInfo) WriteTo(w io.Writer) (n int64, err error) { 64 if _, err = w.Write(types.EncodeUint32(&info.size)); err != nil { 65 return 66 } 67 n += 4 68 ckpsn, err := info.ckps.WriteTo(w) 69 n += ckpsn 70 if err != nil { 71 return 72 } 73 return 74 } 75 76 func (info *partialCkpInfo) ReadFrom(r io.Reader) (n int64, err error) { 77 if _, err = r.Read(types.EncodeUint32(&info.size)); err != nil { 78 return 79 } 80 n += 4 81 info.ckps = roaring.New() 82 ckpsn, err := info.ckps.ReadFrom(r) 83 n += ckpsn 84 if err != nil { 85 return 86 } 87 return 88 }