From 456cb36f5524daa407a83029c5ec49be62319640 Mon Sep 17 00:00:00 2001 From: Ayan Alam Date: Mon, 28 Sep 2026 01:40:48 +0530 Subject: [PATCH] refactor(server): remove the inactive master redirect filter RedirectFilter only forwarded requests when GlobalMasterInfo.supportElection() was true, and the only code that set it was the role election path removed in #3244, which nothing had called since #3082. The filter was still registered on 21 endpoint methods and returned early on every request. Remove RedirectFilter, RedirectFilterDynamicFeature and the @RedirectMasterRole annotations, the election and master URL state in GlobalMasterInfo, and GraphTransaction.queryServerInfos(), which read the ~server vertices HugeServerInfo used to write and had no callers. --- .../hugegraph/api/filter/RedirectFilter.java | 156 ------------------ .../filter/RedirectFilterDynamicFeature.java | 35 ---- .../hugegraph/api/job/AlgorithmAPI.java | 2 - .../apache/hugegraph/api/job/ComputerAPI.java | 2 - .../apache/hugegraph/api/job/GremlinAPI.java | 2 - .../apache/hugegraph/api/job/RebuildAPI.java | 3 - .../org/apache/hugegraph/api/job/TaskAPI.java | 3 - .../apache/hugegraph/api/raft/RaftAPI.java | 3 - .../hugegraph/api/schema/EdgeLabelAPI.java | 4 - .../hugegraph/api/schema/IndexLabelAPI.java | 4 - .../hugegraph/api/schema/PropertyKeyAPI.java | 4 - .../hugegraph/api/schema/VertexLabelAPI.java | 4 - .../hugegraph/server/ApplicationConfig.java | 3 - .../backend/tx/GraphTransaction.java | 12 -- .../masterelection/GlobalMasterInfo.java | 56 +------ .../unit/api/filter/AccessLogFilterTest.java | 20 --- 16 files changed, 1 insertion(+), 312 deletions(-) delete mode 100644 hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/RedirectFilter.java delete mode 100644 hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/RedirectFilterDynamicFeature.java diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/RedirectFilter.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/RedirectFilter.java deleted file mode 100644 index 2a2a9142ef..0000000000 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/RedirectFilter.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hugegraph.api.filter; - -import java.io.IOException; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.lang3.StringUtils; -import org.apache.http.client.utils.URIBuilder; -import org.apache.hugegraph.core.GraphManager; -import org.apache.hugegraph.masterelection.GlobalMasterInfo; -import org.apache.hugegraph.util.E; -import org.apache.hugegraph.util.Log; -import org.glassfish.hk2.api.IterableProvider; -import org.glassfish.hk2.api.ServiceHandle; -import org.glassfish.jersey.message.internal.HeaderUtils; -import org.slf4j.Logger; - -import jakarta.ws.rs.NameBinding; -import jakarta.ws.rs.client.Client; -import jakarta.ws.rs.client.ClientBuilder; -import jakarta.ws.rs.client.Entity; -import jakarta.ws.rs.client.Invocation; -import jakarta.ws.rs.container.ContainerRequestContext; -import jakarta.ws.rs.container.ContainerRequestFilter; -import jakarta.ws.rs.core.Context; -import jakarta.ws.rs.core.MultivaluedMap; -import jakarta.ws.rs.core.Response; - -public class RedirectFilter implements ContainerRequestFilter { - - private static final Logger LOG = Log.logger(RedirectFilter.class); - - private static final String X_HG_REDIRECT = "x-hg-redirect"; - - private static volatile Client client = null; - - @Context - private IterableProvider managerProvider; - - private static final Set MUST_BE_NULL = new HashSet<>(); - - static { - MUST_BE_NULL.add("DELETE"); - MUST_BE_NULL.add("GET"); - MUST_BE_NULL.add("HEAD"); - MUST_BE_NULL.add("TRACE"); - } - - @Override - public void filter(ContainerRequestContext context) throws IOException { - ServiceHandle handle = this.managerProvider.getHandle(); - E.checkState(handle != null, "Context GraphManager is absent"); - GraphManager manager = handle.getService(); - E.checkState(manager != null, "Context GraphManager is absent"); - - String redirectTag = context.getHeaderString(X_HG_REDIRECT); - if (StringUtils.isNotEmpty(redirectTag)) { - return; - } - - GlobalMasterInfo globalNodeInfo = manager.globalNodeRoleInfo(); - if (globalNodeInfo == null || !globalNodeInfo.supportElection()) { - return; - } - GlobalMasterInfo.NodeInfo masterInfo = globalNodeInfo.masterInfo(); - if (masterInfo == null || masterInfo.isMaster() || - StringUtils.isEmpty(masterInfo.nodeUrl())) { - return; - } - String url = masterInfo.nodeUrl(); - - URI redirectUri; - try { - URIBuilder redirectURIBuilder = new URIBuilder(context.getUriInfo().getRequestUri()); - URI masterURI = URI.create(url); - redirectURIBuilder.setHost(masterURI.getHost()); - redirectURIBuilder.setPort(masterURI.getPort()); - redirectURIBuilder.setScheme(masterURI.getScheme()); - - redirectUri = redirectURIBuilder.build(); - } catch (URISyntaxException e) { - LOG.error("Redirect request exception occurred", e); - return; - } - this.initClientIfNeeded(); - Response response = this.forwardRequest(context, redirectUri); - context.abortWith(response); - } - - private Response forwardRequest(ContainerRequestContext requestContext, URI redirectUri) { - MultivaluedMap headers = requestContext.getHeaders(); - MultivaluedMap newHeaders = HeaderUtils.createOutbound(); - if (headers != null) { - for (Map.Entry> entry : headers.entrySet()) { - for (String value : entry.getValue()) { - newHeaders.add(entry.getKey(), value); - } - } - } - newHeaders.add(X_HG_REDIRECT, new Date().getTime()); - Invocation.Builder builder = client.target(redirectUri) - .request() - .headers(newHeaders); - Response response; - if (MUST_BE_NULL.contains(requestContext.getMethod())) { - response = builder.method(requestContext.getMethod()); - } else { - response = builder.method(requestContext.getMethod(), - Entity.json(requestContext.getEntityStream())); - } - return response; - } - - private void initClientIfNeeded() { - if (client != null) { - return; - } - - synchronized (RedirectFilter.class) { - if (client != null) { - return; - } - client = ClientBuilder.newClient(); - } - } - - @NameBinding - @Retention(RetentionPolicy.RUNTIME) - public @interface RedirectMasterRole { - - } -} diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/RedirectFilterDynamicFeature.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/RedirectFilterDynamicFeature.java deleted file mode 100644 index 9a90084dde..0000000000 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/RedirectFilterDynamicFeature.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hugegraph.api.filter; - -import jakarta.ws.rs.Priorities; -import jakarta.ws.rs.container.DynamicFeature; -import jakarta.ws.rs.container.ResourceInfo; -import jakarta.ws.rs.core.FeatureContext; -import jakarta.ws.rs.ext.Provider; - -@Provider -public class RedirectFilterDynamicFeature implements DynamicFeature { - - @Override - public void configure(ResourceInfo resourceInfo, FeatureContext context) { - if (resourceInfo.getResourceMethod().isAnnotationPresent(RedirectFilter.RedirectMasterRole.class)) { - context.register(RedirectFilter.class, Priorities.USER + 1); - } - } -} diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/AlgorithmAPI.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/AlgorithmAPI.java index 79933bc371..6554d58072 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/AlgorithmAPI.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/AlgorithmAPI.java @@ -21,7 +21,6 @@ import org.apache.hugegraph.HugeGraph; import org.apache.hugegraph.api.API; -import org.apache.hugegraph.api.filter.RedirectFilter; import org.apache.hugegraph.api.filter.StatusFilter.Status; import org.apache.hugegraph.backend.id.Id; import org.apache.hugegraph.core.GraphManager; @@ -60,7 +59,6 @@ public class AlgorithmAPI extends API { @Status(Status.CREATED) @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON_WITH_CHARSET) - @RedirectFilter.RedirectMasterRole public Map post(@Context GraphManager manager, @Parameter(description = "The graphspace name") @PathParam("graphspace") String graphSpace, diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/ComputerAPI.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/ComputerAPI.java index d5188385cc..222ead7e55 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/ComputerAPI.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/ComputerAPI.java @@ -21,7 +21,6 @@ import org.apache.hugegraph.HugeGraph; import org.apache.hugegraph.api.API; -import org.apache.hugegraph.api.filter.RedirectFilter; import org.apache.hugegraph.api.filter.StatusFilter.Status; import org.apache.hugegraph.backend.id.Id; import org.apache.hugegraph.core.GraphManager; @@ -60,7 +59,6 @@ public class ComputerAPI extends API { @Status(Status.CREATED) @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON_WITH_CHARSET) - @RedirectFilter.RedirectMasterRole public Map post(@Context GraphManager manager, @Parameter(description = "The graph name") @PathParam("graph") String graph, diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/GremlinAPI.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/GremlinAPI.java index 779cf19b66..c6abac4067 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/GremlinAPI.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/GremlinAPI.java @@ -28,7 +28,6 @@ import org.apache.hugegraph.HugeException; import org.apache.hugegraph.HugeGraph; import org.apache.hugegraph.api.API; -import org.apache.hugegraph.api.filter.RedirectFilter; import org.apache.hugegraph.api.filter.StatusFilter.Status; import org.apache.hugegraph.backend.id.Id; import org.apache.hugegraph.core.GraphManager; @@ -77,7 +76,6 @@ public class GremlinAPI extends API { @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"space_member", "$graphspace=$graphspace $owner=$graph " + "$action=gremlin_execute"}) - @RedirectFilter.RedirectMasterRole public Map post(@Context GraphManager manager, @Parameter(description = "The graphspace name") @PathParam("graphspace") String graphSpace, diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/RebuildAPI.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/RebuildAPI.java index 3219c8b3ab..6c103ca414 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/RebuildAPI.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/RebuildAPI.java @@ -21,7 +21,6 @@ import org.apache.hugegraph.HugeGraph; import org.apache.hugegraph.api.API; -import org.apache.hugegraph.api.filter.RedirectFilter; import org.apache.hugegraph.api.filter.StatusFilter.Status; import org.apache.hugegraph.backend.id.Id; import org.apache.hugegraph.core.GraphManager; @@ -55,7 +54,6 @@ public class RebuildAPI extends API { @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"space", "$graphspace=$graphspace $owner=$graph " + "$action=index_label_write"}) - @RedirectFilter.RedirectMasterRole public Map vertexLabelRebuild(@Context GraphManager manager, @Parameter(description = "The graphspace name") @PathParam("graphspace") @@ -100,7 +98,6 @@ public Map edgeLabelRebuild(@Context GraphManager manager, @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"space", "$graphspace=$graphspace $owner=$graph " + "$action=index_label_write"}) - @RedirectFilter.RedirectMasterRole public Map indexLabelRebuild(@Context GraphManager manager, @Parameter(description = "The graphspace name") @PathParam("graphspace") diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/TaskAPI.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/TaskAPI.java index 7143efb5f7..0accec132a 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/TaskAPI.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/TaskAPI.java @@ -26,7 +26,6 @@ import org.apache.groovy.util.Maps; import org.apache.hugegraph.api.API; -import org.apache.hugegraph.api.filter.RedirectFilter; import org.apache.hugegraph.api.filter.StatusFilter.Status; import org.apache.hugegraph.backend.id.Id; import org.apache.hugegraph.backend.id.IdGenerator; @@ -153,7 +152,6 @@ public Map get(@Context GraphManager manager, @DELETE @Timed @Path("{id}") - @RedirectFilter.RedirectMasterRole public void delete(@Context GraphManager manager, @Parameter(description = "The graphspace name") @PathParam("graphspace") String graphSpace, @@ -176,7 +174,6 @@ public void delete(@Context GraphManager manager, @Path("{id}") @Status(Status.ACCEPTED) @Produces(APPLICATION_JSON_WITH_CHARSET) - @RedirectFilter.RedirectMasterRole public Map update(@Context GraphManager manager, @Parameter(description = "The graphspace name") @PathParam("graphspace") diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/raft/RaftAPI.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/raft/RaftAPI.java index f868df522e..fcc18c4c8c 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/raft/RaftAPI.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/raft/RaftAPI.java @@ -24,7 +24,6 @@ import org.apache.hugegraph.HugeException; import org.apache.hugegraph.HugeGraph; import org.apache.hugegraph.api.API; -import org.apache.hugegraph.api.filter.RedirectFilter; import org.apache.hugegraph.api.filter.StatusFilter.Status; import org.apache.hugegraph.backend.id.Id; import org.apache.hugegraph.backend.store.raft.RaftAddPeerJob; @@ -173,7 +172,6 @@ public Map setLeader(@Context GraphManager manager, @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"space_member"}) - @RedirectFilter.RedirectMasterRole public Map addPeer(@Context GraphManager manager, @Parameter(description = "The graph space name") @PathParam("graphspace") String graphSpace, @@ -209,7 +207,6 @@ public Map addPeer(@Context GraphManager manager, @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"space_member"}) - @RedirectFilter.RedirectMasterRole public Map removePeer(@Context GraphManager manager, @Parameter(description = "The graph space name") @PathParam("graphspace") String graphSpace, diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/schema/EdgeLabelAPI.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/schema/EdgeLabelAPI.java index f2026d58bd..3031b687d0 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/schema/EdgeLabelAPI.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/schema/EdgeLabelAPI.java @@ -26,7 +26,6 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.hugegraph.HugeGraph; import org.apache.hugegraph.api.API; -import org.apache.hugegraph.api.filter.RedirectFilter; import org.apache.hugegraph.api.filter.StatusFilter.Status; import org.apache.hugegraph.backend.id.Id; import org.apache.hugegraph.core.GraphManager; @@ -75,7 +74,6 @@ public class EdgeLabelAPI extends API { @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"space_member", "$graphspace=$graphspace $owner=$graph " + "$action=edge_label_write"}) - @RedirectFilter.RedirectMasterRole public String create(@Context GraphManager manager, @Parameter(description = "The graph space name") @PathParam("graphspace") String graphSpace, @@ -98,7 +96,6 @@ public String create(@Context GraphManager manager, @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"space_member", "$graphspace=$graphspace $owner=$graph " + "$action=edge_label_write"}) - @RedirectFilter.RedirectMasterRole public String update(@Context GraphManager manager, @Parameter(description = "The graph space name") @PathParam("graphspace") String graphSpace, @@ -185,7 +182,6 @@ public String get(@Context GraphManager manager, @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"space_member", "$graphspace=$graphspace $owner=$graph " + "$action=edge_label_delete"}) - @RedirectFilter.RedirectMasterRole public Map delete(@Context GraphManager manager, @Parameter(description = "The graph space name") @PathParam("graphspace") String graphSpace, diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/schema/IndexLabelAPI.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/schema/IndexLabelAPI.java index b76d532360..3bc769801d 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/schema/IndexLabelAPI.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/schema/IndexLabelAPI.java @@ -25,7 +25,6 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.hugegraph.HugeGraph; import org.apache.hugegraph.api.API; -import org.apache.hugegraph.api.filter.RedirectFilter; import org.apache.hugegraph.api.filter.StatusFilter.Status; import org.apache.hugegraph.backend.id.Id; import org.apache.hugegraph.core.GraphManager; @@ -75,7 +74,6 @@ public class IndexLabelAPI extends API { @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"space_member", "$graphspace=$graphspace $owner=$graph " + "$action=index_label_write"}) - @RedirectFilter.RedirectMasterRole public String create(@Context GraphManager manager, @Parameter(description = "The graph space name") @PathParam("graphspace") String graphSpace, @@ -97,7 +95,6 @@ public String create(@Context GraphManager manager, @Path("{name}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON_WITH_CHARSET) - @RedirectFilter.RedirectMasterRole public String update(@Context GraphManager manager, @Parameter(description = "The graph space name") @PathParam("graphspace") String graphSpace, @@ -183,7 +180,6 @@ public String get(@Context GraphManager manager, @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"space_member", "$graphspace=$graphspace $owner=$graph " + "$action=index_label_delete"}) - @RedirectFilter.RedirectMasterRole public Map delete(@Context GraphManager manager, @Parameter(description = "The graph space name") @PathParam("graphspace") String graphSpace, diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/schema/PropertyKeyAPI.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/schema/PropertyKeyAPI.java index 27d6ab1da2..1364b02fea 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/schema/PropertyKeyAPI.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/schema/PropertyKeyAPI.java @@ -25,7 +25,6 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.hugegraph.HugeGraph; import org.apache.hugegraph.api.API; -import org.apache.hugegraph.api.filter.RedirectFilter; import org.apache.hugegraph.api.filter.StatusFilter.Status; import org.apache.hugegraph.backend.id.Id; import org.apache.hugegraph.backend.id.IdGenerator; @@ -78,7 +77,6 @@ public class PropertyKeyAPI extends API { @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"space_member", "$graphspace=$graphspace $owner=$graph " + "$action=property_key_write"}) - @RedirectFilter.RedirectMasterRole public String create(@Context GraphManager manager, @Parameter(description = "The graph space name") @PathParam("graphspace") String graphSpace, @@ -102,7 +100,6 @@ public String create(@Context GraphManager manager, @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"space_member", "$graphspace=$graphspace $owner=$graph " + "$action=property_key_write"}) - @RedirectFilter.RedirectMasterRole public String update(@Context GraphManager manager, @Parameter(description = "The graph space name") @PathParam("graphspace") String graphSpace, @@ -205,7 +202,6 @@ public String get(@Context GraphManager manager, @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"space_member", "$graphspace=$graphspace $owner=$graph " + "$action=property_key_delete"}) - @RedirectFilter.RedirectMasterRole public Map delete(@Context GraphManager manager, @Parameter(description = "The graph space name") @PathParam("graphspace") String graphSpace, diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/schema/VertexLabelAPI.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/schema/VertexLabelAPI.java index c86622f7e5..4001ce27f5 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/schema/VertexLabelAPI.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/schema/VertexLabelAPI.java @@ -25,7 +25,6 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.hugegraph.HugeGraph; import org.apache.hugegraph.api.API; -import org.apache.hugegraph.api.filter.RedirectFilter; import org.apache.hugegraph.api.filter.StatusFilter.Status; import org.apache.hugegraph.backend.id.Id; import org.apache.hugegraph.core.GraphManager; @@ -73,7 +72,6 @@ public class VertexLabelAPI extends API { @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"space_member", "$graphspace=$graphspace $owner=$graph " + "$action=vertex_label_write"}) - @RedirectFilter.RedirectMasterRole public String create(@Context GraphManager manager, @Parameter(description = "The graph space name") @PathParam("graphspace") String graphSpace, @@ -97,7 +95,6 @@ public String create(@Context GraphManager manager, @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"space_member", "$graphspace=$graphspace $owner=$graph " + "$action=vertex_label_write"}) - @RedirectFilter.RedirectMasterRole public String update(@Context GraphManager manager, @Parameter(description = "The graph space name") @PathParam("graphspace") String graphSpace, @@ -186,7 +183,6 @@ public String get(@Context GraphManager manager, @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"space_member", "$graphspace=$graphspace $owner=$graph " + "$action=vertex_label_delete"}) - @RedirectFilter.RedirectMasterRole public Map delete(@Context GraphManager manager, @Parameter(description = "The graph space name") @PathParam("graphspace") String graphSpace, diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/server/ApplicationConfig.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/server/ApplicationConfig.java index 1930a1146c..dd4a0f46e9 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/server/ApplicationConfig.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/server/ApplicationConfig.java @@ -18,7 +18,6 @@ package org.apache.hugegraph.server; import org.apache.hugegraph.HugeException; -import org.apache.hugegraph.api.filter.RedirectFilterDynamicFeature; import org.apache.hugegraph.config.HugeConfig; import org.apache.hugegraph.core.GraphManager; import org.apache.hugegraph.define.WorkLoad; @@ -77,8 +76,6 @@ public ApplicationConfig(HugeConfig conf, EventHub hub) { // Register to use the jsr250 annotations @RolesAllowed register(RolesAllowedDynamicFeature.class); - register(RedirectFilterDynamicFeature.class); - // Register HugeConfig to context register(new ConfFactory(conf)); diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java index 3999b3d0c2..b22fb1dad3 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java @@ -751,18 +751,6 @@ public Iterator queryTaskInfos(Object... vertexIds) { HugeType.VERTEX); } - public Iterator queryServerInfos(Query query) { - return this.queryVertices(query); - } - - public Iterator queryServerInfos(Object... vertexIds) { - if (this.graph().backendStoreFeatures().supportsTaskAndServerVertex()) { - return this.queryVerticesByIds(vertexIds, false, false, - HugeType.SERVER); - } - return this.queryVerticesByIds(vertexIds, false, false, HugeType.VERTEX); - } - protected Iterator queryVerticesByIds(Object[] vertexIds, boolean adjacentVertex, boolean checkMustExist) { return this.queryVerticesByIds(vertexIds, adjacentVertex, checkMustExist, HugeType.VERTEX); diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/GlobalMasterInfo.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/GlobalMasterInfo.java index 4856744459..ef7c2f338d 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/GlobalMasterInfo.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/GlobalMasterInfo.java @@ -22,50 +22,16 @@ import org.apache.hugegraph.type.define.NodeRole; import org.apache.hugegraph.util.E; -// TODO: We need to completely delete the startup of master-worker public final class GlobalMasterInfo { - private static final NodeInfo NO_MASTER = new NodeInfo(false, ""); - - private volatile boolean supportElection; - private volatile NodeInfo masterNodeInfo; - private volatile Id nodeId; private volatile NodeRole nodeRole; public GlobalMasterInfo() { - this(NO_MASTER); - } - - public GlobalMasterInfo(NodeInfo masterInfo) { - this.supportElection = false; - this.masterNodeInfo = masterInfo; - this.nodeId = null; this.nodeRole = null; } - public void supportElection(boolean featureSupport) { - this.supportElection = featureSupport; - } - - public boolean supportElection() { - return this.supportElection; - } - - public void resetMasterInfo() { - this.masterNodeInfo = NO_MASTER; - } - - public void masterInfo(boolean isMaster, String nodeUrl) { - // final can avoid instruction rearrangement, visibility can be ignored - this.masterNodeInfo = new NodeInfo(isMaster, nodeUrl); - } - - public NodeInfo masterInfo() { - return this.masterNodeInfo; - } - public Id nodeId() { return this.nodeId; } @@ -91,29 +57,9 @@ public void changeNodeRole(NodeRole role) { } public static GlobalMasterInfo master(String nodeId) { - NodeInfo masterInfo = new NodeInfo(true, nodeId); - GlobalMasterInfo nodeInfo = new GlobalMasterInfo(masterInfo); + GlobalMasterInfo nodeInfo = new GlobalMasterInfo(); nodeInfo.nodeId = IdGenerator.of(nodeId); nodeInfo.nodeRole = NodeRole.MASTER; return nodeInfo; } - - public static class NodeInfo { - - private final boolean isMaster; - private final String nodeUrl; - - public NodeInfo(boolean isMaster, String url) { - this.isMaster = isMaster; - this.nodeUrl = url; - } - - public boolean isMaster() { - return this.isMaster; - } - - public String nodeUrl() { - return this.nodeUrl; - } - } } diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/filter/AccessLogFilterTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/filter/AccessLogFilterTest.java index ee7d87091b..bb6e455dca 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/filter/AccessLogFilterTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/filter/AccessLogFilterTest.java @@ -39,9 +39,6 @@ import org.apache.hugegraph.api.filter.DecompressInterceptor; import org.apache.hugegraph.api.filter.DecompressInterceptor.Decompress; import org.apache.hugegraph.api.filter.PathFilter; -import org.apache.hugegraph.api.filter.RedirectFilter; -import org.apache.hugegraph.api.filter.RedirectFilter.RedirectMasterRole; -import org.apache.hugegraph.api.filter.RedirectFilterDynamicFeature; import org.apache.hugegraph.config.HugeConfig; import org.apache.hugegraph.config.ServerOptions; import org.apache.hugegraph.core.GraphManager; @@ -65,11 +62,9 @@ import org.mockito.Mockito; import jakarta.inject.Provider; -import jakarta.ws.rs.Priorities; import jakarta.ws.rs.container.ContainerRequestContext; import jakarta.ws.rs.container.ContainerResponseContext; import jakarta.ws.rs.container.ResourceInfo; -import jakarta.ws.rs.core.FeatureContext; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.MultivaluedHashMap; import jakarta.ws.rs.core.UriInfo; @@ -365,16 +360,6 @@ public void testSkipBody_ForResourceThatDecodesEntity() throws IOException { Mockito.verify(this.requestContext, Mockito.never()).setEntityStream(Mockito.any(InputStream.class)); } - @Test - public void testRedirectRunsAfterBodyCapture() { - this.mockResourceMethod("redirectResource"); - FeatureContext context = Mockito.mock(FeatureContext.class); - - new RedirectFilterDynamicFeature().configure(this.resourceInfo, context); - - Mockito.verify(context).register(RedirectFilter.class, Priorities.USER + 1); - } - /** * Test the slow query log line contains the client IP and the body preview */ @@ -543,11 +528,6 @@ public void decompressResource() { // pass } - @RedirectMasterRole - public void redirectResource() { - // pass - } - private void mockElapsed(long elapsed) { Mockito.when(this.requestContext.getProperty(PathFilter.REQUEST_TIME)) .thenReturn(System.currentTimeMillis() - elapsed);