feat(gc): add sync protection mechanism for cross-cluster sync#23675
Open
LeftHandCold wants to merge 19 commits intomatrixorigin:mainfrom
Open
feat(gc): add sync protection mechanism for cross-cluster sync#23675LeftHandCold wants to merge 19 commits intomatrixorigin:mainfrom
LeftHandCold wants to merge 19 commits intomatrixorigin:mainfrom
Conversation
This commit implements a sync protection mechanism to prevent GC from deleting files that are being synchronized across clusters. Key changes: - Add SyncProtectionManager to manage sync protection entries - Use index.BloomFilter (xorfilter-based, deterministic) instead of bloomfilter.BloomFilter (wyhash-based, non-deterministic) - Integrate sync protection check into MakeBloomfilterCoarseFilter so protected files stay in filesNotGC (recorded in GC metadata) - Add mo_ctl handlers for register/renew/unregister sync protection - Add mo-tool sync-protection command for testing The protection is applied at the coarse filter stage to ensure: 1. Protected files are recorded in GC window metadata 2. Protected files are not deleted during GC 3. After protection is released, files can be GC'd normally
heni02
approved these changes
Feb 5, 2026
ouyuanning
approved these changes
Feb 5, 2026
aunjgr
approved these changes
Feb 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
What type of PR is this?
Which issue(s) this PR fixes:
issue #23525
What this PR does / why we need it:
This commit implements a sync protection mechanism to prevent GC from
deleting files that are being synchronized across clusters.
Key changes:
BloomFilter-based file matching
cross-process file matching
so protected files stay in filesNotGC
unregister_sync_protection
Protection workflow:
Safety features:
PR Type
Enhancement, Tests
Description
Implements a comprehensive sync protection mechanism to prevent GC from deleting files being synchronized across clusters
Core
SyncProtectionManagerusesindex.BloomFilter(xorfilter-based, deterministic) for cross-process file matchingIntegrates sync protection into GC pipeline via
MakeBloomfilterCoarseFilterto keep protected files infilesNotGClistAdds three mo_ctl command handlers:
RegisterSyncProtection,RenewSyncProtection,UnregisterSyncProtectionwith JSON request parsingDefines six new error codes (20642-20647) for sync protection operations:
ErrGCIsRunning,ErrSyncProtectionNotFound,ErrSyncProtectionExists,ErrSyncProtectionMaxCount,ErrSyncProtectionSoftDelete,ErrSyncProtectionInvalidImplements protection workflow: register before sync → GC checks BloomFilter → unregister after sync → cleanup soft-deleted entries when checkpoint watermark exceeds validTS
Includes safety features: blocks new registrations during GC execution, TTL-based cleanup for crashed jobs (20 min default), max protection count limit (100 default)
Adds comprehensive unit tests (20+ test cases) covering registration, renewal, unregistration, cleanup, concurrent access, and edge cases
Includes BVT test suite validating mo_ctl command error handling and graceful failures
Provides CLI testing tool for end-to-end validation of sync protection mechanism
Diagram Walkthrough
File Walkthrough
1 files
operations.pb.go
Protobuf code generation for SyncProtection message typepkg/vm/engine/cmd_util/operations.pb.go
SyncProtectionstruct (Reset,String, Marshal, Unmarshal, etc.)
protocol buffer messages
SyncProtectionmessage typeregistration
SyncProtectionfields:Op,JobID,Objects,ValidTS5 files
sync_protection_test.go
Unit tests for sync protection manager functionalitypkg/vm/engine/tae/db/gc/v3/sync_protection_test.go
SyncProtectionManagerwith 20+ test casesfiltering operations
index.BloomFilter(xorfilter)soft delete cleanup
main.go
Create GC testing tool for sync protectionpkg/vm/engine/tae/db/gc/v3/tool/main.go
gc-toolcommandPrepareSyncProtectionCommand()subcommand for sync protectiontesting
mock_cleaner.go
Implement sync protection method in mock cleanerpkg/vm/engine/tae/db/gc/v3/mock_cleaner.go
GetSyncProtectionManager()method inMockCleanernilfor mock implementationmo_ctl_sync_protection.test
Add BVT tests for sync protection commandstest/distributed/cases/function/mo_ctl/mo_ctl_sync_protection.test
commands
protections, empty commands, and unknown operations
mo_ctl_sync_protection.result
Add expected results for sync protection teststest/distributed/cases/function/mo_ctl/mo_ctl_sync_protection.result
non-existent protections, and invalid operations
11 files
sync_protection.go
CLI tool for sync protection testing and validationpkg/vm/engine/tae/db/gc/v3/tool/sync_protection.go
protections
wait time, DSN)
sync_protection.go
Sync protection manager with BloomFilter-based file matchingpkg/vm/engine/tae/db/gc/v3/sync_protection.go
SyncProtectionManagerimplementation managing sync protectionentries
index.BloomFilter(xorfilter-based, deterministic) forcross-process file matching
cleanup operations
checkpoint.go
Integration of sync protection into GC checkpoint cleanerpkg/vm/engine/tae/db/gc/v3/checkpoint.go
SyncProtectionManagerintocheckpointCleanerstructwatermark exceeds validTS
exec_v1.go
Sync protection integration into GC job executionpkg/vm/engine/tae/db/gc/v3/exec_v1.go
syncProtectionfield toCheckpointBasedGCJobstructSyncProtectionManagerthrough GC job creation and executionpipeline
MakeBloomfilterCoarseFilterto check protected files and skipmarking them for GC
filesNotGClist, preventing their deletionhandle_debug.go
Add sync protection mo_ctl command handlerspkg/vm/engine/tae/rpc/handle_debug.go
encoding/jsonimport for JSON unmarshalingRegisterSyncProtection,RenewSyncProtection, andUnregisterSyncProtectionand valid timestamp
SyncProtectionManagermethods and return JSONstatus responses
cmd_disk_cleaner.go
Add sync protection command parsing and validationpkg/sql/plan/function/ctl/cmd_disk_cleaner.go
logutilandzapimports for loggingwithout strict length limits
RegisterSyncProtection,RenewSyncProtection, andUnregisterSyncProtectionoperationshandle JSON with embedded dots
window.go
Integrate sync protection into GC window executionpkg/vm/engine/tae/db/gc/v3/window.go
syncProtectionparameter of type*SyncProtectionManagertoExecuteGlobalCheckpointBasedGCmethodsyncProtectionparameter through to downstream function callsoperations.go
Define SyncProtection request structurepkg/vm/engine/cmd_util/operations.go
SyncProtectionstruct for sync protection requestsJobID(sync job identifier),BF(base64-encodedBloomFilter),
ValidTS(timestamp in nanoseconds),TestObject(optionaldebugging field)
type.go
Add sync protection operation constantspkg/vm/engine/cmd_util/type.go
RegisterSyncProtection,RenewSyncProtection,UnregisterSyncProtectiontypes.go
Add sync protection manager interface methodpkg/vm/engine/tae/db/gc/v3/types.go
GetSyncProtectionManager()method toCleanerinterfaceSyncProtectionManagerfor accessing sync protectionfunctionality
operations.proto
Define SyncProtection protobuf messagepkg/vm/engine/cmd_util/operations.proto
SyncProtectionprotobuf message definitionOp(operation type),JobID(sync job identifier),Objects(repeated protected object names),ValidTS(valid timestamp)2 files
error_no_ctx.go
Error definitions for sync protection operationspkg/common/moerr/error_no_ctx.go
ErrGCIsRunning,ErrSyncProtectionNotFound,ErrSyncProtectionExists,ErrSyncProtectionMaxCount,ErrSyncProtectionSoftDelete,ErrSyncProtectionInvaliderror.go
Define sync protection error codes and messagespkg/common/moerr/error.go
ErrGCIsRunning,ErrSyncProtectionNotFound,ErrSyncProtectionExists,ErrSyncProtectionMaxCount,ErrSyncProtectionSoftDelete,ErrSyncProtectionInvaliderrorMsgRefermap withdescriptive text