bitflicker64 commented on code in PR #832:
URL:
https://github.com/apache/hugegraph-toolchain/pull/832#discussion_r4349529486
##########
hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/service/graphs/GraphsService.java:
##########
@@ -799,50 +812,50 @@ public void initCovid19(HugeClient client, boolean exist,
}
/**
- * 统计指定单个图中的顶点总数和边总数
+ * Read recorded element counts without starting a graph-wide count.
+ * A graph without a recent statistics snapshot has unknown counts.
*/
public Map<String, Object> evCount(HugeClient client,
String graphSpace,
String graph) {
Map<String, Object> res = new HashMap<>();
+ String key = this.statisticsKey(client, graphSpace, graph);
+ GraphStatisticsEntity statistics = key == null ? null :
this.boundedStatistics.getIfPresent(key);
+ if (statistics != null) {
+ res.put("date", statistics.getUpdateTime().substring(0,
10).replace("-", ""));
+ res.put("vertex", Long.valueOf(statistics.getVertexCount()));
+ res.put("edge", Long.valueOf(statistics.getEdgeCount()));
+ res.put("approximate", true);
+ res.put("scan_limit", statistics.getScanLimit());
+ return res;
+ }
Long edgeCount = null;
Long vertexCount = null;
String statisticDate = HubbleUtil.dateFormatDay(HubbleUtil.nowDate());
client.assignGraph(graphSpace, graph);
GraphMetricsAPI.ElementCount statistic = null;
- boolean pdEnabled = this.config != null &&
- this.config.get(HubbleOptions.PD_ENABLED);
- if (!pdEnabled) {
+ try {
Review Comment:
Minor: Removing the `if (!pdEnabled)` guard means PD mode now also requests
`graphspaces/{gs}/graphs/{g}/metrics/elementcount`, for today and then for
yesterday. Apache HugeGraph Server has no such resource: on master,
`elementcount` matches nothing in hugegraph-server, and MetricsAPI only serves
`metrics/system`, `backend`, `gauges` and similar. So each evCount sends two
requests that fail, and GraphMetricsAPI.getEVCount logs a WARN for each, per
graph card and per overview load. The PR body mentions snapshot reads, but not
that they always fail on Apache Server.
Please keep the guard, or drop the snapshot read if no supported Server
provides it.
##########
hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/service/graphs/GraphsService.java:
##########
@@ -461,12 +506,29 @@ public static String getStatisticsKey(String graphSpace,
String graph) {
public GraphStatisticsEntity getStatistics(HugeClient client,
String graphSpace,
String graph) {
- GraphStatisticsEntity result;
- // Only invalidate the cache entry of the current graph
- this.graphStatistics.remove(getStatisticsKey(graphSpace, graph));
- result = postSmallStatistics(client, graphSpace, graph);
+ String key = this.statisticsKey(client, graphSpace, graph);
+ if (key == null) {
+ // Snapshot reuse requires a stable target, identity and current
policy.
+ return this.collectBoundedStatistics(client);
+ }
+ try {
+ return this.boundedStatistics.get(key, () ->
this.collectBoundedStatistics(client));
Review Comment:
Important: A cached zero is reused as a confirmed zero after the graph gets
data.
Collect on an empty graph, then load data through Hubble. For up to 30
minutes, getStatistics and evCount return 0/0, because explicit collection
reuses the entry and nothing invalidates it. `canRunLouvain`
(algorithmsForm/Home) and `isEmptyGraph` (GraphResult/Home) treat that as a
known zero, so Louvain stays disabled and the empty-graph state shows, although
the PR body says algorithms are disabled only for confirmed zero counts. Before
this PR, both paths recomputed. A focused test that changes the Gremlin result
between two calls reproduces it.
The simplest fix is not to keep a zero: after `get`, call
`this.boundedStatistics.invalidate(key)` when the vertex or edge count is
`"0"`. An empty scan is cheap to repeat, and this covers every write path,
including writes from outside Hubble.
##########
hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/service/graphs/GraphsService.java:
##########
@@ -799,50 +812,50 @@ public void initCovid19(HugeClient client, boolean exist,
}
/**
- * 统计指定单个图中的顶点总数和边总数
+ * Read recorded element counts without starting a graph-wide count.
+ * A graph without a recent statistics snapshot has unknown counts.
*/
public Map<String, Object> evCount(HugeClient client,
String graphSpace,
String graph) {
Map<String, Object> res = new HashMap<>();
+ String key = this.statisticsKey(client, graphSpace, graph);
Review Comment:
Minor: Every passive read builds the full key first, so `statisticsPolicy`
makes `verifyToken` (or `findUserByName`) plus `getUserRole` calls before
`getIfPresent`, even though only an explicit collection fills the cache and a
miss is the usual result. GraphSpaceService.evCount repeats this once per graph
in the space, with the same client and policy each time.
One simple option is to key the cache by context and graph, store the policy
hash in the entry, and compute the policy only on a hit.
##########
hugegraph-hubble/hubble-fe/src/pages/GraphSpace/Card.js:
##########
@@ -136,6 +137,7 @@ const GraphSpaceCard = ({
const memory = showText(item.memory_limit, t('graphspace.unit.memory'),
unlimited);
const storage = showText(item.storage_limit, t('graphspace.unit.memory'),
unlimited);
const statisticDate = item.statistic?.date;
+ const hasStatistics = isKnownCount(item.statistic?.vertex) &&
isKnownCount(item.statistic?.edge);
Review Comment:
Minor: `hasStatistics` is now always false. graphSpaceView puts an empty
`statistic` map (GraphSpaceService.java:178), and accessibleView, anonymousView
and getAccessibleWithAdmins no longer call setStatistic. So the counts row,
snapshot date and tooltip on graph space cards can no longer render, and the
three Card.test.js cases with `vertex: 0` cover input the backend no longer
sends.
Please remove the row, its tests and the empty `statistic` put, and mention
in the PR description that space cards no longer show totals.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]