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

Atomic upsertWithWhere #563

Merged
merged 1 commit into from Nov 30, 2020
Merged

Conversation

mrbatista
Copy link
Contributor

@mrbatista mrbatista commented Feb 9, 2020

Implement atomic upsertWithWhere method.

The out-of-the-box implementation catch error if multiple instances are founds.
With atomic implementation one test present in the juggler datasource will be disabled.
I added a new option to specify if connector has an atomic implementation. See loopbackio/loopback-datasource-juggler#1864.

Checklist

👉 Read and sign the CLA (Contributor License Agreement) 👈

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • Commit messages are following our guidelines

@stale
Copy link

stale bot commented May 30, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 30, 2020
@agnes512
Copy link
Contributor

agnes512 commented Jun 5, 2020

@mrbatista Thank you for the PR. Could you add some tests for the changes?

@stale stale bot removed the stale label Jun 5, 2020
@stale
Copy link

stale bot commented Aug 8, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 8, 2020
@agnes512 agnes512 removed the stale label Aug 10, 2020
@dhmlau
Copy link
Member

dhmlau commented Aug 21, 2020

We just switch the contribution method from CLA to DCO, making your contribution easier in the future. Please sign the commits with DCO by amending your commit messages with -s flag and push the changes again. If you're using the command line, you can:

git commit --amend -s
git push --force-with-lease

Please refer to this docs page for details. Thanks!

For more questions, please join our Slack workspace - #loopback-contributors.

@jamesjjk
Copy link

jamesjjk commented Sep 2, 2020

@mrbatista @fabien I don't understand why you would want to use a transactional operation? Maybe I'm missing something. Atomic upsert and document return is achieved with findAndModify operation with the "new" and "update" flags. transactional seems overkill.

@mrbatista mrbatista changed the title [WIP] Transactional upsertWithWhere [WIP] Atomic upsertWithWhere Sep 2, 2020
@mrbatista
Copy link
Contributor Author

@jamesjjk If the connector does not implement the upsertWithWhere method, the DAO use a non atomic implementation. See the relevant code.
I need the atomic implementation for concurrent requests.

@jamesjjk
Copy link

jamesjjk commented Sep 2, 2020

@jamesjjk If the connector does not implement the upsertWithWhere method, the DAO use a non atomic implementation. See the relevant code.
I need the atomic implementation for concurrent requests.

@mrbatista Atomic I fully understand but why transactional? I too need an atomic version which is implemented by MongoDB native findAndModify with the appropriate parameters. Your ticket mentions transactional, which is not the same as an atomic opetation. Would it not be sufficient to implement findAndModify (with new and upsert parameters) in the connector to parse any of the DOA's upsertWithWhere operations?

@mrbatista
Copy link
Contributor Author

@jamesjjk I changed the title to respect the implementation of this PR.
For the implementation the DAO define the methods that each connector (oracle, mysql, ecc..) can implement.
If use findAndModfy (with specific options set) or updateMany (like in this PR) is not relevant.

@jamesjjk
Copy link

jamesjjk commented Sep 2, 2020

@mrbatista Understood, are you updating the respective connector? Which connector are you using if I may ask?

@mrbatista
Copy link
Contributor Author

mrbatista commented Sep 2, 2020

@mrbatista Understood, are you updating the respective connector? Which connector are you using if I may ask?

I'm currently using my fork which implements atomic upsertWithWhere.
Today add more test to permit review by mainteners of this repo. 😃

@mrbatista mrbatista changed the title [WIP] Atomic upsertWithWhere Atomic upsertWithWhere Sep 2, 2020
@mrbatista mrbatista force-pushed the feat/upsert-with-where branch 2 times, most recently from 06c0958 to be18dae Compare September 2, 2020 12:48
mrbatista added a commit to mrbatista/loopback-datasource-juggler that referenced this pull request Sep 2, 2020
mrbatista added a commit to mrbatista/loopback-datasource-juggler that referenced this pull request Sep 2, 2020
See loopbackio/loopback-connector-mongodb#563

Signed-off-by: Matteo Padovano <mrbatista@users.noreply.github.com>
@mrbatista
Copy link
Contributor Author

mrbatista commented Sep 2, 2020

@agnes512 I have update the PR and first comment. Please review.
No test needed because the functionality of upsertWithWhere method is tested in loopback-datasource-juggler.
See relevant test:

  1. normalize-undefined test
  2. crud-with-options test
  3. manipulation test
  4. persistence-hooks suite

To have green tests need to merge this PR loopbackio/loopback-datasource-juggler#1864

@jannyHou
Copy link
Contributor

Thanks @mrbatista , I merged and published the juggler test, but it fails due to

1) juggler-v3

       manipulation

         upsertWithWhere

           fails the upsertWithWhere operation when multiple instances are retrieved based on the filter criteria:

      Uncaught AssertionError: expected 'Performing an update on the path \'_id\' would modify the immutable field \'_id\'' to be 'There are multiple instances found.Upsert Operation will not be performed!'

      + expected - actual

      -Performing an update on the path '_id' would modify the immutable field '_id'

      +There are multiple instances found.Upsert Operation will not be performed!

juggler-v3 complains the same problem. Could you take a look?

@jannyHou
Copy link
Contributor

cc @mrbatista any update about the test?

@mrbatista
Copy link
Contributor Author

@jannyHou You have release only juggler 4.x. Please backport the change of this commit in 3.x juggler branch.
Ping me when release a new 3.x version.

@mrbatista
Copy link
Contributor Author

@jannyHou On my local environment only the juggler 3.x fail.

jannyHou pushed a commit to loopbackio/loopback-datasource-juggler that referenced this pull request Oct 15, 2020
Introduce the new property atomicUpsertWithWhere for
connector that implement specific method.
See loopbackio/loopback-connector-mongodb#563
for mongodb implementation.

Signed-off-by: Matteo Padovano <mrbatista@users.noreply.github.com>
@jannyHou
Copy link
Contributor

@mrbatista Thanks, I see created PR loopbackio/loopback-datasource-juggler#1871 to back port it.

jannyHou pushed a commit to loopbackio/loopback-datasource-juggler that referenced this pull request Oct 19, 2020
Introduce the new property atomicUpsertWithWhere for
connector that implement specific method.
See loopbackio/loopback-connector-mongodb#563
for mongodb implementation.

Signed-off-by: Matteo Padovano <mrbatista@users.noreply.github.com>
@mrbatista
Copy link
Contributor Author

@jannyHou Any update on this PR?

@jannyHou
Copy link
Contributor

Hi @mrbatista sorry for late update, I am making time to address the feedback in loopbackio/loopback-datasource-juggler#1871, after that, this PR should be good to land.

jannyHou pushed a commit to loopbackio/loopback-datasource-juggler that referenced this pull request Nov 23, 2020
Introduce the new property atomicUpsertWithWhere for
connector that implement specific method.
See loopbackio/loopback-connector-mongodb#563
for mongodb implementation.

Signed-off-by: Matteo Padovano <mrbatista@users.noreply.github.com>
jannyHou pushed a commit to loopbackio/loopback-datasource-juggler that referenced this pull request Nov 23, 2020
Introduce the new property atomicUpsertWithWhere for
connector that implement specific method.
See loopbackio/loopback-connector-mongodb#563
for mongodb implementation.

Signed-off-by: Matteo Padovano <mrbatista@users.noreply.github.com>
jannyHou added a commit to loopbackio/loopback-datasource-juggler that referenced this pull request Nov 24, 2020
Introduce the new property atomicUpsertWithWhere for
connector that implement specific method.
See loopbackio/loopback-connector-mongodb#563
for mongodb implementation.

Signed-off-by: Matteo Padovano <mrbatista@users.noreply.github.com>

Co-authored-by: Matteo Padovano <mrbatista@users.noreply.github.com>
@jannyHou
Copy link
Contributor

@slnode test please

@bajtos
Copy link
Member

bajtos commented Nov 26, 2020

I wanted to re-run Travis CI build but it looks like the old Travis at https://travis-ci.org does not allow that (or I don't have permissions to do so). I think we will need to force-push to the feature branch to trigger a new build, can you @jannyHou PTAL?

We need a new run to pick the recently released versions of juggler v3 and v4 that should fix the failure of the test it fails the upsertWithWhere operation when multiple instances are retrieved based on the filter criteria

@jannyHou
Copy link
Contributor

@bajtos thank you for looking into the error, triggered a test.

@jannyHou
Copy link
Contributor

jannyHou commented Nov 27, 2020

It failed because I didn't release the change in juggler v3. Just released 3.36.1, let me rerun it.

Great it passed.

@mrbatista
Copy link
Contributor Author

@jannyHou green CI 🎉🥳

Signed-off-by: = <mrbatista@users.noreply.github.com>
Copy link
Contributor

@jannyHou jannyHou left a comment

Choose a reason for hiding this comment

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

👍 Cheers!

Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

👏🏻

@jannyHou jannyHou merged commit 0cf4d7e into loopbackio:master Nov 30, 2020
bajtos added a commit that referenced this pull request Dec 1, 2020
 * atomic upsertWithWhere (#563) (Matteo Padovano)
vramaniuk pushed a commit to jrcigars/loopback-connector-mongodb that referenced this pull request May 30, 2023
Signed-off-by: = <mrbatista@users.noreply.github.com>
vramaniuk pushed a commit to jrcigars/loopback-connector-mongodb that referenced this pull request May 30, 2023
 * atomic upsertWithWhere (loopbackio#563) (Matteo Padovano)
vramaniuk pushed a commit to jrcigars/loopback-connector-mongodb that referenced this pull request Jun 1, 2023
Use each to itterate through restuls rather than toArray to aviod issues with large datasets [fixes loopbackio#129]
chore(release): v7.0.0-alpha.1

 * ci: update Node.js test matrix (Rifa Achrinza)

 * chore: update Node.js engine matrix (Rifa Achrinza)

 * feat: upgrade mongodb driver to version 4.x (Antonio Ramón Sánchez Morales)

 * chore: lock file maintenance (renovate[bot])

 * chore: update supercharge/mongodb-github-action action to v1.8.0 (renovate[bot])

 * chore: update dependency eslint to ^8.23.0 (renovate[bot])

 * chore: update commitlint monorepo to v17 (renovate[bot])

 * chore: update dependency eslint to ^8.19.0 (renovate[bot])

 * chore: update github/codeql-action action to v2 (renovate[bot])

 * chore: update dependency mocha to ^9.2.2 (renovate[bot])

 * chore: update dependency loopback-datasource-juggler to ^4.27.1 (renovate[bot])

 * chore: update dependency eslint to ^8.18.0 (renovate[bot])

 * chore: update dependency strong-globalize to ^6.0.5 (renovate[bot])

 * chore: update supercharge/mongodb-github-action action to v1.7.0 (renovate[bot])

 * chore: update actions/setup-node action to v3 (renovate[bot])

 * chore: update actions/checkout action to v3 (renovate[bot])

 * chore: update dependency semver to ^7.3.7 (renovate[bot])

 * chore: update dependency should to ^13.2.3 (renovate[bot])

 * chore: update dependency debug to ^4.3.4 (renovate[bot])

 * chore: update dependency loopback-connector to ^5.0.1 (renovate[bot])

 * chore: update dependency bson to ^1.1.6 (renovate[bot])

 * chore: update dependency bluebird to ^3.7.2 (renovate[bot])

 * chore: update dependency async to ^3.2.4 (renovate[bot])

 * ci: add renovate config (Rifa Achrinza)

 * fix(*): run autoupdate in serial to avoid conflicts (Simon Stone)

 * fix: optional chaining (preussmann)

 * chore: update v6 EOL (Rifa Achrinza)

 * ci: test against Node.js v18 (Rifa Achrinza)

Signed-off-by: Rifa Achrinza <25147899+achrinza@users.noreply.github.com>
ci: update Node.js test matrix

Signed-off-by: Rifa Achrinza <25147899+achrinza@users.noreply.github.com>
chore: update Node.js engine matrix

BREAKING CHANGE: This drops explicit, documented support for Node.js
v10, v11, v12, v13, v15, v17

Signed-off-by: Rifa Achrinza <25147899+achrinza@users.noreply.github.com>
feat: upgrade mongodb driver to version 4.x

Signed-off-by: Antonio Ramón Sánchez Morales <antonioramonsm@gmail.com>
chore: lock file maintenance

Signed-off-by: Renovate Bot <bot@renovateapp.com>
chore: update supercharge/mongodb-github-action action to v1.8.0

Signed-off-by: Renovate Bot <bot@renovateapp.com>
chore: update dependency eslint to ^8.23.0

Signed-off-by: Renovate Bot <bot@renovateapp.com>
chore: update commitlint monorepo to v17

Signed-off-by: Renovate Bot <bot@renovateapp.com>
chore: update dependency eslint to ^8.19.0

Signed-off-by: Renovate Bot <bot@renovateapp.com>
chore: update github/codeql-action action to v2

Signed-off-by: Renovate Bot <bot@renovateapp.com>
chore: update dependency mocha to ^9.2.2

Signed-off-by: Renovate Bot <bot@renovateapp.com>
chore: update dependency loopback-datasource-juggler to ^4.27.1

Signed-off-by: Renovate Bot <bot@renovateapp.com>
chore: update dependency eslint to ^8.18.0

Signed-off-by: Renovate Bot <bot@renovateapp.com>
chore: update dependency strong-globalize to ^6.0.5

Signed-off-by: Renovate Bot <bot@renovateapp.com>
chore: update supercharge/mongodb-github-action action to v1.7.0

Signed-off-by: Renovate Bot <bot@renovateapp.com>
chore: update actions/setup-node action to v3

Signed-off-by: Renovate Bot <bot@renovateapp.com>
chore: update actions/checkout action to v3

Signed-off-by: Renovate Bot <bot@renovateapp.com>
chore: update dependency semver to ^7.3.7

Signed-off-by: Renovate Bot <bot@renovateapp.com>
chore: update dependency should to ^13.2.3

Signed-off-by: Renovate Bot <bot@renovateapp.com>
chore: update dependency debug to ^4.3.4

Signed-off-by: Renovate Bot <bot@renovateapp.com>
chore: update dependency loopback-connector to ^5.0.1

Signed-off-by: Renovate Bot <bot@renovateapp.com>
chore: update dependency bson to ^1.1.6

Signed-off-by: Renovate Bot <bot@renovateapp.com>
chore: update dependency bluebird to ^3.7.2

Signed-off-by: Renovate Bot <bot@renovateapp.com>
chore: update dependency async to ^3.2.4

Signed-off-by: Renovate Bot <bot@renovateapp.com>
ci: add renovate config

see: loopbackio/cicd#15

Signed-off-by: Rifa Achrinza <25147899+achrinza@users.noreply.github.com>
fix(*): run autoupdate in serial to avoid conflicts

Signed-off-by: Simon Stone <Simon.Stone@docusign.com>
fix: optional chaining

fixed error if this._models[modelName] is an empty object

Signed-off-by: minp <nicolas.preussmann@impact-group.de>
chore: update v6 EOL

Signed-off-by: Rifa Achrinza <25147899+achrinza@users.noreply.github.com>
ci: test against Node.js v18

see: loopbackio/cicd#27

Signed-off-by: Rifa Achrinza <25147899+achrinza@users.noreply.github.com>
6.2.0

 * docs: add SECURITY.md (Diana Lau)
 * chore: tls README example (d-bo)
 * docs: update coc (Diana Lau)
 * docs: add code of conduct (Diana Lau)
 * chore: update v6 EOL (Rifa Achrinza)
 * ci: fix typo (Rifa Achrinza)
 * chore: update deps (Rifa Achrinza)
 * feat: add tls options as of mongo 3.7 (d-bo)
 * ci: update Node.js version (Rifa Achrinza)
 * ci: pin NPM version (Rifa Achrinza)
 * chore: add @achrinza and update CODEOWNERS (Diana Lau)
 * fix: isObjectIDProperty array param check (Rifa Achrinza)
 * fix: handle url default db name (Rifa Achrinza)
 * ci: restrict GITHUB_TOKEN permissions (Rifa Achrinza)
docs: add SECURITY.md

Signed-off-by: Diana Lau <dhmlau@ca.ibm.com>
chore: tls README example

Signed-off-by: d-bo <vathsven@pm.me>
docs: update coc

Signed-off-by: Diana Lau <dhmlau@ca.ibm.com>
docs: add code of conduct

Signed-off-by: Diana Lau <dhmlau@ca.ibm.com>
chore: update v6 EOL

Coninuation of loopbackio#652

Signed-off-by: Rifa Achrinza <25147899+achrinza@users.noreply.github.com>
ci: fix typo

Signed-off-by: Rifa Achrinza <25147899+achrinza@users.noreply.github.com>
chore: update deps

Signed-off-by: Rifa Achrinza <25147899+achrinza@users.noreply.github.com>
feat: add tls options as of mongo 3.7

Signed-off-by: d-bo <vathsven@pm.me>
ci: update Node.js version

see: loopbackio/cicd#2
see: loopbackio/cicd#4

Signed-off-by: Rifa Achrinza <25147899+achrinza@users.noreply.github.com>
ci: pin NPM version

see: loopbackio/cicd#6

Signed-off-by: Rifa Achrinza <25147899+achrinza@users.noreply.github.com>
chore: add @achrinza and update CODEOWNERS

Signed-off-by: Diana Lau <dhmlau@ca.ibm.com>
fix: isObjectIDProperty array param check

fixes loopbackio#645

Signed-off-by: Rifa Achrinza <25147899+achrinza@users.noreply.github.com>
fix: handle url default db name

Co-authored-by: Nico Flaig <nflaig@protonmail.com>
Signed-off-by: Rifa Achrinza <25147899+achrinza@users.noreply.github.com>
ci: restrict GITHUB_TOKEN permissions

Signed-off-by: Rifa Achrinza <25147899+achrinza@users.noreply.github.com>
6.1.0

 * ci: misc updates (Rifa Achrinza)
 * feat: add transaction support (Sergey Nosenko)
 * ci: align gh actions workflow with 5.x (Rifa Achrinza)
 * chore: move repo to loopbackio org (Diana Lau)
ci: misc updates

- Enable Node.js v16 testing
- Update supercharge/mongodb-github-action to v1.6.0
- Enable amd64/8 testing
- Re-enable coverage reporting
- General CI sync with other pipelines.

Signed-off-by: Rifa Achrinza <25147899+achrinza@users.noreply.github.com>
feat: add transaction support

Signed-off by: Sergey Nosenko <darknos@gmail.com>
Signed-off-by: Rifa Achrinza <25147899+achrinza@users.noreply.github.com>
ci: align gh actions workflow with 5.x

see loopbackio#634

Signed-off-by: Rifa Achrinza <25147899+achrinza@users.noreply.github.com>
chore: move repo to loopbackio org

Signed-off-by: Diana Lau <dhmlau@ca.ibm.com>
6.0.1

 * fix: allows fields filter with custom field name (louis.nguyen)
 * README: update notes about 6.0 (Miroslav Bajtoš)
fix: allows fields filter with custom field name

Signed-off-by: louis.nguyen <louis.nguyen@jetstudio.io>
README: update notes about 6.0

Remove the message "6.0 is in development", update LTS table with the
correct date of publishing v6.0.0

Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
6.0.0

 * coerce values of array defined as ObjectID type (=)
 * Update mongodb to ^3.6.4 (wolrajhti)
 * ci: convert from Travis to Github action ci (Agnes Lin)
 * README: mention our work on 6.0 (Miroslav Bajtoš)
 * [SEMVER-MAJOR] Drop support for LoopBack 3.x (Yaapa Hage)
coerce values of array defined as ObjectID type

Signed-off-by: = <mrbatista@users.noreply.github.com>
Update mongodb to ^3.6.4

Signed-off-by: wolrajhti <pierre.bouteloup@hotmail.fr>
ci: convert from Travis to Github action ci

Signed-off-by: Agnes Lin <agneslin.lin@ibm.com>
[SEMVER-MAJOR] Drop support for LoopBack 3.x

Signed-off-by: Yaapa Hage <hage.yaapa@in.ibm.com>
README: mention our work on 6.0

Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
5.5.0

 * atomic upsertWithWhere (loopbackio#563) (Matteo Padovano)
atomic upsertWithWhere (loopbackio#563)

Signed-off-by: = <mrbatista@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants