niyue commented on a change in pull request #11486:
URL: https://github.com/apache/arrow/pull/11486#discussion_r732838271



##########
File path: cpp/src/arrow/ipc/io_recorded_random_access_file.cc
##########
@@ -0,0 +1,63 @@
+#include "io_recorded_random_access_file.h"
+
+namespace arrow {
+namespace ipc {
+Result<int64_t> IoRecordedRandomAccessFile::GetSize() { return file_size_; }
+
+Result<int64_t> IoRecordedRandomAccessFile::ReadAt(int64_t position, int64_t 
nbytes,
+                                                   void* out) {
+  auto num_bytes_read = std::min(file_size_, position + nbytes) - position;
+
+  if (!recorded_io_vec_.empty() &&
+      position == recorded_io_vec_.back().first + 
recorded_io_vec_.back().second) {
+    // merge continuous IOs into one if possible
+    recorded_io_vec_.back().second += num_bytes_read;
+  } else {
+    // no real IO is performed, it is only saved into a vector for replaying 
later
+    recorded_io_vec_.emplace_back(position, num_bytes_read);
+  }

Review comment:
       I introduce a `IoRecordedRandomAccessFile` class which will record the 
read IO operations performed, and it does nothing but saving these read 
operations as <offset, length> pair in a vector, and it is replayed later to do 
the real IO.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to