summaryrefslogtreecommitdiffstats
path: root/vdslib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-11-25 18:17:27 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-11-26 00:23:06 +0000
commitee2baa1b001a282bd57318a3f0b8881cdcbc3049 (patch)
treee1bd88266adb509a9ce4006f7d68cbc59db3c295 /vdslib
parente1584673531bc771fa94731da337ce311b4ff7d1 (diff)
As we have have now removed the expensive Route member we can further compact the message objects.
- Compact StorageMessageAddress to 16 bytes by - using reference to cluster name. - Use small enums for protocol and node type. - Avoid having StorageMessage as separate allocation. - Avoid default values
Diffstat (limited to 'vdslib')
-rw-r--r--vdslib/src/vespa/vdslib/state/nodetype.cpp29
-rw-r--r--vdslib/src/vespa/vdslib/state/nodetype.h27
2 files changed, 36 insertions, 20 deletions
diff --git a/vdslib/src/vespa/vdslib/state/nodetype.cpp b/vdslib/src/vespa/vdslib/state/nodetype.cpp
index 915b1548f88..97e15625186 100644
--- a/vdslib/src/vespa/vdslib/state/nodetype.cpp
+++ b/vdslib/src/vespa/vdslib/state/nodetype.cpp
@@ -3,15 +3,15 @@
#include "nodetype.h"
#include <vespa/vespalib/util/exceptions.h>
#include <vespa/vespalib/stllike/asciistream.h>
+#include <cassert>
-namespace storage {
-namespace lib {
+namespace storage::lib {
// WARNING: Because static initialization happen in random order, the State
// class use these enum values directly during static initialization since
// these objects may yet not exist. Update in State if you change this.
-const NodeType NodeType::STORAGE("storage", 0);
-const NodeType NodeType::DISTRIBUTOR("distributor", 1);
+const NodeType NodeType::STORAGE("storage", NodeType::Type::STORAGE);
+const NodeType NodeType::DISTRIBUTOR("distributor", NodeType::Type::DISTRIBUTOR);
const NodeType&
NodeType::get(vespalib::stringref serialized)
@@ -26,8 +26,22 @@ NodeType::get(vespalib::stringref serialized)
"Unknown node type " + serialized + " given.", VESPA_STRLOC);
}
-NodeType::NodeType(vespalib::stringref name, uint16_t enumValue)
- : _enumValue(enumValue), _name(name)
+const NodeType&
+NodeType::get(Type type)
+{
+ switch (type) {
+ case Type::STORAGE:
+ return STORAGE;
+ case Type::DISTRIBUTOR:
+ return DISTRIBUTOR;
+ case Type::UNKNOWN:
+ assert(type != Type::UNKNOWN);
+ }
+ abort();
+}
+
+NodeType::NodeType(vespalib::stringref name, Type type)
+ : _type(type), _name(name)
{
}
@@ -39,5 +53,4 @@ vespalib::asciistream & operator << (vespalib::asciistream & os, const NodeType
return os << n.toString();
}
-} // lib
-} // storage
+}
diff --git a/vdslib/src/vespa/vdslib/state/nodetype.h b/vdslib/src/vespa/vdslib/state/nodetype.h
index 35edd83fdac..abf1c5709b6 100644
--- a/vdslib/src/vespa/vdslib/state/nodetype.h
+++ b/vdslib/src/vespa/vdslib/state/nodetype.h
@@ -10,31 +10,30 @@
#pragma once
#include <vespa/vespalib/stllike/string.h>
-#include <stdint.h>
namespace vespalib {
class asciistream;
}
-namespace storage {
-namespace lib {
+namespace storage::lib {
class NodeType {
- typedef vespalib::asciistream asciistream;
- uint16_t _enumValue;
- vespalib::string _name;
-
- NodeType(vespalib::stringref name, uint16_t enumValue);
-
public:
+ NodeType(const NodeType &) = delete;
+ NodeType & operator = (const NodeType &) = delete;
+ NodeType(NodeType &&) = delete;
+ NodeType & operator =(NodeType &&) = delete;
+ enum class Type : uint8_t {STORAGE = 0, DISTRIBUTOR = 1, UNKNOWN = 2};
static const NodeType DISTRIBUTOR;
static const NodeType STORAGE;
/** Throws vespalib::IllegalArgumentException if invalid state given. */
static const NodeType& get(vespalib::stringref serialized);
+ static const NodeType& get(Type type);
const vespalib::string& serialize() const { return _name; }
- operator uint16_t() const { return _enumValue; }
+ Type getType() const { return _type; }
+ operator uint16_t() const { return static_cast<uint16_t>(_type); }
const vespalib::string & toString() const { return _name; }
bool operator==(const NodeType& other) const { return (&other == this); }
@@ -43,11 +42,15 @@ public:
bool operator<(const NodeType& other) const {
return (&other == this ? false : *this == NodeType::DISTRIBUTOR);
}
+private:
+ Type _type;
+ vespalib::string _name;
+
+ NodeType(vespalib::stringref name, Type type);
};
std::ostream & operator << (std::ostream & os, const NodeType & n);
vespalib::asciistream & operator << (vespalib::asciistream & os, const NodeType & n);
-} // lib
-} // storage
+}