-
Notifications
You must be signed in to change notification settings - Fork 172
feat: Backup Helper and Metadata Management Enhancement #1334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This PR adds utility functions for backup line management and metadata handling: New helper functions: - normalizeBackupLine(): Normalize 'default' vs 'adhoc' backup designations - resolveBackupLine(): Determine correct backup line for a server - shouldRunRestic(): Check if restic should be used based on config - buildBackupMetaFileName(): Generate metadata file paths - parseAdhocMetaFileID(): Extract backup ID from filenames - parseBackupToolFromMetaFilename(): Parse backup tool from filename - retentionDeadline(): Calculate retention cutoff dates - Meta file read/write/delete operations New files: - cluster/backup_helpers.go (+349 lines) - cluster/backup_helpers_test.go (+434 lines) Test coverage: ~70% Dependencies: - Requires PR #2 (config.BackupRestic* fields) What it enables: - Unified backup line concept (default/adhoc) - Backup metadata tracking with IDs - Support for multiple backup tools (mysqldump, mariabackup, xtrabackup, restic) - Retention policy enforcement
This PR adds utility functions for backup line management and metadata handling: New helper functions: - normalizeBackupLine(): Normalize 'default' vs 'adhoc' backup designations - resolveBackupLine(): Determine correct backup line for a server - shouldRunRestic(): Check if restic should be used based on config - buildBackupMetaFileName(): Generate metadata file paths - parseAdhocMetaFileID(): Extract backup ID from filenames - parseBackupToolFromMetaFilename(): Parse backup tool from filename - retentionDeadline(): Calculate retention cutoff dates - Meta file read/write/delete operations New files: - cluster/backup_helpers.go (+349 lines) - cluster/backup_helpers_test.go (+434 lines) Test coverage: ~70% Dependencies: - Requires PR #2 (config.BackupRestic* fields) What it enables: - Unified backup line concept (default/adhoc) - Backup metadata tracking with IDs - Support for multiple backup tools (mysqldump, mariabackup, xtrabackup, restic) - Retention policy enforcement
…' into feature/restic-03-backup-helpers
PR Review: Backup Helper and Metadata Management EnhancementSummaryThis PR introduces a solid set of utility functions for managing backup metadata, handling ad-hoc and default backup designations, and enforcing retention policies. The implementation is well-tested with ~70% coverage and includes clear separation of concerns. ✅ Strengths
|
|
@claude review my pull request |
|
Claude finished @caffeinated92's task in 41s —— View job Code Review: Backup Helper and Metadata Management Enhancement📋 Review Status
✅ Strengths1. Excellent Security Improvements
2. Smart Timestamp Validation
3. Solid Thread-Safety Architecture
4. Comprehensive Test Coverage
5. Clean API Design
|
| Aspect | Status | Evidence |
|---|---|---|
| Path Traversal | ✅ PROTECTED | isSafeBackupToolName() + isPathWithinBase() validation |
| File Deletion | ✅ PROTECTED | Paths validated before os.RemoveAll() (line 330-335) |
| JSON Parsing | ✅ SAFE | Proper error handling, continues on parse errors |
| Timestamp Validation | ✅ PROTECTED | isLikelyUnixTimestamp() range checks |
| Concurrent Access | ✅ SAFE | Uses sync.Map for thread-safe operations |
📊 Test Coverage Assessment
Well-Tested Functions ✅
normalizeBackupLine()- 10 test casesparseAdhocMetaFileID()- 8 test casesparseBackupToolFromMetaFilename()- 7 test casesretentionDeadline()- 8 test casesreadBackupMetadataFile()- Multiple error scenariosisPathWithinBase()- Explicit tests (line 561-571)isSafeBackupToolName()- Tested indirectly viabuildBackupMetaFileName()
Needs Attention
LoadAdhocBackupMetadata()- Good test but limited error scenariosGetLatestMetaForLine()- No explicit test for Range iterationPurgeExpiredAdhocBackups()- Simulated but not full integration
🎯 Recommendations Summary
Must Address (before merge):
- Add docstring to
BackupRunOptionsstruct explaining each field - Add docstrings to
resolveBackupLine()andshouldRunRestic()methods - Verify
BackupMetaMap.Delete()method exists and is accessible
Should Address (before merge):
- Enable
TestBuildBackupMetaFileNameby providing mock implementation - Change JSON parse error logging from DEBUG to WARN level for retention operations
- Add integration test for
PurgeExpiredAdhocBackups()with actual file cleanup
Nice to Have (consider for future):
- Add test for
GetLatestMetaForLine()with multiple metadata entries - Add edge case test for concurrent purge operations
🚀 Overall Assessment
Status: ✅ Approve with minor documentation fixes
Summary:
- Code quality is high with excellent security hardening
- Thread-safety properly addressed using
sync.Map - Timestamp validation correctly prevents common bugs
- Path validation prevents critical security vulnerabilities
- Test coverage is solid at ~70%
Critical blockers: None identified
Blocking improvements: Add struct/method documentation for API clarity
This PR demonstrates thoughtful implementation of backup lifecycle management with proper attention to concurrency, security, and error handling. The addition of path validation and timestamp sanity checks significantly improves production safety.
|
@claude review my pull request |
|
Claude finished @caffeinated92's task in 39s —— View job PR Review: Backup Helper and Metadata Management Enhancement📋 Review Tasks
✅ Strengths1. Excellent Security Implementation
2. Strong Thread-Safety Design
3. Comprehensive Test Coverage
4. Clean API Design & Code Organization
5. Error Handling & Resilience
|
| Component | Status | Evidence |
|---|---|---|
| Path Traversal | ✅ PROTECTED | isSafeBackupToolName() prevents ../ attacks |
| File Deletion | ✅ PROTECTED | isPathWithinBase() validates before os.RemoveAll() |
| JSON Parsing | ✅ SAFE | Errors handled, parsing continues on invalid JSON |
| Timestamp Validation | ✅ PROTECTED | Range checks prevent treating IDs as timestamps |
| Thread-Safety | ✅ SAFE | sync.Map used correctly, proper synchronization |
| File Permissions | ✅ ADEQUATE | Standard Go file ops with error handling |
📊 Test Coverage Assessment
Excellent Coverage ✅
normalizeBackupLine()- 10 test cases covering case sensitivity, spacing, hyphensparseAdhocMetaFileID()- 8 cases with edge cases (zero ID, negative, invalid formats)parseBackupToolFromMetaFilename()- 7 cases for default and adhoc formatsretentionDeadline()- 8 cases covering all timestamp sourcesreadBackupMetadataFile()- Valid file + 3 error scenarios + non-existent filebuildBackupMetaFileName()- Path construction with security testsisPathWithinBase()- Path validation with inside/outside cases
Tested Integration Points ✅
TestLoadAdhocBackupMetadataReturnsError- Mixed valid/invalid metadata handlingTestResolveBackupLine- Server role-based resolution with master/backup/otherTestShouldRunRestic- Configuration override logic
🚀 Overall Assessment
Status: ✅ Approve with one critical verification
Summary:
This PR demonstrates excellent software engineering practices:
- ✅ Comprehensive security hardening (path traversal, timestamp validation)
- ✅ Proper concurrency handling with
sync.Map - ✅ 70%+ test coverage with meaningful scenarios
- ✅ Clean API design and separation of concerns
- ✅ Robust error handling with graceful degradation
Critical Blocker:
- Verify
BackupMetaMap.Delete()method exists or implement it
Should Fix Before Merge:
- Change metadata parse error logging from DEBUG to WARN level (line 200)
- Document thread-safety guarantee for
Cluster.Serversaccess inPurgeExpiredAdhocBackups()
Nice to Have:
- Add integration test for concurrent purge operations
- Extend
GetLatestMetaForLine()test coverage
Questions for Author:
- Does
BackupMetaMaphave aDelete()method? If not, this needs implementation. - Is the
Cluster.Serversslice protected from concurrent modifications? - Should metadata parse errors be WARNING level instead of DEBUG?
This pull request introduces a new file,
backup_helpers.go, in theclusterpackage, providing a comprehensive set of helper functions and types to manage backup metadata, retention, and cleanup operations for MariaDB/MySQL clusters. The changes improve how ad-hoc and default backups are identified, stored, and purged, and add utilities for working with backup metadata files.Key new features and improvements:
Backup Metadata Management:
BackupRunOptionsstruct to encapsulate options for backup runs, improving code clarity and maintainability.Ad-hoc Backup Handling:
LoadAdhocBackupMetadatato load all ad-hoc backup metadata files for a server, ensuring metadata is correctly populated and registered in the cluster’s backup metadata map.Backup Retention and Purging:
PurgeExpiredAdhocBackups, which iterates over all servers in a cluster and purges expired ad-hoc backups and their associated metadata and storage, including integration with Rest