Skip to content

Commit

Permalink
dump core if no txn found during prepare commit (#15857)
Browse files Browse the repository at this point in the history
  • Loading branch information
XuPeng-SH committed May 6, 2024
1 parent 1400a68 commit 76e2657
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/vm/engine/tae/catalog/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (

"github.com/matrixorigin/matrixone/pkg/common/moerr"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/logutil"
"github.com/matrixorigin/matrixone/pkg/util/stack"
"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/common"
"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/iface/txnif"
"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/txn/txnbase"
Expand Down Expand Up @@ -87,6 +89,9 @@ func (be *BaseEntryImpl[T]) CreateWithTS(ts types.TS, baseNode T) {
}

func (be *BaseEntryImpl[T]) CreateWithTxn(txn txnif.AsyncTxn, baseNode T) {
if txn == nil {
logutil.Warnf("unexpected txn is nil: %+v", stack.Callers(0))
}
node := &MVCCNode[T]{
EntryMVCCNode: &EntryMVCCNode{
CreatedAt: txnif.UncommitTS,
Expand Down
5 changes: 5 additions & 0 deletions pkg/vm/engine/tae/txn/txnbase/mvccnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"io"

"github.com/matrixorigin/matrixone/pkg/common/moerr"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/containers"
Expand Down Expand Up @@ -407,6 +408,10 @@ func (un *TxnMVCCNode) String() string {
}

func (un *TxnMVCCNode) PrepareCommit() (ts types.TS, err error) {
if un.Txn == nil {
err = moerr.NewTxnNotFoundNoCtx()
return
}
un.Prepare = un.Txn.GetPrepareTS()
ts = un.Prepare
return
Expand Down
17 changes: 17 additions & 0 deletions pkg/vm/engine/tae/txn/txnimpl/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
package txnimpl

import (
"bytes"
"context"
"fmt"
"runtime/trace"
"time"

"github.com/matrixorigin/matrixone/pkg/fileservice"
"github.com/matrixorigin/matrixone/pkg/util"
"go.uber.org/zap"

"github.com/matrixorigin/matrixone/pkg/perfcounter"
Expand Down Expand Up @@ -1443,12 +1445,27 @@ func (tbl *txnTable) PrePrepare() (err error) {
return
}

func (tbl *txnTable) dumpCore(errMsg string) {
var errInfo bytes.Buffer
errInfo.WriteString(fmt.Sprintf("Table: %s", tbl.entry.String()))
errInfo.WriteString(fmt.Sprintf("\nTxn: %s", tbl.store.txn.String()))
errInfo.WriteString(fmt.Sprintf("\nErr: %s", errMsg))
logutil.Error(errInfo.String())
util.EnableCoreDump()
util.CoreDump()
}

func (tbl *txnTable) PrepareCommit() (err error) {
for idx, node := range tbl.txnEntries.entries {
if tbl.txnEntries.IsDeleted(idx) {
continue
}
if err = node.PrepareCommit(); err != nil {
if moerr.IsMoErrCode(err, moerr.ErrTxnNotFound) {
var buf bytes.Buffer
buf.WriteString(fmt.Sprintf("%d/%d No Txn", idx, len(tbl.txnEntries.entries)))
tbl.dumpCore(buf.String())
}
break
}
}
Expand Down

0 comments on commit 76e2657

Please sign in to comment.