Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions hugegraph-api/src/main/java/com/baidu/hugegraph/api/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ public class API {
public static final String ACTION_ELIMINATE = "eliminate";
public static final String ACTION_CLEAR = "clear";

private static final Meter succeedMeter =
private static final Meter SUCCEED_METER =
MetricsUtil.registerMeter(API.class, "commit-succeed");
private static final Meter illegalArgErrorMeter =
private static final Meter ILLEGAL_ARG_ERROR_METER =
MetricsUtil.registerMeter(API.class, "illegal-arg");
private static final Meter expectedErrorMeter =
private static final Meter EXPECTED_ERROR_METER =
MetricsUtil.registerMeter(API.class, "expected-error");
private static final Meter unknownErrorMeter =
private static final Meter UNKNOWN_ERROR_METER =
MetricsUtil.registerMeter(API.class, "unknown-error");

public static HugeGraph graph(GraphManager manager, String graph) {
Expand Down Expand Up @@ -96,19 +96,19 @@ public static <R> R commit(HugeGraph g, Callable<R> callable) {
try {
R result = callable.call();
g.tx().commit();
succeedMeter.mark();
SUCCEED_METER.mark();
return result;
} catch (IllegalArgumentException | NotFoundException |
ForbiddenException e) {
illegalArgErrorMeter.mark();
ILLEGAL_ARG_ERROR_METER.mark();
rollback.accept(null);
throw e;
} catch (RuntimeException e) {
expectedErrorMeter.mark();
EXPECTED_ERROR_METER.mark();
rollback.accept(e);
throw e;
} catch (Throwable e) {
unknownErrorMeter.mark();
UNKNOWN_ERROR_METER.mark();
rollback.accept(e);
// TODO: throw the origin exception 'e'
throw new HugeException("Failed to commit", e);
Expand Down Expand Up @@ -171,7 +171,9 @@ protected static Map<String, Object> parseProperties(String properties) {
Map<String, Object> props = null;
try {
props = JsonUtil.fromJson(properties, Map.class);
} catch (Exception ignored) {}
} catch (Exception ignored) {
// ignore
}

// If properties is the string "null", props will be null
E.checkArgument(props != null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public void delete(@Context GraphManager manager,
throw new IllegalArgumentException("Invalid project id: " + id);
}
}

public static boolean isAddGraph(String action) {
return ACTION_ADD_GRAPH.equals(action);
}
Expand Down Expand Up @@ -267,6 +268,6 @@ public void checkUpdate() {
this.description != null,
"Must specify 'graphs' or 'description' " +
"field that need to be updated");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public class BatchAPI extends API {
private static final Logger LOG = Log.logger(BatchAPI.class);

// NOTE: VertexAPI and EdgeAPI should share a counter
private static final AtomicInteger batchWriteThreads = new AtomicInteger(0);
private static final AtomicInteger BATCH_WRITE_THREADS = new AtomicInteger(0);

static {
MetricsUtil.registerGauge(RestServer.class, "batch-write-threads",
() -> batchWriteThreads.intValue());
() -> BATCH_WRITE_THREADS.intValue());
}

private final Meter batchMeter;
Expand All @@ -64,24 +64,24 @@ public BatchAPI() {
public <R> R commit(HugeConfig config, HugeGraph g, int size,
Callable<R> callable) {
int maxWriteThreads = config.get(ServerOptions.MAX_WRITE_THREADS);
int writingThreads = batchWriteThreads.incrementAndGet();
int writingThreads = BATCH_WRITE_THREADS.incrementAndGet();
if (writingThreads > maxWriteThreads) {
batchWriteThreads.decrementAndGet();
BATCH_WRITE_THREADS.decrementAndGet();
throw new HugeException("The rest server is too busy to write");
}

LOG.debug("The batch writing threads is {}", batchWriteThreads);
LOG.debug("The batch writing threads is {}", BATCH_WRITE_THREADS);
try {
R result = commit(g, callable);
this.batchMeter.mark(size);
return result;
} finally {
batchWriteThreads.decrementAndGet();
BATCH_WRITE_THREADS.decrementAndGet();
}
}

@JsonIgnoreProperties(value = {"type"})
protected static abstract class JsonElement implements Checkable {
protected abstract static class JsonElement implements Checkable {

@JsonProperty("id")
public Object id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
@Singleton
public class GremlinAPI extends API {

private static final Histogram gremlinInputHistogram =
private static final Histogram GREMLIN_INPUT_HISTOGRAM =
MetricsUtil.registerHistogram(GremlinAPI.class, "gremlin-input");
private static final Histogram gremlinOutputHistogram =
private static final Histogram GREMLIN_OUTPUT_HISTOGRAM =
MetricsUtil.registerHistogram(GremlinAPI.class, "gremlin-output");

private static final Set<String> FORBIDDEN_REQUEST_EXCEPTIONS =
Expand Down Expand Up @@ -100,14 +100,14 @@ public Response post(@Context HugeConfig conf,
// .build();
String auth = headers.getHeaderString(HttpHeaders.AUTHORIZATION);
Response response = this.client().doPostRequest(auth, request);
gremlinInputHistogram.update(request.length());
gremlinOutputHistogram.update(response.getLength());
GREMLIN_INPUT_HISTOGRAM.update(request.length());
GREMLIN_OUTPUT_HISTOGRAM.update(response.getLength());
return transformResponseIfNeeded(response);
}

@GET
@Timed
@Compress(buffer=(1024 * 40))
@Compress(buffer = (1024 * 40))
@Produces(APPLICATION_JSON_WITH_CHARSET)
public Response get(@Context HugeConfig conf,
@Context HttpHeaders headers,
Expand All @@ -116,8 +116,8 @@ public Response get(@Context HugeConfig conf,
String query = uriInfo.getRequestUri().getRawQuery();
MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
Response response = this.client().doGetRequest(auth, params);
gremlinInputHistogram.update(query.length());
gremlinOutputHistogram.update(response.getLength());
GREMLIN_INPUT_HISTOGRAM.update(query.length());
GREMLIN_OUTPUT_HISTOGRAM.update(response.getLength());
return transformResponseIfNeeded(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class GremlinAPI extends API {

private static final int MAX_NAME_LENGTH = 256;

private static final Histogram gremlinJobInputHistogram =
private static final Histogram GREMLIN_JOB_INPUT_HISTOGRAM =
MetricsUtil.registerHistogram(GremlinAPI.class, "gremlin-input");

@POST
Expand All @@ -79,7 +79,7 @@ public Map<String, Id> post(@Context GraphManager manager,
GremlinRequest request) {
LOG.debug("Graph [{}] schedule gremlin job: {}", graph, request);
checkCreatingBody(request);
gremlinJobInputHistogram.update(request.gremlin.length());
GREMLIN_JOB_INPUT_HISTOGRAM.update(request.gremlin.length());

HugeGraph g = graph(manager, graph);
request.aliase(graph, "graph");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public String update(@Context GraphManager manager,

HugeGraph g = graph(manager, graph);
IndexLabel.Builder builder = jsonIndexLabel.convert2Builder(g);
IndexLabel IndexLabel = append ? builder.append() : builder.eliminate();
return manager.serializer(g).writeIndexlabel(mapIndexLabel(IndexLabel));
IndexLabel indexLabel = append ? builder.append() : builder.eliminate();
return manager.serializer(g).writeIndexlabel(mapIndexLabel(indexLabel));
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public interface HugeAuthenticator extends Authenticator {

public UserWithRole authenticate(String username, String password,
String token);

public AuthManager authManager();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public final class HugeFactoryAuthProxy {
private static final Set<String> PROTECT_METHODS = ImmutableSet.of(
"instance");

private static final Map<HugeGraph, HugeGraph> graphs = new HashMap<>();
private static final Map<HugeGraph, HugeGraph> GRAPHS = new HashMap<>();

static {
HugeGraphAuthProxy.setContext(HugeGraphAuthProxy.Context.admin());
Expand All @@ -81,10 +81,10 @@ public static synchronized HugeGraph open(Configuration config) {
* TODO: Add verify to StandardHugeGraph() to prevent dynamic creation
*/
HugeGraph graph = HugeFactory.open(config);
HugeGraph proxy = graphs.get(graph);
HugeGraph proxy = GRAPHS.get(graph);
if (proxy == null) {
proxy = new HugeGraphAuthProxy(graph);
graphs.put(graph, proxy);
GRAPHS.put(graph, proxy);
}
return proxy;
}
Expand Down Expand Up @@ -120,16 +120,16 @@ private static void registerPrivateActions() {
Reflection.registerFieldsToFilter(com.baidu.hugegraph.auth.HugeGraphAuthProxy.ContextTask.class, "runner", "context");
Reflection.registerFieldsToFilter(com.baidu.hugegraph.StandardHugeGraph.class, "LOG", "started", "closed", "mode", "variables", "name", "params", "configuration", "schemaEventHub", "graphEventHub", "indexEventHub", "writeRateLimiter", "readRateLimiter", "taskManager", "authManager", "features", "storeProvider", "tx", "ramtable", "$assertionsDisabled");
Reflection.registerMethodsToFilter(com.baidu.hugegraph.StandardHugeGraph.class, "lambda$0", "access$3", "access$4", "access$2", "access$5", "access$6", "access$7", "waitUntilAllTasksCompleted", "access$8", "loadStoreProvider", "graphTransaction", "schemaTransaction", "openSchemaTransaction", "checkGraphNotClosed", "openSystemTransaction", "openGraphTransaction", "systemTransaction", "access$9", "access$10", "access$11", "access$12", "access$13", "access$14", "access$15", "access$16", "access$17", "access$18", "serializer", "loadSchemaStore", "loadSystemStore", "loadGraphStore", "closeTx", "analyzer", "serverInfoManager", "reloadRamtable", "reloadRamtable", "access$19", "access$20", "access$21");
Reflection.registerFieldsToFilter(c("com.baidu.hugegraph.StandardHugeGraph$StandardHugeGraphParams"), "graph", "this$0");
Reflection.registerMethodsToFilter(c("com.baidu.hugegraph.StandardHugeGraph$StandardHugeGraphParams"), "access$1", "graph");
Reflection.registerFieldsToFilter(c("com.baidu.hugegraph.StandardHugeGraph$TinkerPopTransaction"), "refs", "opened", "transactions", "this$0", "$assertionsDisabled");
Reflection.registerMethodsToFilter(c("com.baidu.hugegraph.StandardHugeGraph$TinkerPopTransaction"), "lambda$0", "access$3", "access$2", "lambda$1", "graphTransaction", "schemaTransaction", "systemTransaction", "access$1", "setOpened", "doCommit", "verifyOpened", "doRollback", "doClose", "destroyTransaction", "doOpen", "setClosed", "getOrNewTransaction", "access$0", "resetState");
Reflection.registerFieldsToFilter(loadClass("com.baidu.hugegraph.StandardHugeGraph$StandardHugeGraphParams"), "graph", "this$0");
Reflection.registerMethodsToFilter(loadClass("com.baidu.hugegraph.StandardHugeGraph$StandardHugeGraphParams"), "access$1", "graph");
Reflection.registerFieldsToFilter(loadClass("com.baidu.hugegraph.StandardHugeGraph$TinkerPopTransaction"), "refs", "opened", "transactions", "this$0", "$assertionsDisabled");
Reflection.registerMethodsToFilter(loadClass("com.baidu.hugegraph.StandardHugeGraph$TinkerPopTransaction"), "lambda$0", "access$3", "access$2", "lambda$1", "graphTransaction", "schemaTransaction", "systemTransaction", "access$1", "setOpened", "doCommit", "verifyOpened", "doRollback", "doClose", "destroyTransaction", "doOpen", "setClosed", "getOrNewTransaction", "access$0", "resetState");
Reflection.registerFieldsToFilter(org.apache.tinkerpop.gremlin.structure.util.AbstractThreadLocalTransaction.class, "readWriteConsumerInternal", "closeConsumerInternal", "transactionListeners");
Reflection.registerMethodsToFilter(org.apache.tinkerpop.gremlin.structure.util.AbstractThreadLocalTransaction.class, "doClose", "fireOnCommit", "fireOnRollback", "doReadWrite", "lambda$fireOnRollback$1", "lambda$fireOnCommit$0");
Reflection.registerFieldsToFilter(org.apache.tinkerpop.gremlin.structure.util.AbstractTransaction.class, "g");
Reflection.registerMethodsToFilter(org.apache.tinkerpop.gremlin.structure.util.AbstractTransaction.class, "doCommit", "doRollback", "doClose", "doOpen", "fireOnCommit", "fireOnRollback", "doReadWrite");
Reflection.registerFieldsToFilter(c("com.baidu.hugegraph.StandardHugeGraph$Txs"), "schemaTx", "systemTx", "graphTx", "openedTime", "$assertionsDisabled");
Reflection.registerMethodsToFilter(c("com.baidu.hugegraph.StandardHugeGraph$Txs"), "access$2", "access$1", "access$0");
Reflection.registerFieldsToFilter(loadClass("com.baidu.hugegraph.StandardHugeGraph$Txs"), "schemaTx", "systemTx", "graphTx", "openedTime", "$assertionsDisabled");
Reflection.registerMethodsToFilter(loadClass("com.baidu.hugegraph.StandardHugeGraph$Txs"), "access$2", "access$1", "access$0");
Reflection.registerFieldsToFilter(com.baidu.hugegraph.backend.tx.GraphTransaction.class, "indexTx", "addedVertices", "removedVertices", "addedEdges", "removedEdges", "addedProps", "removedProps", "updatedVertices", "updatedEdges", "updatedOldestProps", "locksTable", "checkCustomVertexExist", "checkAdjacentVertexExist", "lazyLoadAdjacentVertex", "ignoreInvalidEntry", "commitPartOfAdjacentEdges", "batchSize", "pageSize", "verticesCapacity", "edgesCapacity", "$assertionsDisabled", "$SWITCH_TABLE$com$baidu$hugegraph$type$define$IdStrategy");
Reflection.registerMethodsToFilter(com.baidu.hugegraph.backend.tx.GraphTransaction.class, "lambda$0", "lambda$1", "lambda$2", "lambda$3", "lambda$4", "lambda$5", "lambda$6", "lambda$7", "lambda$8", "lambda$9", "lambda$10", "lambda$11", "lambda$12", "lambda$13", "lambda$14", "lambda$15", "lambda$16", "lambda$17", "lambda$18", "lambda$19", "access$1", "$SWITCH_TABLE$com$baidu$hugegraph$type$define$IdStrategy", "indexTransaction", "indexTransaction", "beforeWrite", "prepareCommit", "verticesInTxSize", "edgesInTxSize", "checkTxVerticesCapacity", "checkTxEdgesCapacity", "verticesInTxUpdated", "verticesInTxRemoved", "removingEdgeOwner", "prepareDeletions", "prepareDeletions", "prepareUpdates", "prepareAdditions", "checkVertexExistIfCustomizedId", "checkAggregateProperty", "checkAggregateProperty", "checkNonnullProperty", "queryEdgesFromBackend", "commitPartOfEdgeDeletions", "optimizeQueries", "checkVertexLabel", "checkId", "queryVerticesFromBackend", "joinTxVertices", "joinTxEdges", "lockForUpdateProperty", "optimizeQuery", "verifyVerticesConditionQuery", "verifyEdgesConditionQuery", "indexQuery", "joinTxRecords", "propertyUpdated", "parseEntry", "traverseByLabel", "reset", "queryVerticesByIds", "filterUnmatchedRecords", "skipOffsetOrStopLimit", "filterExpiredResultFromFromBackend", "queryEdgesByIds", "matchEdgeSortKeys", "rightResultFromIndexQuery");
Reflection.registerFieldsToFilter(com.baidu.hugegraph.backend.tx.IndexableTransaction.class, "$assertionsDisabled");
Expand Down Expand Up @@ -321,7 +321,7 @@ private static boolean registerClass(Class<?> clazz,
return true;
}

private static Class<?> c(String clazz) {
private static Class<?> loadClass(String clazz) {
try {
return Class.forName(clazz);
} catch (ClassNotFoundException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import jakarta.ws.rs.NotAuthorizedException;

import org.apache.commons.configuration2.Configuration;
import org.apache.groovy.json.internal.MapItemValue;
import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
import org.apache.tinkerpop.gremlin.process.traversal.Bytecode.Instruction;
Expand Down Expand Up @@ -1749,17 +1748,17 @@ public String toString() {
}
}

private static final ThreadLocal<Context> contexts =
private static final ThreadLocal<Context> CONTEXTS =
new InheritableThreadLocal<>();

protected static final Context setContext(Context context) {
Context old = contexts.get();
contexts.set(context);
Context old = CONTEXTS.get();
CONTEXTS.set(context);
return old;
}

protected static final void resetContext() {
contexts.remove();
CONTEXTS.remove();
}

protected static final Context getContext() {
Expand All @@ -1770,7 +1769,7 @@ protected static final Context getContext() {
return new Context(user);
}

return contexts.get();
return CONTEXTS.get();
}

protected static final String getContextString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private LicenseVerifier() {

public static LicenseVerifier instance() {
if (INSTANCE == null) {
synchronized(LicenseVerifier.class) {
synchronized (LicenseVerifier.class) {
if (INSTANCE == null) {
INSTANCE = new LicenseVerifier();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,27 @@

public class MetricsUtil {

private static final MetricRegistry registry =
private static final MetricRegistry REGISTRY =
MetricManager.INSTANCE.getRegistry();

public static <T> Gauge<T> registerGauge(Class<?> clazz, String name,
Gauge<T> gauge) {
return registry.register(MetricRegistry.name(clazz, name), gauge);
return REGISTRY.register(MetricRegistry.name(clazz, name), gauge);
}

public static Counter registerCounter(Class<?> clazz, String name) {
return registry.counter(MetricRegistry.name(clazz, name));
return REGISTRY.counter(MetricRegistry.name(clazz, name));
}

public static Histogram registerHistogram(Class<?> clazz, String name) {
return registry.histogram(MetricRegistry.name(clazz, name));
return REGISTRY.histogram(MetricRegistry.name(clazz, name));
}

public static Meter registerMeter(Class<?> clazz, String name) {
return registry.meter(MetricRegistry.name(clazz, name));
return REGISTRY.meter(MetricRegistry.name(clazz, name));
}

public static Timer registerTimer(Class<?> clazz, String name) {
return registry.timer(MetricRegistry.name(clazz, name));
return REGISTRY.timer(MetricRegistry.name(clazz, name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ private class GraphManagerFactory extends AbstractBinder

public GraphManagerFactory(HugeConfig conf, EventHub hub) {
register(new ApplicationEventListener() {
private final ApplicationEvent.Type EVENT_INITED =
private final ApplicationEvent.Type eventInited =
ApplicationEvent.Type.INITIALIZATION_FINISHED;
private final ApplicationEvent.Type EVENT_DESTROYED =
private final ApplicationEvent.Type eventDestroyed =
ApplicationEvent.Type.DESTROY_FINISHED;

@Override
public void onEvent(ApplicationEvent event) {
if (event.getType() == this.EVENT_INITED) {
if (event.getType() == this.eventInited) {
GraphManagerFactory.this.manager = new GraphManager(conf, hub);
} else if (event.getType() == this.EVENT_DESTROYED) {
} else if (event.getType() == this.eventDestroyed) {
if (GraphManagerFactory.this.manager != null) {
GraphManagerFactory.this.manager.close();
}
Expand Down