Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

better concurrency handling #58

Merged
merged 1 commit into from
Jun 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Write concern

This adapter uses a transaction timeout of 50 secs by default.

The default write concern for this adapater is acknowledged and journaled (['w' => 1, 'j' => true]).
The default write concern for this adapater is acknowledged (['w' => 1]).

It's possible to change both values by injecting them into the constructor or by using the factory.

Expand Down
8 changes: 6 additions & 2 deletions src/MongoDbEventStoreAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ final class MongoDbEventStoreAdapter implements Adapter, CanHandleTransaction
*/
private $writeConcern = [
'w' => 1,
'j' => true
];

/**
Expand Down Expand Up @@ -174,8 +173,13 @@ public function appendTo(StreamName $streamName, Iterator $streamEvents)

try {
$insertBatch->execute();
} catch (\MongoDuplicateKeyException $e) {
throw new ConcurrencyException('At least one event with same version exists already', 0, $e);
} catch (\MongoWriteConcernException $e) {
throw new ConcurrencyException('', 0, $e);
$code = $e->getDocument()['writeErrors'][0]['code'];
if (in_array($code, [11000, 11001, 12582])) {
throw new ConcurrencyException('At least one event with same version exists already', 0, $e);
}
}
}

Expand Down