-
Notifications
You must be signed in to change notification settings - Fork 3
Add Directory Layer implementation #17
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 commit adds two major features to the Swift bindings: ## Versionstamp Support - Implement 12-byte Versionstamp structure (10-byte transaction version + 2-byte user version) - Add incomplete versionstamp support for transaction-time assignment - Implement Tuple integration with versionstamp encoding (type code 0x33) - Add packWithVersionstamp() for atomic operations ## Subspace Implementation - Implement Subspace for key namespace management with tuple encoding - Add range() method using prefix + [0x00] / prefix + [0xFF] pattern - Implement strinc() algorithm for raw binary prefix support - Add prefixRange() method for complete prefix coverage - Define SubspaceError for proper error handling ## Testing - Add VersionstampTests with 15 test cases - Add StringIncrementTests with 14 test cases for strinc() algorithm - Add SubspaceTests with 22 test cases covering range() and prefixRange() - Verify cross-language compatibility with official bindings All implementations follow the canonical behavior of official Java, Python, Go, and C++ bindings.
This commit completes the Versionstamp implementation by adding decode support and comprehensive roundtrip tests. ## Tuple.decode() Integration - Add versionstamp case (0x33) to Tuple.decode() switch - Enable automatic Versionstamp decoding in tuples - Allows reading versionstamped keys from database ## Roundtrip Tests - Add 5 roundtrip tests (encode → decode) - Complete versionstamp roundtrip - Incomplete versionstamp roundtrip - Mixed tuple with multiple types - Multiple versionstamps in one tuple - Error handling for insufficient bytes ## Test Fixes - Fix withUnsafeBytes crash by ensuring exact 4-byte array - Add size validation before unsafe memory access - Fix range test expectations (prefix vs prefix + [0x00]) ## Code Cleanup - Remove dead code for API < 520 (no longer supported) - Simplify to single code path using 4-byte offsets - Update documentation to reflect API 520+ requirement All 150 tests now pass successfully.
… system This commit adds a complete implementation of the FoundationDB Directory Layer, including hierarchical namespace management, partition support, and high contention allocation. The implementation ensures consistency between metadata storage and API return values through a unified prefix coordinate system. ## Key Features - **Directory Layer**: Hierarchical path-to-prefix mapping with automatic allocation - **Partition Support**: Isolated namespaces with their own DirectoryLayer instances - **High Contention Allocator**: Window-based allocation for efficient unique prefixes - **Unified Prefix Coordinates**: Relative prefixes in metadata, absolute in API returns ## Core Components ### DirectoryLayer.swift (1,250 lines) - Unified prefix coordinate system (store relative, return absolute) - Partition-aware operations (create, open, move, list, remove) - Automatic prefix allocation via HCA - Manual prefix validation with conflict detection - Cross-partition move prevention ### DirectoryError.swift (181 lines) - Comprehensive error types with DocC documentation - Detailed error descriptions for debugging ### DirectorySubspace.swift (205 lines) - Lightweight wrapper combining Subspace with path and type - Convenient key encoding/decoding methods ### HighContentionAllocator.swift (218 lines) - Official FDB algorithm with dynamic window sizing - Write conflict detection for concurrent allocations ### DirectoryVersion.swift (56 lines) - Version management for metadata compatibility ## Bug Fixes 1. **Double-prefix bug**: Removed redundant partition prefix concatenation 2. **Cross-partition move**: Added explicit boundary validation 3. **Manual prefix validation**: Unified absolute/relative coordinate systems 4. **Partition list operations**: Delegate to partition layer for correct metadata lookup ## Design Decisions ### Prefix Coordinate System - **Metadata storage**: Relative prefixes (HCA-compatible) - **API return values**: Absolute prefixes (contentSubspace + relative) - **Manual prefixes**: Treated as relative (same as HCA) ### Removed isInsidePartition Flag - Replaced with rootLayer reference for cleaner design - Partition nesting check: `rootLayer != nil` ## Testing Comprehensive test suite with 23 tests covering: - Basic operations (create, open, list, move, remove) - Partition operations and traversal - Manual prefix collision detection - Cross-language metadata compatibility - Deep nested directories within partitions - Multi-level partition directories All tests passing: 23/23 ✅
Fixes two HIGH priority bugs identified in code review: 1. move() now stores relative prefix in metadata instead of absolute - Prevents double-prefix on reopen - Ensures data remains accessible after move 2. removeInternal() now cleans up parent entry when removing partition root - Prevents dangling references in parent's subdirs - Ensures removed partition cannot be reopened Added regression tests: - movePrefixCorrectness: Verifies move preserves prefix through reopen - removePartitionRootCleansUpParent: Verifies parent cleanup Added write conflict range optimization extensions: - setNextWriteNoWriteConflictRange(): Exclude next write from conflict checking - addWriteConflictKey(): Add single key to write conflict range - addWriteConflictRange(): Add key range to write conflict range All 25 tests passing.
|
Thanks for the PR and putting time into this. However, I've few non-code related comments:
We still have some pending internal discussions on what Tuple layer should look like. So I don't know if I personally would like to review it right away, and definitely not in its current form. What I would suggest is starting with an issue (maybe a much smaller PR with basic interfaces), and people interested can discuss it, refine the design, guide you in the right direction, and successfully get changes merged in. |
|
Thank you for the honest and constructive feedback. I understand and accept all your points. On Process: On PR Size: On AI Usage:
This approach allows me to tune AI prompts consistently to match your expectations and reduce review burden. On Project Direction:
Next Steps:
Thank you for maintaining quality standards. I want to contribute effectively within your process. |
Summary
This PR adds a complete implementation of the FoundationDB Directory Layer to the Swift bindings, bringing feature parity with Python, Java, and Go official bindings.
Dependencies
What is Directory Layer?
The Directory Layer is a standard component in all major FoundationDB language bindings:
fdb.directorycom.apple.foundationdb.directoryfdb/directorypackagePurpose:
Use Cases:
Implementation
New Files:
Sources/FoundationDB/Directory/DirectoryLayer.swift- Core directory management systemSources/FoundationDB/Directory/DirectorySubspace.swift- Directory result containerSources/FoundationDB/Directory/DirectoryError.swift- Directory-specific errorsSources/FoundationDB/Directory/DirectoryVersion.swift- Version metadataSources/FoundationDB/Directory/HighContentionAllocator.swift- Automatic prefix allocationFeatures:
API Example:
Design
Unified Prefix Coordinate System
The implementation uses a unified coordinate system for consistency:
contentPrefix + relativePrefix)resolve()converts relative → absolute when readingThis ensures compatibility with other language bindings while maintaining clean separation between storage and API layers.
Naming: "DirectoryLayer"
Consistent with official implementations:
fdb.DirectoryLayercom.apple.foundationdb.directory.DirectoryLayerdirectory.NewDirectoryLayer()"Layer" reflects that it's a complete management system built on top of Subspace/Tuple layers, following FoundationDB's layered architecture concept.
Testing
Test Coverage:
Tests/FoundationDBTests/DirectoryLayerTests.swift- 25 comprehensive tests:Test Results:
Compatibility
Documentation
The implementation follows the official FoundationDB documentation:
Checklist