Compare commits

...

3 Commits

Author SHA1 Message Date
Marko Budiselić
37a97dc242 Merge branch 'master' into fix-some-warnings 2022-06-09 07:43:09 +02:00
Marko Budiselić
35e2b609a5 Merge branch 'master' into fix-some-warnings 2022-02-04 18:42:15 +01:00
Marko Budiselic
bb12920d86 Fix compiler warnings 2022-01-31 08:16:34 +01:00
4 changed files with 41 additions and 35 deletions

View File

@@ -15,11 +15,12 @@
namespace memgraph::storage {
CommitLog::CommitLog() : allocator_(utils::NewDeleteResource()) {}
CommitLog::CommitLog(uint64_t oldest_active) : allocator_(utils::NewDeleteResource()) {
CommitLog::CommitLog(uint64_t oldest_active)
: head_start_(oldest_active / kIdsInBlock * kIdsInBlock),
next_start_(head_start_ + kIdsInBlock),
allocator_(utils::NewDeleteResource()) {
head_ = allocator_.allocate(1);
allocator_.construct(head_);
head_start_ = oldest_active / kIdsInBlock * kIdsInBlock;
next_start_ = head_start_ + kIdsInBlock;
// set all the previous ids
const auto field_idx = (oldest_active % kIdsInBlock) / kIdsInField;

View File

@@ -73,29 +73,30 @@ class PreviousPtr {
uintptr_t type = value & kMask;
if (type == kDelta) {
return Pointer{reinterpret_cast<Delta *>(value & ~kMask)};
} else if (type == kVertex) {
return Pointer{reinterpret_cast<Vertex *>(value & ~kMask)};
} else if (type == kEdge) {
return Pointer{reinterpret_cast<Edge *>(value & ~kMask)};
} else {
LOG_FATAL("Invalid pointer type!");
}
if (type == kVertex) {
return Pointer{reinterpret_cast<Vertex *>(value & ~kMask)};
}
if (type == kEdge) {
return Pointer{reinterpret_cast<Edge *>(value & ~kMask)};
}
LOG_FATAL("Invalid pointer type!");
}
void Set(Delta *delta) {
uintptr_t value = reinterpret_cast<uintptr_t>(delta);
auto value = reinterpret_cast<uintptr_t>(delta);
MG_ASSERT((value & kMask) == 0, "Invalid pointer!");
storage_.store(value | kDelta, std::memory_order_release);
}
void Set(Vertex *vertex) {
uintptr_t value = reinterpret_cast<uintptr_t>(vertex);
auto value = reinterpret_cast<uintptr_t>(vertex);
MG_ASSERT((value & kMask) == 0, "Invalid pointer!");
storage_.store(value | kVertex, std::memory_order_release);
}
void Set(Edge *edge) {
uintptr_t value = reinterpret_cast<uintptr_t>(edge);
auto value = reinterpret_cast<uintptr_t>(edge);
MG_ASSERT((value & kMask) == 0, "Invalid pointer!");
storage_.store(value | kEdge, std::memory_order_release);
}
@@ -149,45 +150,45 @@ struct Delta {
struct RemoveInEdgeTag {};
struct RemoveOutEdgeTag {};
Delta(DeleteObjectTag, std::atomic<uint64_t> *timestamp, uint64_t command_id)
Delta(DeleteObjectTag /*unused*/, std::atomic<uint64_t> *timestamp, uint64_t command_id)
: action(Action::DELETE_OBJECT), timestamp(timestamp), command_id(command_id) {}
Delta(RecreateObjectTag, std::atomic<uint64_t> *timestamp, uint64_t command_id)
Delta(RecreateObjectTag /*unused*/, std::atomic<uint64_t> *timestamp, uint64_t command_id)
: action(Action::RECREATE_OBJECT), timestamp(timestamp), command_id(command_id) {}
Delta(AddLabelTag, LabelId label, std::atomic<uint64_t> *timestamp, uint64_t command_id)
Delta(AddLabelTag /*unused*/, LabelId label, std::atomic<uint64_t> *timestamp, uint64_t command_id)
: action(Action::ADD_LABEL), timestamp(timestamp), command_id(command_id), label(label) {}
Delta(RemoveLabelTag, LabelId label, std::atomic<uint64_t> *timestamp, uint64_t command_id)
Delta(RemoveLabelTag /*unused*/, LabelId label, std::atomic<uint64_t> *timestamp, uint64_t command_id)
: action(Action::REMOVE_LABEL), timestamp(timestamp), command_id(command_id), label(label) {}
Delta(SetPropertyTag, PropertyId key, const PropertyValue &value, std::atomic<uint64_t> *timestamp,
Delta(SetPropertyTag /*unused*/, PropertyId key, const PropertyValue &value, std::atomic<uint64_t> *timestamp,
uint64_t command_id)
: action(Action::SET_PROPERTY), timestamp(timestamp), command_id(command_id), property({key, value}) {}
Delta(AddInEdgeTag, EdgeTypeId edge_type, Vertex *vertex, EdgeRef edge, std::atomic<uint64_t> *timestamp,
Delta(AddInEdgeTag /*unused*/, EdgeTypeId edge_type, Vertex *vertex, EdgeRef edge, std::atomic<uint64_t> *timestamp,
uint64_t command_id)
: action(Action::ADD_IN_EDGE),
timestamp(timestamp),
command_id(command_id),
vertex_edge({edge_type, vertex, edge}) {}
Delta(AddOutEdgeTag, EdgeTypeId edge_type, Vertex *vertex, EdgeRef edge, std::atomic<uint64_t> *timestamp,
Delta(AddOutEdgeTag /*unused*/, EdgeTypeId edge_type, Vertex *vertex, EdgeRef edge, std::atomic<uint64_t> *timestamp,
uint64_t command_id)
: action(Action::ADD_OUT_EDGE),
timestamp(timestamp),
command_id(command_id),
vertex_edge({edge_type, vertex, edge}) {}
Delta(RemoveInEdgeTag, EdgeTypeId edge_type, Vertex *vertex, EdgeRef edge, std::atomic<uint64_t> *timestamp,
uint64_t command_id)
Delta(RemoveInEdgeTag /*unused*/, EdgeTypeId edge_type, Vertex *vertex, EdgeRef edge,
std::atomic<uint64_t> *timestamp, uint64_t command_id)
: action(Action::REMOVE_IN_EDGE),
timestamp(timestamp),
command_id(command_id),
vertex_edge({edge_type, vertex, edge}) {}
Delta(RemoveOutEdgeTag, EdgeTypeId edge_type, Vertex *vertex, EdgeRef edge, std::atomic<uint64_t> *timestamp,
uint64_t command_id)
Delta(RemoveOutEdgeTag /*unused*/, EdgeTypeId edge_type, Vertex *vertex, EdgeRef edge,
std::atomic<uint64_t> *timestamp, uint64_t command_id)
: action(Action::REMOVE_OUT_EDGE),
timestamp(timestamp),
command_id(command_id),

View File

@@ -456,12 +456,12 @@ VertexAccessor Storage::Accessor::CreateVertex() {
OOMExceptionEnabler oom_exception;
auto gid = storage_->vertex_id_.fetch_add(1, std::memory_order_acq_rel);
auto acc = storage_->vertices_.access();
auto delta = CreateDeleteObjectDelta(&transaction_);
auto *delta = CreateDeleteObjectDelta(&transaction_);
auto [it, inserted] = acc.insert(Vertex{storage::Gid::FromUint(gid), delta});
MG_ASSERT(inserted, "The vertex must be inserted here!");
MG_ASSERT(it != acc.end(), "Invalid Vertex accessor!");
delta->prev.Set(&*it);
return VertexAccessor(&*it, &transaction_, &storage_->indices_, &storage_->constraints_, config_);
return {&*it, &transaction_, &storage_->indices_, &storage_->constraints_, config_};
}
VertexAccessor Storage::Accessor::CreateVertex(storage::Gid gid) {
@@ -475,12 +475,12 @@ VertexAccessor Storage::Accessor::CreateVertex(storage::Gid gid) {
storage_->vertex_id_.store(std::max(storage_->vertex_id_.load(std::memory_order_acquire), gid.AsUint() + 1),
std::memory_order_release);
auto acc = storage_->vertices_.access();
auto delta = CreateDeleteObjectDelta(&transaction_);
auto *delta = CreateDeleteObjectDelta(&transaction_);
auto [it, inserted] = acc.insert(Vertex{gid, delta});
MG_ASSERT(inserted, "The vertex must be inserted here!");
MG_ASSERT(it != acc.end(), "Invalid Vertex accessor!");
delta->prev.Set(&*it);
return VertexAccessor(&*it, &transaction_, &storage_->indices_, &storage_->constraints_, config_);
return {&*it, &transaction_, &storage_->indices_, &storage_->constraints_, config_};
}
std::optional<VertexAccessor> Storage::Accessor::FindVertex(Gid gid, View view) {
@@ -1343,7 +1343,7 @@ void Storage::CollectGarbage() {
while (true) {
// We don't want to hold the lock on commited transactions for too long,
// because that prevents other transactions from committing.
Transaction *transaction;
Transaction *transaction = nullptr;
{
auto committed_transactions_ptr = committed_transactions_.Lock();
if (committed_transactions_ptr->empty()) {
@@ -1590,7 +1590,7 @@ void Storage::AppendToWal(const Transaction &transaction, uint64_t final_commit_
// delta that should be processed and then appends all discovered deltas.
auto find_and_apply_deltas = [&](const auto *delta, const auto &parent, auto filter) {
while (true) {
auto older = delta->next.load(std::memory_order_acquire);
auto *older = delta->next.load(std::memory_order_acquire);
if (older == nullptr || older->timestamp->load(std::memory_order_acquire) != current_commit_timestamp) break;
delta = older;
}
@@ -1825,10 +1825,10 @@ void Storage::FreeMemory() {
uint64_t Storage::CommitTimestamp(const std::optional<uint64_t> desired_commit_timestamp) {
if (!desired_commit_timestamp) {
return timestamp_++;
} else {
timestamp_ = std::max(timestamp_, *desired_commit_timestamp + 1);
return *desired_commit_timestamp;
}
timestamp_ = std::max(timestamp_, *desired_commit_timestamp + 1);
return *desired_commit_timestamp;
}
bool Storage::SetReplicaRole(io::network::Endpoint endpoint, const replication::ReplicationServerConfig &config) {

View File

@@ -94,8 +94,8 @@ class AllVerticesIterable final {
constraints_(constraints),
config_(config) {}
Iterator begin() { return Iterator(this, vertices_accessor_.begin()); }
Iterator end() { return Iterator(this, vertices_accessor_.end()); }
Iterator begin() { return {this, vertices_accessor_.begin()}; }
Iterator end() { return {this, vertices_accessor_.end()}; }
};
/// Generic access to different kinds of vertex iterations.
@@ -190,6 +190,10 @@ class Storage final {
/// @throw std::bad_alloc
explicit Storage(Config config = Config());
Storage(const Storage &) = delete;
Storage &operator=(const Storage &) = delete;
Storage(Storage &&) = delete;
Storage &operator=(Storage &&other) = delete;
~Storage();
class Accessor final {
@@ -232,7 +236,7 @@ class Storage final {
/// Return approximate number of all vertices in the database.
/// Note that this is always an over-estimate and never an under-estimate.
int64_t ApproximateVertexCount() const { return storage_->vertices_.size(); }
auto ApproximateVertexCount() const { return storage_->vertices_.size(); }
/// Return approximate number of vertices with the given label.
/// Note that this is always an over-estimate and never an under-estimate.