All possible request changes from D9#146 are done

This commit is contained in:
Marko Budiselic 2016-11-30 11:05:48 +01:00
parent 5eb90f9e52
commit cfd36be2e0
9 changed files with 57 additions and 29 deletions

View File

@ -19,15 +19,19 @@ class DbTransaction : public Loggable
friend DbAccessor;
public:
DbTransaction(Db &db);
DbTransaction(Db &db, tx::Transaction &trans)
: Loggable("DbTransaction"), db(db), trans(trans)
{
}
DbTransaction() = delete;
~DbTransaction() = default;
DbTransaction(const DbTransaction& other) = delete;
DbTransaction(DbTransaction&& other) = default;
DbTransaction &operator=(const DbTransaction &) = delete;
DbTransaction &operator=(DbTransaction &&) = default;
DbTransaction(Db &db);
DbTransaction(Db &db, tx::Transaction &trans)
: Loggable("DbTransaction"), db(db), trans(trans) {}
// Global transactional algorithms,operations and general methods meant for
// internal use should be here or should be routed through this object.
// This should provide cleaner hierarchy of operations on database.

View File

@ -8,6 +8,14 @@ class LabelsWriter
public:
LabelsWriter(Buffer &buffer) : buffer_(buffer) {}
~LabelsWriter() = default;
LabelsWriter(const LabelsWriter &) = delete;
LabelsWriter(LabelsWriter &&) = delete;
LabelsWriter &operator=(const LabelsWriter &) = delete;
LabelsWriter &operator=(LabelsWriter &&) = delete;
void handle(const Label& label);
private:

View File

@ -56,10 +56,9 @@ public:
template <typename Stream>
void stream_repr(Stream& stream) const
{
if (this->record != nullptr)
this->record->stream_repr(stream);
else
std::cout << "TRACE: record is nullptr" << std::endl;
if (!this->record)
return;
this->record->stream_repr(stream);
}
};

View File

@ -102,7 +102,7 @@ public:
// Relases all memory.
void free()
{
while (allocated_blocks.size() > 0)
while (allocated_blocks.size())
{
blocks.release(allocated_blocks.back());
allocated_blocks.pop_back();

View File

@ -8,6 +8,25 @@ namespace utils
class StringBuffer
{
public:
StringBuffer() = default;
~StringBuffer() = default;
StringBuffer(const StringBuffer &) = delete;
StringBuffer(StringBuffer &&) = default;
StringBuffer &operator=(const StringBuffer &) = delete;
StringBuffer &operator=(StringBuffer &&) = default;
StringBuffer(std::string::size_type count)
{
resize(count);
}
void resize(std::string::size_type count)
{
data.resize(count);
}
StringBuffer &operator<<(const std::string &str)
{
data += str;

View File

@ -8,12 +8,6 @@
#include "storage/label/label.hpp"
#include "storage/vertex.hpp"
#define TRY(x) \
if (!x) \
{ \
return false; \
}
DbTransaction::DbTransaction(Db &db)
: Loggable("DbTransaction"), db(db), trans(db.tx_engine.begin())
{
@ -75,11 +69,14 @@ bool DbTransaction::update_indexes()
// TODO: This could be done in batch
// NOTE: This assumes that type index is created with the database.
TRY(edge.record->data.edge_type->index().insert(EdgeTypeIndexRecord(
std::nullptr_t(), edge.record, edge.vlist)));
if (!edge.record->data.edge_type->index().insert(
EdgeTypeIndexRecord(std::nullptr_t(), edge.record,
edge.vlist)))
return false;
TRY(db.indexes().update_property_indexes<TypeGroupEdge>(edge,
trans));
if (!db.indexes().update_property_indexes<TypeGroupEdge>(edge,
trans))
return false;
}
else
{
@ -90,12 +87,14 @@ bool DbTransaction::update_indexes()
// TODO: This could be done in batch
// NOTE: This assumes that label index is created with the
// database.
TRY(label.get().index().insert(LabelIndexRecord(
std::nullptr_t(), vertex.record, vertex.vlist)));
if (!label.get().index().insert(LabelIndexRecord(
std::nullptr_t(), vertex.record, vertex.vlist)))
return false;
}
TRY(db.indexes().update_property_indexes<TypeGroupVertex>(vertex,
trans));
if (!db.indexes().update_property_indexes<TypeGroupVertex>(vertex,
trans))
return false;
}
index_updates.pop_back();

View File

@ -35,7 +35,7 @@ bool IndexRecord<TG, K>::is_valid(tx::Transaction &t) const
// this index and then tries to access to the same element again through
// the same index
auto newest_record = vlist->find(t);
if (newest_record == nullptr)
if (!newest_record)
return false;
return (record == newest_record) || (newest_record->tx.cre() == t.id);
}

View File

@ -299,13 +299,13 @@ auto load_basic_functions(Db &db)
.type(type);
if (it_type.count() > it_vertex.count()) {
// Going through vertices wiil probably be faster
// TODO: Going through vertices wiil probably be faster
it_vertex.to().for_all([&](auto m) {
// PRINT m
});
} else {
// Going through edges will probably be faster
// TODO: Going through edges will probably be faster
it_type.to().for_all([&](auto m) {
// PRINT m
});

View File

@ -24,7 +24,6 @@ int main(int argc, char *argv[])
logging::init_sync();
logging::log->pipe(std::make_unique<Stdout>());
auto log = logging::log->logger("test");
log.info("bla");
// init db, functions and stripper
Db db;