From ee2baa1b001a282bd57318a3f0b8881cdcbc3049 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Wed, 25 Nov 2020 18:17:27 +0000 Subject: 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 --- vdslib/src/vespa/vdslib/state/nodetype.cpp | 29 +++++++++++++++++++++-------- vdslib/src/vespa/vdslib/state/nodetype.h | 27 +++++++++++++++------------ 2 files changed, 36 insertions(+), 20 deletions(-) (limited to 'vdslib/src') 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 #include +#include -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 -#include 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(_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 +} -- cgit v1.2.3