Skip to content

Commit

Permalink
update tugraph version and support arm runtime (#43)
Browse files Browse the repository at this point in the history
* fix arm compile

* add proto source file

* migrate on arm and merge dev (#4)

* init

* per_node_limit

* asc -> desc

* update protoc version for arm

---------

Co-authored-by: hk286513 <hk286513@antgroup.com>

* remove so and add proto back (#5)

* update to 0.2.0-alpha tag

* add proto back

* igore proto java file

---------

Co-authored-by: hk286513 <hk286513@antgroup.com>
  • Loading branch information
qishipengqsp and spasserby authored Nov 26, 2024
1 parent 1bf806c commit 84e69fe
Show file tree
Hide file tree
Showing 13 changed files with 871 additions and 106,908 deletions.
1 change: 1 addition & 0 deletions tugraph/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/main/java/lgraph/
32 changes: 16 additions & 16 deletions tugraph/data/import.conf
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@
{
"label": "transfer",
"type": "EDGE",
"tid": "timestamp",
"tid_order": "desc",
"temporal": "timestamp",
"temporal_order": "DESC",
"properties": [
{
"name": "timestamp",
Expand Down Expand Up @@ -253,8 +253,8 @@
{
"label": "withdraw",
"type": "EDGE",
"tid": "timestamp",
"tid_order": "desc",
"temporal": "timestamp",
"temporal_order": "DESC",
"properties": [
{
"name": "timestamp",
Expand All @@ -269,8 +269,8 @@
{
"label": "repay",
"type": "EDGE",
"tid": "timestamp",
"tid_order": "desc",
"temporal": "timestamp",
"temporal_order": "DESC",
"properties": [
{
"name": "timestamp",
Expand All @@ -285,8 +285,8 @@
{
"label": "deposit",
"type": "EDGE",
"tid": "timestamp",
"tid_order": "desc",
"temporal": "timestamp",
"temporal_order": "DESC",
"properties": [
{
"name": "timestamp",
Expand All @@ -301,8 +301,8 @@
{
"label": "signIn",
"type": "EDGE",
"tid": "timestamp",
"tid_order": "desc",
"temporal": "timestamp",
"temporal_order": "DESC",
"properties": [
{
"name": "timestamp",
Expand All @@ -318,8 +318,8 @@
{
"label": "invest",
"type": "EDGE",
"tid": "timestamp",
"tid_order": "desc",
"temporal": "timestamp",
"temporal_order": "DESC",
"properties": [
{
"name": "timestamp",
Expand All @@ -334,8 +334,8 @@
{
"label": "apply",
"type": "EDGE",
"tid": "timestamp",
"tid_order": "desc",
"temporal": "timestamp",
"temporal_order": "DESC",
"properties": [
{
"name": "timestamp",
Expand All @@ -351,8 +351,8 @@
{
"label": "guarantee",
"type": "EDGE",
"tid": "timestamp",
"tid_order": "desc",
"temporal": "timestamp",
"temporal_order": "DESC",
"properties": [
{
"name": "timestamp",
Expand Down
5 changes: 2 additions & 3 deletions tugraph/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<maven.compiler.plugin>3.6.1</maven.compiler.plugin>
<maven.source.plugin>2.2.1</maven.source.plugin>
<maven.javadoc.plugin>2.9.1</maven.javadoc.plugin>
<protoc.jar.maven.plugin>3.6.0</protoc.jar.maven.plugin>
<protoc.jar.maven.plugin>3.11.4</protoc.jar.maven.plugin>
<jdk.version>1.8</jdk.version>
</properties>

Expand Down Expand Up @@ -208,9 +208,8 @@
<goal>run</goal>
</goals>
<configuration>
<protocVersion>3.6.0</protocVersion>
<protocArtifact>com.google.protobuf:protoc:3.21.1</protocArtifact>
<addSources>none</addSources>
<includeStdTypes>true</includeStdTypes>
<outputDirectory>src/main/java</outputDirectory>
<inputDirectories>
<include>src/main/proto</include>
Expand Down
3 changes: 2 additions & 1 deletion tugraph/procedures/cpp/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
print(r.content)

data = {'name':'%s' % plugin_name}
content = open('%s.so' % plugin_name, 'rb').read()
content = open('%s.cpp' % plugin_name, 'rb').read()
data['code_base64'] = base64.b64encode(content).decode()
data['description'] = '%s' % plugin_name
data['read_only'] = read_only
data['code_type'] = 'cpp'
js = json.dumps(data)
r = requests.post(url='http://%s/db/default/cpp_plugin' % endpoint, data=js, headers={'Content-Type':'application/json', 'Authorization':'Bearer %s' % jwt})
print(r.status_code)
Expand Down
17 changes: 8 additions & 9 deletions tugraph/procedures/cpp/tcr8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re
for (auto deposit =
LabeledOutEdgeIterator(loan.GetOutEdgeIterator(), loan.GetId(), 0, deposit_id, limit);
deposit.IsValid(); deposit.Next()) {
auto ts = deposit.Eit().GetField(TIMESTAMP).AsInt64();
auto timestamp = deposit.Eit().GetField(TIMESTAMP).AsInt64();
auto amount = deposit.Eit().GetField(AMOUNT).AsDouble();
if (ts > start_time && ts < end_time) {
if (timestamp > start_time && timestamp < end_time) {
auto dst = deposit.Eit().GetDst();
src_set.emplace(dst);
add_amount(min_amount, dst, amount);
Expand All @@ -170,10 +170,10 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re
for (auto eit = LabeledOutEdgeIterator(vit.GetOutEdgeIterator(), vit.GetId(), 0,
edge_label_ids, limit);
eit.IsValid(); eit.Next()) {
auto ts = eit.Eit().GetField(TIMESTAMP).AsInt64();
auto timestamp = eit.Eit().GetField(TIMESTAMP).AsInt64();
auto amount = eit.Eit().GetField(AMOUNT).AsDouble();
auto dst_vid = eit.Eit().GetDst();
if (ts > start_time && ts < end_time) {
if (timestamp > start_time && timestamp < end_time) {
add_amount(min_amount, dst_vid, amount);
add_dst(merged_in, min_amount, dst_vid, vid, eit.Eit().GetUid().ToString(),
amount, threshold, i);
Expand Down Expand Up @@ -208,12 +208,11 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re
lgraph_api::Result api_result(
{{"i", LGraphType::INTEGER}, {"r", LGraphType::DOUBLE}, {"d", LGraphType::INTEGER}});
for (auto& item : result) {
auto& r = api_result.NewRecord();
r.Insert("i", FieldData::Int64(std::get<2>(item)));
r.Insert("r", FieldData::Double(std::get<0>(item)));
r.Insert("d", FieldData::Int64(std::get<1>(item)));
auto r = api_result.MutableRecord();
r->Insert("i", FieldData::Int64(std::get<2>(item)));
r->Insert("r", FieldData::Double(std::get<0>(item)));
r->Insert("d", FieldData::Int64(std::get<1>(item)));
}
response = api_result.Dump();
return true;
}

33 changes: 16 additions & 17 deletions tugraph/procedures/cpp/trw1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re
static const std::string TRANSFER_TIMESTAMP = "timestamp";
static const std::vector<std::string> TRANSFER_FIELD_NAMES = {"timestamp", "amount"};
lgraph_api::Result api_result({{"msg", LGraphType::STRING}, {"txn", LGraphType::STRING}});
auto& record = api_result.NewRecord();
record.Insert("txn", FieldData::String("abort"));
auto record = api_result.MutableRecord();
record->Insert("txn", FieldData::String("abort"));
int64_t src_id, dst_id, time, amt, start_time, end_time;
int64_t limit = -1;
try {
Expand All @@ -109,7 +109,7 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re
parse_from_json(end_time, "endTime", input);
parse_from_json(limit, "limit", input);
} catch (std::exception& e) {
record.Insert("msg", FieldData::String("json parse error: " + std::string(e.what())));
record->Insert("msg", FieldData::String("json parse error: " + std::string(e.what())));
response = api_result.Dump();
return false;
}
Expand All @@ -120,13 +120,13 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re
(int16_t)txn.GetEdgeLabelId(TRANSFER_LABEL),
};
if (!src.IsValid() || !dst.IsValid()) {
record.Insert("msg", FieldData::String("src/dst invalid"));
record->Insert("msg", FieldData::String("src/dst invalid"));
response = api_result.Dump();
txn.Abort();
return false;
}
if (src.GetField(ACCOUNT_ISBLOCKED).AsBool() || dst.GetField(ACCOUNT_ISBLOCKED).AsBool()) {
record.Insert("msg", FieldData::String("src/dst is blocked"));
record->Insert("msg", FieldData::String("src/dst is blocked"));
response = api_result.Dump();
txn.Abort();
return true;
Expand All @@ -138,31 +138,31 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re
for (auto src_eit =
LabeledInEdgeIterator(src.GetInEdgeIterator(), 0, src.GetId(), transfer_id, limit);
src_eit.IsValid(); src_eit.Next()) {
auto ts = src_eit.Eit().GetField(TRANSFER_TIMESTAMP);
if (ts.AsInt64() > start_time && ts.AsInt64() < end_time) {
auto timestamp = src_eit.Eit().GetField(TRANSFER_TIMESTAMP);
if (timestamp.AsInt64() > start_time && timestamp.AsInt64() < end_time) {
src_in.emplace(src_eit.Eit().GetSrc());
}
}
if (src_in.empty()) {
record.Insert("msg", FieldData::String("not detected"));
record.Insert("txn", FieldData::String("commit"));
record->Insert("msg", FieldData::String("not detected"));
record->Insert("txn", FieldData::String("commit"));
response = api_result.Dump();
txn.Commit();
return true;
}
for (auto dst_eit =
LabeledOutEdgeIterator(dst.GetOutEdgeIterator(), dst.GetId(), 0, transfer_id, limit);
dst_eit.IsValid(); dst_eit.Next()) {
auto ts = dst_eit.Eit().GetField(TRANSFER_TIMESTAMP);
if (ts.AsInt64() > start_time && ts.AsInt64() < end_time &&
auto timestamp = dst_eit.Eit().GetField(TRANSFER_TIMESTAMP);
if (timestamp.AsInt64() > start_time && timestamp.AsInt64() < end_time &&
src_in.find(dst_eit.Eit().GetDst()) != src_in.end()) {
txn.Abort();
break;
}
}
if (txn.IsValid()) {
record.Insert("msg", FieldData::String("not detected"));
record.Insert("txn", FieldData::String("commit"));
record->Insert("msg", FieldData::String("not detected"));
record->Insert("txn", FieldData::String("commit"));
response = api_result.Dump();
txn.Commit();
return true;
Expand All @@ -172,16 +172,15 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re
dst = txn.GetVertexByUniqueIndex(ACCOUNT_LABEL, ACCOUNT_ID, FieldData(dst_id));
if (!src.IsValid() || !dst.IsValid()) {
txn.Abort();
record.Insert("msg", FieldData::String("src/dst invalid"));
record->Insert("msg", FieldData::String("src/dst invalid"));
response = api_result.Dump();
return false;
}
src.SetField(ACCOUNT_ISBLOCKED, FieldData(true));
dst.SetField(ACCOUNT_ISBLOCKED, FieldData(true));
record.Insert("msg", FieldData::String("block src/dst"));
record.Insert("txn", FieldData::String("commit"));
record->Insert("msg", FieldData::String("block src/dst"));
record->Insert("txn", FieldData::String("commit"));
response = api_result.Dump();
txn.Commit();
return true;
}

25 changes: 12 additions & 13 deletions tugraph/procedures/cpp/trw2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ using json = nlohmann::json;
#define COUNT_TRANSFER(eit) \
count = 0; \
while (eit.IsValid()) { \
auto ts = eit.Eit().GetField(TRANSFER_TIMESTAMP); \
auto timestamp = eit.Eit().GetField(TRANSFER_TIMESTAMP); \
auto amount = eit.Eit().GetField(TRANSFER_AMOUNT); \
if (ts.AsInt64() > start_time && ts.AsInt64() < end_time && \
if (timestamp.AsInt64() > start_time && timestamp.AsInt64() < end_time && \
amount.AsDouble() > threshold) { \
count += 1; \
break; \
} \
eit.Next(); \
} \
if (count == 0) { \
record.Insert("msg", FieldData::String("not detected")); \
record.Insert("txn", FieldData::String("commit")); \
record->Insert("msg", FieldData::String("not detected")); \
record->Insert("txn", FieldData::String("commit")); \
response = api_result.Dump(); \
txn.Commit(); \
return true; \
Expand Down Expand Up @@ -118,8 +118,8 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re
static const std::string TRANSFER_AMOUNT = "amount";
static const std::vector<std::string> TRANSFER_FIELD_NAMES = {"timestamp", "amount"};
lgraph_api::Result api_result({{"msg", LGraphType::STRING}, {"txn", LGraphType::STRING}});
auto& record = api_result.NewRecord();
record.Insert("txn", FieldData::String("abort"));
auto record = api_result.MutableRecord();
record->Insert("txn", FieldData::String("abort"));
int64_t src_id, dst_id, time, start_time, end_time;
int64_t limit = -1;
double amt, threshold;
Expand All @@ -134,21 +134,21 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re
parse_from_json(end_time, "endTime", input);
parse_from_json(limit, "limit", input);
} catch (std::exception& e) {
record.Insert("msg", FieldData::String("json parse error: " + std::string(e.what())));
record->Insert("msg", FieldData::String("json parse error: " + std::string(e.what())));
response = api_result.Dump();
return false;
}
auto txn = db.CreateWriteTxn();
auto src = txn.GetVertexByUniqueIndex(ACCOUNT_LABEL, ACCOUNT_ID, FieldData(src_id));
auto dst = txn.GetVertexByUniqueIndex(ACCOUNT_LABEL, ACCOUNT_ID, FieldData(dst_id));
if (!src.IsValid() || !dst.IsValid()) {
record.Insert("msg", FieldData::String("src/dst invalid"));
record->Insert("msg", FieldData::String("src/dst invalid"));
response = api_result.Dump();
txn.Abort();
return false;
}
if (src.GetField(ACCOUNT_ISBLOCKED).AsBool() || dst.GetField(ACCOUNT_ISBLOCKED).AsBool()) {
record.Insert("msg", FieldData::String("src/dst is blocked"));
record->Insert("msg", FieldData::String("src/dst is blocked"));
response = api_result.Dump();
txn.Abort();
return true;
Expand Down Expand Up @@ -180,16 +180,15 @@ extern "C" bool Process(GraphDB& db, const std::string& request, std::string& re
dst = txn.GetVertexByUniqueIndex(ACCOUNT_LABEL, ACCOUNT_ID, FieldData(dst_id));
if (!src.IsValid() || !dst.IsValid()) {
txn.Abort();
record.Insert("msg", FieldData::String("src/dst invalid"));
record->Insert("msg", FieldData::String("src/dst invalid"));
response = api_result.Dump();
return false;
}
src.SetField(ACCOUNT_ISBLOCKED, FieldData(true));
dst.SetField(ACCOUNT_ISBLOCKED, FieldData(true));
record.Insert("msg", FieldData::String("block src/dst"));
record.Insert("txn", FieldData::String("commit"));
record->Insert("msg", FieldData::String("block src/dst"));
record->Insert("txn", FieldData::String("commit"));
response = api_result.Dump();
txn.Commit();
return true;
}

Loading

0 comments on commit 84e69fe

Please sign in to comment.