-
Notifications
You must be signed in to change notification settings - Fork 49
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 example code for Read/Write Splitting sample #765
Conversation
@@ -0,0 +1,26 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need a new folder or a new package inside AWSDriverExample ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm not sure what you are suggesting, can you clarify? I believe the ReadWriteSplittingSample directory matches our other example directory structures, eg HikariExample. Are you suggesting I move this to the AWSDriverExample directory instead of having it in its own directory? My concerns with doing that are that AWSDriverExample contains single isolated java files, but this sample might end up containing multiple java files, and the logging config in ReadWriteSplittingExample is pretty specific to just ReadWriteSplittingSample.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something that is not directly for this PR: i kinda question the structure with folders for each set of examples, instead of packages. when having multiple folders, then there are more files needed to set up the gradle configuration for each of those folders.
As this structure was in place before i added telemetry into it, i was wondering whether that was on purpose or needed to be kept. I'm ok with either, just asking questions on what makes more sense
// 1: no r/w splitting | ||
// 2: r/w splitting using r/w plugin | ||
// 3: r/w plugin with internal connection pools | ||
static final int APPROACH_ID = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we should abandon the approach idea and have one sample file for each approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would simplify the file, but there would also be more code duplication and users would no longer be able to view all the code at once in a single file. Do we still want to go ahead with splitting this into different files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple files follow some arbitrary guidelines that I have seen since working on the wrapper. We tend to have multiple small files that handle one single case so users can run/copy them. If you believe the "approach" strategy matches better the way people will read it, that's completely fine by me too.
examples/ReadWriteSplittingSample/src/main/java/software/amazon/ReadWriteSplittingSample.java
Show resolved
Hide resolved
examples/ReadWriteSplittingSample/src/main/java/software/amazon/ReadWriteSplittingSample.java
Outdated
Show resolved
Hide resolved
examples/ReadWriteSplittingSample/src/main/java/software/amazon/ReadWriteSplittingSample.java
Outdated
Show resolved
Hide resolved
examples/ReadWriteSplittingSample/src/main/java/software/amazon/ReadWriteSplittingSample.java
Outdated
Show resolved
Hide resolved
examples/ReadWriteSplittingSample/src/main/java/software/amazon/ReadWriteSplittingSample.java
Show resolved
Hide resolved
examples/ReadWriteSplittingSample/src/main/java/software/amazon/ReadWriteSplittingSample.java
Outdated
Show resolved
Hide resolved
try (PreparedStatement stmt = conn.prepareStatement(selectSQL)) { | ||
for (int i = 0; i < NUM_READS; i++) { | ||
stmt.setInt(1, tableNum); | ||
stmt.execute(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didnt try it out but I think you can do the following so you only execute once:
try (PreparedStatement stmt = conn.prepareStatement(selectSQL)) { | |
for (int i = 0; i < NUM_READS; i++) { | |
stmt.setInt(1, tableNum); | |
stmt.execute(); | |
} | |
} | |
try (PreparedStatement stmt = conn.prepareStatement(selectSQL)) { | |
for (int i = 0; i < NUM_READS; i++) { | |
stmt.setInt(1, tableNum); | |
stmt.addToBatch(); | |
} | |
stmt.executeBatch(); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the advantage to doing it this way? If its just for performance, I wonder if we should make the change or not. I was using this code to purposely overload the writer so that we could observe how r/w splitting improved performance for this scenario. Then again, users probably won't be overloading their writer when they execute this code, since it requires a pretty specific configuration of settings in this file and rds cluster configuration settings. What do you think, should we go ahead with your suggested change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a more common practice to use batch execute because of performance improvements. I just think that since it is a sample code we would want to follow best practices in our code. If we use batchExecute do we no longer see a performance improvement?
1eb3e1d
to
02f8b96
Compare
95215bc
to
c6c1691
Compare
* Configuration Profiles (aws#711) Co-authored-by: sergiyvamz <svvoshch@amazon.com> * chore(deps): bump org.testcontainers:postgresql from 1.19.1 to 1.19.2 (aws#743) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump io.vertx:vertx-stack-depchain from 4.4.6 to 4.5.0 (aws#745) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump org.testcontainers:junit-jupiter from 1.19.1 to 1.19.2 (aws#747) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump io.opentelemetry:opentelemetry-api from 1.31.0 to 1.32.0 (aws#746) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump com.fasterxml.jackson.core:jackson-databind from 2.15.3 to 2.16.0 (aws#744) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Disable failing integration test for PG driver (aws#742) * Configuration Profiles documentation (aws#738) * feat: Autoregister a target driver (aws#748) * chore: reduce log level for intentionally ignored exceptions (aws#751) * chore(deps): bump org.testcontainers:mariadb from 1.19.1 to 1.19.3 (aws#756) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump software.amazon.awssdk:secretsmanager from 2.21.21 to 2.21.31 (aws#762) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump io.opentelemetry:opentelemetry-sdk from 1.31.0 to 1.32.0 (aws#758) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump org.testcontainers:postgresql from 1.19.2 to 1.19.3 (aws#757) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump org.testcontainers:junit-jupiter from 1.19.2 to 1.19.3 (aws#759) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat: node fastest response time strategy (aws#755) * chore: update changelog and versioning for version 2.3.1 (aws#754) * chore(deps): bump org.testcontainers:testcontainers from 1.19.1 to 1.19.3 (aws#771) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump org.mariadb.jdbc:mariadb-java-client from 3.3.0 to 3.3.1 (aws#767) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump org.apache.poi:poi-ooxml from 5.2.4 to 5.2.5 (aws#769) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump software.amazon.awssdk:secretsmanager from 2.21.31 to 2.21.38 (aws#772) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump software.amazon.awssdk:rds from 2.21.11 to 2.21.38 (aws#773) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump software.amazon.awssdk:rds from 2.21.38 to 2.21.42 (aws#776) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump org.postgresql:postgresql from 42.6.0 to 42.7.1 (aws#778) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump software.amazon.awssdk:secretsmanager from 2.21.38 to 2.21.43 (aws#781) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump io.opentelemetry:opentelemetry-exporter-otlp from 1.32.0 to 1.33.0 (aws#777) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: use existing entries to update the round robin cache (aws#739) * set hostId in HostSpec (aws#782) * docs: update HikariCP example to include configuring the datasource with a JDBC URL (aws#749) * Enhanced host monitoring plugin ver.2 (aws#764) * Fix: expose AuroraInitialConnectionStrategyPlugin with a plugin code (aws#784) * feat: FederatedAuthConnectionPlugin (aws#741) * chore: replace synchronized with locks in AwsCredentialsManager (aws#785) * docs: FederatedAuthPlugin (aws#787) Co-authored-by: Karen <64801825+karenc-bq@users.noreply.github.com> * chore(deps): bump io.opentelemetry:opentelemetry-sdk-metrics from 1.32.0 to 1.33.0 (aws#792) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump software.amazon.awssdk:ec2 from 2.21.12 to 2.22.1 (aws#795) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump io.opentelemetry:opentelemetry-api from 1.32.0 to 1.33.0 (aws#794) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump org.junit.jupiter:junit-jupiter-params from 5.10.0 to 5.10.1 (aws#793) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Improve efm2 failure detection timing (aws#797) * chore: update versioning and changelog (aws#791) * fix: SqlMethodAnalyzer to handle empty SQL query and not throw IndexOutOfBoundsException (aws#798) * Add documentation for read/write splitting Spring limitations (aws#800) * Add example code for Read/Write Splitting sample (aws#765) * fix: restructuring try blocks in dialects for exception handling (aws#799) * chore(deps): bump software.amazon.awssdk:secretsmanager from 2.21.43 to 2.22.5 (aws#802) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump io.vertx:vertx-stack-depchain from 4.5.0 to 4.5.1 (aws#803) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump com.amazonaws:aws-xray-recorder-sdk-core from 2.14.0 to 2.15.0 (aws#804) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: add missing log message (aws#801) Co-authored-by: Bruno Paiva Lima da Silva <64107800+brunos-bq@users.noreply.github.com> * fix: making a variable volatile in RdsHostListProvider (aws#806) * chore(deps): bump software.amazon.awssdk:ec2 from 2.22.1 to 2.22.9 (aws#808) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump io.opentelemetry:opentelemetry-sdk from 1.32.0 to 1.33.0 (aws#809) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump org.postgresql:postgresql from 42.6.0 to 42.7.1 (aws#810) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump tj-actions/changed-files from 37 to 41 in /.github/workflows (aws#811) * transfer session state during failover (aws#814) * feat: Session state transfer redesign (aws#821) * chore(deps): bump software.amazon.awssdk:rds from 2.21.42 to 2.22.13 (aws#822) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump software.amazon.awssdk:sts from 2.21.42 to 2.22.13 (aws#823) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump com.fasterxml.jackson.core:jackson-databind from 2.16.0 to 2.16.1 (aws#818) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump com.github.spotbugs from 5.2.+ to 6.0.6 (aws#820) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Improve Multi-AZ cluster detection (aws#824) --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Bruno Paiva Lima da Silva <64107800+brunos-bq@users.noreply.github.com> Co-authored-by: sergiyvamz <svvoshch@amazon.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: sergiyvamz <75754709+sergiyvamz@users.noreply.github.com> Co-authored-by: Karen <64801825+karenc-bq@users.noreply.github.com> Co-authored-by: crystall-bitquill <97126568+crystall-bitquill@users.noreply.github.com> Co-authored-by: aaronchung-bitquill <118320132+aaronchung-bitquill@users.noreply.github.com> Co-authored-by: congoamz <75754763+congoamz@users.noreply.github.com>
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.