kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [2/2] kudu git commit: catalog_manager: avoid race in InitSysCatalogAsync() and GetTabletPeer()
Date Tue, 16 Aug 2016 18:41:41 GMT
catalog_manager: avoid race in InitSysCatalogAsync() and GetTabletPeer()

Commit 2525ad0 took a stab at this, but it doesn't handle the case where
InitSysCatalogAsync() fails and leaves behind sys_catalog_ without a
functional tablet peer, as in the new integration test
MasterReplicationTest.TestMasterPeerSetsDontMatch. So here's another
attempt, where sys_catalog_ is only set when it is fully formed (i.e. when
it has a functional TabletPeer).

It turns out this isn't enough; we also need to prevent ElectedAsLeaderCb
from making progress until InitSysCatalogAsync() sets sys_catalog_. The
extra lock acquisition is hacky in that it doesn't explicitly protect
anything, but it gets the job done.

Below I've included test output when the race hits.

master_replication-itest: /home/jenkins-slave/workspace/kudu-3/src/kudu/gutil/ref_counted.h:273:
T *scoped_refptr<kudu::tablet::TabletPeer>::operator->() const [T = kudu::tablet::TabletPeer]:
Assertion `ptr_ != __null' failed.
*** Aborted at 1471309445 (unix time) try "date -d @1471309445" if you are using GNU date
***
PC: @     0x7f330225dcc9 gsignal
*** SIGABRT (@0x3e800006e90) received by PID 28304 (TID 0x7f32f06eb700) from PID 28304; stack
trace: ***
    @           0x42e687 __tsan::CallUserSignalHandler() at /home/jenkins-slave/workspace/kudu-3/thirdparty/llvm-3.8.0.src/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:1962
    @           0x42f4d3 rtl_sigaction() at /home/jenkins-slave/workspace/kudu-3/thirdparty/llvm-3.8.0.src/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:2039
    @     0x7f33090a4340 (unknown) at ??:0
    @     0x7f330225dcc9 gsignal at ??:0
    @     0x7f33022610d8 abort at ??:0
    @     0x7f3302256b86 (unknown) at ??:0
    @     0x7f3302256c32 __assert_fail at ??:0
    @     0x7f330ca13130 scoped_refptr<>::operator->() at ??:0
    @     0x7f330ca1a952 kudu::master::SysCatalogTable::tablet_id() at ??:0
    @     0x7f330ca0b136 kudu::master::CatalogManager::GetTabletPeer() at ??:0
    @     0x7f330c69214d kudu::tserver::(anonymous namespace)::LookupTabletPeerOrRespond<>()
at ??:0
    @     0x7f330c691bab kudu::tserver::ConsensusServiceImpl::RequestConsensusVote() at ??:0
    @     0x7f3307c9fca5 kudu::consensus::ConsensusServiceIf::ConsensusServiceIf()::$_1::operator()()
at ??:0
    @     0x7f3307c9fabf std::_Function_handler<>::_M_invoke() at ??:0
    @     0x7f3306bd7219 std::function<>::operator()() at ??:0
    @     0x7f3306bd6c8e kudu::rpc::GeneratedServiceIf::Handle() at ??:0
    @     0x7f3306bd8b3e kudu::rpc::ServicePool::RunThread() at ??:0
    @     0x7f3306bdaa27 boost::_mfi::mf0<>::operator()() at ??:0
    @     0x7f3306bda98b boost::_bi::list1<>::operator()<>() at ??:0
    @     0x7f3306bda934 boost::_bi::bind_t<>::operator()() at ??:0
    @     0x7f3306bda75a boost::detail::function::void_function_obj_invoker0<>::invoke()
at ??:0
    @     0x7f3306b758b2 boost::function0<>::operator()() at ??:0
    @     0x7f3304962630 kudu::Thread::SuperviseThread() at ??:0

Change-Id: I43fdc6499cb84d2053bed08b689fe5a08a6761d6
Reviewed-on: http://gerrit.cloudera.org:8080/3997
Tested-by: Kudu Jenkins
Reviewed-by: Todd Lipcon <todd@apache.org>


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

Branch: refs/heads/master
Commit: a5a192a48f12cc8ae87ad3c7568d41bf6e657d0b
Parents: f7201a9
Author: Adar Dembo <adar@cloudera.com>
Authored: Mon Aug 15 18:27:48 2016 -0700
Committer: Adar Dembo <adar@cloudera.com>
Committed: Tue Aug 16 18:41:11 2016 +0000

----------------------------------------------------------------------
 src/kudu/master/catalog_manager.cc | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/a5a192a4/src/kudu/master/catalog_manager.cc
----------------------------------------------------------------------
diff --git a/src/kudu/master/catalog_manager.cc b/src/kudu/master/catalog_manager.cc
index 6d756fe..b11218e 100644
--- a/src/kudu/master/catalog_manager.cc
+++ b/src/kudu/master/catalog_manager.cc
@@ -618,6 +618,10 @@ Status CatalogManager::WaitUntilCaughtUpAsLeader(const MonoDelta&
timeout) {
 }
 
 void CatalogManager::VisitTablesAndTabletsTask() {
+  {
+    // Hack to block this function until InitSysCatalogAsync() is finished.
+    shared_lock<LockType> l(lock_);
+  }
   Consensus* consensus = sys_catalog_->tablet_peer()->consensus();
   int64_t term = consensus->ConsensusState(CONSENSUS_CONFIG_COMMITTED).current_term();
   {
@@ -693,15 +697,17 @@ Status CatalogManager::VisitTablesAndTablets() {
 
 Status CatalogManager::InitSysCatalogAsync(bool is_first_run) {
   std::lock_guard<LockType> l(lock_);
-  sys_catalog_.reset(new SysCatalogTable(master_,
-                                         master_->metric_registry(),
-                                         Bind(&CatalogManager::ElectedAsLeaderCb,
-                                              Unretained(this))));
+  unique_ptr<SysCatalogTable> new_catalog(
+      new SysCatalogTable(master_,
+                          master_->metric_registry(),
+                          Bind(&CatalogManager::ElectedAsLeaderCb,
+                               Unretained(this))));
   if (is_first_run) {
-    RETURN_NOT_OK(sys_catalog_->CreateNew(master_->fs_manager()));
+    RETURN_NOT_OK(new_catalog->CreateNew(master_->fs_manager()));
   } else {
-    RETURN_NOT_OK(sys_catalog_->Load(master_->fs_manager()));
+    RETURN_NOT_OK(new_catalog->Load(master_->fs_manager()));
   }
+  sys_catalog_.reset(new_catalog.release());
   return Status::OK();
 }
 


Mime
View raw message