From ae4e9a2c8d35686714a991e5a726c24f0e83b8d7 Mon Sep 17 00:00:00 2001 From: Zhang Lei Date: Thu, 10 Oct 2024 17:03:29 +0800 Subject: [PATCH] fix(interactive): Fixing Interactive CI (#4283) 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. --- .gitignore | 1 + .../graph_db/database/graph_db_operations.cc | 35 ++++++++++--------- .../graph_db/database/graph_db_operations.h | 9 ++--- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index ded6583762c7..64d448025de3 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/flex/engines/graph_db/database/graph_db_operations.cc b/flex/engines/graph_db/database/graph_db_operations.cc index 494f8034a1bc..648d007da4d4 100644 --- a/flex/engines/graph_db/database/graph_db_operations.cc +++ b/flex/engines/graph_db/database/graph_db_operations.cc @@ -161,7 +161,8 @@ Result GraphDBOperations::GetVertex( return Result(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(rapidjson_stringify(result)); @@ -199,11 +200,12 @@ Result 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(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(rapidjson_stringify(result)); @@ -605,10 +607,11 @@ Status GraphDBOperations::updateEdge(std::vector&& edge_data, Result GraphDBOperations::getVertex( std::vector&& vertex_data, - const std::vector& property_names, GraphDBSession& session) { + const std::vector& 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) { @@ -616,11 +619,10 @@ Result GraphDBOperations::getVertex( 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(std::move(result)); @@ -632,7 +634,7 @@ Result GraphDBOperations::getVertex( Result GraphDBOperations::getEdge( std::vector&& 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); @@ -650,11 +652,10 @@ Result 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()) { diff --git a/flex/engines/graph_db/database/graph_db_operations.h b/flex/engines/graph_db/database/graph_db_operations.h index bc03efbd1cec..6bd3392a3d8d 100644 --- a/flex/engines/graph_db/database/graph_db_operations.h +++ b/flex/engines/graph_db/database/graph_db_operations.h @@ -108,12 +108,13 @@ class GraphDBOperations { GraphDBSession& session); static Status updateEdge(std::vector&& edge_data, GraphDBSession& session); - static Result getEdge(std::vector&& edge_data, - const std::string& property_name, - GraphDBSession& session); + static Result getEdge( + std::vector&& edge_data, const std::string& property_name, + GraphDBSession& session, rapidjson::Document::AllocatorType& allocator); static Result getVertex( std::vector&& vertex_data, - const std::vector& property_names, GraphDBSession& session); + const std::vector& property_names, GraphDBSession& session, + rapidjson::Document::AllocatorType& allocator); }; } // namespace gs