You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by ad...@apache.org on 2019/12/09 04:16:00 UTC

[kudu] branch master updated (9639f03 -> 6b69108)

This is an automated email from the ASF dual-hosted git repository.

adar pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git.


    from 9639f03  Update IWYU fix_includes.py
     new 5b9289a  [build-support] fix on enable_devtoolset_inner.sh, take two
     new e5ab399  fs: mark 'filesystem_block_size_bytes' optional
     new b5e07be  fs: rename PathInstance-related things
     new 7f0a4a2  KUDU-1938 Add VARCHAR to tooling and helpers pt 7
     new 6b69108  KUDU-3001 Multi-thread to load containers in a data directory

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 build-support/enable_devtoolset_inner.sh           |   2 +-
 src/kudu/common/row.h                              |  10 +
 src/kudu/fs/CMakeLists.txt                         |   4 +-
 src/kudu/fs/block_manager-test.cc                  |   2 +-
 src/kudu/fs/data_dirs.cc                           |  67 +--
 src/kudu/fs/data_dirs.h                            |  24 +-
 ...block_manager_util-test.cc => dir_util-test.cc} |  37 +-
 src/kudu/fs/{block_manager_util.cc => dir_util.cc} |  42 +-
 src/kudu/fs/{block_manager_util.h => dir_util.h}   |  20 +-
 src/kudu/fs/error_manager.h                        |   2 +-
 src/kudu/fs/file_block_manager.cc                  |   4 +-
 src/kudu/fs/fs.proto                               |  39 +-
 src/kudu/fs/fs_manager-test.cc                     |   8 +-
 src/kudu/fs/log_block_manager-test.cc              |  10 +-
 src/kudu/fs/log_block_manager.cc                   | 524 ++++++++++++---------
 src/kudu/fs/log_block_manager.h                    |  17 +-
 src/kudu/tools/tool_action_perf.cc                 |   8 +-
 src/kudu/tools/tool_action_table.cc                |  17 +-
 18 files changed, 474 insertions(+), 363 deletions(-)
 rename src/kudu/fs/{block_manager_util-test.cc => dir_util-test.cc} (71%)
 rename src/kudu/fs/{block_manager_util.cc => dir_util.cc} (89%)
 rename src/kudu/fs/{block_manager_util.h => dir_util.h} (88%)


[kudu] 02/05: fs: mark 'filesystem_block_size_bytes' optional

Posted by ad...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

adar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit e5ab399e0f2545214d9fdc6f6c04a67540a9aadc
Author: Andrew Wong <aw...@apache.org>
AuthorDate: Thu Dec 5 00:28:14 2019 -0800

    fs: mark 'filesystem_block_size_bytes' optional
    
    While the field is useful when dealing with data directories, if we want
    to reuse the path instance files for WAL directories, the field won't
    always be necessary. As such, this marks it 'optional' instead of
    'required'.
    
    Is this safe? While not strictly backwards compatible as far as protobuf
    goes, I'm assuming that the DataDirManager will continue to use the now
    optional field. Taken in that context, the switch to optional shouldn't
    pose backwards compatibility issues for older clusters. While I can't
    guarantee that, I've at least added a comment indicating the appropriate
    usage of the field.
    
    Change-Id: I5378391a94e5faa54a11a277d9191d151e0225d5
    Reviewed-on: http://gerrit.cloudera.org:8080/14856
    Tested-by: Kudu Jenkins
    Reviewed-by: Adar Dembo <ad...@cloudera.com>
---
 src/kudu/fs/fs.proto | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/kudu/fs/fs.proto b/src/kudu/fs/fs.proto
index 241187e..3292240 100644
--- a/src/kudu/fs/fs.proto
+++ b/src/kudu/fs/fs.proto
@@ -68,7 +68,8 @@ message PathInstanceMetadataPB {
   // Block size on the filesystem where this instance was created. If the
   // instance (and its data) are ever copied to another location, the block
   // size in that location must be the same.
-  required uint64 filesystem_block_size_bytes = 3;
+  // This must be present if this instance belongs to a data directory.
+  optional uint64 filesystem_block_size_bytes = 3;
 }
 
 message BlockIdPB {


[kudu] 03/05: fs: rename PathInstance-related things

Posted by ad...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

adar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit b5e07be0598d5836ddff05996a4b1274cd8184ec
Author: Andrew Wong <aw...@apache.org>
AuthorDate: Thu Dec 5 00:28:14 2019 -0800

    fs: rename PathInstance-related things
    
    I'm expecting the directory management code to be reused for WAL
    directories, and I've sometimes found it mildly annoying that we have
    different nomenclature for path instances, directories, and block
    managers in the same area (mostly in the PathInstances). So thought I'd
    rename some things now to make some things more straight-forward:
    
    * PathInstanceMetadataFile -> DirInstanceMetadataFile
    * PathInstanceMetadataPB -> DirInstanceMetadataPB
    * PathSetPB -> DirSetPB
    * block_manager_type -> dir_type (in the context of instance files only)
    * block_manager_util -> dir_util
    
    Along the way, I modernized our usage of the DataDir threadpool when
    calling DataDirManager::Open().
    
    Change-Id: I89049fafe149d535d584e7d4cd2497c298c16043
    Reviewed-on: http://gerrit.cloudera.org:8080/14862
    Tested-by: Kudu Jenkins
    Reviewed-by: Adar Dembo <ad...@cloudera.com>
---
 src/kudu/fs/CMakeLists.txt                         |  4 +-
 src/kudu/fs/block_manager-test.cc                  |  2 +-
 src/kudu/fs/data_dirs.cc                           | 63 +++++++++++-----------
 src/kudu/fs/data_dirs.h                            | 24 ++++-----
 ...block_manager_util-test.cc => dir_util-test.cc} | 37 ++++++-------
 src/kudu/fs/{block_manager_util.cc => dir_util.cc} | 42 +++++++--------
 src/kudu/fs/{block_manager_util.h => dir_util.h}   | 20 +++----
 src/kudu/fs/error_manager.h                        |  2 +-
 src/kudu/fs/file_block_manager.cc                  |  4 +-
 src/kudu/fs/fs.proto                               | 38 ++++++-------
 src/kudu/fs/fs_manager-test.cc                     |  8 +--
 src/kudu/fs/log_block_manager.cc                   |  8 +--
 src/kudu/fs/log_block_manager.h                    |  2 +-
 13 files changed, 124 insertions(+), 130 deletions(-)

diff --git a/src/kudu/fs/CMakeLists.txt b/src/kudu/fs/CMakeLists.txt
index 593a08e..bab8d54 100644
--- a/src/kudu/fs/CMakeLists.txt
+++ b/src/kudu/fs/CMakeLists.txt
@@ -29,8 +29,8 @@ add_library(kudu_fs
   block_id.cc
   block_manager.cc
   block_manager_metrics.cc
-  block_manager_util.cc
   data_dirs.cc
+  dir_util.cc
   error_manager.cc
   file_block_manager.cc
   fs_manager.cc
@@ -54,9 +54,9 @@ target_link_libraries(kudu_fs_test_util
 # Tests
 SET_KUDU_TEST_LINK_LIBS(kudu_fs kudu_fs_test_util)
 ADD_KUDU_TEST(block_manager-test)
-ADD_KUDU_TEST(block_manager_util-test)
 ADD_KUDU_TEST(block_manager-stress-test RUN_SERIAL true)
 ADD_KUDU_TEST(data_dirs-test)
+ADD_KUDU_TEST(dir_util-test)
 ADD_KUDU_TEST(error_manager-test)
 ADD_KUDU_TEST(fs_manager-test)
 if (NOT APPLE)
diff --git a/src/kudu/fs/block_manager-test.cc b/src/kudu/fs/block_manager-test.cc
index 7f19903..31da823 100644
--- a/src/kudu/fs/block_manager-test.cc
+++ b/src/kudu/fs/block_manager-test.cc
@@ -321,7 +321,7 @@ void BlockManagerTest<FileBlockManager>::RunMultipathTest(const vector<string>&
       if (child == "." || child == "..") {
         continue;
       }
-      PathInstanceMetadataPB instance;
+      DirInstanceMetadataPB instance;
       ASSERT_OK(pb_util::ReadPBContainerFromPath(env_,
                                                  JoinPathSegments(path, child),
                                                  &instance));
diff --git a/src/kudu/fs/data_dirs.cc b/src/kudu/fs/data_dirs.cc
index a7f96e0..b7df6ed 100644
--- a/src/kudu/fs/data_dirs.cc
+++ b/src/kudu/fs/data_dirs.cc
@@ -37,7 +37,7 @@
 #include <google/protobuf/stubs/common.h>
 
 #include "kudu/fs/block_manager.h"
-#include "kudu/fs/block_manager_util.h"
+#include "kudu/fs/dir_util.h"
 #include "kudu/fs/fs.pb.h"
 #include "kudu/gutil/bind.h"
 #include "kudu/gutil/integral_types.h"
@@ -165,7 +165,7 @@ DataDir::DataDir(Env* env,
                  DataDirMetrics* metrics,
                  DataDirFsType fs_type,
                  string dir,
-                 unique_ptr<PathInstanceMetadataFile> metadata_file,
+                 unique_ptr<DirInstanceMetadataFile> metadata_file,
                  unique_ptr<ThreadPool> pool)
     : env_(env),
       metrics_(metrics),
@@ -397,7 +397,7 @@ Status DataDirManager::Create() {
   for (const auto& r : canonicalized_data_fs_roots_) {
     RETURN_NOT_OK_PREPEND(r.status, "Could not create directory manager with disks failed");
   }
-  vector<unique_ptr<PathInstanceMetadataFile>> loaded_instances;
+  vector<unique_ptr<DirInstanceMetadataFile>> loaded_instances;
   bool has_existing_instances;
   RETURN_NOT_OK(LoadInstances(&loaded_instances, &has_existing_instances));
   if (has_existing_instances) {
@@ -412,7 +412,7 @@ Status DataDirManager::Create() {
 }
 
 Status DataDirManager::CreateNewDirectoriesAndUpdateInstances(
-    vector<unique_ptr<PathInstanceMetadataFile>> instances) {
+    vector<unique_ptr<DirInstanceMetadataFile>> instances) {
   CHECK(!opts_.read_only);
   CHECK_NE(UpdateInstanceBehavior::DONT_UPDATE, opts_.update_instances);
 
@@ -448,7 +448,7 @@ Status DataDirManager::CreateNewDirectoriesAndUpdateInstances(
   //
   // Note: we don't bother trying to create/update the instance if the file is
   // otherwise unhealthy.
-  vector<unique_ptr<PathInstanceMetadataFile>> healthy_instances;
+  vector<unique_ptr<DirInstanceMetadataFile>> healthy_instances;
   for (auto& instance : instances) {
     if (instance->healthy()) {
       healthy_instances.emplace_back(std::move(instance));
@@ -466,13 +466,13 @@ Status DataDirManager::CreateNewDirectoriesAndUpdateInstances(
 
   // Go through the healthy instances and look for instances that don't have
   // the full complete set of instance UUIDs.
-  vector<unique_ptr<PathInstanceMetadataFile>> instances_to_update;
+  vector<unique_ptr<DirInstanceMetadataFile>> instances_to_update;
   for (auto& instance : healthy_instances) {
     DCHECK(instance->healthy());
-    const auto& path_set = instance->metadata()->path_set();
+    const auto& dir_set = instance->metadata()->dir_set();
     set<string> instance_uuids;
-    for (int i = 0; i < path_set.all_uuids_size(); i++) {
-      InsertIfNotPresent(&instance_uuids, path_set.all_uuids(i));
+    for (int i = 0; i < dir_set.all_uuids_size(); i++) {
+      InsertIfNotPresent(&instance_uuids, dir_set.all_uuids(i));
     }
     // If an instance file disagrees with the expected UUIDs, rewrite it.
     if (all_uuids != instance_uuids) {
@@ -500,7 +500,7 @@ Status DataDirManager::CreateNewDirectoriesAndUpdateInstances(
 }
 
 Status DataDirManager::UpdateHealthyInstances(
-    const vector<unique_ptr<PathInstanceMetadataFile>>& instances_to_update,
+    const vector<unique_ptr<DirInstanceMetadataFile>>& instances_to_update,
     const set<string>& new_all_uuids) {
   unordered_map<string, string> copies_to_restore;
   unordered_set<string> copies_to_delete;
@@ -548,10 +548,10 @@ Status DataDirManager::UpdateHealthyInstances(
     string copy_filename = instance_filename + kTmpInfix;
 
     // Put together the PB and perform the update.
-    PathInstanceMetadataPB new_pb = *instance->metadata();
-    new_pb.mutable_path_set()->mutable_all_uuids()->Clear();
+    DirInstanceMetadataPB new_pb = *instance->metadata();
+    new_pb.mutable_dir_set()->mutable_all_uuids()->Clear();
     for (const auto& uuid : new_all_uuids) {
-      new_pb.mutable_path_set()->add_all_uuids(uuid);
+      new_pb.mutable_dir_set()->add_all_uuids(uuid);
     }
 
     // We're about to update the file; if we fail midway, we should try to
@@ -587,7 +587,7 @@ Status DataDirManager::UpdateHealthyInstances(
 }
 
 Status DataDirManager::LoadInstances(
-    vector<unique_ptr<PathInstanceMetadataFile>>* instance_files,
+    vector<unique_ptr<DirInstanceMetadataFile>>* instance_files,
     bool* has_existing_instances) {
   LockMode lock_mode;
   if (!FLAGS_fs_lock_data_dirs) {
@@ -598,7 +598,7 @@ Status DataDirManager::LoadInstances(
     lock_mode = LockMode::MANDATORY;
   }
   vector<string> missing_roots_tmp;
-  vector<unique_ptr<PathInstanceMetadataFile>> loaded_instances;
+  vector<unique_ptr<DirInstanceMetadataFile>> loaded_instances;
   ObjectIdGenerator gen;
   for (int i = 0; i < canonicalized_data_fs_roots_.size(); i++) {
     const auto& root = canonicalized_data_fs_roots_[i];
@@ -608,8 +608,8 @@ Status DataDirManager::LoadInstances(
     // Initialize the instance with a backup UUID. In case the load fails, this
     // will be the UUID for our instnace.
     string backup_uuid = gen.Next();
-    unique_ptr<PathInstanceMetadataFile> instance(
-        new PathInstanceMetadataFile(env_, std::move(backup_uuid), opts_.block_manager_type,
+    unique_ptr<DirInstanceMetadataFile> instance(
+        new DirInstanceMetadataFile(env_, std::move(backup_uuid), opts_.block_manager_type,
                                      instance_filename));
     if (PREDICT_FALSE(!root.status.ok())) {
       instance->SetInstanceFailed(root.status);
@@ -675,11 +675,11 @@ Status DataDirManager::PopulateDirectoryMaps(const vector<unique_ptr<DataDir>>&
     for (const auto& dd : dds) {
       // Find a healthy instance file and use its set of UUIDs.
       if (dd->instance()->healthy()) {
-        const auto& path_set = dd->instance()->metadata()->path_set();
-        VLOG(1) << Substitute("using path set $0 as reference: $1",
-            dd->instance()->path(), pb_util::SecureDebugString(path_set));
-        for (int idx = 0; idx < path_set.all_uuids_size(); idx++) {
-          const string& uuid = path_set.all_uuids(idx);
+        const auto& dir_set = dd->instance()->metadata()->dir_set();
+        VLOG(1) << Substitute("using dir set $0 as reference: $1",
+            dd->instance()->path(), pb_util::SecureDebugString(dir_set));
+        for (int idx = 0; idx < dir_set.all_uuids_size(); idx++) {
+          const string& uuid = dir_set.all_uuids(idx);
           InsertIfNotPresent(&uuid_to_idx, uuid, idx);
         }
         break;
@@ -691,7 +691,7 @@ Status DataDirManager::PopulateDirectoryMaps(const vector<unique_ptr<DataDir>>&
           Substitute("instance file is corrupted: $0 unique UUIDs expected, got $1",
                      dds.size(), uuid_to_idx.size()));
     }
-    // Keep track of any dirs that were not referenced in the path set. These
+    // Keep track of any dirs that were not referenced in the dir set. These
     // are presumably from instance files we failed to read. We'll assign them
     // indexes of those that remain.
     vector<DataDir*> unassigned_dirs;
@@ -730,7 +730,7 @@ Status DataDirManager::Open() {
                                               canonicalized_data_fs_roots_.size(), kMaxDataDirs));
   }
 
-  vector<unique_ptr<PathInstanceMetadataFile>> loaded_instances;
+  vector<unique_ptr<DirInstanceMetadataFile>> loaded_instances;
   // Load the instance files from disk.
   bool has_existing_instances;
   RETURN_NOT_OK_PREPEND(LoadInstances(&loaded_instances, &has_existing_instances),
@@ -762,13 +762,6 @@ Status DataDirManager::Open() {
     auto& instance = loaded_instances[i];
     const string data_dir = instance->dir();
 
-    // Create a per-dir thread pool.
-    unique_ptr<ThreadPool> pool;
-    RETURN_NOT_OK(ThreadPoolBuilder(Substitute("data dir $0", i))
-                  .set_max_threads(1)
-                  .set_trace_metric_prefix("data dirs")
-                  .Build(&pool));
-
     // Figure out what filesystem the data directory is on.
     DataDirFsType fs_type = DataDirFsType::OTHER;
     if (instance->healthy()) {
@@ -792,9 +785,15 @@ Status DataDirManager::Open() {
       }
     }
 
+    // Create a per-dir thread pool.
+    unique_ptr<ThreadPool> pool;
+    RETURN_NOT_OK(ThreadPoolBuilder(Substitute("data dir $0", i))
+                  .set_max_threads(1)
+                  .set_trace_metric_prefix("data dirs")
+                  .Build(&pool));
     unique_ptr<DataDir> dd(new DataDir(
         env_, metrics_.get(), fs_type, data_dir, std::move(instance),
-        unique_ptr<ThreadPool>(pool.release())));
+        std::move(pool)));
     dds.emplace_back(std::move(dd));
   }
 
diff --git a/src/kudu/fs/data_dirs.h b/src/kudu/fs/data_dirs.h
index a9188ed..18f989d 100644
--- a/src/kudu/fs/data_dirs.h
+++ b/src/kudu/fs/data_dirs.h
@@ -58,8 +58,8 @@ namespace fs {
 typedef std::unordered_map<int, std::string> UuidByUuidIndexMap;
 typedef std::unordered_map<std::string, int> UuidIndexByUuidMap;
 
-class PathInstanceMetadataFile;
 struct CreateBlockOptions;
+class DirInstanceMetadataFile;
 
 const char kInstanceMetadataFileName[] = "block_manager_instance";
 const char kDataDirName[] = "data";
@@ -68,7 +68,7 @@ namespace internal {
 
 // A DataDirGroup is a group of directories used by an entity for block
 // placement. A group is represented in memory by a list of indices which index
-// into the list of all UUIDs found in a PathSetPB. A group is represented
+// into the list of all UUIDs found in a DirSetPB. A group is represented
 // on-disk as a list of full UUIDs, and as such, when writing or reading from
 // disk, a mapping is needed to translate between index and UUID.
 //
@@ -117,7 +117,7 @@ enum class DataDirFsType {
 // Defines the behavior when opening a directory manager that has an
 // inconsistent or incomplete set of instance files.
 enum UpdateInstanceBehavior {
-  // If the data directories don't match the on-disk path sets, update the
+  // If the data directories don't match the on-disk dir sets, update the
   // on-disk data to match if not in read-only mode.
   UPDATE_AND_IGNORE_FAILURES,
 
@@ -125,8 +125,8 @@ enum UpdateInstanceBehavior {
   // on-disk files fail.
   UPDATE_AND_ERROR_ON_FAILURE,
 
-  // If the data directories don't match the on-disk path sets, continue
-  // without updating the on-disk data.
+  // If the data directories don't match the on-disk dir sets, continue without
+  // updating the on-disk data.
   DONT_UPDATE
 };
 
@@ -144,7 +144,7 @@ class DataDir {
           DataDirMetrics* metrics,
           DataDirFsType fs_type,
           std::string dir,
-          std::unique_ptr<PathInstanceMetadataFile> metadata_file,
+          std::unique_ptr<DirInstanceMetadataFile> metadata_file,
           std::unique_ptr<ThreadPool> pool);
   ~DataDir();
 
@@ -180,7 +180,7 @@ class DataDir {
 
   const std::string& dir() const { return dir_; }
 
-  const PathInstanceMetadataFile* instance() const {
+  const DirInstanceMetadataFile* instance() const {
     return metadata_file_.get();
   }
 
@@ -199,7 +199,7 @@ class DataDir {
   DataDirMetrics* metrics_;
   const DataDirFsType fs_type_;
   const std::string dir_;
-  const std::unique_ptr<PathInstanceMetadataFile> metadata_file_;
+  const std::unique_ptr<DirInstanceMetadataFile> metadata_file_;
   const std::unique_ptr<ThreadPool> pool_;
 
   bool is_shutdown_;
@@ -392,7 +392,7 @@ class DataDirManager {
   // Finds a data directory by uuid index, returning null if it can't be found.
   //
   // More information on uuid indexes and their relation to data directories
-  // can be found next to PathSetPB in fs.proto.
+  // can be found next to DirSetPB in fs.proto.
   DataDir* FindDataDirByUuidIndex(int uuid_idx) const;
 
   // Finds a uuid index by data directory, returning false if it can't be found.
@@ -450,7 +450,7 @@ class DataDirManager {
   // Returns an error if an instance file fails in an irreconcileable way (e.g.
   // the file is locked).
   Status LoadInstances(
-      std::vector<std::unique_ptr<PathInstanceMetadataFile>>* instance_files,
+      std::vector<std::unique_ptr<DirInstanceMetadataFile>>* instance_files,
       bool* has_existing_instances);
 
   // Takes the set of instance files, does some basic verification on them,
@@ -467,7 +467,7 @@ class DataDirManager {
   // If in UPDATE_AND_ERROR_ON_FAILURE mode, a failure to update instances will
   // surface as an error.
   Status CreateNewDirectoriesAndUpdateInstances(
-      std::vector<std::unique_ptr<PathInstanceMetadataFile>> instances);
+      std::vector<std::unique_ptr<DirInstanceMetadataFile>> instances);
 
   // Updates the on-disk instance files specified by 'instances_to_update'
   // (presumably those whose 'all_uuids' field doesn't match 'new_all_uuids')
@@ -481,7 +481,7 @@ class DataDirManager {
   // If in UPDATE_AND_ERROR_ON_FAILURE mode, any failure will immediately attempt
   // to clean up any altered state and return with an error.
   Status UpdateHealthyInstances(
-      const std::vector<std::unique_ptr<PathInstanceMetadataFile>>& instances_to_update,
+      const std::vector<std::unique_ptr<DirInstanceMetadataFile>>& instances_to_update,
       const std::set<std::string>& new_all_uuids);
 
   // Returns a random directory in the data dir group specified in 'opts',
diff --git a/src/kudu/fs/block_manager_util-test.cc b/src/kudu/fs/dir_util-test.cc
similarity index 71%
rename from src/kudu/fs/block_manager_util-test.cc
rename to src/kudu/fs/dir_util-test.cc
index 2f3fbcf..d669188 100644
--- a/src/kudu/fs/block_manager_util-test.cc
+++ b/src/kudu/fs/dir_util-test.cc
@@ -15,19 +15,16 @@
 // specific language governing permissions and limitations
 // under the License.
 
-#include "kudu/fs/block_manager_util.h"
+#include "kudu/fs/dir_util.h"
 
-#include <memory>
 #include <ostream>
 #include <string>
-#include <vector>
 
 #include <glog/logging.h>
 #include <google/protobuf/repeated_field.h> // IWYU pragma: keep
 #include <gtest/gtest.h>
 
 #include "kudu/fs/fs.pb.h"
-#include "kudu/gutil/strings/substitute.h"
 #include "kudu/util/env.h"
 #include "kudu/util/status.h"
 #include "kudu/util/test_macros.h"
@@ -36,11 +33,7 @@
 namespace kudu {
 namespace fs {
 
-using google::protobuf::RepeatedPtrField;
 using std::string;
-using std::unique_ptr;
-using std::vector;
-using strings::Substitute;
 
 TEST_F(KuduTest, Lifecycle) {
   string kType = "asdf";
@@ -49,27 +42,27 @@ TEST_F(KuduTest, Lifecycle) {
 
   // Test that the metadata file was created.
   {
-    PathInstanceMetadataFile file(env_, kUuid, kType, kFileName);
+    DirInstanceMetadataFile file(env_, kUuid, kType, kFileName);
     ASSERT_OK(file.Create({ kUuid }));
   }
   ASSERT_TRUE(env_->FileExists(kFileName));
 
   // Test that we could open and parse it.
   {
-    PathInstanceMetadataFile file(env_, kUuid, kType, kFileName);
+    DirInstanceMetadataFile file(env_, kUuid, kType, kFileName);
     ASSERT_OK(file.LoadFromDisk());
-    const PathInstanceMetadataPB* md = file.metadata();
-    ASSERT_EQ(kType, md->block_manager_type());
-    const PathSetPB& path_set = md->path_set();
-    ASSERT_EQ(kUuid, path_set.uuid());
-    ASSERT_EQ(1, path_set.all_uuids_size());
-    ASSERT_EQ(kUuid, path_set.all_uuids(0));
+    const DirInstanceMetadataPB* md = file.metadata();
+    ASSERT_EQ(kType, md->dir_type());
+    const DirSetPB& dir_set = md->dir_set();
+    ASSERT_EQ(kUuid, dir_set.uuid());
+    ASSERT_EQ(1, dir_set.all_uuids_size());
+    ASSERT_EQ(kUuid, dir_set.all_uuids(0));
   }
 
   // Test that expecting a different type of block manager fails.
   {
-    PathInstanceMetadataFile file(env_, kUuid, "other type", kFileName);
-    PathInstanceMetadataPB pb;
+    DirInstanceMetadataFile file(env_, kUuid, "other type", kFileName);
+    DirInstanceMetadataPB pb;
     ASSERT_TRUE(file.LoadFromDisk().IsIOError());
   }
 }
@@ -79,10 +72,10 @@ TEST_F(KuduTest, Locking) {
   const string kFileName = GetTestPath("foo");
   string kUuid = "a_uuid";
 
-  PathInstanceMetadataFile file(env_, kUuid, kType, kFileName);
+  DirInstanceMetadataFile file(env_, kUuid, kType, kFileName);
   ASSERT_OK(file.Create({ kUuid }));
 
-  PathInstanceMetadataFile first(env_, "", kType, kFileName);
+  DirInstanceMetadataFile first(env_, "", kType, kFileName);
   ASSERT_OK(first.LoadFromDisk());
   ASSERT_EQ(kUuid, first.uuid());
   ASSERT_OK(first.Lock());
@@ -90,7 +83,7 @@ TEST_F(KuduTest, Locking) {
   // Note: we must use a death test here because file locking is only
   // disallowed across processes, and death tests spawn child processes.
   ASSERT_DEATH({
-    PathInstanceMetadataFile second(env_, "", kType, kFileName);
+    DirInstanceMetadataFile second(env_, "", kType, kFileName);
     CHECK_OK(second.LoadFromDisk());
     CHECK_EQ(kUuid, second.uuid());
     CHECK_OK(second.Lock());
@@ -98,7 +91,7 @@ TEST_F(KuduTest, Locking) {
 
   ASSERT_OK(first.Unlock());
   ASSERT_DEATH({
-    PathInstanceMetadataFile second(env_, "", kType, kFileName);
+    DirInstanceMetadataFile second(env_, "", kType, kFileName);
     CHECK_OK(second.LoadFromDisk());
     CHECK_EQ(kUuid, second.uuid());
     Status s = second.Lock();
diff --git a/src/kudu/fs/block_manager_util.cc b/src/kudu/fs/dir_util.cc
similarity index 89%
rename from src/kudu/fs/block_manager_util.cc
rename to src/kudu/fs/dir_util.cc
index 92b2765..98f4e82 100644
--- a/src/kudu/fs/block_manager_util.cc
+++ b/src/kudu/fs/dir_util.cc
@@ -14,7 +14,7 @@
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
-#include "kudu/fs/block_manager_util.h"
+#include "kudu/fs/dir_util.h"
 
 #include <cstdint>
 #include <ostream>
@@ -125,22 +125,22 @@ Status CheckHolePunch(Env* env, const string& path) {
   } \
 } while (0)
 
-PathInstanceMetadataFile::PathInstanceMetadataFile(Env* env,
+DirInstanceMetadataFile::DirInstanceMetadataFile(Env* env,
                                                    string uuid,
-                                                   string block_manager_type,
+                                                   string dir_type,
                                                    string filename)
     : env_(env),
       uuid_(std::move(uuid)),
-      block_manager_type_(std::move(block_manager_type)),
+      dir_type_(std::move(dir_type)),
       filename_(std::move(filename)) {}
 
-PathInstanceMetadataFile::~PathInstanceMetadataFile() {
+DirInstanceMetadataFile::~DirInstanceMetadataFile() {
   if (lock_) {
     WARN_NOT_OK(Unlock(), Substitute("Failed to unlock file $0", filename_));
   }
 }
 
-Status PathInstanceMetadataFile::Create(const set<string>& all_uuids,
+Status DirInstanceMetadataFile::Create(const set<string>& all_uuids,
                                         bool* created_dir) {
   DCHECK(!lock_);
   DCHECK(ContainsKey(all_uuids, uuid_));
@@ -159,7 +159,7 @@ Status PathInstanceMetadataFile::Create(const set<string>& all_uuids,
 
   // If we're initializing the log block manager, check that we support
   // hole-punching.
-  if (block_manager_type_ == "log") {
+  if (dir_type_ == "log") {
     RETURN_NOT_OK_FAIL_INSTANCE_PREPEND(CheckHolePunch(env_, dir_name),
                                         kHolePunchErrorMsg);
   }
@@ -187,17 +187,17 @@ Status PathInstanceMetadataFile::Create(const set<string>& all_uuids,
   RETURN_NOT_OK_FAIL_INSTANCE_PREPEND(env_->GetBlockSize(created_filename, &block_size),
                                       "failed to check block size");
 
-  // Set up the path set.
-  PathInstanceMetadataPB new_instance;
-  PathSetPB* new_path_set = new_instance.mutable_path_set();
-  new_path_set->set_uuid(uuid_);
-  new_path_set->mutable_all_uuids()->Reserve(all_uuids.size());
+  // Set up the directory set.
+  DirInstanceMetadataPB new_instance;
+  DirSetPB* new_dir_set = new_instance.mutable_dir_set();
+  new_dir_set->set_uuid(uuid_);
+  new_dir_set->mutable_all_uuids()->Reserve(all_uuids.size());
   for (const string& u : all_uuids) {
-    new_path_set->add_all_uuids(u);
+    new_dir_set->add_all_uuids(u);
   }
 
   // And the rest of the metadata.
-  new_instance.set_block_manager_type(block_manager_type_);
+  new_instance.set_dir_type(dir_type_);
   new_instance.set_filesystem_block_size_bytes(block_size);
 
   RETURN_NOT_OK_FAIL_INSTANCE_PREPEND(pb_util::WritePBContainerToPath(
@@ -216,19 +216,19 @@ Status PathInstanceMetadataFile::Create(const set<string>& all_uuids,
   return Status::OK();
 }
 
-Status PathInstanceMetadataFile::LoadFromDisk() {
+Status DirInstanceMetadataFile::LoadFromDisk() {
   DCHECK(!lock_) <<
       "Opening a metadata file that's already locked would release the lock";
 
-  unique_ptr<PathInstanceMetadataPB> pb(new PathInstanceMetadataPB());
+  unique_ptr<DirInstanceMetadataPB> pb(new DirInstanceMetadataPB());
   RETURN_NOT_OK_FAIL_INSTANCE_PREPEND(pb_util::ReadPBContainerFromPath(env_, filename_, pb.get()),
       Substitute("Failed to read metadata file from $0", filename_));
 
-  if (pb->block_manager_type() != block_manager_type_) {
+  if (pb->dir_type() != dir_type_) {
     return Status::IOError(Substitute(
       "existing instance was written using the '$0' format; cannot restart "
       "with a different format type '$1'",
-      pb->block_manager_type(), block_manager_type_));
+      pb->dir_type(), dir_type_));
   }
 
   uint64_t block_size;
@@ -239,12 +239,12 @@ Status PathInstanceMetadataFile::LoadFromDisk() {
         "Expected $0 but was $1", pb->filesystem_block_size_bytes(), block_size));
   }
 
-  uuid_ = pb->path_set().uuid();
+  uuid_ = pb->dir_set().uuid();
   metadata_ = std::move(pb);
   return Status::OK();
 }
 
-Status PathInstanceMetadataFile::Lock() {
+Status DirInstanceMetadataFile::Lock() {
   DCHECK(!lock_);
 
   FileLock* lock;
@@ -256,7 +256,7 @@ Status PathInstanceMetadataFile::Lock() {
   return Status::OK();
 }
 
-Status PathInstanceMetadataFile::Unlock() {
+Status DirInstanceMetadataFile::Unlock() {
   DCHECK(lock_);
 
   RETURN_NOT_OK_FAIL_INSTANCE_PREPEND(env_->UnlockFile(lock_.release()),
diff --git a/src/kudu/fs/block_manager_util.h b/src/kudu/fs/dir_util.h
similarity index 88%
rename from src/kudu/fs/block_manager_util.h
rename to src/kudu/fs/dir_util.h
index 4675a3c..c55436e 100644
--- a/src/kudu/fs/block_manager_util.h
+++ b/src/kudu/fs/dir_util.h
@@ -26,30 +26,30 @@
 
 namespace kudu {
 
+class DirInstanceMetadataPB;
 class Env;
 class FileLock;
-class PathInstanceMetadataPB;
 
 namespace fs {
 
 // Reads and writes block manager instance metadata files.
 //
 // Thread-unsafe; access to this object must be externally synchronized.
-class PathInstanceMetadataFile {
+class DirInstanceMetadataFile {
  public:
   // 'env' must remain valid for the lifetime of this class.
   //
   // 'uuid' is the UUID used for this instance file, though the UUID may be
   // changed if we read the instance file from disk and find a different UUID.
-  PathInstanceMetadataFile(Env* env, std::string uuid, std::string block_manager_type,
-                           std::string filename);
+  DirInstanceMetadataFile(Env* env, std::string uuid, std::string dir_type,
+                          std::string filename);
 
-  ~PathInstanceMetadataFile();
+  ~DirInstanceMetadataFile();
 
   // Creates, writes, synchronizes, and closes a new instance metadata file.
   // Fails the PIMF in the case of a failed directory.
   //
-  // 'all_uuids' is all of the unique UUIDs in this instance's path set.
+  // 'all_uuids' is all of the unique UUIDs in this instance's dir set.
   // 'uuid_' must exist in this set. 'created_dir' is set to true if the parent
   // directory of the file was also created during this process.
   //
@@ -79,7 +79,7 @@ class PathInstanceMetadataFile {
   // Sets that the instance failed (e.g. due to a disk failure).
   //
   // If failed, there is no guarantee that the instance will have a 'metadata_'.
-  void SetInstanceFailed(const Status& s = Status::IOError("Path instance failed")) {
+  void SetInstanceFailed(const Status& s = Status::IOError("directory instance failed")) {
     health_status_ = s;
   }
 
@@ -96,7 +96,7 @@ class PathInstanceMetadataFile {
   std::string uuid() const { return uuid_; }
   std::string dir() const { return DirName(filename_); }
   const std::string& path() const { return filename_; }
-  PathInstanceMetadataPB* metadata() const { return metadata_.get(); }
+  DirInstanceMetadataPB* metadata() const { return metadata_.get(); }
 
  private:
   Env* env_;
@@ -111,12 +111,12 @@ class PathInstanceMetadataFile {
   std::string uuid_;
 
   // The type of this instance file.
-  const std::string block_manager_type_;
+  const std::string dir_type_;
 
   // The name of the file associated with this instance.
   const std::string filename_;
 
-  std::unique_ptr<PathInstanceMetadataPB> metadata_;
+  std::unique_ptr<DirInstanceMetadataPB> metadata_;
 
   // In order to prevent multiple Kudu processes from starting up using the
   // same directories, we lock the instance files when starting up.
diff --git a/src/kudu/fs/error_manager.h b/src/kudu/fs/error_manager.h
index 936c91b..046d734 100644
--- a/src/kudu/fs/error_manager.h
+++ b/src/kudu/fs/error_manager.h
@@ -22,8 +22,8 @@
 
 #include <glog/logging.h>
 
-#include "kudu/fs/block_manager_util.h"
 #include "kudu/fs/data_dirs.h"
+#include "kudu/fs/dir_util.h"
 #include "kudu/fs/fs.pb.h"
 #include "kudu/gutil/callback.h"
 #include "kudu/gutil/port.h"
diff --git a/src/kudu/fs/file_block_manager.cc b/src/kudu/fs/file_block_manager.cc
index fcf1352..9ec4471 100644
--- a/src/kudu/fs/file_block_manager.cc
+++ b/src/kudu/fs/file_block_manager.cc
@@ -81,8 +81,8 @@ namespace internal {
 //
 // A block ID uniquely locates a block. Every ID is a uint64_t, broken down
 // into multiple logical components:
-// 1. Bytes 0 (MSB) and 1 identify the block's data dir by path set index. See
-//    fs.proto for more details on path sets.
+// 1. Bytes 0 (MSB) and 1 identify the block's data dir by dir set index. See
+//    fs.proto for more details on dir sets.
 // 2. Bytes 2-7 (LSB) uniquely identify the block within the data dir. As more
 //    and more blocks are created in a data dir, the likelihood of a collision
 //    becomes greater. In the event of a collision, the block manager will
diff --git a/src/kudu/fs/fs.proto b/src/kudu/fs/fs.proto
index 3292240..7b0a44a 100644
--- a/src/kudu/fs/fs.proto
+++ b/src/kudu/fs/fs.proto
@@ -38,32 +38,34 @@ message InstanceMetadataPB {
   // TODO: add a "node type" (TS/Master?)
 }
 
-// Describes a collection of filesystem path instances and the membership of a
-// particular instance in the collection.
+// Describes a collection of filesystem directory instances and the membership
+// of a particular instance in the collection.
 //
-// In a healthy filesystem (see below), a path instance can be referred to via
-// its UUID's position in all_uuids instead of via the UUID itself. This is
+// In a healthy filesystem (see below), a directory instance can be referred to
+// via its UUID's position in all_uuids instead of via the UUID itself. This is
 // useful when there are many such references, as the position is much shorter
 // than the UUID.
-message PathSetPB {
-  // Globally unique identifier for this path instance.
+message DirSetPB {
+  // Globally unique identifier for this directory instance.
   required bytes uuid = 1;
 
-  // All UUIDs in this path instance set. In a healthy filesystem:
-  // 1. There exists an on-disk PathInstanceMetadataPB for each listed UUID, and
-  // 2. Every PathSetPB contains an identical copy of all_uuids.
+  // All UUIDs in this dir instance set. In a healthy filesystem:
+  // 1. There exists an on-disk DirInstanceMetadataPB for each listed UUID, and
+  // 2. Every DirSetPB contains an identical copy of all_uuids.
   repeated bytes all_uuids = 2;
 }
 
-// A filesystem instance can contain multiple paths. One of these structures
-// is persisted in each path when the filesystem instance is created.
-message PathInstanceMetadataPB {
-  // Describes this path instance as well as all of the other path instances
-  // that, taken together, describe a complete set.
-  required PathSetPB path_set = 1;
-
-  // Textual representation of the block manager that formatted this path.
-  required string block_manager_type = 2;
+// A filesystem instance can contain multiple directories. One of these
+// structures is persisted in each directory when the filesystem instance is
+// created.
+message DirInstanceMetadataPB {
+  // Describes this directory instance as well as all of the other directory
+  // instances that, taken together, describe a complete directory set.
+  required DirSetPB dir_set = 1;
+
+  // Textual representation of the directory type for which this directory was
+  // formatted.
+  required string dir_type = 2;
 
   // Block size on the filesystem where this instance was created. If the
   // instance (and its data) are ever copied to another location, the block
diff --git a/src/kudu/fs/fs_manager-test.cc b/src/kudu/fs/fs_manager-test.cc
index 6516228..0a9fc13 100644
--- a/src/kudu/fs/fs_manager-test.cc
+++ b/src/kudu/fs/fs_manager-test.cc
@@ -38,8 +38,8 @@
 #include <gtest/gtest.h>
 
 #include "kudu/fs/block_manager.h"
-#include "kudu/fs/block_manager_util.h"
 #include "kudu/fs/data_dirs.h"
+#include "kudu/fs/dir_util.h"
 #include "kudu/fs/fs.pb.h"
 #include "kudu/fs/fs_report.h"
 #include "kudu/gutil/map-util.h"
@@ -840,7 +840,7 @@ TEST_F(FsManagerTestBase, TestEIOWhileRunningUpdateDirsTool) {
   };
 
   // Helper to collect the contents of the InstanceMetadataPB and
-  // PathInstanceMetadtaPBs we expect to see in 'data_roots'. We'll read the
+  // DirInstanceMetadataPBs we expect to see in 'data_roots'. We'll read the
   // contents of each instance file from disk and compare them before and after
   // a botched update of the FsManager.
   auto get_added_instance_files = [&] (const vector<string>& data_roots,
@@ -863,8 +863,8 @@ TEST_F(FsManagerTestBase, TestEIOWhileRunningUpdateDirsTool) {
         InsertOrDie(&instances, instance_path, SecureDebugString(*pb));
       }
 
-      // Collect the contents of the PathInstanceMetadataPB objects.
-      unique_ptr<PathInstanceMetadataPB> bmi_pb(new PathInstanceMetadataPB);
+      // Collect the contents of the DirInstanceMetadataPB objects.
+      unique_ptr<DirInstanceMetadataPB> bmi_pb(new DirInstanceMetadataPB);
       const auto block_manager_instance = JoinPathSegments(
           JoinPathSegments(root, kDataDirName), kInstanceMetadataFileName);
       s = ReadPBContainerFromPath(env_, block_manager_instance, bmi_pb.get());
diff --git a/src/kudu/fs/log_block_manager.cc b/src/kudu/fs/log_block_manager.cc
index dff3870..3789c38 100644
--- a/src/kudu/fs/log_block_manager.cc
+++ b/src/kudu/fs/log_block_manager.cc
@@ -17,10 +17,11 @@
 
 #include "kudu/fs/log_block_manager.h"
 
+#include <errno.h>
+
 #include <algorithm>
 #include <cstddef>
 #include <cstdint>
-#include <errno.h>
 #include <map>
 #include <memory>
 #include <mutex>
@@ -34,12 +35,11 @@
 
 #include <boost/optional/optional.hpp>
 #include <gflags/gflags.h>
-#include <gflags/gflags_declare.h>
 #include <glog/logging.h>
 
 #include "kudu/fs/block_manager_metrics.h"
-#include "kudu/fs/block_manager_util.h"
 #include "kudu/fs/data_dirs.h"
+#include "kudu/fs/dir_util.h"
 #include "kudu/fs/error_manager.h"
 #include "kudu/fs/fs.pb.h"
 #include "kudu/fs/fs_report.h"
@@ -541,7 +541,7 @@ class LogBlockContainer: public RefCountedThreadSafe<LogBlockContainer> {
   bool dead() const { return dead_.Load(); }
   const LogBlockManagerMetrics* metrics() const { return metrics_; }
   DataDir* data_dir() const { return data_dir_; }
-  const PathInstanceMetadataPB* instance() const { return data_dir_->instance()->metadata(); }
+  const DirInstanceMetadataPB* instance() const { return data_dir_->instance()->metadata(); }
 
   // Adjusts the number of blocks being written.
   // Positive means increase, negative means decrease.
diff --git a/src/kudu/fs/log_block_manager.h b/src/kudu/fs/log_block_manager.h
index 11c1216..7631042 100644
--- a/src/kudu/fs/log_block_manager.h
+++ b/src/kudu/fs/log_block_manager.h
@@ -33,6 +33,7 @@
 
 #include "kudu/fs/block_id.h"
 #include "kudu/fs/block_manager.h"
+#include "kudu/fs/fs.pb.h"
 #include "kudu/gutil/macros.h"
 #include "kudu/gutil/ref_counted.h"
 #include "kudu/util/atomic.h"
@@ -44,7 +45,6 @@
 
 namespace kudu {
 
-class BlockRecordPB;
 class Env;
 class RWFile;
 


[kudu] 05/05: KUDU-3001 Multi-thread to load containers in a data directory

Posted by ad...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

adar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit 6b6910870ce2c35bf8b9be9408f44a8cec6b580a
Author: Yingchun Lai <40...@qq.com>
AuthorDate: Fri Nov 15 19:47:57 2019 +0800

    KUDU-3001 Multi-thread to load containers in a data directory
    
    When a data directory has many block containers, a single thread to
    load these container files is low efficiency, we can improve it by
    multi-threads.
    
    We did some simple benchmarks to verify it. Adjust
    'log_container_max_size' to 1GB to generate more containers when do
    benchmarks, adjust 'startup_benchmark_data_dir_count_for_testing' to 8
    to make sure existing concurrent data directories load are effective,
    and adjust 'fs_max_thread_count_per_data_dir' and
    'startup_benchmark_block_count_for_testing' to different
    values, timing 10 times ReopenBlockManager(), in milliseconds,
    result details as follow:
    
    disk type: SSD
                             |                          new version
    Block count  old version | 1 thread | 2 threads | 4 threads | 8 threads | 16 threads | 32 threads
        100,000        2,375      2,382       2,342       2,372       2,343        2,353        2,393
      1,000,000       24,018     23,813      22,628      22,407      22,367       22,636       23,173
      2,000,000       50,163     51,120      39,726      37,589      37,671       37,501       37,710
      4,000,000      104,051    105,560      90,427      79,778      73,129       73,205       74,947
      8,000,000      214,347    216,210     199,456     159,143     157,190      158,798      157,056
    
    disk type: spinning disk
                             |                          new version
    Block count  old version | 1 thread | 2 threads | 4 threads | 8 threads | 16 threads | 32 threads
        100,000        3,207      3,347       3,345       3,279       3,237        3,263        3,221
      1,000,000       33,659     34,106      32,081      30,261      30,142       30,115       30,876
      2,000,000       68,097     74,939      56,976      51,407      50,957       56,299       58,456
      4,000,000      146,503    162,389     116,956     104,435      94,905      102,606      100,526
      8,000,000      331,201    349,609     267,259     247,069     243,064      247,810      247,472
    
    Change-Id: I0721ee4a5a6824db146ba0658e60eec25dd0c65c
    Reviewed-on: http://gerrit.cloudera.org:8080/14743
    Reviewed-by: Adar Dembo <ad...@cloudera.com>
    Tested-by: Adar Dembo <ad...@cloudera.com>
---
 src/kudu/fs/data_dirs.cc              |   6 +-
 src/kudu/fs/log_block_manager-test.cc |  10 +-
 src/kudu/fs/log_block_manager.cc      | 516 +++++++++++++++++++---------------
 src/kudu/fs/log_block_manager.h       |  15 +-
 4 files changed, 318 insertions(+), 229 deletions(-)

diff --git a/src/kudu/fs/data_dirs.cc b/src/kudu/fs/data_dirs.cc
index b7df6ed..ddeb55f 100644
--- a/src/kudu/fs/data_dirs.cc
+++ b/src/kudu/fs/data_dirs.cc
@@ -101,6 +101,10 @@ DEFINE_bool(fs_data_dirs_consider_available_space, true,
 TAG_FLAG(fs_data_dirs_consider_available_space, runtime);
 TAG_FLAG(fs_data_dirs_consider_available_space, evolving);
 
+DEFINE_uint64(fs_max_thread_count_per_data_dir, 8,
+              "Maximum work thread per data directory.");
+TAG_FLAG(fs_max_thread_count_per_data_dir, advanced);
+
 METRIC_DEFINE_gauge_uint64(server, data_dirs_failed,
                            "Data Directories Failed",
                            kudu::MetricUnit::kDataDirectories,
@@ -788,7 +792,7 @@ Status DataDirManager::Open() {
     // Create a per-dir thread pool.
     unique_ptr<ThreadPool> pool;
     RETURN_NOT_OK(ThreadPoolBuilder(Substitute("data dir $0", i))
-                  .set_max_threads(1)
+                  .set_max_threads(FLAGS_fs_max_thread_count_per_data_dir)
                   .set_trace_metric_prefix("data dirs")
                   .Build(&pool));
     unique_ptr<DataDir> dd(new DataDir(
diff --git a/src/kudu/fs/log_block_manager-test.cc b/src/kudu/fs/log_block_manager-test.cc
index 01952c8..b1eec55 100644
--- a/src/kudu/fs/log_block_manager-test.cc
+++ b/src/kudu/fs/log_block_manager-test.cc
@@ -86,6 +86,10 @@ DECLARE_string(block_manager_preflush_control);
 DECLARE_string(env_inject_eio_globs);
 DECLARE_uint64(log_container_preallocate_bytes);
 DECLARE_uint64(log_container_max_size);
+DEFINE_int32(startup_benchmark_block_count_for_testing, 1000000,
+             "Block count to do startup benchmark.");
+DEFINE_int32(startup_benchmark_data_dir_count_for_testing, 8,
+             "Data directories to do startup benchmark.");
 
 // Block manager metrics.
 METRIC_DECLARE_counter(block_manager_total_blocks_deleted);
@@ -1005,10 +1009,8 @@ TEST_F(LogBlockManagerTest, TestParseKernelRelease) {
 //
 // However it still can be used to micro-optimize the startup process.
 TEST_F(LogBlockManagerTest, StartupBenchmark) {
-  const int kTestDataDirCount = 8;
-  FLAGS_fs_target_data_dirs_per_tablet = kTestDataDirCount;
   std::vector<std::string> test_dirs;
-  for (int i = 0; i < kTestDataDirCount; ++i) {
+  for (int i = 0; i < FLAGS_startup_benchmark_data_dir_count_for_testing; ++i) {
     test_dirs.emplace_back(test_dir_ + "/" + std::to_string(i));
   }
   // Re-open block manager to place data on multiple data directories.
@@ -1023,7 +1025,7 @@ TEST_F(LogBlockManagerTest, StartupBenchmark) {
   // See http://yoshinorimatsunobu.blogspot.com/2014/03/how-syncfilerange-really-works.html
   // for details.
   FLAGS_block_manager_preflush_control = "never";
-  const int kNumBlocks = AllowSlowTests() ? 1000000 : 1000;
+  const int kNumBlocks = AllowSlowTests() ? FLAGS_startup_benchmark_block_count_for_testing : 1000;
   // Creates 'kNumBlocks' blocks with minimal data.
   {
     unique_ptr<BlockCreationTransaction> transaction = bm_->NewCreationTransaction();
diff --git a/src/kudu/fs/log_block_manager.cc b/src/kudu/fs/log_block_manager.cc
index 3789c38..af182f7 100644
--- a/src/kudu/fs/log_block_manager.cc
+++ b/src/kudu/fs/log_block_manager.cc
@@ -20,6 +20,7 @@
 #include <errno.h>
 
 #include <algorithm>
+#include <cerrno>
 #include <cstddef>
 #include <cstdint>
 #include <map>
@@ -63,7 +64,6 @@
 #include "kudu/util/locks.h"
 #include "kudu/util/malloc.h"
 #include "kudu/util/metrics.h"
-#include "kudu/util/monotime.h"
 #include "kudu/util/path_util.h"
 #include "kudu/util/pb_util.h"
 #include "kudu/util/random.h"
@@ -1500,6 +1500,37 @@ void LogBlockDeletionTransaction::AddBlock(const LogBlockRefPtr& lb) {
 }
 
 ////////////////////////////////////////////////////////////
+// LogBlockContainerLoadResult
+////////////////////////////////////////////////////////////
+
+struct LogBlockContainerLoadResult {
+  Status status;
+  FsReport report;
+
+  // Keep track of containers that have nothing but dead blocks; they will be
+  // deleted during repair.
+  vector<LogBlockContainerRefPtr> dead_containers;
+  // Keep track of containers whose live block ratio is low; their metadata
+  // files will be compacted during repair.
+  unordered_map<string, vector<BlockRecordPB>> low_live_block_containers;
+  // Keep track of deleted blocks whose space hasn't been punched; they will
+  // be repunched during repair.
+  vector<LogBlockRefPtr> need_repunching_blocks;
+
+  LogBlockContainerLoadResult() {
+    // We are going to perform these checks.
+    //
+    // Note: this isn't necessarily the complete set of FsReport checks; there
+    // may be checks that the LBM cannot perform.
+    report.full_container_space_check.emplace();
+    report.incomplete_container_check.emplace();
+    report.malformed_record_check.emplace();
+    report.misaligned_block_check.emplace();
+    report.partial_record_check.emplace();
+  }
+};
+
+////////////////////////////////////////////////////////////
 // LogBlock (definition)
 ////////////////////////////////////////////////////////////
 
@@ -1939,6 +1970,21 @@ LogBlockManager::~LogBlockManager() {
   dd_manager_->WaitOnClosures();
 }
 
+// Ensure that no load task failed without being handled.
+//
+// Currently only disk failures are handled. Reports from failed disks are
+// unusable.
+#define RETURN_ON_NON_DISK_FAILURE(d, s)                        \
+  do {                                                          \
+    if (PREDICT_FALSE(!(s).ok())) {                             \
+      if (!(s).IsDiskFailure()) {                               \
+        return s;                                               \
+      }                                                         \
+      LOG(ERROR) << Substitute("Not using report from $0: $1",  \
+          (d)->dir(), (s).ToString());                          \
+    }                                                           \
+  } while (false)
+
 Status LogBlockManager::Open(FsReport* report) {
   RETURN_NOT_OK(file_cache_.Init());
 
@@ -1981,8 +2027,10 @@ Status LogBlockManager::Open(FsReport* report) {
     InsertOrDie(&block_limits_by_data_dir_, dd.get(), limit);
   }
 
-  vector<FsReport> reports(dd_manager_->data_dirs().size());
+  // Open containers in each data dirs.
   vector<Status> statuses(dd_manager_->data_dirs().size());
+  vector<vector<unique_ptr<internal::LogBlockContainerLoadResult>>> container_results(
+      dd_manager_->data_dirs().size());
   int i = -1;
   for (const auto& dd : dd_manager_->data_dirs()) {
     i++;
@@ -1994,12 +2042,13 @@ Status LogBlockManager::Open(FsReport* report) {
       statuses[i] = Status::IOError("Data directory failed", "", EIO);
       continue;
     }
+
     // Open the data dir asynchronously.
     dd->ExecClosure(
         Bind(&LogBlockManager::OpenDataDir,
              Unretained(this),
              dd.get(),
-             &reports[i],
+             &container_results[i],
              &statuses[i]));
   }
 
@@ -2007,26 +2056,73 @@ Status LogBlockManager::Open(FsReport* report) {
   for (const auto& dd : dd_manager_->data_dirs()) {
     dd->WaitOnClosures();
   }
-  if (dd_manager_->GetFailedDataDirs().size() == dd_manager_->data_dirs().size()) {
-    return Status::IOError("All data dirs failed to open", "", EIO);
+
+  // Check load errors and merge each data dir's container load results, then do repair tasks.
+  vector<unique_ptr<internal::LogBlockContainerLoadResult>> dir_results(
+      dd_manager_->data_dirs().size());
+  for (int i = 0; i < dd_manager_->data_dirs().size(); ++i) {
+    const auto& s = statuses[i];
+    const auto& dd = dd_manager_->data_dirs()[i];
+    RETURN_ON_NON_DISK_FAILURE(dd, s);
+    // If open dir error, do not try to repair.
+    if (PREDICT_FALSE(!s.ok())) {
+      continue;
+    }
+
+    unique_ptr<internal::LogBlockContainerLoadResult> dir_result(
+        new internal::LogBlockContainerLoadResult());
+    dir_result->report.data_dirs.push_back(dd->dir());
+    bool do_repair = true;
+    for (const auto& container_result : container_results[i]) {
+      RETURN_ON_NON_DISK_FAILURE(dd, container_result->status);
+      if (PREDICT_FALSE(!s.ok())) {
+        // If open container error, do not try to repair.
+        do_repair = false;
+        break;
+      }
+
+      dir_result->report.MergeFrom(container_result->report);
+      dir_result->dead_containers.insert(
+          dir_result->dead_containers.end(),
+          container_result->dead_containers.begin(),
+          container_result->dead_containers.end());
+      container_result->dead_containers.clear();
+      dir_result->low_live_block_containers.insert(
+          container_result->low_live_block_containers.begin(),
+          container_result->low_live_block_containers.end());
+      container_result->low_live_block_containers.clear();
+      dir_result->need_repunching_blocks.insert(
+          dir_result->need_repunching_blocks.end(),
+          container_result->need_repunching_blocks.begin(),
+          container_result->need_repunching_blocks.end());
+      container_result->need_repunching_blocks.clear();
+    }
+    if (do_repair) {
+      dir_results[i] = std::move(dir_result);
+      dd->ExecClosure(Bind(&LogBlockManager::RepairTask, Unretained(this),
+                           dd.get(), Unretained(dir_results[i].get())));
+    }
+  }
+
+  // Wait for the repair tasks to complete.
+  for (const auto& dd : dd_manager_->data_dirs()) {
+    dd->WaitOnClosures();
   }
 
-  // Ensure that no open failed without being handled.
-  //
-  // Currently only disk failures are handled. Reports from failed disks are
-  // unusable.
   FsReport merged_report;
-  for (i = 0; i < statuses.size(); i++) {
-    const Status& s = statuses[i];
-    if (PREDICT_TRUE(s.ok())) {
-      merged_report.MergeFrom(reports[i]);
+  for (int i = 0; i < dd_manager_->data_dirs().size(); ++i) {
+    if (PREDICT_FALSE(!dir_results[i])) {
       continue;
     }
-    if (!s.IsDiskFailure()) {
-      return s;
+    if (PREDICT_TRUE(dir_results[i]->status.ok())) {
+      merged_report.MergeFrom(dir_results[i]->report);
+      continue;
     }
-    LOG(ERROR) << Substitute("Not using report from $0: $1",
-        dd_manager_->data_dirs()[i]->dir(), s.ToString());
+    RETURN_ON_NON_DISK_FAILURE(dd_manager_->data_dirs()[i], dir_results[i]->status);
+  }
+
+  if (dd_manager_->GetFailedDataDirs().size() == dd_manager_->data_dirs().size()) {
+    return Status::IOError("All data dirs failed to open", "", EIO);
   }
 
   // Either return or log the report.
@@ -2376,34 +2472,10 @@ Status LogBlockManager::RemoveLogBlock(const BlockId& block_id,
   return Status::OK();
 }
 
-void LogBlockManager::OpenDataDir(DataDir* dir,
-                                  FsReport* report,
-                                  Status* result_status) {
-  FsReport local_report;
-  local_report.data_dirs.push_back(dir->dir());
-
-  // We are going to perform these checks.
-  //
-  // Note: this isn't necessarily the complete set of FsReport checks; there
-  // may be checks that the LBM cannot perform.
-  local_report.full_container_space_check.emplace();
-  local_report.incomplete_container_check.emplace();
-  local_report.malformed_record_check.emplace();
-  local_report.misaligned_block_check.emplace();
-  local_report.partial_record_check.emplace();
-
-  // Keep track of deleted blocks whose space hasn't been punched; they will
-  // be repunched during repair.
-  vector<LogBlockRefPtr> need_repunching;
-
-  // Keep track of containers that have nothing but dead blocks; they will be
-  // deleted during repair.
-  vector<LogBlockContainerRefPtr> dead_containers;
-
-  // Keep track of containers whose live block ratio is low; their metadata
-  // files will be compacted during repair.
-  unordered_map<string, vector<BlockRecordPB>> low_live_block_containers;
-
+void LogBlockManager::OpenDataDir(
+    DataDir* dir,
+    vector<unique_ptr<internal::LogBlockContainerLoadResult>>* results,
+    Status* result_status) {
   // Find all containers and open them.
   unordered_set<string> containers_seen;
   vector<string> children;
@@ -2415,7 +2487,7 @@ void LogBlockManager::OpenDataDir(DataDir* dir,
         "Could not list children of $0", dir->dir()));
     return;
   }
-  MonoTime last_opened_container_log_time = MonoTime::Now();
+
   for (const string& child : children) {
     string container_name;
     if (!TryStripSuffixString(
@@ -2428,14 +2500,16 @@ void LogBlockManager::OpenDataDir(DataDir* dir,
       continue;
     }
 
+    // Add a new result for the container.
+    results->emplace_back(new internal::LogBlockContainerLoadResult());
     LogBlockContainerRefPtr container;
     s = LogBlockContainer::Open(
-        this, dir, &local_report, container_name, &container);
-    if (s.IsAborted()) {
-      // Skip the container. Open() added a record of it to 'local_report' for us.
-      continue;
-    }
+        this, dir, &results->back()->report, container_name, &container);
     if (!s.ok()) {
+      if (s.IsAborted()) {
+        // Skip the container. Open() added a record of it to 'results->back()->report' for us.
+        continue;
+      }
       if (opts_.read_only && s.IsNotFound()) {
         // Skip the container while the operation is read-only and the files are away,
         // especially for the kudu cli tool.
@@ -2446,201 +2520,201 @@ void LogBlockManager::OpenDataDir(DataDir* dir,
       return;
     }
 
-    // Process the records, building a container-local map for live blocks and
-    // a list of dead blocks.
-    //
-    // It's important that we don't try to add these blocks to the global map
-    // incrementally as we see each record, since it's possible that one container
-    // has a "CREATE <b>" while another has a "CREATE <b> ; DELETE <b>" pair.
-    // If we processed those two containers in this order, then upon processing
-    // the second container, we'd think there was a duplicate block. Building
-    // the container-local map first ensures that we discount deleted blocks
-    // before checking for duplicate IDs.
-    //
-    // NOTE: Since KUDU-1538, we allocate sequential block IDs, which makes reuse
-    // exceedingly unlikely. However, we might have old data which still exhibits
-    // the above issue.
-    UntrackedBlockMap live_blocks;
-    BlockRecordMap live_block_records;
-    vector<LogBlockRefPtr> dead_blocks;
-    uint64_t max_block_id = 0;
-    s = container->ProcessRecords(&local_report,
-                                  &live_blocks,
-                                  &live_block_records,
-                                  &dead_blocks,
-                                  &max_block_id);
-    if (!s.ok()) {
-      *result_status = s.CloneAndPrepend(Substitute(
-          "Could not process records in container $0", container->ToString()));
-      return;
+    // Load the container's records asynchronously.
+    dir->ExecClosure(Bind(&LogBlockManager::LoadContainer, Unretained(this),
+                          dir, container, Unretained(results->back().get())));
+  }
+}
+
+void LogBlockManager::LoadContainer(DataDir* dir,
+                                    LogBlockContainerRefPtr container,
+                                    internal::LogBlockContainerLoadResult* result) {
+  // Process the records, building a container-local map for live blocks and
+  // a list of dead blocks.
+  //
+  // It's important that we don't try to add these blocks to the global map
+  // incrementally as we see each record, since it's possible that one container
+  // has a "CREATE <b>" while another has a "CREATE <b> ; DELETE <b>" pair.
+  // If we processed those two containers in this order, then upon processing
+  // the second container, we'd think there was a duplicate block. Building
+  // the container-local map first ensures that we discount deleted blocks
+  // before checking for duplicate IDs.
+  //
+  // NOTE: Since KUDU-1538, we allocate sequential block IDs, which makes reuse
+  // exceedingly unlikely. However, we might have old data which still exhibits
+  // the above issue.
+  UntrackedBlockMap live_blocks;
+  BlockRecordMap live_block_records;
+  vector<LogBlockRefPtr> dead_blocks;
+  uint64_t max_block_id = 0;
+  Status s = container->ProcessRecords(&result->report,
+                                       &live_blocks,
+                                       &live_block_records,
+                                       &dead_blocks,
+                                       &max_block_id);
+  if (!s.ok()) {
+    result->status = s.CloneAndPrepend(Substitute(
+        "Could not process records in container $0", container->ToString()));
+    return;
+  }
+
+  // With deleted blocks out of the way, check for misaligned blocks.
+  //
+  // We could also enforce that the record's offset is aligned with the
+  // underlying filesystem's block size, an invariant maintained by the log
+  // block manager. However, due to KUDU-1793, that invariant may have been
+  // broken, so we'll note but otherwise allow it.
+  for (const auto& e : live_blocks) {
+    if (PREDICT_FALSE(e.second->offset() %
+                      container->instance()->filesystem_block_size_bytes() != 0)) {
+      result->report.misaligned_block_check->entries.emplace_back(
+          container->ToString(), e.first);
+
     }
+  }
 
-    // With deleted blocks out of the way, check for misaligned blocks.
+  if (container->full()) {
+    // Full containers without any live blocks can be deleted outright.
     //
-    // We could also enforce that the record's offset is aligned with the
-    // underlying filesystem's block size, an invariant maintained by the log
-    // block manager. However, due to KUDU-1793, that invariant may have been
-    // broken, so we'll note but otherwise allow it.
-    for (const auto& e : live_blocks) {
-      if (PREDICT_FALSE(e.second->offset() %
-                        container->instance()->filesystem_block_size_bytes() != 0)) {
-        local_report.misaligned_block_check->entries.emplace_back(
-            container->ToString(), e.first);
-
+    // TODO(adar): this should be reported as an inconsistency once dead
+    // container deletion is also done in real time. Until then, it would be
+    // confusing to report it as such since it'll be a natural event at startup.
+    if (container->live_blocks() == 0) {
+      DCHECK(live_blocks.empty());
+      result->dead_containers.emplace_back(container);
+    } else if (static_cast<double>(container->live_blocks()) /
+        container->total_blocks() <= FLAGS_log_container_live_metadata_before_compact_ratio) {
+      // Metadata files of containers with very few live blocks will be compacted.
+      //
+      // TODO(adar): this should be reported as an inconsistency once
+      // container metadata compaction is also done in realtime. Until then,
+      // it would be confusing to report it as such since it'll be a natural
+      // event at startup.
+      vector<BlockRecordPB> records(live_block_records.size());
+      int i = 0;
+      for (auto& e : live_block_records) {
+        records[i].Swap(&e.second);
+        i++;
       }
-    }
 
-    if (container->full()) {
-      // Full containers without any live blocks can be deleted outright.
+      // Sort the records such that their ordering reflects the ordering in
+      // the pre-compacted metadata file.
       //
-      // TODO(adar): this should be reported as an inconsistency once dead
-      // container deletion is also done in real time. Until then, it would be
-      // confusing to report it as such since it'll be a natural event at startup.
-      if (container->live_blocks() == 0) {
-        DCHECK(live_blocks.empty());
-        dead_containers.emplace_back(container);
-      } else if (static_cast<double>(container->live_blocks()) /
-          container->total_blocks() <= FLAGS_log_container_live_metadata_before_compact_ratio) {
-        // Metadata files of containers with very few live blocks will be compacted.
-        //
-        // TODO(adar): this should be reported as an inconsistency once
-        // container metadata compaction is also done in realtime. Until then,
-        // it would be confusing to report it as such since it'll be a natural
-        // event at startup.
-        vector<BlockRecordPB> records(live_block_records.size());
-        int i = 0;
-        for (auto& e : live_block_records) {
-          records[i].Swap(&e.second);
-          i++;
+      // This is preferred to storing the records in an order-preserving
+      // container (such as std::map) because while records are temporarily
+      // retained for every container, only some containers will actually
+      // undergo metadata compaction.
+      std::sort(records.begin(), records.end(),
+                [](const BlockRecordPB& a, const BlockRecordPB& b) {
+        // Sort by timestamp.
+        if (a.timestamp_us() != b.timestamp_us()) {
+          return a.timestamp_us() < b.timestamp_us();
         }
 
-        // Sort the records such that their ordering reflects the ordering in
-        // the pre-compacted metadata file.
+        // If the timestamps match, sort by offset.
         //
-        // This is preferred to storing the records in an order-preserving
-        // container (such as std::map) because while records are temporarily
-        // retained for every container, only some containers will actually
-        // undergo metadata compaction.
-        std::sort(records.begin(), records.end(),
-                  [](const BlockRecordPB& a, const BlockRecordPB& b) {
-          // Sort by timestamp.
-          if (a.timestamp_us() != b.timestamp_us()) {
-            return a.timestamp_us() < b.timestamp_us();
-          }
-
-          // If the timestamps match, sort by offset.
-          //
-          // If the offsets also match (i.e. both blocks are of zero length),
-          // it doesn't matter which of the two records comes first.
-          return a.offset() < b.offset();
-        });
-
-        low_live_block_containers[container->ToString()] = std::move(records);
-      }
+        // If the offsets also match (i.e. both blocks are of zero length),
+        // it doesn't matter which of the two records comes first.
+        return a.offset() < b.offset();
+      });
 
-      // Having processed the block records, let's check whether any full
-      // containers have any extra space (left behind after a crash or from an
-      // older version of Kudu).
-      //
-      // Filesystems are unpredictable beasts and may misreport the amount of
-      // space allocated to a file in various interesting ways. Some examples:
-      // - XFS's speculative preallocation feature may artificially enlarge the
-      //   container's data file without updating its file size. This makes the
-      //   file size untrustworthy for the purposes of measuring allocated space.
-      //   See KUDU-1856 for more details.
-      // - On el6.6/ext4 a container data file that consumed ~32K according to
-      //   its extent tree was actually reported as consuming an additional fs
-      //   block (2k) of disk space. A similar container data file (generated
-      //   via the same workload) on Ubuntu 16.04/ext4 did not exhibit this.
-      //   The suspicion is that older versions of ext4 include interior nodes
-      //   of the extent tree when reporting file block usage.
-      //
-      // To deal with these issues, our extra space cleanup code (deleted block
-      // repunching and container truncation) is gated on an "actual disk space
-      // consumed" heuristic. To prevent unnecessary triggering of the
-      // heuristic, we allow for some slop in our size measurements. The exact
-      // amount of slop is configurable via
-      // log_container_excess_space_before_cleanup_fraction.
-      //
-      // Too little slop and we'll do unnecessary work at startup. Too much and
-      // more unused space may go unreclaimed.
-      string data_filename = StrCat(container->ToString(), kContainerDataFileSuffix);
-      uint64_t reported_size;
-      s = env_->GetFileSizeOnDisk(data_filename, &reported_size);
-      if (!s.ok()) {
-        HANDLE_DISK_FAILURE(s, error_manager_->RunErrorNotificationCb(
-            ErrorHandlerType::DISK_ERROR, dir));
-        *result_status = s.CloneAndPrepend(Substitute(
-            "Could not get on-disk file size of container $0", container->ToString()));
-        return;
-      }
-      int64_t cleanup_threshold_size = container->live_bytes_aligned() *
-          (1 + FLAGS_log_container_excess_space_before_cleanup_fraction);
-      if (reported_size > cleanup_threshold_size) {
-        local_report.full_container_space_check->entries.emplace_back(
-            container->ToString(), reported_size - container->live_bytes_aligned());
-
-        // If the container is to be deleted outright, don't bother repunching
-        // its blocks. The report entry remains, however, so it's clear that
-        // there was a space discrepancy.
-        if (container->live_blocks()) {
-          need_repunching.insert(need_repunching.end(),
-                                 dead_blocks.begin(), dead_blocks.end());
-        }
-      }
+      result->low_live_block_containers[container->ToString()] = std::move(records);
+    }
 
-      local_report.stats.lbm_full_container_count++;
+    // Having processed the block records, let's check whether any full
+    // containers have any extra space (left behind after a crash or from an
+    // older version of Kudu).
+    //
+    // Filesystems are unpredictable beasts and may misreport the amount of
+    // space allocated to a file in various interesting ways. Some examples:
+    // - XFS's speculative preallocation feature may artificially enlarge the
+    //   container's data file without updating its file size. This makes the
+    //   file size untrustworthy for the purposes of measuring allocated space.
+    //   See KUDU-1856 for more details.
+    // - On el6.6/ext4 a container data file that consumed ~32K according to
+    //   its extent tree was actually reported as consuming an additional fs
+    //   block (2k) of disk space. A similar container data file (generated
+    //   via the same workload) on Ubuntu 16.04/ext4 did not exhibit this.
+    //   The suspicion is that older versions of ext4 include interior nodes
+    //   of the extent tree when reporting file block usage.
+    //
+    // To deal with these issues, our extra space cleanup code (deleted block
+    // repunching and container truncation) is gated on an "actual disk space
+    // consumed" heuristic. To prevent unnecessary triggering of the
+    // heuristic, we allow for some slop in our size measurements. The exact
+    // amount of slop is configurable via
+    // log_container_excess_space_before_cleanup_fraction.
+    //
+    // Too little slop and we'll do unnecessary work at startup. Too much and
+    // more unused space may go unreclaimed.
+    string data_filename = StrCat(container->ToString(), kContainerDataFileSuffix);
+    uint64_t reported_size;
+    s = env_->GetFileSizeOnDisk(data_filename, &reported_size);
+    if (!s.ok()) {
+      HANDLE_DISK_FAILURE(s, error_manager_->RunErrorNotificationCb(
+          ErrorHandlerType::DISK_ERROR, dir));
+      result->status = s.CloneAndPrepend(Substitute(
+          "Could not get on-disk file size of container $0", container->ToString()));
+      return;
     }
-    local_report.stats.live_block_bytes += container->live_bytes();
-    local_report.stats.live_block_bytes_aligned += container->live_bytes_aligned();
-    local_report.stats.live_block_count += container->live_blocks();
-    local_report.stats.lbm_container_count++;
-
-    // Log number of containers opened every 10 seconds
-    MonoTime now = MonoTime::Now();
-    if ((now - last_opened_container_log_time).ToSeconds() > 10) {
-      LOG(INFO) << Substitute("Opened $0 log block containers in $1",
-                              local_report.stats.lbm_container_count, dir->dir());
-      last_opened_container_log_time = now;
+    int64_t cleanup_threshold_size = container->live_bytes_aligned() *
+        (1 + FLAGS_log_container_excess_space_before_cleanup_fraction);
+    if (reported_size > cleanup_threshold_size) {
+      result->report.full_container_space_check->entries.emplace_back(
+          container->ToString(), reported_size - container->live_bytes_aligned());
+
+      // If the container is to be deleted outright, don't bother repunching
+      // its blocks. The report entry remains, however, so it's clear that
+      // there was a space discrepancy.
+      if (container->live_blocks()) {
+        result->need_repunching_blocks.insert(result->need_repunching_blocks.end(),
+                                              dead_blocks.begin(), dead_blocks.end());
+      }
     }
 
-    next_block_id_.StoreMax(max_block_id + 1);
+    result->report.stats.lbm_full_container_count++;
+  }
+  result->report.stats.live_block_bytes += container->live_bytes();
+  result->report.stats.live_block_bytes_aligned += container->live_bytes_aligned();
+  result->report.stats.live_block_count += container->live_blocks();
+  result->report.stats.lbm_container_count++;
 
-    int64_t mem_usage = 0;
-    for (UntrackedBlockMap::value_type& e : live_blocks) {
-      int block_mem = kudu_malloc_usable_size(e.second.get());
-      if (!AddLogBlock(std::move(e.second))) {
-        // TODO(adar): track as an inconsistency?
-        LOG(FATAL) << "Found duplicate CREATE record for block " << e.first
-                   << " which already is alive from another container when "
-                   << " processing container " << container->ToString();
-      }
-      mem_usage += block_mem;
+  next_block_id_.StoreMax(max_block_id + 1);
+
+  int64_t mem_usage = 0;
+  for (UntrackedBlockMap::value_type& e : live_blocks) {
+    int block_mem = kudu_malloc_usable_size(e.second.get());
+    if (!AddLogBlock(std::move(e.second))) {
+      // TODO(adar): track as an inconsistency?
+      LOG(FATAL) << "Found duplicate CREATE record for block " << e.first
+                 << " which already is alive from another container when "
+                 << " processing container " << container->ToString();
     }
+    mem_usage += block_mem;
+  }
 
-    mem_tracker_->Consume(mem_usage);
+  mem_tracker_->Consume(mem_usage);
 
+  int64_t container_count = 0;
+  {
     std::lock_guard<simple_spinlock> l(lock_);
     AddNewContainerUnlocked(container);
     MakeContainerAvailableUnlocked(std::move(container));
+    container_count = all_containers_by_name_.size();
   }
 
-  // Like the rest of Open(), repairs are performed per data directory to take
-  // advantage of parallelism.
-  s = Repair(dir,
-             &local_report,
-             std::move(need_repunching),
-             std::move(dead_containers),
-             std::move(low_live_block_containers));
-  if (!s.ok()) {
-    *result_status = s.CloneAndPrepend(Substitute(
-        "fatal error while repairing inconsistencies in data directory $0",
-        dir->dir()));
-    return;
+  // Log every 200 number of log block containers
+  if (container_count % 200 == 0) {
+    LOG(INFO) << Substitute("Opened $0 log block containers", container_count);
   }
+}
 
-  *report = std::move(local_report);
-  *result_status = Status::OK();
+void LogBlockManager::RepairTask(DataDir* dir, internal::LogBlockContainerLoadResult* result) {
+  result->status = Repair(dir,
+                          &result->report,
+                          std::move(result->need_repunching_blocks),
+                          std::move(result->dead_containers),
+                          std::move(result->low_live_block_containers));
 }
 
 #define RETURN_NOT_OK_LBM_DISK_FAILURE_PREPEND(status_expr, msg) do { \
diff --git a/src/kudu/fs/log_block_manager.h b/src/kudu/fs/log_block_manager.h
index 7631042..3c26f90 100644
--- a/src/kudu/fs/log_block_manager.h
+++ b/src/kudu/fs/log_block_manager.h
@@ -59,6 +59,7 @@ class LogBlock;
 class LogBlockContainer;
 class LogBlockDeletionTransaction;
 class LogWritableBlock;
+struct LogBlockContainerLoadResult;
 struct LogBlockManagerMetrics;
 } // namespace internal
 
@@ -328,6 +329,9 @@ class LogBlockManager : public BlockManager {
   Status RemoveLogBlock(const BlockId& block_id,
                         LogBlockRefPtr* lb);
 
+  // Simple wrapper of Repair(), used as a runnable function in thread.
+  void RepairTask(DataDir* dir, internal::LogBlockContainerLoadResult* result);
+
   // Repairs any inconsistencies for 'dir' described in 'report'.
   //
   // The following additional repairs will be performed:
@@ -358,14 +362,19 @@ class LogBlockManager : public BlockManager {
                              int64_t* file_bytes_delta);
 
   // Opens a particular data directory belonging to the block manager. The
-  // results of consistency checking (and repair, if applicable) are written to
-  // 'report'.
+  // results of consistency checking are written to 'results'.
   //
   // Success or failure is set in 'result_status'.
   void OpenDataDir(DataDir* dir,
-                   FsReport* report,
+                   std::vector<std::unique_ptr<internal::LogBlockContainerLoadResult>>* results,
                    Status* result_status);
 
+  // Reads records from one log block container in the data directory.
+  // The result details will be collected into 'result'.
+  void LoadContainer(DataDir* dir,
+                     LogBlockContainerRefPtr container,
+                     internal::LogBlockContainerLoadResult* result);
+
   // Perform basic initialization.
   Status Init();
 


[kudu] 04/05: KUDU-1938 Add VARCHAR to tooling and helpers pt 7

Posted by ad...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

adar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit 7f0a4a2dc4de9c1afed979552015fcd66c294f77
Author: Attila Bukor <ab...@apache.org>
AuthorDate: Fri Dec 6 14:35:25 2019 -0800

    KUDU-1938 Add VARCHAR to tooling and helpers pt 7
    
    VARCHAR support was missing from some tools and helpers, adding them
    here.
    
    Change-Id: I84257c71528dafdf9c01c0d3cdda44a626ed7f67
    Reviewed-on: http://gerrit.cloudera.org:8080/14831
    Tested-by: Kudu Jenkins
    Reviewed-by: Adar Dembo <ad...@cloudera.com>
---
 src/kudu/common/row.h               | 10 ++++++++++
 src/kudu/tools/tool_action_perf.cc  |  8 +++++++-
 src/kudu/tools/tool_action_table.cc | 17 ++++++++++++++---
 3 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/src/kudu/common/row.h b/src/kudu/common/row.h
index 846ba02..3ffffcd 100644
--- a/src/kudu/common/row.h
+++ b/src/kudu/common/row.h
@@ -618,6 +618,16 @@ class RowBuilder {
     AddSlice(str);
   }
 
+  void AddVarchar(const Slice &slice) {
+    CheckNextType(VARCHAR);
+    AddSlice(slice);
+  }
+
+  void AddVarchar(const std::string &str) {
+    CheckNextType(VARCHAR);
+    AddSlice(str);
+  }
+
   void AddInt8(int8_t val) {
     CheckNextType(INT8);
     *reinterpret_cast<int8_t *>(&buf_[byte_idx_]) = val;
diff --git a/src/kudu/tools/tool_action_perf.cc b/src/kudu/tools/tool_action_perf.cc
index 9b83122..5ccd814 100644
--- a/src/kudu/tools/tool_action_perf.cc
+++ b/src/kudu/tools/tool_action_perf.cc
@@ -175,11 +175,11 @@
 #include <string>
 #include <thread>
 #include <unordered_map>
+#include <utility>
 #include <vector>
 
 #include <boost/optional/optional.hpp>
 #include <gflags/gflags.h>
-#include <gflags/gflags_declare.h>
 #include <glog/logging.h>
 
 #include "kudu/client/client.h"
@@ -499,6 +499,12 @@ Status GenerateRowData(Generator* gen, KuduPartialRow* row,
           RETURN_NOT_OK(row->SetStringNoCopy(idx, fixed_string));
         }
         break;
+      case VARCHAR:
+        if (fixed_string.empty()) {
+          RETURN_NOT_OK(row->SetVarchar(idx, gen->Next<string>()));
+        } else {
+          RETURN_NOT_OK(row->SetStringNoCopy(idx, fixed_string));
+        }
       default:
         return Status::InvalidArgument("unknown data type");
     }
diff --git a/src/kudu/tools/tool_action_table.cc b/src/kudu/tools/tool_action_table.cc
index aaa6d70..54a1650 100644
--- a/src/kudu/tools/tool_action_table.cc
+++ b/src/kudu/tools/tool_action_table.cc
@@ -29,8 +29,8 @@
 #include <boost/algorithm/string/predicate.hpp>
 #include <boost/optional/optional.hpp>
 #include <gflags/gflags.h>
-#include <gflags/gflags_declare.h>
 #include <glog/logging.h>
+#include <google/protobuf/stubs/common.h>
 #include <google/protobuf/stubs/status.h>
 #include <google/protobuf/stubs/stringpiece.h>
 #include <google/protobuf/util/json_util.h>
@@ -287,7 +287,8 @@ Status LocateRow(const RunnerContext& context) {
         break;
       }
       case KuduColumnSchema::BINARY:
-      case KuduColumnSchema::STRING: {
+      case KuduColumnSchema::STRING:
+      case KuduColumnSchema::VARCHAR: {
         string value;
         RETURN_NOT_OK_PREPEND(
             reader.ExtractString(values[i], /*field=*/nullptr, &value),
@@ -586,6 +587,13 @@ Status ConvertToKuduPartialRow(
         RETURN_NOT_OK(range_bound_partial_row->SetString(col_name, value));
         break;
       }
+      case KuduColumnSchema::VARCHAR: {
+        string value;
+        RETURN_NOT_OK_PREPEND(
+          reader.ExtractString(values[i], /*field=*/nullptr, &value),
+          error_msg);
+        RETURN_NOT_OK(range_bound_partial_row->SetVarchar(col_name, value));
+      }
       case KuduColumnSchema::BOOL:
       case KuduColumnSchema::FLOAT:
       case KuduColumnSchema::DOUBLE:
@@ -714,7 +722,8 @@ Status ParseValueOfType(const string& default_value,
       break;
     }
     case KuduColumnSchema::DataType::BINARY:
-    case KuduColumnSchema::DataType::STRING: {
+    case KuduColumnSchema::DataType::STRING:
+    case KuduColumnSchema::DataType::VARCHAR: {
       string str_value;
       RETURN_NOT_OK_PREPEND(
         reader.ExtractString(values[0], /*field=*/nullptr, &str_value), msg);
@@ -891,6 +900,7 @@ Status ToJsonPartialRow(const RepeatedPtrField<string>& values,
   string joined = JoinMapped(values, [&](const string& v) {
     auto data_type = range_columns[i++].second;
     if (data_type == KuduColumnSchema::STRING ||
+        data_type == KuduColumnSchema::VARCHAR ||
         data_type == KuduColumnSchema::BINARY) {
       return "\"" + v + "\"";
     }
@@ -996,6 +1006,7 @@ Status ParseTableSchema(const SchemaPB& schema,
       string default_v;
       if (column.column_type() == "STRING" ||
           column.column_type() == "BINARY" ||
+          column.column_type() == "VARCHAR" ||
           column.column_type() == "DECIMAL") {
         default_v = "[\"" + column.default_value() + "\"]";
       } else {


[kudu] 01/05: [build-support] fix on enable_devtoolset_inner.sh, take two

Posted by ad...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

adar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit 5b9289a6c90bfe7ebed5510aacf45f7005c64490
Author: Alexey Serbin <al...@apache.org>
AuthorDate: Tue Dec 3 19:03:05 2019 -0800

    [build-support] fix on enable_devtoolset_inner.sh, take two
    
    Prior to this fix, when configuring a build via cmake as described at
    https://kudu.apache.org/docs/installation.html#build_from_source,
    the following error was output (at least by bash 4.1.2):
    
      build-support/enable_devtoolset_inner.sh: line 28: [: too many arguments
    
    This is a follow-up to 719418a60235a5155efe95c37e9fc6e319f41e0c.
    
    Change-Id: I8de79a99a5386e47e968ca9e8f6939159b06fbda
    Reviewed-on: http://gerrit.cloudera.org:8080/14825
    Tested-by: Kudu Jenkins
    Reviewed-by: Andrew Wong <aw...@cloudera.com>
---
 build-support/enable_devtoolset_inner.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/build-support/enable_devtoolset_inner.sh b/build-support/enable_devtoolset_inner.sh
index 5866ab2..0b0ba91 100755
--- a/build-support/enable_devtoolset_inner.sh
+++ b/build-support/enable_devtoolset_inner.sh
@@ -25,7 +25,7 @@ set -e
 
 # If ccache was on the PATH and CC/CXX have not already been set, set them to
 # devtoolset-3 specific ccache helper scripts (thus enabling ccache).
-if which ccache > /dev/null 2>&1 && [ -a ! "$CC" -a ! "$CXX" ]; then
+if which ccache > /dev/null 2>&1 && [ ! "$CC" -a ! "$CXX" ]; then
   ROOT=$(cd $(dirname "$BASH_SOURCE") ; pwd)
   export CC="$ROOT/ccache-devtoolset-3/cc"
   export CXX="$ROOT/ccache-devtoolset-3/c++"