diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-02-07 07:51:38 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-02-07 07:51:38 +0000 |
commit | fbadddae97167d0a6e765e1ddf9da7def86e6df2 (patch) | |
tree | bed88d431bc8fa0441a6fca3a7b5b8724d12790d | |
parent | 1c72b80691b2085de2bbdcef88f0ff76d951abce (diff) |
Use steady_clock in StorageNode::waitUntilInitialized
-rw-r--r-- | storage/src/vespa/storage/storageserver/storagenode.cpp | 15 | ||||
-rw-r--r-- | storage/src/vespa/storage/storageserver/storagenode.h | 2 |
2 files changed, 7 insertions, 10 deletions
diff --git a/storage/src/vespa/storage/storageserver/storagenode.cpp b/storage/src/vespa/storage/storageserver/storagenode.cpp index 3987827a264..2836ab80acf 100644 --- a/storage/src/vespa/storage/storageserver/storagenode.cpp +++ b/storage/src/vespa/storage/storageserver/storagenode.cpp @@ -37,7 +37,7 @@ namespace { void writePidFile(const vespalib::string& pidfile) { - int rv = -1; + ssize_t rv = -1; vespalib::string mypid = vespalib::make_string("%d\n", getpid()); size_t lastSlash = pidfile.rfind('/'); if (lastSlash != vespalib::string::npos) { @@ -372,7 +372,7 @@ StorageNode::shutdown() _chain->flush(); } - if (_pidFile != "") { + if ( !_pidFile.empty() ) { LOG(debug, "Removing pid file"); removePidFile(_pidFile); } @@ -510,10 +510,8 @@ StorageNode::updateMetrics(const MetricLockGuard &) { } void -StorageNode::waitUntilInitialized(uint32_t timeout) { - framework::defaultimplementation::RealClock clock; - framework::MilliSecTime endTime( - clock.getTimeInMillis() + framework::MilliSecTime(1000 * timeout)); +StorageNode::waitUntilInitialized(vespalib::duration timeout) { + vespalib::steady_time doom = vespalib::steady_clock::now() + timeout; while (true) { { NodeStateUpdater::Lock::SP lock(_component->getStateUpdater().grabStateChangeLock()); @@ -521,10 +519,9 @@ StorageNode::waitUntilInitialized(uint32_t timeout) { if (nodeState.getState() == lib::State::UP) break; } std::this_thread::sleep_for(10ms); - if (clock.getTimeInMillis() >= endTime) { + if (vespalib::steady_clock::now() >= doom) { std::ostringstream ost; - ost << "Storage server not initialized after waiting timeout of " - << timeout << " seconds."; + ost << "Storage server not initialized after waiting timeout of " << timeout << " seconds."; throw vespalib::IllegalStateException(ost.str(), VESPA_STRLOC); } } diff --git a/storage/src/vespa/storage/storageserver/storagenode.h b/storage/src/vespa/storage/storageserver/storagenode.h index 0e420f206e2..19b930c184f 100644 --- a/storage/src/vespa/storage/storageserver/storagenode.h +++ b/storage/src/vespa/storage/storageserver/storagenode.h @@ -78,7 +78,7 @@ public: virtual const lib::NodeType& getNodeType() const = 0; bool attemptedStopped() const; void notifyDoneInitializing() override; - void waitUntilInitialized(uint32_t timeoutSeconds = 15); + void waitUntilInitialized(vespalib::duration timeout = 15s); void updateMetrics(const MetricLockGuard & guard) override; /** Updates the document type repo. */ |