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 1 commit
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 @@ -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 @@ public void serverStarted(GlobalMasterInfo nodeInfo) {
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 @@ protected void reloadRamtable(boolean loadFromFile) {

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

Expand All @@ -581,11 +584,12 @@ public GraphComputer compute() throws IllegalArgumentException {
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())
).create();
}

Expand Down Expand Up @@ -1135,12 +1139,12 @@ public void registerRpcServices(RpcServiceConfig4Server serverConfig,
// 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 Txs getOrNewTransaction() {
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 @@ public void reload() {
}

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 @@ -23,12 +23,13 @@
import java.util.List;
import java.util.Map;

import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.schema.builder.SchemaBuilder;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.type.define.Frequency;
import org.apache.hugegraph.util.E;

import com.google.common.base.Objects;

public class EdgeLabel extends SchemaLabel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
import java.util.List;
import java.util.Map;

import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.id.IdGenerator;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.schema.builder.SchemaBuilder;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.type.define.IndexType;
import org.apache.hugegraph.util.E;

import com.google.common.base.Objects;

public class IndexLabel extends SchemaElement {
Expand Down Expand Up @@ -90,10 +91,10 @@ public HugeType queryType() {
return HugeType.SYS_SCHEMA;
default:
throw new AssertionError(String.format(
"Query type of index label is either '%s' or '%s', " +
"but '%s' is used",
HugeType.VERTEX_LABEL, HugeType.EDGE_LABEL,
this.baseType));
"Query type of index label is either '%s' or '%s', " +
"but '%s' is used",
HugeType.VERTEX_LABEL, HugeType.EDGE_LABEL,
this.baseType));
}
}

Expand Down Expand Up @@ -180,7 +181,7 @@ public static IndexLabel label(HugeType type) {
return ILN_IL;
default:
throw new AssertionError(String.format(
"No primitive index label for '%s'", type));
"No primitive index label for '%s'", type));
}
}

Expand All @@ -202,7 +203,7 @@ public static IndexLabel label(HugeGraph graph, Id id) {
return ILN_IL;
default:
throw new AssertionError(String.format(
"No primitive index label for '%s'", id));
"No primitive index label for '%s'", id));
}
}
return graph.indexLabel(id);
Expand Down Expand Up @@ -238,8 +239,8 @@ public static SchemaLabel getBaseLabel(HugeGraph graph,
break;
default:
throw new AssertionError(String.format(
"Unsupported base type '%s' of index label",
baseType));
"Unsupported base type '%s' of index label",
baseType));
}

E.checkArgumentNotNull(label, "Can't find the %s with name '%s'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import java.util.Map;
import java.util.Set;

import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.exception.NotSupportException;
import org.apache.hugegraph.schema.builder.SchemaBuilder;
import org.apache.hugegraph.type.HugeType;
Expand Down Expand Up @@ -142,7 +142,7 @@ public String clazz() {
return String.format("List<%s>", dataType);
default:
throw new AssertionError(String.format(
"Unsupported cardinality: '%s'", this.cardinality));
"Unsupported cardinality: '%s'", this.cardinality));
}
}

Expand All @@ -162,7 +162,7 @@ public Class<?> implementClazz() {
break;
default:
throw new AssertionError(String.format(
"Unsupported cardinality: '%s'", this.cardinality));
"Unsupported cardinality: '%s'", this.cardinality));
}
return cls;
}
Expand All @@ -189,10 +189,11 @@ public <T> T newValue() {

/**
* Check property value valid
*
* @param value the property value to be checked data type and cardinality
* @param <V> the property value class
* @param <V> the property value class
* @return true if data type and cardinality satisfy requirements,
* otherwise false
* otherwise false
*/
public <V> boolean checkValueType(V value) {
boolean valid;
Expand All @@ -211,28 +212,30 @@ public <V> boolean checkValueType(V value) {
break;
default:
throw new AssertionError(String.format(
"Unsupported cardinality: '%s'", this.cardinality));
"Unsupported cardinality: '%s'", this.cardinality));
}
return valid;
}

/**
* Check type of the value valid
*
* @param value the property value to be checked data type
* @param <V> the property value original data type
* @return true if the value is or can convert to the data type,
* otherwise false
* otherwise false
*/
private <V> boolean checkDataType(V value) {
return this.dataType().clazz().isInstance(value);
}

/**
* Check type of all the values(maybe some list properties) valid
*
* @param values the property values to be checked data type
* @param <V> the property value class
* @param <V> the property value class
* @return true if all the values are or can convert to the data type,
* otherwise false
* otherwise false
*/
private <V> boolean checkDataType(Collection<V> values) {
boolean valid = true;
Expand Down Expand Up @@ -280,8 +283,8 @@ public <V> V validValue(V value) {
return this.convValue(value);
} catch (RuntimeException e) {
throw new IllegalArgumentException(String.format(
"Invalid property value '%s' for key '%s': %s",
value, this.name(), e.getMessage()));
"Invalid property value '%s' for key '%s': %s",
value, this.name(), e.getMessage()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
import java.util.Collections;
import java.util.Map;

import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.id.IdGenerator;
import org.apache.tinkerpop.gremlin.structure.Graph;

import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.id.IdGenerator;
import org.apache.hugegraph.type.Nameable;
import org.apache.hugegraph.type.Typeable;
import org.apache.hugegraph.type.define.SchemaStatus;
import org.apache.hugegraph.util.E;
import org.apache.tinkerpop.gremlin.structure.Graph;

import com.google.common.base.Objects;

public abstract class SchemaElement implements Nameable, Typeable,
Expand Down Expand Up @@ -158,7 +158,7 @@ public boolean equals(Object obj) {

@Override
public int hashCode() {
return this.type().hashCode() ^ this.id.hashCode();
return this.type().hashCode() ^ this.id.hashCode();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@
import java.util.HashSet;
import java.util.Set;

import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.id.IdGenerator;
import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.id.IdGenerator;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.type.Indexable;
import org.apache.hugegraph.type.Propertiable;
import org.apache.hugegraph.util.E;

import com.google.common.base.Objects;

public abstract class SchemaLabel extends SchemaElement
implements Indexable, Propertiable {
implements Indexable, Propertiable {

private final Set<Id> properties;
private final Set<Id> nullableKeys;
Expand Down Expand Up @@ -167,13 +168,13 @@ public static Id getLabelId(HugeGraph graph, HugeType type, Object label) {
return graph.edgeLabel((String) label).id();
} else {
throw new HugeException(
"Not support query from '%s' with label '%s'",
type, label);
"Not support query from '%s' with label '%s'",
type, label);
}
} else {
throw new HugeException(
"The label type must be number or string, but got '%s'",
label.getClass());
"The label type must be number or string, but got '%s'",
label.getClass());
}
}
}
Loading