-
Notifications
You must be signed in to change notification settings - Fork 31
STITCH-2584 Java SDK: Use bulk operations wherever possible on local database for sync #115
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
Conversation
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 have mostly questions before I give final approval. I didn't look at tests. Really nice changes and great stress test app improvements though!
android/build.gradle
Outdated
} | ||
testInstrumentationRunnerArgument "test.stitch.baseURL", properties.getProperty("test.stitch.baseURL", "http://10.0.2.2:9090") | ||
testInstrumentationRunnerArgument "test.stitch.baseURL", | ||
properties.getProperty("test.stitch.baseURL", "http://10.1.14.181:9090") |
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.
Undo
implementation "com.android.support:appcompat-v7:${support_library_version}" | ||
implementation "com.android.support:recyclerview-v7:${support_library_version}" | ||
implementation "com.android.support.constraint:constraint-layout:1.1.0" | ||
// implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.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.
uncomment?
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.
Can just delete, we don't need core.
<manifest package="com.mongodb.stitch.android.services.mongodb.remote"> | ||
<manifest package="com.mongodb.stitch.android.services.mongodb.remote" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<application android:usesCleartextTraffic="true" /> |
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 you can undo these changes
|
||
override fun getStitchBaseURL(): String { | ||
return InstrumentationRegistry.getArguments().getString("test.stitch.baseURL", "http://10.0.2.2:9090") | ||
return "http://10.0.2.2:9090" |
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.
Should this be reverted?
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
) { | ||
Map<BsonValue, CoreDocumentSynchronizationConfig> configs = new HashMap<>(); | ||
for (final BsonValue documentId : documentIds) { | ||
if (getSynchronizedDocument(documentId) == null) { |
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] Should we add a getSynchronizedDocuments
to speed this up?
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 don't think we need to, it's just reading from a hashmap.
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.
👍
* documents. | ||
*/ | ||
public class DataSynchronizer implements NetworkMonitor.StateListener { | ||
class BatchOps { |
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.
[nit] May be better to move this into its own class in a different file instead of this being an inner non-static class. Would just need to provide more args for its methods though to compensate not having direct access. Might be cleaner though.
} | ||
|
||
void merge(@Nullable final BatchOps batchOps) { | ||
if (batchOps != null) { |
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.
[nit] Can make this if null early return to reduce indentation
undoCollection.deleteOne(getDocumentIdFilter(documentId)); | ||
eventsToEmit.add(event); | ||
} | ||
triggerListeningToNamespace(namespace); |
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] Do we need to trigger here as a part of this 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.
Yes, desync
used to trigger every time it was called. It no longer does that, so we need to do it manually after desyncing has been done. There is a cleaner way to do this by tracking what operations have been done and if the streams need to be restarted.
} | ||
} | ||
|
||
void setPendingWritesCompleteNoDB(final BsonDocument atVersion) { |
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] Is the point of this to make sync not skip over these during batch processing?
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.
The point of this is to not replace the doc config everytime we set pending writes– that's very slow. So we change it in memory here and do a bulk write after the pass on the namespace is done.
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.
cool
new BsonDocument( | ||
CoreDocumentSynchronizationConfig.ConfigCodec.Fields.IS_STALE, | ||
new BsonBoolean(stale)))); | ||
// docsColl.updateOne( |
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.
Should this be uncommented or method removed?
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.
Removed
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.
LGTM
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.
Please address questions.
new BsonDocument( | ||
CoreDocumentSynchronizationConfig.ConfigCodec.Fields.IS_STALE, | ||
new BsonBoolean(stale)))); | ||
isStale = stale; |
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] approve of caching locally but looks like this never gets written to the docConfig as a result - are we ok with this?
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 does get written when we do the bulk writes.
In the event that the app crashes before it can be written, the document is marked stale anyway on app restart.
* @param atVersion the version for which the write occurred. | ||
* @param changeEvent the description of the write/change. | ||
*/ | ||
void setSomePendingWrites( |
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] why add this? does not appear this is called anywhere? did I miss it?
No description provided.