Merge branch 'project-pineapples' into T1083-MG-limit-and-order-expand-one_v3

This commit is contained in:
Jeremy B 2022-10-21 18:17:34 +02:00 committed by GitHub
commit cb00b43ca7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 164 additions and 2 deletions

View File

@ -11,7 +11,10 @@
#pragma once
#include <chrono>
#include <compare>
#include <ctime>
#include <iomanip>
#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

View File

@ -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<SchemaProperty> schema;
std::map<PrimaryKey, Shard> 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<LabelId, LabelSpace> label_spaces;
std::map<LabelId, std::vector<SchemaProperty>> 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;

View File

@ -20,6 +20,30 @@
#include <boost/uuid/uuid_io.hpp>
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

View File

@ -14,6 +14,7 @@
#include <bit>
#include <cstdint>
#include <functional>
#include <iostream>
#include <type_traits>
#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<int64_t>(id_); } \
\
friend std::ostream &operator<<(std::ostream &in, const name &n) { \
in << n.AsInt(); \
return in; \
} \
\
private: \
uint64_t id_; \
}; \

View File

@ -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<common::SchemaType> PropertyTypeToSchemaType(const PropertyValue &property_value);
std::string SchemaTypeToString(common::SchemaType type);
} // namespace memgraph::storage::v3

View File

@ -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 <map>
#include <memory>
#include <vector>
namespace memgraph::utils::print_helpers {
template <typename T>
std::ostream &operator<<(std::ostream &in, const std::vector<T> &vector) {
in << "[";
bool first = true;
for (const auto &item : vector) {
if (!first) {
in << ", ";
}
first = false;
in << item;
}
in << "]";
return in;
}
template <typename K, typename V>
std::ostream &operator<<(std::ostream &in, const std::map<K, V> &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 <typename K, typename V>
std::ostream &operator<<(std::ostream &in, const std::pair<K, V> &pair) {
const auto &[a, b] = pair;
in << "(";
in << a;
in << ", ";
in << b;
in << ")";
return in;
}
} // namespace memgraph::utils::print_helpers