Skip to content

Conversation

jsflax
Copy link
Contributor

@jsflax jsflax commented Nov 1, 2018

  • Fix for swapped boolean logic for same GUIDs
  • Fix for unprocessed events not being read in L2R
  • Tests for:
    SyncVersionConflictedUpdateRemoteWins
    SyncVersionConflictedUpdateLocalWins
    RemoteUpdateLocalAndRemoteEmptyVersion
    RemoteUpdateLocalOrRemoteEmptyVersion
    RemoteUpdateLocalVersionEqual
    RemoteUpdateLocalVersionHigher
    RemoteUpdateRemoteVersionHigher
    RemoteUpdateDifferentGUIDs
    RemoteUpdateDifferentGUIDsNewDoc

@jsflax jsflax requested review from edaniels, adamchel and dkaminsky and removed request for edaniels November 1, 2018 21:28
@coveralls
Copy link

Coverage Status

Coverage decreased (-4.6%) to 66.18% when pulling 4081f20 on jsflax:STITCH-2134 into ee20789 on mongodb:master.

@coveralls
Copy link

coveralls commented Nov 1, 2018

Coverage Status

Coverage decreased (-43.3%) to 27.5% when pulling faa8ec8 on jsflax:STITCH-2134 into ee20789 on mongodb:master.

Copy link
Contributor

@adamchel adamchel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a bunch of nits and q's, mostly about the comments in the unit tests.

// i. Find the corresponding local document config.
final CoreDocumentSynchronizationConfig docConfig =
nsConfig.getSynchronizedDocument(eventEntry.getKey().asDocument().get("_id"));
nsConfig.getSynchronizedDocument(eventEntry.getValue().getDocumentKey().get("_id"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] the arg can be BsonUtils.getDocumentId(eventEntry.getValue().getDocumentKey())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix that we spoke about in Slack earlier.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BsonUtils.getDocumentId() is just a helper that makes it so you don't have to do .get("_id") with the hardcoded "_id" string

nsLock.writeLock().lockInterruptibly();
try {
events.put(event.getData().getDocumentKey(), event.getData());
events.put(event.getData().getDocumentKey().get("_id"), event.getData());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] the arg can be BsonUtils.getDocumentId(event.getData().getValue().getDocumentKey())

*/
fun mockDeleteException(exception: Exception)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] newline

verify(ctx.collectionMock).insertOne(captor.capture())
val versionDoc =
DocumentVersionInfo.fromVersionDoc(captor.value["__stitch_sync_version"]!!.asDocument())
println(versionDoc)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] is this println from debugging? also shouldn't we check the values in the versionDoc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was exclusively for debugging. I'm not sure checking the inner values of version doc is valuable here, since we are really seeking out a specific result unrelated to what the versionDoc looks like.

ctx.insertTestDocument()
ctx.doSyncPass()
// update the doc locally and queue a fake update remotely.
// neither of these will have versions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] update comment

ctx.insertTestDocument()
ctx.doSyncPass()
// update the doc locally and queue a fake update remotely.
// neither of these will have versions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] update comment

ctx.queueConsumableRemoteUpdateEvent(
ctx.testDocumentId,
pseudoUpdatedDocument,
TestVersionState.NEXT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] why does this update not go through if it is indeed the next version? I think this update does go through, but the update at line 1473 doesn't go through. or am I understanding this wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The final update does not go through, because when we downgrade the remote version, our R2L code considers it an event generated by us, as intended.

TestVersionState.NEW)

ctx.shouldConflictBeResolvedByRemote = true
// sync, creating a conflict. because remote has an empty version,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit q] I thought remote has a version with a new GUIDs, not an empty version (meaning no GUID at all). I would think that this case isn't supposed to delete anything, but rather replace the local doc with the new document in the update event

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I see what's happening now. The remote event is stale (but has a document with a new version GUID), but the remote collection itself no longer has the document, so the conflict is using the latest remote document which doesn't exist to resolve the conflict. maybe you should update the comments to clarify that

ctx.insertTestDocument()
ctx.doSyncPass()
// update the doc locally and queue a fake update remotely.
// neither of these will have versions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] update comment

when (versionState) {
TestVersionState.NONE ->
fakeUpdateDoc.remove("__stitch_sync_version")
TestVersionState.PREVIOUS ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] might be worth throwing an IllegalStateException if documentVersionInfo.version.versionCounter <= 0 so we know we're not doing anything funky by having a negative version counter in the test.

Copy link
Contributor

@edaniels edaniels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

val fakeUpdateDoc = document.clone()
val cachedVersion = fakeUpdateDoc["__stitch_sync_version"] ?: getVersionForTestDocument()

if (cachedVersion != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat

@jsflax jsflax merged commit 7c836d0 into mongodb:master Nov 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants