Apply suggestions from code review

Co-authored-by: Andi <andi8647@gmail.com>
This commit is contained in:
gvolfing
2023-10-17 08:01:05 +02:00
committed by GitHub
parent 89585fad1c
commit 422f9199bd
2 changed files with 24 additions and 29 deletions

View File

@@ -550,11 +550,9 @@ VerticesIterable DiskStorage::DiskAccessor::Vertices(LabelId label, View view) {
utils::SkipList<memgraph::storage::Vertex> *indexed_vertices{nullptr};
std::list<storage::Delta> *index_deltas{nullptr};
auto merge_with_main_cache = [&](auto &index, auto &index_delta_storage) -> std::unordered_set<Gid> {
auto merge_with_main_cache = [&](auto &index, auto &index_delta_storage) -> std::unordered_set<Gid> {
indexed_vertices = &index[label];
index_delta_storage.emplace_back();
index_deltas = &index_delta_storage.back();
index_deltas = &index_delta_storage.emplace_back();
return MergeVerticesFromMainCacheWithLabelIndexCache(label, view, *index_deltas, *indexed_vertices);
};
@@ -566,27 +564,23 @@ VerticesIterable DiskStorage::DiskAccessor::Vertices(LabelId label, View view) {
if (transaction_.command_id > cache_ci) {
cache_ci = transaction_.command_id;
} else {
if (cache.contains(label)) {
if (view == View::OLD) {
// TODO
// we do not need this merge if we can make sure that
// the removing and re-adding the same label to a given
// vertex within one transaction is not permitted.
merge_with_main_cache(cache, index_delta_storage);
return VerticesIterable(AllVerticesIterable(cache[label].access(), storage_, &transaction_, view));
}
cache[label] = utils::SkipList<Vertex>();
merge_with_main_cache(cache, index_delta_storage);
return VerticesIterable(AllVerticesIterable(cache[label].access(), storage_, &transaction_, view));
}
cache[label] = utils::SkipList<Vertex>();
index_delta_storage.emplace_back();
index_deltas = &index_delta_storage.back();
LoadVerticesFromDiskLabelIndex({}, label, *index_deltas, transaction_.vertices_);
merge_with_main_cache(cache, index_delta_storage);
return VerticesIterable(AllVerticesIterable(indexed_vertices->access(), storage_, &transaction_, view));
}
if (cache.contains(label)) {
if (view == View::NEW) {
cache[label] = utils::SkipList<Vertex>();
}
// TODO
// we do not need this merge if we can make sure that
// the removing and re-adding the same label to a given
// vertex within one transaction is not permitted.
merge_with_main_cache(cache, index_delta_storage);
return VerticesIterable(AllVerticesIterable(cache[label].access(), storage_, &transaction_, view));
}
cache[label] = utils::SkipList<Vertex>();
index_deltas = &index_delta_storage.emplace_back();
LoadVerticesFromDiskLabelIndex({}, label, *index_deltas, transaction_.vertices_);
merge_with_main_cache(cache, index_delta_storage);
return VerticesIterable(AllVerticesIterable(indexed_vertices->access(), storage_, &transaction_, view));
}

View File

@@ -97,11 +97,12 @@ class DiskStorage final : public Storage {
template <typename TIndex, typename TIndexCacheKey, typename TMergeFunc>
void SyncDeletedVertices(TIndex &index, TIndexCacheKey &cache_key,
std::vector<std::list<Delta>> &index_delta_storage, View view, TMergeFunc &merge_func) {
if (!transaction_.vertices_to_delete_.empty()) {
index[cache_key] = utils::SkipList<Vertex>();
if (view == View::OLD) {
merge_func(index, index_delta_storage);
}
if (transaction_.vertices_to_delete_.empty()) {
continue;
}
index[cache_key] = utils::SkipList<Vertex>();
if (view == View::OLD) {
merge_func(index, index_delta_storage);
}
}