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

Batch transaction #5849

Merged
merged 30 commits into from
Jul 31, 2019
Merged

Conversation

davimacedo
Copy link
Member

This PR empowers the current Parse Server's /batch/ endpoint with transaction capability for both MongoDB (>4.0) and Postgres. You can find an example of request below:

        request({
          method: 'POST',
          headers: headers,
          url: 'http://localhost:8378/1/batch',
          body: JSON.stringify({
            requests: [
              {
                method: 'POST',
                path: '/1/classes/MyObject',
                body: { key: 'value1' },
              },
              {
                method: 'POST',
                path: '/1/classes/MyObject',
                body: { key: 'value2' },
              },
            ],
            transaction: true,
          }),
        })

Close #2159

@codecov
Copy link

codecov bot commented Jul 26, 2019

Codecov Report

Merging #5849 into master will increase coverage by 0.03%.
The diff coverage is 92.92%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #5849      +/-   ##
=========================================
+ Coverage   93.67%   93.7%   +0.03%     
=========================================
  Files         153     153              
  Lines       10636   10708      +72     
=========================================
+ Hits         9963   10034      +71     
- Misses        673     674       +1
Impacted Files Coverage Δ
src/Adapters/Storage/Mongo/MongoCollection.js 97.43% <100%> (ø) ⬆️
src/Adapters/Storage/Mongo/MongoStorageAdapter.js 92.92% <100%> (+1.07%) ⬆️
src/Controllers/DatabaseController.js 94.81% <81.81%> (-0.27%) ⬇️
src/ParseServerRESTController.js 94.73% <90.47%> (-0.51%) ⬇️
...dapters/Storage/Postgres/PostgresStorageAdapter.js 96.87% <93.54%> (-0.03%) ⬇️
src/batch.js 90.38% <95.23%> (+0.64%) ⬆️
src/RestWrite.js 93.56% <0%> (-0.17%) ⬇️
src/Adapters/WebSocketServer/WSAdapter.js 100% <0%> (ø) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d4fa62a...20cb761. Read the comment docs.

@davimacedo
Copy link
Member Author

@dplewis sorry for flooding you with so many commits in this PR. It is actually working, but MongoDB only supports transactions when running version >4 in a wiredTiger replicaset. I am trying to figure out how to setup this environment in Travis. I will let you know then.

@dplewis
Copy link
Member

dplewis commented Jul 26, 2019

No problem take your time. I know this is a highly requested feature.

@davimacedo davimacedo requested a review from dplewis July 29, 2019 07:31
};
let initialPromise = Promise.resolve();
if (req.body.transaction === true) {
initialPromise = req.config.database.createTransactionalSession();
Copy link
Member

Choose a reason for hiding this comment

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

Good job getting this one in. I can't wait to use it.

Can you add this to direct access?

https://github.com/parse-community/parse-server/blob/master/src/ParseServerRESTController.js

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@davimacedo davimacedo requested a review from dplewis July 31, 2019 04:36
Copy link
Member

@dplewis dplewis left a comment

Choose a reason for hiding this comment

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

LGTM!

@davimacedo davimacedo merged commit 8b97c13 into parse-community:master Jul 31, 2019
UnderratedDev pushed a commit to UnderratedDev/parse-server that referenced this pull request Mar 21, 2020
* Batch transaction boilerplate

* Refactoring transaction boilerplate

* Independent sessions test

* Transactions - partial

* Missing only one test

* All tests passing for mongo db

* Tests on Travis

* Transactions on postgres

* Fix travis to restart mongodb

* Remove mongodb service and keep only mongodb runner

* MongoDB service back

* Initialize replicaset

* Remove mongodb runner again

* Again only with mongodb-runner and removing cache

* Trying with pretest and posttest

* WiredTiger

* Pretest and posttest again

* Removing inexistent scripts

* wiredTiger

* One more attempt

* Trying another way to run mongodb-runner

* Fixing tests

* Include batch transaction on direct access

* Add tests to direct access
@andreasanta
Copy link

Guys this is great work! Any plans to make it accessible from the JS SDK and the remaning SDKs soon? Can I help with that?

@davimacedo
Copy link
Member Author

Yes. There is an open PR (parse-community/Parse-SDK-JS#1090) that we are working on.

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.

Transaction/Commit Support
3 participants