Skip to content

optimize(api): disable GraphSpaceAPI and ManagerAPI in standalone mode#2966

Open
contrueCT wants to merge 8 commits intoapache:masterfrom
contrueCT:feat/disable-graphspace-manager-api-in-standalone
Open

optimize(api): disable GraphSpaceAPI and ManagerAPI in standalone mode#2966
contrueCT wants to merge 8 commits intoapache:masterfrom
contrueCT:feat/disable-graphspace-manager-api-in-standalone

Conversation

@contrueCT
Copy link
Contributor

Purpose of the PR

Main Changes

The issue requires GraphSpaceAPI to return a friendly response in standalone mode. During code investigation, I found that ManagerAPI has a similar problem: in standalone mode, manager.graphSpace(name) returns a fake new GraphSpace("DEFAULT"), which causes ManagerAPI.validGraphSpace() to pass incorrectly. As a result, ManagerAPI can still enter logic that is not actually supported in standalone mode, leading to unfriendly errors or behavior that does not match the API semantics. For consistency and correctness, I applied the same standalone-mode guard to ManagerAPI as well.

  • Add public isUsePD() accessor to GraphManager to expose PD status
  • Add checkPdModeEnabled() helper in API base class
  • Call checkPdModeEnabled() in all public methods of GraphSpaceAPI (list/get/create/manage/delete)
  • Call checkPdModeEnabled() in all public methods of ManagerAPI (createManager/delete/list/checkRole/getRolesInGs)
  • Returns HTTP 400 with message 'GraphSpace management is not supported in standalone mode'
  • Add standalone-mode rejection tests in GraphSpaceApiTest and ManagerApiTest

Verifying these changes

  • Trivial rework / code cleanup without any test coverage. (No Need)
  • Already covered by existing tests, such as (please modify tests here).
  • Need tests and can be verified as follows:
    • xxx

Does this PR potentially affect the following parts?

Documentation Status

  • Doc - TODO
  • Doc - Done
  • Doc - No Need

contrueCT and others added 3 commits March 10, 2026 17:34
- Add public isUsePD() accessor to GraphManager to expose PD status
- Add checkPdModeEnabled() helper in API base class
- Call checkPdModeEnabled() in all public methods of GraphSpaceAPI (list/get/create/manage/delete)
- Call checkPdModeEnabled() in all public methods of ManagerAPI (createManager/delete/list/checkRole/getRolesInGs)
- Returns HTTP 400 with message 'GraphSpace management is not supported in standalone mode'
- Add standalone-mode rejection tests in GraphSpaceApiTest and ManagerApiTest
@imbajin imbajin requested a review from Copilot March 10, 2026 12:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses issue #2964 by disabling GraphSpaceAPI and ManagerAPI endpoints in standalone (non-PD) mode, returning a friendly HTTP 400 error instead of allowing logic that doesn't apply outside of PD mode.

Changes:

  • Added isUsePD() public accessor to GraphManager to expose PD status
  • Added checkPdModeEnabled() static helper in API base class, called at the start of all public methods in GraphSpaceAPI and ManagerAPI
  • Added standalone-mode rejection tests in GraphSpaceApiTest and ManagerApiTest

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
GraphManager.java Exposes isUsePD() as a public method
API.java Adds checkPdModeEnabled() helper throwing HTTP 400 in non-PD mode
GraphSpaceAPI.java Guards all public endpoints with checkPdModeEnabled()
ManagerAPI.java Guards all public endpoints with checkPdModeEnabled()
GraphSpaceApiTest.java Tests that all GraphSpaceAPI endpoints return 400 in standalone mode
ManagerApiTest.java Tests that all ManagerAPI endpoints return 400 in standalone mode

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@contrueCT contrueCT requested review from Copilot and imbajin March 11, 2026 16:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}

@Test
public void testListManagerReturnsFriendlyError() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ The new standalone tests only exercise the ADMIN branch, so they don't actually lock down the regression described in the PR body. The problematic path was that validGraphSpace() could still succeed in standalone mode because manager.graphSpace(name) returns a synthetic DEFAULT space, and that only happens in the SPACE / SPACE_MEMBER branches.

ASCII view:

checkPdModeEnabled()
        |
        +-- ADMIN         <- covered here
        +-- SPACE         <- regression path
        \-- SPACE_MEMBER <- regression path

Please add at least one standalone test with type=SPACE or type=SPACE_MEMBER against a non-DEFAULT graphspace, so this PR verifies the branch that used to fall through.

Suggested change
public void testListManagerReturnsFriendlyError() {
@Test
public void testListSpaceManagerReturnsFriendlyError() {
Response r = this.client().get(managerPath("nonexistent"),
Map.of("type", (Object) HugePermission.SPACE));
String content = assertResponseStatus(400, r);
Assert.assertTrue(content.contains(STANDALONE_ERROR));
}

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +537 to +538
}
catch (IOException e) {
Comment on lines +513 to +514
}
else {
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +325 to +327
Map<String, List<Map<String, Object>>> resultMap = JsonUtil.fromJson(result,
new TypeReference<Map<String, List<Map<String, Object>>>>() {
});
String backend = System.getProperty("backend");
Assume.assumeTrue(
"skip standalone tests: backend is '" + backend + "' (hstore/PD mode)",
backend != null && !backend.equals("hstore"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ assumeStandaloneMode() uses a double-negative condition (backend != null && !backend.equals("hstore")), which reduces readability. Prefer an explicit boolean variable and Assume.assumeFalse(...) for clarity and null-safety:

boolean isPdMode = "hstore".equals(backend);
Assume.assumeFalse("Skip in PD/distributed mode", isPdMode);

}
}

public static void checkPdModeEnabled(GraphManager manager) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Method name checkPdModeEnabled() is non-idiomatic for a method that throws — Java convention uses imperative names like ensure* or require* for assertion/guard methods. Consider renaming:

public static void ensurePdModeEnabled(GraphManager manager) {

Also missing: a null-check for manager and a Javadoc comment explaining what exception is thrown and when.

}
}

public static void checkPdModeEnabled(GraphManager manager) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Declaring this as public static on the widely-used API base class unnecessarily expands the public API surface. Since this guard is only called from API subclasses, consider reducing visibility to protected:

protected static void checkPdModeEnabled(GraphManager manager) {

public static void checkPdModeEnabled(GraphManager manager) {
if (!manager.usePD()) {
throw new HugeException(
"GraphSpace management is not supported in standalone mode");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 The error message "GraphSpace management is not supported in standalone mode" is duplicated across production code and tests. Extract it to a constant to avoid typos and make future changes easier:

private static final String PD_MODE_REQUIRED_MSG =
        "GraphSpace management is not supported in standalone mode";

}

private boolean usePD() {
public boolean usePD() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ usePD() is an ambiguous name for a public boolean accessor — Java convention for boolean getters is is* or has*. Consider renaming to isPdEnabled() or isUsePD() to make the intent clear:

public boolean isPdEnabled() {
    return this.PDExist;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] protect GraphSpaceAPI in non-hstore status

3 participants