-
Notifications
You must be signed in to change notification settings - Fork 10
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
Introduced data freshness with the MongoDB implementation at connection-level and at query-level #209
Conversation
…on-level and at query-level
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #209 +/- ##
============================================
- Coverage 79.70% 79.69% -0.01%
- Complexity 1022 1036 +14
============================================
Files 194 198 +4
Lines 4879 4921 +42
Branches 408 411 +3
============================================
+ Hits 3889 3922 +33
- Misses 706 713 +7
- Partials 284 286 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@@ -6,7 +6,7 @@ plugins { | |||
id("org.hypertrace.ci-utils-plugin") version "0.3.0" | |||
id("org.hypertrace.publish-plugin") version "1.0.2" apply false | |||
id("org.hypertrace.code-style-plugin") version "1.1.0" apply false | |||
id("org.owasp.dependencycheck") version "8.2.1" | |||
id("org.owasp.dependencycheck") version "8.4.3" |
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.
Any reason for not moving to latest version - 10.0.4
?
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 tried that version. It's failing (mostly due to Java version incompatibility).
@@ -71,7 +71,7 @@ public class DocStoreTest { | |||
public static void init() { | |||
datastoreMap = Maps.newHashMap(); | |||
mongo = | |||
new GenericContainer<>(DockerImageName.parse("mongo:4.4.0")) | |||
new GenericContainer<>(DockerImageName.parse("mongo:7.0.14")) |
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.
Is the MongoDB version 7.0.14? Is this the same version that has been deployed?
* @param queryOptions The query options | ||
* @return {@link CloseableIterator} of matching documents | ||
*/ | ||
CloseableIterator<Document> query( |
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.
Q: the existing query api deprecated?
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.
Don't think that's required. If clients want to query with the default configurations, the older method can be used.
@SuppressWarnings("UnnecessarySemicolon") | ||
public enum DataFreshness { | ||
SYSTEM_DEFAULT, | ||
REALTIME_FRESHNESS, |
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.
Q: What does the freshness mean?
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.
Freshness means the liveliness of the data.
REALTIME_FRESHNESS means we want the most up-to-date data.
NEAR_REALTIME_FRESHNESS means a little bit of stale data is acceptable.
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.
Here NEAR_REALTIME_FRESHNESS
means fetching data from secondary, right?
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.
Yes. Basically "SECONDARY" is preferred. In case "SECONDARY" is not available, it'll fetch from "PRIMARY".
final CacheKey cacheKey = | ||
CacheKey.builder().readPreference(readPreference(connectionConfig, queryOptions)).build(); | ||
return collectionCache.computeIfAbsent( | ||
cacheKey, key -> collection.withReadPreference(key.readPreference())); |
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.
How is the CacheKey associated with the collection? Since ReadPreference can be either primary or secondary, does this mean that this.collectionCache
contains a maximum of 2 values?
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.
Since ReadPreference can be either primary or secondary, does this mean that this.collectionCache contains a maximum of 2 values?
Yes.
@SuppressWarnings("UnnecessarySemicolon") | ||
public enum DataFreshness { | ||
SYSTEM_DEFAULT, | ||
REALTIME_FRESHNESS, |
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.
Here NEAR_REALTIME_FRESHNESS
means fetching data from secondary, right?
This PRs gives the flexibility to redirect reads optionally to secondary MongoDB nodes.
This configuration can be tweaked at the connection-level while instantiating a connection-config object. It can also be configured at a query level. By default, all the reads will go to the primary node for backward compatibility.
Preference order:
In this PR, the Postgres implementation simply ignores the configuration.