From 163df9fc2205140aff1d134b83497a7266fd7f5d Mon Sep 17 00:00:00 2001 From: seagle Date: Fri, 3 Jun 2022 15:26:51 +0800 Subject: [PATCH 1/9] add redundant --- .../baidu/hugegraph/analyzer/Analyzer.java | 2 +- .../baidu/hugegraph/backend/Transaction.java | 10 ++-- .../baidu/hugegraph/backend/cache/Cache.java | 46 +++++++++--------- .../backend/cache/CacheNotifier.java | 12 ++--- .../backend/cache/CachedGraphTransaction.java | 8 ++-- .../cache/CachedSchemaTransaction.java | 14 +++--- .../hugegraph/backend/cache/OffheapCache.java | 6 +-- .../com/baidu/hugegraph/backend/id/Id.java | 24 +++++----- .../hugegraph/backend/page/QueryList.java | 6 +-- .../hugegraph/backend/query/Aggregate.java | 4 +- .../backend/query/ConditionQuery.java | 4 +- .../baidu/hugegraph/backend/query/Query.java | 2 +- .../backend/store/BackendFeatures.java | 48 +++++++++---------- .../backend/store/BackendMetrics.java | 30 ++++++------ .../backend/store/raft/RaftGroupManager.java | 14 +++--- .../hugegraph/backend/store/ram/RamMap.java | 8 ++-- .../java/com/baidu/hugegraph/job/Job.java | 4 +- .../hugegraph/job/computer/Computer.java | 8 ++-- .../hugegraph/plugin/HugeGraphPlugin.java | 16 +++---- .../rpc/RpcServiceConfig4Client.java | 10 ++-- .../rpc/RpcServiceConfig4Server.java | 8 ++-- .../schema/builder/SchemaBuilder.java | 16 +++---- .../traversal/algorithm/records/Records.java | 12 ++--- .../algorithm/records/record/Record.java | 12 ++--- .../algorithm/strategy/TraverseStrategy.java | 20 ++++---- .../traversal/optimize/QueryHolder.java | 20 ++++---- .../com/baidu/hugegraph/type/Idfiable.java | 2 +- .../com/baidu/hugegraph/type/Indexable.java | 2 +- .../com/baidu/hugegraph/type/Nameable.java | 2 +- .../baidu/hugegraph/type/Propertiable.java | 2 +- .../com/baidu/hugegraph/type/Typeable.java | 2 +- .../hugegraph/type/define/GraphMode.java | 2 +- .../hugegraph/type/define/GraphReadMode.java | 2 +- .../baidu/hugegraph/type/define/NodeRole.java | 2 +- .../com/baidu/hugegraph/util/RateLimiter.java | 8 ++-- .../util/collection/IntIterator.java | 28 +++++------ .../hugegraph/util/collection/IntMap.java | 12 ++--- .../hugegraph/util/collection/IntSet.java | 28 +++++------ .../util/collection/ObjectIntMapping.java | 6 +-- .../backend/store/hbase/HbaseSessions.java | 32 ++++++------- style/checkstyle.xml | 1 + 41 files changed, 247 insertions(+), 248 deletions(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/analyzer/Analyzer.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/analyzer/Analyzer.java index 52ce194eed..8cc1372219 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/analyzer/Analyzer.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/analyzer/Analyzer.java @@ -23,5 +23,5 @@ public interface Analyzer { - public Set segment(String text); + Set segment(String text); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/Transaction.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/Transaction.java index b3c066b1ec..bbf20a2b38 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/Transaction.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/Transaction.java @@ -21,13 +21,13 @@ public interface Transaction { - public void commit() throws BackendException; + void commit() throws BackendException; - public void commitIfGtSize(int size) throws BackendException; + void commitIfGtSize(int size) throws BackendException; - public void rollback() throws BackendException; + void rollback() throws BackendException; - public boolean autoCommit(); + boolean autoCommit(); - public void close(); + void close(); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/Cache.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/Cache.java index 7212a4b7f4..580e57f565 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/Cache.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/Cache.java @@ -24,48 +24,48 @@ public interface Cache { - public static final String ACTION_INVALID = "invalid"; - public static final String ACTION_CLEAR = "clear"; - public static final String ACTION_INVALIDED = "invalided"; - public static final String ACTION_CLEARED = "cleared"; + String ACTION_INVALID = "invalid"; + String ACTION_CLEAR = "clear"; + String ACTION_INVALIDED = "invalided"; + String ACTION_CLEARED = "cleared"; - public V get(K id); + V get(K id); - public V getOrFetch(K id, Function fetcher); + V getOrFetch(K id, Function fetcher); - public boolean containsKey(K id); + boolean containsKey(K id); - public boolean update(K id, V value); + boolean update(K id, V value); - public boolean update(K id, V value, long timeOffset); + boolean update(K id, V value, long timeOffset); - public boolean updateIfAbsent(K id, V value); + boolean updateIfAbsent(K id, V value); - public boolean updateIfPresent(K id, V value); + boolean updateIfPresent(K id, V value); - public void invalidate(K id); + void invalidate(K id); - public void traverse(Consumer consumer); + void traverse(Consumer consumer); - public void clear(); + void clear(); - public void expire(long ms); + void expire(long ms); - public long expire(); + long expire(); - public long tick(); + long tick(); - public long capacity(); + long capacity(); - public long size(); + long size(); - public boolean enableMetrics(boolean enabled); + boolean enableMetrics(boolean enabled); - public long hits(); + long hits(); - public long miss(); + long miss(); - public T attachment(T object); + T attachment(T object); public T attachment(); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CacheNotifier.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CacheNotifier.java index 39154807a0..784d8e6917 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CacheNotifier.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CacheNotifier.java @@ -24,15 +24,15 @@ public interface CacheNotifier extends AutoCloseable { - public void invalid(HugeType type, Id id); + void invalid(HugeType type, Id id); - public void invalid2(HugeType type, Object[] ids); + void invalid2(HugeType type, Object[] ids); - public void clear(HugeType type); + void clear(HugeType type); - public void reload(); + void reload(); - public interface GraphCacheNotifier extends CacheNotifier {} + interface GraphCacheNotifier extends CacheNotifier {} - public interface SchemaCacheNotifier extends CacheNotifier {} + interface SchemaCacheNotifier extends CacheNotifier {} } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedGraphTransaction.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedGraphTransaction.java index fa397862f4..d7b2fcb436 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedGraphTransaction.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedGraphTransaction.java @@ -230,7 +230,7 @@ private boolean needCacheVertex(HugeVertex vertex) { @Override @Watched(prefix = "graphcache") - protected final Iterator queryVerticesFromBackend(Query query) { + protected Iterator queryVerticesFromBackend(Query query) { if (this.enableCacheVertex() && query.idsSize() > 0 && query.conditionsSize() == 0) { return this.queryVerticesByIds((IdQuery) query); @@ -302,7 +302,7 @@ private Iterator queryVerticesByIds(IdQuery query) { @Override @Watched(prefix = "graphcache") - protected final Iterator queryEdgesFromBackend(Query query) { + protected Iterator queryEdgesFromBackend(Query query) { RamTable ramtable = this.params().ramtable(); if (ramtable != null && ramtable.matched(query)) { return ramtable.query(query); @@ -357,7 +357,7 @@ protected final Iterator queryEdgesFromBackend(Query query) { @Override @Watched(prefix = "graphcache") - protected final void commitMutation2Backend(BackendMutation... mutations) { + protected void commitMutation2Backend(BackendMutation... mutations) { // Collect changes before commit Collection updates = this.verticesInTxUpdated(); Collection deletions = this.verticesInTxRemoved(); @@ -409,7 +409,7 @@ protected final void commitMutation2Backend(BackendMutation... mutations) { } @Override - public final void removeIndex(IndexLabel indexLabel) { + public void removeIndex(IndexLabel indexLabel) { try { super.removeIndex(indexLabel); } finally { diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedSchemaTransaction.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedSchemaTransaction.java index 0e7a55328c..3e52f8fbfe 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedSchemaTransaction.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedSchemaTransaction.java @@ -136,17 +136,17 @@ private void unlistenChanges() { schemaEventHub.unlisten(Events.CACHE, this.cacheEventListener); } - private final void notifyChanges(String action, HugeType type, Id id) { + private void notifyChanges(String action, HugeType type, Id id) { EventHub graphEventHub = this.params().schemaEventHub(); graphEventHub.notify(Events.CACHE, action, type, id); } - private final void resetCachedAll(HugeType type) { + private void resetCachedAll(HugeType type) { // Set the cache all flag of the schema type to false this.cachedTypes().put(type, false); } - private final void resetCachedAllIfReachedCapacity() { + private void resetCachedAllIfReachedCapacity() { if (this.idCache.size() >= this.idCache.capacity()) { LOG.warn("Schema cache reached capacity({}): {}", this.idCache.capacity(), this.idCache.size()); @@ -154,11 +154,11 @@ private final void resetCachedAllIfReachedCapacity() { } } - private final CachedTypes cachedTypes() { + private CachedTypes cachedTypes() { return this.arrayCaches.cachedTypes(); } - private final void clearCache(boolean notify) { + private void clearCache(boolean notify) { this.idCache.clear(); this.nameCache.clear(); this.arrayCaches.clear(); @@ -168,7 +168,7 @@ private final void clearCache(boolean notify) { } } - private final void updateCache(SchemaElement schema) { + private void updateCache(SchemaElement schema) { this.resetCachedAllIfReachedCapacity(); // update id cache @@ -183,7 +183,7 @@ private final void updateCache(SchemaElement schema) { this.arrayCaches.updateIfNeeded(schema); } - private final void invalidateCache(HugeType type, Id id) { + private void invalidateCache(HugeType type, Id id) { // remove from id cache and name cache Id prefixedId = generateId(type, id); Object value = this.idCache.get(prefixedId); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/OffheapCache.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/OffheapCache.java index 993809750b..cc3ccf05c9 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/OffheapCache.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/OffheapCache.java @@ -346,7 +346,7 @@ private HugeException unsupported(Object value) { } } - private static enum ValueType { + private enum ValueType { UNKNOWN, LIST, @@ -365,11 +365,11 @@ private static enum ValueType { private DataType dataType; - private ValueType() { + ValueType() { this(DataType.UNKNOWN); } - private ValueType(DataType dataType) { + ValueType(DataType dataType) { this.dataType = dataType; } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/Id.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/Id.java index 78afad4823..06cf053cfe 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/Id.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/Id.java @@ -23,37 +23,37 @@ public interface Id extends Comparable { - public static final int UUID_LENGTH = 16; + int UUID_LENGTH = 16; - public Object asObject(); + Object asObject(); - public String asString(); + String asString(); - public long asLong(); + long asLong(); - public byte[] asBytes(); + byte[] asBytes(); - public int length(); + int length(); - public IdType type(); + IdType type(); - public default boolean number() { + default boolean number() { return this.type() == IdType.LONG; } - public default boolean uuid() { + default boolean uuid() { return this.type() == IdType.UUID; } - public default boolean string() { + default boolean string() { return this.type() == IdType.STRING; } - public default boolean edge() { + default boolean edge() { return this.type() == IdType.EDGE; } - public enum IdType { + enum IdType { UNKNOWN, LONG, diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/page/QueryList.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/page/QueryList.java index 4e20945863..a72ef072d5 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/page/QueryList.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/page/QueryList.java @@ -130,7 +130,7 @@ private interface FlattenQuery { * For non-paging situation * @return BackendEntry iterator */ - public QueryResults iterator(); + QueryResults iterator(); /** * For paging situation @@ -139,9 +139,9 @@ private interface FlattenQuery { * @param pageSize set query page size * @return BackendEntry iterator with page */ - public PageResults iterator(int index, String page, long pageSize); + PageResults iterator(int index, String page, long pageSize); - public int total(); + int total(); } /** diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Aggregate.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Aggregate.java index a9a0439a1e..b30f7df1e0 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Aggregate.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Aggregate.java @@ -60,7 +60,7 @@ public String toString() { this.column == null ? "*" : this.column); } - public static enum AggregateFunc { + public enum AggregateFunc { COUNT("count", 0L, NumberHelper::add), MAX("max", -Double.MAX_VALUE, NumberHelper::max), @@ -72,7 +72,7 @@ public static enum AggregateFunc { private final Number defaultValue; private final BiFunction merger; - private AggregateFunc(String name, Number defaultValue, + AggregateFunc(String name, Number defaultValue, BiFunction merger) { this.name = name; this.defaultValue = defaultValue; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java index 7deb444bc2..6ccfbc025d 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java @@ -875,8 +875,8 @@ public Id indexField() { } } - public static interface ResultsFilter { + public interface ResultsFilter { - public boolean test(HugeElement element); + boolean test(HugeElement element); } } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Query.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Query.java index 49e1fd8f41..397b313b52 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Query.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Query.java @@ -577,7 +577,7 @@ public static final void checkForceCapacity(long count) } } - public static enum Order { + public enum Order { ASC, DESC; } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendFeatures.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendFeatures.java index cef6523e36..c1dac27803 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendFeatures.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendFeatures.java @@ -21,57 +21,57 @@ public interface BackendFeatures { - public default boolean supportsPersistence() { + default boolean supportsPersistence() { return true; } - public default boolean supportsSharedStorage() { + default boolean supportsSharedStorage() { return true; } - public default boolean supportsSnapshot() { + default boolean supportsSnapshot() { return false; } - public boolean supportsScanToken(); + boolean supportsScanToken(); - public boolean supportsScanKeyPrefix(); + boolean supportsScanKeyPrefix(); - public boolean supportsScanKeyRange(); + boolean supportsScanKeyRange(); - public boolean supportsQuerySchemaByName(); + boolean supportsQuerySchemaByName(); - public boolean supportsQueryByLabel(); + boolean supportsQueryByLabel(); - public boolean supportsQueryWithInCondition(); + boolean supportsQueryWithInCondition(); - public boolean supportsQueryWithRangeCondition(); + boolean supportsQueryWithRangeCondition(); - public boolean supportsQueryWithContains(); + boolean supportsQueryWithContains(); - public boolean supportsQueryWithContainsKey(); + boolean supportsQueryWithContainsKey(); - public boolean supportsQueryWithOrderBy(); + boolean supportsQueryWithOrderBy(); - public boolean supportsQueryByPage(); + boolean supportsQueryByPage(); - public boolean supportsQuerySortByInputIds(); + boolean supportsQuerySortByInputIds(); - public boolean supportsDeleteEdgeByLabel(); + boolean supportsDeleteEdgeByLabel(); - public boolean supportsUpdateVertexProperty(); + boolean supportsUpdateVertexProperty(); - public boolean supportsMergeVertexProperty(); + boolean supportsMergeVertexProperty(); - public boolean supportsUpdateEdgeProperty(); + boolean supportsUpdateEdgeProperty(); - public boolean supportsTransaction(); + boolean supportsTransaction(); - public boolean supportsNumberType(); + boolean supportsNumberType(); - public boolean supportsAggregateProperty(); + boolean supportsAggregateProperty(); - public boolean supportsTtl(); + boolean supportsTtl(); - public boolean supportsOlapProperties(); + boolean supportsOlapProperties(); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendMetrics.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendMetrics.java index e621c2e440..1a103f154f 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendMetrics.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendMetrics.java @@ -23,27 +23,27 @@ public interface BackendMetrics { - public String BACKEND = "backend"; + String BACKEND = "backend"; - public String NODES = "nodes"; - public String CLUSTER_ID = "cluster_id"; - public String SERVERS = "servers"; - public String SERVER_LOCAL = "local"; - public String SERVER_CLUSTER = "cluster"; + String NODES = "nodes"; + String CLUSTER_ID = "cluster_id"; + String SERVERS = "servers"; + String SERVER_LOCAL = "local"; + String SERVER_CLUSTER = "cluster"; // Memory related metrics - public String MEM_USED = "mem_used"; - public String MEM_COMMITTED = "mem_committed"; - public String MEM_MAX = "mem_max"; - public String MEM_UNIT = "mem_unit"; + String MEM_USED = "mem_used"; + String MEM_COMMITTED = "mem_committed"; + String MEM_MAX = "mem_max"; + String MEM_UNIT = "mem_unit"; // Data load related metrics - public String DISK_USAGE = "disk_usage"; - public String DISK_UNIT = "disk_unit"; + String DISK_USAGE = "disk_usage"; + String DISK_UNIT = "disk_unit"; - public String READABLE = "_readable"; + String READABLE = "_readable"; - public String EXCEPTION = "exception"; + String EXCEPTION = "exception"; - public Map metrics(); + Map metrics(); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/raft/RaftGroupManager.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/raft/RaftGroupManager.java index c15ca4e89d..7a786863bd 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/raft/RaftGroupManager.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/raft/RaftGroupManager.java @@ -23,17 +23,17 @@ public interface RaftGroupManager { - public String group(); + String group(); - public List listPeers(); + List listPeers(); - public String getLeader(); + String getLeader(); - public String transferLeaderTo(String endpoint); + String transferLeaderTo(String endpoint); - public String setLeader(String endpoint); + String setLeader(String endpoint); - public String addPeer(String endpoint); + String addPeer(String endpoint); - public String removePeer(String endpoint); + String removePeer(String endpoint); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/RamMap.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/RamMap.java index 62c72a4c0c..456f97e58d 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/RamMap.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/RamMap.java @@ -25,11 +25,11 @@ public interface RamMap { - public void clear(); + void clear(); - public long size(); + long size(); - public void writeTo(DataOutputStream buffer) throws IOException; + void writeTo(DataOutputStream buffer) throws IOException; - public void readFrom(DataInputStream buffer) throws IOException; + void readFrom(DataInputStream buffer) throws IOException; } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/Job.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/Job.java index 3b7063d4b5..32325a96f9 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/Job.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/Job.java @@ -21,7 +21,7 @@ public interface Job { - public String type(); + String type(); - public V execute() throws Exception; + V execute() throws Exception; } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/computer/Computer.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/computer/Computer.java index 5d9521754e..f735796593 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/computer/Computer.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/computer/Computer.java @@ -25,11 +25,11 @@ public interface Computer { - public String name(); + String name(); - public String category(); + String category(); - public Object call(Job job, Map parameters); + Object call(Job job, Map parameters); - public void checkParameters(Map parameters); + void checkParameters(Map parameters); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/plugin/HugeGraphPlugin.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/plugin/HugeGraphPlugin.java index c0897eab8e..742e56ef46 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/plugin/HugeGraphPlugin.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/plugin/HugeGraphPlugin.java @@ -26,27 +26,27 @@ public interface HugeGraphPlugin { - public String name(); + String name(); - public void register(); + void register(); - public String supportsMinVersion(); + String supportsMinVersion(); - public String supportsMaxVersion(); + String supportsMaxVersion(); - public static void registerOptions(String name, String classPath) { + static void registerOptions(String name, String classPath) { OptionSpace.register(name, classPath); } - public static void registerBackend(String name, String classPath) { + static void registerBackend(String name, String classPath) { BackendProviderFactory.register(name, classPath); } - public static void registerSerializer(String name, String classPath) { + static void registerSerializer(String name, String classPath) { SerializerFactory.register(name, classPath); } - public static void registerAnalyzer(String name, String classPath) { + static void registerAnalyzer(String name, String classPath) { AnalyzerFactory.register(name, classPath); } } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/rpc/RpcServiceConfig4Client.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/rpc/RpcServiceConfig4Client.java index 13cfca96f0..0833980d9d 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/rpc/RpcServiceConfig4Client.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/rpc/RpcServiceConfig4Client.java @@ -21,17 +21,17 @@ public interface RpcServiceConfig4Client { - public T serviceProxy(String interfaceId); + T serviceProxy(String interfaceId); - public T serviceProxy(String graph, String interfaceId); + T serviceProxy(String graph, String interfaceId); - public default T serviceProxy(Class clazz) { + default T serviceProxy(Class clazz) { return this.serviceProxy(clazz.getName()); } - public default T serviceProxy(String graph, Class clazz) { + default T serviceProxy(String graph, Class clazz) { return this.serviceProxy(graph, clazz.getName()); } - public void removeAllServiceProxy(); + void removeAllServiceProxy(); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/rpc/RpcServiceConfig4Server.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/rpc/RpcServiceConfig4Server.java index 7139073cf3..2a9c14454c 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/rpc/RpcServiceConfig4Server.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/rpc/RpcServiceConfig4Server.java @@ -21,12 +21,12 @@ public interface RpcServiceConfig4Server { - public String addService(Class clazz, S serviceImpl); + String addService(Class clazz, S serviceImpl); - public String addService(String graph, + String addService(String graph, Class clazz, S serviceImpl); - public void removeService(String serviceId); + void removeService(String serviceId); - public void removeAllService(); + void removeAllService(); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/SchemaBuilder.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/SchemaBuilder.java index 8f0b74e78f..f09d4644a5 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/SchemaBuilder.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/SchemaBuilder.java @@ -24,19 +24,19 @@ public interface SchemaBuilder { - public SchemaBuilder id(long id); + SchemaBuilder id(long id); - public T build(); + T build(); - public T create(); + T create(); - public T append(); + T append(); - public T eliminate(); + T eliminate(); - public Id remove(); + Id remove(); - public SchemaBuilder ifNotExist(); + SchemaBuilder ifNotExist(); - public SchemaBuilder checkExist(boolean checkExist); + SchemaBuilder checkExist(boolean checkExist); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/records/Records.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/records/Records.java index 405ed933eb..183d6c19a9 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/records/Records.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/records/Records.java @@ -26,16 +26,16 @@ public interface Records { - public void startOneLayer(boolean forward); + void startOneLayer(boolean forward); - public void finishOneLayer(); + void finishOneLayer(); - public boolean hasNextKey(); + boolean hasNextKey(); - public Id nextKey(); + Id nextKey(); - public PathSet findPath(Id target, Function filter, + PathSet findPath(Id target, Function filter, boolean all, boolean ring); - public long accessed(); + long accessed(); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/records/record/Record.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/records/record/Record.java index f138243fe4..0f50fa7b1a 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/records/record/Record.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/records/record/Record.java @@ -23,15 +23,15 @@ public interface Record { - public IntIterator keys(); + IntIterator keys(); - public boolean containsKey(int node); + boolean containsKey(int node); - public IntIterator get(int node); + IntIterator get(int node); - public void addPath(int node, int parent); + void addPath(int node, int parent); - public int size(); + int size(); - public boolean concurrent(); + boolean concurrent(); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/strategy/TraverseStrategy.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/strategy/TraverseStrategy.java index 9bfc2759ba..9d69e5cb5a 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/strategy/TraverseStrategy.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/strategy/TraverseStrategy.java @@ -31,22 +31,20 @@ public interface TraverseStrategy { - public abstract void traverseOneLayer( - Map> vertices, - EdgeStep step, BiConsumer consumer); + void traverseOneLayer(Map> vertices, + EdgeStep step, BiConsumer consumer); - public abstract Map> newMultiValueMap(); + Map> newMultiValueMap(); - public abstract Set newPathSet(); + Set newPathSet(); - public abstract void addNode(Map> vertices, - Id id, HugeTraverser.Node node); + void addNode(Map> vertices, Id id, + HugeTraverser.Node node); - public abstract void addNewVerticesToAll( - Map> newVertices, - Map> targets); + void addNewVerticesToAll(Map> newVertices, + Map> targets); - public static TraverseStrategy create(boolean concurrent, HugeGraph graph) { + static TraverseStrategy create(boolean concurrent, HugeGraph graph) { return concurrent ? new ConcurrentTraverseStrategy(graph) : new SingleTraverseStrategy(graph); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/QueryHolder.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/QueryHolder.java index 4cb3442545..7584e4c554 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/QueryHolder.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/QueryHolder.java @@ -30,12 +30,12 @@ public interface QueryHolder extends HasContainerHolder, Metadatable { - public static final String SYSPROP_PAGE = "~page"; + String SYSPROP_PAGE = "~page"; - public Iterator lastTimeResults(); + Iterator lastTimeResults(); @Override - public default Object metadata(String meta, Object... args) { + default Object metadata(String meta, Object... args) { Iterator results = this.lastTimeResults(); if (results instanceof Metadatable) { return ((Metadatable) results).metadata(meta, args); @@ -43,30 +43,30 @@ public default Object metadata(String meta, Object... args) { throw new IllegalStateException("Original results is not Metadatable"); } - public Query queryInfo(); + Query queryInfo(); - public default void orderBy(String key, Order order) { + default void orderBy(String key, Order order) { this.queryInfo().order(TraversalUtil.string2HugeKey(key), TraversalUtil.convOrder(order)); } - public default long setRange(long start, long end) { + default long setRange(long start, long end) { return this.queryInfo().range(start, end); } - public default void setPage(String page) { + default void setPage(String page) { this.queryInfo().page(page); } - public default void setCount() { + default void setCount() { this.queryInfo().capacity(Query.NO_CAPACITY); } - public default void setAggregate(AggregateFunc func, String key) { + default void setAggregate(AggregateFunc func, String key) { this.queryInfo().aggregate(func, key); } - public default Q injectQueryInfo(Q query) { + default Q injectQueryInfo(Q query) { query.copyBasic(this.queryInfo()); return query; } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/Idfiable.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/Idfiable.java index 62e40c0879..d2ab141e82 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/Idfiable.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/Idfiable.java @@ -23,5 +23,5 @@ public interface Idfiable { - public Id id(); + Id id(); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/Indexable.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/Indexable.java index 6085e52353..08cb386f92 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/Indexable.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/Indexable.java @@ -25,5 +25,5 @@ public interface Indexable { - public Set indexLabels(); + Set indexLabels(); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/Nameable.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/Nameable.java index 8d4ba418c2..eb8e474e4f 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/Nameable.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/Nameable.java @@ -25,6 +25,6 @@ public interface Nameable { * * @return Name of this entity. */ - public String name(); + String name(); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/Propertiable.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/Propertiable.java index 666633b1a7..4ca8df77b2 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/Propertiable.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/Propertiable.java @@ -25,5 +25,5 @@ public interface Propertiable { - public Set properties(); + Set properties(); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/Typeable.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/Typeable.java index c807857327..fb569fd027 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/Typeable.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/Typeable.java @@ -22,5 +22,5 @@ public interface Typeable { // Return schema/data type - public HugeType type(); + HugeType type(); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/GraphMode.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/GraphMode.java index 97e5d143ae..906051fe51 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/GraphMode.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/GraphMode.java @@ -50,7 +50,7 @@ public enum GraphMode { private final byte code; private final String name; - private GraphMode(int code, String name) { + GraphMode(int code, String name) { assert code < 256; this.code = (byte) code; this.name = name; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/GraphReadMode.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/GraphReadMode.java index 5fe85368eb..6c1b70d7ed 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/GraphReadMode.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/GraphReadMode.java @@ -30,7 +30,7 @@ public enum GraphReadMode { private final byte code; private final String name; - private GraphReadMode(int code, String name) { + GraphReadMode(int code, String name) { assert code < 256; this.code = (byte) code; this.name = name; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/NodeRole.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/NodeRole.java index 645854dc44..c824b022a9 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/NodeRole.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/NodeRole.java @@ -30,7 +30,7 @@ public enum NodeRole implements SerialEnum { private final byte code; private final String name; - private NodeRole(int code, String name) { + NodeRole(int code, String name) { assert code < 256; this.code = (byte) code; this.name = name; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/RateLimiter.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/RateLimiter.java index a1bd4952d2..f25b12138c 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/RateLimiter.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/RateLimiter.java @@ -24,15 +24,15 @@ // TODO: Move to common module (concurrent package) public interface RateLimiter { - public final Logger LOG = Log.logger(RateLimiter.class); + Logger LOG = Log.logger(RateLimiter.class); - public final long RESET_PERIOD = 1000L; + long RESET_PERIOD = 1000L; /** * Acquires one permit from RateLimiter if it can be acquired immediately * without delay. */ - public boolean tryAcquire(); + boolean tryAcquire(); /** * Create a RateLimiter with specified rate, to keep compatible with @@ -43,7 +43,7 @@ public interface RateLimiter { * * TODO: refactor it to make method unchangeable */ - public static RateLimiter create(double ratePerSecond) { + static RateLimiter create(double ratePerSecond) { return new FixedTimerWindowRateLimiter((int) ratePerSecond); } } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntIterator.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntIterator.java index 7f9f52f2f3..9e1f0480b1 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntIterator.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntIterator.java @@ -26,14 +26,14 @@ public interface IntIterator { - public final int[] EMPTY_INTS = new int[0]; - public final IntIterator EMPTY = new EmptyIntIterator(); + int[] EMPTY_INTS = new int[0]; + IntIterator EMPTY = new EmptyIntIterator(); - public boolean hasNext(); + boolean hasNext(); - public int next(); + int next(); - public default Iterator asIterator() { + default Iterator asIterator() { return new Iterator() { @Override @@ -48,20 +48,20 @@ public Integer next() { }; } - public static IntIterator wrap( + static IntIterator wrap( org.eclipse.collections.api.iterator.IntIterator iter) { return new EcIntIterator(iter); } - public static IntIterator wrap(int[] values) { + static IntIterator wrap(int[] values) { return new ArrayIntIterator(values); } - public static IntIterator wrap(int value) { + static IntIterator wrap(int value) { return new ArrayIntIterator(new int[]{value}); } - public final class EcIntIterator implements IntIterator { + final class EcIntIterator implements IntIterator { private final org.eclipse.collections.api.iterator.IntIterator iterator; @@ -81,7 +81,7 @@ public boolean hasNext() { } } - public final class ArrayIntIterator implements IntIterator { + final class ArrayIntIterator implements IntIterator { private final int[] array; private int index; @@ -102,7 +102,7 @@ public boolean hasNext() { } } - public final class EmptyIntIterator implements IntIterator { + final class EmptyIntIterator implements IntIterator { @Override public boolean hasNext() { @@ -115,7 +115,7 @@ public int next() { } } - public final class IntIterators implements IntIterator { + final class IntIterators implements IntIterator { private final List iters; private int currentIndex; @@ -158,7 +158,7 @@ public int next() { } } - public final class MapperInt2IntIterator implements IntIterator { + final class MapperInt2IntIterator implements IntIterator { private final IntIterator originIter; private final IntMapper intMapper; @@ -184,7 +184,7 @@ public interface IntMapper { } } - public final class MapperInt2ObjectIterator implements Iterator { + final class MapperInt2ObjectIterator implements Iterator { private final IntIterator originIter; private final IntMapper intMapper; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntMap.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntMap.java index 3bd5a14199..edd31eed2d 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntMap.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntMap.java @@ -199,7 +199,7 @@ public boolean concurrent() { return true; } - private final IntMap segment(int key) { + private IntMap segment(int key) { long ukey = key + this.unsignedSize; if (ukey >= this.capacity || ukey < 0L) { E.checkArgument(false, @@ -233,7 +233,7 @@ private final IntMap segment(int key) { } } - private final IntMap segmentAt(int index) { + private IntMap segmentAt(int index) { // volatile get this.maps[index] long offset = (index << SHIFT) + BASE_OFFSET; IntMap map = (IntMap) UNSAFE.getObjectVolatile(this.maps, offset); @@ -247,7 +247,7 @@ private final IntMap segmentAt(int index) { * - faster 8x than ec IntIntHashMap for 4 threads, 4x operations * with 0.5x cost; */ - public static final class IntMapByFixedAddr implements IntMap { + final class IntMapByFixedAddr implements IntMap { private final int[] values; private final int capacity; @@ -509,7 +509,7 @@ public int next() { } } - public static final class IntMapByEcSegment implements IntMap { + final class IntMapByEcSegment implements IntMap { private final MutableIntIntMap[] maps; private final int segmentMask; @@ -597,6 +597,6 @@ public boolean concurrent() { } } - public static final int NULL_VALUE = Integer.MIN_VALUE; - public static final Unsafe UNSAFE = IntSet.UNSAFE; + int NULL_VALUE = Integer.MIN_VALUE; + Unsafe UNSAFE = IntSet.UNSAFE; } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntSet.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntSet.java index 5a070f1ea9..bdfee99032 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntSet.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntSet.java @@ -201,7 +201,7 @@ private final IntSet segmentAt(int index) { * - faster 20x than ec IntIntHashSet-segment-lock for 4 threads; * - faster 60x than ec IntIntHashSet-global-lock for 4 threads; */ - public static final class IntSetByFixedAddr implements IntSet { + final class IntSetByFixedAddr implements IntSet { private final long[] bits; private final long numBits; @@ -284,7 +284,7 @@ public boolean concurrent() { return true; } - private final long offset(long key) { + private long offset(long key) { long ukey = key + this.numBitsUnsigned; if (ukey >= this.numBits || ukey < 0L) { E.checkArgument(false, "The key %s is out of bound %s", @@ -294,7 +294,7 @@ private final long offset(long key) { } } - public static final class IntSetByFixedAddr4Unsigned implements IntSet { + final class IntSetByFixedAddr4Unsigned implements IntSet { private final long[] bits; private final int numBits; @@ -422,7 +422,7 @@ public int nextKey(int key) { return key; } - private final long offset(int key) { + private long offset(int key) { if (key >= this.numBits || key < 0) { E.checkArgument(false, "The key %s is out of bound %s", key, this.numBits); @@ -447,7 +447,7 @@ private static final long bitmaskOfKey(long key) { } } - public static final class IntSetByEcSegment implements IntSet { + final class IntSetByEcSegment implements IntSet { private final MutableIntCollection[] sets; private final int segmentMask; @@ -467,7 +467,7 @@ public IntSetByEcSegment(int segments) { } } - private final MutableIntCollection set(int key) { + private MutableIntCollection set(int key) { // NOTE '%' is slower 20% ~ 50% than '&': key % this.sets.length; int index = key & this.segmentMask; return this.sets[index]; @@ -510,7 +510,7 @@ public boolean concurrent() { } } - public static final class IntSetByFixedAddrByHppc implements IntSet { + final class IntSetByFixedAddrByHppc implements IntSet { private final com.carrotsearch.hppc.BitSet bits; @@ -551,13 +551,13 @@ public boolean concurrent() { } } - public static final int CPUS = Runtime.getRuntime().availableProcessors(); - public static final sun.misc.Unsafe UNSAFE = UnsafeAccess.UNSAFE; + int CPUS = Runtime.getRuntime().availableProcessors(); + sun.misc.Unsafe UNSAFE = UnsafeAccess.UNSAFE; - public static final long MOD64 = 0x3fL; - public static final int DIV64 = 6; + long MOD64 = 0x3fL; + int DIV64 = 6; - public static int segmentSize(long capacity, int segments) { + static int segmentSize(long capacity, int segments) { long eachSize = capacity / segments; eachSize = IntSet.sizeToPowerOf2Size((int) eachSize); /* @@ -571,7 +571,7 @@ public static int segmentSize(long capacity, int segments) { return (int) eachSize; } - public static int sizeToPowerOf2Size(int size) { + static int sizeToPowerOf2Size(int size) { if (size < 1) { size = 1; } @@ -587,7 +587,7 @@ public static int sizeToPowerOf2Size(int size) { return size; } - public static int bits2words(long numBits) { + static int bits2words(long numBits) { return (int) ((numBits - 1) >>> DIV64) + 1; } } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/ObjectIntMapping.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/ObjectIntMapping.java index 21737092df..072439b80e 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/ObjectIntMapping.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/ObjectIntMapping.java @@ -21,9 +21,9 @@ public interface ObjectIntMapping { - public int object2Code(Object object); + int object2Code(Object object); - public V code2Object(int code); + V code2Object(int code); - public void clear(); + void clear(); } diff --git a/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java b/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java index 35d8e051c5..b56c06d1a0 100644 --- a/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java +++ b/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java @@ -331,19 +331,19 @@ public interface HbaseSession { /** * Add a row record to a table */ - public abstract void put(String table, byte[] family, byte[] rowkey, + void put(String table, byte[] family, byte[] rowkey, Collection columns); /** * Add a row record to a table(can be used when adding an index) */ - public abstract void put(String table, byte[] family, + void put(String table, byte[] family, byte[] rowkey, byte[] qualifier, byte[] value); /** * Delete a record by rowkey and qualifier from a table */ - public default void remove(String table, byte[] family, + default void remove(String table, byte[] family, byte[] rowkey, byte[] qualifier) { this.remove(table, family, rowkey, qualifier, false); } @@ -352,34 +352,34 @@ public default void remove(String table, byte[] family, * Delete a record by rowkey and qualifier from a table, * just delete the latest version of the specified column if need */ - public void remove(String table, byte[] family, byte[] rowkey, + void remove(String table, byte[] family, byte[] rowkey, byte[] qualifier, boolean latestVersion); /** * Delete a record by rowkey from a table */ - public void delete(String table, byte[] family, byte[] rowkey); + void delete(String table, byte[] family, byte[] rowkey); /** * Get a record by rowkey and qualifier from a table */ - public R get(String table, byte[] family, byte[] rowkey, + R get(String table, byte[] family, byte[] rowkey, byte[] qualifier); /** * Get a record by rowkey from a table */ - public R get(String table, byte[] family, byte[] rowkey); + R get(String table, byte[] family, byte[] rowkey); /** * Get multi records by rowkeys from a table */ - public R get(String table, byte[] family, Set rowkeys); + R get(String table, byte[] family, Set rowkeys); /** * Scan all records from a table */ - public default R scan(String table, long limit) { + default R scan(String table, long limit) { Scan scan = new Scan(); if (limit >= 0) { scan.setFilter(new PageFilter(limit)); @@ -390,14 +390,14 @@ public default R scan(String table, long limit) { /** * Scan records by rowkey prefix from a table */ - public default R scan(String table, byte[] prefix) { + default R scan(String table, byte[] prefix) { return this.scan(table, prefix, true, prefix); } /** * Scan records by multi rowkey prefixes from a table */ - public default R scan(String table, Set prefixes) { + default R scan(String table, Set prefixes) { FilterList orFilters = new FilterList(Operator.MUST_PASS_ONE); for (byte[] prefix : prefixes) { FilterList andFilters = new FilterList(Operator.MUST_PASS_ALL); @@ -416,7 +416,7 @@ public default R scan(String table, Set prefixes) { /** * Scan records by rowkey start and prefix from a table */ - public default R scan(String table, byte[] startRow, + default R scan(String table, byte[] startRow, boolean inclusiveStart, byte[] prefix) { Scan scan = new Scan().withStartRow(startRow, inclusiveStart) .setFilter(new PrefixFilter(prefix)); @@ -426,14 +426,14 @@ public default R scan(String table, byte[] startRow, /** * Scan records by rowkey range from a table */ - public default R scan(String table, byte[] startRow, byte[] stopRow) { + default R scan(String table, byte[] startRow, byte[] stopRow) { return this.scan(table, startRow, true, stopRow, false); } /** * Scan records by rowkey range from a table */ - public default R scan(String table, + default R scan(String table, byte[] startRow, boolean inclusiveStart, byte[] stopRow, boolean inclusiveStop) { Scan scan = new Scan().withStartRow(startRow, inclusiveStart); @@ -446,12 +446,12 @@ public default R scan(String table, /** * Inner scan: send scan request to HBase and get iterator */ - public R scan(String table, Scan scan); + R scan(String table, Scan scan); /** * Increase a counter by rowkey and qualifier to a table */ - public long increase(String table, byte[] family, + long increase(String table, byte[] family, byte[] rowkey, byte[] qualifier, long value); } diff --git a/style/checkstyle.xml b/style/checkstyle.xml index acc4c40d95..bd62d3e63b 100644 --- a/style/checkstyle.xml +++ b/style/checkstyle.xml @@ -36,6 +36,7 @@ + From 02f0207ac5aa31ad319e84db4cb62eb45f835802 Mon Sep 17 00:00:00 2001 From: seagle Date: Sun, 5 Jun 2022 15:47:03 +0800 Subject: [PATCH 2/9] add redundant check --- .../baidu/hugegraph/api/auth/AccessAPI.java | 1 - .../hugegraph/api/gremlin/CypherAPI.java | 11 ++- .../hugegraph/api/gremlin/GremlinAPI.java | 11 --- .../api/traversers/JaccardSimilarityAPI.java | 4 +- .../hugegraph/auth/HugeAuthenticator.java | 68 +++++++++---------- .../hugegraph/auth/HugeGraphAuthProxy.java | 10 +-- .../auth/WsAndHttpBasicAuthHandler.java | 6 +- .../com/baidu/hugegraph/define/Checkable.java | 4 +- .../hugegraph/serializer/Serializer.java | 50 +++++++------- .../baidu/hugegraph/backend/cache/Cache.java | 2 +- .../hugegraph/backend/id/IdGenerator.java | 2 +- .../store/AbstractBackendStoreProvider.java | 1 - .../com/baidu/hugegraph/task/TaskManager.java | 6 +- .../util/collection/IntIterator.java | 4 +- .../hugegraph/util/collection/IntMap.java | 4 +- .../hugegraph/util/collection/IntSet.java | 8 +-- .../backend/store/hbase/HbaseStore.java | 2 +- .../store/rocksdb/RocksDBSessions.java | 2 +- .../backend/store/rocksdb/RocksDBStore.java | 12 ++-- .../baidu/hugegraph/unit/UnitTestSuite.java | 1 - style/checkstyle.xml | 5 +- 21 files changed, 101 insertions(+), 113 deletions(-) diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/AccessAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/AccessAPI.java index ee14855d40..8843b260ea 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/AccessAPI.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/AccessAPI.java @@ -21,7 +21,6 @@ import java.util.List; -import io.swagger.annotations.Api; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.ws.rs.Consumes; import jakarta.ws.rs.DELETE; diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/gremlin/CypherAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/gremlin/CypherAPI.java index 15a0ca1884..d3626a259e 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/gremlin/CypherAPI.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/gremlin/CypherAPI.java @@ -28,7 +28,6 @@ public class CypherAPI extends GremlinQueryAPI { private static final Logger LOG = Log.logger(CypherAPI.class); - @GET @Timed @CompressInterceptor.Compress(buffer = (1024 * 40)) @@ -63,11 +62,11 @@ private Response queryByCypher(String graph, LOG.debug("translated gremlin is {}", gremlin); String auth = headers.getHeaderString(HttpHeaders.AUTHORIZATION); - String request = "{" - + "\"gremlin\":\"" + gremlin + "\"," - + "\"bindings\":{}," - + "\"language\":\"gremlin-groovy\"," - + "\"aliases\":{\"g\":\"__g_" + graph + "\"}}"; + String request = "{" + + "\"gremlin\":\"" + gremlin + "\"," + + "\"bindings\":{}," + + "\"language\":\"gremlin-groovy\"," + + "\"aliases\":{\"g\":\"__g_" + graph + "\"}}"; Response response = this.client().doPostRequest(auth, request); return transformResponseIfNeeded(response); diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/gremlin/GremlinAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/gremlin/GremlinAPI.java index 8f1e8504a9..f1283f8f59 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/gremlin/GremlinAPI.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/gremlin/GremlinAPI.java @@ -19,9 +19,6 @@ package com.baidu.hugegraph.api.gremlin; -import java.util.Map; -import java.util.Set; - import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.ws.rs.Consumes; import jakarta.ws.rs.GET; @@ -30,22 +27,15 @@ import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.Context; import jakarta.ws.rs.core.HttpHeaders; -import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.MultivaluedMap; import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.UriInfo; -import com.baidu.hugegraph.api.API; import com.baidu.hugegraph.api.filter.CompressInterceptor.Compress; import com.baidu.hugegraph.config.HugeConfig; -import com.baidu.hugegraph.config.ServerOptions; -import com.baidu.hugegraph.exception.HugeGremlinException; import com.baidu.hugegraph.metrics.MetricsUtil; import com.codahale.metrics.Histogram; import com.codahale.metrics.annotation.Timed; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import jakarta.inject.Provider; import jakarta.inject.Singleton; @Path("gremlin") @@ -58,7 +48,6 @@ public class GremlinAPI extends GremlinQueryAPI { private static final Histogram GREMLIN_OUTPUT_HISTOGRAM = MetricsUtil.registerHistogram(GremlinAPI.class, "gremlin-output"); - @POST @Timed @Compress diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/JaccardSimilarityAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/JaccardSimilarityAPI.java index 48ae1efd7e..c723b20302 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/JaccardSimilarityAPI.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/JaccardSimilarityAPI.java @@ -86,8 +86,8 @@ public String get(@Context GraphManager manager, double similarity; try (JaccardSimilarTraverser traverser = new JaccardSimilarTraverser(g)) { - similarity = traverser.jaccardSimilarity(sourceId, targetId, dir, - edgeLabel, maxDegree); + similarity = traverser.jaccardSimilarity(sourceId, targetId, dir, + edgeLabel, maxDegree); } return JsonUtil.toJson(ImmutableMap.of("jaccard_similarity", similarity)); diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeAuthenticator.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeAuthenticator.java index b6369b3552..8bfe1f5461 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeAuthenticator.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeAuthenticator.java @@ -43,36 +43,36 @@ public interface HugeAuthenticator extends Authenticator { - public static final String KEY_USERNAME = - CredentialGraphTokens.PROPERTY_USERNAME; - public static final String KEY_PASSWORD = - CredentialGraphTokens.PROPERTY_PASSWORD; - public static final String KEY_TOKEN = "token"; - public static final String KEY_ROLE = "role"; - public static final String KEY_ADDRESS = "address"; - public static final String KEY_PATH = "path"; - - public static final String USER_SYSTEM = "system"; - public static final String USER_ADMIN = "admin"; - public static final String USER_ANONY = AuthenticatedUser.ANONYMOUS_USERNAME; - - public static final RolePermission ROLE_NONE = RolePermission.none(); - public static final RolePermission ROLE_ADMIN = RolePermission.admin(); - - public static final String VAR_PREFIX = "$"; - public static final String KEY_OWNER = VAR_PREFIX + "owner"; - public static final String KEY_DYNAMIC = VAR_PREFIX + "dynamic"; - public static final String KEY_ACTION = VAR_PREFIX + "action"; - - public void setup(HugeConfig config); - - public UserWithRole authenticate(String username, String password, + String KEY_USERNAME = + CredentialGraphTokens.PROPERTY_USERNAME; + String KEY_PASSWORD = + CredentialGraphTokens.PROPERTY_PASSWORD; + String KEY_TOKEN = "token"; + String KEY_ROLE = "role"; + String KEY_ADDRESS = "address"; + String KEY_PATH = "path"; + + String USER_SYSTEM = "system"; + String USER_ADMIN = "admin"; + String USER_ANONY = AuthenticatedUser.ANONYMOUS_USERNAME; + + RolePermission ROLE_NONE = RolePermission.none(); + RolePermission ROLE_ADMIN = RolePermission.admin(); + + String VAR_PREFIX = "$"; + String KEY_OWNER = VAR_PREFIX + "owner"; + String KEY_DYNAMIC = VAR_PREFIX + "dynamic"; + String KEY_ACTION = VAR_PREFIX + "action"; + + void setup(HugeConfig config); + + UserWithRole authenticate(String username, String password, String token); - public AuthManager authManager(); + AuthManager authManager(); @Override - public default void setup(final Map config) { + default void setup(final Map config) { E.checkState(config != null, "Must provide a 'config' in the 'authentication'"); String path = (String) config.get("tokens"); @@ -83,7 +83,7 @@ public default void setup(final Map config) { } @Override - public default User authenticate(final Map credentials) + default User authenticate(final Map credentials) throws AuthenticationException { HugeGraphAuthProxy.resetContext(); @@ -115,11 +115,11 @@ public default User authenticate(final Map credentials) } @Override - public default boolean requireAuthentication() { + default boolean requireAuthentication() { return true; } - public default boolean verifyRole(RolePermission role) { + default boolean verifyRole(RolePermission role) { if (role == ROLE_NONE || role == null) { return false; } else { @@ -127,9 +127,9 @@ public default boolean verifyRole(RolePermission role) { } } - public void initAdminUser(String password) throws Exception; + void initAdminUser(String password) throws Exception; - public static HugeAuthenticator loadAuthenticator(HugeConfig conf) { + static HugeAuthenticator loadAuthenticator(HugeConfig conf) { String authClass = conf.get(ServerOptions.AUTHENTICATOR); if (authClass.isEmpty()) { return null; @@ -150,7 +150,7 @@ public static HugeAuthenticator loadAuthenticator(HugeConfig conf) { return authenticator; } - public static class User extends AuthenticatedUser { + class User extends AuthenticatedUser { public static final User ADMIN = new User(USER_ADMIN, ROLE_ADMIN); public static final User ANONYMOUS = new User(USER_ANONY, ROLE_ADMIN); @@ -255,7 +255,7 @@ public static class UserJson { } } - public static class RolePerm { + class RolePerm { @JsonProperty("roles") // graph -> action -> resource private Map> roles; @@ -395,7 +395,7 @@ public static boolean match(Object role, RolePermission grant, } } - public static class RequiredPerm { + class RequiredPerm { @JsonProperty("owner") private String owner; diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeGraphAuthProxy.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeGraphAuthProxy.java index d3efb5aa35..9b440137bb 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeGraphAuthProxy.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeGraphAuthProxy.java @@ -1764,17 +1764,17 @@ public String toString() { private static final ThreadLocal CONTEXTS = new InheritableThreadLocal<>(); - protected static final Context setContext(Context context) { + protected static Context setContext(Context context) { Context old = CONTEXTS.get(); CONTEXTS.set(context); return old; } - protected static final void resetContext() { + protected static void resetContext() { CONTEXTS.remove(); } - protected static final Context getContext() { + protected static Context getContext() { // Return task context first String taskContext = TaskManager.getContext(); User user = User.fromJson(taskContext); @@ -1785,7 +1785,7 @@ protected static final Context getContext() { return CONTEXTS.get(); } - protected static final String getContextString() { + protected static String getContextString() { Context context = getContext(); if (context == null) { return null; @@ -1793,7 +1793,7 @@ protected static final String getContextString() { return context.user().toJson(); } - protected static final void logUser(User user, String path) { + protected static void logUser(User user, String path) { LOG.info("User '{}' login from client [{}] with path '{}'", user.username(), user.client(), path); } diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/WsAndHttpBasicAuthHandler.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/WsAndHttpBasicAuthHandler.java index 514d8e03db..580173bd9e 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/WsAndHttpBasicAuthHandler.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/WsAndHttpBasicAuthHandler.java @@ -150,10 +150,10 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) { } } - private void sendError(ChannelHandlerContext ctx, Object msg) { + private void sendError(ChannelHandlerContext context, Object msg) { // Close the connection as soon as the error message is sent. - ctx.writeAndFlush(new DefaultFullHttpResponse(HTTP_1_1, UNAUTHORIZED)) - .addListener(ChannelFutureListener.CLOSE); + context.writeAndFlush(new DefaultFullHttpResponse(HTTP_1_1, UNAUTHORIZED)) + .addListener(ChannelFutureListener.CLOSE); ReferenceCountUtil.release(msg); } } diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/define/Checkable.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/define/Checkable.java index e4246955fb..71f1d43f73 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/define/Checkable.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/define/Checkable.java @@ -2,9 +2,9 @@ public interface Checkable { - public void checkCreate(boolean isBatch); + void checkCreate(boolean isBatch); - public default void checkUpdate() { + default void checkUpdate() { this.checkCreate(false); } } diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/Serializer.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/Serializer.java index a7544d0368..0adde9e31d 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/Serializer.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/Serializer.java @@ -42,65 +42,65 @@ public interface Serializer { - public String writeMap(Map map); + String writeMap(Map map); - public String writeList(String label, Collection list); + String writeList(String label, Collection list); - public String writePropertyKey(PropertyKey propertyKey); + String writePropertyKey(PropertyKey propertyKey); - public String writePropertyKeys(List propertyKeys); + String writePropertyKeys(List propertyKeys); - public String writeVertexLabel(VertexLabel vertexLabel); + String writeVertexLabel(VertexLabel vertexLabel); - public String writeVertexLabels(List vertexLabels); + String writeVertexLabels(List vertexLabels); - public String writeEdgeLabel(EdgeLabel edgeLabel); + String writeEdgeLabel(EdgeLabel edgeLabel); - public String writeEdgeLabels(List edgeLabels); + String writeEdgeLabels(List edgeLabels); - public String writeIndexlabel(IndexLabel indexLabel); + String writeIndexlabel(IndexLabel indexLabel); - public String writeIndexlabels(List indexLabels); + String writeIndexlabels(List indexLabels); - public String writeTaskWithSchema(SchemaElement.TaskWithSchema tws); + String writeTaskWithSchema(SchemaElement.TaskWithSchema tws); - public String writeVertex(Vertex v); + String writeVertex(Vertex v); - public String writeVertices(Iterator vertices, boolean paging); + String writeVertices(Iterator vertices, boolean paging); - public String writeEdge(Edge e); + String writeEdge(Edge e); - public String writeEdges(Iterator edges, boolean paging); + String writeEdges(Iterator edges, boolean paging); - public String writeIds(List ids); + String writeIds(List ids); - public String writeAuthElement(AuthElement elem); + String writeAuthElement(AuthElement elem); - public String writeAuthElements(String label, + String writeAuthElements(String label, List users); - public String writePaths(String name, Collection paths, + String writePaths(String name, Collection paths, boolean withCrossPoint, Iterator vertices); - public default String writePaths(String name, + default String writePaths(String name, Collection paths, boolean withCrossPoint) { return this.writePaths(name, paths, withCrossPoint, null); } - public String writeCrosspoints(CrosspointsPaths paths, + String writeCrosspoints(CrosspointsPaths paths, Iterator iterator, boolean withPath); - public String writeSimilars(SimilarsMap similars, + String writeSimilars(SimilarsMap similars, Iterator vertices); - public String writeWeightedPath(NodeWithWeight path, + String writeWeightedPath(NodeWithWeight path, Iterator vertices); - public String writeWeightedPaths(WeightedPaths paths, + String writeWeightedPaths(WeightedPaths paths, Iterator vertices); - public String writeNodesWithPath(String name, List nodes, long size, + String writeNodesWithPath(String name, List nodes, long size, Collection paths, Iterator vertices); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/Cache.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/Cache.java index 580e57f565..f7f98efcd7 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/Cache.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/Cache.java @@ -67,5 +67,5 @@ public interface Cache { T attachment(T object); - public T attachment(); + T attachment(); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/IdGenerator.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/IdGenerator.java index 3ab42ee77e..a6b0b829b1 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/IdGenerator.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/IdGenerator.java @@ -121,7 +121,7 @@ public static final IdType idType(Id id) { return IdType.UNKNOWN; } - private static final int compareType(Id id1, Id id2) { + private static int compareType(Id id1, Id id2) { return idType(id1).ordinal() - idType(id2).ordinal(); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/AbstractBackendStoreProvider.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/AbstractBackendStoreProvider.java index ed01b378c4..09fa316830 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/AbstractBackendStoreProvider.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/AbstractBackendStoreProvider.java @@ -26,7 +26,6 @@ import org.slf4j.Logger; import com.alipay.remoting.rpc.RpcServer; -import com.baidu.hugegraph.HugeGraph; import com.baidu.hugegraph.backend.BackendException; import com.baidu.hugegraph.backend.store.raft.StoreSnapshotFile; import com.baidu.hugegraph.config.CoreOptions; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskManager.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskManager.java index 8d9040fa64..723391e0bc 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskManager.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskManager.java @@ -324,15 +324,15 @@ private void scheduleOrExecuteJobForGraph(StandardTaskScheduler scheduler) { private static final ThreadLocal CONTEXTS = new ThreadLocal<>(); - protected static final void setContext(String context) { + protected static void setContext(String context) { CONTEXTS.set(context); } - protected static final void resetContext() { + protected static void resetContext() { CONTEXTS.remove(); } - public static final String getContext() { + public static String getContext() { return CONTEXTS.get(); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntIterator.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntIterator.java index 9e1f0480b1..e780dd56a6 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntIterator.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntIterator.java @@ -180,7 +180,7 @@ public int next() { public interface IntMapper { - public int map(int key); + int map(int key); } } @@ -207,7 +207,7 @@ public T next() { public interface IntMapper { - public T map(int key); + T map(int key); } } } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntMap.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntMap.java index edd31eed2d..5d624d5beb 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntMap.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntMap.java @@ -397,7 +397,7 @@ public boolean concurrent() { return true; } - private final long offset(int key) { + private long offset(int key) { if (key >= this.capacity || key < 0) { E.checkArgument(false, "The key %s is out of bound %s", key, this.capacity); @@ -529,7 +529,7 @@ public IntMapByEcSegment(int segments) { } } - private final MutableIntIntMap map(int key) { + private MutableIntIntMap map(int key) { // NOTE '%' is slower 20% ~ 50% than '&': key % this.maps.length; int index = key & this.segmentMask; return this.maps[index]; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntSet.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntSet.java index bdfee99032..82f56a0a64 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntSet.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/IntSet.java @@ -151,7 +151,7 @@ public boolean concurrent() { return true; } - private final IntSet segment(int key) { + private IntSet segment(int key) { long ukey = key + this.unsignedSize; if (ukey >= this.capacity || ukey < 0L) { E.checkArgument(false, @@ -185,7 +185,7 @@ private final IntSet segment(int key) { } } - private final IntSet segmentAt(int index) { + private IntSet segmentAt(int index) { // volatile get this.sets[index] long offset = (index << SHIFT) + BASE_OFFSET; IntSet set = (IntSet) UNSAFE.getObjectVolatile(this.sets, offset); @@ -430,7 +430,7 @@ private long offset(int key) { return bitOffsetToByteOffset(key); } - private static final long bitOffsetToByteOffset(long key) { + private static long bitOffsetToByteOffset(long key) { // bits to long offset long index = key >> DIV64; // long offset to byte offset @@ -440,7 +440,7 @@ private static final long bitOffsetToByteOffset(long key) { return offset; } - private static final long bitmaskOfKey(long key) { + private static long bitmaskOfKey(long key) { long bitIndex = key & MOD64; long bitmask = 1L << bitIndex; return bitmask; diff --git a/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseStore.java b/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseStore.java index 628048a5d7..791c0942d3 100644 --- a/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseStore.java +++ b/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseStore.java @@ -434,7 +434,7 @@ public void rollbackTx() { session.rollback(); } - private final void checkConnectionOpened() { + private void checkConnectionOpened() { E.checkState(this.sessions != null && this.sessions.opened(), "HBase store has not been initialized"); } diff --git a/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBSessions.java b/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBSessions.java index 2d56a35a08..ad74bc6abb 100644 --- a/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBSessions.java +++ b/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBSessions.java @@ -133,6 +133,6 @@ public static boolean matchScanType(int expected, int actual) { public interface Countable { - public long count(); + long count(); } } diff --git a/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBStore.java b/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBStore.java index cd14d3e6da..b0e34d9c88 100644 --- a/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBStore.java +++ b/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBStore.java @@ -781,13 +781,13 @@ public void resumeSnapshot(String snapshotPrefix, boolean deleteSnapshot) { } } - private final void useSessions() { + private void useSessions() { for (RocksDBSessions sessions : this.sessions()) { sessions.useSession(); } } - private final void closeSessions() { + private void closeSessions() { Iterator> iter = this.dbs.entrySet() .iterator(); while (iter.hasNext()) { @@ -800,7 +800,7 @@ private final void closeSessions() { } } - private final List session() { + private List session() { this.checkOpened(); if (this.tableDiskMapping.isEmpty()) { @@ -816,11 +816,11 @@ private final List session() { return list; } - private final Collection sessions() { + private Collection sessions() { return this.dbs.values(); } - private final void parseTableDiskMapping(Map disks, + private void parseTableDiskMapping(Map disks, String dataPath) { this.tableDiskMapping.clear(); for (Map.Entry disk : disks.entrySet()) { @@ -868,7 +868,7 @@ private String findDiskTableKeyByPath(String diskPath) { return diskTableKey; } - private final void checkDbOpened() { + private void checkDbOpened() { E.checkState(this.sessions != null && !this.sessions.closed(), "RocksDB has not been opened"); } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/UnitTestSuite.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/UnitTestSuite.java index fe8f0d14da..c95aaf6007 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/UnitTestSuite.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/UnitTestSuite.java @@ -66,7 +66,6 @@ import com.baidu.hugegraph.unit.serializer.TextBackendEntryTest; import com.baidu.hugegraph.unit.util.CompressUtilTest; import com.baidu.hugegraph.unit.util.JsonUtilTest; -import com.baidu.hugegraph.unit.util.RateLimiterTest; import com.baidu.hugegraph.unit.util.StringEncodingTest; import com.baidu.hugegraph.unit.util.VersionTest; import com.baidu.hugegraph.unit.util.collection.CollectionFactoryTest; diff --git a/style/checkstyle.xml b/style/checkstyle.xml index bd62d3e63b..6f6bf56815 100644 --- a/style/checkstyle.xml +++ b/style/checkstyle.xml @@ -36,7 +36,10 @@ - + + + From bfdf11a7f9a247d7e1eb0c855d10c9214dffb9cf Mon Sep 17 00:00:00 2001 From: seagle yuan Date: Sun, 5 Jun 2022 18:52:25 +0800 Subject: [PATCH 3/9] merge line --- .../com/baidu/hugegraph/auth/HugeAuthenticator.java | 9 +++------ .../com/baidu/hugegraph/serializer/Serializer.java | 12 ++++-------- .../com/baidu/hugegraph/backend/query/Aggregate.java | 2 +- .../java/com/baidu/hugegraph/util/RateLimiter.java | 2 -- .../hugegraph/backend/store/hbase/HbaseSessions.java | 3 +-- 5 files changed, 9 insertions(+), 19 deletions(-) diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeAuthenticator.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeAuthenticator.java index 8bfe1f5461..821312c835 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeAuthenticator.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeAuthenticator.java @@ -43,10 +43,8 @@ public interface HugeAuthenticator extends Authenticator { - String KEY_USERNAME = - CredentialGraphTokens.PROPERTY_USERNAME; - String KEY_PASSWORD = - CredentialGraphTokens.PROPERTY_PASSWORD; + String KEY_USERNAME = CredentialGraphTokens.PROPERTY_USERNAME; + String KEY_PASSWORD = CredentialGraphTokens.PROPERTY_PASSWORD; String KEY_TOKEN = "token"; String KEY_ROLE = "role"; String KEY_ADDRESS = "address"; @@ -66,8 +64,7 @@ public interface HugeAuthenticator extends Authenticator { void setup(HugeConfig config); - UserWithRole authenticate(String username, String password, - String token); + UserWithRole authenticate(String username, String password, String token); AuthManager authManager(); diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/Serializer.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/Serializer.java index 0adde9e31d..82deb103d2 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/Serializer.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/Serializer.java @@ -76,8 +76,7 @@ public interface Serializer { String writeAuthElement(AuthElement elem); - String writeAuthElements(String label, - List users); + String writeAuthElements(String label, List users); String writePaths(String name, Collection paths, boolean withCrossPoint, Iterator vertices); @@ -91,14 +90,11 @@ default String writePaths(String name, String writeCrosspoints(CrosspointsPaths paths, Iterator iterator, boolean withPath); - String writeSimilars(SimilarsMap similars, - Iterator vertices); + String writeSimilars(SimilarsMap similars, Iterator vertices); - String writeWeightedPath(NodeWithWeight path, - Iterator vertices); + String writeWeightedPath(NodeWithWeight path, Iterator vertices); - String writeWeightedPaths(WeightedPaths paths, - Iterator vertices); + String writeWeightedPaths(WeightedPaths paths, Iterator vertices); String writeNodesWithPath(String name, List nodes, long size, Collection paths, diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Aggregate.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Aggregate.java index b30f7df1e0..a5e5041e30 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Aggregate.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Aggregate.java @@ -73,7 +73,7 @@ public enum AggregateFunc { private final BiFunction merger; AggregateFunc(String name, Number defaultValue, - BiFunction merger) { + BiFunction merger) { this.name = name; this.defaultValue = defaultValue; this.merger = merger; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/RateLimiter.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/RateLimiter.java index f25b12138c..c2983da684 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/util/RateLimiter.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/util/RateLimiter.java @@ -24,8 +24,6 @@ // TODO: Move to common module (concurrent package) public interface RateLimiter { - Logger LOG = Log.logger(RateLimiter.class); - long RESET_PERIOD = 1000L; /** diff --git a/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java b/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java index b56c06d1a0..c73127f46f 100644 --- a/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java +++ b/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java @@ -331,8 +331,7 @@ public interface HbaseSession { /** * Add a row record to a table */ - void put(String table, byte[] family, byte[] rowkey, - Collection columns); + void put(String table, byte[] family, byte[] rowkey, Collection columns); /** * Add a row record to a table(can be used when adding an index) From 12b91c1380eb6dad3d1dcd0decbc7f595db156a3 Mon Sep 17 00:00:00 2001 From: seagle Date: Mon, 6 Jun 2022 14:28:19 +0800 Subject: [PATCH 4/9] update alignment --- .../hugegraph/auth/HugeAuthenticator.java | 3 +- .../hugegraph/serializer/Serializer.java | 15 +++++----- .../rpc/RpcServiceConfig4Server.java | 4 +-- .../traversal/algorithm/records/Records.java | 4 +-- .../backend/store/hbase/HbaseSessions.java | 28 +++++++++---------- .../backend/store/rocksdb/RocksDBStore.java | 3 +- 6 files changed, 29 insertions(+), 28 deletions(-) diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeAuthenticator.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeAuthenticator.java index 821312c835..88c5c78705 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeAuthenticator.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeAuthenticator.java @@ -81,7 +81,8 @@ default void setup(final Map config) { @Override default User authenticate(final Map credentials) - throws AuthenticationException { + throws AuthenticationException { + HugeGraphAuthProxy.resetContext(); User user = User.ANONYMOUS; diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/Serializer.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/Serializer.java index 82deb103d2..e5b1c1bcea 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/Serializer.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/Serializer.java @@ -79,16 +79,15 @@ public interface Serializer { String writeAuthElements(String label, List users); String writePaths(String name, Collection paths, - boolean withCrossPoint, Iterator vertices); + boolean withCrossPoint, Iterator vertices); - default String writePaths(String name, - Collection paths, - boolean withCrossPoint) { + default String writePaths(String name, Collection paths, + boolean withCrossPoint) { return this.writePaths(name, paths, withCrossPoint, null); } - String writeCrosspoints(CrosspointsPaths paths, - Iterator iterator, boolean withPath); + String writeCrosspoints(CrosspointsPaths paths, Iterator iterator, + boolean withPath); String writeSimilars(SimilarsMap similars, Iterator vertices); @@ -97,6 +96,6 @@ String writeCrosspoints(CrosspointsPaths paths, String writeWeightedPaths(WeightedPaths paths, Iterator vertices); String writeNodesWithPath(String name, List nodes, long size, - Collection paths, - Iterator vertices); + Collection paths, + Iterator vertices); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/rpc/RpcServiceConfig4Server.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/rpc/RpcServiceConfig4Server.java index 2a9c14454c..23541e3137 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/rpc/RpcServiceConfig4Server.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/rpc/RpcServiceConfig4Server.java @@ -23,8 +23,8 @@ public interface RpcServiceConfig4Server { String addService(Class clazz, S serviceImpl); - String addService(String graph, - Class clazz, S serviceImpl); + String addService(String graph, Class clazz, + S serviceImpl); void removeService(String serviceId); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/records/Records.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/records/Records.java index 183d6c19a9..d5444cd82c 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/records/Records.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/records/Records.java @@ -34,8 +34,8 @@ public interface Records { Id nextKey(); - PathSet findPath(Id target, Function filter, - boolean all, boolean ring); + PathSet findPath(Id target, Function filter, boolean all, + boolean ring); long accessed(); } diff --git a/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java b/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java index c73127f46f..0c8b13f366 100644 --- a/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java +++ b/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java @@ -331,19 +331,20 @@ public interface HbaseSession { /** * Add a row record to a table */ - void put(String table, byte[] family, byte[] rowkey, Collection columns); + void put(String table, byte[] family, byte[] rowkey, + Collection columns); /** * Add a row record to a table(can be used when adding an index) */ - void put(String table, byte[] family, - byte[] rowkey, byte[] qualifier, byte[] value); + void put(String table, byte[] family, byte[] rowkey, byte[] qualifier, + byte[] value); /** * Delete a record by rowkey and qualifier from a table */ - default void remove(String table, byte[] family, - byte[] rowkey, byte[] qualifier) { + default void remove(String table, byte[] family, byte[] rowkey, + byte[] qualifier) { this.remove(table, family, rowkey, qualifier, false); } @@ -352,7 +353,7 @@ default void remove(String table, byte[] family, * just delete the latest version of the specified column if need */ void remove(String table, byte[] family, byte[] rowkey, - byte[] qualifier, boolean latestVersion); + byte[] qualifier, boolean latestVersion); /** * Delete a record by rowkey from a table @@ -415,8 +416,8 @@ default R scan(String table, Set prefixes) { /** * Scan records by rowkey start and prefix from a table */ - default R scan(String table, byte[] startRow, - boolean inclusiveStart, byte[] prefix) { + default R scan(String table, byte[] startRow, boolean inclusiveStart, + byte[] prefix) { Scan scan = new Scan().withStartRow(startRow, inclusiveStart) .setFilter(new PrefixFilter(prefix)); return this.scan(table, scan); @@ -432,9 +433,8 @@ default R scan(String table, byte[] startRow, byte[] stopRow) { /** * Scan records by rowkey range from a table */ - default R scan(String table, - byte[] startRow, boolean inclusiveStart, - byte[] stopRow, boolean inclusiveStop) { + default R scan(String table, byte[] startRow, boolean inclusiveStart, + byte[] stopRow, boolean inclusiveStop) { Scan scan = new Scan().withStartRow(startRow, inclusiveStart); if (stopRow != null) { scan.withStopRow(stopRow, inclusiveStop); @@ -450,15 +450,15 @@ default R scan(String table, /** * Increase a counter by rowkey and qualifier to a table */ - long increase(String table, byte[] family, - byte[] rowkey, byte[] qualifier, long value); + long increase(String table, byte[] family, byte[] rowkey, + byte[] qualifier, long value); } /** * Session implement for HBase */ public class Session extends AbstractBackendSession - implements HbaseSession { + implements HbaseSession { private final Map> batch; diff --git a/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBStore.java b/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBStore.java index b0e34d9c88..ade30b9fb6 100644 --- a/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBStore.java +++ b/hugegraph-rocksdb/src/main/java/com/baidu/hugegraph/backend/store/rocksdb/RocksDBStore.java @@ -821,7 +821,8 @@ private Collection sessions() { } private void parseTableDiskMapping(Map disks, - String dataPath) { + String dataPath) { + this.tableDiskMapping.clear(); for (Map.Entry disk : disks.entrySet()) { // The format of `disk` like: `graph/vertex: /path/to/disk1` From 92a4bf0b69467919395b5cd93d1ab4f364d2d2eb Mon Sep 17 00:00:00 2001 From: seagle Date: Wed, 15 Jun 2022 21:07:59 +0800 Subject: [PATCH 5/9] delete duplicates check MissingSwitchDefault --- style/checkstyle.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/style/checkstyle.xml b/style/checkstyle.xml index 6f6bf56815..7ba1a4a75e 100644 --- a/style/checkstyle.xml +++ b/style/checkstyle.xml @@ -202,7 +202,6 @@ - From d3d7c796820d09cc497a2c13fd2973e20578c040 Mon Sep 17 00:00:00 2001 From: seagle Date: Wed, 15 Jun 2022 21:38:53 +0800 Subject: [PATCH 6/9] update wrap line --- .../backend/store/hbase/HbaseSessions.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java b/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java index 0c8b13f366..13c53ca5b0 100644 --- a/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java +++ b/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java @@ -220,7 +220,7 @@ public boolean existsTable(String table) throws IOException { public void createTable(String table, List cfs) throws IOException { TableDescriptorBuilder tdb = TableDescriptorBuilder.newBuilder( - TableName.valueOf(this.namespace, table)); + TableName.valueOf(this.namespace, table)); for (byte[] cf : cfs) { tdb.setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(cf) .build()); @@ -231,7 +231,7 @@ public void createTable(String table, List cfs) throws IOException { } } - public void createPreSplitTable(String table, List cfs, + public void createPreSplitTable(String table, List cfs, short numOfPartitions) throws IOException { TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder( TableName.valueOf(this.namespace, table)); @@ -239,7 +239,7 @@ public void createPreSplitTable(String table, List cfs, builder.setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(cf).build()); } byte[][] splits = new byte[numOfPartitions - 1] - [org.apache.hadoop.hbase.util.Bytes.SIZEOF_SHORT]; + [org.apache.hadoop.hbase.util.Bytes.SIZEOF_SHORT]; for (short split = 1; split < numOfPartitions; split++) { splits[split - 1] = org.apache.hadoop.hbase.util.Bytes.toBytes(split); } @@ -363,8 +363,7 @@ void remove(String table, byte[] family, byte[] rowkey, /** * Get a record by rowkey and qualifier from a table */ - R get(String table, byte[] family, byte[] rowkey, - byte[] qualifier); + R get(String table, byte[] family, byte[] rowkey, byte[] qualifier); /** * Get a record by rowkey from a table @@ -484,7 +483,7 @@ private int batchSize() { } private void checkBatchResults(Object[] results, List rows) - throws Throwable { + throws Throwable { assert rows.size() == results.length; for (int i = 0; i < results.length; i++) { Object result = results[i]; @@ -553,7 +552,7 @@ public Integer commit() { } catch (Throwable e) { // TODO: Mark and delete committed records throw new BackendException("Failed to commit, " + - "there may be inconsistent states for HBase", e); + "there may be inconsistent states for HBase", e); } } @@ -808,7 +807,7 @@ private void dump(String table, Scan scan) throws IOException { byte[] key = CellUtil.cloneQualifier(cell); byte[] val = CellUtil.cloneValue(cell); LOG.info(" {}={}", StringEncoding.format(key), - StringEncoding.format(val)); + StringEncoding.format(val)); } } } From ff82af06d11802593ca9f6d9991213a961ca894c Mon Sep 17 00:00:00 2001 From: seagle Date: Fri, 17 Jun 2022 09:40:06 +0800 Subject: [PATCH 7/9] update code style --- .../baidu/hugegraph/backend/store/hbase/HbaseSessions.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java b/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java index 13c53ca5b0..03d0d5596e 100644 --- a/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java +++ b/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java @@ -220,7 +220,7 @@ public boolean existsTable(String table) throws IOException { public void createTable(String table, List cfs) throws IOException { TableDescriptorBuilder tdb = TableDescriptorBuilder.newBuilder( - TableName.valueOf(this.namespace, table)); + TableName.valueOf(this.namespace, table)); for (byte[] cf : cfs) { tdb.setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(cf) .build()); @@ -239,7 +239,7 @@ public void createPreSplitTable(String table, List cfs, builder.setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(cf).build()); } byte[][] splits = new byte[numOfPartitions - 1] - [org.apache.hadoop.hbase.util.Bytes.SIZEOF_SHORT]; + [org.apache.hadoop.hbase.util.Bytes.SIZEOF_SHORT]; for (short split = 1; split < numOfPartitions; split++) { splits[split - 1] = org.apache.hadoop.hbase.util.Bytes.toBytes(split); } From c1e2d4c45142f242431b6ae93f3dc3f8d1832083 Mon Sep 17 00:00:00 2001 From: seagle Date: Wed, 12 Oct 2022 12:00:01 +0800 Subject: [PATCH 8/9] merge dev --- .../com/baidu/hugegraph/election/Config.java | 35 ++ .../election/RoleElectionStateMachine.java | 27 ++ .../RoleElectionStateMachineImpl.java | 312 ++++++++++++++++++ .../hugegraph/election/RoleTypeData.java | 91 +++++ .../election/RoleTypeDataAdapter.java | 29 ++ .../election/StateMachineCallback.java | 35 ++ .../election/StateMachineContext.java | 37 +++ 7 files changed, 566 insertions(+) create mode 100644 hugegraph-core/src/main/java/com/baidu/hugegraph/election/Config.java create mode 100644 hugegraph-core/src/main/java/com/baidu/hugegraph/election/RoleElectionStateMachine.java create mode 100644 hugegraph-core/src/main/java/com/baidu/hugegraph/election/RoleElectionStateMachineImpl.java create mode 100644 hugegraph-core/src/main/java/com/baidu/hugegraph/election/RoleTypeData.java create mode 100644 hugegraph-core/src/main/java/com/baidu/hugegraph/election/RoleTypeDataAdapter.java create mode 100644 hugegraph-core/src/main/java/com/baidu/hugegraph/election/StateMachineCallback.java create mode 100644 hugegraph-core/src/main/java/com/baidu/hugegraph/election/StateMachineContext.java diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/election/Config.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/election/Config.java new file mode 100644 index 0000000000..ad39c0b5ef --- /dev/null +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/election/Config.java @@ -0,0 +1,35 @@ +/* + * Copyright 2017 HugeGraph Authors + * + * 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 com.baidu.hugegraph.election; + +public interface Config { + + String node(); + + int exceedsFailCount(); + + long randomTimeoutMillisecond(); + + long heartBeatIntervalSecond(); + + int exceedsWorkerCount(); + + long baseTimeoutMillisecond(); +} diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/election/RoleElectionStateMachine.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/election/RoleElectionStateMachine.java new file mode 100644 index 0000000000..4bc258623b --- /dev/null +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/election/RoleElectionStateMachine.java @@ -0,0 +1,27 @@ +/* + * Copyright 2017 HugeGraph Authors + * + * 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 com.baidu.hugegraph.election; + +public interface RoleElectionStateMachine { + + void shutdown(); + + void apply(StateMachineCallback stateMachineCallback); +} diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/election/RoleElectionStateMachineImpl.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/election/RoleElectionStateMachineImpl.java new file mode 100644 index 0000000000..016f51cb8d --- /dev/null +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/election/RoleElectionStateMachineImpl.java @@ -0,0 +1,312 @@ +/* + * Copyright 2017 HugeGraph Authors + * + * 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 com.baidu.hugegraph.election; + +import java.security.SecureRandom; +import java.util.Optional; +import java.util.concurrent.locks.LockSupport; + +import com.baidu.hugegraph.util.E; + +public class RoleElectionStateMachineImpl implements RoleElectionStateMachine { + + private volatile boolean shutdown; + private final Config config; + private volatile RoleState state; + private final RoleTypeDataAdapter roleTypeDataAdapter; + + public RoleElectionStateMachineImpl(Config config, RoleTypeDataAdapter adapter) { + this.config = config; + this.roleTypeDataAdapter = adapter; + this.state = new UnknownState(null); + this.shutdown = false; + } + + @Override + public void shutdown() { + this.shutdown = true; + } + + @Override + public void apply(StateMachineCallback stateMachineCallback) { + int failCount = 0; + StateMachineContextImpl context = new StateMachineContextImpl(this); + while (!this.shutdown) { + E.checkArgumentNotNull(this.state, "State don't be null"); + try { + this.state = state.transform(context); + Callback runnable = this.state.callback(stateMachineCallback); + runnable.call(context); + failCount = 0; + } catch (Throwable e) { + stateMachineCallback.error(context, e); + failCount ++; + if (failCount >= this.config.exceedsFailCount()) { + this.state = new AbdicationState(context.epoch()); + Callback runnable = this.state.callback(stateMachineCallback); + runnable.call(context); + } + } + } + } + + private interface RoleState { + + SecureRandom secureRandom = new SecureRandom(); + + RoleState transform(StateMachineContext context); + + Callback callback(StateMachineCallback callback); + + static void heartBeatPark(StateMachineContext context) { + long heartBeatIntervalSecond = context.config().heartBeatIntervalSecond(); + LockSupport.parkNanos(heartBeatIntervalSecond * 1_000_000_000); + } + + static void randomPark(StateMachineContext context) { + long randomTimeout = context.config().randomTimeoutMillisecond(); + long baseTime = context.config().baseTimeoutMillisecond(); + long timeout = (long) (baseTime + (randomTimeout / 10.0 * secureRandom.nextInt(11))); + LockSupport.parkNanos(timeout * 1_000_000); + } + } + + @FunctionalInterface + private interface Callback { + + void call(StateMachineContext context); + } + + private static class UnknownState implements RoleState { + + final Integer epoch; + + public UnknownState(Integer epoch) { + this.epoch = epoch; + } + + @Override + public RoleState transform(StateMachineContext context) { + RoleTypeDataAdapter adapter = context.adapter(); + Optional roleTypeDataOpt = adapter.query(); + if (!roleTypeDataOpt.isPresent()) { + context.reset(); + Integer nextEpoch = this.epoch == null ? 1 : this.epoch + 1; + context.epoch(nextEpoch); + return new CandidateState(nextEpoch); + } + + RoleTypeData roleTypeData = roleTypeDataOpt.get(); + if (this.epoch != null && roleTypeData.epoch() < this.epoch) { + context.reset(); + Integer nextEpoch = this.epoch + 1; + context.epoch(nextEpoch); + return new CandidateState(nextEpoch); + } + + context.epoch(roleTypeData.epoch()); + if (roleTypeData.isMaster(context.node())) { + return new MasterState(roleTypeData); + } else { + return new WorkerState(roleTypeData); + } + } + + @Override + public Callback callback(StateMachineCallback callback) { + return callback::unknown; + } + } + + private static class AbdicationState implements RoleState { + + private final Integer epoch; + + public AbdicationState(Integer epoch) { + this.epoch = epoch; + } + + @Override + public RoleState transform(StateMachineContext context) { + RoleState.heartBeatPark(context); + return new UnknownState(this.epoch).transform(context); + } + + @Override + public Callback callback(StateMachineCallback callback) { + return callback::abdication; + } + } + + private static class MasterState implements RoleState { + + private final RoleTypeData roleTypeData; + + public MasterState(RoleTypeData roleTypeData) { + this.roleTypeData = roleTypeData; + } + + @Override + public RoleState transform(StateMachineContext context) { + this.roleTypeData.increaseClock(); + RoleState.heartBeatPark(context); + if (context.adapter().updateIfNodePresent(this.roleTypeData)) { + return this; + } + context.reset(); + context.epoch(this.roleTypeData.epoch()); + return new UnknownState(this.roleTypeData.epoch()).transform(context); + } + + @Override + public Callback callback(StateMachineCallback callback) { + return callback::master; + } + } + + private static class WorkerState implements RoleState { + + private RoleTypeData roleTypeData; + private int clock; + + public WorkerState(RoleTypeData roleTypeData) { + this.roleTypeData = roleTypeData; + this.clock = 0; + } + + @Override + public RoleState transform(StateMachineContext context) { + RoleState.heartBeatPark(context); + RoleState nextState = new UnknownState(this.roleTypeData.epoch()).transform(context); + if (nextState instanceof WorkerState) { + this.merge((WorkerState) nextState); + if (this.clock > context.config().exceedsWorkerCount()) { + return new CandidateState(this.roleTypeData.epoch() + 1); + } else { + return this; + } + } else { + return nextState; + } + } + + @Override + public Callback callback(StateMachineCallback callback) { + return callback::worker; + } + + public void merge(WorkerState state) { + if (state.roleTypeData.epoch() > this.roleTypeData.epoch()) { + this.clock = 0; + this.roleTypeData = state.roleTypeData; + } else if (state.roleTypeData.epoch() < this.roleTypeData.epoch()){ + throw new IllegalStateException("Epoch must increase"); + } else if (state.roleTypeData.epoch() == this.roleTypeData.epoch() && + state.roleTypeData.clock() < this.roleTypeData.clock()) { + throw new IllegalStateException("Clock must increase"); + } else if (state.roleTypeData.epoch() == this.roleTypeData.epoch() && + state.roleTypeData.clock() > this.roleTypeData.clock()) { + this.clock = 0; + this.roleTypeData = state.roleTypeData; + } else { + this.clock++; + } + } + } + + private static class CandidateState implements RoleState { + + private final Integer epoch; + + public CandidateState(Integer epoch) { + this.epoch = epoch; + } + + @Override + public RoleState transform(StateMachineContext context) { + RoleState.randomPark(context); + int epoch = this.epoch == null ? 1 : this.epoch; + RoleTypeData roleTypeData = new RoleTypeData(context.config().node(), epoch); + //failover to master success + context.epoch(roleTypeData.epoch()); + if (context.adapter().updateIfNodePresent(roleTypeData)) { + return new MasterState(roleTypeData); + } else { + return new UnknownState(epoch).transform(context); + } + } + + @Override + public Callback callback(StateMachineCallback callback) { + return callback::candidate; + } + } + + private static class StateMachineContextImpl implements StateMachineContext { + + private Integer epoch; + private final String node; + private final RoleElectionStateMachineImpl machine; + + public StateMachineContextImpl(RoleElectionStateMachineImpl machine) { + this.node = machine.config.node(); + this.machine = machine; + } + + @Override + public Integer epoch() { + return this.epoch; + } + + @Override + public String node() { + return this.node; + } + + @Override + public void epoch(Integer epoch) { + this.epoch = epoch; + } + + @Override + public RoleTypeDataAdapter adapter() { + return this.machine.adapter(); + } + + @Override + public Config config() { + return this.machine.config; + } + + @Override + public RoleElectionStateMachine stateMachine() { + return this.machine; + } + + @Override + public void reset() { + this.epoch = null; + } + } + + protected RoleTypeDataAdapter adapter() { + return this.roleTypeDataAdapter; + } +} diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/election/RoleTypeData.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/election/RoleTypeData.java new file mode 100644 index 0000000000..aa60c47ace --- /dev/null +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/election/RoleTypeData.java @@ -0,0 +1,91 @@ +/* + * Copyright 2017 HugeGraph Authors + * + * 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 com.baidu.hugegraph.election; + +import java.util.Objects; + +public class RoleTypeData { + + private String node; + private long clock; + private int epoch; + + public RoleTypeData(String node, int epoch) { + this(node, epoch, 1); + } + + public RoleTypeData(String node, int epoch, long clock) { + this.node = node; + this.epoch = epoch; + this.clock = clock; + } + + public void increaseClock() { + this.clock++; + } + + public boolean isMaster(String node) { + return Objects.equals(this.node, node); + } + + public int epoch() { + return this.epoch; + } + + public long clock() { + return this.clock; + } + + public void clock(long clock) { + this.clock = clock; + } + + public String node() { + return this.node; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof RoleTypeData)) { + return false; + } + RoleTypeData metaData = (RoleTypeData) obj; + return clock == metaData.clock && + epoch == metaData.epoch && + Objects.equals(node, metaData.node); + } + + @Override + public int hashCode() { + return Objects.hash(node, clock, epoch); + } + + @Override + public String toString() { + return "RoleStateData{" + + "node='" + node + '\'' + + ", clock=" + clock + + ", epoch=" + epoch + + '}'; + } +} diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/election/RoleTypeDataAdapter.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/election/RoleTypeDataAdapter.java new file mode 100644 index 0000000000..41a2021f09 --- /dev/null +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/election/RoleTypeDataAdapter.java @@ -0,0 +1,29 @@ +/* + * Copyright 2017 HugeGraph Authors + * + * 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 com.baidu.hugegraph.election; + +import java.util.Optional; + +public interface RoleTypeDataAdapter { + + boolean updateIfNodePresent(RoleTypeData stateData); + + Optional query(); +} diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/election/StateMachineCallback.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/election/StateMachineCallback.java new file mode 100644 index 0000000000..8403b59502 --- /dev/null +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/election/StateMachineCallback.java @@ -0,0 +1,35 @@ +/* + * Copyright 2017 HugeGraph Authors + * + * 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 com.baidu.hugegraph.election; + +public interface StateMachineCallback { + + void master(StateMachineContext context); + + void worker(StateMachineContext context); + + void candidate(StateMachineContext context); + + void unknown(StateMachineContext context); + + void abdication(StateMachineContext context); + + void error(StateMachineContext context, Throwable e); +} diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/election/StateMachineContext.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/election/StateMachineContext.java new file mode 100644 index 0000000000..a3693f5fac --- /dev/null +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/election/StateMachineContext.java @@ -0,0 +1,37 @@ +/* + * Copyright 2017 HugeGraph Authors + * + * 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 com.baidu.hugegraph.election; + +public interface StateMachineContext { + + Integer epoch(); + + String node(); + + RoleElectionStateMachine stateMachine(); + + void epoch(Integer epoch); + + Config config(); + + RoleTypeDataAdapter adapter(); + + void reset(); +} From 8cda2a07075ce81e21f476a9bb305bae3bc8a239 Mon Sep 17 00:00:00 2001 From: seagle Date: Wed, 12 Oct 2022 15:52:54 +0800 Subject: [PATCH 9/9] merge master --- .github/workflows/codeql-analysis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 1d4b13bc5b..5bcfa103cb 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -37,7 +37,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v1 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -48,7 +48,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v2 + uses: github/codeql-action/autobuild@v1 # â„šī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -62,4 +62,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v1