Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: format and clean code in core module #2440

Merged
merged 4 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ public static void shutdown(long timeout) {

/**
* Stop all the daemon threads
* @param timeout wait in seconds
*
* @param timeout wait in seconds
* @param ignoreException don't throw exception if true
*/
public static void shutdown(long timeout, boolean ignoreException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public interface HugeGraph extends Graph {
<K, V> V option(TypedOption<K, V> option);

void registerRpcServices(RpcServiceConfig4Server serverConfig,
RpcServiceConfig4Client clientConfig);
RpcServiceConfig4Client clientConfig);

default List<String> mapPkId2Name(Collection<Id> ids) {
List<String> names = new ArrayList<>(ids.size());
Expand Down Expand Up @@ -316,8 +316,8 @@ default Id[] mapVlName2Id(String[] vertexLabels) {

static void registerTraversalStrategies(Class<?> clazz) {
TraversalStrategies strategies = TraversalStrategies.GlobalCache
.getStrategies(Graph.class)
.clone();
.getStrategies(Graph.class)
.clone();
strategies.addStrategies(HugeVertexStepStrategy.instance(),
HugeGraphStepStrategy.instance(),
HugeCountStepStrategy.instance(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@

package org.apache.hugegraph;

import org.apache.hugegraph.analyzer.Analyzer;
import org.apache.hugegraph.backend.LocalCounter;
import org.apache.hugegraph.backend.serializer.AbstractSerializer;
import org.apache.hugegraph.backend.store.BackendFeatures;
import org.apache.hugegraph.backend.store.BackendStore;
import org.apache.hugegraph.backend.store.ram.RamTable;
import org.apache.hugegraph.backend.tx.GraphTransaction;
import org.apache.hugegraph.backend.tx.SchemaTransaction;
import org.apache.hugegraph.config.HugeConfig;
import org.apache.hugegraph.event.EventHub;
import org.apache.hugegraph.job.EphemeralJob;
import org.apache.hugegraph.task.ServerInfoManager;
import org.apache.hugegraph.type.define.GraphMode;
import org.apache.hugegraph.type.define.GraphReadMode;
import org.apache.hugegraph.analyzer.Analyzer;
import org.apache.hugegraph.backend.serializer.AbstractSerializer;
import org.apache.hugegraph.config.HugeConfig;
import org.apache.hugegraph.event.EventHub;

import com.google.common.util.concurrent.RateLimiter;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,26 +121,26 @@
public class StandardHugeGraph implements HugeGraph {

public static final Class<?>[] PROTECT_CLASSES = {
StandardHugeGraph.class,
StandardHugeGraph.StandardHugeGraphParams.class,
TinkerPopTransaction.class,
StandardHugeGraph.Txs.class,
StandardHugeGraph.SysTransaction.class
StandardHugeGraph.class,
StandardHugeGraph.StandardHugeGraphParams.class,
TinkerPopTransaction.class,
StandardHugeGraph.Txs.class,
StandardHugeGraph.SysTransaction.class
Comment on lines -124 to +128
Copy link
Member

Choose a reason for hiding this comment

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

IMPORTANT: we need to ensure 4 or 8 spaces to format (and sync to "hugegraph-style" config files & other PRs)

};

public static final Set<TypedOption<?, ?>> ALLOWED_CONFIGS = ImmutableSet.of(
CoreOptions.TASK_WAIT_TIMEOUT,
CoreOptions.TASK_SYNC_DELETION,
CoreOptions.TASK_TTL_DELETE_BATCH,
CoreOptions.TASK_INPUT_SIZE_LIMIT,
CoreOptions.TASK_RESULT_SIZE_LIMIT,
CoreOptions.OLTP_CONCURRENT_THREADS,
CoreOptions.OLTP_CONCURRENT_DEPTH,
CoreOptions.OLTP_COLLECTION_TYPE,
CoreOptions.VERTEX_DEFAULT_LABEL,
CoreOptions.VERTEX_ENCODE_PK_NUMBER,
CoreOptions.STORE_GRAPH,
CoreOptions.STORE
CoreOptions.TASK_WAIT_TIMEOUT,
CoreOptions.TASK_SYNC_DELETION,
CoreOptions.TASK_TTL_DELETE_BATCH,
CoreOptions.TASK_INPUT_SIZE_LIMIT,
CoreOptions.TASK_RESULT_SIZE_LIMIT,
CoreOptions.OLTP_CONCURRENT_THREADS,
CoreOptions.OLTP_CONCURRENT_DEPTH,
CoreOptions.OLTP_COLLECTION_TYPE,
CoreOptions.VERTEX_DEFAULT_LABEL,
CoreOptions.VERTEX_ENCODE_PK_NUMBER,
CoreOptions.STORE_GRAPH,
CoreOptions.STORE
);

private static final Logger LOG = Log.logger(StandardHugeGraph.class);
Expand Down Expand Up @@ -294,14 +294,17 @@
private void initRoleStateMachine(Id serverId) {
HugeConfig conf = this.configuration;
Config roleConfig = new RoleElectionConfig(serverId.toString(),
conf.get(RoleElectionOptions.NODE_EXTERNAL_URL),
conf.get(RoleElectionOptions.EXCEEDS_FAIL_COUNT),
conf.get(RoleElectionOptions.RANDOM_TIMEOUT_MILLISECOND),
conf.get(RoleElectionOptions.HEARTBEAT_INTERVAL_SECOND),
conf.get(RoleElectionOptions.MASTER_DEAD_TIMES),
conf.get(RoleElectionOptions.BASE_TIMEOUT_MILLISECOND));
conf.get(RoleElectionOptions.NODE_EXTERNAL_URL),
conf.get(RoleElectionOptions.EXCEEDS_FAIL_COUNT),
conf.get(
RoleElectionOptions.RANDOM_TIMEOUT_MILLISECOND),
conf.get(
RoleElectionOptions.HEARTBEAT_INTERVAL_SECOND),
conf.get(RoleElectionOptions.MASTER_DEAD_TIMES),
conf.get(
RoleElectionOptions.BASE_TIMEOUT_MILLISECOND));
ClusterRoleStore roleStore = new StandardClusterRoleStore(this.params);
this.roleElectionStateMachine = new StandardRoleElectionStateMachine(roleConfig,
this.roleElectionStateMachine = new StandardRoleElectionStateMachine(roleConfig,
roleStore);
}

Expand Down Expand Up @@ -572,7 +575,7 @@

@Override
public <C extends GraphComputer> C compute(Class<C> clazz)
throws IllegalArgumentException {
throws IllegalArgumentException {
throw Graph.Exceptions.graphComputerNotSupported();
}

Expand All @@ -581,11 +584,12 @@
throw Graph.Exceptions.graphComputerNotSupported();
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public <I extends Io> I io(final Io.Builder<I> builder) {
return (I) builder.graph(this).onMapper(mapper ->
mapper.addRegistry(HugeGraphIoRegistry.instance())
mapper.addRegistry(
HugeGraphIoRegistry.instance())

Check warning on line 592 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/StandardHugeGraph.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/StandardHugeGraph.java#L591-L592

Added lines #L591 - L592 were not covered by tests
).create();
}

Expand Down Expand Up @@ -1135,12 +1139,12 @@
// The proxy is sometimes unavailable (issue #664)
CacheNotifier proxy = clientConfig.serviceProxy(this.name, clazz1);
serverConfig.addService(this.name, clazz1, new HugeGraphCacheNotifier(
this.graphEventHub, proxy));
this.graphEventHub, proxy));

Class<SchemaCacheNotifier> clazz2 = SchemaCacheNotifier.class;
proxy = clientConfig.serviceProxy(this.name, clazz2);
serverConfig.addService(this.name, clazz2, new HugeSchemaCacheNotifier(
this.schemaEventHub, proxy));
this.schemaEventHub, proxy));
}

private void closeTx() {
Expand Down Expand Up @@ -1493,7 +1497,7 @@
private void destroyTransaction() {
if (this.isOpen()) {
throw new HugeException(
"Transaction should be closed before destroying");
"Transaction should be closed before destroying");
}

// Do close if needed, then remove the reference
Expand Down Expand Up @@ -1634,17 +1638,17 @@
}

private static class HugeSchemaCacheNotifier
extends AbstractCacheNotifier
implements SchemaCacheNotifier {
extends AbstractCacheNotifier
implements SchemaCacheNotifier {

public HugeSchemaCacheNotifier(EventHub hub, CacheNotifier proxy) {
super(hub, proxy);
}
}

private static class HugeGraphCacheNotifier
extends AbstractCacheNotifier
implements GraphCacheNotifier {
extends AbstractCacheNotifier
implements GraphCacheNotifier {

public HugeGraphCacheNotifier(EventHub hub, CacheNotifier proxy) {
super(hub, proxy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ private static Analyzer customizedAnalyzer(String name, String mode) {
return clazz.getConstructor(String.class).newInstance(mode);
} catch (Exception e) {
throw new HugeException(
"Failed to construct analyzer '%s' with mode '%s'",
e, name, mode);
"Failed to construct analyzer '%s' with mode '%s'",
e, name, mode);
}
}

@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
public static void register(String name, String classPath) {
ClassLoader classLoader = SerializerFactory.class.getClassLoader();
Class<?> clazz;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import org.ansj.splitWord.analysis.IndexAnalysis;
import org.ansj.splitWord.analysis.NlpAnalysis;
import org.ansj.splitWord.analysis.ToAnalysis;

import org.apache.hugegraph.config.ConfigException;
import org.apache.hugegraph.util.InsertionOrderUtil;

import com.google.common.collect.ImmutableList;

/**
Expand All @@ -48,8 +48,8 @@ public class AnsjAnalyzer implements Analyzer {
public AnsjAnalyzer(String mode) {
if (!SUPPORT_MODES.contains(mode)) {
throw new ConfigException(
"Unsupported segment mode '%s' for ansj analyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
"Unsupported segment mode '%s' for ansj analyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
}
this.analysis = mode;
}
Expand All @@ -72,7 +72,7 @@ public Set<String> segment(String text) {
break;
default:
throw new AssertionError(String.format(
"Unsupported segment mode '%s'", this.analysis));
"Unsupported segment mode '%s'", this.analysis));
}

assert terms != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.apache.hugegraph.config.ConfigException;
import org.apache.hugegraph.util.InsertionOrderUtil;

import com.google.common.collect.ImmutableList;
import com.hankcs.hanlp.seg.Dijkstra.DijkstraSegment;
import com.hankcs.hanlp.seg.NShort.NShortSegment;
Expand All @@ -38,14 +39,14 @@
public class HanLPAnalyzer implements Analyzer {

public static final List<String> SUPPORT_MODES =
ImmutableList.<String>builder()
.add("standard")
.add("nlp")
.add("index")
.add("nShort")
.add("shortest")
.add("speed")
.build();
ImmutableList.<String>builder()
.add("standard")
.add("nlp")
.add("index")
.add("nShort")
.add("shortest")
.add("speed")
.build();

private static final Segment N_SHORT_SEGMENT =
new NShortSegment().enableCustomDictionary(false)
Expand All @@ -61,8 +62,8 @@ public class HanLPAnalyzer implements Analyzer {
public HanLPAnalyzer(String mode) {
if (!SUPPORT_MODES.contains(mode)) {
throw new ConfigException(
"Unsupported segment mode '%s' for hanlp analyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
"Unsupported segment mode '%s' for hanlp analyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
}
this.tokenizer = mode;
}
Expand Down Expand Up @@ -91,7 +92,7 @@ public Set<String> segment(String text) {
break;
default:
throw new AssertionError(String.format(
"Unsupported segment mode '%s'", this.tokenizer));
"Unsupported segment mode '%s'", this.tokenizer));
}

assert terms != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import java.util.Set;

import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.config.ConfigException;
import org.apache.hugegraph.util.InsertionOrderUtil;
import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import org.apache.hugegraph.config.ConfigException;
import org.apache.hugegraph.util.InsertionOrderUtil;
import com.google.common.collect.ImmutableList;

/**
Expand All @@ -44,8 +44,8 @@ public class IKAnalyzer implements Analyzer {
public IKAnalyzer(String mode) {
if (!SUPPORT_MODES.contains(mode)) {
throw new ConfigException(
"Unsupported segment mode '%s' for ikanalyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
"Unsupported segment mode '%s' for ikanalyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
}
this.smartSegMode = SUPPORT_MODES.get(0).equals(mode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
import java.util.Set;

import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.config.ConfigException;
import org.apache.hugegraph.util.InsertionOrderUtil;
import org.lionsoul.jcseg.ISegment;
import org.lionsoul.jcseg.IWord;
import org.lionsoul.jcseg.dic.ADictionary;
import org.lionsoul.jcseg.dic.DictionaryFactory;
import org.lionsoul.jcseg.segmenter.SegmenterConfig;

import org.apache.hugegraph.config.ConfigException;
import org.apache.hugegraph.util.InsertionOrderUtil;
import com.google.common.collect.ImmutableList;

/**
Expand All @@ -50,8 +50,8 @@ public class JcsegAnalyzer implements Analyzer {
public JcsegAnalyzer(String mode) {
if (!SUPPORT_MODES.contains(mode)) {
throw new ConfigException(
"Unsupported segment mode '%s' for jcseg analyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
"Unsupported segment mode '%s' for jcseg analyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
}

if ("Simple".equals(mode)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.apache.hugegraph.config.ConfigException;
import org.apache.hugegraph.util.InsertionOrderUtil;

import com.google.common.collect.ImmutableList;
import com.huaban.analysis.jieba.JiebaSegmenter;
import com.huaban.analysis.jieba.SegToken;
Expand All @@ -43,8 +44,8 @@ public class JiebaAnalyzer implements Analyzer {
public JiebaAnalyzer(String mode) {
if (!SUPPORT_MODES.contains(mode)) {
throw new ConfigException(
"Unsupported segment mode '%s' for jieba analyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
"Unsupported segment mode '%s' for jieba analyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
}
this.segMode = JiebaSegmenter.SegMode.valueOf(mode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.config.ConfigException;
import org.apache.hugegraph.util.InsertionOrderUtil;

import com.chenlb.mmseg4j.ComplexSeg;
import com.chenlb.mmseg4j.Dictionary;
import com.chenlb.mmseg4j.MMSeg;
Expand Down Expand Up @@ -51,8 +52,8 @@ public class MMSeg4JAnalyzer implements Analyzer {
public MMSeg4JAnalyzer(String mode) {
if (!SUPPORT_MODES.contains(mode)) {
throw new ConfigException(
"Unsupported segment mode '%s' for mmseg4j analyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
"Unsupported segment mode '%s' for mmseg4j analyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
}
int index = SUPPORT_MODES.indexOf(mode);
switch (index) {
Expand All @@ -67,7 +68,7 @@ public MMSeg4JAnalyzer(String mode) {
break;
default:
throw new AssertionError(String.format(
"Unsupported segment mode '%s'", mode));
"Unsupported segment mode '%s'", mode));
}
}

Expand Down
Loading
Loading