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

Adding atomicSet and atomicSetArray collection strategies #1096

Merged
merged 1 commit into from May 19, 2015

Conversation

malarzm
Copy link
Member

@malarzm malarzm commented May 15, 2015

This is an early implementation of how atomicSet and atomicSetArray could work in my opinion. There are some things that needs to be done

  • maybe add atomic=true flag to mapping instead of new strategy (or change existing $set behaviour)
  • inserts
  • updates
  • upserts
  • removing collection
  • collection within collection with different strategies throw exception if used in embedded documents
  • more tests
  • docs

cc @jwage @jmikola @alcaeus @lavoiesl @blockjon

If this PR will reach its final form it will resolve #1009, #437, #1095 and #1094

@malarzm malarzm added the Idea label May 15, 2015
@malarzm malarzm force-pushed the atomicset branch 3 times, most recently from 58458e8 to b8efc4e Compare May 15, 2015 17:44
@blockjon
Copy link

@malarzm I was thinking that the ODM should always perform all changes to a record in one atomic query. Do you agree, or do you do you feel as though this behavior should be parameterized?

@malarzm
Copy link
Member Author

malarzm commented May 16, 2015

ODM can't do all changes within one query, for instance (citing @jmikola from #1009 (comment))

Collections are currently handled separately out of necessity for the base case where elements are being added and removed from the same array, since MongoDB doesn't allow that in the same write operation.

but of course this in not the case with $set. For now I have made this parametrized as I wanted to have current tests pass and only new ones I'm writing fail but changing this will not be hard if we come to conclusion that we want to change existing behaviour.

@malarzm
Copy link
Member Author

malarzm commented May 16, 2015

I'm afraid we won't be able to change existing set behaviour since I'm not able to make atomic update from within DocumentPersister to collection nested in another collection with pushAll strategy (especially not when embedded object containing that collection is yet to be created). Right now I'm thinking about limiting the feature to be available only in top level document (or deeply embedded but only within collections with atomic* strategy).

I've been also thinking that atomic flag in set and setArray could adapt and make atomic updates when possible and fall back to old behaviour but I think this can be at least confusing. That said I think that introducing new strategies is ok and even wanted given said limitations.

@malarzm malarzm added Feature and removed Idea labels May 16, 2015
@malarzm malarzm changed the title [WIP] Early implementation of atomicSet and atomicSetArray [WIP] atomicSet and atomicSetArray collection strategies May 16, 2015
@malarzm
Copy link
Member Author

malarzm commented May 16, 2015

@blockjon could you run your test against this PR?

@blockjon
Copy link

Having just quickly read through the code, it appears as if this might do the trick. I will try this today and report back my findings.

@blockjon
Copy link

@malarzm Looks like your changes fix my problem as seen here: malarzm#3


.. note::

Only top level document can contain collection with ``atomicSet`` or
Copy link
Member

Choose a reason for hiding this comment

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

I'd rephrase as "The atomicSet and atomicSetArray strategies may only be used for collections mapped directly in a top-level document." And perhaps we want to duplicate this note for the atomicSetArray section below.

@blockjon
Copy link

Friendly question for you all - This branch fixes a critical problem I'm faced with and I would love to use it sooner rather than later.

Since I'm new to this project, I'd like to get a sense of when you feel as though it would be in a state that you feel I should attempt to integrate into my project. Should I want until this gets merged to master, or until you tag a beta 13, for example?

* with collection update in one query we won't need the $unset
*/
$this->uow->unscheduleCollectionDeletion($coll);
} else {
Copy link
Member

Choose a reason for hiding this comment

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

Would it be safer swap out the else for a separate isCollectionScheduledForDeletion() check here? I realize UnitOfWork::scheduleCollectionOwner(), which populates the array returned by getScheduledCollections(), is currently only called from scheduleCollectionDeletion() and scheduleCollectionUpdate(); however, if that changes in the future, we're looking at a very destructive else condition :)

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 elseif was there before but I'll bring it back ;)

Copy link
Member

Choose a reason for hiding this comment

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

@jwage: If we make this an elseif again, how do you feel about a final else condition throwing a LogicException?

@malarzm
Copy link
Member Author

malarzm commented May 19, 2015

@blockjon idea is to have this feature merged and tag BETA-13 then

@malarzm malarzm changed the title [WIP] atomicSet and atomicSetArray collection strategies Adding atomicSet and atomicSetArray collection strategies May 19, 2015
@malarzm malarzm added this to the 1.0.0-BETA13 milestone May 19, 2015
@jmikola
Copy link
Member

jmikola commented May 19, 2015

LGTM pending test results. @jwage: Do you have a chance to take a look at this within the next day?

Ideally, we'd like to get it included in a new 1.0.0-BETA13 tag this week (to help with doctrine/DoctrineMongoDBBundle#298).

@jwage
Copy link
Member

jwage commented May 19, 2015

👍

malarzm added a commit that referenced this pull request May 19, 2015
Adding atomicSet and atomicSetArray collection strategies
@blockjon
Copy link

I AM EXCITED!!!!!!

@smolinari
Copy link

Nice work gentlemen. 👍

Scott

@BernardoSilva
Copy link
Contributor

👍 Nice work.

@malarzm
Copy link
Member Author

malarzm commented May 22, 2015

@blockjon BETA13 is now released :)

@blockjon
Copy link

@malarzm This is fantastic news thank you!!!!

@ghost
Copy link

ghost commented Sep 28, 2015

@malarzm - I think you need to implement atomicSet as default where possible. I just found a bug in production that happened in only 1/100.000 cases and it was driving me nuts for weeks before I found the problem. Using pushAll and multiple queries as default is really something unexpected for me as a developer.

@blockjon
Copy link

@daniphp +1 on your comments there... I had the same feedback here #782 (comment)

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

Successfully merging this pull request may close these issues.

Doctrine take too much time to save/update a document
6 participants