Skip to content

Commit

Permalink
add deug log
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangxinmeng1 committed Jun 12, 2024
1 parent cef02bf commit 8ba7bc3
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
47 changes: 47 additions & 0 deletions pkg/vm/engine/tae/catalog/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/fileservice"
"github.com/matrixorigin/matrixone/pkg/logutil"
"github.com/matrixorigin/matrixone/pkg/objectio"
v2 "github.com/matrixorigin/matrixone/pkg/util/metric/v2"

Expand All @@ -40,6 +41,8 @@ type ObjectEntry struct {
table *TableEntry
*ObjectNode
objData data.Object

hasPrintedPrepareComapct bool
}

func (entry *ObjectEntry) GetLoaded() bool {
Expand Down Expand Up @@ -647,6 +650,50 @@ func (entry *ObjectEntry) GetPKZoneMap(
}
return stats.SortKeyZoneMap(), nil
}

func (entry *ObjectEntry) CheckPrintPrepareCompact() bool {
entry.RLock()
defer entry.RUnlock()
return entry.CheckPrintPrepareCompactLocked()
}

func (entry *ObjectEntry) CheckPrintPrepareCompactLocked() bool {
lastNode := entry.GetLatestNodeLocked()
startTS := lastNode.GetStart()
return startTS.Physical() < time.Now().UTC().UnixNano()-(time.Minute*30).Nanoseconds()
}

func (entry *ObjectEntry) PrintPrepareCompactDebugLog() {
if entry.hasPrintedPrepareComapct {
return
}
entry.hasPrintedPrepareComapct = true
s := fmt.Sprintf("prepare compact failed, obj %v", entry.PPString(3, 0, ""))
lastNode := entry.GetLatestNodeLocked()
startTS := lastNode.GetStart()
if lastNode.Txn != nil {
s = fmt.Sprintf("%s txn is %x.", s, lastNode.Txn.GetID())
}
it := entry.GetTable().MakeObjectIt(false)
for ; it.Valid(); it.Next() {
obj := it.Get().GetPayload()
obj.RLock()
sameTxn := false
obj.LoopChainLocked(func(m *MVCCNode[*ObjectMVCCNode]) bool {
if m.Start.Equal(&startTS) {
sameTxn = true
return false
}
return true
})
obj.RUnlock()
if sameTxn {
s = fmt.Sprintf("%s %v.", s, obj.PPString(3, 0, ""))
}
}
logutil.Infof(s)
}

func MockObjEntryWithTbl(tbl *TableEntry, size uint64) *ObjectEntry {
stats := objectio.NewObjectStats()
objectio.SetObjectStatsSize(stats, uint32(size))
Expand Down
12 changes: 11 additions & 1 deletion pkg/vm/engine/tae/tables/aobj.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,25 @@ func (obj *aobject) PrepareCompact() bool {

if droppedCommitted {
if !obj.meta.PrepareCompactLocked() {
if obj.meta.CheckPrintPrepareCompactLocked() {
obj.meta.PrintPrepareCompactDebugLog()
}
return false
}
} else {
if !obj.meta.PrepareCompactLocked() ||
!obj.appendMVCC.PrepareCompactLocked() /* all appends are committed */ {
if obj.meta.CheckPrintPrepareCompactLocked() {
logutil.Infof("obj %v, data prepare compact failed", obj.meta.ID.String())
}
return false
}
}
return obj.RefCount() == 0
prepareCompact := obj.RefCount() == 0
if !prepareCompact && obj.meta.CheckPrintPrepareCompactLocked() {
logutil.Infof("obj %v, data ref count > 0", obj.meta.ID.String())
}
return prepareCompact
}

func (obj *aobject) Pin() *common.PinnedItem[*aobject] {
Expand Down
6 changes: 5 additions & 1 deletion pkg/vm/engine/tae/tables/obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ func (obj *object) OnApplyDelete(
}

func (obj *object) PrepareCompact() bool {
return obj.meta.PrepareCompact()
prepareCompact := obj.meta.PrepareCompact()
if !prepareCompact && obj.meta.CheckPrintPrepareCompact() {
obj.meta.PrintPrepareCompactDebugLog()
}
return prepareCompact
}

func (obj *object) PrepareCompactInfo() (result bool, reason string) {
Expand Down

0 comments on commit 8ba7bc3

Please sign in to comment.