Skip to content

Commit

Permalink
fix(interactive): Fixing Interactive CI (#4283)
Browse files Browse the repository at this point in the history
Resolve the CI failures from PR #4249, as seen in the logs from
https://github.com/alibaba/GraphScope/actions/runs/11269316654/job/31337690010
and
https://github.com/alibaba/GraphScope/actions/runs/11269316658/job/31337690238.
The issue appears to stem from improper use of rapidjson without a
careful allocator.
  • Loading branch information
zhanglei1949 authored Oct 10, 2024
1 parent d163d5b commit ae4e9a2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ flex/interactive/sdk/java/.openapi-generator/*
flex/interactive/sdk/java/src/main/AndroidManifest.xml
flex/interactive/sdk/java/.openapi-generate/
flex/interactive/sdk/java/settings.gradle
flex/interactive/sdk/java/reference/**
flex/interactive/sdk/java/src/main/java/com/alibaba/graphscope/interactive/models/
flex/interactive/sdk/java/src/main/java/com/alibaba/graphscope/interactive/api/
flex/interactive/sdk/java/src/main/java/com/alibaba/graphscope/interactive/auth/
Expand Down
35 changes: 18 additions & 17 deletions flex/engines/graph_db/database/graph_db_operations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ Result<std::string> GraphDBOperations::GetVertex(
return Result<std::string>(check_result);
}
vertex_data.push_back(vertex);
auto get_result = getVertex(std::move(vertex_data), property_names, session);
auto get_result = getVertex(std::move(vertex_data), property_names, session,
result.GetAllocator());
if (get_result.ok()) {
result.AddMember("values", get_result.value(), result.GetAllocator());
return Result<std::string>(rapidjson_stringify(result));
Expand Down Expand Up @@ -199,11 +200,12 @@ Result<std::string> GraphDBOperations::GetEdge(
result.AddMember("dst_primary_key_value", dst_pk_value,
result.GetAllocator());
if (property_name.empty()) {
result.AddMember("properties", rapidjson::Value(rapidjson::kArrayType),
result.GetAllocator());
rapidjson::Value properties(rapidjson::kObjectType);
result.AddMember("properties", properties, result.GetAllocator());
return Result<std::string>(rapidjson_stringify(result));
}
auto get_result = getEdge(std::move(edge_data), property_name, session);
auto get_result = getEdge(std::move(edge_data), property_name, session,
result.GetAllocator());
if (get_result.ok()) {
result.AddMember("properties", get_result.value(), result.GetAllocator());
return Result<std::string>(rapidjson_stringify(result));
Expand Down Expand Up @@ -605,22 +607,22 @@ Status GraphDBOperations::updateEdge(std::vector<EdgeData>&& edge_data,

Result<rapidjson::Value> GraphDBOperations::getVertex(
std::vector<VertexData>&& vertex_data,
const std::vector<std::string>& property_names, GraphDBSession& session) {
const std::vector<std::string>& property_names, GraphDBSession& session,
rapidjson::Document::AllocatorType& allocator) {
try {
auto& vertex = vertex_data[0];
rapidjson::Document result(rapidjson::kArrayType);
rapidjson::Document result(rapidjson::kArrayType, &allocator);
auto txn = session.GetReadTransaction();
auto vertex_db = txn.FindVertex(vertex.label_id, vertex.pk_value);
if (vertex_db.IsValid() == false) {
txn.Abort();
throw std::runtime_error("Vertex not found");
}
for (int i = 0; i < vertex_db.FieldNum(); i++) {
rapidjson::Value values(rapidjson::kObjectType);
values.AddMember("name", property_names[i], result.GetAllocator());
values.AddMember("value", vertex_db.GetField(i).to_string(),
result.GetAllocator());
result.PushBack(values, result.GetAllocator());
rapidjson::Document values(rapidjson::kObjectType, &allocator);
values.AddMember("name", property_names[i], allocator);
values.AddMember("value", vertex_db.GetField(i).to_string(), allocator);
result.PushBack(values, allocator);
}
txn.Commit();
return Result<rapidjson::Value>(std::move(result));
Expand All @@ -632,7 +634,7 @@ Result<rapidjson::Value> GraphDBOperations::getVertex(

Result<rapidjson::Value> GraphDBOperations::getEdge(
std::vector<EdgeData>&& edge_data, const std::string& property_name,
GraphDBSession& session) {
GraphDBSession& session, rapidjson::Document::AllocatorType& allocator) {
try {
const auto& edge = edge_data[0];
rapidjson::Document result(rapidjson::kArrayType);
Expand All @@ -650,11 +652,10 @@ Result<rapidjson::Value> GraphDBOperations::getEdge(
edgeIt.IsValid(); edgeIt.Next()) {
if (edgeIt.GetNeighbor() != dst_vid)
continue;
rapidjson::Value push_json(rapidjson::kObjectType);
push_json.AddMember("name", property_name, result.GetAllocator());
push_json.AddMember("value", edgeIt.GetData().to_string(),
result.GetAllocator());
result.PushBack(push_json, result.GetAllocator());
rapidjson::Document push_json(rapidjson::kObjectType, &allocator);
push_json.AddMember("name", property_name, allocator);
push_json.AddMember("value", edgeIt.GetData().to_string(), allocator);
result.PushBack(push_json, allocator);
break;
}
if (result.Empty()) {
Expand Down
9 changes: 5 additions & 4 deletions flex/engines/graph_db/database/graph_db_operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,13 @@ class GraphDBOperations {
GraphDBSession& session);
static Status updateEdge(std::vector<EdgeData>&& edge_data,
GraphDBSession& session);
static Result<rapidjson::Value> getEdge(std::vector<EdgeData>&& edge_data,
const std::string& property_name,
GraphDBSession& session);
static Result<rapidjson::Value> getEdge(
std::vector<EdgeData>&& edge_data, const std::string& property_name,
GraphDBSession& session, rapidjson::Document::AllocatorType& allocator);
static Result<rapidjson::Value> getVertex(
std::vector<VertexData>&& vertex_data,
const std::vector<std::string>& property_names, GraphDBSession& session);
const std::vector<std::string>& property_names, GraphDBSession& session,
rapidjson::Document::AllocatorType& allocator);
};

} // namespace gs
Expand Down

0 comments on commit ae4e9a2

Please sign in to comment.