diff --git a/pkg/vm/engine/tae/catalog/object.go b/pkg/vm/engine/tae/catalog/object.go index 960cf4b93258..77a233bdf730 100644 --- a/pkg/vm/engine/tae/catalog/object.go +++ b/pkg/vm/engine/tae/catalog/object.go @@ -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" @@ -40,6 +41,8 @@ type ObjectEntry struct { table *TableEntry *ObjectNode objData data.Object + + hasPrintedPrepareComapct bool } func (entry *ObjectEntry) GetLoaded() bool { @@ -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)) diff --git a/pkg/vm/engine/tae/tables/aobj.go b/pkg/vm/engine/tae/tables/aobj.go index ce89aa7f8526..c74ce5a123e4 100644 --- a/pkg/vm/engine/tae/tables/aobj.go +++ b/pkg/vm/engine/tae/tables/aobj.go @@ -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] { diff --git a/pkg/vm/engine/tae/tables/obj.go b/pkg/vm/engine/tae/tables/obj.go index b07745fe0a2c..5e99a54789cf 100644 --- a/pkg/vm/engine/tae/tables/obj.go +++ b/pkg/vm/engine/tae/tables/obj.go @@ -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) {