refactored storage engine
This commit is contained in:
parent
1324b2ded1
commit
d22eedfe9e
@ -1,16 +1,23 @@
|
|||||||
#ifndef MEMGRAPH_STORAGE_EDGE_HPP
|
#pragma once
|
||||||
#define MEMGRAPH_STORAGE_EDGE_HPP
|
|
||||||
|
|
||||||
#include <vector>
|
#include "model/properties/jsonwriter.hpp"
|
||||||
|
#include "model/edge_model.hpp"
|
||||||
|
#include "mvcc/record.hpp"
|
||||||
|
|
||||||
#include "model/record.hpp"
|
class Edge;
|
||||||
|
|
||||||
struct Vertex;
|
class Edge : public mvcc::Record<Edge>
|
||||||
|
|
||||||
struct Edge : public Record<Edge>
|
|
||||||
{
|
{
|
||||||
Vertex* from;
|
public:
|
||||||
Vertex* to;
|
Edge() = default;
|
||||||
};
|
Edge(const EdgeModel& data) : data(data) {}
|
||||||
|
Edge(EdgeModel&& data) : data(std::move(data)) {}
|
||||||
|
|
||||||
#endif
|
Edge(const Edge&) = delete;
|
||||||
|
Edge(Edge&&) = delete;
|
||||||
|
|
||||||
|
Edge& operator=(const Edge&) = delete;
|
||||||
|
Edge& operator=(Edge&&) = delete;
|
||||||
|
|
||||||
|
EdgeModel data;
|
||||||
|
};
|
||||||
|
39
storage/model/edge_list.hpp
Normal file
39
storage/model/edge_list.hpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "mvcc/version_list.hpp"
|
||||||
|
|
||||||
|
class EdgeList
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
auto begin() { return edges.begin(); }
|
||||||
|
auto begin() const { return edges.begin(); }
|
||||||
|
auto cbegin() const { return edges.begin(); }
|
||||||
|
|
||||||
|
auto end() { return edges.end(); }
|
||||||
|
auto end() const { return edges.end(); }
|
||||||
|
auto cend() const { return edges.end(); }
|
||||||
|
|
||||||
|
void add(EdgeRecord* edge)
|
||||||
|
{
|
||||||
|
edges.push_back(edge);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t degree() const
|
||||||
|
{
|
||||||
|
return edges.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
void remove(EdgeRecord* edge)
|
||||||
|
{
|
||||||
|
edges.erase(std::remove(edges.begin(), edges.end(), edge), edges.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear()
|
||||||
|
{
|
||||||
|
edges.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<EdgeRecord*> edges;
|
||||||
|
};
|
14
storage/model/edge_model.hpp
Normal file
14
storage/model/edge_model.hpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "property_model.hpp"
|
||||||
|
#include "edge_type.hpp"
|
||||||
|
#include "mvcc/version_list.hpp"
|
||||||
|
|
||||||
|
class EdgeModel : public PropertyModel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VertexRecord* from;
|
||||||
|
VertexRecord* to;
|
||||||
|
|
||||||
|
EdgeType edge_type;
|
||||||
|
};
|
35
storage/model/edge_type.hpp
Normal file
35
storage/model/edge_type.hpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <ostream>
|
||||||
|
#include "utils/total_ordering.hpp"
|
||||||
|
|
||||||
|
class EdgeType : public TotalOrdering<EdgeType>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
EdgeType(const std::string& id) : id(id) {}
|
||||||
|
EdgeType(std::string&& id) : id(std::move(id)) {}
|
||||||
|
|
||||||
|
friend bool operator<(const EdgeType& lhs, const EdgeType& rhs)
|
||||||
|
{
|
||||||
|
return lhs.id < rhs.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend bool operator==(const EdgeType& lhs, const EdgeType& rhs)
|
||||||
|
{
|
||||||
|
return lhs.id == rhs.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend std::ostream& operator<<(std::ostream& stream, const EdgeType& type)
|
||||||
|
{
|
||||||
|
return stream << type.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
operator const std::string&() const
|
||||||
|
{
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string id;
|
||||||
|
};
|
35
storage/model/label.hpp
Normal file
35
storage/model/label.hpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <ostream>
|
||||||
|
#include "utils/total_ordering.hpp"
|
||||||
|
|
||||||
|
class Label : public TotalOrdering<Label>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Label(const std::string& id) : id(id) {}
|
||||||
|
Label(std::string&& id) : id(std::move(id)) {}
|
||||||
|
|
||||||
|
friend bool operator<(const Label& lhs, const Label& rhs)
|
||||||
|
{
|
||||||
|
return lhs.id < rhs.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend bool operator==(const Label& lhs, const Label& rhs)
|
||||||
|
{
|
||||||
|
return lhs.id == rhs.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend std::ostream& operator<<(std::ostream& stream, const Label& label)
|
||||||
|
{
|
||||||
|
return stream << label.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
operator const std::string&() const
|
||||||
|
{
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string id;
|
||||||
|
};
|
54
storage/model/label_list.hpp
Normal file
54
storage/model/label_list.hpp
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
#include "label.hpp"
|
||||||
|
|
||||||
|
class LabelList
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
auto begin() { return labels.begin(); }
|
||||||
|
auto begin() const { return labels.begin(); }
|
||||||
|
auto cbegin() const { return labels.begin(); }
|
||||||
|
|
||||||
|
auto end() { return labels.end(); }
|
||||||
|
auto end() const { return labels.end(); }
|
||||||
|
auto cend() const { return labels.end(); }
|
||||||
|
|
||||||
|
bool add(Label&& label)
|
||||||
|
{
|
||||||
|
return labels.insert(std::move(label)).second;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool add(const Label& label)
|
||||||
|
{
|
||||||
|
return labels.insert(label).second;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool has(const Label& label) const
|
||||||
|
{
|
||||||
|
return labels.count(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t count() const
|
||||||
|
{
|
||||||
|
return labels.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool remove(const Label& label)
|
||||||
|
{
|
||||||
|
auto it = labels.find(label);
|
||||||
|
|
||||||
|
if(it == labels.end())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return labels.erase(it), true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear()
|
||||||
|
{
|
||||||
|
labels.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::set<Label> labels;
|
||||||
|
};
|
@ -1,8 +1,6 @@
|
|||||||
#ifndef MEMGRAPH_STORAGE_PROPERTIES_JSONWRITER_HPP
|
#pragma once
|
||||||
#define MEMGRAPH_STORAGE_PROPERTIES_JSONWRITER_HPP
|
|
||||||
|
|
||||||
#include "properties.hpp"
|
#include "properties.hpp"
|
||||||
#include "storage/model/properties/jsonwriter.hpp"
|
|
||||||
|
|
||||||
template <class Buffer>
|
template <class Buffer>
|
||||||
struct JsonWriter
|
struct JsonWriter
|
||||||
@ -95,5 +93,3 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::string data;
|
std::string data;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#ifndef MEMGRAPH_STORAGE_MODEL_PROPERTIES_PROPERTIES_HPP
|
#pragma once
|
||||||
#define MEMGRAPH_STORAGE_MODEL_PROPERTIES_PROPERTIES_HPP
|
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "rapidjson/document.h"
|
|
||||||
|
|
||||||
#include "property.hpp"
|
#include "property.hpp"
|
||||||
|
|
||||||
@ -15,7 +13,7 @@ public:
|
|||||||
{
|
{
|
||||||
return props.find(key);
|
return props.find(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
Property* at(const std::string& key)
|
Property* at(const std::string& key)
|
||||||
{
|
{
|
||||||
auto it = props.find(key);
|
auto it = props.find(key);
|
||||||
@ -49,14 +47,14 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class Handler>
|
template <class Handler>
|
||||||
void accept(Handler& handler)
|
void accept(Handler& handler) const
|
||||||
{
|
{
|
||||||
bool first = true;
|
bool first = true;
|
||||||
|
|
||||||
for(auto& kv : props)
|
for(auto& kv : props)
|
||||||
{
|
{
|
||||||
handler.handle(kv.first, *kv.second, first);
|
handler.handle(kv.first, *kv.second, first);
|
||||||
|
|
||||||
if(first)
|
if(first)
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
@ -65,5 +63,3 @@ public:
|
|||||||
private:
|
private:
|
||||||
props_t props;
|
props_t props;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
9
storage/model/property_model.hpp
Normal file
9
storage/model/property_model.hpp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "properties/properties.hpp"
|
||||||
|
|
||||||
|
class PropertyModel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Properties props;
|
||||||
|
};
|
@ -14,16 +14,14 @@
|
|||||||
#include "properties/properties.hpp"
|
#include "properties/properties.hpp"
|
||||||
|
|
||||||
template <class Derived>
|
template <class Derived>
|
||||||
class Record
|
class Record : public Crtp<Derived>, public mvcc::Mvcc<Derived>
|
||||||
: public Crtp<Derived>,
|
|
||||||
public mvcc::Mvcc<Derived>
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// a record contains a key value map containing data
|
// a record contains a key value map containing data
|
||||||
Properties properties;
|
Properties properties;
|
||||||
|
|
||||||
// each record can have one or more distinct labels.
|
// each record can have one or more distinct labels.
|
||||||
std::set<uint16_t> labels;
|
// std::set<uint16_t> labels;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
12
storage/model/vertex_model.hpp
Normal file
12
storage/model/vertex_model.hpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "property_model.hpp"
|
||||||
|
#include "label_list.hpp"
|
||||||
|
#include "edge_list.hpp"
|
||||||
|
|
||||||
|
class VertexModel : public PropertyModel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
EdgeList in, out;
|
||||||
|
LabelList labels;
|
||||||
|
};
|
@ -1,29 +1,37 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "model/properties/jsonwriter.hpp"
|
#include "model/properties/jsonwriter.hpp"
|
||||||
#include "model/record.hpp"
|
#include "model/vertex_model.hpp"
|
||||||
#include "edge.hpp"
|
#include "mvcc/record.hpp"
|
||||||
|
|
||||||
struct Vertex : public Record<Vertex>
|
class Vertex : public mvcc::Record<Vertex>
|
||||||
{
|
{
|
||||||
std::vector<Edge*> in;
|
public:
|
||||||
std::vector<Edge*> out;
|
Vertex() = default;
|
||||||
|
Vertex(const VertexModel& data) : data(data) {}
|
||||||
|
Vertex(VertexModel&& data) : data(std::move(data)) {}
|
||||||
|
|
||||||
|
Vertex(const Vertex&) = delete;
|
||||||
|
Vertex(Vertex&&) = delete;
|
||||||
|
|
||||||
|
Vertex& operator=(const Vertex&) = delete;
|
||||||
|
Vertex& operator=(Vertex&&) = delete;
|
||||||
|
|
||||||
|
VertexModel data;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::ostream& operator<<(std::ostream& stream, Vertex& record)
|
inline std::ostream& operator<<(std::ostream& stream, const Vertex& record)
|
||||||
{
|
{
|
||||||
StringBuffer buffer;
|
StringBuffer buffer;
|
||||||
JsonWriter<StringBuffer> writer(buffer);
|
JsonWriter<StringBuffer> writer(buffer);
|
||||||
|
|
||||||
// dump properties in this buffer
|
// dump properties in this buffer
|
||||||
record.properties.accept(writer);
|
record.data.props.accept(writer);
|
||||||
writer.finish();
|
writer.finish();
|
||||||
|
|
||||||
return stream << "Vertex"
|
return stream << "Vertex"
|
||||||
<< "(xmin = " << record.tx.min()
|
<< "(xmin = " << record.tx.cre()
|
||||||
<< ", xmax = " << record.tx.max()
|
<< ", xmax = " << record.tx.exp()
|
||||||
<< "): " << buffer.str();
|
<< "): " << buffer.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +43,7 @@ inline std::string properties_to_string(Vertex* vertex)
|
|||||||
JsonWriter<StringBuffer> writer(buffer);
|
JsonWriter<StringBuffer> writer(buffer);
|
||||||
|
|
||||||
// dump properties in this buffer
|
// dump properties in this buffer
|
||||||
vertex->properties.accept(writer);
|
vertex->data.props.accept(writer);
|
||||||
writer.finish();
|
writer.finish();
|
||||||
|
|
||||||
// respond to the use with the buffer
|
// respond to the use with the buffer
|
||||||
|
Loading…
Reference in New Issue
Block a user