-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add support for ACID transaction #49
Merged
Merged
Conversation
This file contains 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
- joinHostPath: efficient 0 allocation concat host & path
…handle url with domain. Special care must be taken to safely extract param value from the url.
# Conflicts: # fox.go # fox_test.go # iter.go # iter_test.go # node.go # recovery.go # route.go # tree.go
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #49 +/- ##
==========================================
- Coverage 91.88% 91.50% -0.38%
==========================================
Files 19 22 +3
Lines 3131 3533 +402
==========================================
+ Hits 2877 3233 +356
- Misses 196 234 +38
- Partials 58 66 +8 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
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.
Introdcution
During a discussion with the team about foxmock, one of the questions was how we can ensure that a route with its mock can be registered in the router (those valid and non-conflicting with other routes) while not serving the registered handler before this mock is committed to the database. One of the solutions was to register a temporary handler such as "not found," and then only register the final handler after a database write succeeds. Another solution suggested by @hbenhoud was to add a "dry run" option to the router that fully validates the route but registers nothing. Both options are valid for inserting or updating a route, but they don’t scale really well if we have multiple inserts or updates to do in a single database transaction. This is also the case, to some extent, when deleting routes.
For this reason, this PR implement a new kind of immutable Radix Tree that supports lock-free read while allowing a single writer to make progress concurrently (like the actual one). Updates are applied by calculating the change which would be made to the tree were it mutable, assembling those changes into a patch which is propagated to the root and applied in a single atomic operation. The result is a shallow copy of the tree, where only the modified path and its ancestors are cloned, ensuring efficient updates and low memory overhead. Multiple patches can be applied in a single transaction, with intermediate nodes cached during the process to prevent redundant cloning.
This new design allow to supports read-write and read-only transactions (with Atomicity, Consistency, and Isolation; Durability is not supported as transactions are in memory). Thread that route requests always see a consistent version of the routing tree and are fully isolated from an ongoing transaction until committed. Read-only transactions capture a point-in-time snapshot of the tree, ensuring they do not observe any ongoing or committed changes made after their creation.
The new approach enhances read performance, especially under parallel workloads, by reducing atomic pointer operations during lookups. This comes at the cost of a small increase in write overhead due to broader tree mutations during updates.
Note that the unsafe
Tree
api has been entirely removed, this is a big breaking change for wizads.Here a some exemple of the new API.
Managed read-write transaction
Unmanaged read-write transaction
Managed read-only transaction
Differential benchmark