Skip to content

Commit dfb6fd9

Browse files
authored
All table lists need to be obtained during GC (#22626)
All table lists need to be obtained during GC Approved by: @XuPeng-SH
1 parent 27eff20 commit dfb6fd9

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

pkg/vm/engine/tae/db/gc/v3/checkpoint.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,7 @@ func (c *checkpointCleaner) doGCAgainstGlobalCheckpointLocked(
11931193
pitrs,
11941194
c.mutation.snapshotMeta,
11951195
iscp,
1196+
c.checkpointCli,
11961197
memoryBuffer,
11971198
c.config.canGCCacheSize,
11981199
c.config.estimateRows,
@@ -1365,6 +1366,7 @@ func (c *checkpointCleaner) DoCheck(ctx context.Context) error {
13651366
pitr,
13661367
c.mutation.snapshotMeta,
13671368
iscp,
1369+
c.checkpointCli,
13681370
buffer,
13691371
c.config.canGCCacheSize,
13701372
c.config.estimateRows,
@@ -1388,6 +1390,7 @@ func (c *checkpointCleaner) DoCheck(ctx context.Context) error {
13881390
pitr,
13891391
c.mutation.snapshotMeta,
13901392
iscp,
1393+
c.checkpointCli,
13911394
buffer,
13921395
c.config.canGCCacheSize,
13931396
c.config.estimateRows,

pkg/vm/engine/tae/db/gc/v3/exec_v1.go

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ package gc
1616

1717
import (
1818
"context"
19-
2019
"github.com/matrixorigin/matrixone/pkg/common/bloomfilter"
2120
"github.com/matrixorigin/matrixone/pkg/common/malloc"
2221
"github.com/matrixorigin/matrixone/pkg/logutil"
22+
"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/db/checkpoint"
2323
"go.uber.org/zap"
2424

2525
"github.com/matrixorigin/matrixone/pkg/container/types"
@@ -71,6 +71,7 @@ type CheckpointBasedGCJob struct {
7171
ts *types.TS
7272
globalCkpLoc objectio.Location
7373
globalCkpVer uint32
74+
checkpointCli checkpoint.Runner // Added to access catalog
7475

7576
result struct {
7677
vecToGC *vector.Vector
@@ -87,6 +88,7 @@ func NewCheckpointBasedGCJob(
8788
accountSnapshots map[uint32][]types.TS,
8889
iscpTables map[uint64]types.TS,
8990
snapshotMeta *logtail.SnapshotMeta,
91+
checkpointCli checkpoint.Runner,
9092
buffer *containers.OneSchemaBatchBuffer,
9193
isOwner bool,
9294
mp *mpool.MPool,
@@ -103,6 +105,7 @@ func NewCheckpointBasedGCJob(
103105
globalCkpLoc: globalCkpLoc,
104106
globalCkpVer: gckpVersion,
105107
iscpTables: iscpTables,
108+
checkpointCli: checkpointCli,
106109
}
107110
for _, opt := range opts {
108111
opt(e)
@@ -173,6 +176,7 @@ func (e *CheckpointBasedGCJob) Execute(ctx context.Context) error {
173176
e.snapshotMeta,
174177
transObjects,
175178
e.iscpTables,
179+
e.checkpointCli,
176180
)
177181
if err != nil {
178182
return err
@@ -316,17 +320,58 @@ func MakeBloomfilterCoarseFilter(
316320
}, nil
317321
}
318322

323+
// buildTableExistenceMap creates a combined map of table IDs from both snapshotMeta and catalog
324+
// This avoids the need for locking on every table existence check
325+
func buildTableExistenceMap(snapshotMeta *logtail.SnapshotMeta, checkpointCli checkpoint.Runner) (map[uint64]bool, error) {
326+
// First, copy all table IDs from snapshotMeta
327+
tableExistenceMap := snapshotMeta.GetAllTableIDs()
328+
catalog := checkpointCli.GetCatalog()
329+
count := len(tableExistenceMap)
330+
defer func() {
331+
logutil.Info("GC-TRACE-TABLE-LIST",
332+
zap.Int("gc-table-count", count),
333+
zap.Int("all-table-count", len(tableExistenceMap)))
334+
}()
335+
if catalog == nil {
336+
return tableExistenceMap, nil
337+
}
338+
it := catalog.MakeDBIt(true)
339+
for ; it.Valid(); it.Next() {
340+
db := it.Get().GetPayload()
341+
342+
itTable := db.MakeTableIt(true)
343+
for itTable.Valid() {
344+
table := itTable.Get().GetPayload()
345+
drop := table.GetDeleteAtLocked()
346+
if drop.IsEmpty() {
347+
tableID := table.GetID()
348+
tableExistenceMap[tableID] = true
349+
}
350+
itTable.Next()
351+
}
352+
}
353+
354+
return tableExistenceMap, nil
355+
}
356+
319357
func MakeSnapshotAndPitrFineFilter(
320358
ts *types.TS,
321359
accountSnapshots map[uint32][]types.TS,
322360
pitrs *logtail.PitrInfo,
323361
snapshotMeta *logtail.SnapshotMeta,
324362
transObjects map[string]map[uint64]*ObjectEntry,
325363
iscpTables map[uint64]types.TS,
364+
checkpointCli checkpoint.Runner,
326365
) (
327366
filter FilterFn,
328367
err error,
329368
) {
369+
// Build combined table existence map from both snapshotMeta and catalog
370+
tableExistenceMap, err := buildTableExistenceMap(snapshotMeta, checkpointCli)
371+
if err != nil {
372+
return nil, err
373+
}
374+
330375
tableSnapshots, tablePitrs := snapshotMeta.AccountToTableSnapshots(
331376
accountSnapshots,
332377
pitrs,
@@ -354,8 +399,8 @@ func MakeSnapshotAndPitrFineFilter(
354399
if transObjects[name] != nil {
355400
tables := transObjects[name]
356401
if entry := tables[tableID]; entry != nil {
357-
// Check if the table still exists
358-
_, ok := snapshotMeta.GetAccountId(tableID)
402+
// Check if the table still exists using the combined map
403+
ok := tableExistenceMap[tableID]
359404
// The table has not been dropped, and the dropTS is empty, so it cannot be deleted.
360405
if entry.dropTS.IsEmpty() && ok {
361406
continue

pkg/vm/engine/tae/db/gc/v3/window.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ func (w *GCWindow) ExecuteGlobalCheckpointBasedGC(
124124
pitrs *logtail.PitrInfo,
125125
snapshotMeta *logtail.SnapshotMeta,
126126
iscpTables map[uint64]types.TS,
127+
checkpointCli checkpoint.Runner,
127128
buffer *containers.OneSchemaBatchBuffer,
128129
cacheSize int,
129130
estimateRows int,
@@ -144,6 +145,7 @@ func (w *GCWindow) ExecuteGlobalCheckpointBasedGC(
144145
accountSnapshots,
145146
iscpTables,
146147
snapshotMeta,
148+
checkpointCli,
147149
buffer,
148150
false,
149151
mp,

pkg/vm/engine/tae/logtail/snapshot.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,17 @@ func (sm *SnapshotMeta) GetAccountId(tid uint64) (uint32, bool) {
18751875
return sm.tableIDIndex[tid].accountID, true
18761876
}
18771877

1878+
// GetAllTableIDs returns a copy of all table IDs in the snapshot meta
1879+
func (sm *SnapshotMeta) GetAllTableIDs() map[uint64]bool {
1880+
sm.RLock()
1881+
defer sm.RUnlock()
1882+
result := make(map[uint64]bool, len(sm.tableIDIndex))
1883+
for tableID := range sm.tableIDIndex {
1884+
result[tableID] = true
1885+
}
1886+
return result
1887+
}
1888+
18781889
// for test
18791890
func (sm *SnapshotMeta) GetTablePK(tid uint64) string {
18801891
sm.RLock()

0 commit comments

Comments
 (0)