Skip to content
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

Detect 3rd-party changes made during replication #1214

Merged
merged 2 commits into from
Mar 20, 2015

Conversation

bajtos
Copy link
Member

@bajtos bajtos commented Mar 16, 2015

  • Modify Change.diff() to include current data revision in each delta reported back. The current data revision is stored in delta.prev.
  • Modify PersistedModel.bulkUpdate() to check that the current data revision matches delta.prev and report a conflict if a third party has modified the database under our hands.
  • Fix Change implementation and tests so that they are no longer attempting to create instances with duplicate ids. (This used to work because the memory connector was silently converting such requests to updateOrCreate/findOrCreate.)

Closes #986
Requires loopbackio/loopback-datasource-juggler#502
Requires loopbackio/loopback-datasource-juggler#511
Requires loopbackio/loopback-datasource-juggler#510

/to @ritch please review
/cc @BerkeleyTrue

Note: This change may be viewed as a breaking change, because a bulkUpdate called with a hand-crafted list of updates will probably start reporting conflict errors. If you think this is a valid concern and we should preserve BC for such users, then I am proposing to add a flag to bulkUpdate that will control this behaviour.

Thoughts?

@bajtos bajtos added the #review label Mar 16, 2015
@bajtos bajtos assigned bajtos and ritch and unassigned bajtos Mar 16, 2015
@bajtos bajtos force-pushed the fix/bulkUpdate-race-condition branch from dd4e039 to 552be04 Compare March 16, 2015 13:38
});
break;
case Change.DELETE:
// NOTE(bajtos) Delete does not care whether the model has
// the same revision as expected, we are going to delete it anyway
Copy link
Member

Choose a reason for hiding this comment

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

Delete does not care whether the model has the same revision as expected

The delete should be a conflict if the current target revision doesn't match the previous revision of the source. If someone has changed the target, we shouldn't blindly delete it (although I'm not certain that is what you are doing).

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I'll add a check for that too.

Copy link
Member Author

Choose a reason for hiding this comment

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

The fix for this requires loopbackio/loopback-datasource-juggler#511 and possibly implementation in all connectors.

@ritch ritch assigned bajtos and unassigned ritch Mar 17, 2015
@bajtos
Copy link
Member Author

bajtos commented Mar 18, 2015

@ritch I have addressed all your comments, PTAL again.

@bajtos bajtos assigned ritch and unassigned bajtos Mar 18, 2015
@bajtos bajtos added this to the #Epic: Offline Sync V1 milestone Mar 18, 2015
@ritch
Copy link
Member

ritch commented Mar 18, 2015

LGTM

@ritch ritch assigned bajtos and unassigned ritch Mar 18, 2015
@bajtos
Copy link
Member Author

bajtos commented Mar 20, 2015

@slnode test please

Modify `Change.diff()` to include current data revision in each
delta reported back. The current data revision is stored in
`delta.prev`.

Modify `PersistedModel.bulkUpdate()` to check that the current data
revision matches `delta.prev` and report a conflict if a third party
has modified the database under our hands.

Fix `Change` implementation and tests so that they are no longer
attempting to create instances with duplicate ids.
(This used to work because the memory connector was silently
converting such requests to updateOrCreate/findOrCreate.)
@bajtos bajtos force-pushed the fix/bulkUpdate-race-condition branch from b7a552a to 87940a4 Compare March 20, 2015 07:20
@bajtos
Copy link
Member Author

bajtos commented Mar 20, 2015

The Jenkins build is passing on v0.10 and v0.12 and failing on io.js 1.6.0 due to nodejs/node#1215 that has been fixed in 1.6.1. @rmg could you please upgrade our build slaves?

bajtos added a commit that referenced this pull request Mar 20, 2015
Detect 3rd-party changes made during replication
@bajtos bajtos merged commit 7454462 into master Mar 20, 2015
@bajtos bajtos removed the #review label Mar 20, 2015
@bajtos bajtos deleted the fix/bulkUpdate-race-condition branch March 20, 2015 07:30
@rmg
Copy link
Member

rmg commented Mar 20, 2015

Yep, I'll upgrade in the morning.

@bajtos
Copy link
Member Author

bajtos commented Mar 23, 2015

Note: This change may be viewed as a breaking change, because a bulkUpdate called with a hand-crafted list of updates will probably start reporting conflict errors. If you think this is a valid concern and we should preserve BC for such users, then I am proposing to add a flag to bulkUpdate that will control this behaviour.

@chandadharap @dashby3000 @sumitha Can you check with our customers if they are using bulkUdate on it's own? We don't have exact day when this will be released, I'd say it will be a week or two at most.

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.

Race condition in the replication algorithm
3 participants