Repository navigation
fix table clone visibility for repeated alter - #24987
Conversation
7da9dd5 to
61349c5
Compare
XuPeng-SH
left a comment
There was a problem hiding this comment.
I re-checked the latest head. The original rollback-GC leak I raised is fixed, but there is still one remaining high-severity cleanup window in the commit path.
pkg/vm/engine/disttae/txn.go:2005-2008 now defers txn.delTransaction() only when txn.Commit() returns err == nil. That preserves the workspace for failures inside CN-side commit preparation. But once workspace.Commit() succeeds, the outer txn operator has not actually committed yet — it still has to validate, build/send the commit request, and process the response.
In pkg/txn/client/operator.go:1113-1180, after workspace.Commit() succeeds, later failures from validate, doSend, or commit response handling just bubble out of the commit path. They do not call workspace.Rollback(). At that point txn.delTransaction() has already run, which deletes the clone txn cache in pkg/vm/engine/disttae/txn.go:2188-2190.
That means clone-related txn-local source/data/tombstone files can still lose their local GC/bookkeeping path if commit fails after workspace.Commit() but before the outer commit actually succeeds. So the leak window is narrower than before, but not closed.
Concrete suggestions
- Keep clone/workspace cleanup state alive until the txn operator knows the commit RPC has definitively succeeded, not merely until
workspace.Commit()finishes building payload. - If you want to keep
Transaction.Commit()as a pure "prepare payload" step, then move the clone-cache deletion / final workspace teardown to the operator’s post-commit-success path instead of the workspace commit path. - Alternatively, add an explicit post-
workspace.Commit()failure cleanup path in the operator for any later commit failure (validate,doSend, response handling), so the clone GC logic still runs on those failures. - Add one focused regression test for the exact window: inject a failure after
workspace.Commit()succeeds but before commit RPC completion, then assert clone source/data/tombstone files are still cleaned up.
Non-blocking remaining coverage gap
- I still do not see a direct test for same-txn row-level DELETE tombstone propagation across repeated ALTER/clone (
BEGIN; DELETE; ALTER; ALTER; COMMIT;plus base-table and index-backed visibility checks).
XuPeng-SH
left a comment
There was a problem hiding this comment.
I re-checked the latest head. The previous post-workspace-commit cleanup window is fixed now, but I still see one remaining high-severity issue in the snapshot-clone path.
TableMetaReader.addCloneSharedFile() still records clone source/object protection under r.table.db.getTxn().op.Txn().ID, i.e. the source reader's transaction ID.
That is fine when source and destination share the same txn, but not in the snapshot-clone flow:
table_clonemarks onlyproc.GetTxnOperator().GetWorkspace()as clone-aware- when
ScanSnapshot.TSis set, it opens the source side onproc.GetCloneTxnOperator() - rollback GC later consults
cloneTxnCacheusing the destination workspace txn ID
So in snapshot-based clone, shared/txn-local shared files can be recorded under the source snapshot txn ID while rollback GC checks the destination txn ID. In that case the clone cache protection is invisible to GC, and source objects referenced by the cloned metadata can still be deleted on rollback.
Concrete suggestions
- Record clone shared / txn-local-shared files against the destination clone-workspace txn ID that rollback GC actually uses, not the source snapshot reader txn ID.
- If that ID is not directly reachable from
TableMetaReader, thread it in explicitly when building the reader for clone flows. - Add one focused regression test for snapshot clone specifically (not same-txn clone): source opened through
CloneSnapshotOp, destination clone txn rolls back, and shared source objects are still protected from GC.
|
@XuPeng-SH I checked this against current head The key point is that
So the source snapshot operator has a separate snapshot timestamp/workspace, but not a distinct transaction ID. The shared-file protection is recorded and later checked under the same txn ID in this path. I also reran the focused clone-GC tests after initializing the local MO env: |
XuPeng-SH
left a comment
There was a problem hiding this comment.
I re-checked this PR from a correctness / unhappy-path angle. The repeated-ALTER visibility fix looks reasonable, but I think there is still one real resource-management regression in the clone/txn-local shared-file lifecycle.
Blocker: txn-local shared clone files can leak after later in-transaction DELETE/compaction
Once a clone step marks a txn-local object as shared, that object name stays in txnLocalSharedFiles for the rest of the transaction.
That becomes a problem in this mixed path:
- clone/alter reads a txn-local persisted object and marks it via
AddTxnLocalSharedFile(...) - the same transaction later deletes rows from that flushed object (
deletedBlockspath) - pre-commit compaction rewrites the object and tries to GC the old file
- intermediate clone GC now skips that old file because it is still marked txn-local-shared
- the original write entry is then nulled out, and successful commit never revisits the skipped file
So the superseded object is orphaned permanently in object storage.
Evidence
TableMetaReadermarks txn-local source objects withAddTxnLocalSharedFile(...).gcFiles(... cloneGCIntermediate ...)filters out anytxnLocalSharedFile.- delete-on-txn-uncommitted-persisted objects are tracked in
deletedBlocks. compactDeletionOnObjsLockedrewrites dirty objects, clears the original write batch (txn.writes[i].bat = nil), then callsGCObjsByStats(dirtyObject...).FinalizeCommitonly drops txn state/cache; it does not do a second GC pass for those skipped old files.
Suggested fix
- Remove a file from
txnLocalSharedFilesonce a later step rewrites/supersedes it (for example incompactDeletionOnObjsLockedbeforeGCObjsByStats), or - replace the current add-only flag with a more precise liveness/reference model.
Please also add a regression test for a mixed transaction like:
INSERT (force flush) -> DELETE -> ALTER TABLE ... -> COMMIT
Because this can leak superseded CN-created objects on a valid transaction path, I think this should be changes requested before merge.
XuPeng-SH
left a comment
There was a problem hiding this comment.
I re-checked the latest head. The snapshot-clone shared-file ownership issue I raised last time looks addressed, but I still see one remaining GC hole in the dropped-table cleanup path.
When tablesInVain is processed in txn.mergeTxnWorkspaceLocked(), each affected write entry is GC'd through GCObjsByIdxRange(i, i) before the batch is cleared. But that path still uses the intermediate clone-GC rules, which explicitly preserve any object still marked as txnLocalShared.
The problem is that the new unprotectUnreferencedTxnLocalSharedFilesLocked(...) helper only runs from the compaction path. It is not run before this tablesInVain cleanup. So if a clone/ALTER chain has marked an older workspace object as txnLocalShared, and then the table is dropped/truncated in the same transaction, GCObjsByIdxRange(i, i) can skip deleting that object, the write gets nulled, and the file becomes orphaned.
You can see the pieces in the current head:
txn.go:1548-1557GC'stablesInVainentries viaGCObjsByIdxRange(i, i)and then clears the batchtypes.go:834-843preservestxnLocalSharedFilesduringcloneGCIntermediatetxn.go:1881-1904only removes unreferenced txn-local shared protection in the compaction pathtxn.delTransaction()later just drops the cache entry; it does not come back and delete any skipped object files
Concrete suggestions
- Before GC-ing
tablesInVainentries, remove txn-local shared protection for files that no longer have any live object-stats references. - Or, run this dropped-table cleanup with a final-GC scope that does not preserve
txnLocalSharedFiles. - Add one focused regression test for: clone/ALTER creates txn-local shared object -> table is dropped/truncated in the same txn -> object file is actually deleted and not orphaned.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-checked the newest head. The latest delta does fix the dropped-table tablesInVain txn-local-shared cleanup path, but the earlier ErrTxnUnknown blocker I raised is still unresolved.
pkg/txn/client/operator.go still routes ambiguous commit outcomes to workspace.FinalizeCommitWithUnknownResult(...), and disttae.Transaction still implements that as delTransaction(). That means an ambiguous commit result can still discard the workspace/object-stat metadata before any later abort/rollback cleanup has a chance to inspect it and GC flushed CN-created objects.
So my review status stays at request changes until the ErrTxnUnknown path preserves enough state for a later abort/rollback cleanup (or is otherwise made safe).
|
Fixed in I re-checked the Also synced the same fix to 4.0-dev in Verified with:
|
XuPeng-SH
left a comment
There was a problem hiding this comment.
I re-checked the newest head. The operator-local ErrTxnUnknown handling is improved now, but the end-to-end frontend commit path still drops the only live txnOp reference before any later abort/rollback cleanup can use the preserved workspace metadata.
Concretely:
txnOperator.doWrite()now preserves workspace state forErrTxnUnknownby callingFinalizeCommitWithUnknownResult(...)instead of rollback.- But
TxnHandler.commitUnsafe()still callsth.invalidateTxnUnsafe()on any commit error. - The normal error path above it then goes through
rollbackTxnFunc(), butrollbackUnsafe()immediately returns when there is no active txn / no livetxnOp.
So if a commit returns ErrTxnUnknown, the metadata is preserved inside the workspace, but the frontend has already discarded the txn operator before any later rollback/abort decision can actually invoke cleanup. In practice that strands the preserved object-stat metadata and leaves the original ambiguous-commit GC issue unresolved in the real frontend flow.
Concrete suggestions
- Keep the txn operator reachable across
ErrTxnUnknownuntil a later status resolution / rollback decision is made. - Or add an explicit ambiguous-commit resolution path in frontend txn handling that can invoke cleanup only after the txn is confirmed aborted.
- Add one focused regression test at the frontend/TxnHandler layer for
ErrTxnUnknown: commit returns unknown, later path decides to abort, and flushed CN objects are still discoverable for cleanup through the real lifecycle.
|
Fixed in I re-checked the frontend lifecycle and this was a valid gap:
Synced the same fix to the 4.0-dev PR in Verified with:
|
|
Another high-signal issue I confirmed on the newest head:
You can see the lifecycle mismatch here:
So an ambiguous commit can leave stale CCPR cache entries behind indefinitely. Later transactions that touch the same shared object name can then see extra Suggested fix: add an "unknown-result" CCPR cleanup path that removes the txn ID from |
|
Fixed the CCPR unknown-result cleanup issue in This was a valid lifecycle gap. The fix adds Synced to 4.0-dev in Verified with:
|
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-checked the newest head. The previous blockers are now closed: the frontend commit path keeps the txn operator reachable across ErrTxnUnknown, and the CCPR unknown-result path now removes cache tracking without wrongly GCing objects. With those lifecycle fixes plus the earlier clone/rollback/shared-file cleanup work, I do not see a remaining correctness issue that should keep this blocked.
|
Queued — the merge queue status continues in this comment ↓. |
Merge Queue Status
This pull request spent 1 hour 26 minutes 44 seconds in the queue, including 1 hour 18 minutes 15 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
fixes #24762
What this PR does / why we need it:
Repeated ALTER TABLE statements in one transaction can clone from a table or hidden index table that was produced by an earlier ALTER in the same transaction. The old TableMetaReader only read the committed partition snapshot and constructed the local reader without the current transaction write offset, so the second clone could miss uncommitted object stats from the first clone. The base table data remained visible, but secondary index data could be missing after commit.
This PR keeps the clone path and makes the clone source reader transaction-visible:
It also extends git4data clone BVT coverage with repeated ALTER cases, including a stress case with secondary, unique, fulltext, and ivfflat vector indexes plus multiple ALTER operations in one transaction.
Validation: