From 2acffecca1f3027bfc71e38c3cbbe9ae6b17b535 Mon Sep 17 00:00:00 2001 From: Yanqin Jin Date: Wed, 29 Sep 2021 14:25:43 -0700 Subject: [PATCH] Add comments for MultiGetBlob() and checks for MultiRead() (#8972) Summary: Add comments for MultiGetBlob() that input argument `offsets` must be sorted. In addition, add assertion for this condition in debug build. Repeat the same for RandomAccessFileReader::MultiRead(). Pull Request resolved: https://github.com/facebook/rocksdb/pull/8972 Test Plan: make check Reviewed By: pdillinger Differential Revision: D31253205 Pulled By: riversand963 fbshipit-source-id: 98758229b8052f3aeb319d5584026b4de2d220a2 --- db/blob/blob_file_reader.cc | 7 +++++++ db/blob/blob_file_reader.h | 1 + file/random_access_file_reader.cc | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/db/blob/blob_file_reader.cc b/db/blob/blob_file_reader.cc index 9ce0b5b89..0cb49ae62 100644 --- a/db/blob/blob_file_reader.cc +++ b/db/blob/blob_file_reader.cc @@ -358,11 +358,18 @@ void BlobFileReader::MultiGetBlob( const autovector& value_sizes, autovector& statuses, autovector& values, uint64_t* bytes_read) const { const size_t num_blobs = user_keys.size(); + assert(num_blobs > 0); assert(num_blobs == offsets.size()); assert(num_blobs == value_sizes.size()); assert(num_blobs == statuses.size()); assert(num_blobs == values.size()); +#ifndef NDEBUG + for (size_t i = 0; i < offsets.size() - 1; ++i) { + assert(offsets[i] <= offsets[i + 1]); + } +#endif // !NDEBUG + std::vector read_reqs(num_blobs); autovector adjustments; uint64_t total_len = 0; diff --git a/db/blob/blob_file_reader.h b/db/blob/blob_file_reader.h index 06087c3a0..b7da393f3 100644 --- a/db/blob/blob_file_reader.h +++ b/db/blob/blob_file_reader.h @@ -44,6 +44,7 @@ class BlobFileReader { CompressionType compression_type, PinnableSlice* value, uint64_t* bytes_read) const; + // offsets must be sorted in ascending order by caller. void MultiGetBlob( const ReadOptions& read_options, const autovector>& user_keys, diff --git a/file/random_access_file_reader.cc b/file/random_access_file_reader.cc index dd0392609..489167719 100644 --- a/file/random_access_file_reader.cc +++ b/file/random_access_file_reader.cc @@ -224,6 +224,12 @@ IOStatus RandomAccessFileReader::MultiRead(const IOOptions& opts, (void)aligned_buf; // suppress warning of unused variable in LITE mode assert(num_reqs > 0); +#ifndef NDEBUG + for (size_t i = 0; i < num_reqs - 1; ++i) { + assert(read_reqs[i].offset <= read_reqs[i + 1].offset); + } +#endif // !NDEBUG + // To be paranoid modify scratch a little bit, so in case underlying // FileSystem doesn't fill the buffer but return succee and `scratch` returns // contains a previous block, returned value will not pass checksum.