Commit 92dc113
committed
feat: implement global namespace with caching and smart S3 routing
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).1 parent 488203e commit 92dc113
21 files changed
Lines changed: 600 additions & 227 deletions
File tree
- anvil-core
- src
- anvil-test-utils/src
- anvil
- migrations_global
- migrations_regional
- src
- bin
- tests
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
| 7 | + | |
15 | 8 | | |
16 | 9 | | |
17 | 10 | | |
18 | | - | |
| 11 | + | |
19 | 12 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
30 | 19 | | |
31 | 20 | | |
32 | 21 | | |
33 | | - | |
| 22 | + | |
34 | 23 | | |
35 | | - | |
36 | | - | |
37 | | - | |
| 24 | + | |
38 | 25 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
| 26 | + | |
| 27 | + | |
46 | 28 | | |
47 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
48 | 33 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
56 | 40 | | |
57 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
58 | 44 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
76 | 50 | | |
77 | 51 | | |
78 | 52 | | |
79 | 53 | | |
80 | 54 | | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
86 | 61 | | |
87 | 62 | | |
88 | 63 | | |
89 | 64 | | |
90 | 65 | | |
91 | | - | |
| 66 | + | |
92 | 67 | | |
93 | 68 | | |
94 | 69 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
99 | 88 | | |
100 | 89 | | |
101 | 90 | | |
102 | 91 | | |
103 | 92 | | |
104 | | - | |
| 93 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| 110 | + | |
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
0 commit comments