github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/wal/walinfo.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 wal
    16  
    17  import (
    18  	"sync"
    19  
    20  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/logstore/entry"
    21  )
    22  
    23  type walInfo struct {
    24  	ucLsnTidMap map[uint64]string
    25  	ucmu        sync.RWMutex
    26  	cTidLsnMap  map[string]uint64
    27  	cmu         sync.RWMutex
    28  }
    29  
    30  func newWalInfo() *walInfo {
    31  	return &walInfo{
    32  		ucLsnTidMap: make(map[uint64]string),
    33  		ucmu:        sync.RWMutex{},
    34  		cTidLsnMap:  make(map[string]uint64),
    35  		cmu:         sync.RWMutex{},
    36  	}
    37  }
    38  
    39  func (w *walInfo) logEntry(info *entry.Info) {
    40  	if info.Group == GroupPrepare {
    41  		w.cmu.Lock()
    42  		w.cTidLsnMap[info.TxnId] = info.GroupLSN
    43  		w.cmu.Unlock()
    44  	}
    45  	if info.Group == GroupUC {
    46  		w.ucmu.Lock()
    47  		w.ucLsnTidMap[info.GroupLSN] = info.Uncommits
    48  		w.ucmu.Unlock()
    49  	}
    50  }
    51  
    52  func (w *walInfo) onLogInfo(items ...any) {
    53  	for _, item := range items {
    54  		e := item.(*entryWithInfo)
    55  		w.logEntry(e.info.(*entry.Info))
    56  	}
    57  }