summaryrefslogtreecommitdiffstats
path: root/vdslib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-02-07 11:07:57 +0100
committerGitHub <noreply@github.com>2023-02-07 11:07:57 +0100
commit2e9c4005b24c90a42167d2fdf197a855c5a11fee (patch)
tree943d30fccfa195299e2e44abfa48f8c41f83ede0 /vdslib
parent0e2842965370836f66c505c61a3c2f4ebac7c6ad (diff)
Revert "Use steady_time for vdslib::NodeState MERGEOK"
Diffstat (limited to 'vdslib')
-rw-r--r--vdslib/src/tests/state/nodestatetest.cpp2
-rw-r--r--vdslib/src/vespa/vdslib/state/nodestate.cpp60
-rw-r--r--vdslib/src/vespa/vdslib/state/nodestate.h28
3 files changed, 45 insertions, 45 deletions
diff --git a/vdslib/src/tests/state/nodestatetest.cpp b/vdslib/src/tests/state/nodestatetest.cpp
index c854adf3915..000542e77fe 100644
--- a/vdslib/src/tests/state/nodestatetest.cpp
+++ b/vdslib/src/tests/state/nodestatetest.cpp
@@ -20,7 +20,7 @@ TEST(NodeStateTest, test_parsing)
{
NodeState ns = NodeState("t:4");
EXPECT_EQ(std::string("s:u t:4"), ns.toString());
- EXPECT_EQ(4s, ns.getStartTimestamp().time_since_epoch());
+ EXPECT_EQ(uint64_t(4), ns.getStartTimestamp());
}
{
NodeState ns = NodeState("s:u c:2.4 b:12");
diff --git a/vdslib/src/vespa/vdslib/state/nodestate.cpp b/vdslib/src/vespa/vdslib/state/nodestate.cpp
index 0dd7f5abb4c..a7c5476456a 100644
--- a/vdslib/src/vespa/vdslib/state/nodestate.cpp
+++ b/vdslib/src/vespa/vdslib/state/nodestate.cpp
@@ -8,8 +8,9 @@
#include <vespa/vespalib/util/exceptions.h>
#include <vespa/vespalib/stllike/asciistream.h>
#include <sstream>
-
+#include <cmath>
#include <vespa/log/log.h>
+
LOG_SETUP(".vdslib.nodestate");
namespace storage::lib {
@@ -18,16 +19,16 @@ NodeState::NodeState(const NodeState &) = default;
NodeState & NodeState::operator = (const NodeState &) = default;
NodeState::NodeState(NodeState &&) noexcept = default;
NodeState & NodeState::operator = (NodeState &&) noexcept = default;
-NodeState::~NodeState() = default;
+NodeState::~NodeState() { }
NodeState::NodeState()
- : _type(nullptr),
- _state(nullptr),
+ : _type(0),
+ _state(0),
_description(""),
_capacity(1.0),
_initProgress(0.0),
_minUsedBits(16),
- _startTimestamp()
+ _startTimestamp(0)
{
setState(State::UP);
}
@@ -35,12 +36,12 @@ NodeState::NodeState()
NodeState::NodeState(const NodeType& type, const State& state,
vespalib::stringref description, double capacity)
: _type(&type),
- _state(nullptr),
+ _state(0),
_description(description),
_capacity(1.0),
_initProgress(0.0),
_minUsedBits(16),
- _startTimestamp()
+ _startTimestamp(0)
{
setState(state);
if (type == NodeType::STORAGE) {
@@ -55,24 +56,25 @@ NodeState::NodeState(vespalib::stringref serialized, const NodeType* type)
_capacity(1.0),
_initProgress(0.0),
_minUsedBits(16),
- _startTimestamp()
+ _startTimestamp(0)
{
vespalib::StringTokenizer st(serialized, " \t\f\r\n");
st.removeEmptyTokens();
- for (auto it : st)
+ for (vespalib::StringTokenizer::Iterator it = st.begin();
+ it != st.end(); ++it)
{
- std::string::size_type index = it.find(':');
+ std::string::size_type index = it->find(':');
if (index == std::string::npos) {
throw vespalib::IllegalArgumentException(
- "Token " + it + " does not contain ':': " + serialized,
+ "Token " + *it + " does not contain ':': " + serialized,
VESPA_STRLOC);
}
- std::string key = it.substr(0, index);
- std::string value = it.substr(index + 1);
- if (!key.empty()) switch (key[0]) {
+ std::string key = it->substr(0, index);
+ std::string value = it->substr(index + 1);
+ if (key.size() > 0) switch (key[0]) {
case 'b':
- if (_type != nullptr && *type != NodeType::STORAGE) break;
+ if (_type != 0 && *type != NodeType::STORAGE) break;
if (key.size() > 1) break;
try{
setMinUsedBits(boost::lexical_cast<uint32_t>(value));
@@ -89,7 +91,7 @@ NodeState::NodeState(vespalib::stringref serialized, const NodeType* type)
continue;
case 'c':
if (key.size() > 1) break;
- if (_type != nullptr && *type != NodeType::STORAGE) break;
+ if (_type != 0 && *type != NodeType::STORAGE) break;
try{
setCapacity(boost::lexical_cast<double>(value));
} catch (...) {
@@ -113,7 +115,7 @@ NodeState::NodeState(vespalib::stringref serialized, const NodeType* type)
case 't':
if (key.size() > 1) break;
try{
- setStartTimestamp(vespalib::system_time(std::chrono::seconds(boost::lexical_cast<uint64_t>(value))));
+ setStartTimestamp(boost::lexical_cast<uint64_t>(value));
} catch (...) {
throw vespalib::IllegalArgumentException(
"Illegal start timestamp '" + value + "'. Start "
@@ -163,7 +165,7 @@ NodeState::serialize(vespalib::asciistream & out, vespalib::stringref prefix,
SeparatorPrinter sep;
// Always give node state if not part of a system state
// to prevent empty serialization
- if (*_state != State::UP || prefix.empty()) {
+ if (*_state != State::UP || prefix.size() == 0) {
out << sep << prefix << "s:";
out << _state->serialize();
}
@@ -176,8 +178,8 @@ NodeState::serialize(vespalib::asciistream & out, vespalib::stringref prefix,
if (*_state == State::INITIALIZING) {
out << sep << prefix << "i:" << _initProgress;
}
- if (_startTimestamp != vespalib::system_time()) {
- out << sep << prefix << "t:" << vespalib::count_s(_startTimestamp.time_since_epoch());
+ if (_startTimestamp != 0) {
+ out << sep << prefix << "t:" << _startTimestamp;
}
if (includeDescription && ! _description.empty()) {
out << sep << prefix << "m:"
@@ -188,7 +190,7 @@ NodeState::serialize(vespalib::asciistream & out, vespalib::stringref prefix,
void
NodeState::setState(const State& state)
{
- if (_type != nullptr) {
+ if (_type != 0) {
// We don't know whether you want to store reported, wanted or
// current node state, so we must accept any.
if (!state.validReportedNodeState(*_type)
@@ -223,7 +225,7 @@ NodeState::setCapacity(vespalib::Double capacity)
"must be a positive floating point number";
throw vespalib::IllegalArgumentException(ost.str(), VESPA_STRLOC);
}
- if (_type != nullptr && *_type != NodeType::STORAGE) {
+ if (_type != 0 && *_type != NodeType::STORAGE) {
throw vespalib::IllegalArgumentException(
"Capacity only make sense for storage nodes.", VESPA_STRLOC);
}
@@ -243,7 +245,7 @@ NodeState::setInitProgress(vespalib::Double initProgress)
}
void
-NodeState::setStartTimestamp(vespalib::system_time startTimestamp)
+NodeState::setStartTimestamp(uint64_t startTimestamp)
{
_startTimestamp = startTimestamp;
}
@@ -268,10 +270,10 @@ NodeState::print(std::ostream& out, bool verbose,
if (*_state == State::INITIALIZING) {
out << ", init progress " << _initProgress;
}
- if (_startTimestamp != vespalib::system_time()) {
- out << ", start timestamp " << vespalib::to_string(_startTimestamp);
+ if (_startTimestamp != 0) {
+ out << ", start timestamp " << _startTimestamp;
}
- if (!_description.empty()) {
+ if (_description.size() > 0) {
out << ": " << _description;
}
}
@@ -315,7 +317,7 @@ NodeState::similarTo(const NodeState& other) const
void
NodeState::verifySupportForNodeType(const NodeType& type) const
{
- if (_type != nullptr && *_type == type) return;
+ if (_type != 0 && *_type == type) return;
if (!_state->validReportedNodeState(type)
&& !_state->validWantedNodeState(type))
{
@@ -355,8 +357,8 @@ NodeState::getTextualDifference(const NodeState& other) const {
}
}
if (_startTimestamp != other._startTimestamp) {
- source << ", start timestamp " << vespalib::to_string(_startTimestamp);
- target << ", start timestamp " << vespalib::to_string(other._startTimestamp);
+ source << ", start timestamp " << _startTimestamp;
+ target << ", start timestamp " << other._startTimestamp;
}
if (source.str().length() < 2 || target.str().length() < 2) {
diff --git a/vdslib/src/vespa/vdslib/state/nodestate.h b/vdslib/src/vespa/vdslib/state/nodestate.h
index 4fb035b6dcd..541395e15cb 100644
--- a/vdslib/src/vespa/vdslib/state/nodestate.h
+++ b/vdslib/src/vespa/vdslib/state/nodestate.h
@@ -13,7 +13,6 @@
#include "state.h"
#include <vespa/document/util/printable.h>
#include <vespa/vespalib/objects/floatingpointtype.h>
-#include <vespa/vespalib/util/time.h>
#include <memory>
namespace storage::lib {
@@ -26,7 +25,7 @@ class NodeState : public document::Printable
vespalib::Double _capacity;
vespalib::Double _initProgress;
uint32_t _minUsedBits;
- vespalib::system_time _startTimestamp;
+ uint64_t _startTimestamp;
public:
using CSP = std::shared_ptr<const NodeState>;
@@ -44,8 +43,8 @@ public:
vespalib::stringref description = "",
double capacity = 1.0);
/** Set type if you want to verify that content fit with the given type. */
- explicit NodeState(vespalib::stringref serialized, const NodeType* nodeType = nullptr);
- ~NodeState() override;
+ NodeState(vespalib::stringref serialized, const NodeType* nodeType = 0);
+ ~NodeState();
/**
* Setting prefix to something implies using this function to write a
@@ -55,27 +54,26 @@ public:
void serialize(vespalib::asciistream & out, vespalib::stringref prefix = "",
bool includeDescription = true) const;
- [[nodiscard]] const State& getState() const { return *_state; }
- [[nodiscard]] vespalib::Double getCapacity() const { return _capacity; }
- [[nodiscard]] uint32_t getMinUsedBits() const { return _minUsedBits; }
- [[nodiscard]] vespalib::Double getInitProgress() const { return _initProgress; }
- [[nodiscard]] const vespalib::string& getDescription() const { return _description; }
- [[nodiscard]] vespalib::system_time getStartTimestamp() const { return _startTimestamp; }
+ const State& getState() const { return *_state; }
+ vespalib::Double getCapacity() const { return _capacity; }
+ uint32_t getMinUsedBits() const { return _minUsedBits; }
+ vespalib::Double getInitProgress() const { return _initProgress; }
+ const vespalib::string& getDescription() const { return _description; }
+ uint64_t getStartTimestamp() const { return _startTimestamp; }
void setState(const State& state);
void setCapacity(vespalib::Double capacity);
void setMinUsedBits(uint32_t usedBits);
void setInitProgress(vespalib::Double initProgress);
- void setStartTimestamp(vespalib::system_time startTimestamp);
+ void setStartTimestamp(uint64_t startTimestamp);
void setDescription(vespalib::stringref desc) { _description = desc; }
void print(std::ostream& out, bool verbose,
const std::string& indent) const override;
bool operator==(const NodeState& other) const;
- bool operator!=(const NodeState& other) const {
- return !(operator==(other));
- }
- [[nodiscard]] bool similarTo(const NodeState& other) const;
+ bool operator!=(const NodeState& other) const
+ { return !(operator==(other)); }
+ bool similarTo(const NodeState& other) const;
/**
* Verify that the contents of this object fits with the given nodetype.