Skip to content

Commit

Permalink
Fix bug about deleting edge label (#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
ljcui committed May 15, 2024
1 parent 22bcec0 commit 7ad4838
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/core/graph_data_pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,15 @@ class KeyPacker {
return v;
}

static EdgeUid GetEuidFromPropertyTableKey(const Value& key) {
static EdgeUid GetEuidFromPropertyTableKey(const Value& key, uint16_t lid) {
auto no_tid = ::lgraph::_detail::VID_SIZE*2 + ::lgraph::_detail::EID_SIZE;
auto with_tid = ::lgraph::_detail::VID_SIZE*2 +
::lgraph::_detail::EID_SIZE +
::lgraph::_detail::TID_SIZE;
FMA_ASSERT(key.Size() == no_tid || key.Size() == with_tid);
bool compress_tid = (key.Size() == no_tid);
EdgeUid ret;
ret.lid = lid;
uint8_t offset = 0;
ret.src = GetNByteIntId<::lgraph::_detail::VID_SIZE>(key.Data());
offset = ::lgraph::_detail::VID_SIZE;
Expand Down
7 changes: 4 additions & 3 deletions src/core/lightning_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ bool LightningGraph::DelLabel(const std::string& label, bool is_vertex, size_t*
bool r = graph_->DeleteVertex(txn.GetTxn(), vid, on_edge_deleted);
FMA_DBG_ASSERT(r);
} else {
auto euid = graph::KeyPacker::GetEuidFromPropertyTableKey(kv_iter->GetKey());
auto euid = graph::KeyPacker::GetEuidFromPropertyTableKey(
kv_iter->GetKey(), schema->GetLabelId());
bool r = graph_->DeleteEdge(txn.GetTxn(), euid);
FMA_DBG_ASSERT(r);
}
Expand Down Expand Up @@ -1994,8 +1995,8 @@ bool LightningGraph::BlockingAddIndex(const std::string& label, const std::strin
EdgeIndex* index = extractor->GetEdgeIndex();
auto kv_iter = schema->GetPropertyTable().GetIterator(txn.GetTxn());
for (kv_iter->GotoFirstKey(); kv_iter->IsValid(); kv_iter->Next()) {
auto euid = graph::KeyPacker::GetEuidFromPropertyTableKey(kv_iter->GetKey());
euid.lid = schema->GetLabelId();
auto euid = graph::KeyPacker::GetEuidFromPropertyTableKey(
kv_iter->GetKey(), schema->GetLabelId());
auto prop = kv_iter->GetValue();
if (extractor->GetIsNull(prop)) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/core/lmdb_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void LMDBKvStore::Open(bool create_if_not_exist) {
}
THROW_ON_ERR(mdb_env_create(&env_));
THROW_ON_ERR(mdb_env_set_mapsize(env_, db_size_));
THROW_ON_ERR(mdb_env_set_maxdbs(env_, 5000)); // HENG: former value is 255
THROW_ON_ERR(mdb_env_set_maxdbs(env_, 10000)); // HENG: former value is 255
THROW_ON_ERR(mdb_env_set_maxreaders(env_, 1200));
#if LGRAPH_SHARE_DIR
unsigned int flags = MDB_NOMEMINIT | MDB_NORDAHEAD | MDB_NOTLS | MDB_NOSYNC;
Expand Down
67 changes: 67 additions & 0 deletions test/test_del_detached_label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,73 @@ using namespace lgraph_api;

class TestDelDetachedLabel : public TuGraphTest{};

TEST_F(TestDelDetachedLabel, delete_edge) {
std::string path = "./testdb";
auto ADMIN = lgraph::_detail::DEFAULT_ADMIN_NAME;
auto ADMIN_PASS = lgraph::_detail::DEFAULT_ADMIN_PASS;
lgraph::AutoCleanDir cleaner(path);
Galaxy galaxy(path);
galaxy.SetCurrentUser(ADMIN, ADMIN_PASS);
GraphDB db = galaxy.OpenGraph("default");
VertexOptions vo;
vo.primary_field = "id";
vo.detach_property = true;
UT_EXPECT_TRUE(db.AddVertexLabel("node1",
std::vector<FieldSpec>({{"id", FieldType::INT32, false},
{"int64", FieldType::INT64, true}}),
vo));
UT_EXPECT_TRUE(db.AddVertexLabel("node2",
std::vector<FieldSpec>({{"id", FieldType::INT32, false},
{"int64", FieldType::INT64, true}}),
vo));
EdgeOptions eo;
eo.detach_property = true;
UT_EXPECT_TRUE(db.AddEdgeLabel("edge1",
std::vector<FieldSpec>({{"id", FieldType::INT32, false}}),
eo));
UT_EXPECT_TRUE(db.AddEdgeLabel("edge2",
std::vector<FieldSpec>({}),
eo));
UT_EXPECT_TRUE(db.AddEdgeLabel("edge3",
std::vector<FieldSpec>({{"id", FieldType::INT32, false}}),
eo));
std::vector<std::string> vp({"id", "int64"});
std::vector<std::string> ep({"id"});

int count = 100;
std::vector<int64_t> node1_vids, node2_vids;
auto txn = db.CreateWriteTxn();
UT_EXPECT_EQ(txn.GetEdgeLabelId("edge1"), 0);
UT_EXPECT_EQ(txn.GetEdgeLabelId("edge2"), 1);
UT_EXPECT_EQ(txn.GetEdgeLabelId("edge3"), 2);
for (int32_t i = 0; i < count; i++) {
auto vid1 = txn.AddVertex(
std::string("node1"), vp,
{FieldData::Int32(i), FieldData::Int64(i)});
node1_vids.push_back(vid1);
auto vid2 = txn.AddVertex(
std::string("node2"), vp,
{FieldData::Int32(i), FieldData::Int64(i)});
node2_vids.push_back(vid2);
}
for (int32_t i = 0; i < count; i++) {
txn.AddEdge(node1_vids[i], node2_vids[i], std::string("edge1"),
ep, {FieldData::Int32(i)});
txn.AddEdge(node1_vids[i], node2_vids[i], std::string("edge2"),
std::vector<std::string>{}, std::vector<FieldData>{});
txn.AddEdge(node1_vids[i], node2_vids[i], std::string("edge3"),
ep, {FieldData::Int32(i)});
}
txn.Commit();
size_t modified = 0;
UT_EXPECT_TRUE(db.DeleteEdgeLabel("edge1", &modified));
UT_EXPECT_EQ(modified, count);
UT_EXPECT_TRUE(db.DeleteEdgeLabel("edge2", &modified));
UT_EXPECT_EQ(modified, count);
UT_EXPECT_TRUE(db.DeleteEdgeLabel("edge3", &modified));
UT_EXPECT_EQ(modified, count);
}

TEST_F(TestDelDetachedLabel, common) {
std::string path = "./testdb";
auto ADMIN = lgraph::_detail::DEFAULT_ADMIN_NAME;
Expand Down

0 comments on commit 7ad4838

Please sign in to comment.