kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [kudu] 03/03: KUDU-3070 skip open block manager
Date Tue, 10 Mar 2020 21:41:54 GMT
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 1b3b26d957e2944ff3197eea4ee99dec22640721
Author: wangning <1994wangning@gmail.com>
AuthorDate: Fri Mar 6 21:08:28 2020 +0800

    KUDU-3070 skip open block manager
    
    In some cli ops (e.g. local_replica cmeta rewrite_raft_config), open
    block manager is not necessary.
    
    Change-Id: Ifaec03512086430a6270c458269da1cf996fd9c5
    Reviewed-on: http://gerrit.cloudera.org:8080/15380
    Reviewed-by: Adar Dembo <adar@cloudera.com>
    Tested-by: Kudu Jenkins
    Reviewed-by: Andrew Wong <awong@cloudera.com>
---
 src/kudu/fs/fs_manager.cc                   | 20 +++++++++++++-------
 src/kudu/fs/fs_manager.h                    |  7 +++++++
 src/kudu/tools/tool_action_local_replica.cc |  4 +++-
 3 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/src/kudu/fs/fs_manager.cc b/src/kudu/fs/fs_manager.cc
index a60b922..127f0ba 100644
--- a/src/kudu/fs/fs_manager.cc
+++ b/src/kudu/fs/fs_manager.cc
@@ -141,7 +141,8 @@ FsManagerOpts::FsManagerOpts()
     block_manager_type(FLAGS_block_manager),
     read_only(false),
     update_instances(UpdateInstanceBehavior::UPDATE_AND_IGNORE_FAILURES),
-    file_cache(nullptr) {
+    file_cache(nullptr),
+    skip_block_manager(false) {
   data_roots = strings::Split(FLAGS_fs_data_dirs, ",", strings::SkipEmpty());
 }
 
@@ -151,7 +152,8 @@ FsManagerOpts::FsManagerOpts(const string& root)
     block_manager_type(FLAGS_block_manager),
     read_only(false),
     update_instances(UpdateInstanceBehavior::UPDATE_AND_IGNORE_FAILURES),
-    file_cache(nullptr) {}
+    file_cache(nullptr),
+    skip_block_manager(false) {}
 
 FsManager::FsManager(Env* env, FsManagerOpts opts)
   : env_(DCHECK_NOTNULL(env)),
@@ -425,10 +427,12 @@ Status FsManager::Open(FsReport* report) {
   error_manager_->SetErrorNotificationCb(ErrorHandlerType::DISK_ERROR,
       Bind(&DataDirManager::MarkDirFailedByUuid, Unretained(dd_manager_.get())));
 
-  // Finally, initialize and open the block manager.
-  InitBlockManager();
-  LOG_TIMING(INFO, "opening block manager") {
-    RETURN_NOT_OK(block_manager_->Open(report));
+  // Finally, initialize and open the block manager if needed.
+  if (!opts_.skip_block_manager) {
+    InitBlockManager();
+    LOG_TIMING(INFO, "opening block manager") {
+      RETURN_NOT_OK(block_manager_->Open(report));
+    }
   }
 
   // Report wal and metadata directories.
@@ -763,15 +767,17 @@ void FsManager::DumpFileSystemTree(ostream& out, const string&
prefix,
 
 Status FsManager::CreateNewBlock(const CreateBlockOptions& opts, unique_ptr<WritableBlock>*
block) {
   CHECK(!opts_.read_only);
-
+  DCHECK(block_manager_);
   return block_manager_->CreateBlock(opts, block);
 }
 
 Status FsManager::OpenBlock(const BlockId& block_id, unique_ptr<ReadableBlock>*
block) {
+  DCHECK(block_manager_);
   return block_manager_->OpenBlock(block_id, block);
 }
 
 bool FsManager::BlockExists(const BlockId& block_id) const {
+  DCHECK(block_manager_);
   unique_ptr<ReadableBlock> block;
   return block_manager_->OpenBlock(block_id, &block).ok();
 }
diff --git a/src/kudu/fs/fs_manager.h b/src/kudu/fs/fs_manager.h
index c719be7..7577d06 100644
--- a/src/kudu/fs/fs_manager.h
+++ b/src/kudu/fs/fs_manager.h
@@ -130,6 +130,12 @@ struct FsManagerOpts {
   //
   // Defaults to null.
   FileCache* file_cache;
+
+  // Whether or not to skip opening the block manager. FsManager operations that
+  // require the block manager will crash.
+  //
+  // Default to false.
+  bool skip_block_manager;
 };
 
 // FsManager provides helpers to read data and metadata files,
@@ -286,6 +292,7 @@ class FsManager {
   }
 
   fs::BlockManager* block_manager() {
+    DCHECK(block_manager_);
     return block_manager_.get();
   }
 
diff --git a/src/kudu/tools/tool_action_local_replica.cc b/src/kudu/tools/tool_action_local_replica.cc
index 36b1005..07858e2 100644
--- a/src/kudu/tools/tool_action_local_replica.cc
+++ b/src/kudu/tools/tool_action_local_replica.cc
@@ -284,7 +284,9 @@ Status RewriteRaftConfig(const RunnerContext& context) {
 
   // Make a copy of the old file before rewriting it.
   Env* env = Env::Default();
-  FsManager fs_manager(env, FsManagerOpts());
+  FsManagerOpts fs_opts = FsManagerOpts();
+  fs_opts.skip_block_manager = true;
+  FsManager fs_manager(env, std::move(fs_opts));
   RETURN_NOT_OK(fs_manager.Open());
   RETURN_NOT_OK(BackupConsensusMetadata(&fs_manager, tablet_id));
 


Mime
View raw message