transactions: check tablet before checking stopped
transactions: check tablet before checking stopped

This patch cleans up an unsafe pointer access to Tablet by using the
commonly-used pattern of grabbing a std::shared_ptr<Tablet> and
operating on it within an appropriate scope.

Previously, I saw one failure in multiple thousands of dist-test runs of
an upcoming disk failure test case in exactly_once_writes-itest caused
by this:

*** Aborted at 1511907337 (unix time) try "date -d @1511907337" if you are using GNU date ***
PC: @           0x4a327b __tsan_atomic32_compare_exchange_strong
*** SIGSEGV (@0x240) received by PID 11526 (TID 0x7f5a1a6f8700) from PID 576; stack trace: ***
    @           0x44c8e2 __tsan::CallUserSignalHandler() at
    @           0x44d84d rtl_sigaction() at
    @     0x7f5a3a1e9330 (unknown) at
    @           0x4a327b __tsan_atomic32_compare_exchange_strong at
    @     0x7f5a3e95ca74 base::SpinLock::Lock() at
    @     0x7f5a3e95ca19 kudu::simple_spinlock::lock() at
    @     0x7f5a3d42f055 kudu::tablet::Tablet::HasBeenStopped() at
    @     0x7f5a3d547015 kudu::tablet::TransactionDriver::Init() at
    @     0x7f5a3d520441 kudu::tablet::TabletReplica::NewLeaderTransactionDriver() at
    @     0x7f5a3d51fea9 kudu::tablet::TabletReplica::SubmitWrite() at
    @     0x7f5a3ea0edad kudu::tserver::TabletServiceImpl::Write() at
    @     0x7f5a38cea594 kudu::tserver::TabletServerServiceIf::TabletServerServiceIf()::$_3::operator()() at
    @     0x7f5a38cea4c9 _ZNSt3__128__invoke_void_return_wrapperIvE6__callIJRZN4kudu7tserver21TabletServerServiceIfC1ERK13scoped_refptrINS3_12MetricEntityEERKS6_INS3_3rpc13ResultTrackerEEE3$_3PKN6google8protobuf7MessageEPSK_PNSB_10RpcContextEEEEvDpOT_ at
    @     0x7f5a38cea228 std::__1::__function::__func<>::operator()() at
    @     0x7f5a37d6b023 std::__1::function<>::operator()() at
    @     0x7f5a37d69fba kudu::rpc::GeneratedServiceIf::Handle() at
    @     0x7f5a37d6e9f1 kudu::rpc::ServicePool::RunThread() at
    @     0x7f5a37d734a4 boost::_mfi::mf0<>::operator()() at
    @     0x7f5a37d7335e boost::_bi::list1<>::operator()<>() at
    @     0x7f5a37d732a2 boost::_bi::bind_t<>::operator()() at
    @     0x7f5a37d72e91 boost::detail::function::void_function_obj_invoker0<>::invoke() at
    @     0x7f5a37ca0549 boost::function0<>::operator()() at
    @     0x7f5a360b225e kudu::Thread::SuperviseThread() at
    @           0x44c7bc __tsan_thread_start_func at
    @     0x7f5a3a1e1184 start_thread at
    @     0x7f5a32273ffd clone at
    @                0x0 (unknown)

Change-Id: I4821554e76c987fb8548384462b960f5c3b2c75f
Reviewed-on: http://gerrit.cloudera.org:8080/8673
Tested-by: Kudu Jenkins
Reviewed-by: Mike Percy <e07a1fd797b473a9c849e618aa2ce06d8055760b@apache.org>

EvilMcJerkface/kudu,andrwng/kudu,InspurUSA/kudu,helifu/kudu,helifu/kudu,EvilMcJerkface/kudu,cloudera/kudu,andrwng/kudu,helifu/kudu,InspurUSA/kudu,andrwng/kudu,andrwng/kudu,cloudera/kudu,InspurUSA/kudu,EvilMcJerkface/kudu,EvilMcJerkface/kudu,cloudera/kudu,andrwng/kudu,EvilMcJerkface/kudu,helifu/kudu,InspurUSA/kudu,andrwng/kudu,cloudera/kudu,cloudera/kudu,andrwng/kudu,InspurUSA/kudu,EvilMcJerkface/kudu,cloudera/kudu,InspurUSA/kudu,cloudera/kudu,EvilMcJerkface/kudu,InspurUSA/kudu,helifu/kudu,InspurUSA/kudu,helifu/kudu,andrwng/kudu,andrwng/kudu,InspurUSA/kudu,EvilMcJerkface/kudu,cloudera/kudu,cloudera/kudu,helifu/kudu,helifu/kudu,helifu/kudu,EvilMcJerkface/kudu