Sanity check the keys parameter in MultiGetEntityFromBatchAndDB (#12564)

Summary:
Pull Request resolved: https://github.com/facebook/rocksdb/pull/12564

Similarly to how `db`, `column_family`, and `results` are handled, bail out early from `WriteBatchWithIndex::MultiGetEntityFromBatchAndDB` if `keys` is `nullptr`. Note that these checks are best effort in the sense that with the current method signature, the callee has no way of reporting an error if `statuses` is `nullptr` or catching other types of invalid pointers (e.g. when `keys` and/or `results` is non-`nullptr` but do not point to a contiguous range of `num_keys` objects). We can improve this (and many similar RocksDB APIs) using `std::span` in a major release once we move to C++20.

Reviewed By: jaykorean

Differential Revision: D56318179

fbshipit-source-id: bc7a258eda82b5f6c839f212ab824130e773a4f0
This commit is contained in:
Levi Tamasi 2024-04-18 14:26:58 -07:00 committed by Facebook GitHub Bot
parent 0df601ab07
commit ef38d99edc
1 changed files with 10 additions and 2 deletions

View File

@ -1005,6 +1005,8 @@ void WriteBatchWithIndex::MultiGetEntityFromBatchAndDB(
DB* db, const ReadOptions& read_options, ColumnFamilyHandle* column_family,
size_t num_keys, const Slice* keys, PinnableWideColumns* results,
Status* statuses, bool sorted_input) {
assert(statuses);
if (!db) {
for (size_t i = 0; i < num_keys; ++i) {
statuses[i] = Status::InvalidArgument(
@ -1029,12 +1031,18 @@ void WriteBatchWithIndex::MultiGetEntityFromBatchAndDB(
return;
}
if (!keys) {
for (size_t i = 0; i < num_keys; ++i) {
statuses[i] = Status::InvalidArgument(
"Cannot call MultiGetEntityFromBatchAndDB without keys");
}
}
if (!results) {
for (size_t i = 0; i < num_keys; ++i) {
statuses[i] = Status::InvalidArgument(
"Cannot call MultiGetEntityFromBatchAndDB without "
"PinnableWideColumns "
"objects");
"PinnableWideColumns objects");
}
}