generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 73
[Draft] Remote query cache plugin #1531
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
Open
QuChen88
wants to merge
23
commits into
aws:main
Choose a base branch
from
QuChen88:caching
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
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
examples/AWSDriverExample/src/main/java/software/amazon/DatabaseConnectionWithCacheExample.java
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/cache/CacheConnection.java
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/cache/CacheConnection.java
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/cache/CacheConnection.java
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/cache/CacheConnection.java
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/cache/DataRemoteCachePlugin.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/cache/DataRemoteCachePlugin.java
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/cache/DataRemoteCachePlugin.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/cache/DataRemoteCachePlugin.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/cache/DataRemoteCachePlugin.java
Show resolved
Hide resolved
0ebf8b3 to
2abea77
Compare
|
Updated with support for authentication. |
…on code for CachedResultSet.
Signed-off-by: Nihal Mehta <[email protected]>
…ined as a comment that prefixes the actual SQL query string. It can be in a case-insensitive form of "/* cacheTTL=60s */" to indicate that the query should be cached with 60 seconds of TTL. Or it can indicate the query should not be cached via "/* no cache */".
Allow reading cache query result from replica in cluster mode enabled Redis/Valkey, and support cluster mode disabled setting.
Re-factored all the caching logic into its own directory, and removed unnecessary code and logging.
Fix several issues with caching results:
- Handle failure in cache connection initialization as a cache miss
- Support getString(), getInt(), getDouble(), getFloat(), getBigDecimal(), getBoolean(), getDate(), getTime(), getTimestamp(), getShort() and getByte() APIs for CachedResultSet
- Fix a bug with converting ResultSet into CachedResultSet, and populate basic info for ResultSetMetaData.
Signed-off-by: Nihal Mehta <[email protected]>
…saction. Add unit test for CacheConnection logic.
--------- Co-authored-by: Roberto Luna Rojas <[email protected]>
…ample file to reflect database-agnostic functionality --------- Co-authored-by: Roberto Luna Rojas <[email protected]>
…ic to rely on standard Java object serialization instead of custom JacksonMapper logic. Namely removed custom serialization logic for several special data types that are returned by the underlying SQL driver. Handle conversion from Number for getBigDecimal() and added unit tests for it.
…s (pull request #1) - Replace /* cacheTTL=300s */ with /*+ CACHE_PARAM(ttl=300s) */ format - Add case-insensitive CACHE_PARAM parsing with flexible placement - Implement malformed hint detection with JdbcCacheMalformedQueryHint telemetry - Add comprehensive test coverage for valid/invalid/malformed cases - Support multiple parameters for future extensibility Fixes: Query hint parsing to follow Oracle SQL hint standards feat: add TTL validation for cache query hints - Reject TTL values <= 0 as malformed hints - Allow large TTL values (no upper limit) - Increment malformed hint counter for invalid TTL values - Add comprehensive test coverage for TTL edge cases Validates: ttl=0s, ttl=-10s → not cacheable Allows: ttl=999999s → cache with large TTL updated test cases to reflect new implementation
…improve the caching performance. Renamed DataCacheConnectionPlugin to DataLocalCacheConnectionPlugin for clarity
… support to CachedResultSet (PR #2) fix: Add Timestamp support to CachedResultSet getTime() and getDate() - Implement missing instanceof Timestamp cases in convertToTime() and convertToDate() - Use new Time(timestamp.getTime()) and new Date(timestamp.getTime()) for standard JDBC behavior - Add comprehensive test coverage for Timestamp conversion scenarios - Fix object equality issues in tests by using consistent constructors Resolves missing Timestamp handling that previously fell through to string parsing. added more tests and cleaned up debug logs removed uncessary imports, fixed testing logic for getTime() and getDate() and fixed implementation error for getBytes() and getBoolean() in the original codebase updated future timestamp testing to make it more robust intead of hardcoding the future timestamp updated convertToTime() to use static timezone offset -- functionality unchanged
…etter error logging.
…ssCount, and JdbcCachedQueryAfterUpdate (PR #3) JdbcCachedQueryAfterUpdate feature removed Add OpenTelemetry integration for cache latency monitoring fixed variable naming, added one more context for latency tracking took out cacheMissContext and removed dbContext setSuccess logging removed redundant variables handled closing cacheContext for SQLException and removed dbContext error handling minor syntax fix updated unit tests for the latest telemetry metrics
The postgres test table contains 11 columns containing different data types. The example program populates the table with 400K records, each record has > 1KB of data, for a total of ~520MB of data in the table. It then performs SELECT queries continuously across all 400K rows. postgres=# CREATE TABLE test (id SERIAL PRIMARY KEY, int_col INTEGER, varchar_col varchar(50) NOT NULL, text_col TEXT, num_col DOUBLE PRECISION, date_col date, time_col TIME WITHOUT TIME ZONE, time_tz TIME WITH TIME ZONE, ts_col TIMESTAMP WITHOUT TIME ZONE, ts_tz TIMESTAMP WITH TIME ZONE), description TEXT; CREATE TABLE postgres=# select * from test; id | int_col | varchar_col | text_col | num_col | date_col | time_col | time_tz | ts_col | ts_tz | description ----+---------+-------------+----------+---------+----------+----------+---------+--------+-------+-------------- (0 rows) Suppress debug logs and only log at INFO level and above for example program.
0515db4 to
27433c5
Compare
- Add ElastiCacheIamTokenUtility for token generation - Extend DataRemoteCachePlugin with IAM auth detection - Support serverless and regular ElastiCache endpoints - Implement 15-minute token refresh and 12-hour re-auth cycles - Add cacheIamAuthEnabled configuration property
Caching: Allow user to configure cache connection timeout and max cache connection count
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.
Summary
Remote caching plugin implementation. The goal of the plugin is to cache query result in a remote cache server for certain read-only queries that are deemed to be cacheable. All incoming queries that contain a query hint with caching parameter settings specified will have their responses cached with the defined TTL. Further requests with the same query get their result served from the cache instead of from the backend database. The remote cache server runs on Redis / Valkey and is assumed to be able to scale and handle eviction of data when the cache is full, so the size limitation is no longer an issue on the client side.
Basic walkthrough of code:
DataRemoteCachePlugin.java. It contains the core logic for the remote caching on both the query read path and write path. It will call intoCacheConnection.javato handle reading and writing to the remote cache server.CacheConnection.javamainly handles interaction between the client and the cache server via a connection pool. On the write path, the query result gets serialized into raw bytes which gets stored in the cache server. On the read path, the query result gets fetched from the cache server, de-serialized into Java objects and returned back to the driver application for consumption.CachedResultSet.java.getXXXAPIs there for supported for various data types (e.g. String, boolean, int, double, float, Date, Timestamp, etc) along with serialization and de-serialization logic forCachedResultSet.DataCacheConnectionPlugin.javahas been re-factored intoDataLocalCacheConnectionPluginFactory.javato have a more descriptive name indicating it is storing cached results locally.DataRemoteCachePlugin. Specifically a few additional properties are required for the plugin to work.TODOs