-
Notifications
You must be signed in to change notification settings - Fork 264
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
PHPLIB-1518 WriteResult::get*Count()
always return an int on acknowledged result
#1454
Conversation
WriteResult::get*Count()
always return an int on acknowledged result
ef66a68
to
17c183d
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 we may want to consider unacknowledged writes in rename
.
// If the update resulted in no modification, it's possible that the | ||
// file did not exist, in which case we must raise an error. | ||
if ($updateResult->getMatchedCount() !== 1) { |
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'm not sure we should consider using unacknowledged writes a valid use case, but in case we do there's a functional change here. If we want to preserve the option to use unacknowledged writes with GridFS, we should check isAcknowledged
instead of relying on the null
value from getMatchedCount
:
// If the update resulted in no modification, it's possible that the | |
// file did not exist, in which case we must raise an error. | |
if ($updateResult->getMatchedCount() !== 1) { | |
/* If the update resulted in no modification, it's possible that the | |
* file did not exist, in which case we must raise an error. Checking | |
* the write result's matched count will be most efficient, but fall | |
* back to a findOne operation if necessary (i.e. legacy writes). | |
*/ | |
$found = $updateResult->isAcknowledged() | |
? $updateResult->getMatchedCount() === 1 | |
: $this->collectionWrapper->findFileById($id) !== null; | |
if (! $found) { |
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.
In that case, that's a fix to backport to v1.x, as it already throws an exception when there is an unacknowledged operation.
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.
In that case, let's defer to a separate PR, as this does PR not change existing behaviour.
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.
let's defer to a separate PR
I assume a ticket needs to be created for this. Please cross-reference it here after doing so.
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 just realized that this second if ($updateResult->getMatchedCount() !== 1)
is always true after if ($updateResult->getModifiedCount() === 1) return;
.
Do you know what are the "legacy writes" that are mentioned in the comment?
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.
Legacy opcodes (e.g. OP_UPDATE
), which were removed in MongoDB 6.0. At this point, drivers may still use them for unacknowledged writes but all acknowledged writes are guaranteed to use OP_MSG
and the corresponding write commands (e.g. update).
01a600d
to
4495a6f
Compare
4495a6f
to
49fa315
Compare
I did not update the UPGRADE file, there is nothing to upgrade. |
* v2.x: PHPLIB-1518 `WriteResult::get*Count()` always return an int on acknowledged result (#1454) PHPLIB-954: Add return types to all methods (#1391) PHPLIB-797: Remove unused methods in UnsupportedException (#1436) Revert "Add final annotations to non-internal Operation classes (#1410)" PHPLIB-953 Make internal classes and Operation classes final (#1392) PHPLIB-1218 Remove deprecated fields from GridFS files (#1398)
* v2.x: PHPLIB-1546 and PHPLIB-1159: Remove CreateCollection flags and autoIndexId options (#1478) PHPLIB-1227 Use void return types for operations without meaningful result document (#1468) Remove deprecated functionality (#1439) PHPLIB-1518 `WriteResult::get*Count()` always return an int on acknowledged result (#1454) PHPLIB-954: Add return types to all methods (#1391) PHPLIB-797: Remove unused methods in UnsupportedException (#1436) Revert "Add final annotations to non-internal Operation classes (#1410)" PHPLIB-953 Make internal classes and Operation classes final (#1392) PHPLIB-1218 Remove deprecated fields from GridFS files (#1398)
* v2.x: PHPLIB-1546 and PHPLIB-1159: Remove CreateCollection flags and autoIndexId options (#1478) PHPLIB-1227 Use void return types for operations without meaningful result document (#1468) Remove deprecated functionality (#1439) PHPLIB-1518 `WriteResult::get*Count()` always return an int on acknowledged result (#1454) PHPLIB-954: Add return types to all methods (#1391) PHPLIB-797: Remove unused methods in UnsupportedException (#1436) Revert "Add final annotations to non-internal Operation classes (#1410)" PHPLIB-953 Make internal classes and Operation classes final (#1392) PHPLIB-1218 Remove deprecated fields from GridFS files (#1398)
* v2.x: Regenerate evergreen configuration (#1503) PHPLIB-1546 and PHPLIB-1159: Remove CreateCollection flags and autoIndexId options (#1478) PHPLIB-1227 Use void return types for operations without meaningful result document (#1468) Remove deprecated functionality (#1439) PHPLIB-1518 `WriteResult::get*Count()` always return an int on acknowledged result (#1454) PHPLIB-954: Add return types to all methods (#1391) PHPLIB-797: Remove unused methods in UnsupportedException (#1436) Revert "Add final annotations to non-internal Operation classes (#1410)" PHPLIB-953 Make internal classes and Operation classes final (#1392) PHPLIB-1218 Remove deprecated fields from GridFS files (#1398)
Fix PHPLIB-1518
I chose to rely on the driver exception thrown by mongodb/mongo-php-driver#1687