imbajin commented on code in PR #3008:
URL: https://github.com/apache/hugegraph/pull/3008#discussion_r3187099160
##########
hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/core/GraphManager.java:
##########
@@ -2174,6 +2199,43 @@ public Map<String, Object> graphConfig(String graphSpace,
return this.metaManager.getGraphConfig(graphSpace, graphName);
}
+ /**
+ * Update the nickname of a graph.
+ * In non-PD mode (standalone RocksDB), only the in-memory instance is
updated
+ * since local config files cannot be hot-reloaded.
+ * In PD mode, the change is also persisted to the meta storage so it
+ * survives restarts.
+ */
+ public void updateGraphNickname(String graphSpace, String graphName,
+ String nickname) {
+ // Always update the in-memory graph instance first
+ HugeGraph g = this.graph(graphSpace, graphName);
+ if (g != null) {
+ g.nickname(nickname);
+ }
+ if (!isPDEnabled()) {
+ // Non-PD mode: in-memory only, acceptable for standalone RocksDB
+ return;
+ }
+ try {
+ Map<String, Object> configs =
+ this.metaManager.getGraphConfig(graphSpace, graphName);
+ if (configs != null) {
+ configs.put("nickname", nickname);
+ this.metaManager.updateGraphConfig(graphSpace, graphName,
configs);
+ this.metaManager.notifyGraphUpdate(graphSpace, graphName);
+ }
+ } catch (Exception e) {
+ // Roll back the in-memory change so that the runtime state stays
+ // consistent with what was actually persisted.
+ if (g != null) {
+ g.nickname(null);
Review Comment:
⚠️ **Bug: failed PD persistence rolls back the nickname to `null` instead of
the previous value**
`updateGraphNickname()` mutates the in-memory graph before writing PD meta.
If `updateGraphConfig()` or `notifyGraphUpdate()` fails, the catch block sets
the nickname to `null`, which can leave the running server in a third state
that matches neither the requested value nor the persisted value. Please
capture the old nickname before mutation and restore that value on failure.
```suggestion
String oldNickname = g != null ? g.nickname() : null;
if (g != null) {
g.nickname(nickname);
}
```
##########
hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/profile/GraphsAPI.java:
##########
@@ -136,6 +240,76 @@ public Object get(@Context GraphManager manager,
return ImmutableMap.of("name", g.name(), "backend", g.backend());
}
+ @POST
+ @Timed
+ @Path("{name}/default")
+ @Produces(APPLICATION_JSON_WITH_CHARSET)
+ @RolesAllowed({"space_member", "$owner=$name"})
+ public Map<String, Object> setDefault(@Context GraphManager manager,
+ @Parameter(description = "The graph
space name")
+ @PathParam("graphspace") String
graphSpace,
+ @Parameter(description = "The graph
name")
+ @PathParam("name") String name) {
+ LOG.debug("Set default graph '{}' in graph space '{}'", name,
graphSpace);
+ E.checkArgument(manager.graph(graphSpace, name) != null,
+ "Graph '%s/%s' does not exist", graphSpace, name);
+ // Default graph persistence requires PD meta storage.
Review Comment:
⚠️ **Behavior regression: standalone mode silently ignores default graph
changes**
The earlier standalone-compatibility goal was that `POST/DELETE/GET
.../graphs/default` should work through `StandardAuthManager`. This branch now
returns an empty set in non-PD mode, so Hubble can call the API without an
exception but the user preference is never saved or reflected by `GET
/graphs/default` / `GET /graphs/profile`. If default graph is expected in
standalone RocksDB, please route this through the existing `AuthManager`
implementation instead of making it a no-op; otherwise the endpoint should be
documented as PD-only so the frontend can avoid treating the empty response as
success.
--
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]