-
-
Notifications
You must be signed in to change notification settings - Fork 504
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
Transaction support #2586
Transaction support #2586
Conversation
18a61c2
to
e728816
Compare
* Add tests for commit consistency showing wrong behaviour * Clear scheduled document changes at the end of a commit operation * Rename private variables to communicate intent * Remove obsolete comment * Use different error code * Use single mongos in consistency tests This ensures that the fail points are created on the same server that the write operations take place on, which can't be guaranteed in a sharded cluster with multiple mongoses. * Rename test methods for clarity * Explain reasoning for index error * Extract helper method to create failpoint
* Add configuration setting for transactional flush * Use classic setters for transactional flush setting
* Extract commit logic * Support transactional commit operations * Always use transactional flush if supported With this commit, all tests using the document manager use transactional flush as long as transactions are supported. Certain tests can use the static $allowsTransactions variable to disable this behaviour. * Test with MongoDB 7.0 * Update test names * Update phpstan baseline * Fix query selection in shard key tests * Flip transaction options constant by default * Use supportsTransaction method when skipping tests * Apply review feedback to tests * Add separate test to check write concern in commit options * Strip write options when in transaction * Use majority write concern in test
e728816
to
601714f
Compare
* Pass session and transaction information to event args * Only dispatch lifecycle events once per commit operation * Remove isInTransaction property in event args * Split method signature for readability * Use property promotion for event args classes * Extract construction of eventArgs * Inline spl_object_hash calls * Avoid injecting test instance * Add session to commitOptions in persister * Add session assertions in LifecycleEventManager
* Only retry transaction once * Rename variable
* Remove references to transactions where not applicable * Update transaction documentation * Apply suggestions from code review Co-authored-by: Jeremy Mikola <jmikola@gmail.com> * Change title level in event documentation * Add documentation about transactions to event docs --------- Co-authored-by: Jeremy Mikola <jmikola@gmail.com>
* Removes any hosts beyond the first in a URI. This function should only be | ||
* used with a sharded cluster URI, but that is not enforced. | ||
*/ | ||
protected static function removeMultipleHosts(string $uri): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is technically also lifted from PHPLIB but I have no qualms about copying it here. 🤫
{ | ||
$manager = new Manager(self::getUri()); | ||
|
||
return $manager->selectServer()->getType() !== Server::TYPE_STANDALONE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remind me if we discussed this before, but transactions require either a 4.0+ RS or 4.2+ sharded cluster. Since ODM only tests as low as 4.4, we don't need to concern ourselves with a version check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We didn't discuss this before, so good point bringing it up. We haven't discussed version support in ODM in a while, but I'd say we can ignore anything < 4.4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already do
mongodb-odm/.github/workflows/continuous-integration.yml
Lines 23 to 26 in c9b7f6b
mongodb-version: | |
- "6.0" | |
- "5.0" | |
- "4.4" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant for the purpose of skipping other topologies. In the library, we check server versions for replica sets and sharded clusters to ensure we only test on supported platforms. This isn't necessary here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I admit I've skimmed through as I tried to do all partial PRs, I did not catch more than @jmikola's eagle eye already did ;)
3323e50
to
ef5e8f0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but note the Psalm failures.
@@ -1268,11 +1273,7 @@ private function executeDeletions(ClassMetadata $class, array $documents, array | |||
$value->clearSnapshot(); | |||
} | |||
|
|||
// Document with this $oid after deletion treated as NEW, even if the $oid | |||
// is obtained by a new document because the old one went out of scope. | |||
$this->documentStates[$oid] = self::STATE_NEW; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was just curious about this but traced the explanation back to https://github.com/doctrine/mongodb-odm/pull/2580/files#r1386613660
Thanks for pointing those out. I didn't have those locally, until I realised that I was running on Psalm 5.17. 5.20 has these errors, but they're unrelated to this code so I've skipped them via the baseline. |
* 2.7.x: Bump ramsey/composer-install from 2 to 3 Bump actions/upload-artifact from 3 to 4 (#2601) Bump actions/cache from 3 to 4 (#2609) Transaction support (#2586) make doctrine/annotations dependency optional Decouple AttributeDriver from AnnotationDriver (#2502) Require doctrine/persistence 3 (#2603) Bump doctrine/.github from 3.1.0 to 4.0.0 Remove BC break issue type
Summary
This pull request introduces support for transactions. When calling
DocumentManager::commit
, a transaction will be used depending on a configuration setting. Alternatively, transaction usage can also be changed using a commit option.Usage
A new
useTransactionalFlush
configuration option can be enabled when running on the following deployments:To enable this feature globally, enable transactional flushes in the configuration:
Alternatively, the
withTransaction
commit option can be specified to override this default value and selectively enable or disable transactions:This pull request has been reviewed in smaller chunks in the following pull requests:
This PR is also accompanied by a pull request in the Symfony Bundle to expose the transactional flush setting in the bundle configuration.