summaryrefslogtreecommitdiffstats
path: root/storage
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-02-08 12:20:31 +0100
committerGitHub <noreply@github.com>2023-02-08 12:20:31 +0100
commite963d5ec9f95fd40e469d9cb67c25385d33d0675 (patch)
tree3fa7feafbd970a3ef9a48405de4f490c2f5a9f26 /storage
parentdacf06805e11990437412e828a06fe58d4e4f5f0 (diff)
parent4de586e0b9205501ac56d64f714413bd9853a307 (diff)
Merge pull request #25936 from vespa-engine/balder/reduce-use-of-microsecondtime
Balder/reduce use of microsecondtime
Diffstat (limited to 'storage')
-rw-r--r--storage/src/tests/common/metricstest.cpp20
-rw-r--r--storage/src/tests/common/teststorageapp.cpp2
-rw-r--r--storage/src/tests/storageframework/clock/timetest.cpp7
-rw-r--r--storage/src/tests/storageserver/statereportertest.cpp4
-rw-r--r--storage/src/vespa/storage/distributor/bucketgctimecalculator.cpp15
-rw-r--r--storage/src/vespa/storage/distributor/bucketgctimecalculator.h10
-rw-r--r--storage/src/vespa/storage/distributor/maintenance/node_maintenance_stats_tracker.h10
-rw-r--r--storage/src/vespa/storage/distributor/pendingclusterstate.cpp15
-rw-r--r--storage/src/vespa/storage/distributor/pendingclusterstate.h11
-rw-r--r--storage/src/vespa/storage/distributor/statechecker.cpp3
-rw-r--r--storage/src/vespa/storage/distributor/statecheckers.cpp10
-rw-r--r--storage/src/vespa/storage/distributor/statecheckers.h2
-rw-r--r--storage/src/vespa/storage/distributor/top_level_bucket_db_updater.cpp2
-rw-r--r--storage/src/vespa/storage/persistence/types.h15
-rw-r--r--storage/src/vespa/storage/storageserver/distributornode.cpp4
-rw-r--r--storage/src/vespa/storageframework/defaultimplementation/clock/fakeclock.cpp12
-rw-r--r--storage/src/vespa/storageframework/defaultimplementation/clock/fakeclock.h21
-rw-r--r--storage/src/vespa/storageframework/defaultimplementation/clock/realclock.cpp9
-rw-r--r--storage/src/vespa/storageframework/defaultimplementation/clock/realclock.h1
-rw-r--r--storage/src/vespa/storageframework/generic/clock/clock.h7
-rw-r--r--storage/src/vespa/storageframework/generic/clock/time.cpp6
-rw-r--r--storage/src/vespa/storageframework/generic/clock/time.h39
22 files changed, 73 insertions, 152 deletions
diff --git a/storage/src/tests/common/metricstest.cpp b/storage/src/tests/common/metricstest.cpp
index 290d05e9a59..97d1c22364f 100644
--- a/storage/src/tests/common/metricstest.cpp
+++ b/storage/src/tests/common/metricstest.cpp
@@ -12,7 +12,6 @@
#include <tests/common/dummystoragelink.h>
#include <vespa/metrics/metricmanager.h>
#include <vespa/config/common/exceptions.h>
-#include <vespa/vespalib/stllike/hash_map.hpp>
#include <vespa/vespalib/gtest/gtest.h>
#include <gmock/gmock.h>
#include <filesystem>
@@ -38,9 +37,7 @@ struct MetricsTest : public Test {
std::shared_ptr<VisitorMetrics> _visitorMetrics;
void createSnapshotForPeriod(std::chrono::seconds secs) const;
- void assertMetricLastValue(const std::string& name,
- int interval,
- uint64_t expected) const;
+ void assertMetricLastValue(const std::string& name, int interval, uint64_t expected) const;
MetricsTest();
~MetricsTest() override;
@@ -55,8 +52,8 @@ namespace {
{
framework::Clock& _clock;
explicit MetricClock(framework::Clock& c) : _clock(c) {}
- [[nodiscard]] time_t getTime() const override { return _clock.getTimeInSeconds().getTime(); }
- time_t getTimeInMilliSecs() const override { return vespalib::count_ms(_clock.getMonotonicTime().time_since_epoch()); }
+ [[nodiscard]] time_t getTime() const override { return vespalib::count_s(_clock.getMonotonicTime().time_since_epoch()); }
+ [[nodiscard]] time_t getTimeInMilliSecs() const override { return vespalib::count_ms(_clock.getMonotonicTime().time_since_epoch()); }
};
}
@@ -192,7 +189,7 @@ void MetricsTest::createFakeLoad()
}
_clock->addSecondsToTime(60);
_metricManager->timeChangedNotification();
- while (uint64_t(_metricManager->getLastProcessedTime()) < _clock->getTimeInSeconds().getTime()) {
+ while (int64_t(_metricManager->getLastProcessedTime()) < vespalib::count_s(_clock->getMonotonicTime().time_since_epoch())) {
std::this_thread::sleep_for(5ms);
_metricManager->timeChangedNotification();
}
@@ -242,10 +239,7 @@ TEST_F(MetricsTest, snapshot_presenting) {
for (uint32_t i=0; i<6; ++i) {
_clock->addSecondsToTime(60);
_metricManager->timeChangedNotification();
- while (
- uint64_t(_metricManager->getLastProcessedTime())
- < _clock->getTimeInSeconds().getTime())
- {
+ while (int64_t(_metricManager->getLastProcessedTime()) < vespalib::count_s(_clock->getMonotonicTime().time_since_epoch())) {
std::this_thread::sleep_for(1ms);
}
}
@@ -305,9 +299,7 @@ MetricsTest::createSnapshotForPeriod(std::chrono::seconds secs) const
{
_clock->addSecondsToTime(secs.count());
_metricManager->timeChangedNotification();
- while (uint64_t(_metricManager->getLastProcessedTime())
- < _clock->getTimeInSeconds().getTime())
- {
+ while (int64_t(_metricManager->getLastProcessedTime()) < vespalib::count_s(_clock->getMonotonicTime().time_since_epoch())) {
std::this_thread::sleep_for(100ms);
}
}
diff --git a/storage/src/tests/common/teststorageapp.cpp b/storage/src/tests/common/teststorageapp.cpp
index ea35c2de36a..13861a7cdde 100644
--- a/storage/src/tests/common/teststorageapp.cpp
+++ b/storage/src/tests/common/teststorageapp.cpp
@@ -192,7 +192,7 @@ api::Timestamp
TestDistributorApp::generate_unique_timestamp()
{
std::lock_guard guard(_accessLock);
- uint64_t timeNow(getClock().getTimeInSeconds().getTime());
+ uint64_t timeNow(vespalib::count_s(getClock().getSystemTime().time_since_epoch()));
if (timeNow == _lastUniqueTimestampRequested) {
++_uniqueTimestampCounter;
} else {
diff --git a/storage/src/tests/storageframework/clock/timetest.cpp b/storage/src/tests/storageframework/clock/timetest.cpp
index 0f18dc9ed3a..17625b4bf45 100644
--- a/storage/src/tests/storageframework/clock/timetest.cpp
+++ b/storage/src/tests/storageframework/clock/timetest.cpp
@@ -8,7 +8,6 @@ namespace storage::framework::defaultimplementation {
TEST(TimeTest, testBasics)
{
-
MicroSecTime timeMicros(1000*1000);
MicroSecTime timeMicros2 = timeMicros;
@@ -26,7 +25,8 @@ TEST(TimeTest, testCreatedFromClock)
defaultimplementation::FakeClock clock;
clock.setAbsoluteTimeInSeconds(600);
- EXPECT_EQ(MicroSecTime(600 * 1000 * 1000), MicroSecTime(clock));
+ EXPECT_EQ(vespalib::system_time(600s), clock.getSystemTime());
+ EXPECT_EQ(vespalib::steady_time(600s), clock.getMonotonicTime());
}
TEST(TimeTest, canAssignMicrosecondResolutionTimeToFakeClock)
@@ -34,8 +34,9 @@ TEST(TimeTest, canAssignMicrosecondResolutionTimeToFakeClock)
defaultimplementation::FakeClock clock;
clock.setAbsoluteTimeInMicroSeconds(1234567); // 1.234567 seconds
+ EXPECT_EQ(vespalib::system_time(1234567us), clock.getSystemTime());
+ EXPECT_EQ(vespalib::steady_time(1234567us), clock.getMonotonicTime());
// All non-microsec time points must necessarily be truncated.
- EXPECT_EQ(MicroSecTime(1234567), MicroSecTime(clock));
}
}
diff --git a/storage/src/tests/storageserver/statereportertest.cpp b/storage/src/tests/storageserver/statereportertest.cpp
index 01cf12f7947..b7903de0fe2 100644
--- a/storage/src/tests/storageserver/statereportertest.cpp
+++ b/storage/src/tests/storageserver/statereportertest.cpp
@@ -228,9 +228,7 @@ TEST_F(StateReporterTest, report_metrics) {
for (uint32_t i = 0; i < 6; ++i) {
_clock->addSecondsToTime(60);
_metricManager->timeChangedNotification();
- while (
- uint64_t(_metricManager->getLastProcessedTime())
- < _clock->getTimeInSeconds().getTime())
+ while (int64_t(_metricManager->getLastProcessedTime()) < vespalib::count_s(_clock->getMonotonicTime().time_since_epoch()))
{
std::this_thread::sleep_for(1ms);
}
diff --git a/storage/src/vespa/storage/distributor/bucketgctimecalculator.cpp b/storage/src/vespa/storage/distributor/bucketgctimecalculator.cpp
index 792530514b5..b1d8d61c173 100644
--- a/storage/src/vespa/storage/distributor/bucketgctimecalculator.cpp
+++ b/storage/src/vespa/storage/distributor/bucketgctimecalculator.cpp
@@ -2,20 +2,21 @@
#include "bucketgctimecalculator.h"
+using vespalib::count_s;
+
namespace storage::distributor {
bool
BucketGcTimeCalculator::shouldGc(const document::BucketId& b,
- std::chrono::seconds currentTime,
- std::chrono::seconds lastRunAt) const
+ vespalib::duration currentTime,
+ vespalib::duration lastRunAt) const
{
- if (_checkInterval.count() == 0) {
+ if (count_s(_checkInterval) == 0) {
return false;
}
- std::chrono::seconds gcPoint(_hasher.hash(b) % _checkInterval.count());
- std::chrono::seconds currentPeriodStart(currentTime
- - (currentTime % _checkInterval));
- std::chrono::seconds newestValid(currentPeriodStart + gcPoint);
+ std::chrono::seconds gcPoint(_hasher.hash(b) % count_s(_checkInterval));
+ vespalib::duration currentPeriodStart(currentTime - (currentTime % _checkInterval));
+ vespalib::duration newestValid(currentPeriodStart + gcPoint);
// Should GC have been started in current period?
if (currentTime >= newestValid && lastRunAt < newestValid) {
diff --git a/storage/src/vespa/storage/distributor/bucketgctimecalculator.h b/storage/src/vespa/storage/distributor/bucketgctimecalculator.h
index f8d30b6e526..54abebc4152 100644
--- a/storage/src/vespa/storage/distributor/bucketgctimecalculator.h
+++ b/storage/src/vespa/storage/distributor/bucketgctimecalculator.h
@@ -1,8 +1,8 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
-#include <chrono>
#include <vespa/document/bucket/bucketid.h>
+#include <vespa/vespalib/util/time.h>
namespace storage::distributor {
@@ -35,19 +35,19 @@ public:
};
BucketGcTimeCalculator(const BucketIdHasher& hasher,
- std::chrono::seconds checkInterval)
+ vespalib::duration checkInterval)
: _hasher(hasher),
_checkInterval(checkInterval)
{
}
bool shouldGc(const document::BucketId&,
- std::chrono::seconds currentTime,
- std::chrono::seconds lastRunAt) const;
+ vespalib::duration currentTime,
+ vespalib::duration lastRunAt) const;
private:
const BucketIdHasher& _hasher;
- std::chrono::seconds _checkInterval;
+ vespalib::duration _checkInterval;
};
}
diff --git a/storage/src/vespa/storage/distributor/maintenance/node_maintenance_stats_tracker.h b/storage/src/vespa/storage/distributor/maintenance/node_maintenance_stats_tracker.h
index 0e6c2bb23c2..deeef118685 100644
--- a/storage/src/vespa/storage/distributor/maintenance/node_maintenance_stats_tracker.h
+++ b/storage/src/vespa/storage/distributor/maintenance/node_maintenance_stats_tracker.h
@@ -1,11 +1,9 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
-#include <chrono>
#include <unordered_map>
-#include <iosfwd>
-#include <stdint.h>
#include <vespa/document/bucket/bucketspace.h>
+#include <vespa/vespalib/util/time.h>
namespace storage::distributor {
@@ -53,7 +51,7 @@ public:
private:
PerNodeStats _node_stats;
NodeMaintenanceStats _total_stats;
- std::chrono::seconds _max_observed_time_since_last_gc;
+ vespalib::duration _max_observed_time_since_last_gc;
static const NodeMaintenanceStats _emptyNodeMaintenanceStats;
@@ -86,7 +84,7 @@ public:
++_total_stats.total;
}
- void update_observed_time_since_last_gc(std::chrono::seconds time_since_gc) noexcept {
+ void update_observed_time_since_last_gc(vespalib::duration time_since_gc) noexcept {
_max_observed_time_since_last_gc = std::max(time_since_gc, _max_observed_time_since_last_gc);
}
@@ -116,7 +114,7 @@ public:
return _total_stats;
}
- std::chrono::seconds max_observed_time_since_last_gc() const noexcept {
+ vespalib::duration max_observed_time_since_last_gc() const noexcept {
return _max_observed_time_since_last_gc;
}
diff --git a/storage/src/vespa/storage/distributor/pendingclusterstate.cpp b/storage/src/vespa/storage/distributor/pendingclusterstate.cpp
index b9639f54469..36f7af1c1e6 100644
--- a/storage/src/vespa/storage/distributor/pendingclusterstate.cpp
+++ b/storage/src/vespa/storage/distributor/pendingclusterstate.cpp
@@ -210,11 +210,10 @@ PendingClusterState::requestNode(BucketSpaceAndNode bucketSpaceAndNode)
}
-PendingClusterState::Summary::Summary(const std::string& prevClusterState,
- const std::string& newClusterState,
- uint32_t processingTime)
- : _prevClusterState(prevClusterState),
- _newClusterState(newClusterState),
+PendingClusterState::Summary::Summary(std::string prevClusterState, std::string newClusterState,
+ vespalib::duration processingTime)
+ : _prevClusterState(std::move(prevClusterState)),
+ _newClusterState(std::move(newClusterState)),
_processingTime(processingTime)
{}
@@ -304,9 +303,9 @@ PendingClusterState::printXml(vespalib::XmlOutputStream& xos) const
PendingClusterState::Summary
PendingClusterState::getSummary() const
{
- return Summary(getPrevClusterStateBundleString(),
- getNewClusterStateBundleString(),
- (_clock.getTimeInMicros().getTime() - _creationTimestamp));
+ return {getPrevClusterStateBundleString(),
+ getNewClusterStateBundleString(),
+ _clock.getSystemTime().time_since_epoch() - std::chrono::microseconds(_creationTimestamp)};
}
PendingBucketSpaceDbTransition&
diff --git a/storage/src/vespa/storage/distributor/pendingclusterstate.h b/storage/src/vespa/storage/distributor/pendingclusterstate.h
index 8af08e1ba4d..dcc60a537f1 100644
--- a/storage/src/vespa/storage/distributor/pendingclusterstate.h
+++ b/storage/src/vespa/storage/distributor/pendingclusterstate.h
@@ -6,7 +6,6 @@
#include "clusterinformation.h"
#include <vespa/storageapi/message/bucket.h>
#include <vespa/storageapi/message/state.h>
-#include <vespa/storageframework/generic/clock/clock.h>
#include <vespa/vdslib/state/cluster_state_bundle.h>
#include <vespa/vespalib/util/xmlserializable.h>
#include <vespa/vespalib/stllike/hash_map.h>
@@ -14,6 +13,8 @@
#include <unordered_map>
#include <deque>
+namespace storage::framework { struct Clock; }
+
namespace storage::distributor {
class BucketSpaceStateMap;
@@ -30,16 +31,16 @@ public:
using OutdatedNodes = dbtransition::OutdatedNodes;
using OutdatedNodesMap = dbtransition::OutdatedNodesMap;
struct Summary {
- Summary(const std::string& prevClusterState, const std::string& newClusterState, uint32_t processingTime);
+ Summary(std::string prevClusterState, std::string newClusterState, vespalib::duration processingTime);
Summary(const Summary &);
Summary & operator = (const Summary &);
- Summary(Summary &&) = default;
- Summary & operator = (Summary &&) = default;
+ Summary(Summary &&) noexcept = default;
+ Summary & operator = (Summary &&) noexcept = default;
~Summary();
std::string _prevClusterState;
std::string _newClusterState;
- uint32_t _processingTime;
+ vespalib::duration _processingTime;
};
static std::unique_ptr<PendingClusterState> createForClusterStateChange(
diff --git a/storage/src/vespa/storage/distributor/statechecker.cpp b/storage/src/vespa/storage/distributor/statechecker.cpp
index 91acd494a7a..eaff1f0b780 100644
--- a/storage/src/vespa/storage/distributor/statechecker.cpp
+++ b/storage/src/vespa/storage/distributor/statechecker.cpp
@@ -72,8 +72,7 @@ StateChecker::Context::Context(const DistributorNodeContext& node_ctx_in,
pending_cluster_state(op_ctx_in.pending_cluster_state_or_null(bucket_.getBucketSpace())),
distributorConfig(op_ctx_in.distributor_config()),
distribution(distributorBucketSpace.getDistribution()),
- gcTimeCalculator(op_ctx_in.bucket_id_hasher(),
- std::chrono::duration_cast<std::chrono::seconds>(distributorConfig.getGarbageCollectionInterval())),
+ gcTimeCalculator(op_ctx_in.bucket_id_hasher(), distributorConfig.getGarbageCollectionInterval()),
node_ctx(node_ctx_in),
op_ctx(op_ctx_in),
db(distributorBucketSpace.getBucketDatabase()),
diff --git a/storage/src/vespa/storage/distributor/statecheckers.cpp b/storage/src/vespa/storage/distributor/statecheckers.cpp
index 14cc2509cab..f9c26bf113e 100644
--- a/storage/src/vespa/storage/distributor/statecheckers.cpp
+++ b/storage/src/vespa/storage/distributor/statecheckers.cpp
@@ -1130,7 +1130,7 @@ GarbageCollectionStateChecker::garbage_collection_disabled(const Context& c) noe
}
bool
-GarbageCollectionStateChecker::needs_garbage_collection(const Context& c, std::chrono::seconds time_since_epoch)
+GarbageCollectionStateChecker::needs_garbage_collection(const Context& c, vespalib::duration time_since_epoch)
{
if (c.entry->getNodeCount() == 0) {
return false;
@@ -1148,20 +1148,18 @@ GarbageCollectionStateChecker::check(Context& c) const
if (garbage_collection_disabled(c)) {
return Result::noMaintenanceNeeded();
}
- const std::chrono::seconds now(c.node_ctx.clock().getTimeInSeconds().getTime());
+ const vespalib::duration now(c.node_ctx.clock().getSystemTime().time_since_epoch());
const std::chrono::seconds last_run_at(c.entry->getLastGarbageCollectionTime());
c.stats.update_observed_time_since_last_gc(now - last_run_at);
if (needs_garbage_collection(c, now)) {
- auto op = std::make_unique<GarbageCollectionOperation>(
- c.node_ctx,
- BucketAndNodes(c.getBucket(), c.entry->getNodes()));
+ auto op = std::make_unique<GarbageCollectionOperation>(c.node_ctx, BucketAndNodes(c.getBucket(), c.entry->getNodes()));
vespalib::asciistream reason;
reason << "[Needs garbage collection: Last check at "
<< c.entry->getLastGarbageCollectionTime()
<< ", current time "
- << now.count()
+ << vespalib::count_s(now)
<< ", configured interval "
<< vespalib::to_s(c.distributorConfig.getGarbageCollectionInterval()) << "]";
diff --git a/storage/src/vespa/storage/distributor/statecheckers.h b/storage/src/vespa/storage/distributor/statecheckers.h
index c1579cb5eda..b6cd5ba0534 100644
--- a/storage/src/vespa/storage/distributor/statecheckers.h
+++ b/storage/src/vespa/storage/distributor/statecheckers.h
@@ -88,7 +88,7 @@ public:
const char* getName() const noexcept override { return "GarbageCollection"; }
private:
static bool garbage_collection_disabled(const Context& c) noexcept;
- static bool needs_garbage_collection(const Context& c, std::chrono::seconds time_since_epoch);
+ static bool needs_garbage_collection(const Context& c, vespalib::duration time_since_epoch);
};
}
diff --git a/storage/src/vespa/storage/distributor/top_level_bucket_db_updater.cpp b/storage/src/vespa/storage/distributor/top_level_bucket_db_updater.cpp
index 16be7733c1a..45d7bfc992c 100644
--- a/storage/src/vespa/storage/distributor/top_level_bucket_db_updater.cpp
+++ b/storage/src/vespa/storage/distributor/top_level_bucket_db_updater.cpp
@@ -493,7 +493,7 @@ TopLevelBucketDBUpdater::report_xml_status(vespalib::xml::XmlOutputStream& xos,
xos << XmlTag("change")
<< XmlAttribute("from", i->_prevClusterState)
<< XmlAttribute("to", i->_newClusterState)
- << XmlAttribute("processingtime", i->_processingTime)
+ << XmlAttribute("processingtime", vespalib::count_us(i->_processingTime))
<< XmlEndTag();
}
xos << XmlEndTag()
diff --git a/storage/src/vespa/storage/persistence/types.h b/storage/src/vespa/storage/persistence/types.h
index 60de7dea4fd..c3d7f9eab6d 100644
--- a/storage/src/vespa/storage/persistence/types.h
+++ b/storage/src/vespa/storage/persistence/types.h
@@ -1,29 +1,18 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
-#include <iosfwd>
-#include <vespa/document/bucket/bucketid.h>
-#include <vespa/document/base/documentid.h>
-#include <vespa/storage/bucketdb/storbucketdb.h>
#include <vespa/storageapi/buckets/bucketinfo.h>
-#include <vespa/storageapi/defs.h>
-#include <vespa/vespalib/stllike/string.h>
-#include <vespa/storageframework/generic/clock/time.h>
+#include <memory>
namespace storage {
class MessageTracker;
struct Types {
- using BucketId = document::BucketId;
- using DocumentId = document::DocumentId;
- using GlobalId = document::GlobalId;
- using Timestamp = framework::MicroSecTime;
- using String = vespalib::string;
using BucketInfo = api::BucketInfo;
using MessageTrackerUP = std::unique_ptr<MessageTracker>;
protected:
- ~Types() {} // Noone should refer to objects as Types objects
+ ~Types() = default; // Noone should refer to objects as Types objects
};
} // storage
diff --git a/storage/src/vespa/storage/storageserver/distributornode.cpp b/storage/src/vespa/storage/storageserver/distributornode.cpp
index 6fd8cded08e..5f39c7abada 100644
--- a/storage/src/vespa/storage/storageserver/distributornode.cpp
+++ b/storage/src/vespa/storage/storageserver/distributornode.cpp
@@ -86,7 +86,7 @@ DistributorNode::createChain(IStorageChainBuilder &builder)
// TODO: All components in this chain should use a common thread instead of
// each having its own configfetcher.
StorageLink::UP chain;
- if (_retrievedCommunicationManager.get()) {
+ if (_retrievedCommunicationManager) {
builder.add(std::move(_retrievedCommunicationManager));
} else {
auto communication_manager = std::make_unique<CommunicationManager>(dcr, _configUri);
@@ -139,7 +139,7 @@ DistributorNode::generate_unique_timestamp()
ResumeGuard
DistributorNode::pause()
{
- return ResumeGuard();
+ return {};
}
} // storage
diff --git a/storage/src/vespa/storageframework/defaultimplementation/clock/fakeclock.cpp b/storage/src/vespa/storageframework/defaultimplementation/clock/fakeclock.cpp
index 331b2113838..5221d8a112e 100644
--- a/storage/src/vespa/storageframework/defaultimplementation/clock/fakeclock.cpp
+++ b/storage/src/vespa/storageframework/defaultimplementation/clock/fakeclock.cpp
@@ -3,20 +3,20 @@
namespace storage::framework::defaultimplementation {
-FakeClock::FakeClock(Mode m, framework::MicroSecTime startTime)
+FakeClock::FakeClock(Mode m, vespalib::duration startTime)
: _mode(m),
_absoluteTime(startTime),
_cycleCount(0)
{
}
-framework::MicroSecTime
+int64_t
FakeClock::getTimeInMicros() const {
std::lock_guard guard(_lock);
- if (_mode == FAKE_ABSOLUTE) return _absoluteTime;
- MicroSecTime tmp(_absoluteTime);
- tmp += framework::MicroSecTime(1000000 * _cycleCount++);
- return tmp;
+ if (_mode == FAKE_ABSOLUTE) return vespalib::count_us(_absoluteTime);
+ vespalib::duration tmp(_absoluteTime);
+ tmp += std::chrono::seconds(_cycleCount++);
+ return vespalib::count_us(tmp);
}
}
diff --git a/storage/src/vespa/storageframework/defaultimplementation/clock/fakeclock.h b/storage/src/vespa/storageframework/defaultimplementation/clock/fakeclock.h
index b97c2bd92c1..ed41014c443 100644
--- a/storage/src/vespa/storageframework/defaultimplementation/clock/fakeclock.h
+++ b/storage/src/vespa/storageframework/defaultimplementation/clock/fakeclock.h
@@ -22,13 +22,12 @@ struct FakeClock : public framework::Clock {
private:
Mode _mode;
- framework::MicroSecTime _absoluteTime;
+ vespalib::duration _absoluteTime;
mutable time_t _cycleCount;
mutable std::mutex _lock;
public:
- FakeClock(Mode m = FAKE_ABSOLUTE,
- framework::MicroSecTime startTime = framework::MicroSecTime(1));
+ explicit FakeClock(Mode m = FAKE_ABSOLUTE, vespalib::duration startTime = 1us);
void setMode(Mode m) {
std::lock_guard guard(_lock);
@@ -38,39 +37,39 @@ public:
virtual void setAbsoluteTimeInSeconds(uint32_t seconds) {
std::lock_guard guard(_lock);
- _absoluteTime = framework::MicroSecTime(seconds * uint64_t(1000000));
+ _absoluteTime = std::chrono::seconds(seconds);
_cycleCount = 0;
_mode = FAKE_ABSOLUTE;
}
virtual void setAbsoluteTimeInMicroSeconds(uint64_t usecs) {
std::lock_guard guard(_lock);
- _absoluteTime = framework::MicroSecTime(usecs);
+ _absoluteTime = std::chrono::microseconds(usecs);
_cycleCount = 0;
_mode = FAKE_ABSOLUTE;
}
virtual void addMilliSecondsToTime(uint64_t ms) {
std::lock_guard guard(_lock);
- _absoluteTime += framework::MicroSecTime(ms * 1000);
+ _absoluteTime += std::chrono::milliseconds(ms);
}
virtual void addSecondsToTime(uint32_t nr) {
std::lock_guard guard(_lock);
- _absoluteTime += framework::MicroSecTime(nr * uint64_t(1000000));
+ _absoluteTime += std::chrono::seconds(nr);
}
- framework::MicroSecTime getTimeInMicros() const override ;
+ int64_t getTimeInMicros() const;
framework::SecondTime getTimeInSeconds() const override {
- return getTimeInMicros().getSeconds();
+ return SecondTime(vespalib::count_s(getSystemTime().time_since_epoch()));
}
vespalib::system_time getSystemTime() const override {
// For simplicity, assume fake monotonic time follows fake wall clock.
- return vespalib::system_time(std::chrono::microseconds(getTimeInMicros().getTime()));
+ return vespalib::system_time(std::chrono::microseconds(getTimeInMicros()));
}
vespalib::steady_time getMonotonicTime() const override {
// For simplicity, assume fake monotonic time follows fake wall clock.
- return vespalib::steady_time(std::chrono::microseconds(getTimeInMicros().getTime()));
+ return vespalib::steady_time(std::chrono::microseconds(getTimeInMicros()));
}
};
diff --git a/storage/src/vespa/storageframework/defaultimplementation/clock/realclock.cpp b/storage/src/vespa/storageframework/defaultimplementation/clock/realclock.cpp
index 2e2894de9d5..d26e6a43ed0 100644
--- a/storage/src/vespa/storageframework/defaultimplementation/clock/realclock.cpp
+++ b/storage/src/vespa/storageframework/defaultimplementation/clock/realclock.cpp
@@ -5,17 +5,10 @@
namespace storage::framework::defaultimplementation {
-MicroSecTime
-RealClock::getTimeInMicros() const {
- struct timeval mytime;
- gettimeofday(&mytime, 0);
- return MicroSecTime(mytime.tv_sec * 1000000llu + mytime.tv_usec);
-}
-
SecondTime
RealClock::getTimeInSeconds() const {
struct timeval mytime;
- gettimeofday(&mytime, 0);
+ gettimeofday(&mytime, nullptr);
return SecondTime(mytime.tv_sec);
}
diff --git a/storage/src/vespa/storageframework/defaultimplementation/clock/realclock.h b/storage/src/vespa/storageframework/defaultimplementation/clock/realclock.h
index dc4884b4439..a1f455f13a6 100644
--- a/storage/src/vespa/storageframework/defaultimplementation/clock/realclock.h
+++ b/storage/src/vespa/storageframework/defaultimplementation/clock/realclock.h
@@ -14,7 +14,6 @@
namespace storage::framework::defaultimplementation {
struct RealClock : public Clock {
- MicroSecTime getTimeInMicros() const override;
SecondTime getTimeInSeconds() const override;
vespalib::steady_time getMonotonicTime() const override;
vespalib::system_time getSystemTime() const override;
diff --git a/storage/src/vespa/storageframework/generic/clock/clock.h b/storage/src/vespa/storageframework/generic/clock/clock.h
index 21d6bc589a6..2e431ba8a17 100644
--- a/storage/src/vespa/storageframework/generic/clock/clock.h
+++ b/storage/src/vespa/storageframework/generic/clock/clock.h
@@ -23,12 +23,11 @@ struct Clock {
virtual ~Clock() = default;
- virtual MicroSecTime getTimeInMicros() const = 0;
- virtual SecondTime getTimeInSeconds() const = 0;
+ [[nodiscard]] virtual SecondTime getTimeInSeconds() const = 0;
// Time point resolution is intentionally not defined here.
- virtual vespalib::steady_time getMonotonicTime() const = 0;
- virtual vespalib::system_time getSystemTime() const = 0;
+ [[nodiscard]] virtual vespalib::steady_time getMonotonicTime() const = 0;
+ [[nodiscard]] virtual vespalib::system_time getSystemTime() const = 0;
};
}
diff --git a/storage/src/vespa/storageframework/generic/clock/time.cpp b/storage/src/vespa/storageframework/generic/clock/time.cpp
index f5426901e4c..64434779c91 100644
--- a/storage/src/vespa/storageframework/generic/clock/time.cpp
+++ b/storage/src/vespa/storageframework/generic/clock/time.cpp
@@ -74,12 +74,6 @@ getTimeString(uint64_t microSecondTime, TimeFormat format)
return ost.str();
}
-uint64_t
-getRawMicroTime(const Clock& clock)
-{
- return clock.getTimeInMicros().getTime();
-}
-
template std::ostream& operator<< <MicroSecTime, 1>(std::ostream&, const Time<MicroSecTime, 1> &);
template std::ostream& operator<< <SecondTime, 1000000>(std::ostream&, const Time<SecondTime, 1000000> &);
diff --git a/storage/src/vespa/storageframework/generic/clock/time.h b/storage/src/vespa/storageframework/generic/clock/time.h
index 6f7cb490355..8e2a654b3ed 100644
--- a/storage/src/vespa/storageframework/generic/clock/time.h
+++ b/storage/src/vespa/storageframework/generic/clock/time.h
@@ -34,10 +34,6 @@ vespalib::string getTimeString(uint64_t microSecondTime, TimeFormat format);
// TODO deprecate framework time point and duration classes in favor of
// using std::chrono.
-// As this class can't include clock, this utility function can be used in
-// header implementation to get actual time.
-uint64_t getRawMicroTime(const Clock&);
-
/**
* Class containing common functionality for the various time instances. Try to
* make time instances as easy to use as possible, without creating risk of
@@ -54,8 +50,6 @@ protected:
public:
[[nodiscard]] uint64_t getTime() const { return _time; }
- void setTime(uint64_t t) { _time = t; }
- [[nodiscard]] bool isSet() const { return (_time != 0); }
Type& operator-=(const Type& o) { _time -= o._time; return static_cast<Type&>(*this); }
Type& operator+=(const Type& o) { _time += o._time; return static_cast<Type&>(*this); }
@@ -72,30 +66,15 @@ public:
}
static Type max() { return Type(std::numeric_limits<uint64_t>::max()); }
- static Type min() { return Type(0); }
};
-template<typename Type, typename Number>
-Type& operator/(Type& type, Number n) {
- type.setTime(type.getTime() / n);
- return type;
-}
-
-template<typename Type, typename Number>
-Type& operator*(Type& type, Number n) {
- type.setTime(type.getTime() * n);
- return type;
-}
-
template<typename Type, int MPU>
std::ostream& operator<<(std::ostream& out, const Time<Type, MPU>& t);
template<typename Type, int MPU>
vespalib::asciistream& operator<<(vespalib::asciistream& out, const Time<Type, MPU>& t);
-struct MicroSecTime;
-
/**
* \class storage::framework::SecondTime
* \ingroup clock
@@ -108,8 +87,6 @@ struct MicroSecTime;
*/
struct SecondTime : public Time<SecondTime, 1000000> {
explicit SecondTime(uint64_t t = 0) : Time<SecondTime, 1000000>(t) {}
- explicit SecondTime(const Clock& clock)
- : Time<SecondTime, 1000000>(getRawMicroTime(clock) / 1000000) {}
};
/**
@@ -124,24 +101,8 @@ struct SecondTime : public Time<SecondTime, 1000000> {
*/
struct MicroSecTime : public Time<MicroSecTime, 1> {
explicit MicroSecTime(uint64_t t = 0) : Time<MicroSecTime, 1>(t) {}
- explicit MicroSecTime(const Clock& clock)
- : Time<MicroSecTime, 1>(getRawMicroTime(clock)) {}
[[nodiscard]] SecondTime getSeconds() const { return SecondTime(getTime() / 1000000); }
};
-inline MicroSecTime
-operator + (MicroSecTime a, MicroSecTime b) {
- MicroSecTime result(a);
- result += b;
- return result;
-}
-
-inline MicroSecTime
-operator - (MicroSecTime a, MicroSecTime b) {
- MicroSecTime result(a);
- result -= b;
- return result;
-}
-
}