github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/txn/txnbase/fields.go (about) 1 // Copyright 2022 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 txnbase 16 17 import ( 18 "fmt" 19 20 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/iface/txnif" 21 "go.uber.org/zap" 22 "go.uber.org/zap/zapcore" 23 ) 24 25 func TxnField(txn txnif.AsyncTxn) zap.Field { 26 return zap.Object("txn", txn.(zapcore.ObjectMarshaler)) 27 } 28 29 func TxnMgrField(mgr *TxnManager) zap.Field { 30 return zap.Object("txnmgr", mgr) 31 } 32 33 func (mgr *TxnManager) MarshalLogObject(enc zapcore.ObjectEncoder) (err error) { 34 // TODO 35 return 36 } 37 38 func (txn *Txn) MarshalLogObject(enc zapcore.ObjectEncoder) (err error) { 39 txn.RLock() 40 defer txn.RUnlock() 41 enc.AddString("id", fmt.Sprintf("%X", txn.ID)) 42 //enc.AddString("id", txn.ID) 43 enc.AddString("startTs", txn.StartTS.ToString()) 44 enc.AddString("state", txnif.TxnStrState(txn.State)) 45 if !txn.IsActiveLocked() { 46 enc.AddString("commitTs", txn.CommitTS.ToString()) 47 } 48 return 49 }