-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Support direct shard database operation routing in Spring JDBC #31506
Merged
jhoeller
merged 4 commits into
spring-projects:main
from
meedbek:support-direct-shard-routing-through-key-provider
Dec 8, 2023
Merged
Support direct shard database operation routing in Spring JDBC #31506
jhoeller
merged 4 commits into
spring-projects:main
from
meedbek:support-direct-shard-routing-through-key-provider
Dec 8, 2023
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
This commit introduces a DataSource proxy, that changes the behavior of the getConnection method to use the `createConnectionBuilder()` api to acquire direct shard connections. The shard connection is acquired by specifying a `ShardingKey` that is correspondent to the wanted shard. The sharding key can be specified either by setting the thread bound sharding key value, which will be used later by the `getConnection()` method, or by defining a `ShardingKeyProvider` which is used in the `getConnection` method to get the ShardingKey. If both ways are used at the same time, the thread-bound sharding key is the one that will be used. The goal of binding the sharding key to the current thread, is that we want to specify the sharding key at one level, and want it to be used later in another level, without the need to propagate it, for example set the thread-bound sharding key, and execute a `JdbcTemplate.query(SQL)` method that that will call `DataSource.getConnection()`, and as the sharding key is bound to the thread, it can be acquired to get the shard connection.
spring-projects-issues
added
the
status: waiting-for-triage
An issue we've not yet triaged or decided on
label
Oct 26, 2023
meedbek
changed the title
Support direct shard routing through key provider
Support direct shard database operation routing in Spring JDBC
Oct 26, 2023
What do you mean by "taking over"? You mean replacing? If so, then there should be some discussion to close the other PR then. |
@snicoll thank you for the reply, it's done. The other PR has been closed. |
jhoeller
added
in: data
Issues in data modules (jdbc, orm, oxm, tx)
type: enhancement
A general enhancement
and removed
status: waiting-for-triage
An issue we've not yet triaged or decided on
labels
Nov 14, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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 PR is a follow up to #30988.
Goal is to add support for direct database operation routing in sharded databases in Spring JDBC.
This functionality is achieved by acquiring a shard connection through the JDBC API
DataSource.createConnectionBuilder().shardingKey(key).build().
In this PR we will focus on one of the two approaches that were introduced in the previous PR.
We introduce a DataSource adapter class that applies sharding keys to every standard getConnection() call. The sharding keys are specified through a ShardingKeyProvider object.
Here's an example of how to use it: