convert RecordIO to pwritev
authorTudor Bosman <tudorb@fb.com>
Thu, 9 May 2013 21:27:56 +0000 (14:27 -0700)
committerSara Golemon <sgolemon@fb.com>
Mon, 20 May 2013 18:01:27 +0000 (11:01 -0700)
Summary: zero-copy

Test Plan: record_io_test

Reviewed By: lucian@fb.com

FB internal diff: D806813

folly/io/RecordIO.cpp

index 5eba9bc70fc5d8c83914090e05125636a88506e3..69bea4deeabb39c186971a693d53f9c7bf5b6109 100644 (file)
@@ -50,17 +50,14 @@ void RecordIOWriter::write(std::unique_ptr<IOBuf> buf) {
     return;  // nothing to do
   }
 
-  // TODO(tudorb): Maybe use pwritev, but for now we're copying everything in
-  // one place.
-  buf->unshare();
-  buf->coalesce();
-  DCHECK_EQ(buf->length(), totalLength);
+  DCHECK_EQ(buf->computeChainDataLength(), totalLength);
+  auto iov = buf->getIov();
 
   // We're going to write.  Reserve space for ourselves.
-  off_t pos = filePos_.fetch_add(buf->length());
-  ssize_t bytes = pwriteFull(file_.fd(), buf->data(), buf->length(), pos);
+  off_t pos = filePos_.fetch_add(totalLength);
+  ssize_t bytes = pwritevFull(file_.fd(), iov.data(), iov.size(), pos);
   checkUnixError(bytes, "pwrite() failed");
-  DCHECK_EQ(bytes, buf->length());
+  DCHECK_EQ(bytes, totalLength);
 }
 
 RecordIOReader::RecordIOReader(File file, uint32_t fileId)