Skip to content

Commit

Permalink
Add utility iterfaces to vertexmap, and revisit the hebaviour of `emp…
Browse files Browse the repository at this point in the history
…lace()` in HashmapMVCC. (#1446)

Signed-off-by: Tao He <[email protected]>
  • Loading branch information
sighingnow authored Jul 3, 2023
1 parent 21fc39e commit 6570406
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
10 changes: 6 additions & 4 deletions modules/basic/ds/hashmap_mvcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,17 @@ class HashmapMVCC
/**
* @brief Emplace key-value pair into the hashmap.
*
* @param out If the emplace finished without rehash, the `out` will
* be nullptr, otherwise will be the new hashmap after rehash.
*/
template <class... Args>
inline Status emplace(std::shared_ptr<hashmap_t>& out, Args&&... args) {
out = this->shared_from_this();
if (try_emplace(const_cast<MutEntryPointer>(out->entries_),
out->hash_policy_, out->num_buckets_,
std::forward<Args>(args)...)) {
if (try_emplace(const_cast<MutEntryPointer>(entries_), hash_policy_,
num_buckets_, std::forward<Args>(args)...)) {
out = nullptr;
return Status::OK();
}
out = this->shared_from_this();
size_t new_num_buckets = compute_next_num_buckets(out->num_buckets_);
while (true) {
DVLOG(100) << "trigger rehash when emplace: " << new_num_buckets;
Expand Down
2 changes: 2 additions & 0 deletions modules/graph/fragment/arrow_fragment.vineyard-mod
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ class [[vineyard]] ArrowFragment

bool compact_edges() const override { return compact_edges_; }

bool use_perfect_hash() const override { return vm_ptr_->use_perfect_hash(); }

bool directed() const override { return directed_; }

const PropertyGraphSchema& schema() const override { return schema_; }
Expand Down
2 changes: 2 additions & 0 deletions modules/graph/fragment/arrow_fragment_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ class ArrowFragmentBase : public vineyard::Object {

virtual bool compact_edges() const = 0;

virtual bool use_perfect_hash() const = 0;

virtual const PropertyGraphSchema& schema() const = 0;

virtual bool directed() const = 0;
Expand Down
2 changes: 2 additions & 0 deletions modules/graph/vertex_map/arrow_local_vertex_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class ArrowLocalVertexMap

fid_t fnum() { return fnum_; }

bool use_perfect_hash() const { return false; }

size_t GetTotalNodesNum() const;

size_t GetTotalNodesNum(label_id_t label) const;
Expand Down
2 changes: 2 additions & 0 deletions modules/graph/vertex_map/arrow_vertex_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class ArrowVertexMap

fid_t fnum() const { return fnum_; }

bool use_perfect_hash() const { return use_perfect_hash_; }

size_t GetTotalNodesNum() const;

size_t GetTotalNodesNum(label_id_t label) const;
Expand Down
9 changes: 9 additions & 0 deletions test/hashmap_mvcc_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ void testHashmapMVCC(Client& client) {
for (int i = 1; i <= n; ++i) {
std::shared_ptr<hashmap_t> hmap;
VINEYARD_CHECK_OK(hashmaps[i - 1]->emplace(hmap, i, i * 100.0));
if (hmap == nullptr) {
hmap = hashmaps[i - 1];
}
hashmaps.emplace_back(hmap);
}

Expand Down Expand Up @@ -71,6 +74,9 @@ void testHashmapMVCCLarge(Client& client) {
for (int i = 1; i <= n; ++i) {
std::shared_ptr<hashmap_t> hmap;
VINEYARD_CHECK_OK(hashmaps[i - 1]->emplace(hmap, i, i * 100.0));
if (hmap == nullptr) {
hmap = hashmaps[i - 1];
}
hashmaps.emplace_back(hmap);
}

Expand All @@ -97,6 +103,9 @@ void testHashmapMVCCView(Client& client) {
for (int i = 1; i <= n; ++i) {
std::shared_ptr<hashmap_t> hmap;
VINEYARD_CHECK_OK(hashmaps[i - 1]->emplace(hmap, i, i * 100.0));
if (hmap == nullptr) {
hmap = hashmaps[i - 1];
}
hashmaps.emplace_back(hmap);
}

Expand Down

0 comments on commit 6570406

Please sign in to comment.