kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject kudu git commit: env: unify ReadV and Read code paths
Date Thu, 04 May 2017 18:14:02 GMT
Repository: kudu
Updated Branches:
  refs/heads/master b15ea202d -> a3c5983d8


env: unify ReadV and Read code paths

Reduces similar and duplicate code by directing read calls
to use the ReadV implimentation with a single element vector.

Change-Id: I08538225c7db0eba0e83827b4c2dd5b507491580
Reviewed-on: http://gerrit.cloudera.org:8080/6799
Tested-by: Kudu Jenkins
Reviewed-by: Adar Dembo <adar@cloudera.com>


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/a3c5983d
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/a3c5983d
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/a3c5983d

Branch: refs/heads/master
Commit: a3c5983d8fa71f99e743bf384507baa5161332e4
Parents: b15ea20
Author: Grant Henke <granthenke@gmail.com>
Authored: Thu May 4 12:47:31 2017 -0500
Committer: Adar Dembo <adar@cloudera.com>
Committed: Thu May 4 18:13:39 2017 +0000

----------------------------------------------------------------------
 src/kudu/fs/file_block_manager.cc | 10 ++------
 src/kudu/fs/fs-test-util.h        |  5 ++--
 src/kudu/fs/log_block_manager.cc  | 28 ++--------------------
 src/kudu/util/env_posix.cc        | 43 ++++------------------------------
 4 files changed, 10 insertions(+), 76 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/a3c5983d/src/kudu/fs/file_block_manager.cc
----------------------------------------------------------------------
diff --git a/src/kudu/fs/file_block_manager.cc b/src/kudu/fs/file_block_manager.cc
index 937f4ba..b2419ed 100644
--- a/src/kudu/fs/file_block_manager.cc
+++ b/src/kudu/fs/file_block_manager.cc
@@ -445,14 +445,8 @@ Status FileReadableBlock::Size(uint64_t* sz) const {
 }
 
 Status FileReadableBlock::Read(uint64_t offset, Slice* result) const {
-  DCHECK(!closed_.Load());
-
-  RETURN_NOT_OK(reader_->Read(offset, result));
-  if (block_manager_->metrics_) {
-    block_manager_->metrics_->total_bytes_read->IncrementBy(result->size());
-  }
-
-  return Status::OK();
+  vector<Slice> results = { *result };
+  return ReadV(offset, &results);
 }
 
 Status FileReadableBlock::ReadV(uint64_t offset, vector<Slice>* results) const {

http://git-wip-us.apache.org/repos/asf/kudu/blob/a3c5983d/src/kudu/fs/fs-test-util.h
----------------------------------------------------------------------
diff --git a/src/kudu/fs/fs-test-util.h b/src/kudu/fs/fs-test-util.h
index 23baa44..7f741af 100644
--- a/src/kudu/fs/fs-test-util.h
+++ b/src/kudu/fs/fs-test-util.h
@@ -64,9 +64,8 @@ class CountingReadableBlock : public ReadableBlock {
   }
 
   virtual Status Read(uint64_t offset, Slice* result) const OVERRIDE {
-    RETURN_NOT_OK(block_->Read(offset, result));
-    *bytes_read_ += result->size();
-    return Status::OK();
+    vector<Slice> results = { *result };
+    return ReadV(offset, &results);
   }
 
   virtual Status ReadV(uint64_t offset, std::vector<Slice>* results) const OVERRIDE
{

http://git-wip-us.apache.org/repos/asf/kudu/blob/a3c5983d/src/kudu/fs/log_block_manager.cc
----------------------------------------------------------------------
diff --git a/src/kudu/fs/log_block_manager.cc b/src/kudu/fs/log_block_manager.cc
index 5f8f012..1a3490e 100644
--- a/src/kudu/fs/log_block_manager.cc
+++ b/src/kudu/fs/log_block_manager.cc
@@ -1316,32 +1316,8 @@ Status LogReadableBlock::Size(uint64_t* sz) const {
 }
 
 Status LogReadableBlock::Read(uint64_t offset, Slice* result) const {
-  DCHECK(!closed_.Load());
-
-  uint64_t read_offset = log_block_->offset() + offset;
-  if (log_block_->length() < offset + result->size()) {
-    return Status::IOError("Out-of-bounds read",
-                           Substitute("read of [$0-$1) in block [$2-$3)",
-                                      read_offset,
-                                      read_offset + result->size(),
-                                      log_block_->offset(),
-                                      log_block_->offset() + log_block_->length()));
-  }
-
-  MicrosecondsInt64 start_time = GetMonoTimeMicros();
-  RETURN_NOT_OK(container_->ReadData(read_offset, result));
-  MicrosecondsInt64 end_time = GetMonoTimeMicros();
-
-  int64_t dur = end_time - start_time;
-  TRACE_COUNTER_INCREMENT("lbm_read_time_us", dur);
-
-  const char* counter = BUCKETED_COUNTER_NAME("lbm_reads", dur);
-  TRACE_COUNTER_INCREMENT(counter, 1);
-
-  if (container_->metrics()) {
-    container_->metrics()->generic_metrics.total_bytes_read->IncrementBy(result->size());
-  }
-  return Status::OK();
+  vector<Slice> results = { *result };
+  return ReadV(offset, &results);
 }
 
 Status LogReadableBlock::ReadV(uint64_t offset, vector<Slice>* results) const {

http://git-wip-us.apache.org/repos/asf/kudu/blob/a3c5983d/src/kudu/util/env_posix.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/env_posix.cc b/src/kudu/util/env_posix.cc
index d2d658f..0179a26 100644
--- a/src/kudu/util/env_posix.cc
+++ b/src/kudu/util/env_posix.cc
@@ -276,43 +276,6 @@ Status DoOpen(const string& filename, Env::CreateMode mode, int*
fd) {
   return Status::OK();
 }
 
-Status DoRead(int fd, const string& filename, uint64_t offset, Slice* result) {
-  ThreadRestrictions::AssertIOAllowed();
-  uint64_t cur_offset = offset;
-  uint8_t* dst = result->mutable_data();
-  size_t rem = result->size();
-  while (rem > 0) {
-    size_t req = rem;
-    // Inject a short read for testing
-    if (PREDICT_FALSE(FLAGS_env_inject_short_read_bytes > 0 && req == result->size()))
{
-      DCHECK_LT(FLAGS_env_inject_short_read_bytes, req);
-      req -= FLAGS_env_inject_short_read_bytes;
-    }
-    ssize_t r;
-    RETRY_ON_EINTR(r, pread(fd, dst, req, cur_offset));
-    if (PREDICT_FALSE(r < 0)) {
-      // An error: return a non-ok status.
-      return IOError(filename, errno);
-    }
-    if (PREDICT_FALSE(r == 0)) {
-      // EOF
-      return Status::IOError(Substitute("EOF trying to read $0 bytes at offset $1",
-                                        result->size(), offset));
-    }
-    if (PREDICT_TRUE(r == rem)) {
-      // All requested bytes were read.
-      // This is almost always the case.
-      return Status::OK();
-    }
-    DCHECK_LE(r, rem);
-    dst += r;
-    rem -= r;
-    cur_offset += r;
-  }
-  DCHECK_EQ(0, rem);
-  return Status::OK();
-}
-
 Status DoReadV(int fd, const string& filename, uint64_t offset, vector<Slice>*
results) {
   ThreadRestrictions::AssertIOAllowed();
 
@@ -430,7 +393,8 @@ class PosixRandomAccessFile: public RandomAccessFile {
   virtual ~PosixRandomAccessFile() { close(fd_); }
 
   virtual Status Read(uint64_t offset, Slice* result) const OVERRIDE {
-    return DoRead(fd_, filename_, offset, result);
+    vector<Slice> results = { *result };
+    return ReadV(offset, &results);
   }
 
   virtual Status ReadV(uint64_t offset, vector<Slice>* results) const OVERRIDE {
@@ -676,7 +640,8 @@ class PosixRWFile : public RWFile {
   }
 
   virtual Status Read(uint64_t offset, Slice* result) const OVERRIDE {
-    return DoRead(fd_, filename_, offset, result);
+    vector<Slice> results = { *result };
+    return ReadV(offset, &results);
   }
 
   virtual Status ReadV(uint64_t offset, vector<Slice>* results) const OVERRIDE {


Mime
View raw message