Skip to content
This repository has been archived by the owner on Feb 10, 2022. It is now read-only.

How to achieve Concurrency Control? #177

Open
zixinw opened this issue May 22, 2017 · 8 comments
Open

How to achieve Concurrency Control? #177

zixinw opened this issue May 22, 2017 · 8 comments
Labels

Comments

@zixinw
Copy link

zixinw commented May 22, 2017

I am facing a high concurrency problem, and I found https://docs.mongodb.com/v3.0/core/write-operations-atomicity/. Is there anything like that ?

@vadimdemedes
Copy link
Owner

So you would like to use $isolated? You can extend Mongorito to pass $isolated on every update operation. Check Writing Plugins section in readme.

@zixinw
Copy link
Author

zixinw commented May 23, 2017

Actually, I want is:

    let test = new Test()
    yield test.save()

    let test1 = yield Test.findById(test.get('_id'))
    let test2 = yield Test.findById(test.get('_id'))

    //make some modifications to test1 and  test2

    yield test1.save()
    yield test2.save() //should  throw Exception, because the document has been modified, some fields may have been changed, Storing test2 will overwrite those fileds.

See this: https://docs.mongodb.com/v3.0/tutorial/update-if-current/

My mongorito version is 2.2.0

@vadimdemedes
Copy link
Owner

How would you implement this kind of behavior?

@zixinw
Copy link
Author

zixinw commented May 23, 2017

It's a example I means, but the callbacks actually work like that. Perhaps I can maintain a field version, and increase it each time when the native mongodb update is called. But it seems impossible to achieve in Mongorito, here is the source code.
image

The update query condition has only _id, adding version here I think it would work.

@niallobrien
Copy link

Interesting problem. Any solution for this yet?

@vadimdemedes
Copy link
Owner

I still don't understand the problem completely. @wangzixin1113 Initially you wanted to use $isolated and in the last screenshot and link you point to atomic operations like $inc and $set. Could you provide more information? Maybe examples of the problem/solution in other libraries, like mongoose?

@zaaack
Copy link
Contributor

zaaack commented Jun 9, 2017

I think this is a expansibility problem since upgrading to v3, just like the problem I'm facing. We cannot easily override any built-in behavior because internal action and middleware cannot be override. If I want to change update, I cann't override it with a custom action, because other plugins might depend on it.

@vadimdemedes
Copy link
Owner

We cannot easily override any built-in behavior because internal action and middleware cannot be override.

@zaaack You can override any internal actions in this way:

const ActionTypes = require('mongorito');

const myMiddleware = () => ({dispatch, getState}) => next => action => {
  if (action.type !== UPDATE) {
    // pass through any other action
    return next(action);
  }

  // action.type is UPDATE, start customization of the action props
  return next(action);
};

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants