diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-11-18 22:44:04 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-11-20 10:16:58 +0000 |
commit | 55069682323b0c204b2ddda696bfcd33f4e47a64 (patch) | |
tree | 508042cdb977ec9ea3c6323e8727aa149e09ba54 /searchcore | |
parent | 95432b0ec4be8e844fe5433598a9045d0de08fef (diff) |
Use C++11 chrono instead prehistoric homegrown stuff.
Diffstat (limited to 'searchcore')
-rw-r--r-- | searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.cpp | 30 | ||||
-rw-r--r-- | searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.h | 27 |
2 files changed, 21 insertions, 36 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.cpp b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.cpp index 19175d1e2c7..5598b80b1ca 100644 --- a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.cpp @@ -2,7 +2,6 @@ #include "transactionlogmanagerbase.h" #include <vespa/vespalib/util/stringfmt.h> -#include <vespa/fastos/time.h> #include <vespa/log/log.h> LOG_SETUP(".proton.server.transactionlogmanagerbase"); @@ -21,7 +20,7 @@ TransactionLogManagerBase::TransactionLogManagerBase( _replayCond(), _replayDone(false), _replayStarted(false), - _replayStartTime(0) + _replayStopWatch() { } @@ -31,7 +30,7 @@ TransactionLogManagerBase::StatusResult TransactionLogManagerBase::init() { TransLogClient::Session::UP session = _tlc.open(_domainName); - if (session.get() == NULL) { + if ( ! session) { if (!_tlc.create(_domainName)) { vespalib::string str = vespalib::make_string( "Failed creating domain '%s' on TLS '%s'", @@ -41,7 +40,7 @@ TransactionLogManagerBase::init() LOG(debug, "Created domain '%s' on TLS '%s'", _domainName.c_str(), _tlc.getRPCTarget().c_str()); session = _tlc.open(_domainName); - if (session.get() == NULL) { + if ( ! session) { vespalib::string str = vespalib::make_string( "Could not open session for domain '%s' on TLS '%s'", _domainName.c_str(), _tlc.getRPCTarget().c_str()); @@ -70,16 +69,7 @@ TransactionLogManagerBase::internalStartReplay() std::lock_guard<std::mutex> guard(_replayLock); _replayStarted = true; _replayDone = false; - FastOS_Time timer; - timer.SetNow(); - _replayStartTime = timer.MilliSecs(); -} - -void -TransactionLogManagerBase::markReplayStarted() -{ - std::lock_guard<std::mutex> guard(_replayLock); - _replayStarted = true; + _replayStopWatch = fastos::StopWatch(); } void TransactionLogManagerBase::changeReplayDone() @@ -101,18 +91,18 @@ TransactionLogManagerBase::waitForReplayDone() const void TransactionLogManagerBase::close() { - if (_tlcSession.get() != NULL) { + if (_tlcSession) { _tlcSession->close(); } // Delay destruction until replay is not active. waitForReplayDone(); - if (_tlcSession.get() != NULL) { + if (_tlcSession) { _tlcSession->clear(); } } -TransLogClient::Visitor::UP TransactionLogManagerBase::createTlcVisitor( - TransLogClient::Session::Callback &callback) { +TransLogClient::Visitor::UP +TransactionLogManagerBase::createTlcVisitor(TransLogClient::Session::Callback &callback) { return _tlc.createVisitor(_domainName, callback); } @@ -127,9 +117,7 @@ bool TransactionLogManagerBase::isDoingReplay() const { } void TransactionLogManagerBase::logReplayComplete() const { - FastOS_Time timer; - timer.SetMilliSecs(_replayStartTime); - doLogReplayComplete(_domainName, static_cast<int64_t>(timer.MilliSecsToNow())); + doLogReplayComplete(_domainName, _replayStopWatch.stop().elapsed().ms()); } } // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.h b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.h index 9f4e63842cd..d5a7ab41af0 100644 --- a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.h +++ b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.h @@ -5,6 +5,7 @@ #include <vespa/searchlib/transactionlog/translogclient.h> #include <mutex> #include <condition_variable> +#include <vespa/fastos/timestamp.h> namespace proton { @@ -12,18 +13,19 @@ namespace proton { * Base class managing the initialization and replay of a transaction log. **/ class TransactionLogManagerBase { - - search::transactionlog::TransLogClient _tlc; - search::transactionlog::TransLogClient::Session::UP _tlcSession; - vespalib::string _domainName; - mutable std::mutex _replayLock; +protected: + using TransLogClient = search::transactionlog::TransLogClient; +private: + TransLogClient _tlc; + TransLogClient::Session::UP _tlcSession; + vespalib::string _domainName; + mutable std::mutex _replayLock; mutable std::condition_variable _replayCond; - volatile bool _replayDone; - bool _replayStarted; - double _replayStartTime; + volatile bool _replayDone; + bool _replayStarted; + mutable fastos::StopWatch _replayStopWatch; protected: - typedef search::transactionlog::TransLogClient TransLogClient; typedef search::SerialNum SerialNum; struct StatusResult { @@ -36,8 +38,7 @@ protected: StatusResult init(); void internalStartReplay(); - virtual void doLogReplayComplete(const vespalib::string &domainName, - int64_t elapsedTime) const = 0; + virtual void doLogReplayComplete(const vespalib::string &domainName, int64_t elapsedTime) const = 0; public: TransactionLogManagerBase(const TransactionLogManagerBase &) = delete; @@ -65,10 +66,6 @@ public: bool isDoingReplay() const; void logReplayComplete() const; const vespalib::string &getRpcTarget() const { return _tlc.getRPCTarget(); } - - void - markReplayStarted(); }; } // namespace proton - |