some header files are splitted (WORK IN PROGRESS)

This commit is contained in:
Marko Budiselic 2016-07-05 13:20:33 +01:00
parent b94cae12d1
commit 2b1fc70695
29 changed files with 269 additions and 286 deletions

View File

@ -184,22 +184,25 @@ EXECUTE_PROCESS(
# target_link_libraries(query_hasher ${fmt_static_lib})
# hard coded implementation of queries
add_executable(
queries
src/query_engine/main_queries.cpp
src/storage/vertices.cpp
src/storage/model/properties/property.cpp
src/storage/model/properties/null.cpp
src/storage/model/properties/bool.cpp
src/storage/model/properties/string.cpp
src/storage/model/properties/properties.cpp
src/storage/locking/record_lock.cpp
src/storage/vertices.cpp
src/storage/vertex_accessor.cpp
src/transactions/transaction.cpp
)
target_link_libraries(queries ${fmt_static_lib})
# add_executable(
# queries
# src/query_engine/main_queries.cpp
# src/mvcc/id.cpp
# src/storage/label_store.cpp
# src/storage/vertices.cpp
# src/storage/model/label.cpp
# src/storage/model/label_collection.cpp
# src/storage/model/properties/property.cpp
# src/storage/model/properties/null.cpp
# src/storage/model/properties/bool.cpp
# src/storage/model/properties/string.cpp
# src/storage/model/properties/properties.cpp
# src/storage/locking/record_lock.cpp
# src/storage/vertex_accessor.cpp
# src/transactions/transaction.cpp
# )
# target_link_libraries(queries ${fmt_static_lib})
# tests
# enable_testing()
# add_subdirectory(tests)
enable_testing()
add_subdirectory(tests)

View File

@ -1,11 +1,11 @@
#pragma once
#include <iostream>
#include <string>
#include <stdexcept>
#include <dlfcn.h>
#include <atomic>
#include <iostream>
using std::cout;
using std::endl;

25
include/mvcc/id.hpp Normal file
View File

@ -0,0 +1,25 @@
#pragma once
#include <ostream>
#include <stdint.h>
#include "utils/total_ordering.hpp"
class Id : public TotalOrdering<Id>
{
public:
Id() = default;
Id(uint64_t id);
friend bool operator<(const Id& a, const Id& b);
friend bool operator==(const Id& a, const Id& b);
friend std::ostream& operator<<(std::ostream& stream, const Id& id);
operator uint64_t() const;
private:
uint64_t id {0};
};

View File

@ -0,0 +1,21 @@
#pragma once
#include <stdexcept>
#include "storage/model/label.hpp"
#include "data_structures/concurrent/concurrent_set.hpp"
class LabelStore
{
public:
const Label& find_or_create(const std::string& name);
bool contains(const std::string& name); // TODO: const
// TODO: implement find method
// return { Label, is_found }
private:
ConcurrentSet<Label> labels;
};

View File

@ -0,0 +1,30 @@
#pragma once
#include <stdint.h>
#include <ostream>
#include "utils/total_ordering.hpp"
#include "utils/reference_wrapper.hpp"
class Label : public TotalOrdering<Label>
{
public:
Label(const std::string& name);
Label(std::string&& name);
Label(const Label&) = default;
Label(Label&&) = default;
friend bool operator<(const Label& lhs, const Label& rhs);
friend bool operator==(const Label& lhs, const Label& rhs);
friend std::ostream& operator<<(std::ostream& stream, const Label& label);
operator const std::string&() const;
private:
std::string name;
};
using label_ref_t = ReferenceWrapper<const Label>;

View File

@ -0,0 +1,27 @@
#pragma once
#include <set>
#include "storage/model/label.hpp"
class LabelCollection
{
public:
auto begin();
auto begin() const;
auto cbegin() const;
auto end();
auto end() const;
auto cend() const;
bool add(const Label& label);
bool has(const Label& label) const;
size_t count() const;
bool remove(const Label& label);
void clear();
const std::set<label_ref_t>& operator()() const;
private:
std::set<label_ref_t> _labels;
};

View File

@ -0,0 +1,9 @@
#pragma once
#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"

View File

@ -1,13 +1,7 @@
#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"
#include "storage/model/properties/all.hpp"
template <class Handler>
void accept(Property &property, Handler &h)

View File

@ -1,12 +0,0 @@
## Dynamic Code
```
man nm
cd memgraph/dc
cd example
clang++ -std=c++1y mysql.cpp -o ../tmp/mysql.so -shared -fPIC
clang++ -std=c++1y memsql.cpp -o ../tmp/memsql.so -shared -fPIC
cd ..
clang++ -std=c++1y test.cpp -o test.out -ldl
```

View File

@ -1,22 +0,0 @@
#pragma once
#include <iostream>
using namespace std;
class db
{
public:
// If virtual methods don't have = 0 the compiler
// won't create appropriate _ZTI symbol inside
// the .so lib. That will lead to undefined symbol
// error while the library is loading.
//
// TODO: why?
virtual void name() const = 0;
virtual void type() const = 0;
virtual ~db() {}
};
typedef db* (*produce_t)();
typedef void (*destruct_t)(db*);

View File

@ -1,28 +0,0 @@
#include "db.hpp"
class neo4j : public db
{
public:
void name() const override
{
cout << "Neo4j" << endl;
}
void type() const override
{
cout << "Graph" << endl;
}
~neo4j() {}
};
extern "C" db* produce()
{
return new neo4j();
}
extern "C" void destruct(db* p)
{
delete p;
}

View File

@ -1,28 +0,0 @@
#include "db.hpp"
class postgresql : public db
{
public:
void name() const override
{
cout << "PostgreSQL" << endl;
}
void type() const override
{
cout << "Relational" << endl;
}
~postgresql() {}
};
extern "C" db* produce()
{
return new postgresql();
}
extern "C" void destruct(db* p)
{
delete p;
}

View File

@ -1,2 +0,0 @@
/*
!.gitignore

24
src/mvcc/id.cpp Normal file
View File

@ -0,0 +1,24 @@
#include "mvcc/id.hpp"
Id::Id(uint64_t id) : id(id) {}
bool operator<(const Id& a, const Id& b)
{
return a.id < b.id;
}
bool operator==(const Id& a, const Id& b)
{
return a.id == b.id;
}
std::ostream& operator<<(std::ostream& stream, const Id& id)
{
return stream << id.id;
}
Id::operator uint64_t() const
{
return id;
}

View File

@ -1,36 +0,0 @@
#pragma once
#include <ostream>
#include <stdint.h>
#include "utils/total_ordering.hpp"
class Id : public TotalOrdering<Id>
{
public:
Id() = default;
Id(uint64_t id) : id(id) {}
friend bool operator<(const Id& a, const Id& b)
{
return a.id < b.id;
}
friend bool operator==(const Id& a, const Id& b)
{
return a.id == b.id;
}
friend std::ostream& operator<<(std::ostream& stream, const Id& id)
{
return stream << id.id;
}
operator uint64_t() const
{
return id;
}
private:
uint64_t id {0};
};

View File

@ -1,5 +1,6 @@
#pragma once
#include <iostream>
#include <string>
#include <tuple>
#include <unordered_map>
@ -13,7 +14,6 @@
#include "utils/string/transform.hpp"
#include "utils/variadic/variadic.hpp"
#include <iostream>
template <class T, class V>
void store_query_param(code_args_t &arguments, V &&v)

View File

@ -0,0 +1,13 @@
#include "storage/label_store.hpp"
const Label& LabelStore::find_or_create(const std::string& name)
{
auto accessor = labels.access();
return accessor.insert(Label(name)).first;
}
bool LabelStore::contains(const std::string& name) // const
{
auto accessor = labels.access();
return accessor.find(Label(name)) != accessor.end();
}

View File

@ -1,29 +0,0 @@
#pragma once
#include <stdexcept>
#include "model/label.hpp"
#include "data_structures/concurrent/concurrent_set.hpp"
class LabelStore
{
public:
const Label& find_or_create(const std::string& name)
{
auto accessor = labels.access();
return accessor.insert(Label(name)).first;
}
bool contains(const std::string& name) // const
{
auto accessor = labels.access();
return accessor.find(Label(name)) != accessor.end();
}
// TODO: implement find method
// return { Label, is_found }
private:
ConcurrentSet<Label> labels;
};

View File

@ -0,0 +1,24 @@
#include "storage/model/label.hpp"
Label::Label(const std::string& name) : name(name) {}
Label::Label(std::string&& name) : name(std::move(name)) {}
bool operator<(const Label& lhs, const Label& rhs)
{
return lhs.name < rhs.name;
}
bool operator==(const Label& lhs, const Label& rhs)
{
return lhs.name == rhs.name;
}
std::ostream& operator<<(std::ostream& stream, const Label& label)
{
return stream << label.name;
}
Label::operator const std::string&() const
{
return name;
}

View File

@ -1,42 +0,0 @@
#pragma once
#include <stdint.h>
#include <ostream>
#include "utils/total_ordering.hpp"
#include "utils/reference_wrapper.hpp"
class Label : public TotalOrdering<Label>
{
public:
Label(const std::string& name) : name(name) {}
Label(std::string&& name) : name(std::move(name)) {}
Label(const Label&) = default;
Label(Label&&) = default;
friend bool operator<(const Label& lhs, const Label& rhs)
{
return lhs.name < rhs.name;
}
friend bool operator==(const Label& lhs, const Label& rhs)
{
return lhs.name == rhs.name;
}
friend std::ostream& operator<<(std::ostream& stream, const Label& label)
{
return stream << label.name;
}
operator const std::string&() const
{
return name;
}
private:
std::string name;
};
using label_ref_t = ReferenceWrapper<const Label>;

View File

@ -0,0 +1,43 @@
#include "storage/model/label_collection.hpp"
auto LabelCollection::begin() { return _labels.begin(); }
auto LabelCollection::begin() const { return _labels.begin(); }
auto LabelCollection::cbegin() const { return _labels.begin(); }
auto LabelCollection::end() { return _labels.end(); }
auto LabelCollection::end() const { return _labels.end(); }
auto LabelCollection::cend() const { return _labels.end(); }
bool LabelCollection::add(const Label& label)
{
return _labels.insert(label_ref_t(label)).second;
}
bool LabelCollection::has(const Label& label) const
{
return _labels.count(label);
}
size_t LabelCollection::count() const {
return _labels.size();
}
bool LabelCollection::remove(const Label& label)
{
auto it = _labels.find(label);
if(it == _labels.end())
return false;
return _labels.erase(it), true;
}
void LabelCollection::clear()
{
_labels.clear();
}
const std::set<label_ref_t>& LabelCollection::operator()() const
{
return _labels;
}

View File

@ -1,54 +0,0 @@
#pragma once
#include <set>
#include "label.hpp"
class LabelCollection
{
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(const Label& label)
{
return _labels.insert(label_ref_t(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();
}
const std::set<label_ref_t>& operator()() const
{
return _labels;
}
private:
std::set<label_ref_t> _labels;
};

View File

@ -1,6 +1,5 @@
#pragma once
#include "storage/model/properties/all.hpp"
#include "storage/model/properties/properties.hpp"
#include "storage/model/properties/handler.hpp"

View File

@ -27,7 +27,7 @@ public:
~Pool()
{
alive.store(false, std::memory_order_release);
alive.store(false, std::memory_order_seq_cst);
cond.notify_all();
for(auto& thread : threads)

View File

@ -2,14 +2,14 @@
#include <iostream>
#include <thread>
#include "data_structures/skiplist/skiplist.hpp"
#include "data_structures/concurrent/concurrent_map.hpp"
#include "data_structures/static_array.hpp"
#include "utils/assert.hpp"
#include "utils/sysinfo/memory.hpp"
using std::cout;
using std::endl;
using skiplist_t = SkipList<int, int>;
using skiplist_t = ConcurrentMap<int, int>;
using namespace std::chrono_literals;
#define THREADS_NO 1
@ -77,7 +77,7 @@ int main()
permanent_assert(iterator_counter == 0, "deleted elements");
}
std::this_thread::sleep_for(100s);
std::this_thread::sleep_for(1s);
// TODO: test GC and memory

View File

@ -1,12 +1,36 @@
// TODO: include this into CMakeLists
// compile the shared library
// clang++ -std=c++1y mysql.cpp -o ../tmp/mysql.so -shared -fPIC
// clang++ -std=c++1y memsql.cpp -o ../tmp/memsql.so -shared -fPIC
// clang++ -std=c++1y dynamic_lib.cpp -o test.out -ldl
#include <iostream>
#include <fstream>
#include <vector>
#include <iterator>
#include <cstdlib>
#include "example/db.hpp"
#include "dynamic_lib.hpp"
#include "dc/dynamic_lib.hpp"
#include "utils/string/file.hpp"
class db
{
public:
// If virtual methods don't have = 0 the compiler
// won't create appropriate _ZTI symbol inside
// the .so lib. That will lead to undefined symbol
// error while the library is loading.
//
// TODO: why?
virtual void name() const = 0;
virtual void type() const = 0;
virtual ~db() {}
};
typedef db* (*produce_t)();
typedef void (*destruct_t)(db*);
using std::cout;
using std::endl;