You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by aw...@apache.org on 2018/08/29 01:51:21 UTC

[1/3] kudu git commit: KUDU-2469 pt 1: add an IOContext

Repository: kudu
Updated Branches:
  refs/heads/master 846eb7f97 -> 2974f5a50


http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/tablet_bootstrap.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet_bootstrap.cc b/src/kudu/tablet/tablet_bootstrap.cc
index 670d6ee..e70372a 100644
--- a/src/kudu/tablet/tablet_bootstrap.cc
+++ b/src/kudu/tablet/tablet_bootstrap.cc
@@ -53,6 +53,7 @@
 #include "kudu/fs/data_dirs.h"
 #include "kudu/fs/fs.pb.h"
 #include "kudu/fs/fs_manager.h"
+#include "kudu/fs/io_context.h"
 #include "kudu/gutil/bind.h"
 #include "kudu/gutil/gscoped_ptr.h"
 #include "kudu/gutil/macros.h"
@@ -115,6 +116,7 @@ using kudu::consensus::OperationType_Name;
 using kudu::consensus::RaftConfigPB;
 using kudu::consensus::ReplicateMsg;
 using kudu::consensus::WRITE_OP;
+using kudu::fs::IOContext;
 using kudu::log::Log;
 using kudu::log::LogAnchorRegistry;
 using kudu::log::LogEntryPB;
@@ -254,28 +256,29 @@ class TabletBootstrap {
   // Plays the log segments into the tablet being built.
   // The process of playing the segments generates a new log that can be continued
   // later on when then tablet is rebuilt and starts accepting writes from clients.
-  Status PlaySegments(ConsensusBootstrapInfo* results);
+  Status PlaySegments(const IOContext* io_context, ConsensusBootstrapInfo* consensus_info);
 
   // Append the given commit message to the log.
   // Does not support writing a TxResult.
   Status AppendCommitMsg(const CommitMsg& commit_msg);
 
-  Status PlayWriteRequest(ReplicateMsg* replicate_msg,
+  Status PlayWriteRequest(const IOContext* io_context, ReplicateMsg* replicate_msg,
                           const CommitMsg& commit_msg);
 
-  Status PlayAlterSchemaRequest(ReplicateMsg* replicate_msg,
+  Status PlayAlterSchemaRequest(const IOContext* io_context, ReplicateMsg* replicate_msg,
                                 const CommitMsg& commit_msg);
 
-  Status PlayChangeConfigRequest(ReplicateMsg* replicate_msg,
+  Status PlayChangeConfigRequest(const IOContext* io_context, ReplicateMsg* replicate_msg,
                                  const CommitMsg& commit_msg);
 
-  Status PlayNoOpRequest(ReplicateMsg* replicate_msg,
+  Status PlayNoOpRequest(const IOContext* io_context, ReplicateMsg* replicate_msg,
                          const CommitMsg& commit_msg);
 
   // Plays operations, skipping those that have already been flushed or have previously failed.
   // See ApplyRowOperations() for more details on how the decision of whether an operation
   // is applied or skipped is made.
-  Status PlayRowOperations(WriteTransactionState* tx_state,
+  Status PlayRowOperations(const IOContext* io_context,
+                           WriteTransactionState* tx_state,
                            const TxResultPB& orig_result,
                            TxResultPB* new_result);
 
@@ -294,7 +297,8 @@ class TabletBootstrap {
   // - if it was previously failed, mark as failed
   // - if it previously succeeded but was flushed, skip it.
   // - otherwise, re-apply to the tablet being bootstrapped.
-  Status ApplyOperations(WriteTransactionState* tx_state,
+  Status ApplyOperations(const IOContext* io_context,
+                         WriteTransactionState* tx_state,
                          const TxResultPB& orig_result,
                          TxResultPB* new_result);
 
@@ -336,7 +340,8 @@ class TabletBootstrap {
 
   void DumpReplayStateToLog(const ReplayState& state);
 
-  Status HandleEntry(ReplayState* state,
+  Status HandleEntry(const IOContext* io_context,
+                     ReplayState* state,
                      unique_ptr<LogEntryPB> entry,
                      string* entry_debug_info);
 
@@ -344,12 +349,13 @@ class TabletBootstrap {
   Status HandleReplicateMessage(ReplayState* state,
                                 unique_ptr<LogEntryPB> entry,
                                 string* entry_debug_info);
-  Status HandleCommitMessage(ReplayState* state,
+  Status HandleCommitMessage(const IOContext* io_context, ReplayState* state,
                              unique_ptr<LogEntryPB> entry,
                              string* entry_debug_info);
 
-  Status ApplyCommitMessage(ReplayState* state, LogEntryPB* entry);
-  Status HandleEntryPair(LogEntryPB* replicate_entry, LogEntryPB* commit_entry);
+  Status ApplyCommitMessage(const IOContext* io_context, ReplayState* state, LogEntryPB* entry);
+  Status HandleEntryPair(const IOContext* io_context, LogEntryPB* replicate_entry,
+                         LogEntryPB* commit_entry);
 
   // Checks that an orphaned commit message is actually irrelevant, i.e that none
   // of the data stores it refers to are live.
@@ -601,7 +607,8 @@ Status TabletBootstrap::RunBootstrap(shared_ptr<Tablet>* rebuilt_tablet,
                                            tablet_id));
   }
 
-  RETURN_NOT_OK_PREPEND(PlaySegments(consensus_info), "Failed log replay. Reason");
+  IOContext io_context({ tablet_meta_->table_id() });
+  RETURN_NOT_OK_PREPEND(PlaySegments(&io_context, consensus_info), "Failed log replay. Reason");
 
   RETURN_NOT_OK(Log::RemoveRecoveryDirIfExists(tablet_->metadata()->fs_manager(),
                                                tablet_->metadata()->tablet_id()))
@@ -823,7 +830,8 @@ struct ReplayState {
 };
 
 // Handle the given log entry.
-Status TabletBootstrap::HandleEntry(ReplayState* state,
+Status TabletBootstrap::HandleEntry(const IOContext* io_context,
+                                    ReplayState* state,
                                     unique_ptr<LogEntryPB> entry,
                                     string* entry_debug_info) {
   DCHECK(entry);
@@ -838,7 +846,8 @@ Status TabletBootstrap::HandleEntry(ReplayState* state,
       break;
     case log::COMMIT:
       // check the unpaired ops for the matching replicate msg, abort if not found
-      RETURN_NOT_OK(HandleCommitMessage(state, std::move(entry), entry_debug_info));
+      RETURN_NOT_OK(HandleCommitMessage(io_context, state,
+                                        std::move(entry), entry_debug_info));
       break;
     default:
       return Status::Corruption(Substitute("unexpected log entry type: $0", entry_type));
@@ -917,7 +926,7 @@ Status TabletBootstrap::HandleReplicateMessage(ReplayState* state,
 }
 
 // On returning OK, takes ownership of the pointer from the 'entry_ptr' wrapper.
-Status TabletBootstrap::HandleCommitMessage(ReplayState* state,
+Status TabletBootstrap::HandleCommitMessage(const IOContext* io_context, ReplayState* state,
                                             unique_ptr<LogEntryPB> entry,
                                             string* entry_debug_info) {
   auto info_collector = MakeScopedCleanup([&]() {
@@ -961,14 +970,14 @@ Status TabletBootstrap::HandleCommitMessage(ReplayState* state,
 
   // ... if it does, we apply it and all the commits that immediately follow in the sequence.
   OpId last_applied = committed_op_id;
-  RETURN_NOT_OK(ApplyCommitMessage(state, entry.get()));
+  RETURN_NOT_OK(ApplyCommitMessage(io_context, state, entry.get()));
 
   auto iter = state->pending_commits.begin();
   while (iter != state->pending_commits.end()) {
     if (iter->first == last_applied.index() + 1) {
       auto& buffered_commit_entry(iter->second);
       last_applied = buffered_commit_entry->commit().commited_op_id();
-      RETURN_NOT_OK(ApplyCommitMessage(state, buffered_commit_entry.get()));
+      RETURN_NOT_OK(ApplyCommitMessage(io_context, state, buffered_commit_entry.get()));
       iter = state->pending_commits.erase(iter);
       continue;
     }
@@ -1012,7 +1021,8 @@ Status TabletBootstrap::CheckOrphanedCommitDoesntNeedReplay(const CommitMsg& com
   return Status::OK();
 }
 
-Status TabletBootstrap::ApplyCommitMessage(ReplayState* state, LogEntryPB* entry) {
+Status TabletBootstrap::ApplyCommitMessage(const IOContext* io_context,
+                                           ReplayState* state, LogEntryPB* entry) {
   const OpId& committed_op_id = entry->commit().commited_op_id();
   VLOG_WITH_PREFIX(2) << "Applying commit for " << committed_op_id;
 
@@ -1034,7 +1044,7 @@ Status TabletBootstrap::ApplyCommitMessage(ReplayState* state, LogEntryPB* entry
       LOG_WITH_PREFIX(DFATAL) << error_msg;
       return Status::Corruption(error_msg);
     }
-    RETURN_NOT_OK(HandleEntryPair(pending_replicate_entry.get(), entry));
+    RETURN_NOT_OK(HandleEntryPair(io_context, pending_replicate_entry.get(), entry));
     stats_.ops_committed++;
   } else {
     stats_.orphaned_commits++;
@@ -1045,11 +1055,12 @@ Status TabletBootstrap::ApplyCommitMessage(ReplayState* state, LogEntryPB* entry
 }
 
 // Never deletes 'replicate_entry' or 'commit_entry'.
-Status TabletBootstrap::HandleEntryPair(LogEntryPB* replicate_entry, LogEntryPB* commit_entry) {
+Status TabletBootstrap::HandleEntryPair(const IOContext* io_context, LogEntryPB* replicate_entry,
+                                        LogEntryPB* commit_entry) {
   const char* error_fmt = "Failed to play $0 request. ReplicateMsg: { $1 }, CommitMsg: { $2 }";
 
-#define RETURN_NOT_OK_REPLAY(ReplayMethodName, replicate, commit)       \
-  RETURN_NOT_OK_PREPEND(ReplayMethodName(replicate, commit),            \
+#define RETURN_NOT_OK_REPLAY(ReplayMethodName, io_context, replicate, commit)       \
+  RETURN_NOT_OK_PREPEND(ReplayMethodName(io_context, replicate, commit),            \
                         Substitute(error_fmt, OperationType_Name(op_type), \
                                    SecureShortDebugString(*(replicate)), \
                                    SecureShortDebugString(commit)))
@@ -1060,19 +1071,19 @@ Status TabletBootstrap::HandleEntryPair(LogEntryPB* replicate_entry, LogEntryPB*
 
   switch (op_type) {
     case WRITE_OP:
-      RETURN_NOT_OK_REPLAY(PlayWriteRequest, replicate, commit);
+      RETURN_NOT_OK_REPLAY(PlayWriteRequest, io_context, replicate, commit);
       break;
 
     case ALTER_SCHEMA_OP:
-      RETURN_NOT_OK_REPLAY(PlayAlterSchemaRequest, replicate, commit);
+      RETURN_NOT_OK_REPLAY(PlayAlterSchemaRequest, io_context, replicate, commit);
       break;
 
     case CHANGE_CONFIG_OP:
-      RETURN_NOT_OK_REPLAY(PlayChangeConfigRequest, replicate, commit);
+      RETURN_NOT_OK_REPLAY(PlayChangeConfigRequest, io_context, replicate, commit);
       break;
 
     case NO_OP:
-      RETURN_NOT_OK_REPLAY(PlayNoOpRequest, replicate, commit);
+      RETURN_NOT_OK_REPLAY(PlayNoOpRequest, io_context, replicate, commit);
       break;
 
     default:
@@ -1124,7 +1135,8 @@ void TabletBootstrap::DumpReplayStateToLog(const ReplayState& state) {
   }
 }
 
-Status TabletBootstrap::PlaySegments(ConsensusBootstrapInfo* consensus_info) {
+Status TabletBootstrap::PlaySegments(const IOContext* io_context,
+                                     ConsensusBootstrapInfo* consensus_info) {
   ReplayState state;
   log::SegmentSequence segments;
   RETURN_NOT_OK(log_reader_->GetSegmentsSnapshot(&segments));
@@ -1176,7 +1188,7 @@ Status TabletBootstrap::PlaySegments(ConsensusBootstrapInfo* consensus_info) {
         entry_count++;
 
         string entry_debug_info;
-        s = HandleEntry(&state, std::move(entry), &entry_debug_info);
+        s = HandleEntry(io_context, &state, std::move(entry), &entry_debug_info);
         if (!s.ok()) {
           DumpReplayStateToLog(state);
           RETURN_NOT_OK_PREPEND(s, DebugInfo(tablet_->tablet_id(),
@@ -1324,7 +1336,8 @@ Status TabletBootstrap::DetermineSkippedOpsAndBuildResponse(const TxResultPB& or
   return Status::OK();
 }
 
-Status TabletBootstrap::PlayWriteRequest(ReplicateMsg* replicate_msg,
+Status TabletBootstrap::PlayWriteRequest(const IOContext* io_context,
+                                         ReplicateMsg* replicate_msg,
                                          const CommitMsg& commit_msg) {
   // Prepare the commit entry for the rewritten log.
   LogEntryPB commit_entry;
@@ -1394,7 +1407,7 @@ Status TabletBootstrap::PlayWriteRequest(ReplicateMsg* replicate_msg,
     // failure if we attempted to 'Abort()' after entering the applying stage. Allowing it to
     // Commit isn't problematic because we don't expose the results anyway, and the bad
     // Status returned below will cause us to fail the entire tablet bootstrap anyway.
-    play_status = PlayRowOperations(&tx_state, commit_msg.result(), new_result);
+    play_status = PlayRowOperations(io_context, &tx_state, commit_msg.result(), new_result);
 
     if (play_status.ok()) {
       // Replace the original commit message's result with the new one from the replayed operation.
@@ -1413,7 +1426,8 @@ Status TabletBootstrap::PlayWriteRequest(ReplicateMsg* replicate_msg,
   return Status::OK();
 }
 
-Status TabletBootstrap::PlayAlterSchemaRequest(ReplicateMsg* replicate_msg,
+Status TabletBootstrap::PlayAlterSchemaRequest(const IOContext* /*io_context*/,
+                                               ReplicateMsg* replicate_msg,
                                                const CommitMsg& commit_msg) {
   AlterSchemaRequestPB* alter_schema = replicate_msg->mutable_alter_schema_request();
 
@@ -1439,7 +1453,8 @@ Status TabletBootstrap::PlayAlterSchemaRequest(ReplicateMsg* replicate_msg,
   return AppendCommitMsg(commit_msg);
 }
 
-Status TabletBootstrap::PlayChangeConfigRequest(ReplicateMsg* replicate_msg,
+Status TabletBootstrap::PlayChangeConfigRequest(const IOContext* /*io_context*/,
+                                                ReplicateMsg* replicate_msg,
                                                 const CommitMsg& commit_msg) {
   // Invariant: The committed config change request is always locally persisted
   // in the consensus metadata before the commit message is written to the WAL.
@@ -1458,11 +1473,14 @@ Status TabletBootstrap::PlayChangeConfigRequest(ReplicateMsg* replicate_msg,
   return AppendCommitMsg(commit_msg);
 }
 
-Status TabletBootstrap::PlayNoOpRequest(ReplicateMsg* replicate_msg, const CommitMsg& commit_msg) {
+Status TabletBootstrap::PlayNoOpRequest(const IOContext* /*io_context*/,
+                                        ReplicateMsg* /*replicate_msg*/,
+                                        const CommitMsg& commit_msg) {
   return AppendCommitMsg(commit_msg);
 }
 
-Status TabletBootstrap::PlayRowOperations(WriteTransactionState* tx_state,
+Status TabletBootstrap::PlayRowOperations(const IOContext* io_context,
+                                          WriteTransactionState* tx_state,
                                           const TxResultPB& orig_result,
                                           TxResultPB* new_result) {
   Schema inserts_schema;
@@ -1477,17 +1495,19 @@ Status TabletBootstrap::PlayRowOperations(WriteTransactionState* tx_state,
   RETURN_NOT_OK_PREPEND(tablet_->AcquireRowLocks(tx_state),
                         "Failed to acquire row locks");
 
-  RETURN_NOT_OK(ApplyOperations(tx_state, orig_result, new_result));
+  RETURN_NOT_OK(ApplyOperations(io_context, tx_state, orig_result, new_result));
 
   return Status::OK();
 }
 
-Status TabletBootstrap::ApplyOperations(WriteTransactionState* tx_state,
+Status TabletBootstrap::ApplyOperations(const IOContext* io_context,
+                                        WriteTransactionState* tx_state,
                                         const TxResultPB& orig_result,
                                         TxResultPB* new_result) {
   DCHECK_EQ(tx_state->row_ops().size(), orig_result.ops_size());
   DCHECK_EQ(tx_state->row_ops().size(), new_result->ops_size());
   int32_t op_idx = 0;
+
   for (RowOp* op : tx_state->row_ops()) {
     int32_t curr_op_idx = op_idx++;
     // Increment the seen/ignored stats.
@@ -1530,7 +1550,7 @@ Status TabletBootstrap::ApplyOperations(WriteTransactionState* tx_state,
 
     // Actually apply it.
     ProbeStats stats; // we don't use this, but tablet internals require non-NULL.
-    RETURN_NOT_OK(tablet_->ApplyRowOperation(tx_state, op, &stats));
+    RETURN_NOT_OK(tablet_->ApplyRowOperation(io_context, tx_state, op, &stats));
     DCHECK(op->result != nullptr);
 
     // We expect that the above Apply() will always succeed, because we're

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/tablet_history_gc-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet_history_gc-test.cc b/src/kudu/tablet/tablet_history_gc-test.cc
index d5361cd..37397aa 100644
--- a/src/kudu/tablet/tablet_history_gc-test.cc
+++ b/src/kudu/tablet/tablet_history_gc-test.cc
@@ -233,7 +233,7 @@ TEST_F(TabletHistoryGcTest, TestMajorDeltaCompactionOnSubsetOfColumns) {
   for (int i = 0; i < num_rowsets_; i++) {
     DiskRowSet* drs = down_cast<DiskRowSet*>(rowsets[i].get());
     vector<ColumnId> col_ids_to_compact = { schema_.column_id(2) };
-    ASSERT_OK(drs->MajorCompactDeltaStoresWithColumnIds(col_ids_to_compact,
+    ASSERT_OK(drs->MajorCompactDeltaStoresWithColumnIds(col_ids_to_compact, nullptr,
                                                         tablet()->GetHistoryGcOpts()));
   }
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tools/tool_action_fs.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/tool_action_fs.cc b/src/kudu/tools/tool_action_fs.cc
index 57adf22..f23ef81 100644
--- a/src/kudu/tools/tool_action_fs.cc
+++ b/src/kudu/tools/tool_action_fs.cc
@@ -270,7 +270,7 @@ Status DumpCFile(const RunnerContext& context) {
 
   if (FLAGS_print_rows) {
     gscoped_ptr<CFileIterator> it;
-    RETURN_NOT_OK(reader->NewIterator(&it, CFileReader::DONT_CACHE_BLOCK));
+    RETURN_NOT_OK(reader->NewIterator(&it, CFileReader::DONT_CACHE_BLOCK, nullptr));
     RETURN_NOT_OK(it->SeekToFirst());
 
     RETURN_NOT_OK(DumpIterator(*reader, it.get(), &cout, 0, 0));

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tools/tool_action_local_replica.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/tool_action_local_replica.cc b/src/kudu/tools/tool_action_local_replica.cc
index 085c259..21edb5e 100644
--- a/src/kudu/tools/tool_action_local_replica.cc
+++ b/src/kudu/tools/tool_action_local_replica.cc
@@ -632,6 +632,7 @@ Status DumpRowSetInternal(const shared_ptr<RowSetMetadata>& rs_meta,
   RETURN_NOT_OK(DiskRowSet::Open(rs_meta,
                                  log_reg.get(),
                                  tablet::TabletMemTrackers(),
+                                 nullptr,
                                  &rs));
   vector<string> lines;
   RETURN_NOT_OK(rs->DebugDump(&lines));


[2/3] kudu git commit: KUDU-2469 pt 1: add an IOContext

Posted by aw...@apache.org.
http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/deltamemstore.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/deltamemstore.h b/src/kudu/tablet/deltamemstore.h
index b637e00..253a2c9 100644
--- a/src/kudu/tablet/deltamemstore.h
+++ b/src/kudu/tablet/deltamemstore.h
@@ -57,6 +57,10 @@ namespace consensus {
 class OpId;
 }
 
+namespace fs {
+struct IOContext;
+}
+
 namespace tablet {
 
 class DeltaFileWriter;
@@ -78,7 +82,7 @@ class DeltaMemStore : public DeltaStore,
                        std::shared_ptr<MemTracker> parent_tracker,
                        std::shared_ptr<DeltaMemStore>* dms);
 
-  virtual Status Init() OVERRIDE;
+  virtual Status Init(const fs::IOContext* io_context) OVERRIDE;
 
   virtual bool Initted() OVERRIDE {
     return true;
@@ -122,7 +126,8 @@ class DeltaMemStore : public DeltaStore,
   virtual Status NewDeltaIterator(const RowIteratorOptions& opts,
                                   DeltaIterator** iterator) const OVERRIDE;
 
-  virtual Status CheckRowDeleted(rowid_t row_idx, bool *deleted) const OVERRIDE;
+  virtual Status CheckRowDeleted(rowid_t row_idx, const fs::IOContext* io_context,
+                                 bool* deleted) const OVERRIDE;
 
   virtual uint64_t EstimateSize() const OVERRIDE {
     return arena_->memory_footprint();

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/diskrowset-test-base.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/diskrowset-test-base.h b/src/kudu/tablet/diskrowset-test-base.h
index 9742169..ec3f4b3 100644
--- a/src/kudu/tablet/diskrowset-test-base.h
+++ b/src/kudu/tablet/diskrowset-test-base.h
@@ -186,7 +186,7 @@ class TestRowSet : public KuduRowSetTest {
     ProbeStats stats;
     ScopedTransaction tx(&mvcc_, clock_->Now());
     tx.StartApplying();
-    Status s = rs->MutateRow(tx.timestamp(), probe, mutation, op_id_, &stats, result);
+    Status s = rs->MutateRow(tx.timestamp(), probe, mutation, op_id_, nullptr, &stats, result);
     tx.Commit();
     return s;
   }
@@ -196,7 +196,7 @@ class TestRowSet : public KuduRowSetTest {
     BuildRowKey(&rb, row_idx);
     RowSetKeyProbe probe(rb.row());
     ProbeStats stats;
-    return rs.CheckRowPresent(probe, present, &stats);
+    return rs.CheckRowPresent(probe, nullptr, present, &stats);
   }
 
   // Verify the contents of the given rowset.
@@ -327,6 +327,7 @@ class TestRowSet : public KuduRowSetTest {
     return DiskRowSet::Open(rowset_meta_,
                             new log::LogAnchorRegistry(),
                             TabletMemTrackers(),
+                            nullptr,
                             rowset);
   }
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/diskrowset-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/diskrowset-test.cc b/src/kudu/tablet/diskrowset-test.cc
index ce0fb7d..7e89122 100644
--- a/src/kudu/tablet/diskrowset-test.cc
+++ b/src/kudu/tablet/diskrowset-test.cc
@@ -121,7 +121,7 @@ TEST_F(TestRowSet, TestRowSetRoundTrip) {
     rb.AddString(Slice("h"));
     RowSetKeyProbe probe(rb.row());
     bool present;
-    ASSERT_OK(rs->CheckRowPresent(probe, &present, &stats));
+    ASSERT_OK(rs->CheckRowPresent(probe, nullptr, &present, &stats));
     ASSERT_FALSE(present);
   }
 
@@ -131,7 +131,7 @@ TEST_F(TestRowSet, TestRowSetRoundTrip) {
     rb.AddString(Slice("z"));
     RowSetKeyProbe probe(rb.row());
     bool present;
-    ASSERT_OK(rs->CheckRowPresent(probe, &present, &stats));
+    ASSERT_OK(rs->CheckRowPresent(probe, nullptr, &present, &stats));
     ASSERT_FALSE(present);
   }
 
@@ -142,7 +142,7 @@ TEST_F(TestRowSet, TestRowSetRoundTrip) {
     rb.AddString(Slice("hello 00000000000049x"));
     RowSetKeyProbe probe(rb.row());
     bool present;
-    ASSERT_OK(rs->CheckRowPresent(probe, &present, &stats));
+    ASSERT_OK(rs->CheckRowPresent(probe, nullptr, &present, &stats));
     ASSERT_FALSE(present);
   }
 
@@ -154,7 +154,7 @@ TEST_F(TestRowSet, TestRowSetRoundTrip) {
     rb.AddString(Slice(buf));
     RowSetKeyProbe probe(rb.row());
     bool present;
-    ASSERT_OK(rs->CheckRowPresent(probe, &present, &stats));
+    ASSERT_OK(rs->CheckRowPresent(probe, nullptr, &present, &stats));
     ASSERT_TRUE(present);
   }
 }
@@ -188,7 +188,7 @@ TEST_F(TestRowSet, TestRowSetUpdate) {
 
   OperationResultPB result;
   ProbeStats stats;
-  Status s = rs->MutateRow(timestamp, probe, enc.as_changelist(), op_id_, &stats, &result);
+  Status s = rs->MutateRow(timestamp, probe, enc.as_changelist(), op_id_, nullptr, &stats, &result);
   ASSERT_TRUE(s.IsNotFound());
   ASSERT_EQ(0, result.mutated_stores_size());
 
@@ -219,7 +219,7 @@ TEST_F(TestRowSet, TestErrorDuringUpdate) {
   // The mutation should result in an IOError.
   OperationResultPB result;
   ProbeStats stats;
-  Status s = rs->MutateRow(timestamp, probe, enc.as_changelist(), op_id_, &stats, &result);
+  Status s = rs->MutateRow(timestamp, probe, enc.as_changelist(), op_id_, nullptr, &stats, &result);
   LOG(INFO) << s.ToString();
   ASSERT_TRUE(s.IsIOError());
 }
@@ -307,7 +307,7 @@ TEST_F(TestRowSet, TestDelete) {
       // Flush DMS. The second pass through the loop will re-verify that the
       // externally visible state of the layer has not changed.
       // deletions now in a DeltaFile.
-      ASSERT_OK(rs->FlushDeltas());
+      ASSERT_OK(rs->FlushDeltas(nullptr));
     }
   }
 }
@@ -330,7 +330,7 @@ TEST_F(TestRowSet, TestDMSFlush) {
     ASSERT_EQ(static_cast<int>(n_rows_ * FLAGS_update_fraction),
               rs->delta_tracker_->dms_->Count());
 
-    ASSERT_OK(rs->FlushDeltas());
+    ASSERT_OK(rs->FlushDeltas(nullptr));
 
     // Check that the DiskRowSet's DMS has now been emptied.
     ASSERT_EQ(0, rs->delta_tracker_->dms_->Count());
@@ -403,6 +403,7 @@ TEST_F(TestRowSet, TestFlushedUpdatesRespectMVCC) {
                                           probe,
                                           RowChangeList(update_buf),
                                           op_id_,
+                                          nullptr,
                                           &stats,
                                           &result));
       ASSERT_EQ(1, result.mutated_stores_size());
@@ -429,7 +430,7 @@ TEST_F(TestRowSet, TestFlushedUpdatesRespectMVCC) {
 
   // Flush deltas to disk and ensure that the historical versions are still
   // accessible.
-  ASSERT_OK(rs->FlushDeltas());
+  ASSERT_OK(rs->FlushDeltas(nullptr));
 
   for (int i = 0; i < 5; i++) {
     SCOPED_TRACE(i);
@@ -469,7 +470,7 @@ TEST_F(TestRowSet, TestDeltaApplicationPerformance) {
       StringPrintf("Reading %zd rows with %.2f%% updates %d times (updates in DMS)",
                    n_rows_, FLAGS_update_fraction * 100.0f,
                    FLAGS_n_read_passes));
-    ASSERT_OK(rs->FlushDeltas());
+    ASSERT_OK(rs->FlushDeltas(nullptr));
 
     BenchmarkIterationPerformance(*rs.get(),
       StringPrintf("Reading %zd rows with %.2f%% updates %d times (updates on disk)",
@@ -505,15 +506,15 @@ TEST_F(TestRowSet, TestMakeDeltaIteratorMergerUnlocked) {
   shared_ptr<DiskRowSet> rs;
   ASSERT_OK(OpenTestRowSet(&rs));
   UpdateExistingRows(rs.get(), FLAGS_update_fraction, nullptr);
-  ASSERT_OK(rs->FlushDeltas());
+  ASSERT_OK(rs->FlushDeltas(nullptr));
   DeltaTracker *dt = rs->delta_tracker();
   int num_stores = dt->redo_delta_stores_.size();
   vector<shared_ptr<DeltaStore> > compacted_stores;
   vector<BlockId> compacted_blocks;
   unique_ptr<DeltaIterator> merge_iter;
-  ASSERT_OK(dt->MakeDeltaIteratorMergerUnlocked(0, num_stores - 1, &schema_,
-                                                       &compacted_stores,
-                                                       &compacted_blocks, &merge_iter));
+  ASSERT_OK(dt->MakeDeltaIteratorMergerUnlocked(nullptr, 0, num_stores - 1, &schema_,
+                                                &compacted_stores,
+                                                &compacted_blocks, &merge_iter));
   vector<string> results;
   ASSERT_OK(DebugDumpDeltaIterator(REDO, merge_iter.get(), schema_,
                                           ITERATE_OVER_ALL_ROWS,
@@ -550,7 +551,7 @@ TEST_F(TestRowSet, TestCompactStores) {
 
   // Write a first delta file.
   UpdateExistingRows(rs.get(), FLAGS_update_fraction, nullptr);
-  ASSERT_OK(rs->FlushDeltas());
+  ASSERT_OK(rs->FlushDeltas(nullptr));
   // One file isn't enough for minor compactions, but a major compaction can run.
   ASSERT_EQ(0, rs->DeltaStoresCompactionPerfImprovementScore(RowSet::MINOR_DELTA_COMPACTION));
   NO_FATALS(BetweenZeroAndOne(rs->DeltaStoresCompactionPerfImprovementScore(
@@ -558,7 +559,7 @@ TEST_F(TestRowSet, TestCompactStores) {
 
   // Write a second delta file.
   UpdateExistingRows(rs.get(), FLAGS_update_fraction, nullptr);
-  ASSERT_OK(rs->FlushDeltas());
+  ASSERT_OK(rs->FlushDeltas(nullptr));
   // Two files is enough for all delta compactions.
   NO_FATALS(BetweenZeroAndOne(rs->DeltaStoresCompactionPerfImprovementScore(
       RowSet::MINOR_DELTA_COMPACTION)));
@@ -567,7 +568,7 @@ TEST_F(TestRowSet, TestCompactStores) {
 
   // Write a third delta file.
   UpdateExistingRows(rs.get(), FLAGS_update_fraction, nullptr);
-  ASSERT_OK(rs->FlushDeltas());
+  ASSERT_OK(rs->FlushDeltas(nullptr));
   // We're hitting the max for minor compactions but not for major compactions.
   ASSERT_EQ(1, rs->DeltaStoresCompactionPerfImprovementScore(RowSet::MINOR_DELTA_COMPACTION));
   NO_FATALS(BetweenZeroAndOne(rs->DeltaStoresCompactionPerfImprovementScore(
@@ -578,7 +579,7 @@ TEST_F(TestRowSet, TestCompactStores) {
   int num_stores = dt->redo_delta_stores_.size();
   VLOG(1) << "Number of stores before compaction: " << num_stores;
   ASSERT_EQ(num_stores, 3);
-  ASSERT_OK(dt->CompactStores(0, num_stores - 1));
+  ASSERT_OK(dt->CompactStores(nullptr, 0, num_stores - 1));
   num_stores = dt->redo_delta_stores_.size();
   VLOG(1) << "Number of stores after compaction: " << num_stores;
   ASSERT_EQ(1,  num_stores);
@@ -591,7 +592,7 @@ TEST_F(TestRowSet, TestCompactStores) {
   vector<shared_ptr<DeltaStore> > compacted_stores;
   vector<BlockId> compacted_blocks;
   unique_ptr<DeltaIterator> merge_iter;
-  ASSERT_OK(dt->MakeDeltaIteratorMergerUnlocked(0, num_stores - 1, &schema_,
+  ASSERT_OK(dt->MakeDeltaIteratorMergerUnlocked(nullptr, 0, num_stores - 1, &schema_,
                                                 &compacted_stores,
                                                 &compacted_blocks, &merge_iter));
   vector<string> results;
@@ -619,19 +620,19 @@ TEST_F(TestRowSet, TestGCAncientStores) {
 
   // Write and flush a new REDO delta file.
   UpdateExistingRows(rs.get(), FLAGS_update_fraction, nullptr);
-  ASSERT_OK(rs->FlushDeltas());
+  ASSERT_OK(rs->FlushDeltas(nullptr));
   ASSERT_EQ(0, dt->CountUndoDeltaStores());
   ASSERT_EQ(1, dt->CountRedoDeltaStores());
 
   // Convert the REDO delta to an UNDO delta.
-  ASSERT_OK(rs->MajorCompactDeltaStores(HistoryGcOpts::Disabled()));
+  ASSERT_OK(rs->MajorCompactDeltaStores(nullptr, HistoryGcOpts::Disabled()));
   ASSERT_EQ(1, dt->CountUndoDeltaStores()); // From doing the major delta compaction.
   ASSERT_EQ(0, dt->CountRedoDeltaStores());
 
   // Delete all the UNDO deltas. There shouldn't be any delta stores left.
   int64_t blocks_deleted;
   int64_t bytes_deleted;
-  ASSERT_OK(dt->DeleteAncientUndoDeltas(clock_->Now(), &blocks_deleted, &bytes_deleted));
+  ASSERT_OK(dt->DeleteAncientUndoDeltas(clock_->Now(), nullptr, &blocks_deleted, &bytes_deleted));
   ASSERT_GT(blocks_deleted, 0);
   ASSERT_GT(bytes_deleted, 0);
   ASSERT_EQ(0, dt->CountUndoDeltaStores());
@@ -649,7 +650,7 @@ TEST_F(TestRowSet, TestDiskSizeEstimation) {
 
   // Write a first delta file.
   UpdateExistingRows(rs.get(), FLAGS_update_fraction, nullptr);
-  ASSERT_OK(rs->FlushDeltas());
+  ASSERT_OK(rs->FlushDeltas(nullptr));
 
   // The rowset consists of the cfile set and REDO deltas, so the rowset's
   // on-disk size and the sum of the cfile set and REDO sizes should equal.
@@ -659,7 +660,7 @@ TEST_F(TestRowSet, TestDiskSizeEstimation) {
   ASSERT_EQ(rs->OnDiskSize(), drss.CFileSetOnDiskSize() + drss.redo_deltas_size);
 
   // Convert the REDO delta to an UNDO delta.
-  ASSERT_OK(rs->MajorCompactDeltaStores(HistoryGcOpts::Disabled()));
+  ASSERT_OK(rs->MajorCompactDeltaStores(nullptr, HistoryGcOpts::Disabled()));
 
   // REDO size should be zero, but there should be UNDOs, so the on-disk size
   // of the rowset should be the sum of the cfile set and UNDO sizes.
@@ -669,7 +670,7 @@ TEST_F(TestRowSet, TestDiskSizeEstimation) {
 
   // Write a second delta file.
   UpdateExistingRows(rs.get(), FLAGS_update_fraction, nullptr);
-  ASSERT_OK(rs->FlushDeltas());
+  ASSERT_OK(rs->FlushDeltas(nullptr));
 
   // Now there's base data, REDOs, and UNDOs.
   rs->GetDiskRowSetSpaceUsage(&drss);

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/diskrowset.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/diskrowset.cc b/src/kudu/tablet/diskrowset.cc
index 6517fdb..25c366b 100644
--- a/src/kudu/tablet/diskrowset.cc
+++ b/src/kudu/tablet/diskrowset.cc
@@ -94,6 +94,7 @@ using cfile::BloomFileWriter;
 using fs::BlockManager;
 using fs::BlockCreationTransaction;
 using fs::CreateBlockOptions;
+using fs::IOContext;
 using fs::WritableBlock;
 using log::LogAnchorRegistry;
 using std::shared_ptr;
@@ -508,12 +509,13 @@ RollingDiskRowSetWriter::~RollingDiskRowSetWriter() {
 Status DiskRowSet::Open(const shared_ptr<RowSetMetadata>& rowset_metadata,
                         log::LogAnchorRegistry* log_anchor_registry,
                         const TabletMemTrackers& mem_trackers,
+                        const IOContext* io_context,
                         shared_ptr<DiskRowSet> *rowset) {
   shared_ptr<DiskRowSet> rs(new DiskRowSet(rowset_metadata,
                                            log_anchor_registry,
                                            mem_trackers));
 
-  RETURN_NOT_OK(rs->Open());
+  RETURN_NOT_OK(rs->Open(io_context));
 
   rowset->swap(rs);
   return Status::OK();
@@ -529,15 +531,17 @@ DiskRowSet::DiskRowSet(shared_ptr<RowSetMetadata> rowset_metadata,
       num_rows_(-1),
       has_been_compacted_(false) {}
 
-Status DiskRowSet::Open() {
+Status DiskRowSet::Open(const IOContext* io_context) {
   TRACE_EVENT0("tablet", "DiskRowSet::Open");
   RETURN_NOT_OK(CFileSet::Open(rowset_metadata_,
                                mem_trackers_.tablet_tracker,
+                               io_context,
                                &base_data_));
 
   RETURN_NOT_OK(DeltaTracker::Open(rowset_metadata_,
                                    log_anchor_registry_,
                                    mem_trackers_,
+                                   io_context,
                                    &delta_tracker_));
 
   open_ = true;
@@ -545,17 +549,18 @@ Status DiskRowSet::Open() {
   return Status::OK();
 }
 
-Status DiskRowSet::FlushDeltas() {
+Status DiskRowSet::FlushDeltas(const IOContext* io_context) {
   TRACE_EVENT0("tablet", "DiskRowSet::FlushDeltas");
-  return delta_tracker_->Flush(DeltaTracker::FLUSH_METADATA);
+  return delta_tracker_->Flush(io_context, DeltaTracker::FLUSH_METADATA);
 }
 
-Status DiskRowSet::MinorCompactDeltaStores() {
+Status DiskRowSet::MinorCompactDeltaStores(const IOContext* io_context) {
   TRACE_EVENT0("tablet", "DiskRowSet::MinorCompactDeltaStores");
-  return delta_tracker_->Compact();
+  return delta_tracker_->Compact(io_context);
 }
 
-Status DiskRowSet::MajorCompactDeltaStores(HistoryGcOpts history_gc_opts) {
+Status DiskRowSet::MajorCompactDeltaStores(const IOContext* io_context,
+                                           HistoryGcOpts history_gc_opts) {
   vector<ColumnId> col_ids;
   delta_tracker_->GetColumnIdsWithUpdates(&col_ids);
 
@@ -564,10 +569,11 @@ Status DiskRowSet::MajorCompactDeltaStores(HistoryGcOpts history_gc_opts) {
     return Status::OK();
   }
 
-  return MajorCompactDeltaStoresWithColumnIds(col_ids, std::move(history_gc_opts));
+  return MajorCompactDeltaStoresWithColumnIds(col_ids, io_context, std::move(history_gc_opts));
 }
 
 Status DiskRowSet::MajorCompactDeltaStoresWithColumnIds(const vector<ColumnId>& col_ids,
+                                                        const IOContext* io_context,
                                                         HistoryGcOpts history_gc_opts) {
   LOG_WITH_PREFIX(INFO) << "Major compacting REDO delta stores (cols: " << col_ids << ")";
   TRACE_EVENT0("tablet", "DiskRowSet::MajorCompactDeltaStoresWithColumnIds");
@@ -576,9 +582,10 @@ Status DiskRowSet::MajorCompactDeltaStoresWithColumnIds(const vector<ColumnId>&
 
   // TODO(todd): do we need to lock schema or anything here?
   gscoped_ptr<MajorDeltaCompaction> compaction;
-  RETURN_NOT_OK(NewMajorDeltaCompaction(col_ids, std::move(history_gc_opts), &compaction));
+  RETURN_NOT_OK(NewMajorDeltaCompaction(col_ids, std::move(history_gc_opts),
+                                        io_context, &compaction));
 
-  RETURN_NOT_OK(compaction->Compact());
+  RETURN_NOT_OK(compaction->Compact(io_context));
 
   // Before updating anything, create a copy of the rowset metadata so we can
   // revert changes in case of error.
@@ -599,12 +606,13 @@ Status DiskRowSet::MajorCompactDeltaStoresWithColumnIds(const vector<ColumnId>&
   // appropriate blocks to match the update.
   shared_ptr<CFileSet> new_base;
   RETURN_NOT_OK(CFileSet::Open(rowset_metadata_,
-                          mem_trackers_.tablet_tracker,
-                          &new_base));
+                               mem_trackers_.tablet_tracker,
+                               io_context,
+                               &new_base));
   {
     // Update the delta tracker and the base data with the changes.
     std::lock_guard<rw_spinlock> lock(component_lock_);
-    RETURN_NOT_OK(compaction->UpdateDeltaTracker(delta_tracker_.get()));
+    RETURN_NOT_OK(compaction->UpdateDeltaTracker(delta_tracker_.get(), io_context));
     base_data_.swap(new_base);
   }
 
@@ -621,6 +629,7 @@ Status DiskRowSet::MajorCompactDeltaStoresWithColumnIds(const vector<ColumnId>&
 
 Status DiskRowSet::NewMajorDeltaCompaction(const vector<ColumnId>& col_ids,
                                            HistoryGcOpts history_gc_opts,
+                                           const IOContext* io_context,
                                            gscoped_ptr<MajorDeltaCompaction>* out) const {
   DCHECK(open_);
   shared_lock<rw_spinlock> l(component_lock_);
@@ -629,6 +638,7 @@ Status DiskRowSet::NewMajorDeltaCompaction(const vector<ColumnId>& col_ids,
 
   RowIteratorOptions opts;
   opts.projection = schema;
+  opts.io_context = io_context;
   vector<shared_ptr<DeltaStore>> included_stores;
   unique_ptr<DeltaIterator> delta_iter;
   RETURN_NOT_OK(delta_tracker_->NewDeltaFileIterator(
@@ -650,7 +660,8 @@ Status DiskRowSet::NewRowIterator(const RowIteratorOptions& opts,
   DCHECK(open_);
   shared_lock<rw_spinlock> l(component_lock_);
 
-  shared_ptr<CFileSet::Iterator> base_iter(base_data_->NewIterator(opts.projection));
+  shared_ptr<CFileSet::Iterator> base_iter(base_data_->NewIterator(opts.projection,
+                                                                   opts.io_context));
   gscoped_ptr<ColumnwiseIterator> col_iter;
   RETURN_NOT_OK(delta_tracker_->WrapIterator(base_iter, opts, &col_iter));
 
@@ -661,25 +672,27 @@ Status DiskRowSet::NewRowIterator(const RowIteratorOptions& opts,
 
 Status DiskRowSet::NewCompactionInput(const Schema* projection,
                                       const MvccSnapshot &snap,
-                                      gscoped_ptr<CompactionInput>* out) const  {
-  return CompactionInput::Create(*this, projection, snap, out);
+                                      const IOContext* io_context,
+                                      gscoped_ptr<CompactionInput>* out) const {
+  return CompactionInput::Create(*this, projection, snap, io_context, out);
 }
 
 Status DiskRowSet::MutateRow(Timestamp timestamp,
                              const RowSetKeyProbe &probe,
                              const RowChangeList &update,
                              const consensus::OpId& op_id,
+                             const IOContext* io_context,
                              ProbeStats* stats,
                              OperationResultPB* result) {
   DCHECK(open_);
 #ifndef NDEBUG
   rowid_t num_rows;
-  RETURN_NOT_OK(CountRows(&num_rows));
+  RETURN_NOT_OK(CountRows(io_context, &num_rows));
 #endif
   shared_lock<rw_spinlock> l(component_lock_);
 
   boost::optional<rowid_t> row_idx;
-  RETURN_NOT_OK(base_data_->FindRow(probe, &row_idx, stats));
+  RETURN_NOT_OK(base_data_->FindRow(probe, io_context, &row_idx, stats));
   if (PREDICT_FALSE(row_idx == boost::none)) {
     return Status::NotFound("row not found");
   }
@@ -690,7 +703,7 @@ Status DiskRowSet::MutateRow(Timestamp timestamp,
   // It's possible that the row key exists in this DiskRowSet, but it has
   // in fact been Deleted already. Check with the delta tracker to be sure.
   bool deleted;
-  RETURN_NOT_OK(delta_tracker_->CheckRowDeleted(*row_idx, &deleted, stats));
+  RETURN_NOT_OK(delta_tracker_->CheckRowDeleted(*row_idx, io_context, &deleted, stats));
   if (deleted) {
     return Status::NotFound("row not found");
   }
@@ -701,17 +714,18 @@ Status DiskRowSet::MutateRow(Timestamp timestamp,
 }
 
 Status DiskRowSet::CheckRowPresent(const RowSetKeyProbe &probe,
+                                   const IOContext* io_context,
                                    bool* present,
                                    ProbeStats* stats) const {
   DCHECK(open_);
 #ifndef NDEBUG
   rowid_t num_rows;
-  RETURN_NOT_OK(CountRows(&num_rows));
+  RETURN_NOT_OK(CountRows(io_context, &num_rows));
 #endif
   shared_lock<rw_spinlock> l(component_lock_);
 
   rowid_t row_idx;
-  RETURN_NOT_OK(base_data_->CheckRowPresent(probe, present, &row_idx, stats));
+  RETURN_NOT_OK(base_data_->CheckRowPresent(probe, io_context, present, &row_idx, stats));
   if (!*present) {
     // If it wasn't in the base data, then it's definitely not in the rowset.
     return Status::OK();
@@ -722,19 +736,19 @@ Status DiskRowSet::CheckRowPresent(const RowSetKeyProbe &probe,
 
   // Otherwise it might be in the base data but deleted.
   bool deleted = false;
-  RETURN_NOT_OK(delta_tracker_->CheckRowDeleted(row_idx, &deleted, stats));
+  RETURN_NOT_OK(delta_tracker_->CheckRowDeleted(row_idx, io_context, &deleted, stats));
   *present = !deleted;
   return Status::OK();
 }
 
-Status DiskRowSet::CountRows(rowid_t *count) const {
+Status DiskRowSet::CountRows(const IOContext* io_context, rowid_t *count) const {
   DCHECK(open_);
   rowid_t num_rows = num_rows_.load();
   if (PREDICT_TRUE(num_rows != -1)) {
     *count = num_rows;
   } else {
     shared_lock<rw_spinlock> l(component_lock_);
-    RETURN_NOT_OK(base_data_->CountRows(count));
+    RETURN_NOT_OK(base_data_->CountRows(io_context, count));
     num_rows_.store(*count);
   }
   return Status::OK();
@@ -845,17 +859,19 @@ Status DiskRowSet::EstimateBytesInPotentiallyAncientUndoDeltas(Timestamp ancient
 
 Status DiskRowSet::InitUndoDeltas(Timestamp ancient_history_mark,
                                   MonoTime deadline,
+                                  const IOContext* io_context,
                                   int64_t* delta_blocks_initialized,
                                   int64_t* bytes_in_ancient_undos) {
   TRACE_EVENT0("tablet", "DiskRowSet::InitUndoDeltas");
-  return delta_tracker_->InitUndoDeltas(ancient_history_mark, deadline,
+  return delta_tracker_->InitUndoDeltas(ancient_history_mark, deadline, io_context,
                                         delta_blocks_initialized, bytes_in_ancient_undos);
 }
 
 Status DiskRowSet::DeleteAncientUndoDeltas(Timestamp ancient_history_mark,
+                                           const IOContext* io_context,
                                            int64_t* blocks_deleted, int64_t* bytes_deleted) {
   TRACE_EVENT0("tablet", "DiskRowSet::DeleteAncientUndoDeltas");
-  return delta_tracker_->DeleteAncientUndoDeltas(ancient_history_mark,
+  return delta_tracker_->DeleteAncientUndoDeltas(ancient_history_mark, io_context,
                                                  blocks_deleted, bytes_deleted);
 }
 
@@ -865,7 +881,7 @@ Status DiskRowSet::DebugDump(vector<string> *lines) {
   gscoped_ptr<CompactionInput> input;
   RETURN_NOT_OK(NewCompactionInput(&rowset_metadata_->tablet_schema(),
                                    MvccSnapshot::CreateSnapshotIncludingAllTransactions(),
-                                   &input));
+                                   nullptr, &input));
   return DebugDumpCompactionInput(input.get(), lines);
 }
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/diskrowset.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/diskrowset.h b/src/kudu/tablet/diskrowset.h
index 67e587c..de2e7f6 100644
--- a/src/kudu/tablet/diskrowset.h
+++ b/src/kudu/tablet/diskrowset.h
@@ -68,6 +68,7 @@ class OpId;
 
 namespace fs {
 class BlockCreationTransaction;
+struct IOContext;
 }
 
 namespace log {
@@ -312,6 +313,7 @@ class DiskRowSet : public RowSet {
   static Status Open(const std::shared_ptr<RowSetMetadata>& rowset_metadata,
                      log::LogAnchorRegistry* log_anchor_registry,
                      const TabletMemTrackers& mem_trackers,
+                     const fs::IOContext* io_context,
                      std::shared_ptr<DiskRowSet> *rowset);
 
   ////////////////////////////////////////////////////////////
@@ -319,12 +321,12 @@ class DiskRowSet : public RowSet {
   ////////////////////////////////////////////////////////////
 
   // Flush all accumulated delta data to disk.
-  Status FlushDeltas() override;
+  Status FlushDeltas(const fs::IOContext* io_context) override;
 
   // Perform delta store minor compaction.
   // This compacts the delta files down to a single one.
   // If there is already only a single delta file, this does nothing.
-  Status MinorCompactDeltaStores() override;
+  Status MinorCompactDeltaStores(const fs::IOContext* io_context) override;
 
   ////////////////////////////////////////////////////////////
   // RowSet implementation
@@ -341,12 +343,12 @@ class DiskRowSet : public RowSet {
                    const RowSetKeyProbe &probe,
                    const RowChangeList &update,
                    const consensus::OpId& op_id,
+                   const fs::IOContext* io_context,
                    ProbeStats* stats,
                    OperationResultPB* result) override;
 
-  Status CheckRowPresent(const RowSetKeyProbe &probe,
-                         bool *present,
-                         ProbeStats* stats) const override;
+  Status CheckRowPresent(const RowSetKeyProbe &probe, const fs::IOContext* io_context,
+                         bool *present, ProbeStats* stats) const override;
 
   ////////////////////
   // Read functions.
@@ -356,11 +358,12 @@ class DiskRowSet : public RowSet {
 
   virtual Status NewCompactionInput(const Schema* projection,
                                     const MvccSnapshot &snap,
+                                    const fs::IOContext* io_context,
                                     gscoped_ptr<CompactionInput>* out) const override;
 
   // Gets the number of rows in this rowset, checking 'num_rows_' first. If not
   // yet set, consults the base data and stores the result in 'num_rows_'.
-  Status CountRows(rowid_t *count) const final override;
+  Status CountRows(const fs::IOContext* io_context, rowid_t *count) const final override;
 
   // See RowSet::GetBounds(...)
   virtual Status GetBounds(std::string* min_encoded_key,
@@ -389,14 +392,15 @@ class DiskRowSet : public RowSet {
 
   Status InitUndoDeltas(Timestamp ancient_history_mark,
                         MonoTime deadline,
+                        const fs::IOContext* io_context,
                         int64_t* delta_blocks_initialized,
                         int64_t* bytes_in_ancient_undos) override;
 
-  Status DeleteAncientUndoDeltas(Timestamp ancient_history_mark,
+  Status DeleteAncientUndoDeltas(Timestamp ancient_history_mark, const fs::IOContext* io_context,
                                  int64_t* blocks_deleted, int64_t* bytes_deleted) override;
 
   // Major compacts all the delta files for all the columns.
-  Status MajorCompactDeltaStores(HistoryGcOpts history_gc_opts);
+  Status MajorCompactDeltaStores(const fs::IOContext* io_context, HistoryGcOpts history_gc_opts);
 
   std::mutex *compact_flush_lock() override {
     return &compact_flush_lock_;
@@ -444,15 +448,17 @@ class DiskRowSet : public RowSet {
              log::LogAnchorRegistry* log_anchor_registry,
              TabletMemTrackers mem_trackers);
 
-  Status Open();
+  Status Open(const fs::IOContext* io_context);
 
   // Create a new major delta compaction object to compact the specified columns.
   Status NewMajorDeltaCompaction(const std::vector<ColumnId>& col_ids,
                                  HistoryGcOpts history_gc_opts,
+                                 const fs::IOContext* io_context,
                                  gscoped_ptr<MajorDeltaCompaction>* out) const;
 
   // Major compacts all the delta files for the specified columns.
   Status MajorCompactDeltaStoresWithColumnIds(const std::vector<ColumnId>& col_ids,
+                                              const fs::IOContext* io_context,
                                               HistoryGcOpts history_gc_opts);
 
   std::shared_ptr<RowSetMetadata> rowset_metadata_;

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/memrowset-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/memrowset-test.cc b/src/kudu/tablet/memrowset-test.cc
index ba5134e..1823f14 100644
--- a/src/kudu/tablet/memrowset-test.cc
+++ b/src/kudu/tablet/memrowset-test.cc
@@ -122,7 +122,7 @@ class TestMemRowSet : public KuduTest {
     RowSetKeyProbe probe(rb.row());
     ProbeStats stats;
 
-    return mrs.CheckRowPresent(probe, present, &stats);
+    return mrs.CheckRowPresent(probe, nullptr, present, &stats);
   }
 
   Status InsertRows(MemRowSet *mrs, int num_rows) {
@@ -169,6 +169,7 @@ class TestMemRowSet : public KuduTest {
                               probe,
                               RowChangeList(mutation_buf_),
                               op_id_,
+                              nullptr,
                               &stats,
                               result);
     tx.Commit();
@@ -191,6 +192,7 @@ class TestMemRowSet : public KuduTest {
                               probe,
                               RowChangeList(mutation_buf_),
                               op_id_,
+                              nullptr,
                               &stats,
                               result);
     tx.Commit();

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/memrowset.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/memrowset.cc b/src/kudu/tablet/memrowset.cc
index 0b68782..da107af 100644
--- a/src/kudu/tablet/memrowset.cc
+++ b/src/kudu/tablet/memrowset.cc
@@ -60,6 +60,7 @@ using std::vector;
 namespace kudu { namespace tablet {
 
 using consensus::OpId;
+using fs::IOContext;
 using log::LogAnchorRegistry;
 using strings::Substitute;
 
@@ -221,6 +222,7 @@ Status MemRowSet::MutateRow(Timestamp timestamp,
                             const RowSetKeyProbe &probe,
                             const RowChangeList &delta,
                             const consensus::OpId& op_id,
+                            const IOContext* /*io_context*/,
                             ProbeStats* stats,
                             OperationResultPB *result) {
   {
@@ -259,8 +261,8 @@ Status MemRowSet::MutateRow(Timestamp timestamp,
   return Status::OK();
 }
 
-Status MemRowSet::CheckRowPresent(const RowSetKeyProbe &probe, bool *present,
-                                  ProbeStats* stats) const {
+Status MemRowSet::CheckRowPresent(const RowSetKeyProbe &probe, const IOContext* /*io_context*/,
+                                  bool* present, ProbeStats* stats) const {
   // Use a PreparedMutation here even though we don't plan to mutate. Even though
   // this takes a lock rather than an optimistic copy, it should be a very short
   // critical section, and this call is only made on updates, which are rare.
@@ -307,6 +309,7 @@ Status MemRowSet::NewRowIterator(const RowIteratorOptions& opts,
 
 Status MemRowSet::NewCompactionInput(const Schema* projection,
                                      const MvccSnapshot& snap,
+                                     const IOContext* /*io_context*/,
                                      gscoped_ptr<CompactionInput>* out) const  {
   out->reset(CompactionInput::Create(*this, projection, snap));
   return Status::OK();

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/memrowset.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/memrowset.h b/src/kudu/tablet/memrowset.h
index 429f734..8b2998a 100644
--- a/src/kudu/tablet/memrowset.h
+++ b/src/kudu/tablet/memrowset.h
@@ -56,13 +56,17 @@ class RowChangeList;
 class ScanSpec;
 struct IteratorStats;
 
+namespace fs {
+struct IOContext;
+}  // namespace fs
+
 namespace tablet {
 class MvccSnapshot;
-} // namespace tablet
+}  // namespace tablet
 
 namespace consensus {
 class OpId;
-} // namespace consensus
+}  // namespace consensus
 
 namespace tablet {
 //
@@ -238,6 +242,7 @@ class MemRowSet : public RowSet,
                            const RowSetKeyProbe &probe,
                            const RowChangeList &delta,
                            const consensus::OpId& op_id,
+                           const fs::IOContext* io_context,
                            ProbeStats* stats,
                            OperationResultPB *result) override;
 
@@ -249,7 +254,7 @@ class MemRowSet : public RowSet,
   }
 
   // Conform entry_count to RowSet
-  Status CountRows(rowid_t *count) const override {
+  Status CountRows(const fs::IOContext* /*io_context*/, rowid_t *count) const override {
     *count = entry_count();
     return Status::OK();
   }
@@ -292,8 +297,8 @@ class MemRowSet : public RowSet,
   }
 
   // TODO(todd): unit test me
-  Status CheckRowPresent(const RowSetKeyProbe &probe, bool *present,
-                         ProbeStats* stats) const override;
+  Status CheckRowPresent(const RowSetKeyProbe &probe, const fs::IOContext* io_context,
+                         bool *present, ProbeStats* stats) const override;
 
   // Return the memory footprint of this memrowset.
   // Note that this may be larger than the sum of the data
@@ -320,6 +325,7 @@ class MemRowSet : public RowSet,
   // Create compaction input.
   virtual Status NewCompactionInput(const Schema* projection,
                                     const MvccSnapshot& snap,
+                                    const fs::IOContext* io_context,
                                     gscoped_ptr<CompactionInput>* out) const override;
 
   // Return the Schema for the rows in this memrowset.
@@ -385,6 +391,7 @@ class MemRowSet : public RowSet,
 
   Status InitUndoDeltas(Timestamp /*ancient_history_mark*/,
                         MonoTime /*deadline*/,
+                        const fs::IOContext* /*io_context*/,
                         int64_t* delta_blocks_initialized,
                         int64_t* bytes_in_ancient_undos) override {
     if (delta_blocks_initialized) *delta_blocks_initialized = 0;
@@ -393,15 +400,17 @@ class MemRowSet : public RowSet,
   }
 
   Status DeleteAncientUndoDeltas(Timestamp /*ancient_history_mark*/,
+                                 const fs::IOContext* /*io_context*/,
                                  int64_t* blocks_deleted, int64_t* bytes_deleted) override {
     if (blocks_deleted) *blocks_deleted = 0;
     if (bytes_deleted) *bytes_deleted = 0;
     return Status::OK();
   }
 
-  Status FlushDeltas() override { return Status::OK(); }
+  Status FlushDeltas(const fs::IOContext* /*io_context*/) override { return Status::OK(); }
 
-  Status MinorCompactDeltaStores() override { return Status::OK(); }
+  Status MinorCompactDeltaStores(
+      const fs::IOContext* /*io_context*/) override { return Status::OK(); }
 
  private:
   friend class Iterator;

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/mock-rowsets.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/mock-rowsets.h b/src/kudu/tablet/mock-rowsets.h
index b83fbc5..4a65dfb 100644
--- a/src/kudu/tablet/mock-rowsets.h
+++ b/src/kudu/tablet/mock-rowsets.h
@@ -28,22 +28,29 @@
 #include "kudu/tablet/rowset_metadata.h"
 
 namespace kudu {
+
+namespace fs {
+struct IOContext;
+}  // namespace fs
+
 namespace tablet {
 
 // Mock implementation of RowSet which just aborts on every call.
 class MockRowSet : public RowSet {
  public:
-  virtual Status CheckRowPresent(const RowSetKeyProbe &probe, bool *present,
-                                 ProbeStats* stats) const OVERRIDE {
+  virtual Status CheckRowPresent(const RowSetKeyProbe& /*probe*/,
+                                 const fs::IOContext* /*io_context*/,
+                                 bool* /*present*/, ProbeStats* /*stats*/) const OVERRIDE {
     LOG(FATAL) << "Unimplemented";
     return Status::OK();
   }
-  virtual Status MutateRow(Timestamp timestamp,
-                           const RowSetKeyProbe &probe,
-                           const RowChangeList &update,
-                           const consensus::OpId& op_id_,
-                           ProbeStats* stats,
-                           OperationResultPB *result) OVERRIDE {
+  virtual Status MutateRow(Timestamp /*timestamp*/,
+                           const RowSetKeyProbe& /*probe*/,
+                           const RowChangeList& /*update*/,
+                           const consensus::OpId& /*op_id_*/,
+                           const fs::IOContext* /*io_context*/,
+                           ProbeStats* /*stats*/,
+                           OperationResultPB* /*result*/) OVERRIDE {
     LOG(FATAL) << "Unimplemented";
     return Status::OK();
   }
@@ -52,13 +59,14 @@ class MockRowSet : public RowSet {
     LOG(FATAL) << "Unimplemented";
     return Status::OK();
   }
-  virtual Status NewCompactionInput(const Schema* projection,
-                                    const MvccSnapshot &snap,
-                                    gscoped_ptr<CompactionInput>* out) const OVERRIDE {
+  virtual Status NewCompactionInput(const Schema* /*projection*/,
+                                    const MvccSnapshot& /*snap*/,
+                                    const fs::IOContext* /*io_context*/,
+                                    gscoped_ptr<CompactionInput>* /*out*/) const OVERRIDE {
     LOG(FATAL) << "Unimplemented";
     return Status::OK();
   }
-  virtual Status CountRows(rowid_t *count) const OVERRIDE {
+  virtual Status CountRows(const fs::IOContext* /*io_context*/, rowid_t* /*count*/) const OVERRIDE {
     LOG(FATAL) << "Unimplemented";
     return Status::OK();
   }
@@ -66,7 +74,7 @@ class MockRowSet : public RowSet {
     LOG(FATAL) << "Unimplemented";
     return "";
   }
-  virtual Status DebugDump(std::vector<std::string> *lines = NULL) OVERRIDE {
+  virtual Status DebugDump(std::vector<std::string>* /*lines*/) OVERRIDE {
     LOG(FATAL) << "Unimplemented";
     return Status::OK();
   }
@@ -116,18 +124,18 @@ class MockRowSet : public RowSet {
     return -1;
   }
 
-  virtual double DeltaStoresCompactionPerfImprovementScore(DeltaCompactionType type)
+  virtual double DeltaStoresCompactionPerfImprovementScore(DeltaCompactionType /*type*/)
       const OVERRIDE {
     LOG(FATAL) << "Unimplemented";
     return 0;
   }
 
-  virtual Status FlushDeltas() OVERRIDE {
+  virtual Status FlushDeltas(const fs::IOContext* /*io_context*/) OVERRIDE {
     LOG(FATAL) << "Unimplemented";
     return Status::OK();
   }
 
-  virtual Status MinorCompactDeltaStores() OVERRIDE {
+  virtual Status MinorCompactDeltaStores(const fs::IOContext* /*io_context*/) OVERRIDE {
     LOG(FATAL) << "Unimplemented";
     return Status::OK();
   }
@@ -140,6 +148,7 @@ class MockRowSet : public RowSet {
 
   virtual Status InitUndoDeltas(Timestamp /*ancient_history_mark*/,
                                 MonoTime /*deadline*/,
+                                const fs::IOContext* /*io_context*/,
                                 int64_t* /*delta_blocks_initialized*/,
                                 int64_t* /*bytes_in_ancient_undos*/) OVERRIDE {
     LOG(FATAL) << "Unimplemented";
@@ -147,6 +156,7 @@ class MockRowSet : public RowSet {
   }
 
   virtual Status DeleteAncientUndoDeltas(Timestamp /*ancient_history_mark*/,
+                                         const fs::IOContext* /*io_context*/,
                                          int64_t* /*blocks_deleted*/,
                                          int64_t* /*bytes_deleted*/) OVERRIDE {
     LOG(FATAL) << "Unimplemented";

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/mt-diskrowset-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/mt-diskrowset-test.cc b/src/kudu/tablet/mt-diskrowset-test.cc
index 12906dd..7e494d8 100644
--- a/src/kudu/tablet/mt-diskrowset-test.cc
+++ b/src/kudu/tablet/mt-diskrowset-test.cc
@@ -50,7 +50,7 @@ class TestMultiThreadedRowSet : public TestRowSet {
 
   void FlushThread(DiskRowSet *rs) {
     for (int i = 0; i < 10; i++) {
-      CHECK_OK(rs->FlushDeltas());
+      CHECK_OK(rs->FlushDeltas(nullptr));
     }
   }
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/mt-rowset_delta_compaction-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/mt-rowset_delta_compaction-test.cc b/src/kudu/tablet/mt-rowset_delta_compaction-test.cc
index ad1acab..28e827e 100644
--- a/src/kudu/tablet/mt-rowset_delta_compaction-test.cc
+++ b/src/kudu/tablet/mt-rowset_delta_compaction-test.cc
@@ -93,7 +93,7 @@ class TestMultiThreadedRowSetDeltaCompaction : public TestRowSet {
   void RowSetFlushThread(DiskRowSet *rs) {
     while (ShouldRun()) {
       if (rs->CountDeltaStores() < 5) {
-        CHECK_OK(rs->FlushDeltas());
+        CHECK_OK(rs->FlushDeltas(nullptr));
       } else {
         SleepFor(MonoDelta::FromMilliseconds(10));
       }
@@ -102,7 +102,7 @@ class TestMultiThreadedRowSetDeltaCompaction : public TestRowSet {
 
   void RowSetDeltaCompactionThread(DiskRowSet *rs) {
     while (ShouldRun()) {
-      CHECK_OK(rs->MinorCompactDeltaStores());
+      CHECK_OK(rs->MinorCompactDeltaStores(nullptr));
     }
   }
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/rowset.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/rowset.cc b/src/kudu/tablet/rowset.cc
index 4e94e6d..0dec136 100644
--- a/src/kudu/tablet/rowset.cc
+++ b/src/kudu/tablet/rowset.cc
@@ -36,6 +36,9 @@ using std::vector;
 using strings::Substitute;
 
 namespace kudu {
+
+using fs::IOContext;
+
 namespace tablet {
 
 RowIteratorOptions::RowIteratorOptions()
@@ -110,9 +113,10 @@ Status DuplicatingRowSet::NewRowIterator(const RowIteratorOptions& opts,
   return Status::OK();
 }
 
-Status DuplicatingRowSet::NewCompactionInput(const Schema* projection,
-                                             const MvccSnapshot &snap,
-                                             gscoped_ptr<CompactionInput>* out) const  {
+Status DuplicatingRowSet::NewCompactionInput(const Schema* /*projection*/,
+                                             const MvccSnapshot& /*snap*/,
+                                             const IOContext* /*io_context*/,
+                                             gscoped_ptr<CompactionInput>* /*out*/) const  {
   LOG(FATAL) << "duplicating rowsets do not act as compaction input";
   return Status::OK();
 }
@@ -122,6 +126,7 @@ Status DuplicatingRowSet::MutateRow(Timestamp timestamp,
                                     const RowSetKeyProbe &probe,
                                     const RowChangeList &update,
                                     const consensus::OpId& op_id,
+                                    const IOContext* io_context,
                                     ProbeStats* stats,
                                     OperationResultPB* result) {
   // Duplicate the update to both the relevant input rowset and the output rowset.
@@ -135,7 +140,7 @@ Status DuplicatingRowSet::MutateRow(Timestamp timestamp,
   // First mutate the relevant input rowset.
   bool updated = false;
   for (const shared_ptr<RowSet> &rowset : old_rowsets_) {
-    Status s = rowset->MutateRow(timestamp, probe, update, op_id, stats, result);
+    Status s = rowset->MutateRow(timestamp, probe, update, op_id, io_context, stats, result);
     if (s.ok()) {
       updated = true;
       break;
@@ -155,7 +160,7 @@ Status DuplicatingRowSet::MutateRow(Timestamp timestamp,
   // If it succeeded there, we also need to mirror into the new rowset.
   int mirrored_count = 0;
   for (const shared_ptr<RowSet> &new_rowset : new_rowsets_) {
-    Status s = new_rowset->MutateRow(timestamp, probe, update, op_id, stats, result);
+    Status s = new_rowset->MutateRow(timestamp, probe, update, op_id, io_context, stats, result);
     if (s.ok()) {
       mirrored_count++;
       #ifdef NDEBUG
@@ -176,11 +181,11 @@ Status DuplicatingRowSet::MutateRow(Timestamp timestamp,
   return Status::OK();
 }
 
-Status DuplicatingRowSet::CheckRowPresent(const RowSetKeyProbe &probe,
+Status DuplicatingRowSet::CheckRowPresent(const RowSetKeyProbe &probe, const IOContext* io_context,
                                           bool *present, ProbeStats* stats) const {
   *present = false;
   for (const shared_ptr<RowSet> &rowset : old_rowsets_) {
-    RETURN_NOT_OK(rowset->CheckRowPresent(probe, present, stats));
+    RETURN_NOT_OK(rowset->CheckRowPresent(probe, io_context, present, stats));
     if (*present) {
       return Status::OK();
     }
@@ -188,11 +193,11 @@ Status DuplicatingRowSet::CheckRowPresent(const RowSetKeyProbe &probe,
   return Status::OK();
 }
 
-Status DuplicatingRowSet::CountRows(rowid_t *count) const {
+Status DuplicatingRowSet::CountRows(const IOContext* io_context, rowid_t *count) const {
   int64_t accumulated_count = 0;
   for (const shared_ptr<RowSet> &rs : new_rowsets_) {
     rowid_t this_count;
-    RETURN_NOT_OK(rs->CountRows(&this_count));
+    RETURN_NOT_OK(rs->CountRows(io_context, &this_count));
     accumulated_count += this_count;
   }
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/rowset.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/rowset.h b/src/kudu/tablet/rowset.h
index 47ddf82..1d1c36d 100644
--- a/src/kudu/tablet/rowset.h
+++ b/src/kudu/tablet/rowset.h
@@ -53,6 +53,10 @@ namespace consensus {
 class OpId;
 }
 
+namespace fs {
+struct IOContext;
+}
+
 namespace tablet {
 
 class CompactionInput;
@@ -88,6 +92,11 @@ struct RowIteratorOptions {
   // Defaults to UNORDERED.
   OrderMode order;
 
+  // Context of IO.
+  //
+  // Defaults to nullptr.
+  const fs::IOContext* io_context;
+
   // Whether iteration should include rows whose last mutation was a DELETE.
   //
   // Defaults to false.
@@ -108,8 +117,8 @@ class RowSet {
   // If the row was once present in this rowset, but no longer present
   // due to a DELETE, then this should set *present = false, as if
   // it were never there.
-  virtual Status CheckRowPresent(const RowSetKeyProbe &probe, bool *present,
-                                 ProbeStats* stats) const = 0;
+  virtual Status CheckRowPresent(const RowSetKeyProbe &probe, const fs::IOContext* io_context,
+                                 bool *present, ProbeStats* stats) const = 0;
 
   // Update/delete a row in this rowset.
   // The 'update_schema' is the client schema used to encode the 'update' RowChangeList.
@@ -120,6 +129,7 @@ class RowSet {
                            const RowSetKeyProbe &probe,
                            const RowChangeList &update,
                            const consensus::OpId& op_id,
+                           const fs::IOContext* io_context,
                            ProbeStats* stats,
                            OperationResultPB* result) = 0;
 
@@ -140,10 +150,11 @@ class RowSet {
   // will be projected into this Schema.
   virtual Status NewCompactionInput(const Schema* projection,
                                     const MvccSnapshot &snap,
+                                    const fs::IOContext* io_context,
                                     gscoped_ptr<CompactionInput>* out) const = 0;
 
   // Count the number of rows in this rowset.
-  virtual Status CountRows(rowid_t *count) const = 0;
+  virtual Status CountRows(const fs::IOContext* io_context, rowid_t *count) const = 0;
 
   // Return the bounds for this RowSet. 'min_encoded_key' and 'max_encoded_key'
   // are set to the first and last encoded keys for this RowSet.
@@ -192,10 +203,10 @@ class RowSet {
   virtual double DeltaStoresCompactionPerfImprovementScore(DeltaCompactionType type) const = 0;
 
   // Flush the DMS if there's one
-  virtual Status FlushDeltas() = 0;
+  virtual Status FlushDeltas(const fs::IOContext* io_context) = 0;
 
   // Compact delta stores if more than one.
-  virtual Status MinorCompactDeltaStores() = 0;
+  virtual Status MinorCompactDeltaStores(const fs::IOContext* io_context) = 0;
 
   // Estimate the number of bytes in ancient undo delta stores. This may be an
   // overestimate. The argument 'ancient_history_mark' must be valid (it may
@@ -223,6 +234,7 @@ class RowSet {
   // may be passed in as nullptr.
   virtual Status InitUndoDeltas(Timestamp ancient_history_mark,
                                 MonoTime deadline,
+                                const fs::IOContext* io_context,
                                 int64_t* delta_blocks_initialized,
                                 int64_t* bytes_in_ancient_undos) = 0;
 
@@ -244,6 +256,7 @@ class RowSet {
   // The out-parameters, 'blocks_deleted' and 'bytes_deleted', may be passed in
   // as nullptr.
   virtual Status DeleteAncientUndoDeltas(Timestamp ancient_history_mark,
+                                         const fs::IOContext* io_context,
                                          int64_t* blocks_deleted,
                                          int64_t* bytes_deleted) = 0;
 
@@ -366,20 +379,22 @@ class DuplicatingRowSet : public RowSet {
                            const RowSetKeyProbe &probe,
                            const RowChangeList &update,
                            const consensus::OpId& op_id,
+                           const fs::IOContext* io_context,
                            ProbeStats* stats,
                            OperationResultPB* result) OVERRIDE;
 
-  Status CheckRowPresent(const RowSetKeyProbe &probe, bool *present,
-                         ProbeStats* stats) const OVERRIDE;
+  Status CheckRowPresent(const RowSetKeyProbe &probe, const fs::IOContext* io_context,
+                         bool *present, ProbeStats* stats) const OVERRIDE;
 
   virtual Status NewRowIterator(const RowIteratorOptions& opts,
                                 gscoped_ptr<RowwiseIterator>* out) const OVERRIDE;
 
   virtual Status NewCompactionInput(const Schema* projection,
                                     const MvccSnapshot &snap,
+                                    const fs::IOContext* io_context,
                                     gscoped_ptr<CompactionInput>* out) const OVERRIDE;
 
-  Status CountRows(rowid_t *count) const OVERRIDE;
+  Status CountRows(const fs::IOContext* io_context, rowid_t *count) const OVERRIDE;
 
   virtual Status GetBounds(std::string* min_encoded_key,
                            std::string* max_encoded_key) const OVERRIDE;
@@ -429,7 +444,7 @@ class DuplicatingRowSet : public RowSet {
 
   int64_t MinUnflushedLogIndex() const OVERRIDE { return -1; }
 
-  Status FlushDeltas() OVERRIDE {
+  Status FlushDeltas(const fs::IOContext* /*io_context*/) OVERRIDE {
     // It's important that DuplicatingRowSet does not FlushDeltas. This prevents
     // a bug where we might end up with out-of-order deltas. See the long
     // comment in Tablet::Flush(...)
@@ -445,6 +460,7 @@ class DuplicatingRowSet : public RowSet {
 
   Status InitUndoDeltas(Timestamp /*ancient_history_mark*/,
                         MonoTime /*deadline*/,
+                        const fs::IOContext* /*io_context*/,
                         int64_t* delta_blocks_initialized,
                         int64_t* bytes_in_ancient_undos) OVERRIDE {
     if (delta_blocks_initialized) *delta_blocks_initialized = 0;
@@ -453,13 +469,15 @@ class DuplicatingRowSet : public RowSet {
   }
 
   Status DeleteAncientUndoDeltas(Timestamp /*ancient_history_mark*/,
+                                 const fs::IOContext* /*io_context*/,
                                  int64_t* blocks_deleted, int64_t* bytes_deleted) OVERRIDE {
     if (blocks_deleted) *blocks_deleted = 0;
     if (bytes_deleted) *bytes_deleted = 0;
     return Status::OK();
   }
 
-  Status MinorCompactDeltaStores() OVERRIDE { return Status::OK(); }
+  Status MinorCompactDeltaStores(
+      const fs::IOContext* /*io_context*/) OVERRIDE { return Status::OK(); }
 
  private:
   friend class Tablet;

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/tablet.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet.cc b/src/kudu/tablet/tablet.cc
index 6fe3e96..0c57724 100644
--- a/src/kudu/tablet/tablet.cc
+++ b/src/kudu/tablet/tablet.cc
@@ -51,6 +51,7 @@
 #include "kudu/consensus/log_anchor_registry.h"
 #include "kudu/consensus/opid.pb.h"
 #include "kudu/fs/fs_manager.h"
+#include "kudu/fs/io_context.h"
 #include "kudu/gutil/bind.h"
 #include "kudu/gutil/bind_helpers.h"
 #include "kudu/gutil/casts.h"
@@ -172,6 +173,7 @@ METRIC_DEFINE_gauge_size(tablet, on_disk_data_size, "Tablet Data Size On Disk",
 
 using kudu::MaintenanceManager;
 using kudu::clock::HybridClock;
+using kudu::fs::IOContext;
 using kudu::log::LogAnchorRegistry;
 using std::ostream;
 using std::pair;
@@ -267,12 +269,14 @@ Status Tablet::Open() {
 
   RowSetVector rowsets_opened;
 
+  fs::IOContext io_context({ tablet_id() });
   // open the tablet row-sets
   for (const shared_ptr<RowSetMetadata>& rowset_meta : metadata_->rowsets()) {
     shared_ptr<DiskRowSet> rowset;
     Status s = DiskRowSet::Open(rowset_meta,
                                 log_anchor_registry_.get(),
                                 mem_trackers_,
+                                &io_context,
                                 &rowset);
     if (!s.ok()) {
       LOG_WITH_PREFIX(ERROR) << "Failed to open rowset " << rowset_meta->ToString() << ": "
@@ -379,8 +383,9 @@ Status Tablet::NewRowIterator(const Schema &projection,
   if (metrics_) {
     metrics_->scans_started->Increment();
   }
+  IOContext io_context({ tablet_id() });
   VLOG_WITH_PREFIX(2) << "Created new Iterator under snap: " << snap.ToString();
-  iter->reset(new Iterator(this, projection, snap, order));
+  iter->reset(new Iterator(this, projection, snap, order, std::move(io_context)));
   return Status::OK();
 }
 
@@ -570,7 +575,8 @@ Status Tablet::ValidateMutateUnlocked(const RowOp& op) const {
   return Status::OK();
 }
 
-Status Tablet::InsertOrUpsertUnlocked(WriteTransactionState *tx_state,
+Status Tablet::InsertOrUpsertUnlocked(const IOContext* io_context,
+                                      WriteTransactionState *tx_state,
                                       RowOp* op,
                                       ProbeStats* stats) {
   DCHECK(op->checked_present);
@@ -581,7 +587,7 @@ Status Tablet::InsertOrUpsertUnlocked(WriteTransactionState *tx_state,
 
   if (op->present_in_rowset) {
     if (is_upsert) {
-      return ApplyUpsertAsUpdate(tx_state, op, op->present_in_rowset, stats);
+      return ApplyUpsertAsUpdate(io_context, tx_state, op, op->present_in_rowset, stats);
     }
     Status s = Status::AlreadyPresent("key already present");
     if (metrics_) {
@@ -605,7 +611,7 @@ Status Tablet::InsertOrUpsertUnlocked(WriteTransactionState *tx_state,
   } else {
     if (s.IsAlreadyPresent()) {
       if (is_upsert) {
-        return ApplyUpsertAsUpdate(tx_state, op, comps->memrowset.get(), stats);
+        return ApplyUpsertAsUpdate(io_context, tx_state, op, comps->memrowset.get(), stats);
       }
       if (metrics_) {
         metrics_->insertions_failed_dup_key->Increment();
@@ -616,7 +622,8 @@ Status Tablet::InsertOrUpsertUnlocked(WriteTransactionState *tx_state,
   return s;
 }
 
-Status Tablet::ApplyUpsertAsUpdate(WriteTransactionState* tx_state,
+Status Tablet::ApplyUpsertAsUpdate(const IOContext* io_context,
+                                   WriteTransactionState* tx_state,
                                    RowOp* upsert,
                                    RowSet* rowset,
                                    ProbeStats* stats) {
@@ -652,6 +659,7 @@ Status Tablet::ApplyUpsertAsUpdate(WriteTransactionState* tx_state,
                                *upsert->key_probe,
                                rcl,
                                tx_state->op_id(),
+                               io_context,
                                stats,
                                result.get());
   CHECK(!s.IsNotFound());
@@ -706,7 +714,8 @@ vector<RowSet*> Tablet::FindRowSetsToCheck(const RowOp* op,
   return to_check;
 }
 
-Status Tablet::MutateRowUnlocked(WriteTransactionState *tx_state,
+Status Tablet::MutateRowUnlocked(const IOContext* io_context,
+                                 WriteTransactionState *tx_state,
                                  RowOp* mutate,
                                  ProbeStats* stats) {
   DCHECK(mutate->checked_present);
@@ -724,6 +733,7 @@ Status Tablet::MutateRowUnlocked(WriteTransactionState *tx_state,
                                       *mutate->key_probe,
                                       mutate->decoded_op.changelist,
                                       tx_state->op_id(),
+                                      io_context,
                                       stats,
                                       result.get());
   if (PREDICT_TRUE(s.ok())) {
@@ -744,7 +754,7 @@ void Tablet::StartApplying(WriteTransactionState* tx_state) {
   tx_state->set_tablet_components(components_);
 }
 
-Status Tablet::BulkCheckPresence(WriteTransactionState* tx_state) {
+Status Tablet::BulkCheckPresence(const IOContext* io_context, WriteTransactionState* tx_state) {
   int num_ops = tx_state->row_ops().size();
 
   // TODO(todd) determine why we sometimes get empty writes!
@@ -834,7 +844,8 @@ Status Tablet::BulkCheckPresence(WriteTransactionState* tx_state) {
       }
 
       bool present = false;
-      s = rs->CheckRowPresent(*op->key_probe, &present, tx_state->mutable_op_stats(op_idx));
+      s = rs->CheckRowPresent(*op->key_probe, io_context,
+                              &present, tx_state->mutable_op_stats(op_idx));
       if (PREDICT_FALSE(!s.ok())) {
         LOG(WARNING) << Substitute("Tablet $0 failed to check row presence for op $1: $2",
             tablet_id(), op->ToString(key_schema_), s.ToString());
@@ -892,14 +903,16 @@ Status Tablet::ApplyRowOperations(WriteTransactionState* tx_state) {
     ValidateOpOrMarkFailed(op);
   }
 
-  RETURN_NOT_OK(BulkCheckPresence(tx_state));
+  IOContext io_context({ tablet_id() });
+  RETURN_NOT_OK(BulkCheckPresence(&io_context, tx_state));
 
   // Actually apply the ops.
   for (int op_idx = 0; op_idx < num_ops; op_idx++) {
     RowOp* row_op = tx_state->row_ops()[op_idx];
     if (row_op->has_result()) continue;
 
-    RETURN_NOT_OK(ApplyRowOperation(tx_state, row_op, tx_state->mutable_op_stats(op_idx)));
+    RETURN_NOT_OK(ApplyRowOperation(&io_context, tx_state, row_op,
+                                    tx_state->mutable_op_stats(op_idx)));
     DCHECK(row_op->has_result());
   }
 
@@ -909,7 +922,8 @@ Status Tablet::ApplyRowOperations(WriteTransactionState* tx_state) {
   return Status::OK();
 }
 
-Status Tablet::ApplyRowOperation(WriteTransactionState* tx_state,
+Status Tablet::ApplyRowOperation(const IOContext* io_context,
+                                 WriteTransactionState* tx_state,
                                  RowOp* row_op,
                                  ProbeStats* stats) {
   {
@@ -933,7 +947,8 @@ Status Tablet::ApplyRowOperation(WriteTransactionState* tx_state,
     vector<RowSet *> to_check = FindRowSetsToCheck(row_op, tx_state->tablet_components());
     for (RowSet *rowset : to_check) {
       bool present = false;
-      RETURN_NOT_OK_PREPEND(rowset->CheckRowPresent(*row_op->key_probe, &present, stats),
+      RETURN_NOT_OK_PREPEND(rowset->CheckRowPresent(*row_op->key_probe, io_context,
+                                                    &present, stats),
           "Failed to check if row is present");
       if (present) {
         row_op->present_in_rowset = rowset;
@@ -947,7 +962,7 @@ Status Tablet::ApplyRowOperation(WriteTransactionState* tx_state,
   switch (row_op->decoded_op.type) {
     case RowOperationsPB::INSERT:
     case RowOperationsPB::UPSERT:
-      s = InsertOrUpsertUnlocked(tx_state, row_op, stats);
+      s = InsertOrUpsertUnlocked(io_context, tx_state, row_op, stats);
       if (s.IsAlreadyPresent()) {
         return Status::OK();
       }
@@ -955,7 +970,7 @@ Status Tablet::ApplyRowOperation(WriteTransactionState* tx_state,
 
     case RowOperationsPB::UPDATE:
     case RowOperationsPB::DELETE:
-      s = MutateRowUnlocked(tx_state, row_op, stats);
+      s = MutateRowUnlocked(io_context, tx_state, row_op, stats);
       if (s.IsNotFound()) {
         return Status::OK();
       }
@@ -1023,7 +1038,7 @@ Status Tablet::DoMajorDeltaCompaction(const vector<ColumnId>& col_ids,
                                       const shared_ptr<RowSet>& input_rs) {
   RETURN_IF_STOPPED_OR_CHECK_STATE(kOpen);
   Status s = down_cast<DiskRowSet*>(input_rs.get())
-      ->MajorCompactDeltaStoresWithColumnIds(col_ids, GetHistoryGcOpts());
+      ->MajorCompactDeltaStoresWithColumnIds(col_ids, nullptr, GetHistoryGcOpts());
   return s;
 }
 
@@ -1439,6 +1454,8 @@ Status Tablet::DoMergeCompactionOrFlush(const RowSetsInCompaction &input,
                "tablet_id", tablet_id(),
                "op", op_name);
 
+  const IOContext io_context({ tablet_id() });
+
   MvccSnapshot flush_snap(mvcc_);
   LOG_WITH_PREFIX(INFO) << op_name << ": entering phase 1 (flushing snapshot). Phase 1 snapshot: "
                         << flush_snap.ToString();
@@ -1449,7 +1466,7 @@ Status Tablet::DoMergeCompactionOrFlush(const RowSetsInCompaction &input,
   }
 
   shared_ptr<CompactionInput> merge;
-  RETURN_NOT_OK(input.CreateCompactionInput(flush_snap, schema(), &merge));
+  RETURN_NOT_OK(input.CreateCompactionInput(flush_snap, schema(), &io_context, &merge));
 
   RollingDiskRowSetWriter drsw(metadata_.get(), merge->schema(), DefaultBloomSizing(),
                                compaction_policy_->target_rowset_size());
@@ -1489,6 +1506,7 @@ Status Tablet::DoMergeCompactionOrFlush(const RowSetsInCompaction &input,
       Status s = DiskRowSet::Open(meta,
                                   log_anchor_registry_.get(),
                                   mem_trackers_,
+                                  &io_context,
                                   &new_rowset);
       if (!s.ok()) {
         LOG_WITH_PREFIX(WARNING) << "Unable to open snapshot " << op_name << " results "
@@ -1584,14 +1602,14 @@ Status Tablet::DoMergeCompactionOrFlush(const RowSetsInCompaction &input,
                         << " Phase 2: carrying over any updates which arrived during Phase 1";
   LOG_WITH_PREFIX(INFO) << "Phase 2 snapshot: " << non_duplicated_txns_snap.ToString();
   RETURN_NOT_OK_PREPEND(
-      input.CreateCompactionInput(non_duplicated_txns_snap, schema(), &merge),
+      input.CreateCompactionInput(non_duplicated_txns_snap, schema(), &io_context, &merge),
           Substitute("Failed to create $0 inputs", op_name).c_str());
 
   // Update the output rowsets with the deltas that came in in phase 1, before we swapped
   // in the DuplicatingRowSets. This will perform a flush of the updated DeltaTrackers
   // in the end so that the data that is reported in the log as belonging to the input
   // rowsets is flushed.
-  RETURN_NOT_OK_PREPEND(ReupdateMissedDeltas(metadata_->tablet_id(),
+  RETURN_NOT_OK_PREPEND(ReupdateMissedDeltas(&io_context,
                                              merge.get(),
                                              history_gc_opts,
                                              flush_snap,
@@ -1728,6 +1746,7 @@ Status Tablet::CaptureConsistentIterators(
     const MvccSnapshot& snap,
     const ScanSpec* spec,
     OrderMode order,
+    const IOContext* io_context,
     vector<shared_ptr<RowwiseIterator>>* iters) const {
 
   shared_lock<rw_spinlock> l(component_lock_);
@@ -1747,12 +1766,14 @@ Status Tablet::CaptureConsistentIterators(
   RETURN_NOT_OK(components_->memrowset->NewRowIterator(opts, &ms_iter));
   ret.emplace_back(ms_iter.release());
 
+  opts.io_context = io_context;
+
   // Cull row-sets in the case of key-range queries.
   if (spec != nullptr && spec->lower_bound_key() && spec->exclusive_upper_bound_key()) {
-    // TODO : support open-ended intervals
-    // TODO: the upper bound key is exclusive, but the RowSetTree function takes
-    // an inclusive interval. So, we might end up fetching one more rowset than
-    // necessary.
+    // TODO(todd): support open-ended intervals
+    // TODO(todd): the upper bound key is exclusive, but the RowSetTree
+    // function takes an inclusive interval. So, we might end up fetching one
+    // more rowset than necessary.
     vector<RowSet *> interval_sets;
     components_->rowsets->FindRowSetsIntersectingInterval(
         spec->lower_bound_key()->encoded_key(),
@@ -1790,10 +1811,11 @@ Status Tablet::CountRows(uint64_t *count) const {
   GetComponents(&comps);
 
   // Now sum up the counts.
+  IOContext io_context({ tablet_id() });
   *count = comps->memrowset->entry_count();
   for (const shared_ptr<RowSet> &rowset : comps->rowsets->all_rowsets()) {
     rowid_t l_count;
-    RETURN_NOT_OK(rowset->CountRows(&l_count));
+    RETURN_NOT_OK(rowset->CountRows(&io_context, &l_count));
     *count += l_count;
   }
 
@@ -1894,7 +1916,8 @@ Status Tablet::FlushBestDMS(const ReplaySizeMap &replay_size_map) const {
   RETURN_IF_STOPPED_OR_CHECK_STATE(kOpen);
   shared_ptr<RowSet> rowset = FindBestDMSToFlush(replay_size_map);
   if (rowset) {
-    return rowset->FlushDeltas();
+    IOContext io_context({ tablet_id() });
+    return rowset->FlushDeltas(&io_context);
   }
   return Status::OK();
 }
@@ -1959,7 +1982,7 @@ Status Tablet::FlushBiggestDMS() {
       biggest_drs = rowset;
     }
   }
-  return max_size > 0 ? biggest_drs->FlushDeltas() : Status::OK();
+  return max_size > 0 ? biggest_drs->FlushDeltas(nullptr) : Status::OK();
 }
 
 Status Tablet::FlushAllDMSForTests() {
@@ -1967,7 +1990,7 @@ Status Tablet::FlushAllDMSForTests() {
   scoped_refptr<TabletComponents> comps;
   GetComponents(&comps);
   for (const auto& rowset : comps->rowsets->all_rowsets()) {
-    RETURN_NOT_OK(rowset->FlushDeltas());
+    RETURN_NOT_OK(rowset->FlushDeltas(nullptr));
   }
   return Status::OK();
 }
@@ -1977,12 +2000,13 @@ Status Tablet::MajorCompactAllDeltaStoresForTests() {
   RETURN_IF_STOPPED_OR_CHECK_STATE(kOpen);
   scoped_refptr<TabletComponents> comps;
   GetComponents(&comps);
+  IOContext io_context({ tablet_id() });
   for (const auto& rs : comps->rowsets->all_rowsets()) {
     if (!rs->IsAvailableForCompaction()) continue;
     DiskRowSet* drs = down_cast<DiskRowSet*>(rs.get());
     RETURN_NOT_OK(drs->delta_tracker()->InitAllDeltaStoresForTests(DeltaTracker::REDOS_ONLY));
-    RETURN_NOT_OK_PREPEND(drs->MajorCompactDeltaStores(
-        GetHistoryGcOpts()), "Failed major delta compaction on " + rs->ToString());
+    RETURN_NOT_OK_PREPEND(drs->MajorCompactDeltaStores(&io_context, GetHistoryGcOpts()),
+                          "Failed major delta compaction on " + rs->ToString());
   }
   return Status::OK();
 }
@@ -2010,12 +2034,14 @@ Status Tablet::CompactWorstDeltas(RowSet::DeltaCompactionType type) {
   // We just released compact_select_lock_ so other compactions can select and run, but the
   // rowset is ours.
   DCHECK(perf_improv != 0);
+  IOContext io_context({ tablet_id() });
   if (type == RowSet::MINOR_DELTA_COMPACTION) {
-    RETURN_NOT_OK_PREPEND(rs->MinorCompactDeltaStores(),
+    RETURN_NOT_OK_PREPEND(rs->MinorCompactDeltaStores(&io_context),
                           "Failed minor delta compaction on " + rs->ToString());
   } else if (type == RowSet::MAJOR_DELTA_COMPACTION) {
-    RETURN_NOT_OK_PREPEND(down_cast<DiskRowSet*>(rs.get())->MajorCompactDeltaStores(
-        GetHistoryGcOpts()), "Failed major delta compaction on " + rs->ToString());
+    RETURN_NOT_OK_PREPEND(
+        down_cast<DiskRowSet*>(rs.get())->MajorCompactDeltaStores(&io_context, GetHistoryGcOpts()),
+        "Failed major delta compaction on " + rs->ToString());
   }
   return Status::OK();
 }
@@ -2079,6 +2105,7 @@ Status Tablet::EstimateBytesInPotentiallyAncientUndoDeltas(int64_t* bytes) {
 Status Tablet::InitAncientUndoDeltas(MonoDelta time_budget, int64_t* bytes_in_ancient_undos) {
   MonoTime tablet_init_start = MonoTime::Now();
 
+  IOContext io_context({ tablet_id() });
   Timestamp ancient_history_mark;
   if (!Tablet::GetTabletAncientHistoryMark(&ancient_history_mark)) {
     VLOG_WITH_PREFIX(1) << "Cannot get ancient history mark. "
@@ -2119,7 +2146,7 @@ Status Tablet::InitAncientUndoDeltas(MonoDelta time_budget, int64_t* bytes_in_an
     const auto& rowset = rowsets[index];
     int64_t rowset_blocks_initialized;
     int64_t rowset_bytes_in_ancient_undos;
-    RETURN_NOT_OK(rowset->InitUndoDeltas(ancient_history_mark, deadline,
+    RETURN_NOT_OK(rowset->InitUndoDeltas(ancient_history_mark, deadline, &io_context,
                                          &rowset_blocks_initialized,
                                          &rowset_bytes_in_ancient_undos));
     tablet_bytes_in_ancient_undos += rowset_bytes_in_ancient_undos;
@@ -2167,10 +2194,11 @@ Status Tablet::DeleteAncientUndoDeltas(int64_t* blocks_deleted, int64_t* bytes_d
 
   int64_t tablet_blocks_deleted = 0;
   int64_t tablet_bytes_deleted = 0;
+  fs::IOContext io_context({ tablet_id() });
   for (const auto& rowset : rowsets_to_gc_undos) {
     int64_t rowset_blocks_deleted;
     int64_t rowset_bytes_deleted;
-    RETURN_NOT_OK(rowset->DeleteAncientUndoDeltas(ancient_history_mark,
+    RETURN_NOT_OK(rowset->DeleteAncientUndoDeltas(ancient_history_mark, &io_context,
                                                   &rowset_blocks_deleted, &rowset_bytes_deleted));
     tablet_blocks_deleted += rowset_blocks_deleted;
     tablet_bytes_deleted += rowset_bytes_deleted;
@@ -2269,11 +2297,13 @@ string Tablet::LogPrefix() const {
 ////////////////////////////////////////////////////////////
 
 Tablet::Iterator::Iterator(const Tablet* tablet, const Schema& projection,
-                           MvccSnapshot snap, const OrderMode order)
+                           MvccSnapshot snap, OrderMode order,
+                           IOContext io_context)
     : tablet_(tablet),
       projection_(projection),
       snap_(std::move(snap)),
-      order_(order) {}
+      order_(order),
+      io_context_(std::move(io_context)) {}
 
 Tablet::Iterator::~Iterator() {}
 
@@ -2285,7 +2315,8 @@ Status Tablet::Iterator::Init(ScanSpec *spec) {
 
   vector<shared_ptr<RowwiseIterator>> iters;
 
-  RETURN_NOT_OK(tablet_->CaptureConsistentIterators(&projection_, snap_, spec, order_, &iters));
+  RETURN_NOT_OK(tablet_->CaptureConsistentIterators(&projection_, snap_, spec, order_,
+                                                    &io_context_, &iters));
 
   switch (order_) {
     case ORDERED:

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/tablet.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet.h b/src/kudu/tablet/tablet.h
index 577b5c7..af6797c 100644
--- a/src/kudu/tablet/tablet.h
+++ b/src/kudu/tablet/tablet.h
@@ -34,6 +34,7 @@
 #include "kudu/common/common.pb.h"
 #include "kudu/common/iterator.h"
 #include "kudu/common/schema.h"
+#include "kudu/fs/io_context.h"
 #include "kudu/gutil/gscoped_ptr.h"
 #include "kudu/gutil/macros.h"
 #include "kudu/gutil/port.h"
@@ -181,7 +182,8 @@ class Tablet {
 
   // Apply a single row operation, which must already be prepared.
   // The result is set back into row_op->result.
-  Status ApplyRowOperation(WriteTransactionState* tx_state,
+  Status ApplyRowOperation(const fs::IOContext* io_context,
+                           WriteTransactionState* tx_state,
                            RowOp* row_op,
                            ProbeStats* stats) WARN_UNUSED_RESULT;
 
@@ -370,6 +372,8 @@ class Tablet {
   // Runs a major delta major compaction on columns with specified IDs.
   // NOTE: RowSet must presently be a DiskRowSet. (Perhaps the API should be
   // a shared_ptr API for now?)
+  //
+  // Only used in tests.
   Status DoMajorDeltaCompaction(const std::vector<ColumnId>& col_ids,
                                 const std::shared_ptr<RowSet>& input_rs);
 
@@ -511,18 +515,21 @@ class Tablet {
   // - the row lock is acquired
   // - the tablet components have been acquired
   // - the operation has been decoded
-  Status InsertOrUpsertUnlocked(WriteTransactionState *tx_state,
+  Status InsertOrUpsertUnlocked(const fs::IOContext* io_context,
+                                WriteTransactionState *tx_state,
                                 RowOp* op,
                                 ProbeStats* stats);
 
   // Same as above, but for UPDATE.
-  Status MutateRowUnlocked(WriteTransactionState *tx_state,
+  Status MutateRowUnlocked(const fs::IOContext* io_context,
+                           WriteTransactionState *tx_state,
                            RowOp* mutate,
                            ProbeStats* stats);
 
   // In the case of an UPSERT against a duplicate row, converts the UPSERT
   // into an internal UPDATE operation and performs it.
-  Status ApplyUpsertAsUpdate(WriteTransactionState *tx_state,
+  Status ApplyUpsertAsUpdate(const fs::IOContext* io_context,
+                             WriteTransactionState *tx_state,
                              RowOp* upsert,
                              RowSet* rowset,
                              ProbeStats* stats);
@@ -535,7 +542,8 @@ class Tablet {
   // For each of the operations in 'tx_state', check for the presence of their
   // row keys in the RowSets in the current RowSetTree (as determined by the transaction's
   // captured TabletComponents).
-  Status BulkCheckPresence(WriteTransactionState* tx_state) WARN_UNUSED_RESULT;
+  Status BulkCheckPresence(const fs::IOContext* io_context,
+                           WriteTransactionState* tx_state) WARN_UNUSED_RESULT;
 
   // Capture a set of iterators which, together, reflect all of the data in the tablet.
   //
@@ -545,11 +553,12 @@ class Tablet {
   //
   // The returned iterators are not Init()ed.
   // 'projection' must remain valid and unchanged for the lifetime of the returned iterators.
-  Status CaptureConsistentIterators(const Schema *projection,
-                                    const MvccSnapshot &snap,
-                                    const ScanSpec *spec,
+  Status CaptureConsistentIterators(const Schema* projection,
+                                    const MvccSnapshot& snap,
+                                    const ScanSpec* spec,
                                     OrderMode order,
-                                    std::vector<std::shared_ptr<RowwiseIterator> > *iters) const;
+                                    const fs::IOContext* io_context,
+                                    std::vector<std::shared_ptr<RowwiseIterator> >* iters) const;
 
   Status PickRowSetsToCompact(RowSetsInCompaction *picked,
                               CompactFlags flags) const;
@@ -762,12 +771,13 @@ class Tablet::Iterator : public RowwiseIterator {
   DISALLOW_COPY_AND_ASSIGN(Iterator);
 
   Iterator(const Tablet* tablet, const Schema& projection, MvccSnapshot snap,
-           const OrderMode order);
+           OrderMode order, fs::IOContext io_context);
 
   const Tablet *tablet_;
   Schema projection_;
   const MvccSnapshot snap_;
   const OrderMode order_;
+  const fs::IOContext io_context_;
   gscoped_ptr<RowwiseIterator> iter_;
 };
 


[3/3] kudu git commit: KUDU-2469 pt 1: add an IOContext

Posted by aw...@apache.org.
KUDU-2469 pt 1: add an IOContext

This patch introduces the IOContext class that can be used to pass state
from the Tablet layer to the CFile layer. The top-level caller (whether
it is a Tablet method, an iterator, etc.) will own the IOContext, and
pass a pointer to it to lower-level classes.

I intend on using this to pass the tablet id down to the CFileReaders
for error handling. As such, only codepaths that lead to CFileReaders
are plumbed. Currently the IOContext only contains a tablet id, though
in the future it could be used for more sophisticated things like
resource management, QoS for IO, etc.

Change-Id: I645e10a2fda1f2564326b7052e6a0debc5ad738c
Reviewed-on: http://gerrit.cloudera.org:8080/11248
Reviewed-by: Adar Dembo <ad...@cloudera.com>
Tested-by: Kudu Jenkins


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

Branch: refs/heads/master
Commit: 2974f5a50c95862960d09f3f18831ca259d921b2
Parents: 846eb7f
Author: Andrew Wong <aw...@cloudera.com>
Authored: Thu Aug 23 00:17:26 2018 -0700
Committer: Andrew Wong <aw...@cloudera.com>
Committed: Wed Aug 29 00:40:15 2018 +0000

----------------------------------------------------------------------
 src/kudu/cfile/bloomfile-test-base.h            |   2 +-
 src/kudu/cfile/bloomfile-test.cc                |   8 +-
 src/kudu/cfile/bloomfile.cc                     |  16 +--
 src/kudu/cfile/bloomfile.h                      |   8 +-
 src/kudu/cfile/cfile-test-base.h                |   2 +-
 src/kudu/cfile/cfile-test.cc                    |  10 +-
 src/kudu/cfile/cfile_reader.cc                  |  26 +++--
 src/kudu/cfile/cfile_reader.h                   |  27 +++--
 src/kudu/cfile/cfile_util.h                     |   9 ++
 src/kudu/fs/io_context.h                        |  32 ++++++
 src/kudu/tablet/cfile_set-test.cc               |  16 +--
 src/kudu/tablet/cfile_set.cc                    |  60 ++++++-----
 src/kudu/tablet/cfile_set.h                     |  36 ++++---
 src/kudu/tablet/compaction-test.cc              |  31 +++---
 src/kudu/tablet/compaction.cc                   |  17 +--
 src/kudu/tablet/compaction.h                    |   8 +-
 src/kudu/tablet/delta_compaction.cc             |  17 +--
 src/kudu/tablet/delta_compaction.h              |  10 +-
 src/kudu/tablet/delta_store.h                   |   9 +-
 src/kudu/tablet/delta_tracker.cc                |  74 +++++++------
 src/kudu/tablet/delta_tracker.h                 |  41 ++++----
 src/kudu/tablet/deltafile-test.cc               |   4 +-
 src/kudu/tablet/deltafile.cc                    |  24 +++--
 src/kudu/tablet/deltafile.h                     |   9 +-
 src/kudu/tablet/deltamemstore-test.cc           |   2 +-
 src/kudu/tablet/deltamemstore.cc                |   7 +-
 src/kudu/tablet/deltamemstore.h                 |   9 +-
 src/kudu/tablet/diskrowset-test-base.h          |   5 +-
 src/kudu/tablet/diskrowset-test.cc              |  51 ++++-----
 src/kudu/tablet/diskrowset.cc                   |  70 ++++++++-----
 src/kudu/tablet/diskrowset.h                    |  24 +++--
 src/kudu/tablet/memrowset-test.cc               |   4 +-
 src/kudu/tablet/memrowset.cc                    |   7 +-
 src/kudu/tablet/memrowset.h                     |  23 +++--
 src/kudu/tablet/mock-rowsets.h                  |  42 +++++---
 src/kudu/tablet/mt-diskrowset-test.cc           |   2 +-
 .../tablet/mt-rowset_delta_compaction-test.cc   |   4 +-
 src/kudu/tablet/rowset.cc                       |  23 +++--
 src/kudu/tablet/rowset.h                        |  38 +++++--
 src/kudu/tablet/tablet.cc                       | 103 ++++++++++++-------
 src/kudu/tablet/tablet.h                        |  30 ++++--
 src/kudu/tablet/tablet_bootstrap.cc             |  94 ++++++++++-------
 src/kudu/tablet/tablet_history_gc-test.cc       |   2 +-
 src/kudu/tools/tool_action_fs.cc                |   2 +-
 src/kudu/tools/tool_action_local_replica.cc     |   1 +
 45 files changed, 658 insertions(+), 381 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/cfile/bloomfile-test-base.h
----------------------------------------------------------------------
diff --git a/src/kudu/cfile/bloomfile-test-base.h b/src/kudu/cfile/bloomfile-test-base.h
index a702d32..74251b1 100644
--- a/src/kudu/cfile/bloomfile-test-base.h
+++ b/src/kudu/cfile/bloomfile-test-base.h
@@ -112,7 +112,7 @@ class BloomFileTestBase : public KuduTest {
 
         Slice s(reinterpret_cast<uint8_t *>(&key), sizeof(key));
         bool present;
-        CHECK_OK(bfr_->CheckKeyPresent(BloomKeyProbe(s), &present));
+        CHECK_OK(bfr_->CheckKeyPresent(BloomKeyProbe(s), nullptr, &present));
         if (present) count_present++;
       }
     }

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/cfile/bloomfile-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/cfile/bloomfile-test.cc b/src/kudu/cfile/bloomfile-test.cc
index f699b01..56bb694 100644
--- a/src/kudu/cfile/bloomfile-test.cc
+++ b/src/kudu/cfile/bloomfile-test.cc
@@ -55,7 +55,7 @@ class BloomFileTest : public BloomFileTestBase {
       Slice s(reinterpret_cast<char *>(&i_byteswapped), sizeof(i));
 
       bool present = false;
-      ASSERT_OK_FAST(bfr_->CheckKeyPresent(BloomKeyProbe(s), &present));
+      ASSERT_OK_FAST(bfr_->CheckKeyPresent(BloomKeyProbe(s), nullptr, &present));
       ASSERT_TRUE(present);
     }
 
@@ -66,7 +66,7 @@ class BloomFileTest : public BloomFileTestBase {
       Slice s(reinterpret_cast<char *>(&key), sizeof(key));
 
       bool present = false;
-      ASSERT_OK_FAST(bfr_->CheckKeyPresent(BloomKeyProbe(s), &present));
+      ASSERT_OK_FAST(bfr_->CheckKeyPresent(BloomKeyProbe(s), nullptr, &present));
       if (present) {
         positive_count++;
       }
@@ -133,10 +133,10 @@ TEST_F(BloomFileTest, TestLazyInit) {
 
   // But initializing it should (only the first time), and the bloom's
   // memory usage should increase.
-  ASSERT_OK(reader->Init());
+  ASSERT_OK(reader->Init(nullptr));
   ASSERT_GT(bytes_read, 0);
   size_t bytes_read_after_init = bytes_read;
-  ASSERT_OK(reader->Init());
+  ASSERT_OK(reader->Init(nullptr));
   ASSERT_EQ(bytes_read_after_init, bytes_read);
   ASSERT_GT(tracker->consumption(), lazy_mem_usage);
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/cfile/bloomfile.cc
----------------------------------------------------------------------
diff --git a/src/kudu/cfile/bloomfile.cc b/src/kudu/cfile/bloomfile.cc
index 0dbfa63..ed8efb9 100644
--- a/src/kudu/cfile/bloomfile.cc
+++ b/src/kudu/cfile/bloomfile.cc
@@ -57,6 +57,7 @@ namespace cfile {
 
 using fs::BlockCreationTransaction;
 using fs::BlockManager;
+using fs::IOContext;
 using fs::ReadableBlock;
 using fs::WritableBlock;
 
@@ -199,9 +200,10 @@ Status BloomFileReader::Open(unique_ptr<ReadableBlock> block,
                              ReaderOptions options,
                              unique_ptr<BloomFileReader> *reader) {
   unique_ptr<BloomFileReader> bf_reader;
+  const IOContext* io_context = options.io_context;
   RETURN_NOT_OK(OpenNoInit(std::move(block),
                            std::move(options), &bf_reader));
-  RETURN_NOT_OK(bf_reader->Init());
+  RETURN_NOT_OK(bf_reader->Init(io_context));
 
   *reader = std::move(bf_reader);
   return Status::OK();
@@ -213,10 +215,11 @@ Status BloomFileReader::OpenNoInit(unique_ptr<ReadableBlock> block,
   unique_ptr<CFileReader> cf_reader;
   RETURN_NOT_OK(CFileReader::OpenNoInit(std::move(block),
                                         options, &cf_reader));
+  const IOContext* io_context = options.io_context;
   unique_ptr<BloomFileReader> bf_reader(new BloomFileReader(
       std::move(cf_reader), std::move(options)));
   if (!FLAGS_cfile_lazy_open) {
-    RETURN_NOT_OK(bf_reader->Init());
+    RETURN_NOT_OK(bf_reader->Init(io_context));
   }
 
   *reader = std::move(bf_reader);
@@ -232,15 +235,15 @@ BloomFileReader::BloomFileReader(unique_ptr<CFileReader> reader,
                        memory_footprint_excluding_reader()) {
 }
 
-Status BloomFileReader::Init() {
-  return init_once_.Init([this] { return InitOnce(); });
+Status BloomFileReader::Init(const IOContext* io_context) {
+  return init_once_.Init([this, io_context] { return InitOnce(io_context); });
 }
 
-Status BloomFileReader::InitOnce() {
+Status BloomFileReader::InitOnce(const IOContext* io_context) {
   // Fully open the CFileReader if it was lazily opened earlier.
   //
   // If it's already initialized, this is a no-op.
-  RETURN_NOT_OK(reader_->Init());
+  RETURN_NOT_OK(reader_->Init(io_context));
 
   if (reader_->is_compressed()) {
     return Status::Corruption("bloom file is compressed (compression not supported)",
@@ -283,6 +286,7 @@ Status BloomFileReader::ParseBlockHeader(const Slice &block,
 }
 
 Status BloomFileReader::CheckKeyPresent(const BloomKeyProbe &probe,
+                                        const IOContext* io_context,
                                         bool *maybe_present) {
   DCHECK(init_once_.init_succeeded());
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/cfile/bloomfile.h
----------------------------------------------------------------------
diff --git a/src/kudu/cfile/bloomfile.h b/src/kudu/cfile/bloomfile.h
index e1553ec..63efdfd 100644
--- a/src/kudu/cfile/bloomfile.h
+++ b/src/kudu/cfile/bloomfile.h
@@ -35,6 +35,7 @@ namespace kudu {
 
 namespace fs {
 class BlockCreationTransaction;
+struct IOContext;
 class ReadableBlock;
 class WritableBlock;
 }
@@ -106,13 +107,14 @@ class BloomFileReader {
   // validating its contents.
   //
   // May be called multiple times; subsequent calls will no-op.
-  Status Init();
+  Status Init(const fs::IOContext* io_context);
 
   // Check if the given key may be present in the file.
   //
   // Sets *maybe_present to false if the key is definitely not
   // present, otherwise sets it to true to indicate maybe present.
-  Status CheckKeyPresent(const BloomKeyProbe &probe,
+  Status CheckKeyPresent(const BloomKeyProbe& probe,
+                         const fs::IOContext* io_context,
                          bool* maybe_present);
 
   // Can be called before Init().
@@ -135,7 +137,7 @@ class BloomFileReader {
                           Slice* bloom_data) const;
 
   // Callback used in 'init_once_' to initialize this bloom file.
-  Status InitOnce();
+  Status InitOnce(const fs::IOContext* io_context);
 
   // Returns the memory usage of this object including the object itself but
   // excluding the CFileReader, which is tracked independently.

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/cfile/cfile-test-base.h
----------------------------------------------------------------------
diff --git a/src/kudu/cfile/cfile-test-base.h b/src/kudu/cfile/cfile-test-base.h
index e21ba83..e48d6eb 100644
--- a/src/kudu/cfile/cfile-test-base.h
+++ b/src/kudu/cfile/cfile-test-base.h
@@ -486,7 +486,7 @@ void TimeReadFile(FsManager* fs_manager, const BlockId& block_id, size_t *count_
   ASSERT_OK(CFileReader::Open(std::move(source), ReaderOptions(), &reader));
 
   gscoped_ptr<CFileIterator> iter;
-  ASSERT_OK(reader->NewIterator(&iter, CFileReader::CACHE_BLOCK));
+  ASSERT_OK(reader->NewIterator(&iter, CFileReader::CACHE_BLOCK, nullptr));
   ASSERT_OK(iter->SeekToOrdinal(0));
 
   Arena arena(8192);

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/cfile/cfile-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/cfile/cfile-test.cc b/src/kudu/cfile/cfile-test.cc
index 3213495..dc1458f 100644
--- a/src/kudu/cfile/cfile-test.cc
+++ b/src/kudu/cfile/cfile-test.cc
@@ -118,7 +118,7 @@ class TestCFile : public CFileTestBase {
 
     BlockPointer ptr;
     gscoped_ptr<CFileIterator> iter;
-    ASSERT_OK(reader->NewIterator(&iter, CFileReader::CACHE_BLOCK));
+    ASSERT_OK(reader->NewIterator(&iter, CFileReader::CACHE_BLOCK, nullptr));
 
     ASSERT_OK(iter->SeekToOrdinal(5000));
     ASSERT_EQ(5000u, iter->GetCurrentOrdinal());
@@ -201,7 +201,7 @@ class TestCFile : public CFileTestBase {
     ASSERT_EQ(DataGeneratorType::kDataType, reader->type_info()->type());
 
     gscoped_ptr<CFileIterator> iter;
-    ASSERT_OK(reader->NewIterator(&iter, CFileReader::CACHE_BLOCK));
+    ASSERT_OK(reader->NewIterator(&iter, CFileReader::CACHE_BLOCK, nullptr));
 
     Arena arena(8192);
     ScopedColumnBlock<DataGeneratorType::kDataType> cb(10);
@@ -615,7 +615,7 @@ void TestCFile::TestReadWriteStrings(EncodingType encoding,
   BlockPointer ptr;
 
   gscoped_ptr<CFileIterator> iter;
-  ASSERT_OK(reader->NewIterator(&iter, CFileReader::CACHE_BLOCK));
+  ASSERT_OK(reader->NewIterator(&iter, CFileReader::CACHE_BLOCK, nullptr));
 
   Arena arena(1024);
 
@@ -970,10 +970,10 @@ TEST_P(TestCFileBothCacheTypes, TestLazyInit) {
 
   // But initializing it should (only the first time), and the reader's
   // memory usage should increase.
-  ASSERT_OK(reader->Init());
+  ASSERT_OK(reader->Init(nullptr));
   ASSERT_GT(bytes_read, 0);
   size_t bytes_read_after_init = bytes_read;
-  ASSERT_OK(reader->Init());
+  ASSERT_OK(reader->Init(nullptr));
   ASSERT_EQ(bytes_read_after_init, bytes_read);
   ASSERT_GT(tracker->consumption(), lazy_mem_usage);
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/cfile/cfile_reader.cc
----------------------------------------------------------------------
diff --git a/src/kudu/cfile/cfile_reader.cc b/src/kudu/cfile/cfile_reader.cc
index e0d7688..2ee5236 100644
--- a/src/kudu/cfile/cfile_reader.cc
+++ b/src/kudu/cfile/cfile_reader.cc
@@ -75,6 +75,7 @@ DEFINE_bool(cfile_verify_checksums, true,
             "Verify the checksum for each block on read if one exists");
 TAG_FLAG(cfile_verify_checksums, evolving);
 
+using kudu::fs::IOContext;
 using kudu::fs::ReadableBlock;
 using kudu::pb_util::SecureDebugString;
 using std::string;
@@ -134,10 +135,11 @@ Status CFileReader::Open(unique_ptr<ReadableBlock> block,
                          ReaderOptions options,
                          unique_ptr<CFileReader>* reader) {
   unique_ptr<CFileReader> reader_local;
+  const IOContext* io_context = options.io_context;
   RETURN_NOT_OK(OpenNoInit(std::move(block),
                            std::move(options),
                            &reader_local));
-  RETURN_NOT_OK(reader_local->Init());
+  RETURN_NOT_OK(reader_local->Init(io_context));
 
   *reader = std::move(reader_local);
   return Status::OK();
@@ -148,17 +150,18 @@ Status CFileReader::OpenNoInit(unique_ptr<ReadableBlock> block,
                                unique_ptr<CFileReader>* reader) {
   uint64_t block_size;
   RETURN_NOT_OK(block->Size(&block_size));
+  const IOContext* io_context = options.io_context;
   unique_ptr<CFileReader> reader_local(
       new CFileReader(std::move(options), block_size, std::move(block)));
   if (!FLAGS_cfile_lazy_open) {
-    RETURN_NOT_OK(reader_local->Init());
+    RETURN_NOT_OK(reader_local->Init(io_context));
   }
 
   *reader = std::move(reader_local);
   return Status::OK();
 }
 
-Status CFileReader::InitOnce() {
+Status CFileReader::InitOnce(const IOContext* io_context) {
   VLOG(1) << "Initializing CFile with ID " << block_->id().ToString();
   TRACE_COUNTER_INCREMENT("cfile_init", 1);
 
@@ -191,8 +194,8 @@ Status CFileReader::InitOnce() {
   return Status::OK();
 }
 
-Status CFileReader::Init() {
-  RETURN_NOT_OK_PREPEND(init_once_.Init([this] { return InitOnce(); }),
+Status CFileReader::Init(const IOContext* io_context) {
+  RETURN_NOT_OK_PREPEND(init_once_.Init([this, io_context] { return InitOnce(io_context); }),
                         Substitute("failed to init CFileReader for block $0",
                                    block_id().ToString()));
   return Status::OK();
@@ -571,8 +574,9 @@ bool CFileReader::GetMetadataEntry(const string &key, string *val) const {
   return false;
 }
 
-Status CFileReader::NewIterator(CFileIterator **iter, CacheControl cache_control) {
-  *iter = new CFileIterator(this, cache_control);
+Status CFileReader::NewIterator(CFileIterator** iter, CacheControl cache_control,
+                                const IOContext* io_context) {
+  *iter = new CFileIterator(this, cache_control, io_context);
   return Status::OK();
 }
 
@@ -655,13 +659,15 @@ Status DefaultColumnValueIterator::FinishBatch() {
 // Iterator
 ////////////////////////////////////////////////////////////
 CFileIterator::CFileIterator(CFileReader* reader,
-                             CFileReader::CacheControl cache_control)
+                             CFileReader::CacheControl cache_control,
+                             const IOContext* io_context)
   : reader_(reader),
     seeked_(nullptr),
     prepared_(false),
     cache_control_(cache_control),
     last_prepare_idx_(-1),
-    last_prepare_count_(-1) {
+    last_prepare_count_(-1),
+    io_context_(io_context) {
 }
 
 CFileIterator::~CFileIterator() {
@@ -846,7 +852,7 @@ Status CFileIterator::PrepareForNewSeek() {
   // Fully open the CFileReader if it was lazily opened earlier.
   //
   // If it's already initialized, this is a no-op.
-  RETURN_NOT_OK(reader_->Init());
+  RETURN_NOT_OK(reader_->Init(io_context_));
 
   // Create the index tree iterators if we haven't already done so.
   if (!posidx_iter_ && reader_->footer().has_posidx_info()) {

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/cfile/cfile_reader.h
----------------------------------------------------------------------
diff --git a/src/kudu/cfile/cfile_reader.h b/src/kudu/cfile/cfile_reader.h
index 7263d3f..6e98fa8 100644
--- a/src/kudu/cfile/cfile_reader.h
+++ b/src/kudu/cfile/cfile_reader.h
@@ -21,6 +21,7 @@
 #include <cstddef>
 #include <cstdint>
 #include <memory>
+#include <mutex>
 #include <string>
 #include <vector>
 
@@ -54,6 +55,10 @@ class EncodedKey;
 class SelectionVector;
 class TypeInfo;
 
+namespace fs {
+struct IOContext;
+}  // namespace fs
+
 template <typename T> class ArrayView;
 
 namespace cfile {
@@ -87,7 +92,7 @@ class CFileReader {
   // its contents.
   //
   // May be called multiple times; subsequent calls will no-op.
-  Status Init();
+  Status Init(const fs::IOContext* io_context);
 
   enum CacheControl {
     CACHE_BLOCK,
@@ -95,11 +100,14 @@ class CFileReader {
   };
 
   // Can be called before Init().
-  Status NewIterator(CFileIterator **iter, CacheControl cache_control);
-  Status NewIterator(gscoped_ptr<CFileIterator> *iter,
-                     CacheControl cache_control) {
-    CFileIterator *iter_ptr;
-    RETURN_NOT_OK(NewIterator(&iter_ptr, cache_control));
+  Status NewIterator(CFileIterator** iter,
+                     CacheControl cache_control,
+                     const fs::IOContext* io_context);
+  Status NewIterator(gscoped_ptr<CFileIterator>* iter,
+                     CacheControl cache_control,
+                     const fs::IOContext* io_context) {
+    CFileIterator* iter_ptr;
+    RETURN_NOT_OK(NewIterator(&iter_ptr, cache_control, io_context));
     (*iter).reset(iter_ptr);
     return Status::OK();
   }
@@ -191,7 +199,7 @@ class CFileReader {
               std::unique_ptr<fs::ReadableBlock> block);
 
   // Callback used in 'init_once_' to initialize this cfile.
-  Status InitOnce();
+  Status InitOnce(const fs::IOContext* io_context);
 
   Status ReadAndParseHeader();
   Status ReadAndParseFooter();
@@ -313,7 +321,8 @@ class DefaultColumnValueIterator : public ColumnIterator {
 class CFileIterator : public ColumnIterator {
  public:
   CFileIterator(CFileReader* reader,
-                CFileReader::CacheControl cache_control);
+                CFileReader::CacheControl cache_control,
+                const fs::IOContext* io_context);
   ~CFileIterator();
 
   // Seek to the first entry in the file. This works for both
@@ -498,6 +507,8 @@ class CFileIterator : public ColumnIterator {
 
   IteratorStats io_stats_;
 
+  const fs::IOContext* io_context_;
+
   // a temporary buffer for encoding
   faststring tmp_buf_;
 };

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/cfile/cfile_util.h
----------------------------------------------------------------------
diff --git a/src/kudu/cfile/cfile_util.h b/src/kudu/cfile/cfile_util.h
index 967569e..1574187 100644
--- a/src/kudu/cfile/cfile_util.h
+++ b/src/kudu/cfile/cfile_util.h
@@ -33,6 +33,10 @@ namespace kudu {
 class MemTracker;
 class faststring;
 
+namespace fs {
+struct IOContext;
+}  // namespace fs
+
 namespace cfile {
 
 class CFileReader;
@@ -91,6 +95,11 @@ struct WriterOptions {
 struct ReaderOptions {
   ReaderOptions();
 
+  // The IO context of this reader.
+  //
+  // Default: nullptr
+  const fs::IOContext* io_context;
+
   // The MemTracker that should account for this reader's memory consumption.
   //
   // Default: the root tracker.

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/fs/io_context.h
----------------------------------------------------------------------
diff --git a/src/kudu/fs/io_context.h b/src/kudu/fs/io_context.h
new file mode 100644
index 0000000..9a335a6
--- /dev/null
+++ b/src/kudu/fs/io_context.h
@@ -0,0 +1,32 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#include <string>
+
+namespace kudu {
+namespace fs {
+
+// An IOContext provides a single interface to pass state around during IO.
+struct IOContext {
+  // The tablet_id associated with this IO.
+  std::string tablet_id;
+};
+
+}  // namespace fs
+}  // namespace kudu

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/cfile_set-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/cfile_set-test.cc b/src/kudu/tablet/cfile_set-test.cc
index a1c4316..cef4b71 100644
--- a/src/kudu/tablet/cfile_set-test.cc
+++ b/src/kudu/tablet/cfile_set-test.cc
@@ -106,7 +106,7 @@ class TestCFileSet : public KuduRowSetTest {
                        int32_t lower,
                        int32_t upper) {
     // Create iterator.
-    shared_ptr<CFileSet::Iterator> cfile_iter(fileset->NewIterator(&schema_));
+    shared_ptr<CFileSet::Iterator> cfile_iter(fileset->NewIterator(&schema_, nullptr));
     gscoped_ptr<RowwiseIterator> iter(new MaterializingIterator(cfile_iter));
 
     // Create a scan with a range predicate on the key column.
@@ -163,9 +163,9 @@ TEST_F(TestCFileSet, TestPartiallyMaterialize) {
   WriteTestRowSet(kNumRows);
 
   shared_ptr<CFileSet> fileset;
-  ASSERT_OK(CFileSet::Open(rowset_meta_, MemTracker::GetRootTracker(), &fileset));
+  ASSERT_OK(CFileSet::Open(rowset_meta_, MemTracker::GetRootTracker(), nullptr, &fileset));
 
-  gscoped_ptr<CFileSet::Iterator> iter(fileset->NewIterator(&schema_));
+  gscoped_ptr<CFileSet::Iterator> iter(fileset->NewIterator(&schema_, nullptr));
   ASSERT_OK(iter->Init(nullptr));
 
   Arena arena(4096);
@@ -243,11 +243,11 @@ TEST_F(TestCFileSet, TestIteratePartialSchema) {
   WriteTestRowSet(kNumRows);
 
   shared_ptr<CFileSet> fileset;
-  ASSERT_OK(CFileSet::Open(rowset_meta_, MemTracker::GetRootTracker(), &fileset));
+  ASSERT_OK(CFileSet::Open(rowset_meta_, MemTracker::GetRootTracker(), nullptr, &fileset));
 
   Schema new_schema;
   ASSERT_OK(schema_.CreateProjectionByNames({ "c0", "c2" }, &new_schema));
-  shared_ptr<CFileSet::Iterator> cfile_iter(fileset->NewIterator(&new_schema));
+  shared_ptr<CFileSet::Iterator> cfile_iter(fileset->NewIterator(&new_schema, nullptr));
   gscoped_ptr<RowwiseIterator> iter(new MaterializingIterator(cfile_iter));
 
   ASSERT_OK(iter->Init(nullptr));
@@ -276,10 +276,10 @@ TEST_F(TestCFileSet, TestRangeScan) {
   WriteTestRowSet(kNumRows);
 
   shared_ptr<CFileSet> fileset;
-  ASSERT_OK(CFileSet::Open(rowset_meta_, MemTracker::GetRootTracker(), &fileset));
+  ASSERT_OK(CFileSet::Open(rowset_meta_, MemTracker::GetRootTracker(), nullptr, &fileset));
 
   // Create iterator.
-  shared_ptr<CFileSet::Iterator> cfile_iter(fileset->NewIterator(&schema_));
+  shared_ptr<CFileSet::Iterator> cfile_iter(fileset->NewIterator(&schema_, nullptr));
   gscoped_ptr<RowwiseIterator> iter(new MaterializingIterator(cfile_iter));
   Schema key_schema = schema_.CreateKeyProjection();
   Arena arena(1024);
@@ -329,7 +329,7 @@ TEST_F(TestCFileSet, TestRangePredicates2) {
   WriteTestRowSet(kNumRows);
 
   shared_ptr<CFileSet> fileset;
-  ASSERT_OK(CFileSet::Open(rowset_meta_, MemTracker::GetRootTracker(), &fileset));
+  ASSERT_OK(CFileSet::Open(rowset_meta_, MemTracker::GetRootTracker(), nullptr, &fileset));
 
   // Range scan where rows match on both ends
   DoTestRangeScan(fileset, 2000, 2010);

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/cfile_set.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/cfile_set.cc b/src/kudu/tablet/cfile_set.cc
index 63a28aa..3d16b39 100644
--- a/src/kudu/tablet/cfile_set.cc
+++ b/src/kudu/tablet/cfile_set.cc
@@ -76,6 +76,7 @@ using cfile::CFileReader;
 using cfile::ColumnIterator;
 using cfile::ReaderOptions;
 using cfile::DefaultColumnValueIterator;
+using fs::IOContext;
 using fs::ReadableBlock;
 using std::shared_ptr;
 using std::string;
@@ -90,12 +91,14 @@ using strings::Substitute;
 static Status OpenReader(FsManager* fs,
                          shared_ptr<MemTracker> parent_mem_tracker,
                          const BlockId& block_id,
+                         const IOContext* io_context,
                          unique_ptr<CFileReader>* new_reader) {
   unique_ptr<ReadableBlock> block;
   RETURN_NOT_OK(fs->OpenBlock(block_id, &block));
 
   ReaderOptions opts;
   opts.parent_mem_tracker = std::move(parent_mem_tracker);
+  opts.io_context = io_context;
   return CFileReader::OpenNoInit(std::move(block),
                                  std::move(opts),
                                  new_reader);
@@ -116,17 +119,18 @@ CFileSet::~CFileSet() {
 
 Status CFileSet::Open(shared_ptr<RowSetMetadata> rowset_metadata,
                       shared_ptr<MemTracker> parent_mem_tracker,
+                      const IOContext* io_context,
                       shared_ptr<CFileSet>* cfile_set) {
   shared_ptr<CFileSet> cfs(new CFileSet(std::move(rowset_metadata),
                                         std::move(parent_mem_tracker)));
-  RETURN_NOT_OK(cfs->DoOpen());
+  RETURN_NOT_OK(cfs->DoOpen(io_context));
 
   cfile_set->swap(cfs);
   return Status::OK();
 }
 
-Status CFileSet::DoOpen() {
-  RETURN_NOT_OK(OpenBloomReader());
+Status CFileSet::DoOpen(const IOContext* io_context) {
+  RETURN_NOT_OK(OpenBloomReader(io_context));
 
   // Lazily open the column data cfiles. Each one will be fully opened
   // later, when the first iterator seeks for the first time.
@@ -139,6 +143,7 @@ Status CFileSet::DoOpen() {
     RETURN_NOT_OK(OpenReader(rowset_metadata_->fs_manager(),
                              parent_mem_tracker_,
                              rowset_metadata_->column_data_block_for_col_id(col_id),
+                             io_context,
                              &reader));
     readers_by_col_id_[col_id] = std::move(reader);
     VLOG(1) << "Successfully opened cfile for column id " << col_id
@@ -150,6 +155,7 @@ Status CFileSet::DoOpen() {
     RETURN_NOT_OK(OpenReader(rowset_metadata_->fs_manager(),
                              parent_mem_tracker_,
                              rowset_metadata_->adhoc_index_block(),
+                             io_context,
                              &ad_hoc_idx_reader_));
   }
 
@@ -159,7 +165,7 @@ Status CFileSet::DoOpen() {
     min_encoded_key_ = rowset_metadata_->min_encoded_key();
     max_encoded_key_ = rowset_metadata_->max_encoded_key();
   } else {
-    RETURN_NOT_OK(LoadMinMaxKeys());
+    RETURN_NOT_OK(LoadMinMaxKeys(io_context));
   }
   // Verify the loaded keys are valid.
   if (Slice(min_encoded_key_).compare(max_encoded_key_) > 0) {
@@ -172,13 +178,14 @@ Status CFileSet::DoOpen() {
   return Status::OK();
 }
 
-Status CFileSet::OpenBloomReader() {
+Status CFileSet::OpenBloomReader(const IOContext* io_context) {
   FsManager* fs = rowset_metadata_->fs_manager();
   unique_ptr<ReadableBlock> block;
   RETURN_NOT_OK(fs->OpenBlock(rowset_metadata_->bloom_block(), &block));
 
   ReaderOptions opts;
   opts.parent_mem_tracker = parent_mem_tracker_;
+  opts.io_context = io_context;
   Status s = BloomFileReader::OpenNoInit(std::move(block),
                                          std::move(opts),
                                          &bloom_reader_);
@@ -191,9 +198,9 @@ Status CFileSet::OpenBloomReader() {
   return Status::OK();
 }
 
-Status CFileSet::LoadMinMaxKeys() {
+Status CFileSet::LoadMinMaxKeys(const IOContext* io_context) {
   CFileReader* key_reader = key_index_reader();
-  RETURN_NOT_OK(key_index_reader()->Init());
+  RETURN_NOT_OK(key_index_reader()->Init(io_context));
   if (!key_reader->GetMetadataEntry(DiskRowSet::kMinKeyMetaEntryName, &min_encoded_key_)) {
     return Status::Corruption("No min key found", ToString());
   }
@@ -215,16 +222,18 @@ CFileReader* CFileSet::key_index_reader() const {
 }
 
 Status CFileSet::NewColumnIterator(ColumnId col_id, CFileReader::CacheControl cache_blocks,
-                                   CFileIterator **iter) const {
-  return FindOrDie(readers_by_col_id_, col_id)->NewIterator(iter, cache_blocks);
+                                   const fs::IOContext* io_context, CFileIterator **iter) const {
+  return FindOrDie(readers_by_col_id_, col_id)->NewIterator(iter, cache_blocks,
+                                                            io_context);
 }
 
-CFileSet::Iterator *CFileSet::NewIterator(const Schema *projection) const {
-  return new CFileSet::Iterator(shared_from_this(), projection);
+CFileSet::Iterator* CFileSet::NewIterator(const Schema* projection,
+                                          const IOContext* io_context) const {
+  return new CFileSet::Iterator(shared_from_this(), projection, io_context);
 }
 
-Status CFileSet::CountRows(rowid_t *count) const {
-  RETURN_NOT_OK(key_index_reader()->Init());
+Status CFileSet::CountRows(const IOContext* io_context, rowid_t *count) const {
+  RETURN_NOT_OK(key_index_reader()->Init(io_context));
   return key_index_reader()->CountRows(count);
 }
 
@@ -255,17 +264,18 @@ uint64_t CFileSet::OnDiskDataSize() const {
 }
 
 Status CFileSet::FindRow(const RowSetKeyProbe &probe,
+                         const IOContext* io_context,
                          boost::optional<rowid_t>* idx,
                          ProbeStats* stats) const {
   if (FLAGS_consult_bloom_filters) {
     // Fully open the BloomFileReader if it was lazily opened earlier.
     //
     // If it's already initialized, this is a no-op.
-    RETURN_NOT_OK(bloom_reader_->Init());
+    RETURN_NOT_OK(bloom_reader_->Init(io_context));
 
     stats->blooms_consulted++;
     bool present;
-    Status s = bloom_reader_->CheckKeyPresent(probe.bloom_probe(), &present);
+    Status s = bloom_reader_->CheckKeyPresent(probe.bloom_probe(), io_context, &present);
     if (s.ok() && !present) {
       *idx = boost::none;
       return Status::OK();
@@ -284,7 +294,7 @@ Status CFileSet::FindRow(const RowSetKeyProbe &probe,
 
   stats->keys_consulted++;
   CFileIterator *key_iter = nullptr;
-  RETURN_NOT_OK(NewKeyIterator(&key_iter));
+  RETURN_NOT_OK(NewKeyIterator(io_context, &key_iter));
 
   unique_ptr<CFileIterator> key_iter_scoped(key_iter); // free on return
 
@@ -300,10 +310,10 @@ Status CFileSet::FindRow(const RowSetKeyProbe &probe,
   return Status::OK();
 }
 
-Status CFileSet::CheckRowPresent(const RowSetKeyProbe &probe, bool *present,
-                                 rowid_t *rowid, ProbeStats* stats) const {
+Status CFileSet::CheckRowPresent(const RowSetKeyProbe& probe, const IOContext* io_context,
+                                 bool* present, rowid_t* rowid, ProbeStats* stats) const {
   boost::optional<rowid_t> opt_rowid;
-  RETURN_NOT_OK(FindRow(probe, &opt_rowid, stats));
+  RETURN_NOT_OK(FindRow(probe, io_context, &opt_rowid, stats));
   *present = opt_rowid != boost::none;
   if (*present) {
     *rowid = *opt_rowid;
@@ -311,9 +321,9 @@ Status CFileSet::CheckRowPresent(const RowSetKeyProbe &probe, bool *present,
   return Status::OK();
 }
 
-Status CFileSet::NewKeyIterator(CFileIterator **key_iter) const {
-  RETURN_NOT_OK(key_index_reader()->Init());
-  return key_index_reader()->NewIterator(key_iter, CFileReader::CACHE_BLOCK);
+Status CFileSet::NewKeyIterator(const IOContext* io_context, CFileIterator** key_iter) const {
+  RETURN_NOT_OK(key_index_reader()->Init(io_context));
+  return key_index_reader()->NewIterator(key_iter, CFileReader::CACHE_BLOCK, io_context);
 }
 
 ////////////////////////////////////////////////////////////
@@ -351,7 +361,7 @@ Status CFileSet::Iterator::CreateColumnIterators(const ScanSpec* spec) {
       continue;
     }
     CFileIterator *iter;
-    RETURN_NOT_OK_PREPEND(base_data_->NewColumnIterator(col_id, cache_blocks, &iter),
+    RETURN_NOT_OK_PREPEND(base_data_->NewColumnIterator(col_id, cache_blocks, io_context_, &iter),
                           Substitute("could not create iterator for column $0",
                                      projection_->column(proj_col_idx).ToString()));
     ret_iters.emplace_back(iter);
@@ -364,11 +374,11 @@ Status CFileSet::Iterator::CreateColumnIterators(const ScanSpec* spec) {
 Status CFileSet::Iterator::Init(ScanSpec *spec) {
   CHECK(!initted_);
 
-  RETURN_NOT_OK(base_data_->CountRows(&row_count_));
+  RETURN_NOT_OK(base_data_->CountRows(io_context_, &row_count_));
 
   // Setup Key Iterator
   CFileIterator *tmp;
-  RETURN_NOT_OK(base_data_->NewKeyIterator(&tmp));
+  RETURN_NOT_OK(base_data_->NewKeyIterator(io_context_, &tmp));
   key_iter_.reset(tmp);
 
   // Setup column iterators.

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/cfile_set.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/cfile_set.h b/src/kudu/tablet/cfile_set.h
index 5c533ad..89743d9 100644
--- a/src/kudu/tablet/cfile_set.h
+++ b/src/kudu/tablet/cfile_set.h
@@ -43,7 +43,7 @@
 namespace boost {
 template <class T>
 class optional;
-}
+}  // namespace boost
 
 namespace kudu {
 
@@ -55,7 +55,11 @@ struct IteratorStats;
 
 namespace cfile {
 class BloomFileReader;
-}
+}  // namespace cfile
+
+namespace fs {
+struct IOContext;
+}  // namespace fs
 
 namespace tablet {
 
@@ -72,13 +76,15 @@ class CFileSet : public std::enable_shared_from_this<CFileSet> {
 
   static Status Open(std::shared_ptr<RowSetMetadata> rowset_metadata,
                      std::shared_ptr<MemTracker> parent_mem_tracker,
+                     const fs::IOContext* io_context,
                      std::shared_ptr<CFileSet>* cfile_set);
 
   // Create an iterator with the given projection. 'projection' must remain valid
   // for the lifetime of the returned iterator.
-  virtual Iterator *NewIterator(const Schema *projection) const;
+  virtual Iterator* NewIterator(const Schema* projection,
+                                const fs::IOContext* io_context) const;
 
-  Status CountRows(rowid_t *count) const;
+  Status CountRows(const fs::IOContext* io_context, rowid_t *count) const;
 
   // See RowSet::GetBounds
   virtual Status GetBounds(std::string* min_encoded_key,
@@ -99,6 +105,7 @@ class CFileSet : public std::enable_shared_from_this<CFileSet> {
   // Determine the index of the given row key.
   // Sets *idx to boost::none if the row is not found.
   Status FindRow(const RowSetKeyProbe& probe,
+                 const fs::IOContext* io_context,
                  boost::optional<rowid_t>* idx,
                  ProbeStats* stats) const;
 
@@ -108,8 +115,8 @@ class CFileSet : public std::enable_shared_from_this<CFileSet> {
 
   // Check if the given row is present. If it is, sets *rowid to the
   // row's index.
-  Status CheckRowPresent(const RowSetKeyProbe &probe, bool *present,
-                         rowid_t *rowid, ProbeStats* stats) const;
+  Status CheckRowPresent(const RowSetKeyProbe& probe, const fs::IOContext* io_context,
+                         bool* present, rowid_t* rowid, ProbeStats* stats) const;
 
   // Return true if there exists a CFile for the given column ID.
   bool has_data_for_column_id(ColumnId col_id) const {
@@ -126,15 +133,15 @@ class CFileSet : public std::enable_shared_from_this<CFileSet> {
   CFileSet(std::shared_ptr<RowSetMetadata> rowset_metadata,
            std::shared_ptr<MemTracker> parent_mem_tracker);
 
-  Status DoOpen();
-  Status OpenBloomReader();
-  Status OpenAdHocIndexReader();
-  Status LoadMinMaxKeys();
+  Status DoOpen(const fs::IOContext* io_context);
+  Status OpenBloomReader(const fs::IOContext* io_context);
+  Status LoadMinMaxKeys(const fs::IOContext* io_context);
 
   Status NewColumnIterator(ColumnId col_id,
                            cfile::CFileReader::CacheControl cache_blocks,
+                           const fs::IOContext* io_context,
                            cfile::CFileIterator **iter) const;
-  Status NewKeyIterator(cfile::CFileIterator** key_iter) const;
+  Status NewKeyIterator(const fs::IOContext* io_context, cfile::CFileIterator** key_iter) const;
 
   // Return the CFileReader responsible for reading the key index.
   // (the ad-hoc reader for composite keys, otherwise the key column reader)
@@ -210,12 +217,14 @@ class CFileSet::Iterator : public ColumnwiseIterator {
   friend class CFileSet;
 
   // 'projection' must remain valid for the lifetime of this object.
-  Iterator(std::shared_ptr<CFileSet const> base_data, const Schema *projection)
+  Iterator(std::shared_ptr<CFileSet const> base_data, const Schema* projection,
+           const fs::IOContext* io_context)
       : base_data_(std::move(base_data)),
         projection_(projection),
         initted_(false),
         cur_idx_(0),
-        prepared_count_(0) {}
+        prepared_count_(0),
+        io_context_(io_context) {}
 
   // Fill in col_iters_ for each of the requested columns.
   Status CreateColumnIterators(const ScanSpec* spec);
@@ -252,6 +261,7 @@ class CFileSet::Iterator : public ColumnwiseIterator {
   rowid_t lower_bound_idx_;
   rowid_t upper_bound_idx_;
 
+  const fs::IOContext* io_context_;
 
   // The underlying columns are prepared lazily, so that if a column is never
   // materialized, it doesn't need to be read off disk.

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/compaction-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/compaction-test.cc b/src/kudu/tablet/compaction-test.cc
index e18d966..6c83169 100644
--- a/src/kudu/tablet/compaction-test.cc
+++ b/src/kudu/tablet/compaction-test.cc
@@ -225,6 +225,7 @@ class TestCompaction : public KuduRowSetTest {
                                 probe,
                                 RowChangeList(update_buf),
                                 op_id_,
+                                nullptr,
                                 &stats,
                                 &result));
   }
@@ -261,6 +262,7 @@ class TestCompaction : public KuduRowSetTest {
                                 probe,
                                 RowChangeList(update_buf),
                                 op_id_,
+                                nullptr,
                                 &stats,
                                 &result));
   }
@@ -297,7 +299,7 @@ class TestCompaction : public KuduRowSetTest {
       for (const shared_ptr<RowSetMetadata>& meta : metas) {
         shared_ptr<DiskRowSet> rs;
         ASSERT_OK(DiskRowSet::Open(meta, log_anchor_registry_.get(),
-                                   mem_trackers_, &rs));
+                                   mem_trackers_, nullptr, &rs));
         result_rowsets->push_back(rs);
       }
     }
@@ -310,7 +312,7 @@ class TestCompaction : public KuduRowSetTest {
     vector<shared_ptr<CompactionInput> > merge_inputs;
     for (const shared_ptr<DiskRowSet> &rs : rowsets) {
       gscoped_ptr<CompactionInput> input;
-      RETURN_NOT_OK(CompactionInput::Create(*rs, &projection, merge_snap, &input));
+      RETURN_NOT_OK(CompactionInput::Create(*rs, &projection, merge_snap, nullptr, &input));
       merge_inputs.push_back(shared_ptr<CompactionInput>(input.release()));
     }
     out->reset(CompactionInput::Merge(merge_inputs, &projection));
@@ -396,7 +398,7 @@ class TestCompaction : public KuduRowSetTest {
     // Verify the resulting compaction output has the right number
     // of rows.
     rowid_t count = 0;
-    ASSERT_OK(result_rs->CountRows(&count));
+    ASSERT_OK(result_rs->CountRows(nullptr, &count));
     ASSERT_EQ(1000 * schemas.size(), count);
   }
 
@@ -442,7 +444,7 @@ class TestCompaction : public KuduRowSetTest {
       for (const shared_ptr<RowSetMetadata>& meta : input_meta->rowsets()) {
         shared_ptr<DiskRowSet> rs;
         CHECK_OK(DiskRowSet::Open(meta, log_anchor_registry_.get(),
-                                  mem_trackers_, &rs));
+                                  mem_trackers_, nullptr, &rs));
         rowsets.push_back(rs);
       }
 
@@ -556,14 +558,14 @@ TEST_F(TestCompaction, TestRowSetInput) {
   UpdateRows(rs.get(), 10, 0, 1);
   UpdateRows(rs.get(), 10, 0, 2);
   // Flush DMS, update some more.
-  ASSERT_OK(rs->FlushDeltas());
+  ASSERT_OK(rs->FlushDeltas(nullptr));
   UpdateRows(rs.get(), 10, 0, 3);
   UpdateRows(rs.get(), 10, 0, 4);
 
   // Check compaction input
   vector<string> out;
   gscoped_ptr<CompactionInput> input;
-  ASSERT_OK(CompactionInput::Create(*rs, &schema_, MvccSnapshot(mvcc_), &input));
+  ASSERT_OK(CompactionInput::Create(*rs, &schema_, MvccSnapshot(mvcc_), nullptr, &input));
   IterateInput(input.get(), &out);
   ASSERT_EQ(10, out.size());
   EXPECT_EQ(R"(RowIdxInBlock: 0; Base: (string key="hello 00000000", int32 val=0, )"
@@ -635,6 +637,7 @@ TEST_F(TestCompaction, TestDuplicatedGhostRowsMerging) {
   ASSERT_OK(CompactionInput::Create(*result,
                                     &schema_,
                                     MvccSnapshot::CreateSnapshotIncludingAllTransactions(),
+                                    nullptr,
                                     &input));
   vector<string> out;
   IterateInput(input.get(), &out);
@@ -795,7 +798,7 @@ TEST_F(TestCompaction, TestDuplicatedRowsRandomCompaction) {
   vector<shared_ptr<CompactionInput>> inputs;
   for (auto& row_set : row_sets) {
     gscoped_ptr<CompactionInput> ci;
-    CHECK_OK(row_set->NewCompactionInput(&schema_, all_snap, &ci));
+    CHECK_OK(row_set->NewCompactionInput(&schema_, all_snap, nullptr, &ci));
     inputs.push_back(shared_ptr<CompactionInput>(ci.release()));
   }
 
@@ -816,7 +819,7 @@ TEST_F(TestCompaction, TestDuplicatedRowsRandomCompaction) {
 
   vector<string> out;
   gscoped_ptr<CompactionInput> ci;
-  CHECK_OK(row_sets[0]->NewCompactionInput(&schema_, all_snap, &ci));
+  CHECK_OK(row_sets[0]->NewCompactionInput(&schema_, all_snap, nullptr, &ci));
   IterateInput(ci.get(), &out);
 
   // Finally go through the final compaction input and through the expected one and make sure
@@ -865,10 +868,10 @@ TEST_F(TestCompaction, TestMRSCompactionDoesntOutputUnobservableRows) {
   MvccSnapshot all_snap = MvccSnapshot::CreateSnapshotIncludingAllTransactions();
 
   gscoped_ptr<CompactionInput> rs1_input;
-  ASSERT_OK(CompactionInput::Create(*rs1, &schema_, all_snap, &rs1_input));
+  ASSERT_OK(CompactionInput::Create(*rs1, &schema_, all_snap, nullptr, &rs1_input));
 
   gscoped_ptr<CompactionInput> rs2_input;
-  ASSERT_OK(CompactionInput::Create(*rs2, &schema_, all_snap, &rs2_input));
+  ASSERT_OK(CompactionInput::Create(*rs2, &schema_, all_snap, nullptr, &rs2_input));
 
   vector<shared_ptr<CompactionInput>> to_merge;
   to_merge.push_back(shared_ptr<CompactionInput>(rs1_input.release()));
@@ -917,12 +920,12 @@ TEST_F(TestCompaction, TestOneToOne) {
 
   string dummy_name = "";
 
-  ASSERT_OK(ReupdateMissedDeltas(dummy_name, input.get(), HistoryGcOpts::Disabled(), snap, snap2,
+  ASSERT_OK(ReupdateMissedDeltas(nullptr, input.get(), HistoryGcOpts::Disabled(), snap, snap2,
                                  { rs }));
 
   // If we look at the contents of the DiskRowSet now, we should see the "re-updated" data.
   vector<string> out;
-  ASSERT_OK(CompactionInput::Create(*rs, &schema_, MvccSnapshot(mvcc_), &input));
+  ASSERT_OK(CompactionInput::Create(*rs, &schema_, MvccSnapshot(mvcc_), nullptr, &input));
   IterateInput(input.get(), &out);
   ASSERT_EQ(1000, out.size());
   EXPECT_EQ(R"(RowIdxInBlock: 0; Base: (string key="hello 00000000", int32 val=1, )"
@@ -933,7 +936,7 @@ TEST_F(TestCompaction, TestOneToOne) {
   // And compact (1 input to 1 output)
   MvccSnapshot snap3(mvcc_);
   gscoped_ptr<CompactionInput> compact_input;
-  ASSERT_OK(CompactionInput::Create(*rs, &schema_, snap3, &compact_input));
+  ASSERT_OK(CompactionInput::Create(*rs, &schema_, snap3, nullptr, &compact_input));
   DoFlushAndReopen(compact_input.get(), schema_, snap3, kLargeRollThreshold, nullptr);
 }
 
@@ -975,7 +978,7 @@ TEST_F(TestCompaction, TestKUDU102) {
   string dummy_name = "";
 
   // This would fail without KUDU-102
-  ASSERT_OK(ReupdateMissedDeltas(dummy_name, input.get(), HistoryGcOpts::Disabled(), snap, snap2,
+  ASSERT_OK(ReupdateMissedDeltas(nullptr, input.get(), HistoryGcOpts::Disabled(), snap, snap2,
                                  { rs, rs_b }));
 }
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/compaction.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/compaction.cc b/src/kudu/tablet/compaction.cc
index c754e26..fc0ade5 100644
--- a/src/kudu/tablet/compaction.cc
+++ b/src/kudu/tablet/compaction.cc
@@ -58,6 +58,7 @@
 #include "kudu/util/memory/arena.h"
 
 using kudu::clock::HybridClock;
+using kudu::fs::IOContext;
 using std::deque;
 using std::shared_ptr;
 using std::string;
@@ -852,16 +853,18 @@ string CompactionInputRowToString(const CompactionInputRow& input_row) {
 Status CompactionInput::Create(const DiskRowSet &rowset,
                                const Schema* projection,
                                const MvccSnapshot &snap,
+                               const IOContext* io_context,
                                gscoped_ptr<CompactionInput>* out) {
   CHECK(projection->has_column_ids());
 
-  shared_ptr<ColumnwiseIterator> base_cwise(rowset.base_data_->NewIterator(projection));
+  shared_ptr<ColumnwiseIterator> base_cwise(rowset.base_data_->NewIterator(projection, io_context));
   gscoped_ptr<RowwiseIterator> base_iter(new MaterializingIterator(base_cwise));
 
   // Creates a DeltaIteratorMerger that will only include the relevant REDO deltas.
   RowIteratorOptions redo_opts;
   redo_opts.projection = projection;
   redo_opts.snap_to_include = snap;
+  redo_opts.io_context = io_context;
   unique_ptr<DeltaIterator> redo_deltas;
   RETURN_NOT_OK_PREPEND(rowset.delta_tracker_->NewDeltaIterator(
       redo_opts, DeltaTracker::REDOS_ONLY, &redo_deltas), "Could not open REDOs");
@@ -870,6 +873,7 @@ Status CompactionInput::Create(const DiskRowSet &rowset,
   RowIteratorOptions undo_opts;
   undo_opts.projection = projection;
   undo_opts.snap_to_include = MvccSnapshot::CreateSnapshotIncludingNoTransactions();
+  undo_opts.io_context = io_context;
   unique_ptr<DeltaIterator> undo_deltas;
   RETURN_NOT_OK_PREPEND(rowset.delta_tracker_->NewDeltaIterator(
       undo_opts, DeltaTracker::UNDOS_ONLY, &undo_deltas), "Could not open UNDOs");
@@ -896,13 +900,14 @@ CompactionInput *CompactionInput::Merge(const vector<shared_ptr<CompactionInput>
 
 Status RowSetsInCompaction::CreateCompactionInput(const MvccSnapshot &snap,
                                                   const Schema* schema,
+                                                  const IOContext* io_context,
                                                   shared_ptr<CompactionInput> *out) const {
   CHECK(schema->has_column_ids());
 
   vector<shared_ptr<CompactionInput> > inputs;
   for (const shared_ptr<RowSet> &rs : rowsets_) {
     gscoped_ptr<CompactionInput> input;
-    RETURN_NOT_OK_PREPEND(rs->NewCompactionInput(schema, snap, &input),
+    RETURN_NOT_OK_PREPEND(rs->NewCompactionInput(schema, snap, io_context, &input),
                           Substitute("Could not create compaction input for rowset $0",
                                      rs->ToString()));
     inputs.push_back(shared_ptr<CompactionInput>(input.release()));
@@ -1183,7 +1188,7 @@ Status FlushCompactionInput(CompactionInput* input,
   return Status::OK();
 }
 
-Status ReupdateMissedDeltas(const string &tablet_name,
+Status ReupdateMissedDeltas(const IOContext* io_context,
                             CompactionInput *input,
                             const HistoryGcOpts& history_gc_opts,
                             const MvccSnapshot &snap_to_exclude,
@@ -1294,7 +1299,7 @@ Status ReupdateMissedDeltas(const string &tablet_name,
 
         rowid_t num_rows;
         DiskRowSet* cur_drs = diskrowsets.front();
-        RETURN_NOT_OK(cur_drs->CountRows(&num_rows));
+        RETURN_NOT_OK(cur_drs->CountRows(io_context, &num_rows));
 
         // The index on the input side isn't necessarily the index on the output side:
         // we may have output several small DiskRowSets, so we need to find the index
@@ -1310,7 +1315,7 @@ Status ReupdateMissedDeltas(const string &tablet_name,
           DCHECK_GE(idx_in_delta_tracker, 0);
           diskrowsets.pop_front();
           cur_drs = diskrowsets.front();
-          RETURN_NOT_OK(cur_drs->CountRows(&num_rows));
+          RETURN_NOT_OK(cur_drs->CountRows(io_context, &num_rows));
         }
 
         DeltaTracker* cur_tracker = cur_drs->delta_tracker();
@@ -1355,7 +1360,7 @@ Status ReupdateMissedDeltas(const string &tablet_name,
     TRACE_EVENT0("tablet", "Flushing missed deltas");
     for (DeltaTracker* tracker : updated_trackers) {
       VLOG(1) << "Flushing DeltaTracker updated with missed deltas...";
-      RETURN_NOT_OK_PREPEND(tracker->Flush(DeltaTracker::NO_FLUSH_METADATA),
+      RETURN_NOT_OK_PREPEND(tracker->Flush(io_context, DeltaTracker::NO_FLUSH_METADATA),
                             "Could not flush delta tracker after missed delta update");
     }
   }

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/compaction.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/compaction.h b/src/kudu/tablet/compaction.h
index ae4e7d3..e6fc30a 100644
--- a/src/kudu/tablet/compaction.h
+++ b/src/kudu/tablet/compaction.h
@@ -37,6 +37,10 @@ namespace kudu {
 class Arena;
 class Schema;
 
+namespace fs {
+struct IOContext;
+}  // namespace fs
+
 namespace tablet {
 
 class DiskRowSet;
@@ -104,6 +108,7 @@ class CompactionInput {
   static Status Create(const DiskRowSet &rowset,
                        const Schema* projection,
                        const MvccSnapshot &snap,
+                       const fs::IOContext* io_context,
                        gscoped_ptr<CompactionInput>* out);
 
   // Create an input which reads from the given memrowset, yielding base rows and updates
@@ -151,6 +156,7 @@ class RowSetsInCompaction {
   // for the lifetime of the returned CompactionInput.
   Status CreateCompactionInput(const MvccSnapshot &snap,
                                const Schema* schema,
+                               const fs::IOContext* io_context,
                                std::shared_ptr<CompactionInput> *out) const;
 
   // Dump a log message indicating the chosen rowsets.
@@ -237,7 +243,7 @@ Status FlushCompactionInput(CompactionInput *input,
 //
 // After return of this function, this CompactionInput object is "used up" and will
 // yield no further rows.
-Status ReupdateMissedDeltas(const std::string &tablet_name,
+Status ReupdateMissedDeltas(const fs::IOContext* io_context,
                             CompactionInput *input,
                             const HistoryGcOpts& history_gc_opts,
                             const MvccSnapshot &snap_to_exclude,

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/delta_compaction.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/delta_compaction.cc b/src/kudu/tablet/delta_compaction.cc
index 969cf89..d41f565 100644
--- a/src/kudu/tablet/delta_compaction.cc
+++ b/src/kudu/tablet/delta_compaction.cc
@@ -56,6 +56,7 @@ namespace kudu {
 using fs::BlockCreationTransaction;
 using fs::BlockManager;
 using fs::CreateBlockOptions;
+using fs::IOContext;
 using fs::WritableBlock;
 using std::string;
 using std::unique_ptr;
@@ -109,10 +110,11 @@ string MajorDeltaCompaction::ColumnNamesToString() const {
   return result;
 }
 
-Status MajorDeltaCompaction::FlushRowSetAndDeltas() {
+Status MajorDeltaCompaction::FlushRowSetAndDeltas(const IOContext* io_context) {
   CHECK_EQ(state_, kInitialized);
 
-  shared_ptr<ColumnwiseIterator> old_base_data_cwise(base_data_->NewIterator(&partial_schema_));
+  shared_ptr<ColumnwiseIterator> old_base_data_cwise(base_data_->NewIterator(&partial_schema_,
+                                                                             io_context));
   gscoped_ptr<RowwiseIterator> old_base_data_rwise(new MaterializingIterator(old_base_data_cwise));
 
   ScanSpec spec;
@@ -288,7 +290,7 @@ Status MajorDeltaCompaction::OpenUndoDeltaFileWriter() {
   return new_undo_delta_writer_->Start();
 }
 
-Status MajorDeltaCompaction::Compact() {
+Status MajorDeltaCompaction::Compact(const IOContext* io_context) {
   CHECK_EQ(state_, kInitialized);
 
   LOG(INFO) << "Starting major delta compaction for columns " << ColumnNamesToString();
@@ -300,7 +302,7 @@ Status MajorDeltaCompaction::Compact() {
 
   // We defer calling OpenRedoDeltaFileWriter() since we might not need to flush.
   RETURN_NOT_OK(OpenBaseDataWriter());
-  RETURN_NOT_OK(FlushRowSetAndDeltas());
+  RETURN_NOT_OK(FlushRowSetAndDeltas(io_context));
   LOG(INFO) << "Finished major delta compaction of columns " <<
       ColumnNamesToString();
   return Status::OK();
@@ -360,7 +362,8 @@ void MajorDeltaCompaction::CreateMetadataUpdate(
 // We're called under diskrowset's component_lock_ and delta_tracker's compact_flush_lock_
 // so both AtomicUpdateStores calls can be done separately and still be seen as one atomic
 // operation.
-Status MajorDeltaCompaction::UpdateDeltaTracker(DeltaTracker* tracker) {
+Status MajorDeltaCompaction::UpdateDeltaTracker(DeltaTracker* tracker,
+                                                const IOContext* io_context) {
   CHECK_EQ(state_, kFinished);
 
   // 1. Get all the necessary I/O out of the way. It's OK to fail here
@@ -376,14 +379,14 @@ Status MajorDeltaCompaction::UpdateDeltaTracker(DeltaTracker* tracker) {
     new_redo_blocks.push_back(new_redo_delta_block_);
   }
   SharedDeltaStoreVector new_redo_stores;
-  RETURN_NOT_OK(tracker->OpenDeltaReaders(new_redo_blocks, &new_redo_stores, REDO));
+  RETURN_NOT_OK(tracker->OpenDeltaReaders(new_redo_blocks, io_context, &new_redo_stores, REDO));
 
   // Create blocks for the new undo deltas.
   SharedDeltaStoreVector new_undo_stores;
   if (undo_delta_mutations_written_ > 0) {
     vector<BlockId> new_undo_blocks;
     new_undo_blocks.push_back(new_undo_delta_block_);
-    RETURN_NOT_OK(tracker->OpenDeltaReaders(new_undo_blocks, &new_undo_stores, UNDO));
+    RETURN_NOT_OK(tracker->OpenDeltaReaders(new_undo_blocks, io_context, &new_undo_stores, UNDO));
   }
 
   // 2. Only now that we cannot fail do we update the in-memory state.

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/delta_compaction.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/delta_compaction.h b/src/kudu/tablet/delta_compaction.h
index 6c99d4b..f790504 100644
--- a/src/kudu/tablet/delta_compaction.h
+++ b/src/kudu/tablet/delta_compaction.h
@@ -33,6 +33,10 @@ namespace kudu {
 
 class FsManager;
 
+namespace fs {
+struct IOContext;
+}  // namespace fs
+
 namespace tablet {
 
 class CFileSet;
@@ -65,7 +69,7 @@ class MajorDeltaCompaction {
 
   // Executes the compaction.
   // This has no effect on the metadata of the tablet, etc.
-  Status Compact();
+  Status Compact(const fs::IOContext* io_context);
 
   // After a compaction is successful, prepares a metadata update which:
   // 1) swaps out the old columns for the new ones
@@ -74,7 +78,7 @@ class MajorDeltaCompaction {
   void CreateMetadataUpdate(RowSetMetadataUpdate* update);
 
   // Apply the changes to the given delta tracker.
-  Status UpdateDeltaTracker(DeltaTracker* tracker);
+  Status UpdateDeltaTracker(DeltaTracker* tracker, const fs::IOContext* io_context);
 
  private:
   std::string ColumnNamesToString() const;
@@ -93,7 +97,7 @@ class MajorDeltaCompaction {
   // Reads the current base data, applies the deltas, and then writes the new base data.
   // A new delta file is written if not all columns were selected for compaction and some
   // deltas need to be written back into a delta file.
-  Status FlushRowSetAndDeltas();
+  Status FlushRowSetAndDeltas(const fs::IOContext* io_context);
 
   FsManager* const fs_manager_;
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/delta_store.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/delta_store.h b/src/kudu/tablet/delta_store.h
index aea8a39..d4ea390 100644
--- a/src/kudu/tablet/delta_store.h
+++ b/src/kudu/tablet/delta_store.h
@@ -37,6 +37,10 @@ class Schema;
 class SelectionVector;
 struct ColumnId;
 
+namespace fs {
+struct IOContext;
+}  // namespace fs
+
 namespace tablet {
 
 class DeltaFileWriter;
@@ -52,7 +56,7 @@ class DeltaStore {
  public:
   // Performs any post-construction work for the DeltaStore, which may
   // include additional I/O.
-  virtual Status Init() = 0;
+  virtual Status Init(const fs::IOContext* io_context) = 0;
 
   // Whether this delta store was initialized or not.
   virtual bool Initted() = 0;
@@ -72,7 +76,8 @@ class DeltaStore {
                                   DeltaIterator** iterator) const = 0;
 
   // Set *deleted to true if the latest update for the given row is a deletion.
-  virtual Status CheckRowDeleted(rowid_t row_idx, bool *deleted) const = 0;
+  virtual Status CheckRowDeleted(rowid_t row_idx, const fs::IOContext* io_context,
+                                 bool *deleted) const = 0;
 
   // Get the store's estimated size in bytes.
   virtual uint64_t EstimateSize() const = 0;

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/delta_tracker.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/delta_tracker.cc b/src/kudu/tablet/delta_tracker.cc
index 0ab956f..0e41203 100644
--- a/src/kudu/tablet/delta_tracker.cc
+++ b/src/kudu/tablet/delta_tracker.cc
@@ -62,6 +62,7 @@ namespace tablet {
 
 using cfile::ReaderOptions;
 using fs::CreateBlockOptions;
+using fs::IOContext;
 using fs::ReadableBlock;
 using fs::WritableBlock;
 using log::LogAnchorRegistry;
@@ -75,11 +76,12 @@ using strings::Substitute;
 Status DeltaTracker::Open(const shared_ptr<RowSetMetadata>& rowset_metadata,
                           LogAnchorRegistry* log_anchor_registry,
                           const TabletMemTrackers& mem_trackers,
+                          const IOContext* io_context,
                           gscoped_ptr<DeltaTracker>* delta_tracker) {
   gscoped_ptr<DeltaTracker> local_dt(
       new DeltaTracker(rowset_metadata, log_anchor_registry,
                        mem_trackers));
-  RETURN_NOT_OK(local_dt->DoOpen());
+  RETURN_NOT_OK(local_dt->DoOpen(io_context));
 
   delta_tracker->swap(local_dt);
   return Status::OK();
@@ -96,6 +98,7 @@ DeltaTracker::DeltaTracker(shared_ptr<RowSetMetadata> rowset_metadata,
       dms_empty_(true) {}
 
 Status DeltaTracker::OpenDeltaReaders(const vector<BlockId>& blocks,
+                                      const IOContext* io_context,
                                       vector<shared_ptr<DeltaStore> >* stores,
                                       DeltaType type) {
   FsManager* fs = rowset_metadata_->fs_manager();
@@ -112,6 +115,7 @@ Status DeltaTracker::OpenDeltaReaders(const vector<BlockId>& blocks,
     shared_ptr<DeltaFileReader> dfr;
     ReaderOptions options;
     options.parent_mem_tracker = mem_trackers_.tablet_tracker;
+    options.io_context = io_context;
     s = DeltaFileReader::OpenNoInit(std::move(block),
                                     type,
                                     std::move(options),
@@ -132,15 +136,17 @@ Status DeltaTracker::OpenDeltaReaders(const vector<BlockId>& blocks,
 
 
 // Open any previously flushed DeltaFiles in this rowset
-Status DeltaTracker::DoOpen() {
+Status DeltaTracker::DoOpen(const IOContext* io_context) {
   CHECK(redo_delta_stores_.empty()) << "should call before opening any readers";
   CHECK(undo_delta_stores_.empty()) << "should call before opening any readers";
   CHECK(!open_);
 
   RETURN_NOT_OK(OpenDeltaReaders(rowset_metadata_->redo_delta_blocks(),
+                                 io_context,
                                  &redo_delta_stores_,
                                  REDO));
   RETURN_NOT_OK(OpenDeltaReaders(rowset_metadata_->undo_delta_blocks(),
+                                 io_context,
                                  &undo_delta_stores_,
                                  UNDO));
 
@@ -150,13 +156,14 @@ Status DeltaTracker::DoOpen() {
                                       log_anchor_registry_,
                                       mem_trackers_.dms_tracker,
                                       &dms_));
-  RETURN_NOT_OK(dms_->Init());
+  RETURN_NOT_OK(dms_->Init(io_context));
 
   open_ = true;
   return Status::OK();
 }
 
-Status DeltaTracker::MakeDeltaIteratorMergerUnlocked(size_t start_idx, size_t end_idx,
+Status DeltaTracker::MakeDeltaIteratorMergerUnlocked(const IOContext* io_context,
+                                                     size_t start_idx, size_t end_idx,
                                                      const Schema* projection,
                                                      vector<shared_ptr<DeltaStore> > *target_stores,
                                                      vector<BlockId> *target_blocks,
@@ -181,6 +188,7 @@ Status DeltaTracker::MakeDeltaIteratorMergerUnlocked(size_t start_idx, size_t en
   }
   RowIteratorOptions opts;
   opts.projection = projection;
+  opts.io_context = io_context;
   RETURN_NOT_OK(DeltaIteratorMerger::Create(inputs, opts, out));
   return Status::OK();
 }
@@ -209,14 +217,14 @@ Status DeltaTracker::ValidateDeltaOrder(const std::shared_ptr<DeltaStore>& first
     shared_ptr<DeltaFileReader> first_clone;
     RETURN_NOT_OK(down_cast<DeltaFileReader*>(first.get())->CloneForDebugging(
         rowset_metadata_->fs_manager(), mem_trackers_.tablet_tracker, &first_clone));
-    RETURN_NOT_OK(first_clone->Init());
+    RETURN_NOT_OK(first_clone->Init(nullptr));
     first_copy = first_clone;
   }
   if (!second_copy->Initted()) {
     shared_ptr<DeltaFileReader> second_clone;
     RETURN_NOT_OK(down_cast<DeltaFileReader*>(second.get())->CloneForDebugging(
         rowset_metadata_->fs_manager(), mem_trackers_.tablet_tracker, &second_clone));
-    RETURN_NOT_OK(second_clone->Init());
+    RETURN_NOT_OK(second_clone->Init(nullptr));
     second_copy = second_clone;
   }
 
@@ -309,13 +317,14 @@ void DeltaTracker::AtomicUpdateStores(const SharedDeltaStoreVector& stores_to_re
                       << JoinDeltaStoreStrings(*stores_to_update);
 }
 
-Status DeltaTracker::Compact() {
-  return CompactStores(0, -1);
+Status DeltaTracker::Compact(const IOContext* io_context) {
+  return CompactStores(io_context, 0, -1);
 }
 
 Status DeltaTracker::CommitDeltaStoreMetadataUpdate(const RowSetMetadataUpdate& update,
                                                     const SharedDeltaStoreVector& to_remove,
                                                     const vector<BlockId>& new_delta_blocks,
+                                                    const IOContext* io_context,
                                                     DeltaType type,
                                                     MetadataFlushType flush_type) {
   compact_flush_lock_.AssertAcquired();
@@ -326,7 +335,8 @@ Status DeltaTracker::CommitDeltaStoreMetadataUpdate(const RowSetMetadataUpdate&
   DCHECK(!to_remove.empty());
 
   SharedDeltaStoreVector new_stores;
-  RETURN_NOT_OK_PREPEND(OpenDeltaReaders(new_delta_blocks, &new_stores, type),
+  RETURN_NOT_OK_PREPEND(OpenDeltaReaders(new_delta_blocks, io_context,
+                                         &new_stores, type),
                         "Unable to open delta blocks");
 
   vector<BlockId> removed_blocks;
@@ -356,7 +366,7 @@ Status DeltaTracker::CheckWritableUnlocked() const {
   return Status::OK();
 }
 
-Status DeltaTracker::CompactStores(int start_idx, int end_idx) {
+Status DeltaTracker::CompactStores(const IOContext* io_context, int start_idx, int end_idx) {
   // Prevent concurrent compactions or a compaction concurrent with a flush
   //
   // TODO(perf): this could be more fine grained
@@ -388,7 +398,7 @@ Status DeltaTracker::CompactStores(int start_idx, int end_idx) {
   // Merge and compact the stores.
   vector<shared_ptr<DeltaStore> > compacted_stores;
   vector<BlockId> compacted_blocks;
-  RETURN_NOT_OK(DoCompactStores(start_idx, end_idx, std::move(block),
+  RETURN_NOT_OK(DoCompactStores(io_context, start_idx, end_idx, std::move(block),
                                 &compacted_stores, &compacted_blocks));
 
   vector<BlockId> new_blocks = { new_block_id };
@@ -397,8 +407,8 @@ Status DeltaTracker::CompactStores(int start_idx, int end_idx) {
 
   LOG_WITH_PREFIX(INFO) << "Flushing compaction of redo delta blocks { " << compacted_blocks
                         << " } into block " << new_block_id;
-  RETURN_NOT_OK_PREPEND(CommitDeltaStoreMetadataUpdate(update, compacted_stores, new_blocks, REDO,
-                                                       FLUSH_METADATA),
+  RETURN_NOT_OK_PREPEND(CommitDeltaStoreMetadataUpdate(update, compacted_stores, new_blocks,
+                                                       io_context, REDO, FLUSH_METADATA),
                         "DeltaTracker: CompactStores: Unable to commit delta update");
   return Status::OK();
 }
@@ -426,6 +436,7 @@ Status DeltaTracker::EstimateBytesInPotentiallyAncientUndoDeltas(Timestamp ancie
 
 Status DeltaTracker::InitUndoDeltas(Timestamp ancient_history_mark,
                                     MonoTime deadline,
+                                    const IOContext* io_context,
                                     int64_t* delta_blocks_initialized,
                                     int64_t* bytes_in_ancient_undos) {
   SharedDeltaStoreVector undos_newest_first;
@@ -438,7 +449,7 @@ Status DeltaTracker::InitUndoDeltas(Timestamp ancient_history_mark,
     if (deadline.Initialized() && MonoTime::Now() >= deadline) break;
 
     if (!undo->Initted()) {
-      RETURN_NOT_OK(undo->Init());
+      RETURN_NOT_OK(undo->Init(io_context));
       tmp_blocks_initialized++;
     }
 
@@ -458,6 +469,7 @@ Status DeltaTracker::InitUndoDeltas(Timestamp ancient_history_mark,
 }
 
 Status DeltaTracker::DeleteAncientUndoDeltas(Timestamp ancient_history_mark,
+                                             const IOContext* io_context,
                                              int64_t* blocks_deleted, int64_t* bytes_deleted) {
   DCHECK_NE(Timestamp::kInvalidTimestamp, ancient_history_mark);
 
@@ -503,7 +515,7 @@ Status DeltaTracker::DeleteAncientUndoDeltas(Timestamp ancient_history_mark,
     RowSetMetadataUpdate update;
     update.RemoveUndoDeltaBlocks(block_ids_to_remove);
     // We do not flush the tablet metadata - that is the caller's responsibility.
-    RETURN_NOT_OK(CommitDeltaStoreMetadataUpdate(update, undos_to_remove, {}, UNDO,
+    RETURN_NOT_OK(CommitDeltaStoreMetadataUpdate(update, undos_to_remove, {}, io_context, UNDO,
                                                  NO_FLUSH_METADATA));
   }
 
@@ -512,10 +524,11 @@ Status DeltaTracker::DeleteAncientUndoDeltas(Timestamp ancient_history_mark,
   return Status::OK();
 }
 
-Status DeltaTracker::DoCompactStores(size_t start_idx, size_t end_idx,
-         unique_ptr<WritableBlock> block,
-         vector<shared_ptr<DeltaStore> > *compacted_stores,
-         vector<BlockId> *compacted_blocks) {
+Status DeltaTracker::DoCompactStores(const IOContext* io_context,
+                                     size_t start_idx, size_t end_idx,
+                                     unique_ptr<WritableBlock> block,
+                                     vector<shared_ptr<DeltaStore> > *compacted_stores,
+                                     vector<BlockId> *compacted_blocks) {
   unique_ptr<DeltaIterator> inputs_merge;
 
   // Currently, DeltaFile iterators ignore the passed-in projection in
@@ -523,7 +536,8 @@ Status DeltaTracker::DoCompactStores(size_t start_idx, size_t end_idx,
   // If this changes in the future, we'll have to pass in the current tablet
   // schema here.
   Schema empty_schema;
-  RETURN_NOT_OK(MakeDeltaIteratorMergerUnlocked(start_idx, end_idx, &empty_schema, compacted_stores,
+  RETURN_NOT_OK(MakeDeltaIteratorMergerUnlocked(io_context, start_idx, end_idx,
+                                                &empty_schema, compacted_stores,
                                                 compacted_blocks, &inputs_merge));
   LOG_WITH_PREFIX(INFO) << "Compacting " << (end_idx - start_idx + 1) << " delta files.";
   DeltaFileWriter dfw(std::move(block));
@@ -614,14 +628,14 @@ Status DeltaTracker::Update(Timestamp timestamp,
   return s;
 }
 
-Status DeltaTracker::CheckRowDeleted(rowid_t row_idx, bool *deleted,
-                                     ProbeStats* stats) const {
+Status DeltaTracker::CheckRowDeleted(rowid_t row_idx, const IOContext* io_context,
+                                     bool *deleted, ProbeStats* stats) const {
   shared_lock<rw_spinlock> lock(component_lock_);
 
 
   *deleted = false;
   // Check if the row has a deletion in DeltaMemStore.
-  RETURN_NOT_OK(dms_->CheckRowDeleted(row_idx, deleted));
+  RETURN_NOT_OK(dms_->CheckRowDeleted(row_idx, io_context, deleted));
   if (*deleted) {
     return Status::OK();
   }
@@ -629,7 +643,7 @@ Status DeltaTracker::CheckRowDeleted(rowid_t row_idx, bool *deleted,
   // Then check backwards through the list of trackers.
   for (auto ds = redo_delta_stores_.crbegin(); ds != redo_delta_stores_.crend(); ds++) {
     stats->deltas_consulted++;
-    RETURN_NOT_OK((*ds)->CheckRowDeleted(row_idx, deleted));
+    RETURN_NOT_OK((*ds)->CheckRowDeleted(row_idx, io_context, deleted));
     if (*deleted) {
       return Status::OK();
     }
@@ -639,6 +653,7 @@ Status DeltaTracker::CheckRowDeleted(rowid_t row_idx, bool *deleted,
 }
 
 Status DeltaTracker::FlushDMS(DeltaMemStore* dms,
+                              const IOContext* io_context,
                               shared_ptr<DeltaFileReader>* dfr,
                               MetadataFlushType flush_type) {
   // Open file for write.
@@ -666,6 +681,7 @@ Status DeltaTracker::FlushDMS(DeltaMemStore* dms,
   RETURN_NOT_OK(fs->OpenBlock(block_id, &readable_block));
   ReaderOptions options;
   options.parent_mem_tracker = mem_trackers_.tablet_tracker;
+  options.io_context = io_context;
   RETURN_NOT_OK(DeltaFileReader::OpenNoInit(std::move(readable_block),
                                             REDO,
                                             std::move(options),
@@ -681,7 +697,7 @@ Status DeltaTracker::FlushDMS(DeltaMemStore* dms,
   return Status::OK();
 }
 
-Status DeltaTracker::Flush(MetadataFlushType flush_type) {
+Status DeltaTracker::Flush(const IOContext* io_context, MetadataFlushType flush_type) {
   std::lock_guard<Mutex> l(compact_flush_lock_);
   RETURN_NOT_OK(CheckWritableUnlocked());
 
@@ -704,7 +720,7 @@ Status DeltaTracker::Flush(MetadataFlushType flush_type) {
                                         log_anchor_registry_,
                                         mem_trackers_.dms_tracker,
                                         &dms_));
-    RETURN_NOT_OK(dms_->Init());
+    RETURN_NOT_OK(dms_->Init(nullptr));
     dms_empty_.Store(true);
 
     if (count == 0) {
@@ -724,7 +740,7 @@ Status DeltaTracker::Flush(MetadataFlushType flush_type) {
   // TODO(todd): need another lock to prevent concurrent flushers
   // at some point.
   shared_ptr<DeltaFileReader> dfr;
-  Status s = FlushDMS(old_dms.get(), &dfr, flush_type);
+  Status s = FlushDMS(old_dms.get(), io_context, &dfr, flush_type);
   if (PREDICT_FALSE(!s.ok())) {
     // A failure here leaves a DeltaMemStore permanently in the store list.
     // This isn't allowed, and rolling back the store is difficult, so we leave
@@ -805,12 +821,12 @@ Status DeltaTracker::InitAllDeltaStoresForTests(WhichStores stores) {
   shared_lock<rw_spinlock> lock(component_lock_);
   if (stores == UNDOS_AND_REDOS || stores == UNDOS_ONLY) {
     for (const shared_ptr<DeltaStore>& ds : undo_delta_stores_) {
-      RETURN_NOT_OK(ds->Init());
+      RETURN_NOT_OK(ds->Init(nullptr));
     }
   }
   if (stores == UNDOS_AND_REDOS || stores == REDOS_ONLY) {
     for (const shared_ptr<DeltaStore>& ds : redo_delta_stores_) {
-      RETURN_NOT_OK(ds->Init());
+      RETURN_NOT_OK(ds->Init(nullptr));
     }
   }
   return Status::OK();

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/delta_tracker.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/delta_tracker.h b/src/kudu/tablet/delta_tracker.h
index ed32c4b..7a1e76e 100644
--- a/src/kudu/tablet/delta_tracker.h
+++ b/src/kudu/tablet/delta_tracker.h
@@ -52,6 +52,7 @@ class OpId;
 }
 
 namespace fs {
+struct IOContext;
 class WritableBlock;
 }
 
@@ -85,6 +86,7 @@ class DeltaTracker {
   static Status Open(const std::shared_ptr<RowSetMetadata>& rowset_metadata,
                      log::LogAnchorRegistry* log_anchor_registry,
                      const TabletMemTrackers& mem_trackers,
+                     const fs::IOContext* io_context,
                      gscoped_ptr<DeltaTracker>* delta_tracker);
 
   Status WrapIterator(const std::shared_ptr<CFileSet::Iterator> &base,
@@ -129,9 +131,8 @@ class DeltaTracker {
   // the TabletMetadata) flushed.
   //
   // NOTE: 'flush_type' should almost always be set to 'FLUSH_METADATA', or else
-  // delta stores might become unrecoverable. TODO: see KUDU-204 to clean this up
-  // a bit.
-  Status Flush(MetadataFlushType flush_type);
+  // delta stores might become unrecoverable.
+  Status Flush(const fs::IOContext* io_context, MetadataFlushType flush_type);
 
   // Update the given row in the database.
   // Copies the data, as well as any referenced values into a local arena.
@@ -147,14 +148,11 @@ class DeltaTracker {
   // delta for this row is a deletion.
   //
   // Sets *deleted to true if so; otherwise sets it to false.
-  Status CheckRowDeleted(rowid_t row_idx, bool *deleted, ProbeStats* stats) const;
+  Status CheckRowDeleted(rowid_t row_idx, const fs::IOContext* io_context,
+                         bool *deleted, ProbeStats* stats) const;
 
   // Compacts all REDO delta files.
-  //
-  // TODO keep metadata in the delta stores to indicate whether or not
-  // a minor (or -- when implemented -- major) compaction is warranted
-  // and if so, compact the stores.
-  Status Compact();
+  Status Compact(const fs::IOContext* io_context);
 
   // Updates the in-memory list of delta stores and then persists the updated
   // metadata. This should only be used for compactions or ancient history
@@ -165,6 +163,7 @@ class DeltaTracker {
   Status CommitDeltaStoreMetadataUpdate(const RowSetMetadataUpdate& update,
                                         const SharedDeltaStoreVector& to_remove,
                                         const std::vector<BlockId>& new_delta_blocks,
+                                        const fs::IOContext* io_context,
                                         DeltaType type,
                                         MetadataFlushType flush_type);
 
@@ -172,7 +171,7 @@ class DeltaTracker {
   // "start_idx" and "end_idx" (inclusive) and writes this to a
   // new REDO delta block. If "end_idx" is set to -1, then delta files at
   // all indexes starting with "start_idx" will be compacted.
-  Status CompactStores(int start_idx, int end_idx);
+  Status CompactStores(const fs::IOContext* io_context, int start_idx, int end_idx);
 
   // See RowSet::EstimateBytesInPotentiallyAncientUndoDeltas().
   Status EstimateBytesInPotentiallyAncientUndoDeltas(Timestamp ancient_history_mark,
@@ -181,17 +180,19 @@ class DeltaTracker {
   // See RowSet::InitUndoDeltas().
   Status InitUndoDeltas(Timestamp ancient_history_mark,
                         MonoTime deadline,
+                        const fs::IOContext* io_context,
                         int64_t* delta_blocks_initialized,
                         int64_t* bytes_in_ancient_undos);
 
   // See RowSet::DeleteAncientUndoDeltas().
-  Status DeleteAncientUndoDeltas(Timestamp ancient_history_mark,
+  Status DeleteAncientUndoDeltas(Timestamp ancient_history_mark, const fs::IOContext* io_context,
                                  int64_t* blocks_deleted, int64_t* bytes_deleted);
 
   // Opens the input 'blocks' of type 'type' and returns the opened delta file
   // readers in 'stores'.
   Status OpenDeltaReaders(const std::vector<BlockId>& blocks,
-                          std::vector<std::shared_ptr<DeltaStore> >* stores,
+                          const fs::IOContext* io_context,
+                          std::vector<std::shared_ptr<DeltaStore>>* stores,
                           DeltaType type);
 
   // Validates that 'first' may precede 'second' in an ordered list of deltas,
@@ -268,9 +269,10 @@ class DeltaTracker {
                log::LogAnchorRegistry* log_anchor_registry,
                TabletMemTrackers mem_trackers);
 
-  Status DoOpen();
+  Status DoOpen(const fs::IOContext* io_context);
 
   Status FlushDMS(DeltaMemStore* dms,
+                  const fs::IOContext* io_context,
                   std::shared_ptr<DeltaFileReader>* dfr,
                   MetadataFlushType flush_type);
 
@@ -285,7 +287,8 @@ class DeltaTracker {
   // NOTE: the caller of this method should acquire or already hold an
   // exclusive lock on 'compact_flush_lock_' before calling this
   // method in order to protect 'redo_delta_stores_'.
-  Status DoCompactStores(size_t start_idx, size_t end_idx,
+  Status DoCompactStores(const fs::IOContext* io_context,
+                         size_t start_idx, size_t end_idx,
                          std::unique_ptr<fs::WritableBlock> block,
                          std::vector<std::shared_ptr<DeltaStore>>* compacted_stores,
                          std::vector<BlockId>* compacted_blocks);
@@ -299,11 +302,11 @@ class DeltaTracker {
   // NOTE: the caller of this method must first acquire or already
   // hold a lock on 'compact_flush_lock_'in order to guard against a
   // race on 'redo_delta_stores_'.
-  Status MakeDeltaIteratorMergerUnlocked(size_t start_idx, size_t end_idx,
-                                         const Schema* schema,
-                                         std::vector<std::shared_ptr<DeltaStore > > *target_stores,
-                                         std::vector<BlockId> *target_blocks,
-                                         std::unique_ptr<DeltaIterator> *out);
+  Status MakeDeltaIteratorMergerUnlocked(const fs::IOContext* io_context,
+                                         size_t start_idx, size_t end_idx, const Schema* projection,
+                                         std::vector<std::shared_ptr<DeltaStore>>* target_stores,
+                                         std::vector<BlockId>* target_blocks,
+                                         std::unique_ptr<DeltaIterator>* out);
 
   std::string LogPrefix() const;
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/deltafile-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/deltafile-test.cc b/src/kudu/tablet/deltafile-test.cc
index 19d08f0..0096e28 100644
--- a/src/kudu/tablet/deltafile-test.cc
+++ b/src/kudu/tablet/deltafile-test.cc
@@ -380,10 +380,10 @@ TEST_F(TestDeltaFile, TestLazyInit) {
   ASSERT_EQ(0, bytes_read);
 
   // But initializing it should (only the first time).
-  ASSERT_OK(reader->Init());
+  ASSERT_OK(reader->Init(nullptr));
   ASSERT_GT(bytes_read, 0);
   size_t bytes_read_after_init = bytes_read;
-  ASSERT_OK(reader->Init());
+  ASSERT_OK(reader->Init(nullptr));
   ASSERT_EQ(bytes_read_after_init, bytes_read);
 
   // And let's test non-lazy open for good measure; it should yield the

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/deltafile.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/deltafile.cc b/src/kudu/tablet/deltafile.cc
index 805483c..c52e65c 100644
--- a/src/kudu/tablet/deltafile.cc
+++ b/src/kudu/tablet/deltafile.cc
@@ -82,6 +82,7 @@ using cfile::IndexTreeIterator;
 using cfile::ReaderOptions;
 using fs::BlockCreationTransaction;
 using fs::BlockManager;
+using fs::IOContext;
 using fs::ReadableBlock;
 using fs::WritableBlock;
 
@@ -220,11 +221,12 @@ Status DeltaFileReader::Open(unique_ptr<ReadableBlock> block,
                              ReaderOptions options,
                              shared_ptr<DeltaFileReader>* reader_out) {
   shared_ptr<DeltaFileReader> df_reader;
+  const IOContext* io_context = options.io_context;
   RETURN_NOT_OK(DeltaFileReader::OpenNoInit(std::move(block),
                                             delta_type,
                                             std::move(options),
                                             &df_reader));
-  RETURN_NOT_OK(df_reader->Init());
+  RETURN_NOT_OK(df_reader->Init(io_context));
 
   *reader_out = df_reader;
   return Status::OK();
@@ -235,13 +237,14 @@ Status DeltaFileReader::OpenNoInit(unique_ptr<ReadableBlock> block,
                                    ReaderOptions options,
                                    shared_ptr<DeltaFileReader>* reader_out) {
   unique_ptr<CFileReader> cf_reader;
+  const IOContext* io_context = options.io_context;
   RETURN_NOT_OK(CFileReader::OpenNoInit(std::move(block),
                                         std::move(options),
                                         &cf_reader));
   gscoped_ptr<DeltaFileReader> df_reader(
       new DeltaFileReader(std::move(cf_reader), delta_type));
   if (!FLAGS_cfile_lazy_open) {
-    RETURN_NOT_OK(df_reader->Init());
+    RETURN_NOT_OK(df_reader->Init(io_context));
   }
 
   reader_out->reset(df_reader.release());
@@ -254,15 +257,15 @@ DeltaFileReader::DeltaFileReader(unique_ptr<CFileReader> cf_reader,
     : reader_(cf_reader.release()),
       delta_type_(delta_type) {}
 
-Status DeltaFileReader::Init() {
-  return init_once_.Init([this] { return InitOnce(); });
+Status DeltaFileReader::Init(const IOContext* io_context) {
+  return init_once_.Init([this, io_context] { return InitOnce(io_context); });
 }
 
-Status DeltaFileReader::InitOnce() {
+Status DeltaFileReader::InitOnce(const IOContext* io_context) {
   // Fully open the CFileReader if it was lazily opened earlier.
   //
   // If it's already initialized, this is a no-op.
-  RETURN_NOT_OK(reader_->Init());
+  RETURN_NOT_OK(reader_->Init(io_context));
 
   if (!reader_->has_validx()) {
     return Status::Corruption("file does not have a value index!");
@@ -349,9 +352,9 @@ Status DeltaFileReader::NewDeltaIterator(const RowIteratorOptions& opts,
   return Status::NotFound("MvccSnapshot outside the range of this delta.");
 }
 
-Status DeltaFileReader::CheckRowDeleted(rowid_t row_idx, bool *deleted) const {
-  RETURN_NOT_OK(const_cast<DeltaFileReader*>(this)->Init());
-
+Status DeltaFileReader::CheckRowDeleted(rowid_t row_idx, const IOContext* io_context,
+                                        bool* deleted) const {
+  RETURN_NOT_OK(const_cast<DeltaFileReader*>(this)->Init(io_context));
   // If there are no deletes in the delta file at all, we can short-circuit
   // the seek.
   if (delta_stats_->delete_count() == 0) {
@@ -365,6 +368,7 @@ Status DeltaFileReader::CheckRowDeleted(rowid_t row_idx, bool *deleted) const {
   Schema empty_schema;
   RowIteratorOptions opts;
   opts.projection = &empty_schema;
+  opts.io_context = io_context;
   DeltaIterator* raw_iter;
   Status s = NewDeltaIterator(opts, &raw_iter);
   if (s.IsNotFound()) {
@@ -427,7 +431,7 @@ Status DeltaFileIterator::SeekToOrdinal(rowid_t idx) {
   DCHECK(initted_) << "Must call Init()";
 
   // Finish the initialization of any lazily-initialized state.
-  RETURN_NOT_OK(dfr_->Init());
+  RETURN_NOT_OK(dfr_->Init(opts_.io_context));
 
   // Check again whether this delta file is relevant given the snapshot
   // that we are querying. We did this already before creating the

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/deltafile.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/deltafile.h b/src/kudu/tablet/deltafile.h
index a7203c3..811db5b 100644
--- a/src/kudu/tablet/deltafile.h
+++ b/src/kudu/tablet/deltafile.h
@@ -70,6 +70,7 @@ namespace fs {
 class BlockCreationTransaction;
 class ReadableBlock;
 class WritableBlock;
+struct IOContext;
 } // namespace fs
 
 namespace tablet {
@@ -158,7 +159,7 @@ class DeltaFileReader : public DeltaStore,
                            cfile::ReaderOptions options,
                            std::shared_ptr<DeltaFileReader>* reader_out);
 
-  virtual Status Init() OVERRIDE;
+  virtual Status Init(const fs::IOContext* io_context) OVERRIDE;
 
   virtual bool Initted() OVERRIDE {
     return init_once_.init_succeeded();
@@ -169,7 +170,9 @@ class DeltaFileReader : public DeltaStore,
                           DeltaIterator** iterator) const OVERRIDE;
 
   // See DeltaStore::CheckRowDeleted
-  virtual Status CheckRowDeleted(rowid_t row_idx, bool *deleted) const OVERRIDE;
+  virtual Status CheckRowDeleted(rowid_t row_idx,
+                                 const fs::IOContext* io_context,
+                                 bool *deleted) const OVERRIDE;
 
   virtual uint64_t EstimateSize() const OVERRIDE;
 
@@ -209,7 +212,7 @@ class DeltaFileReader : public DeltaStore,
                   DeltaType delta_type);
 
   // Callback used in 'init_once_' to initialize this delta file.
-  Status InitOnce();
+  Status InitOnce(const fs::IOContext* io_context);
 
   Status ReadDeltaStats();
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/deltamemstore-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/deltamemstore-test.cc b/src/kudu/tablet/deltamemstore-test.cc
index 0c3930c..ae7e1c3 100644
--- a/src/kudu/tablet/deltamemstore-test.cc
+++ b/src/kudu/tablet/deltamemstore-test.cc
@@ -87,7 +87,7 @@ class TestDeltaMemStore : public KuduTest {
     CHECK_OK(DeltaMemStore::Create(0, 0,
                                    new log::LogAnchorRegistry(),
                                    MemTracker::GetRootTracker(), &dms_));
-    CHECK_OK(dms_->Init());
+    CHECK_OK(dms_->Init(nullptr));
   }
 
   void SetUp() OVERRIDE {

http://git-wip-us.apache.org/repos/asf/kudu/blob/2974f5a5/src/kudu/tablet/deltamemstore.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/deltamemstore.cc b/src/kudu/tablet/deltamemstore.cc
index ec07372..842a538 100644
--- a/src/kudu/tablet/deltamemstore.cc
+++ b/src/kudu/tablet/deltamemstore.cc
@@ -45,6 +45,7 @@
 namespace kudu {
 namespace tablet {
 
+using fs::IOContext;
 using log::LogAnchorRegistry;
 using std::string;
 using std::shared_ptr;
@@ -85,7 +86,7 @@ DeltaMemStore::DeltaMemStore(int64_t id,
     disambiguator_sequence_number_(0) {
 }
 
-Status DeltaMemStore::Init() {
+Status DeltaMemStore::Init(const IOContext* /*io_context*/) {
   return Status::OK();
 }
 
@@ -151,7 +152,9 @@ Status DeltaMemStore::NewDeltaIterator(const RowIteratorOptions& opts,
   return Status::OK();
 }
 
-Status DeltaMemStore::CheckRowDeleted(rowid_t row_idx, bool *deleted) const {
+Status DeltaMemStore::CheckRowDeleted(rowid_t row_idx,
+                                      const IOContext* /*io_context*/,
+                                      bool *deleted) const {
   *deleted = false;
 
   DeltaKey key(row_idx, Timestamp(0));