-
Notifications
You must be signed in to change notification settings - Fork 521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(api&core): in oltp apis, add statistics info and support full info about vertices and edges #2262
feat(api&core): in oltp apis, add statistics info and support full info about vertices and edges #2262
Changes from 10 commits
8a8f9c7
8f3f9db
eef9da4
023acf6
fc94aa3
c6ab9f4
c7825a6
e671963
1e33cda
262ae05
793ead8
5bb446a
cea5db2
4cc5f46
92ba7c8
559bff1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ upload-files/ | |
demo* | ||
gen-java | ||
*.class | ||
swagger-ui-* | ||
hugegraph-dist/dist.sh | ||
|
||
### STS ### | ||
.apt_generated | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,24 +22,26 @@ | |
import java.util.concurrent.Callable; | ||
import java.util.function.Consumer; | ||
|
||
import jakarta.ws.rs.ForbiddenException; | ||
import jakarta.ws.rs.NotFoundException; | ||
import jakarta.ws.rs.NotSupportedException; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import org.apache.commons.lang.mutable.MutableLong; | ||
import org.apache.hugegraph.HugeException; | ||
import org.apache.hugegraph.HugeGraph; | ||
import org.apache.hugegraph.core.GraphManager; | ||
import org.apache.hugegraph.define.Checkable; | ||
import org.apache.hugegraph.metrics.MetricsUtil; | ||
import org.slf4j.Logger; | ||
|
||
import org.apache.hugegraph.HugeException; | ||
import org.apache.hugegraph.HugeGraph; | ||
import org.apache.hugegraph.util.E; | ||
import org.apache.hugegraph.util.InsertionOrderUtil; | ||
import org.apache.hugegraph.util.JsonUtil; | ||
import org.apache.hugegraph.util.Log; | ||
import org.slf4j.Logger; | ||
|
||
import com.codahale.metrics.Meter; | ||
import com.google.common.collect.ImmutableMap; | ||
|
||
import jakarta.ws.rs.ForbiddenException; | ||
import jakarta.ws.rs.NotFoundException; | ||
import jakarta.ws.rs.NotSupportedException; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
public class API { | ||
|
||
protected static final Logger LOG = Log.logger(API.class); | ||
|
@@ -69,8 +71,7 @@ public class API { | |
public static HugeGraph graph(GraphManager manager, String graph) { | ||
HugeGraph g = manager.graph(graph); | ||
if (g == null) { | ||
throw new NotFoundException(String.format( | ||
"Graph '%s' does not exist", graph)); | ||
throw new NotFoundException(String.format("Graph '%s' does not exist", graph)); | ||
} | ||
return g; | ||
} | ||
|
@@ -140,8 +141,7 @@ protected static void checkUpdatingBody(Checkable body) { | |
body.checkUpdate(); | ||
} | ||
|
||
protected static void checkCreatingBody( | ||
Collection<? extends Checkable> bodies) { | ||
protected static void checkCreatingBody(Collection<? extends Checkable> bodies) { | ||
E.checkArgumentNotNull(bodies, "The request body can't be empty"); | ||
for (Checkable body : bodies) { | ||
E.checkArgument(body != null, | ||
|
@@ -150,8 +150,7 @@ protected static void checkCreatingBody( | |
} | ||
} | ||
|
||
protected static void checkUpdatingBody( | ||
Collection<? extends Checkable> bodies) { | ||
protected static void checkUpdatingBody(Collection<? extends Checkable> bodies) { | ||
E.checkArgumentNotNull(bodies, "The request body can't be empty"); | ||
for (Checkable body : bodies) { | ||
E.checkArgumentNotNull(body, | ||
|
@@ -186,8 +185,56 @@ public static boolean checkAndParseAction(String action) { | |
} else if (action.equals(ACTION_ELIMINATE)) { | ||
return false; | ||
} else { | ||
throw new NotSupportedException( | ||
String.format("Not support action '%s'", action)); | ||
throw new NotSupportedException(String.format("Not support action '%s'", action)); | ||
} | ||
} | ||
|
||
public static class ApiMeasurer { | ||
|
||
public static final String EDGE_ITER = "edge_iterations"; | ||
public static final String VERTICE_ITER = "vertice_iterations"; | ||
public static final String COST = "cost"; | ||
private final long timeStart; | ||
private final Map<String, Object> measures; | ||
|
||
public ApiMeasurer() { | ||
this.timeStart = System.currentTimeMillis(); | ||
this.measures = InsertionOrderUtil.newMap(); | ||
} | ||
|
||
public Map<String, Object> measures() { | ||
measures.put(COST, System.currentTimeMillis() - timeStart); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. compute duration use System.nanoTime perfered There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
return measures; | ||
} | ||
|
||
public void put(String key, String value) { | ||
this.measures.put(key, value); | ||
} | ||
|
||
public void put(String key, long value) { | ||
this.measures.put(key, value); | ||
} | ||
|
||
public void put(String key, int value) { | ||
this.measures.put(key, value); | ||
} | ||
|
||
protected void addCount(String key, long value) { | ||
Object current = measures.get(key); | ||
if (current == null) { | ||
measures.put(key, new MutableLong(value)); | ||
} else if (current instanceof MutableLong) { | ||
MutableLong currentMutableLong = (MutableLong) current; | ||
currentMutableLong.add(value); | ||
} else if (current instanceof Long) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. measures.computeIfAbsent(key, MutableLong.new).add(value) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add else branch then throw an exception There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
Long currentLong = (Long) current; | ||
measures.put(key, new MutableLong(currentLong + value)); | ||
} | ||
} | ||
|
||
public void addIterCount(long verticeIters, long edgeIters) { | ||
this.addCount(EDGE_ITER, edgeIters); | ||
this.addCount(VERTICE_ITER, verticeIters); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, but we need fix/remove it in the
dist-script
rather than exclude them in git (will be fixed it in another PR) @VGalaxiesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, fixed and rollback change