diff --git a/src/coordinator/hybrid_logical_clock.hpp b/src/coordinator/hybrid_logical_clock.hpp index 04f6eba26..38571dc20 100644 --- a/src/coordinator/hybrid_logical_clock.hpp +++ b/src/coordinator/hybrid_logical_clock.hpp @@ -11,7 +11,10 @@ #pragma once +#include #include +#include +#include #include "io/time.hpp" @@ -31,6 +34,15 @@ struct Hlc { bool operator==(const uint64_t other) const { return logical_id == other; } bool operator<(const uint64_t other) const { return logical_id < other; } bool operator>=(const uint64_t other) const { return logical_id >= other; } + + friend std::ostream &operator<<(std::ostream &in, const Hlc &hlc) { + auto wall_clock = std::chrono::system_clock::to_time_t(hlc.coordinator_wall_clock); + in << "Hlc { logical_id: " << hlc.logical_id; + in << ", coordinator_wall_clock: " << std::put_time(std::localtime(&wall_clock), "%F %T"); + in << " }"; + + return in; + } }; } // namespace memgraph::coordinator diff --git a/src/coordinator/shard_map.hpp b/src/coordinator/shard_map.hpp index 78a80e9e7..f869c79d1 100644 --- a/src/coordinator/shard_map.hpp +++ b/src/coordinator/shard_map.hpp @@ -29,6 +29,7 @@ #include "storage/v3/schemas.hpp" #include "storage/v3/temporal.hpp" #include "utils/exceptions.hpp" +#include "utils/print_helpers.hpp" namespace memgraph::coordinator { @@ -53,7 +54,21 @@ enum class Status : uint8_t { struct AddressAndStatus { memgraph::io::Address address; Status status; + friend bool operator<(const AddressAndStatus &lhs, const AddressAndStatus &rhs) { return lhs.address < rhs.address; } + + friend std::ostream &operator<<(std::ostream &in, const AddressAndStatus &address_and_status) { + in << "AddressAndStatus { address: "; + in << address_and_status.address; + if (address_and_status.status == Status::CONSENSUS_PARTICIPANT) { + in << ", status: CONSENSUS_PARTICIPANT }"; + } else { + in << ", status: INITIALIZING }"; + } + + return in; + } + friend bool operator==(const AddressAndStatus &lhs, const AddressAndStatus &rhs) { return lhs.address == rhs.address; } @@ -83,6 +98,18 @@ struct LabelSpace { std::vector schema; std::map shards; size_t replication_factor; + + friend std::ostream &operator<<(std::ostream &in, const LabelSpace &label_space) { + using utils::print_helpers::operator<<; + + in << "LabelSpace { schema: "; + in << label_space.schema; + in << ", shards: "; + in << label_space.shards; + in << ", replication_factor: " << label_space.replication_factor << "}"; + + return in; + } }; struct ShardMap { @@ -96,6 +123,22 @@ struct ShardMap { std::map label_spaces; std::map> schemas; + friend std::ostream &operator<<(std::ostream &in, const ShardMap &shard_map) { + using utils::print_helpers::operator<<; + + in << "ShardMap { shard_map_version: " << shard_map.shard_map_version; + in << ", max_property_id: " << shard_map.max_property_id; + in << ", max_edge_type_id: " << shard_map.max_edge_type_id; + in << ", properties: " << shard_map.properties; + in << ", edge_types: " << shard_map.edge_types; + in << ", max_label_id: " << shard_map.max_label_id; + in << ", labels: " << shard_map.labels; + in << ", label_spaces: " << shard_map.label_spaces; + in << ", schemas: " << shard_map.schemas; + in << "}"; + return in; + } + Shards GetShards(const LabelName &label) { const auto id = labels.at(label); auto &shards = label_spaces.at(id).shards; diff --git a/src/io/address.hpp b/src/io/address.hpp index 286bab577..73c7f1efd 100644 --- a/src/io/address.hpp +++ b/src/io/address.hpp @@ -20,6 +20,30 @@ #include namespace memgraph::io { + +struct PartialAddress { + boost::asio::ip::address ip; + uint16_t port; + + friend bool operator==(const PartialAddress &lhs, const PartialAddress &rhs) = default; + + /// unique_id is most dominant for ordering, then ip, then port + friend bool operator<(const PartialAddress &lhs, const PartialAddress &rhs) { + if (lhs.ip != rhs.ip) { + return lhs.ip < rhs.ip; + } + + return lhs.port < rhs.port; + } + + std::string ToString() const { return fmt::format("PartialAddress {{ ip: {}, port: {} }}", ip.to_string(), port); } + + friend std::ostream &operator<<(std::ostream &in, const PartialAddress &partial_address) { + in << partial_address.ToString(); + return in; + } +}; + struct Address { // It's important for all participants to have a // unique identifier - IP and port alone are not @@ -73,5 +97,10 @@ struct Address { return fmt::format("Address {{ unique_id: {}, last_known_ip: {}, last_known_port: {} }}", boost::uuids::to_string(unique_id), last_known_ip.to_string(), last_known_port); } + + friend std::ostream &operator<<(std::ostream &in, const Address &address) { + in << address.ToString(); + return in; + } }; }; // namespace memgraph::io diff --git a/src/storage/v3/id_types.hpp b/src/storage/v3/id_types.hpp index 02c98b801..d67a72151 100644 --- a/src/storage/v3/id_types.hpp +++ b/src/storage/v3/id_types.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "utils/cast.hpp" @@ -35,6 +36,11 @@ namespace memgraph::storage::v3 { constexpr uint64_t AsUint() const { return id_; } \ constexpr int64_t AsInt() const { return std::bit_cast(id_); } \ \ + friend std::ostream &operator<<(std::ostream &in, const name &n) { \ + in << n.AsInt(); \ + return in; \ + } \ + \ private: \ uint64_t id_; \ }; \ diff --git a/src/storage/v3/schemas.hpp b/src/storage/v3/schemas.hpp index 8c3232dfc..1fae29b2f 100644 --- a/src/storage/v3/schemas.hpp +++ b/src/storage/v3/schemas.hpp @@ -25,11 +25,22 @@ namespace memgraph::storage::v3 { +std::string SchemaTypeToString(common::SchemaType type); + struct SchemaProperty { PropertyId property_id; common::SchemaType type; friend bool operator==(const SchemaProperty &lhs, const SchemaProperty &rhs); + + friend std::ostream &operator<<(std::ostream &in, const SchemaProperty &schema_property) { + in << "SchemaProperty { property_id: ", in << schema_property.property_id.AsUint(); + in << ", type: "; + in << SchemaTypeToString(schema_property.type); + in << " }"; + + return in; + } }; /// Structure that represents a collection of schemas @@ -69,6 +80,4 @@ class Schemas { std::optional PropertyTypeToSchemaType(const PropertyValue &property_value); -std::string SchemaTypeToString(common::SchemaType type); - } // namespace memgraph::storage::v3 diff --git a/src/utils/print_helpers.hpp b/src/utils/print_helpers.hpp new file mode 100644 index 000000000..e5d3f379c --- /dev/null +++ b/src/utils/print_helpers.hpp @@ -0,0 +1,63 @@ +// Copyright 2022 Memgraph Ltd. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source +// License, and you may not use this file except in compliance with the Business Source License. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +#pragma once + +#include +#include +#include + +namespace memgraph::utils::print_helpers { + +template +std::ostream &operator<<(std::ostream &in, const std::vector &vector) { + in << "["; + bool first = true; + for (const auto &item : vector) { + if (!first) { + in << ", "; + } + first = false; + in << item; + } + in << "]"; + return in; +} + +template +std::ostream &operator<<(std::ostream &in, const std::map &map) { + in << "{"; + bool first = true; + for (const auto &[a, b] : map) { + if (!first) { + in << ", "; + } + first = false; + in << a; + in << ": "; + in << b; + } + in << "}"; + return in; +} + +template +std::ostream &operator<<(std::ostream &in, const std::pair &pair) { + const auto &[a, b] = pair; + in << "("; + in << a; + in << ", "; + in << b; + in << ")"; + return in; +} + +} // namespace memgraph::utils::print_helpers