feat: implement global namespace with caching and smart S3 routing#6
Merged
feat: implement global namespace with caching and smart S3 routing#6
Conversation
This commit overhauls the bucket lookup and region handling logic to support a true global namespace, while significantly improving performance and maintaining data locality constraints.
**Key Changes:**
* **Global Bucket Lookup:** Modified `Persistence::get_bucket_by_name` to remove the `region` constraint. Nodes can now look up any bucket in the global database regardless of its home region.
* **Metadata Caching:** Introduced `MetadataCache` using `moka`. This caches bucket, tenant, and policy metadata locally on each node to reduce load on the global database.
* **Cache Invalidation via P2P:** Implemented a pub/sub mechanism over the existing `libp2p` cluster mesh. Nodes broadcast `MetadataEvent` (e.g., `BucketUpdated`) when modifying metadata, allowing peers to
invalidate their local caches near-instantly.
* **S3 Gateway Smart Routing:** Updated the S3 Gateway to support `301 Moved Permanently` / `307 Temporary Redirect` responses when a client accesses a bucket located in a different region. This enables AWS
SDKs to automatically retry against the correct endpoint.
* **S3 Location Constraint:** Updated `CreateBucket` to correctly parse and respect the `LocationConstraint` XML body, allowing S3 clients to specify the target region for new buckets.
* **Internal Logic Updates:** Refactored `ObjectManager` to verify bucket region *after* lookup, ensuring requests are still processed by the correct regional node (or redirected at the gateway layer).
* **Admin CLI & Tests:** Updated the `admin` CLI to accommodate the new configuration structure. Fixed integration tests to account for eventual consistency when using the direct-to-DB admin tool by
implementing retry logic and configurable cache TTLs.
**Components Touched:**
* `anvil-core`: Persistence layer (SQL updates), Caching logic, P2P Event definitions, ObjectManager refactoring.
* `anvil`: S3 Gateway routing/redirection, Service startup/wiring.
* `anvil-cli` / `admin`: Configuration updates.
* `tests`: Enhanced robustness for async cache updates.
**Performance Impact:**
23 Massively reduced read load on the Global Postgres instance for hot paths (e.g., checking bucket existence on every object request).
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.
This commit overhauls the bucket lookup and region handling logic to support a true global namespace, while significantly improving performance and maintaining data locality constraints.
Key Changes:
Persistence::get_bucket_by_nameto remove theregionconstraint. Nodes can now look up any bucket in the global database regardless of its home region.MetadataCacheusingmoka. This caches bucket, tenant, and policy metadata locally on each node to reduce load on the global database.libp2pcluster mesh. Nodes broadcastMetadataEvent(e.g.,BucketUpdated) when modifying metadata, allowing peers toinvalidate their local caches near-instantly.
301 Moved Permanently/307 Temporary Redirectresponses when a client accesses a bucket located in a different region. This enables AWSSDKs to automatically retry against the correct endpoint.
CreateBucketto correctly parse and respect theLocationConstraintXML body, allowing S3 clients to specify the target region for new buckets.ObjectManagerto verify bucket region after lookup, ensuring requests are still processed by the correct regional node (or redirected at the gateway layer).adminCLI to accommodate the new configuration structure. Fixed integration tests to account for eventual consistency when using the direct-to-DB admin tool byimplementing retry logic and configurable cache TTLs.
Components Touched:
anvil-core: Persistence layer (SQL updates), Caching logic, P2P Event definitions, ObjectManager refactoring.anvil: S3 Gateway routing/redirection, Service startup/wiring.anvil-cli/admin: Configuration updates.tests: Enhanced robustness for async cache updates.Performance Impact:
23 Massively reduced read load on the Global Postgres instance for hot paths (e.g., checking bucket existence on every object request).