some new header + source files (vertices, vertex_accessor, properties), first version of Index works, skiplist<T> + concurrent_set + concurrent_map (still has to be finished)

This commit is contained in:
Marko Budiselic
2016-07-05 04:01:22 +01:00
parent 18e7394d9e
commit b94cae12d1
60 changed files with 1864 additions and 851 deletions

View File

@@ -0,0 +1,20 @@
#pragma once
#include "threading/sync/futex.hpp"
#include "storage/locking/lock_status.hpp"
#include "mvcc/id.hpp"
class RecordLock
{
static constexpr struct timespec timeout {20, 0};
static constexpr Id INVALID = Id();
public:
LockStatus lock(const Id& id);
void lock();
void unlock();
private:
Futex mutex;
Id owner;
};

View File

@@ -0,0 +1,27 @@
#pragma once
#include "storage/model/properties/property.hpp"
class Bool : public Property
{
public:
static constexpr Flags type = Flags::Bool;
Bool(bool value);
Bool(const Bool& other) = default;
bool value() const;
explicit operator bool() const;
bool operator==(const Property& other) const override;
bool operator==(const Bool& other) const;
bool operator==(bool v) const;
std::ostream& print(std::ostream& stream) const override;
friend std::ostream& operator<<(std::ostream& stream, const Bool& prop);
};

View File

@@ -0,0 +1,41 @@
#pragma once
#include "storage/model/properties/property.hpp"
#include "storage/model/properties/bool.hpp"
#include "storage/model/properties/double.hpp"
#include "storage/model/properties/float.hpp"
#include "storage/model/properties/int32.hpp"
#include "storage/model/properties/int64.hpp"
#include "storage/model/properties/string.hpp"
template <class Handler>
void accept(Property &property, Handler &h)
{
switch (property.flags) {
case Property::Flags::True:
return h.handle(static_cast<Bool &>(property));
case Property::Flags::False:
return h.handle(static_cast<Bool &>(property));
case Property::Flags::String:
return h.handle(static_cast<String &>(property));
case Property::Flags::Int32:
return h.handle(static_cast<Int32 &>(property));
case Property::Flags::Int64:
return h.handle(static_cast<Int64 &>(property));
case Property::Flags::Float:
return h.handle(static_cast<Float &>(property));
case Property::Flags::Double:
return h.handle(static_cast<Double &>(property));
default:
return;
}
}

View File

@@ -0,0 +1,31 @@
#pragma once
#include "storage/model/properties/property.hpp"
class Null : public Property
{
public:
friend class Property;
static constexpr Flags type = Flags::Null;
Null(const Null&) = delete;
Null(Null&&) = delete;
Null operator=(const Null&) = delete;
bool operator==(const Property& other) const override;
bool operator==(const Null&) const;
explicit operator bool();
friend std::ostream& operator<<(std::ostream& stream, const Null&);
std::ostream& print(std::ostream& stream) const override;
private:
// the constructor for null is private, it can be constructed only as a
// value inside the Property class, Property::Null
Null();
};

View File

@@ -0,0 +1,33 @@
#pragma once
#include <map>
#include "storage/model/properties/property.hpp"
class Properties
{
public:
using sptr = std::shared_ptr<Properties>;
const Property& at(const std::string& key) const;
template <class T, class... Args>
void set(const std::string& key, Args&&... args);
void set(const std::string& key, Property::sptr value);
void clear(const std::string& key);
template <class Handler>
void accept(Handler& handler) const
{
for(auto& kv : props)
handler.handle(kv.first, *kv.second);
handler.finish();
}
private:
using props_t = std::map<std::string, Property::sptr>;
props_t props;
};

View File

@@ -0,0 +1,113 @@
#pragma once
#include <memory>
#include <string>
#include <cassert>
#include <ostream>
#include <vector>
#include "utils/underlying_cast.hpp"
class Null;
class Property
{
public:
using sptr = std::shared_ptr<Property>;
enum class Flags : unsigned
{
// Type | Mask
// -----------+----------------------------------------
// Null | 0000 0000 0000 0000 0000 0000 0000 0000
// -----------+----------------------------------------
// Bool | 0000 0000 0000 0000 0000 0000 0000 0001
// + True | 0000 0000 0000 0000 0000 0000 0000 0011
// + False | 0000 0000 0000 0000 0000 0000 0000 0101
// -----------+----------------------------------------
// String | 0000 0000 0000 0000 0000 0000 0000 1000
// -----------+----------------------------------------
// Number | 0000 0000 0000 0000 0000 0000 0001 0000
// + Integral | 0000 0000 0000 0000 0000 0000 0011 0000
// + Int32 | 0000 0000 0000 0000 0000 0000 0111 0000
// + Int64 | 0000 0000 0000 0000 0000 0000 1011 0000
// + Floating | 0000 0000 0000 0000 0000 0001 0001 0000
// + Float | 0000 0000 0000 0000 0000 0011 0001 0000
// + Double | 0000 0000 0000 0000 0000 0101 0001 0000
// -----------+----------------------------------------
// Array | 0000 0000 0000 0000 0001 0000 0000 0000
// -----------+----------------------------------------
Null = 0x0,
Bool = 0x1,
True = 0x2 | Bool,
False = 0x4 | Bool,
String = 0x8,
Number = 0x10,
Integral = 0x20 | Number,
Int32 = 0x40 | Integral,
Int64 = 0x80 | Integral,
Floating = 0x100 | Number,
Float = 0x200 | Floating,
Double = 0x400 | Floating,
Array = 0x1000,
type_mask = 0xFFF
};
static const Null Null;
Property(Flags flags);
virtual bool operator==(const Property& other) const = 0;
bool operator!=(const Property& other) const;
template <class T>
bool is() const
{
return underlying_cast(flags) & underlying_cast(T::type);
}
template <class T>
T& as()
{
assert(this->is<T>());
return *static_cast<T*>(this);
}
template <class T>
const T& as() const
{
assert(this->is<T>());
return *static_cast<const T*>(this);
}
virtual std::ostream& print(std::ostream& stream) const = 0;
friend std::ostream& operator<<(std::ostream& stream, const Property& prop);
// template <class Handler>
// void accept(Handler& h)
// {
// switch(flags)
// {
// case Flags::True: return h.handle(static_cast<Bool&>(*this));
// case Flags::False: return h.handle(static_cast<Bool&>(*this));
// case Flags::String: return h.handle(static_cast<String&>(*this));
// case Flags::Int32: return h.handle(static_cast<Int32&>(*this));
// case Flags::Int64: return h.handle(static_cast<Int64&>(*this));
// case Flags::Float: return h.handle(static_cast<Float&>(*this));
// case Flags::Double: return h.handle(static_cast<Double&>(*this));
// default: return;
// }
// }
const Flags flags;
};
using properties_t = std::vector<Property::sptr>;

View File

@@ -0,0 +1,29 @@
#pragma once
#include "storage/model/properties/property.hpp"
class String : public Property
{
public:
static constexpr Flags type = Flags::String;
String(const String&) = default;
String(String&&) = default;
String(const std::string& value);
String(std::string&& value);
operator const std::string&() const;
bool operator==(const Property& other) const override;
bool operator==(const String& other) const;
bool operator==(const std::string& other) const;
friend std::ostream& operator<<(std::ostream& stream, const String& prop);
std::ostream& print(std::ostream& stream) const override;
std::string value;
};

View File

@@ -0,0 +1,25 @@
#pragma once
#include "storage/record_accessor.hpp"
#include "storage/vertex.hpp"
class Vertices;
class Vertex::Accessor
: public RecordAccessor<Vertex, Vertices, Vertex::Accessor>
{
public:
using RecordAccessor::RecordAccessor;
size_t out_degree() const;
size_t in_degree() const;
size_t degree() const;
void add_label(const Label &label);
bool has_label(const Label &label) const;
const std::set<label_ref_t>& labels() const;
};

View File

@@ -0,0 +1,26 @@
#pragma once
#include "data_structures/concurrent/concurrent_map.hpp"
#include "storage/common.hpp"
#include "storage/indexes/index.hpp"
#include "storage/indexes/index_record_collection.hpp"
#include "storage/vertex_accessor.hpp"
class Vertices
{
public:
const Vertex::Accessor find(tx::Transaction &t, const Id &id);
Vertex::Accessor insert(tx::Transaction &t);
void update_label_index(const Label &label,
VertexIndexRecord &&index_record);
VertexIndexRecordCollection& find_label_index(const Label& label);
private:
Index<label_ref_t, VertexIndexRecordCollection> label_index;
ConcurrentMap<uint64_t, VertexRecord> vertices;
AtomicCounter<uint64_t> counter;
};

View File

@@ -0,0 +1,18 @@
#pragma once
#include <string>
#include <unordered_map>
namespace template_engine
{
using std::string;
using data = std::unordered_map<string, string>;
class TemplateEngine
{
public:
string render(const string& form, const data& partials);
};
}

View File

@@ -0,0 +1,42 @@
#pragma once
#include <cstdint>
#include <cstdlib>
#include <vector>
#include "mvcc/id.hpp"
#include "storage/locking/record_lock.hpp"
#include "transactions/lock_store.hpp"
#include "transactions/snapshot.hpp"
namespace tx
{
class Engine;
class Transaction
{
friend class Engine;
public:
Transaction(const Id &id, const Snapshot<Id> &snapshot, Engine &engine);
Transaction(const Transaction &) = delete;
Transaction(Transaction &&) = delete;
// index of this transaction
const Id id;
// index of the current command in the current transaction;
uint8_t cid;
// a snapshot of currently active transactions
const Snapshot<Id> snapshot;
void take_lock(RecordLock &lock);
void commit();
void abort();
Engine &engine;
private:
LockStore<RecordLock> locks;
};
}