fix: format and clean code in core module (#2440)

This commit is contained in:
M 2024-02-20 17:22:28 +08:00 committed by VGalaxies
parent 721111d11a
commit 960b7330fd
247 changed files with 1559 additions and 1544 deletions

View File

@ -145,7 +145,8 @@ public class HugeFactory {
/**
* 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) {

View File

@ -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());
@ -316,8 +316,8 @@ public interface HugeGraph extends Graph {
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(),

View File

@ -17,21 +17,22 @@
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.ISchemaTransaction;
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;
/**

View File

@ -123,26 +123,26 @@ import com.google.common.util.concurrent.RateLimiter;
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
};
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);
@ -306,14 +306,17 @@ public class StandardHugeGraph implements HugeGraph {
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);
}
@ -596,7 +599,7 @@ public class StandardHugeGraph implements HugeGraph {
@Override
public <C extends GraphComputer> C compute(Class<C> clazz)
throws IllegalArgumentException {
throws IllegalArgumentException {
throw Graph.Exceptions.graphComputerNotSupported();
}
@ -605,11 +608,12 @@ public class StandardHugeGraph implements HugeGraph {
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();
}
@ -1159,12 +1163,12 @@ public class StandardHugeGraph implements HugeGraph {
// 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() {
@ -1522,7 +1526,7 @@ public class StandardHugeGraph implements HugeGraph {
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
@ -1663,8 +1667,8 @@ public class StandardHugeGraph implements HugeGraph {
}
private static class HugeSchemaCacheNotifier
extends AbstractCacheNotifier
implements SchemaCacheNotifier {
extends AbstractCacheNotifier
implements SchemaCacheNotifier {
public HugeSchemaCacheNotifier(EventHub hub, CacheNotifier proxy) {
super(hub, proxy);
@ -1672,8 +1676,8 @@ public class StandardHugeGraph implements HugeGraph {
}
private static class HugeGraphCacheNotifier
extends AbstractCacheNotifier
implements GraphCacheNotifier {
extends AbstractCacheNotifier
implements GraphCacheNotifier {
public HugeGraphCacheNotifier(EventHub hub, CacheNotifier proxy) {
super(hub, proxy);

View File

@ -64,12 +64,12 @@ public class AnalyzerFactory {
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;

View File

@ -26,9 +26,9 @@ import org.ansj.splitWord.analysis.BaseAnalysis;
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;
/**
@ -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;
}
@ -72,7 +72,7 @@ public class AnsjAnalyzer implements Analyzer {
break;
default:
throw new AssertionError(String.format(
"Unsupported segment mode '%s'", this.analysis));
"Unsupported segment mode '%s'", this.analysis));
}
assert terms != null;

View File

@ -22,6 +22,7 @@ import java.util.Set;
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;
@ -38,14 +39,14 @@ import com.hankcs.hanlp.tokenizer.StandardTokenizer;
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)
@ -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;
}
@ -91,7 +92,7 @@ public class HanLPAnalyzer implements Analyzer {
break;
default:
throw new AssertionError(String.format(
"Unsupported segment mode '%s'", this.tokenizer));
"Unsupported segment mode '%s'", this.tokenizer));
}
assert terms != null;

View File

@ -22,11 +22,11 @@ import java.util.List;
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;
/**
@ -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);
}

View File

@ -22,14 +22,14 @@ import java.util.List;
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;
/**
@ -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)) {

View File

@ -22,6 +22,7 @@ import java.util.Set;
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;
@ -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);
}

View File

@ -24,6 +24,7 @@ import java.util.Set;
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;
@ -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) {
@ -67,7 +68,7 @@ public class MMSeg4JAnalyzer implements Analyzer {
break;
default:
throw new AssertionError(String.format(
"Unsupported segment mode '%s'", mode));
"Unsupported segment mode '%s'", mode));
}
}

View File

@ -22,19 +22,18 @@ import java.io.StringReader;
import java.util.Set;
import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.util.InsertionOrderUtil;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.hugegraph.util.InsertionOrderUtil;
/**
* Reference from https://lucene.apache.org/core/8_11_2/analyzers-smartcn/index.html
*/
public class SmartCNAnalyzer implements Analyzer {
private static final SmartChineseAnalyzer ANALYZER =
new SmartChineseAnalyzer();
new SmartChineseAnalyzer();
public SmartCNAnalyzer(String mode) {
// pass

View File

@ -22,8 +22,8 @@ import java.util.Set;
import javax.security.sasl.AuthenticationException;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.auth.SchemaDefine.AuthElement;
import org.apache.hugegraph.backend.id.Id;
public interface AuthManager {

View File

@ -22,26 +22,26 @@ import java.util.List;
import java.util.Map;
import java.util.function.Function;
import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.auth.SchemaDefine.Entity;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.query.Condition;
import org.apache.hugegraph.backend.query.ConditionQuery;
import org.apache.hugegraph.backend.query.QueryResults;
import org.apache.hugegraph.backend.tx.GraphTransaction;
import org.apache.hugegraph.exception.NotFoundException;
import org.apache.hugegraph.iterator.MapperIterator;
import org.apache.hugegraph.schema.PropertyKey;
import org.apache.hugegraph.schema.VertexLabel;
import org.apache.hugegraph.structure.HugeVertex;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.type.define.HugeKeys;
import org.apache.hugegraph.util.E;
import org.apache.tinkerpop.gremlin.structure.Graph.Hidden;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.auth.SchemaDefine.Entity;
import org.apache.hugegraph.exception.NotFoundException;
import org.apache.hugegraph.iterator.MapperIterator;
import org.apache.hugegraph.structure.HugeVertex;
import org.apache.hugegraph.util.E;
import com.google.common.collect.ImmutableMap;
public class EntityManager<T extends Entity> {

View File

@ -22,17 +22,16 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.auth.SchemaDefine.Relationship;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.schema.EdgeLabel;
import org.apache.hugegraph.type.define.DataType;
import org.apache.hugegraph.util.E;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph.Hidden;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.auth.SchemaDefine.Relationship;
import org.apache.hugegraph.util.E;
public class HugeAccess extends Relationship {
private static final long serialVersionUID = -7644007602408729385L;

View File

@ -22,15 +22,14 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.auth.SchemaDefine.Relationship;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.schema.EdgeLabel;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph.Hidden;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.auth.SchemaDefine.Relationship;
public class HugeBelong extends Relationship {
public static final String UG = "ug";
@ -103,12 +102,10 @@ public class HugeBelong extends Relationship {
if (super.property(key, value)) {
return true;
}
switch (key) {
case P.DESCRIPTION:
this.description = (String) value;
break;
default:
throw new AssertionError("Unsupported key: " + key);
if (key.equals(P.DESCRIPTION)) {
this.description = (String) value;
} else {
throw new AssertionError("Unsupported key: " + key);
}
return true;
}

View File

@ -22,16 +22,15 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.auth.SchemaDefine.Entity;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.schema.VertexLabel;
import org.apache.hugegraph.util.E;
import org.apache.tinkerpop.gremlin.structure.Graph.Hidden;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.auth.SchemaDefine.Entity;
import org.apache.hugegraph.util.E;
public class HugeGroup extends Entity {
private static final long serialVersionUID = 2330399818352242686L;
@ -195,7 +194,7 @@ public class HugeGroup extends Entity {
this.graph.schemaTransaction().addVertexLabel(label);
}
protected String[] initProperties() {
private String[] initProperties() {
List<String> props = new ArrayList<>();
props.add(createPropertyKey(P.NAME));

View File

@ -25,19 +25,18 @@ import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.auth.SchemaDefine.Entity;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.id.IdGenerator;
import org.apache.hugegraph.schema.VertexLabel;
import org.apache.hugegraph.type.define.Cardinality;
import org.apache.hugegraph.type.define.DataType;
import org.apache.hugegraph.util.E;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.auth.SchemaDefine.Entity;
import org.apache.hugegraph.util.E;
public class HugeProject extends Entity {
private static final long serialVersionUID = 8681323499069874520L;

View File

@ -23,6 +23,10 @@ import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.auth.SchemaDefine.AuthElement;
import org.apache.hugegraph.structure.HugeElement;
import org.apache.hugegraph.traversal.optimize.TraversalUtil;
import org.apache.hugegraph.type.Nameable;
import org.apache.hugegraph.type.Typeable;
import org.apache.hugegraph.util.JsonUtil;
@ -39,10 +43,6 @@ import org.apache.tinkerpop.shaded.jackson.databind.deser.std.StdDeserializer;
import org.apache.tinkerpop.shaded.jackson.databind.module.SimpleModule;
import org.apache.tinkerpop.shaded.jackson.databind.ser.std.StdSerializer;
import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.auth.SchemaDefine.AuthElement;
import org.apache.hugegraph.structure.HugeElement;
import org.apache.hugegraph.traversal.optimize.TraversalUtil;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@ -55,7 +55,7 @@ public class HugeResource {
public static final List<HugeResource> ALL_RES = ImmutableList.of(ALL);
private static final Set<ResourceType> CHECK_NAME_RESS = ImmutableSet.of(
ResourceType.META);
ResourceType.META);
static {
SimpleModule module = new SimpleModule();
@ -143,7 +143,7 @@ public class HugeResource {
private boolean filter(Nameable element) {
assert !(element instanceof Typeable) || this.type.match(
ResourceType.from(((Typeable) element).type()));
ResourceType.from(((Typeable) element).type()));
return this.matchLabel(element.name());
}
@ -258,7 +258,8 @@ public class HugeResource {
}
public static List<HugeResource> parseResources(String resources) {
TypeReference<?> type = new TypeReference<List<HugeResource>>() {};
TypeReference<?> type = new TypeReference<List<HugeResource>>() {
};
return JsonUtil.fromJson(resources, type);
}
@ -298,7 +299,7 @@ public class HugeResource {
@Override
public void serialize(HugeResource res, JsonGenerator generator,
SerializerProvider provider)
throws IOException {
throws IOException {
generator.writeStartObject();
generator.writeObjectField("type", res.type);
@ -320,7 +321,7 @@ public class HugeResource {
@Override
public HugeResource deserialize(JsonParser parser,
DeserializationContext ctxt)
throws IOException {
throws IOException {
HugeResource res = new HugeResource();
while (parser.nextToken() != JsonToken.END_OBJECT) {
String key = parser.getCurrentName();

View File

@ -22,18 +22,17 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.auth.SchemaDefine.Entity;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.schema.VertexLabel;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.JsonUtil;
import org.apache.tinkerpop.gremlin.structure.Graph.Hidden;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.auth.SchemaDefine.Entity;
import org.apache.hugegraph.util.E;
import com.google.common.collect.ImmutableList;
public class HugeTarget extends Entity {

View File

@ -22,16 +22,15 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.auth.SchemaDefine.Entity;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.schema.VertexLabel;
import org.apache.hugegraph.util.E;
import org.apache.tinkerpop.gremlin.structure.Graph.Hidden;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.auth.SchemaDefine.Entity;
import org.apache.hugegraph.util.E;
public class HugeUser extends Entity {
private static final long serialVersionUID = -8951193710873772717L;

View File

@ -22,29 +22,29 @@ import java.util.List;
import java.util.Map;
import java.util.function.Function;
import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.auth.SchemaDefine.Relationship;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.query.Condition;
import org.apache.hugegraph.backend.query.ConditionQuery;
import org.apache.hugegraph.backend.query.QueryResults;
import org.apache.hugegraph.backend.tx.GraphTransaction;
import org.apache.hugegraph.exception.NotFoundException;
import org.apache.hugegraph.iterator.MapperIterator;
import org.apache.hugegraph.schema.EdgeLabel;
import org.apache.hugegraph.schema.PropertyKey;
import org.apache.hugegraph.schema.VertexLabel;
import org.apache.hugegraph.structure.HugeEdge;
import org.apache.hugegraph.structure.HugeVertex;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.type.define.Directions;
import org.apache.hugegraph.type.define.HugeKeys;
import org.apache.hugegraph.util.E;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph.Hidden;
import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.auth.SchemaDefine.Relationship;
import org.apache.hugegraph.exception.NotFoundException;
import org.apache.hugegraph.iterator.MapperIterator;
import org.apache.hugegraph.structure.HugeEdge;
import org.apache.hugegraph.structure.HugeVertex;
import org.apache.hugegraph.util.E;
import com.google.common.collect.ImmutableMap;
public class RelationshipManager<T extends Relationship> {

View File

@ -19,8 +19,8 @@ package org.apache.hugegraph.auth;
import org.apache.hugegraph.auth.SchemaDefine.AuthElement;
import org.apache.hugegraph.schema.SchemaElement;
import org.apache.hugegraph.type.Nameable;
import org.apache.hugegraph.structure.HugeElement;
import org.apache.hugegraph.type.Nameable;
import org.apache.hugegraph.util.E;
public class ResourceObject<V> {

View File

@ -17,6 +17,8 @@
package org.apache.hugegraph.auth;
import java.util.Objects;
import org.apache.hugegraph.type.HugeType;
public enum ResourceType {
@ -70,11 +72,8 @@ public enum ResourceType {
return true;
}
switch (required) {
case NONE:
return this != NONE;
default:
break;
if (Objects.requireNonNull(required) == ResourceType.NONE) {
return this != NONE;
}
switch (this) {

View File

@ -25,6 +25,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.JsonUtil;
import org.apache.tinkerpop.shaded.jackson.annotation.JsonProperty;
import org.apache.tinkerpop.shaded.jackson.core.JsonGenerator;
@ -37,14 +38,12 @@ import org.apache.tinkerpop.shaded.jackson.databind.deser.std.StdDeserializer;
import org.apache.tinkerpop.shaded.jackson.databind.module.SimpleModule;
import org.apache.tinkerpop.shaded.jackson.databind.ser.std.StdSerializer;
import org.apache.hugegraph.util.E;
public class RolePermission {
public static final RolePermission NONE = RolePermission.role(
"none", HugePermission.NONE);
"none", HugePermission.NONE);
public static final RolePermission ADMIN = RolePermission.role(
"admin", HugePermission.ANY);
"admin", HugePermission.ANY);
static {
SimpleModule module = new SimpleModule();
@ -64,7 +63,7 @@ public class RolePermission {
}
private RolePermission(Map<String, Map<HugePermission,
List<HugeResource>>> roles) {
List<HugeResource>>> roles) {
this.roles = roles;
}
@ -76,7 +75,7 @@ public class RolePermission {
protected void add(String graph, HugePermission action,
List<HugeResource> resources) {
Map<HugePermission, List<HugeResource>> permissions =
this.roles.get(graph);
this.roles.get(graph);
if (permissions == null) {
permissions = new TreeMap<>();
this.roles.put(graph, permissions);
@ -95,14 +94,14 @@ public class RolePermission {
public boolean contains(RolePermission other) {
for (Map.Entry<String, Map<HugePermission, List<HugeResource>>> e1 :
other.roles.entrySet()) {
other.roles.entrySet()) {
String g = e1.getKey();
Map<HugePermission, List<HugeResource>> perms = this.roles.get(g);
if (perms == null) {
return false;
}
for (Map.Entry<HugePermission, List<HugeResource>> e2 :
e1.getValue().entrySet()) {
e1.getValue().entrySet()) {
List<HugeResource> ress = perms.get(e2.getKey());
if (ress == null) {
return false;
@ -189,7 +188,7 @@ public class RolePermission {
}
private static class RolePermissionSer
extends StdSerializer<RolePermission> {
extends StdSerializer<RolePermission> {
private static final long serialVersionUID = -2533310506459479383L;
@ -200,7 +199,7 @@ public class RolePermission {
@Override
public void serialize(RolePermission role, JsonGenerator generator,
SerializerProvider provider)
throws IOException {
throws IOException {
generator.writeStartObject();
generator.writeObjectField("roles", role.roles);
generator.writeEndObject();
@ -208,7 +207,7 @@ public class RolePermission {
}
private static class RolePermissionDeser
extends StdDeserializer<RolePermission> {
extends StdDeserializer<RolePermission> {
private static final long serialVersionUID = -2038234657843260957L;
@ -219,9 +218,10 @@ public class RolePermission {
@Override
public RolePermission deserialize(JsonParser parser,
DeserializationContext ctxt)
throws IOException {
throws IOException {
TypeReference<?> type = new TypeReference<TreeMap<String,
TreeMap<HugePermission, List<HugeResource>>>>() {};
TreeMap<HugePermission, List<HugeResource>>>>() {
};
if ("roles".equals(parser.nextFieldName())) {
parser.nextValue();
return new RolePermission(parser.readValueAs(type));

View File

@ -23,6 +23,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.auth.HugeTarget.P;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.id.IdGenerator;
@ -31,18 +32,15 @@ import org.apache.hugegraph.schema.PropertyKey;
import org.apache.hugegraph.schema.SchemaManager;
import org.apache.hugegraph.schema.VertexLabel;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.type.Nameable;
import org.apache.hugegraph.type.define.Cardinality;
import org.apache.hugegraph.type.define.DataType;
import org.apache.hugegraph.util.E;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph.Hidden;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.util.E;
public abstract class SchemaDefine {
protected final HugeGraphParams graph;
@ -242,7 +240,7 @@ public abstract class SchemaDefine {
// NOTE: travis-ci fails if class Entity implements Nameable
public abstract static class Entity extends AuthElement
implements org.apache.hugegraph.type.Nameable {
implements org.apache.hugegraph.type.Nameable {
private static final long serialVersionUID = 4113319546914811762L;
@ -260,7 +258,7 @@ public abstract class SchemaDefine {
vertex.label(), entity.label());
entity.id((Id) vertex.id());
for (Iterator<VertexProperty<Object>> iter = vertex.properties();
iter.hasNext();) {
iter.hasNext(); ) {
VertexProperty<Object> prop = iter.next();
entity.property(prop.key(), prop.value());
}
@ -310,7 +308,7 @@ public abstract class SchemaDefine {
edge.label(), relationship.label());
relationship.id((Id) edge.id());
for (Iterator<Property<Object>> iter = edge.properties();
iter.hasNext();) {
iter.hasNext(); ) {
Property<Object> prop = iter.next();
relationship.property(prop.key(), prop.value());
}

View File

@ -411,13 +411,13 @@ public class StandardAuthManager implements AuthManager {
Id adminGroupId = project.adminGroupId();
Id opGroupId = project.opGroupId();
HugeAccess adminGroupWriteAccess = new HugeAccess(
adminGroupId, targetId,
HugePermission.WRITE);
adminGroupId, targetId,
HugePermission.WRITE);
// Ditto
adminGroupWriteAccess.creator(project.creator());
HugeAccess adminGroupReadAccess = new HugeAccess(
adminGroupId, targetId,
HugePermission.READ);
adminGroupId, targetId,
HugePermission.READ);
// Ditto
adminGroupReadAccess.creator(project.creator());
HugeAccess opGroupReadAccess = new HugeAccess(opGroupId, targetId,
@ -634,7 +634,7 @@ public class StandardAuthManager implements AuthManager {
@Override
public String loginUser(String username, String password)
throws AuthenticationException {
throws AuthenticationException {
HugeUser user = this.matchUser(username, password);
if (user == null) {
String msg = "Incorrect username or password";
@ -672,10 +672,10 @@ public class StandardAuthManager implements AuthManager {
Claims payload = null;
boolean needBuildCache = false;
if (username == null) {
try{
try {
payload = this.tokenGenerator.verify(token);
}catch (Throwable t){
LOG.error(String.format("Failed to verify token:[ %s ], cause:",token),t);
} catch (Throwable t) {
LOG.error(String.format("Failed to verify token:[ %s ], cause:", token), t);
return new UserWithRole("");
}
username = (String) payload.get(AuthConstant.TOKEN_USER_NAME);

View File

@ -22,7 +22,6 @@ import java.util.Date;
import java.util.Map;
import javax.crypto.SecretKey;
import jakarta.ws.rs.NotAuthorizedException;
import org.apache.hugegraph.config.AuthOptions;
import org.apache.hugegraph.config.HugeConfig;
@ -34,6 +33,7 @@ import io.jsonwebtoken.JwtException;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.security.Keys;
import jakarta.ws.rs.NotAuthorizedException;
public class TokenGenerator {

View File

@ -44,7 +44,7 @@ public class BackendException extends HugeException {
}
public static final void check(boolean expression, String message, Object... args)
throws BackendException {
throws BackendException {
if (!expression) {
throw new BackendException(message, args);
}

View File

@ -22,10 +22,9 @@ import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.LongAdder;
import java.util.function.Function;
import org.slf4j.Logger;
import org.apache.hugegraph.perf.PerfUtil.Watched;
import org.apache.hugegraph.util.Log;
import org.slf4j.Logger;
public abstract class AbstractCache<K, V> implements Cache<K, V> {
@ -183,7 +182,7 @@ public abstract class AbstractCache<K, V> implements Cache<K, V> {
int expireItems = 0;
long current = now();
for (Iterator<CacheNode<K, V>> it = this.nodes(); it.hasNext();) {
for (Iterator<CacheNode<K, V>> it = this.nodes(); it.hasNext(); ) {
CacheNode<K, V> node = it.next();
if (current - node.time() >= expireTime) {
// Remove item while iterating map (it must be ConcurrentMap)

View File

@ -24,12 +24,11 @@ import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.Log;
import org.slf4j.Logger;
public class CacheManager {
@ -69,7 +68,7 @@ public class CacheManager {
public void run() {
try {
for (Entry<String, Cache<Id, Object>> entry :
caches().entrySet()) {
caches().entrySet()) {
this.tick(entry.getKey(), entry.getValue());
}
} catch (Throwable e) {
@ -97,7 +96,7 @@ public class CacheManager {
}
public <V> Map<String, Cache<Id, V>> caches() {
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
Map<String, Cache<Id, V>> caches = (Map) this.caches;
return Collections.unmodifiableMap(caches);
}

View File

@ -30,7 +30,11 @@ public interface CacheNotifier extends AutoCloseable {
void reload();
interface GraphCacheNotifier extends CacheNotifier {}
interface GraphCacheNotifier extends CacheNotifier {
interface SchemaCacheNotifier extends CacheNotifier {}
}
interface SchemaCacheNotifier extends CacheNotifier {
}
}

View File

@ -19,8 +19,8 @@ package org.apache.hugegraph.backend.cache;
import java.util.Iterator;
import org.apache.hugegraph.backend.query.Query;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.query.Query;
import org.apache.hugegraph.backend.store.BackendEntry;
import org.apache.hugegraph.backend.store.BackendFeatures;
import org.apache.hugegraph.backend.store.BackendMutation;

View File

@ -25,15 +25,15 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.backend.cache.CachedBackendStore.QueryId;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.query.IdQuery;
import org.apache.hugegraph.backend.query.Query;
import org.apache.hugegraph.backend.query.QueryResults;
import org.apache.hugegraph.backend.store.BackendMutation;
import org.apache.hugegraph.backend.store.BackendStore;
import org.apache.hugegraph.backend.store.ram.RamTable;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.query.IdQuery;
import org.apache.hugegraph.backend.query.QueryResults;
import org.apache.hugegraph.backend.tx.GraphTransaction;
import org.apache.hugegraph.config.CoreOptions;
import org.apache.hugegraph.config.HugeConfig;
@ -49,6 +49,7 @@ import org.apache.hugegraph.structure.HugeVertex;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.Events;
import com.google.common.collect.ImmutableSet;
public final class CachedGraphTransaction extends GraphTransaction {

View File

@ -23,12 +23,12 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import org.apache.hugegraph.backend.store.BackendStore;
import org.apache.hugegraph.backend.store.ram.IntObjectMap;
import org.apache.hugegraph.backend.tx.SchemaTransaction;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.id.IdGenerator;
import org.apache.hugegraph.backend.store.BackendStore;
import org.apache.hugegraph.backend.store.ram.IntObjectMap;
import org.apache.hugegraph.backend.tx.SchemaTransaction;
import org.apache.hugegraph.config.CoreOptions;
import org.apache.hugegraph.event.EventHub;
import org.apache.hugegraph.event.EventListener;
@ -37,6 +37,7 @@ import org.apache.hugegraph.schema.SchemaElement;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.Events;
import com.google.common.collect.ImmutableSet;
public final class CachedSchemaTransaction extends SchemaTransaction {
@ -437,7 +438,7 @@ public final class CachedSchemaTransaction extends SchemaTransaction {
}
private static class CachedTypes
extends ConcurrentHashMap<HugeType, Boolean> {
extends ConcurrentHashMap<HugeType, Boolean> {
private static final long serialVersionUID = -2215549791679355996L;
}

View File

@ -24,14 +24,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
import org.apache.hugegraph.backend.store.BackendEntry;
import org.apache.hugegraph.backend.store.BackendEntry.BackendColumn;
import org.caffinitas.ohc.CacheSerializer;
import org.caffinitas.ohc.CloseableIterator;
import org.caffinitas.ohc.Eviction;
import org.caffinitas.ohc.OHCache;
import org.caffinitas.ohc.OHCacheBuilder;
import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.backend.id.Id;
@ -39,6 +31,8 @@ import org.apache.hugegraph.backend.serializer.AbstractSerializer;
import org.apache.hugegraph.backend.serializer.BinaryBackendEntry;
import org.apache.hugegraph.backend.serializer.BinarySerializer;
import org.apache.hugegraph.backend.serializer.BytesBuffer;
import org.apache.hugegraph.backend.store.BackendEntry;
import org.apache.hugegraph.backend.store.BackendEntry.BackendColumn;
import org.apache.hugegraph.structure.HugeEdge;
import org.apache.hugegraph.structure.HugeVertex;
import org.apache.hugegraph.type.HugeType;
@ -46,6 +40,11 @@ import org.apache.hugegraph.type.define.DataType;
import org.apache.hugegraph.util.Bytes;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.InsertionOrderUtil;
import org.caffinitas.ohc.CacheSerializer;
import org.caffinitas.ohc.CloseableIterator;
import org.caffinitas.ohc.Eviction;
import org.caffinitas.ohc.OHCache;
import org.caffinitas.ohc.OHCacheBuilder;
public class OffheapCache extends AbstractCache<Id, Object> {
@ -119,7 +118,7 @@ public class OffheapCache extends AbstractCache<Id, Object> {
}
if (serializedSize > VALUE_SIZE_TO_SKIP) {
LOG.info("Skip to cache '{}' due to value size {} > limit {}",
id, serializedSize, VALUE_SIZE_TO_SKIP);
id, serializedSize, VALUE_SIZE_TO_SKIP);
return false;
}
@ -334,13 +333,13 @@ public class OffheapCache extends AbstractCache<Id, Object> {
private HugeException unsupported(ValueType type) {
throw new HugeException(
"Unsupported deserialize type: %s", type);
"Unsupported deserialize type: %s", type);
}
private HugeException unsupported(Object value) {
throw new HugeException(
"Unsupported type of serialize value: '%s'(%s)",
value, value.getClass());
"Unsupported type of serialize value: '%s'(%s)",
value, value.getClass());
}
}

View File

@ -156,7 +156,7 @@ public class RamCache extends AbstractCache<Id, Object> {
@Override
protected Iterator<CacheNode<Id, Object>> nodes() {
Iterator<LinkNode<Id, Object>> iter = this.map.values().iterator();
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
Iterator<CacheNode<Id, Object>> iterSuper = (Iterator) iter;
return iterSuper;
}
@ -280,8 +280,8 @@ public class RamCache extends AbstractCache<Id, Object> {
/**
* Reset the head node and rear node
* NOTE:
* only called by LinkedQueueNonBigLock() without lock
* or called by clear() with lock(head, rear)
* only called by LinkedQueueNonBigLock() without lock
* or called by clear() with lock(head, rear)
*/
private void reset() {
this.head.prev = this.empty;
@ -316,7 +316,7 @@ public class RamCache extends AbstractCache<Id, Object> {
List<K> keys = this.dumpKeys();
if (keys.contains(key)) {
throw new RuntimeException(String.format(
"Expect %s should be not in %s", key, keys));
"Expect %s should be not in %s", key, keys));
}
return true;
}
@ -338,8 +338,8 @@ public class RamCache extends AbstractCache<Id, Object> {
int selfPos = keys.indexOf(self.key());
if (prevPos > selfPos && selfPos != -1) {
throw new RuntimeException(String.format(
"Expect %s should be before %s, actual %s",
prev.key(), self.key(), keys));
"Expect %s should be before %s, actual %s",
prev.key(), self.key(), keys));
}
return true;
}

View File

@ -35,12 +35,12 @@ import org.apache.hugegraph.util.StringEncoding;
*/
public class EdgeId implements Id {
public static final HugeKeys[] KEYS = new HugeKeys[] {
HugeKeys.OWNER_VERTEX,
HugeKeys.DIRECTION,
HugeKeys.LABEL,
HugeKeys.SORT_VALUES,
HugeKeys.OTHER_VERTEX
public static final HugeKeys[] KEYS = new HugeKeys[]{
HugeKeys.OWNER_VERTEX,
HugeKeys.DIRECTION,
HugeKeys.LABEL,
HugeKeys.SORT_VALUES,
HugeKeys.OTHER_VERTEX
};
private final Id ownerVertexId;
@ -135,17 +135,17 @@ public class EdgeId implements Id {
}
if (this.directed) {
this.cache = SplicingIdGenerator.concat(
IdUtil.writeString(this.ownerVertexId),
this.direction.type().string(),
IdUtil.writeLong(this.edgeLabelId),
this.sortValues,
IdUtil.writeString(this.otherVertexId));
IdUtil.writeString(this.ownerVertexId),
this.direction.type().string(),
IdUtil.writeLong(this.edgeLabelId),
this.sortValues,
IdUtil.writeString(this.otherVertexId));
} else {
this.cache = SplicingIdGenerator.concat(
IdUtil.writeString(this.sourceVertexId()),
IdUtil.writeLong(this.edgeLabelId),
this.sortValues,
IdUtil.writeString(this.targetVertexId()));
IdUtil.writeString(this.sourceVertexId()),
IdUtil.writeLong(this.edgeLabelId),
this.sortValues,
IdUtil.writeString(this.targetVertexId()));
}
return this.cache;
}
@ -233,7 +233,7 @@ public class EdgeId implements Id {
}
public static EdgeId parse(String id, boolean returnNullIfError)
throws NotFoundException {
throws NotFoundException {
String[] idParts = SplicingIdGenerator.split(id);
if (!(idParts.length == 4 || idParts.length == 5)) {
if (returnNullIfError) {
@ -284,10 +284,10 @@ public class EdgeId implements Id {
public static String asStoredString(Id id) {
EdgeId eid = (EdgeId) id;
return SplicingIdGenerator.concat(
IdUtil.writeStoredString(eid.sourceVertexId()),
IdGenerator.asStoredString(eid.edgeLabelId()),
eid.sortValues(),
IdUtil.writeStoredString(eid.targetVertexId()));
IdUtil.writeStoredString(eid.sourceVertexId()),
IdGenerator.asStoredString(eid.edgeLabelId()),
eid.sortValues(),
IdUtil.writeStoredString(eid.targetVertexId()));
}
public static String concat(String... ids) {

View File

@ -20,7 +20,6 @@ package org.apache.hugegraph.backend.id;
import java.nio.ByteBuffer;
import org.apache.commons.lang3.StringUtils;
import org.apache.hugegraph.backend.id.Id.IdType;
import org.apache.hugegraph.backend.serializer.BytesBuffer;

View File

@ -16,8 +16,6 @@ package org.apache.hugegraph.backend.id;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger;
import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.HugeGraphParams;
@ -27,13 +25,14 @@ import org.apache.hugegraph.structure.HugeVertex;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.Log;
import org.apache.hugegraph.util.TimeUtil;
import org.slf4j.Logger;
public class SnowflakeIdGenerator extends IdGenerator {
private static final Logger LOG = Log.logger(SnowflakeIdGenerator.class);
private static final Map<String, SnowflakeIdGenerator> INSTANCES =
new ConcurrentHashMap<>();
new ConcurrentHashMap<>();
private final boolean forceString;
private final IdWorker idWorker;
@ -114,13 +113,13 @@ public class SnowflakeIdGenerator extends IdGenerator {
// Sanity check for workerId
if (workerId > MAX_WORKER_ID || workerId < 0) {
throw new IllegalArgumentException(String.format(
"Worker id can't > %d or < 0",
MAX_WORKER_ID));
"Worker id can't > %d or < 0",
MAX_WORKER_ID));
}
if (datacenterId > MAX_DC_ID || datacenterId < 0) {
throw new IllegalArgumentException(String.format(
"Datacenter id can't > %d or < 0",
MAX_DC_ID));
"Datacenter id can't > %d or < 0",
MAX_DC_ID));
}
this.workerId = workerId;
this.datacenterId = datacenterId;

View File

@ -70,8 +70,9 @@ public class SplicingIdGenerator extends IdGenerator {
/**
* Concat multiple ids into one composite id with IDS_SPLITOR
*
* @param ids the string id values to be concatted
* @return concatted string value
* @return concatted string value
*/
public static String concat(String... ids) {
// NOTE: must support string id when using this method
@ -80,8 +81,9 @@ public class SplicingIdGenerator extends IdGenerator {
/**
* Split a composite id into multiple ids with IDS_SPLITOR
*
* @param ids the string id value to be splitted
* @return splitted string values
* @return splitted string values
*/
public static String[] split(String ids) {
return IdUtil.unescape(ids, IDS_SPLITOR_STR, ESCAPE_STR);
@ -89,8 +91,9 @@ public class SplicingIdGenerator extends IdGenerator {
/**
* Concat property values with NAME_SPLITOR
*
* @param values the property values to be concatted
* @return concatted string value
* @return concatted string value
*/
public static String concatValues(List<?> values) {
// Convert the object list to string array
@ -104,8 +107,9 @@ public class SplicingIdGenerator extends IdGenerator {
/**
* Concat property values with NAME_SPLITOR
*
* @param values the property values to be concatted
* @return concatted string value
* @return concatted string value
*/
public static String concatValues(Object... values) {
return concatValues(Arrays.asList(values));
@ -113,8 +117,9 @@ public class SplicingIdGenerator extends IdGenerator {
/**
* Concat multiple parts into a single id with ID_SPLITOR
*
* @param parts the string id values to be spliced
* @return spliced id object
* @return spliced id object
*/
public static Id splicing(String... parts) {
String escaped = IdUtil.escape(ID_SPLITOR, ESCAPE, parts);
@ -123,8 +128,9 @@ public class SplicingIdGenerator extends IdGenerator {
/**
* Parse a single id into multiple parts with ID_SPLITOR
*
* @param id the id object to be parsed
* @return parsed string id parts
* @return parsed string id parts
*/
public static String[] parse(Id id) {
return IdUtil.unescape(id.asString(), ID_SPLITOR_STR, ESCAPE_STR);

View File

@ -23,15 +23,14 @@ import java.util.Set;
import java.util.function.Function;
import org.apache.commons.lang.NotImplementedException;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.query.ConditionQuery;
import org.apache.hugegraph.backend.query.Query;
import org.apache.hugegraph.backend.store.BackendEntry;
import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.iterator.CIter;
import org.apache.hugegraph.iterator.Metadatable;
import org.apache.hugegraph.util.E;
import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator;
public abstract class IdHolder {
@ -133,7 +132,7 @@ public abstract class IdHolder {
}
public static class BatchIdHolder extends IdHolder
implements CIter<IdHolder> {
implements CIter<IdHolder> {
private final Iterator<BackendEntry> entries;
private final Function<Long, Set<Id>> fetcher;

View File

@ -21,11 +21,10 @@ import java.util.NoSuchElementException;
import org.apache.hugegraph.backend.query.Query;
import org.apache.hugegraph.backend.query.QueryResults;
import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator;
import org.apache.hugegraph.exception.NotSupportException;
import org.apache.hugegraph.iterator.CIter;
import org.apache.hugegraph.util.E;
import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator;
public class PageEntryIterator<R> implements CIter<R> {

View File

@ -20,6 +20,7 @@ package org.apache.hugegraph.backend.page;
import java.util.Set;
import org.apache.hugegraph.backend.id.Id;
import com.google.common.collect.ImmutableSet;
public final class PageIds {

View File

@ -22,14 +22,14 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.page.IdHolder.BatchIdHolder;
import org.apache.hugegraph.backend.page.IdHolder.FixedIdHolder;
import org.apache.hugegraph.backend.query.ConditionQuery;
import org.apache.hugegraph.backend.query.ConditionQuery.OptimizedType;
import org.apache.hugegraph.backend.query.IdQuery;
import org.apache.hugegraph.backend.query.Query;
import org.apache.hugegraph.backend.query.QueryResults;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.page.IdHolder.BatchIdHolder;
import org.apache.hugegraph.backend.page.IdHolder.FixedIdHolder;
import org.apache.hugegraph.util.Bytes;
import org.apache.hugegraph.util.E;
@ -46,7 +46,7 @@ public final class QueryList<R> {
this.queries = new ArrayList<>();
}
protected Query parent() {
Query parent() {
return this.parent;
}
@ -98,7 +98,7 @@ public final class QueryList<R> {
return QueryResults.flatMap(this.queries.iterator(), FlattenQuery::iterator);
}
protected PageResults<R> fetchNext(PageInfo pageInfo, long pageSize) {
PageResults<R> fetchNext(PageInfo pageInfo, long pageSize) {
FlattenQuery<R> query = null;
int offset = pageInfo.offset();
int visited = 0;
@ -126,16 +126,18 @@ public final class QueryList<R> {
/**
* For non-paging situation
* @return BackendEntry iterator
*
* @return BackendEntry iterator
*/
QueryResults<R> iterator();
/**
* For paging situation
* @param index position IdHolder(Query)
* @param page set query page
* @param pageSize set query page size
* @return BackendEntry iterator with page
*
* @param index position IdHolder(Query)
* @param page set query page
* @param pageSize set query page size
* @return BackendEntry iterator with page
*/
PageResults<R> iterator(int index, String page, long pageSize);
@ -323,8 +325,8 @@ public final class QueryList<R> {
public static class PageResults<R> {
public static final PageResults<?> EMPTY = new PageResults<>(
QueryResults.empty(),
PageState.EMPTY);
QueryResults.empty(),
PageState.EMPTY);
private final QueryResults<R> results;
private final PageState pageState;

View File

@ -22,11 +22,12 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.hugegraph.backend.query.Query;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.page.IdHolder.FixedIdHolder;
import org.apache.hugegraph.backend.query.Query;
import org.apache.hugegraph.util.CollectionUtil;
import org.apache.hugegraph.util.InsertionOrderUtil;
import com.google.common.collect.ImmutableSet;
public class SortByCountIdHolderList extends IdHolderList {

View File

@ -43,7 +43,7 @@ public class BatchConditionQuery extends ConditionQuery {
if (this.in == null) {
assert !this.containsRelation(RelationType.IN);
this.resetConditions(InsertionOrderUtil.newList(
(List<Condition>) query.conditions()));
(List<Condition>) query.conditions()));
this.unsetCondition(key);
List<Object> list = new ArrayList<>(this.batchSize);

View File

@ -17,7 +17,6 @@
package org.apache.hugegraph.backend.query;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
@ -29,9 +28,8 @@ import java.util.function.BiFunction;
import java.util.function.BiPredicate;
import org.apache.commons.lang.ArrayUtils;
import org.apache.hugegraph.backend.store.Shard;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.store.Shard;
import org.apache.hugegraph.structure.HugeElement;
import org.apache.hugegraph.structure.HugeProperty;
import org.apache.hugegraph.type.define.HugeKeys;
@ -39,6 +37,7 @@ import org.apache.hugegraph.util.Bytes;
import org.apache.hugegraph.util.DateUtil;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.NumericUtil;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@ -49,7 +48,7 @@ public abstract class Condition {
RELATION,
AND,
OR,
NOT;
NOT
}
public enum RelationType implements BiPredicate<Object, Object> {
@ -146,12 +145,12 @@ public abstract class Condition {
private final Class<?> v2Class;
RelationType(String op,
BiFunction<Object, Object, Boolean> tester) {
BiFunction<Object, Object, Boolean> tester) {
this(op, null, null, tester);
}
RelationType(String op, Class<?> v1Class, Class<?> v2Class,
BiFunction<Object, Object, Boolean> tester) {
BiFunction<Object, Object, Boolean> tester) {
this.operator = op;
this.tester = tester;
this.v1Class = v1Class;
@ -164,7 +163,8 @@ public abstract class Condition {
/**
* Determine two values of any type equal
* @param first is actual value
*
* @param first is actual value
* @param second is value in query condition
* @return true if equal, otherwise false
*/
@ -188,13 +188,14 @@ public abstract class Condition {
/**
* Determine two numbers equal
* @param first is actual value, might be Number/Date or String, It is
* probably that the `first` is serialized to String.
*
* @param first is actual value, might be Number/Date or String, It is
* probably that the `first` is serialized to String.
* @param second is value in query condition, must be Number/Date
* @return the value 0 if first is numerically equal to second;
* a value less than 0 if first is numerically less than
* second; and a value greater than 0 if first is
* numerically greater than second.
* a value less than 0 if first is numerically less than
* second; and a value greater than 0 if first is
* numerically greater than second.
*/
private static int compare(final Object first, final Object second) {
assert second != null;
@ -206,9 +207,9 @@ public abstract class Condition {
}
throw new IllegalArgumentException(String.format(
"Can't compare between %s(%s) and %s(%s)", first,
first == null ? null : first.getClass().getSimpleName(),
second, second.getClass().getSimpleName()));
"Can't compare between %s(%s) and %s(%s)", first,
first == null ? null : first.getClass().getSimpleName(),
second, second.getClass().getSimpleName()));
}
private static int compareDate(Object first, Date second) {
@ -220,9 +221,9 @@ public abstract class Condition {
}
throw new IllegalArgumentException(String.format(
"Can't compare between %s(%s) and %s(%s)",
first, first.getClass().getSimpleName(),
second, second.getClass().getSimpleName()));
"Can't compare between %s(%s) and %s(%s)",
first, first.getClass().getSimpleName(),
second, second.getClass().getSimpleName()));
}
private void checkBaseType(Object value, Class<?> clazz) {
@ -543,7 +544,8 @@ public abstract class Condition {
}
}
public static class Not extends Condition implements Serializable {
public static class Not extends Condition {
Condition condition;
public Not(Condition condition) {
@ -629,8 +631,8 @@ public abstract class Condition {
protected Object serialValue;
protected static final Set<RelationType> UNFLATTEN_RELATION_TYPES =
ImmutableSet.of(RelationType.IN, RelationType.NOT_IN,
RelationType.TEXT_CONTAINS_ANY);
ImmutableSet.of(RelationType.IN, RelationType.NOT_IN,
RelationType.TEXT_CONTAINS_ANY);
@Override
public ConditionType type() {

View File

@ -63,10 +63,11 @@ public class ConditionQuery extends IdQuery {
public static final char INDEX_SYM_MAX = '\u0003';
// Note: here we use "new String" to distinguish normal string code
public static final String INDEX_VALUE_NULL = new String("<null>");
public static final String INDEX_VALUE_EMPTY = new String("<empty>");
public static final String INDEX_VALUE_NULL = "<null>";
public static final String INDEX_VALUE_EMPTY = "<empty>";
public static final Set<String> IGNORE_SYM_SET;
static {
List<String> list = new ArrayList<>(INDEX_SYM_MAX - INDEX_SYM_MIN);
for (char ch = INDEX_SYM_MIN; ch <= INDEX_SYM_MAX; ch++) {
@ -472,6 +473,7 @@ public class ConditionQuery extends IdQuery {
/**
* This method is only used for secondary index scenario,
* its relation must be EQ
*
* @param fields the user property fields
* @return the corresponding user property serial values of fields
*/
@ -493,8 +495,8 @@ public class ConditionQuery extends IdQuery {
}
if (!got) {
throw new BackendException(
"No such userprop named '%s' in the query '%s'",
field, this);
"No such userprop named '%s' in the query '%s'",
field, this);
}
}
return concatValues(values);
@ -652,7 +654,7 @@ public class ConditionQuery extends IdQuery {
public void optimized(OptimizedType optimizedType) {
assert this.optimizedType.ordinal() <= optimizedType.ordinal() :
this.optimizedType + " !<= " + optimizedType;
this.optimizedType + " !<= " + optimizedType;
this.optimizedType = optimizedType;
Query originQuery = this.originQuery();
@ -722,7 +724,8 @@ public class ConditionQuery extends IdQuery {
public static String concatValues(Object value) {
if (value instanceof String) {
return escapeSpecialValueIfNeeded((String) value);
} if (value instanceof List) {
}
if (value instanceof List) {
return concatValues((List<?>) value);
} else if (needConvertNumber(value)) {
return LongEncoding.encodeNumber(value);
@ -798,7 +801,7 @@ public class ConditionQuery extends IdQuery {
this.filed2IndexValues.putIfAbsent(indexField, new HashMap<>());
}
Map<Id, Set<Object>> element2IndexValueMap =
this.filed2IndexValues.get(indexField);
this.filed2IndexValues.get(indexField);
if (element2IndexValueMap.containsKey(elementId)) {
element2IndexValueMap.get(elementId).add(indexValue);
} else {
@ -843,7 +846,7 @@ public class ConditionQuery extends IdQuery {
}
Condition.UserpropRelation propRelation =
(Condition.UserpropRelation) cond;
(Condition.UserpropRelation) cond;
Id propId = propRelation.key();
Set<Object> fieldValues = this.toRemoveIndexValues(propId,
element.id());

View File

@ -40,7 +40,7 @@ import com.google.common.collect.ImmutableSet;
public final class ConditionQueryFlatten {
private static final Set<HugeKeys> SPECIAL_KEYS = ImmutableSet.of(
HugeKeys.LABEL
HugeKeys.LABEL
);
public static List<ConditionQuery> flatten(ConditionQuery query) {

View File

@ -27,6 +27,7 @@ import org.apache.hugegraph.structure.HugeElement;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.InsertionOrderUtil;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@ -157,7 +158,7 @@ public class IdQuery extends Query {
@Override
public Set<Id> ids() {
return this.id == null ? ImmutableSet.of() :
ImmutableSet.of(this.id);
ImmutableSet.of(this.id);
}
@Override

View File

@ -412,8 +412,8 @@ public class Query implements Cloneable {
query = query.substring(0, MAX_CHARS) + "...";
}
throw new LimitExceedException(
"Too many records(must <= %s) for the query: %s",
this.capacity, query);
"Too many records(must <= %s) for the query: %s",
this.capacity, query);
}
}
@ -611,8 +611,8 @@ public class Query implements Cloneable {
public static void checkForceCapacity(long count) throws LimitExceedException {
if (count > Query.DEFAULT_CAPACITY) {
throw new LimitExceedException(
"Too many records(must <= %s) for one query",
Query.DEFAULT_CAPACITY);
"Too many records(must <= %s) for one query",
Query.DEFAULT_CAPACITY);
}
}

View File

@ -26,8 +26,6 @@ import java.util.NoSuchElementException;
import java.util.Set;
import java.util.function.Function;
import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator;
import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.iterator.CIter;
@ -38,13 +36,14 @@ import org.apache.hugegraph.perf.PerfUtil.Watched;
import org.apache.hugegraph.type.Idfiable;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.InsertionOrderUtil;
import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator;
public class QueryResults<R> {
private static final Iterator<?> EMPTY_ITERATOR = new EmptyIterator<>();
private static final QueryResults<?> EMPTY = new QueryResults<>(
emptyIterator(), Query.NONE);
emptyIterator(), Query.NONE);
private final Iterator<R> results;
private final List<Query> queries;
@ -97,7 +96,7 @@ public class QueryResults<R> {
}
public <T extends Idfiable> Iterator<T> keepInputOrderIfNeeded(
Iterator<T> origin) {
Iterator<T> origin) {
if (!origin.hasNext()) {
// None result found
return origin;
@ -216,7 +215,7 @@ public class QueryResults<R> {
}
public static <T, R> QueryResults<R> flatMap(
Iterator<T> iterator, Function<T, QueryResults<R>> func) {
Iterator<T> iterator, Function<T, QueryResults<R>> func) {
@SuppressWarnings("unchecked")
QueryResults<R>[] qr = new QueryResults[1];
qr[0] = new QueryResults<>(new FlatMapperIterator<>(iterator, i -> {
@ -266,7 +265,9 @@ public class QueryResults<R> {
return (Iterator<T>) EMPTY_ITERATOR;
}
public interface Fetcher<R> extends Function<Query, QueryResults<R>> {}
public interface Fetcher<R> extends Function<Query, QueryResults<R>> {
}
private static class EmptyIterator<T> implements CIter<T> {

View File

@ -19,20 +19,18 @@ package org.apache.hugegraph.backend.serializer;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.backend.id.EdgeId;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.query.ConditionQuery;
import org.apache.hugegraph.backend.query.IdQuery;
import org.apache.hugegraph.backend.query.Query;
import org.apache.hugegraph.backend.store.BackendEntry;
import org.apache.hugegraph.iterator.CIter;
import org.apache.hugegraph.structure.HugeVertex;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.config.HugeConfig;
import org.apache.hugegraph.iterator.CIter;
import org.apache.hugegraph.type.HugeType;
import org.apache.tinkerpop.gremlin.structure.Edge;
public abstract class AbstractSerializer
implements GraphSerializer, SchemaSerializer {
implements GraphSerializer, SchemaSerializer {
protected HugeConfig config;
@ -41,7 +39,7 @@ public abstract class AbstractSerializer
}
public AbstractSerializer(HugeConfig config) {
this.config = config;
this.config = config;
}
protected BackendEntry convertEntry(BackendEntry entry) {

View File

@ -22,12 +22,12 @@ import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.id.IdGenerator;
import org.apache.hugegraph.backend.store.BackendEntry;
import org.apache.hugegraph.backend.store.BackendEntry.BackendColumn;
import org.apache.hugegraph.config.HugeConfig;
import org.apache.hugegraph.schema.VertexLabel;
import org.apache.hugegraph.structure.HugeProperty;
import org.apache.hugegraph.structure.HugeVertex;
import org.apache.hugegraph.structure.HugeVertexProperty;
import org.apache.hugegraph.type.define.HugeKeys;
import org.apache.hugegraph.config.HugeConfig;
public class BinaryScatterSerializer extends BinarySerializer {

View File

@ -17,8 +17,6 @@
package org.apache.hugegraph.backend.serializer;
import static org.apache.hugegraph.schema.SchemaElement.UNDEF;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
@ -26,20 +24,12 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.lang.NotImplementedException;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.backend.id.EdgeId;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.id.IdGenerator;
import org.apache.hugegraph.backend.page.PageState;
import org.apache.hugegraph.backend.store.BackendEntry;
import org.apache.hugegraph.backend.store.BackendEntry.BackendColumn;
import org.apache.hugegraph.iterator.CIter;
import org.apache.hugegraph.iterator.MapperIterator;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.type.define.EdgeLabelType;
import org.apache.hugegraph.util.*;
import org.apache.hugegraph.backend.query.Condition;
import org.apache.hugegraph.backend.query.Condition.RangeConditions;
import org.apache.hugegraph.backend.query.ConditionQuery;
@ -47,7 +37,11 @@ import org.apache.hugegraph.backend.query.IdPrefixQuery;
import org.apache.hugegraph.backend.query.IdRangeQuery;
import org.apache.hugegraph.backend.query.Query;
import org.apache.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId;
import org.apache.hugegraph.backend.store.BackendEntry;
import org.apache.hugegraph.backend.store.BackendEntry.BackendColumn;
import org.apache.hugegraph.config.HugeConfig;
import org.apache.hugegraph.iterator.CIter;
import org.apache.hugegraph.iterator.MapperIterator;
import org.apache.hugegraph.schema.EdgeLabel;
import org.apache.hugegraph.schema.IndexLabel;
import org.apache.hugegraph.schema.PropertyKey;
@ -60,6 +54,7 @@ import org.apache.hugegraph.structure.HugeIndex;
import org.apache.hugegraph.structure.HugeProperty;
import org.apache.hugegraph.structure.HugeVertex;
import org.apache.hugegraph.structure.HugeVertexProperty;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.type.define.AggregateType;
import org.apache.hugegraph.type.define.Cardinality;
import org.apache.hugegraph.type.define.DataType;
@ -71,7 +66,10 @@ import org.apache.hugegraph.type.define.IndexType;
import org.apache.hugegraph.type.define.SchemaStatus;
import org.apache.hugegraph.type.define.SerialEnum;
import org.apache.hugegraph.type.define.WriteType;
import org.apache.hugegraph.util.Bytes;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.JsonUtil;
import org.apache.hugegraph.util.NumericUtil;
import org.apache.hugegraph.util.StringEncoding;
import org.apache.tinkerpop.gremlin.structure.Edge;
@ -214,7 +212,7 @@ public class BinarySerializer extends AbstractSerializer {
} else {
if (!(value instanceof Collection)) {
throw new BackendException(
"Invalid value of non-single property: %s", value);
"Invalid value of non-single property: %s", value);
}
owner.addProperty(pkey, value);
}
@ -532,7 +530,6 @@ public class BinarySerializer extends AbstractSerializer {
@Override
public CIter<Edge> readEdges(HugeGraph graph, BackendEntry bytesEntry) {
BinaryBackendEntry entry = this.convertEntry(bytesEntry);
// Parse id
@ -914,7 +911,9 @@ public class BinarySerializer extends AbstractSerializer {
buffer.write(parsedEntry.id().asBytes());
buffer.write(bytes);
parsedEntry = new BinaryBackendEntry(originEntry.type(), new BinaryId(buffer.bytes(),
BytesBuffer.wrap(buffer.bytes()).readEdgeId()));
BytesBuffer.wrap(
buffer.bytes())
.readEdgeId()));
for (BackendColumn col : originEntry.columns()) {
parsedEntry.column(buffer.bytes(), col.value);
@ -962,9 +961,7 @@ public class BinarySerializer extends AbstractSerializer {
protected static boolean indexFieldValuesUnmatched(byte[] value,
Object fieldValues) {
if (value != null && value.length > 0 && fieldValues != null) {
if (!StringEncoding.decode(value).equals(fieldValues)) {
return true;
}
return !StringEncoding.decode(value).equals(fieldValues);
}
return false;
}

View File

@ -18,7 +18,6 @@
package org.apache.hugegraph.backend.serializer;
import java.io.OutputStream;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Collection;
@ -29,13 +28,14 @@ import org.apache.hugegraph.backend.id.EdgeId;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.id.Id.IdType;
import org.apache.hugegraph.backend.id.IdGenerator;
import org.apache.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId;
import org.apache.hugegraph.schema.PropertyKey;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.type.define.Cardinality;
import org.apache.hugegraph.type.define.DataType;
import org.apache.hugegraph.util.*;
import org.apache.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId;
import org.apache.hugegraph.util.Blob;
import org.apache.hugegraph.util.Bytes;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.KryoUtil;
import org.apache.hugegraph.util.StringEncoding;
@ -170,7 +170,7 @@ public final class BytesBuffer extends OutputStream {
"Capacity exceeds max buffer capacity: %s",
MAX_BUFFER_CAPACITY);
ByteBuffer newBuffer = ByteBuffer.allocate(newCapacity);
((Buffer) this.buffer).flip();
this.buffer.flip();
newBuffer.put(this.buffer);
this.buffer = newBuffer;
}
@ -344,7 +344,7 @@ public final class BytesBuffer extends OutputStream {
* 0xFF is not a valid byte in UTF8 bytes
*/
assert !Bytes.contains(bytes, STRING_ENDING_BYTE_FF) :
"Invalid UTF8 bytes: " + value;
"Invalid UTF8 bytes: " + value;
if (Bytes.contains(bytes, STRING_ENDING_BYTE)) {
E.checkArgument(false,
"Can't contains byte '0x00' in string: '%s'",
@ -421,7 +421,7 @@ public final class BytesBuffer extends OutputStream {
this.write(0x80 | ((value >>> 14) & 0x7f));
}
if (value > 0x7f || value < 0) {
this.write(0x80 | ((value >>> 7) & 0x7f));
this.write(0x80 | ((value >>> 7) & 0x7f));
}
this.write(value & 0x7f);
@ -485,7 +485,7 @@ public final class BytesBuffer extends OutputStream {
this.write(0x80 | ((int) (value >>> 14) & 0x7f));
}
if (value > 0x7fL || value < 0L) {
this.write(0x80 | ((int) (value >>> 7) & 0x7f));
this.write(0x80 | ((int) (value >>> 7) & 0x7f));
}
this.write((int) value & 0x7f);
@ -906,7 +906,7 @@ public final class BytesBuffer extends OutputStream {
value |= this.readUInt16();
break;
case 2:
value |= this.readUInt8() << 16 | this.readUInt16();
value |= (long) this.readUInt8() << 16 | this.readUInt16();
break;
case 3:
value |= this.readUInt32();

View File

@ -23,12 +23,12 @@ import org.apache.hugegraph.backend.query.ConditionQuery;
import org.apache.hugegraph.backend.query.Query;
import org.apache.hugegraph.backend.store.BackendEntry;
import org.apache.hugegraph.iterator.CIter;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.structure.HugeEdge;
import org.apache.hugegraph.structure.HugeEdgeProperty;
import org.apache.hugegraph.structure.HugeIndex;
import org.apache.hugegraph.structure.HugeVertex;
import org.apache.hugegraph.structure.HugeVertexProperty;
import org.apache.hugegraph.type.HugeType;
import org.apache.tinkerpop.gremlin.structure.Edge;
public interface GraphSerializer {
@ -46,6 +46,7 @@ public interface GraphSerializer {
BackendEntry writeEdgeProperty(HugeEdgeProperty<?> prop);
HugeEdge readEdge(HugeGraph graph, BackendEntry entry);
CIter<Edge> readEdges(HugeGraph graph, BackendEntry bytesEntry);
BackendEntry writeIndex(HugeIndex index);

View File

@ -36,12 +36,12 @@ public class MergeIterator<T, R> extends WrappedIterator<T> {
List<Iterator<R>> iterators,
BiFunction<T, R, Boolean> merger) {
E.checkArgumentNotNull(originIterator, "The origin iterator of " +
"MergeIterator can't be null");
"MergeIterator can't be null");
E.checkArgument(iterators != null && !iterators.isEmpty(),
"The iterators of MergeIterator can't be " +
"null or empty");
E.checkArgumentNotNull(merger, "The merger function of " +
"MergeIterator can't be null");
"MergeIterator can't be null");
this.originIterator = originIterator;
this.headElements = new ArrayList<>();

View File

@ -56,7 +56,7 @@ public class SerializerFactory {
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
public static void register(String name, String classPath) {
ClassLoader classLoader = SerializerFactory.class.getClassLoader();
Class<?> clazz;

View File

@ -27,7 +27,6 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.lang3.NotImplementedException;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.store.BackendEntry;
import org.apache.hugegraph.type.HugeType;

View File

@ -32,8 +32,6 @@ import org.apache.hugegraph.backend.query.Condition;
import org.apache.hugegraph.backend.query.ConditionQuery;
import org.apache.hugegraph.backend.query.Query;
import org.apache.hugegraph.backend.store.BackendEntry;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.util.JsonUtil;
import org.apache.hugegraph.config.HugeConfig;
import org.apache.hugegraph.schema.EdgeLabel;
import org.apache.hugegraph.schema.IndexLabel;
@ -48,6 +46,7 @@ import org.apache.hugegraph.structure.HugeIndex;
import org.apache.hugegraph.structure.HugeProperty;
import org.apache.hugegraph.structure.HugeVertex;
import org.apache.hugegraph.structure.HugeVertexProperty;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.type.define.AggregateType;
import org.apache.hugegraph.type.define.Cardinality;
import org.apache.hugegraph.type.define.DataType;
@ -60,6 +59,7 @@ import org.apache.hugegraph.type.define.SchemaStatus;
import org.apache.hugegraph.type.define.SerialEnum;
import org.apache.hugegraph.type.define.WriteType;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.JsonUtil;
public abstract class TableSerializer extends AbstractSerializer {
@ -108,7 +108,7 @@ public abstract class TableSerializer extends AbstractSerializer {
} else {
if (!(value instanceof Collection)) {
throw new BackendException(
"Invalid value of non-single property: %s", value);
"Invalid value of non-single property: %s", value);
}
owner.addProperty(pkey, value);
}
@ -157,9 +157,10 @@ public abstract class TableSerializer extends AbstractSerializer {
/**
* Parse an edge from a entry row
* @param row edge entry
*
* @param row edge entry
* @param vertex null or the source vertex
* @param graph the HugeGraph context object
* @param graph the HugeGraph context object
* @return the source vertex
*/
protected HugeEdge parseEdge(TableBackendEntry.Row row,
@ -560,8 +561,8 @@ public abstract class TableSerializer extends AbstractSerializer {
AggregateType aggregateType = schemaEnum(entry, HugeKeys.AGGREGATE_TYPE,
AggregateType.class);
WriteType writeType = schemaEnumOrDefault(
entry, HugeKeys.WRITE_TYPE,
WriteType.class, WriteType.OLTP);
entry, HugeKeys.WRITE_TYPE,
WriteType.class, WriteType.OLTP);
Object properties = schemaColumn(entry, HugeKeys.PROPERTIES);
SchemaStatus status = schemaEnum(entry, HugeKeys.STATUS,
SchemaStatus.class);
@ -697,9 +698,9 @@ public abstract class TableSerializer extends AbstractSerializer {
}
private static <T extends SerialEnum> T schemaEnumOrDefault(
TableBackendEntry entry,
HugeKeys key, Class<T> clazz,
T defaultValue) {
TableBackendEntry entry,
HugeKeys key, Class<T> clazz,
T defaultValue) {
assert entry.type().isSchema();
Number value = entry.column(key);

View File

@ -165,7 +165,7 @@ public class TextBackendEntry implements BackendEntry, Cloneable {
}
public boolean containsValue(String value) {
return this.columns.values().contains(value);
return this.columns.containsValue(value);
}
public void append(TextBackendEntry entry) {
@ -371,6 +371,7 @@ public class TextBackendEntry implements BackendEntry, Cloneable {
return true;
}
@Override
public int hashCode() {
return this.id().hashCode() ^ this.columns().hashCode();
}

View File

@ -23,16 +23,10 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.NotImplementedException;
import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.backend.store.BackendEntry;
import org.apache.hugegraph.config.HugeConfig;
import org.apache.commons.lang.NotImplementedException;
import org.apache.hugegraph.iterator.CIter;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.util.JsonUtil;
import org.apache.hugegraph.backend.id.EdgeId;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.id.IdGenerator;
@ -43,6 +37,9 @@ import org.apache.hugegraph.backend.query.ConditionQuery;
import org.apache.hugegraph.backend.query.IdPrefixQuery;
import org.apache.hugegraph.backend.query.IdRangeQuery;
import org.apache.hugegraph.backend.query.Query;
import org.apache.hugegraph.backend.store.BackendEntry;
import org.apache.hugegraph.config.HugeConfig;
import org.apache.hugegraph.iterator.CIter;
import org.apache.hugegraph.schema.EdgeLabel;
import org.apache.hugegraph.schema.IndexLabel;
import org.apache.hugegraph.schema.PropertyKey;
@ -56,6 +53,7 @@ import org.apache.hugegraph.structure.HugeIndex.IdWithExpiredTime;
import org.apache.hugegraph.structure.HugeProperty;
import org.apache.hugegraph.structure.HugeVertex;
import org.apache.hugegraph.structure.HugeVertexProperty;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.type.define.AggregateType;
import org.apache.hugegraph.type.define.Cardinality;
import org.apache.hugegraph.type.define.DataType;
@ -67,6 +65,7 @@ import org.apache.hugegraph.type.define.IndexType;
import org.apache.hugegraph.type.define.SchemaStatus;
import org.apache.hugegraph.type.define.WriteType;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.JsonUtil;
import org.apache.tinkerpop.gremlin.structure.Edge;
import com.google.common.collect.ImmutableMap;
@ -75,7 +74,7 @@ public class TextSerializer extends AbstractSerializer {
private static final String VALUE_SPLITOR = TextBackendEntry.VALUE_SPLITOR;
private static final String EDGE_NAME_ENDING =
ConditionQuery.INDEX_SYM_ENDING;
ConditionQuery.INDEX_SYM_ENDING;
private static final String EDGE_OUT_TYPE = writeType(HugeType.EDGE_OUT);
@ -166,7 +165,7 @@ public class TextSerializer extends AbstractSerializer {
} else {
if (!(value instanceof Collection)) {
throw new BackendException(
"Invalid value of non-single property: %s", colValue);
"Invalid value of non-single property: %s", colValue);
}
for (Object v : (Collection<?>) value) {
v = JsonUtil.castNumber(v, pkey.dataType().clazz());
@ -316,7 +315,7 @@ public class TextSerializer extends AbstractSerializer {
HugeVertex vertex = new HugeVertex(graph, id, vertexLabel);
String expiredTime = entry.column(this.formatSyspropName(
HugeKeys.EXPIRED_TIME));
HugeKeys.EXPIRED_TIME));
// Expired time is null when backend entry is fake vertex with edges
if (expiredTime != null) {
vertex.expiredTime(readLong(expiredTime));
@ -395,11 +394,11 @@ public class TextSerializer extends AbstractSerializer {
TextBackendEntry entry = this.convertEntry(backendEntry);
String indexValues = entry.column(
formatSyspropName(HugeKeys.FIELD_VALUES));
formatSyspropName(HugeKeys.FIELD_VALUES));
String indexLabelId = entry.column(
formatSyspropName(HugeKeys.INDEX_LABEL_ID));
formatSyspropName(HugeKeys.INDEX_LABEL_ID));
String elemIds = entry.column(
formatSyspropName(HugeKeys.ELEMENT_IDS));
formatSyspropName(HugeKeys.ELEMENT_IDS));
IndexLabel indexLabel = IndexLabel.label(graph, readId(indexLabelId));
HugeIndex index = new HugeIndex(graph, indexLabel);
@ -875,7 +874,7 @@ public class TextSerializer extends AbstractSerializer {
Map<String, Object> map = (Map<String, Object>) values[i];
idValue = map.get(HugeKeys.ID.string());
expiredTime = ((Number) map.get(
HugeKeys.EXPIRED_TIME.string())).longValue();
HugeKeys.EXPIRED_TIME.string())).longValue();
} else {
idValue = values[i];
expiredTime = 0L;

View File

@ -21,7 +21,7 @@ import org.apache.hugegraph.exception.ConnectionException;
import org.apache.hugegraph.type.HugeType;
public abstract class AbstractBackendStore<Session extends BackendSession>
implements BackendStore {
implements BackendStore {
// TODO: move SystemSchemaStore into backend like MetaStore
private final SystemSchemaStore systemSchemaStore;
@ -43,7 +43,7 @@ public abstract class AbstractBackendStore<Session extends BackendSession>
@Override
public String storedVersion() {
throw new UnsupportedOperationException(
"AbstractBackendStore.storedVersion()");
"AbstractBackendStore.storedVersion()");
}
@Override
@ -68,8 +68,8 @@ public abstract class AbstractBackendStore<Session extends BackendSession>
protected void checkOpened() throws ConnectionException {
if (!this.opened()) {
throw new ConnectionException(
"The '%s' store of %s has not been opened",
this.database(), this.provider().type());
"The '%s' store of %s has not been opened",
this.database(), this.provider().type());
}
}

View File

@ -21,11 +21,8 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import org.apache.hugegraph.backend.store.raft.StoreSnapshotFile;
import org.slf4j.Logger;
import com.alipay.remoting.rpc.RpcServer;
import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.backend.store.raft.StoreSnapshotFile;
import org.apache.hugegraph.config.CoreOptions;
import org.apache.hugegraph.config.HugeConfig;
import org.apache.hugegraph.event.EventHub;
@ -33,9 +30,12 @@ import org.apache.hugegraph.event.EventListener;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.Events;
import org.apache.hugegraph.util.Log;
import org.slf4j.Logger;
import com.alipay.remoting.rpc.RpcServer;
public abstract class AbstractBackendStoreProvider
implements BackendStoreProvider {
implements BackendStoreProvider {
private static final Logger LOG = Log.logger(AbstractBackendStoreProvider.class);

View File

@ -213,7 +213,6 @@ public abstract class BackendEntryIterator implements CIter<BackendEntry> {
@Override
public void close() throws Exception {
return;
}
}
}

View File

@ -46,7 +46,8 @@ public class BackendMutation {
/**
* Add data entry with an action to collection `updates`
* @param entry the backend entry
*
* @param entry the backend entry
* @param action operate action on the entry
*/
@Watched(prefix = "mutation")
@ -72,11 +73,11 @@ public class BackendMutation {
/**
* The optimized scenes include but are not limited to
* 1.If you want to delete an entry, the other mutations previously
* can be ignored.
* can be ignored.
* 2.As similar to the No.1 item, If you want to insert an entry,
* the other mutations previously also can be ignored.
* the other mutations previously also can be ignored.
* 3.If you append an entry and then eliminate it, the new action
* can override the old one.
* can override the old one.
*/
@Watched(prefix = "mutation")
private void optimizeUpdates(BackendEntry entry, Action action) {
@ -85,7 +86,7 @@ public class BackendMutation {
final List<BackendAction> items = this.updates.get(entry.type(), id);
assert items != null;
boolean ignoreCurrent = false;
for (Iterator<BackendAction> iter = items.iterator(); iter.hasNext();) {
for (Iterator<BackendAction> iter = items.iterator(); iter.hasNext(); ) {
BackendAction originItem = iter.next();
Action originAction = originItem.action();
switch (action) {
@ -105,9 +106,9 @@ public class BackendMutation {
if (entry.type().isUniqueIndex() &&
originAction == Action.APPEND) {
throw new IllegalArgumentException(String.format(
"Unique constraint conflict is found in" +
" transaction between %s and %s",
entry, originItem.entry()));
"Unique constraint conflict is found in" +
" transaction between %s and %s",
entry, originItem.entry()));
}
if (originAction == Action.INSERT ||
@ -137,7 +138,7 @@ public class BackendMutation {
break;
default:
throw new AssertionError(String.format(
"Unknown mutate action: %s", action));
"Unknown mutate action: %s", action));
}
}
if (!ignoreCurrent) {
@ -146,8 +147,8 @@ public class BackendMutation {
}
private static HugeException incompatibleActionException(
Action newAction,
Action originAction) {
Action newAction,
Action originAction) {
return new HugeException("The action '%s' is incompatible with " +
"action '%s'", newAction, originAction);
}
@ -156,11 +157,12 @@ public class BackendMutation {
* Merges another mutation into this mutation. Ensures that all additions
* and deletions are added to this mutation. Does not remove duplicates
* if such exist - this needs to be ensured by the caller.
*
* @param mutation another mutation to be merged
*/
public void merge(BackendMutation mutation) {
E.checkNotNull(mutation, "mutation");
for (Iterator<BackendAction> it = mutation.mutation(); it.hasNext();) {
for (Iterator<BackendAction> it = mutation.mutation(); it.hasNext(); ) {
BackendAction item = it.next();
this.add(item.entry(), item.action());
}
@ -172,6 +174,7 @@ public class BackendMutation {
/**
* Get all mutations
*
* @return mutations
*/
public Iterator<BackendAction> mutation() {
@ -180,6 +183,7 @@ public class BackendMutation {
/**
* Get mutations by type
*
* @param type entry type
* @return mutations
*/
@ -189,8 +193,9 @@ public class BackendMutation {
/**
* Get mutations by type and id
*
* @param type entry type
* @param id entry id
* @param id entry id
* @return mutations
*/
public List<BackendAction> mutation(HugeType type, Id id) {
@ -199,7 +204,8 @@ public class BackendMutation {
/**
* Whether mutation contains entry and action
* @param entry entry
*
* @param entry entry
* @param action action
* @return true if exist, otherwise false
*/
@ -218,12 +224,13 @@ public class BackendMutation {
/**
* Whether mutation contains type and action
* @param type type
*
* @param type type
* @param action action
* @return true if exist, otherwise false
*/
public boolean contains(HugeType type, Action action) {
for (Iterator<BackendAction> i = this.updates.get(type); i.hasNext();) {
for (Iterator<BackendAction> i = this.updates.get(type); i.hasNext(); ) {
BackendAction entry = i.next();
if (entry.action() == action) {
return true;
@ -234,6 +241,7 @@ public class BackendMutation {
/**
* Whether this mutation is empty
*
* @return true if empty, otherwise false
*/
public boolean isEmpty() {
@ -242,6 +250,7 @@ public class BackendMutation {
/**
* Get size of mutations
*
* @return size
*/
public int size() {

View File

@ -20,8 +20,6 @@ package org.apache.hugegraph.backend.store;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.backend.store.memory.InMemoryDBStoreProvider;
@ -29,6 +27,7 @@ import org.apache.hugegraph.backend.store.raft.RaftBackendStoreProvider;
import org.apache.hugegraph.config.CoreOptions;
import org.apache.hugegraph.config.HugeConfig;
import org.apache.hugegraph.util.Log;
import org.slf4j.Logger;
public class BackendProviderFactory {
@ -83,7 +82,7 @@ public class BackendProviderFactory {
return instance;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
public static void register(String name, String classPath) {
ClassLoader classLoader = BackendProviderFactory.class.getClassLoader();
Class<?> clazz = null;
@ -96,7 +95,7 @@ public class BackendProviderFactory {
// Check subclass
boolean subclass = BackendStoreProvider.class.isAssignableFrom(clazz);
BackendException.check(subclass, "Class '%s' is not a subclass of " +
"class BackendStoreProvider", classPath);
"class BackendStoreProvider", classPath);
// Check exists
BackendException.check(!providers.containsKey(name),

View File

@ -23,11 +23,10 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.apache.hugegraph.config.CoreOptions;
import org.apache.hugegraph.config.HugeConfig;
import org.apache.hugegraph.util.Log;
import org.slf4j.Logger;
public abstract class BackendSessionPool {
@ -47,7 +46,7 @@ public abstract class BackendSessionPool {
this.sessionCount = new AtomicInteger(0);
this.sessions = new ConcurrentHashMap<>();
this.reconnectDetectInterval = this.config.get(
CoreOptions.STORE_CONN_DETECT_INTERVAL);
CoreOptions.STORE_CONN_DETECT_INTERVAL);
}
public HugeConfig config() {

View File

@ -106,7 +106,7 @@ public interface BackendStore {
}
E.checkState(counter != 0L, "Please check whether '%s' is OK",
this.provider().type());
this.provider().type());
E.checkState(counter == expect, "'%s' is busy please try again",
this.provider().type());
@ -179,6 +179,11 @@ public interface BackendStore {
}
enum TxState {
BEGIN, COMMITTING, COMMITT_FAIL, ROLLBACKING, ROLLBACK_FAIL, CLEAN
BEGIN,
COMMITTING,
COMMITT_FAIL,
ROLLBACKING,
ROLLBACK_FAIL,
CLEAN
}
}

View File

@ -18,9 +18,8 @@
package org.apache.hugegraph.backend.store;
import org.apache.hugegraph.config.HugeConfig;
import org.slf4j.Logger;
import org.apache.hugegraph.util.Log;
import org.slf4j.Logger;
public class BackendStoreInfo {

View File

@ -17,11 +17,12 @@
package org.apache.hugegraph.backend.store;
import com.alipay.remoting.rpc.RpcServer;
import org.apache.hugegraph.config.HugeConfig;
import org.apache.hugegraph.event.EventHub;
import org.apache.hugegraph.event.EventListener;
import com.alipay.remoting.rpc.RpcServer;
public interface BackendStoreProvider {
String SCHEMA_STORE = "m";

View File

@ -280,8 +280,8 @@ public abstract class BackendTable<Session extends BackendSession, Entry> {
assert count > 1;
byte[] each = align(new BigInteger(1, subtract(end, start))
.divide(BigInteger.valueOf(count))
.toByteArray(),
.divide(BigInteger.valueOf(count))
.toByteArray(),
length);
byte[] offset = start;
byte[] last = offset;

View File

@ -26,6 +26,7 @@ import java.util.Set;
import org.apache.hugegraph.type.define.HugeKeys;
import org.apache.hugegraph.util.InsertionOrderUtil;
import com.google.common.collect.ImmutableMap;
public class TableDefine {

View File

@ -53,7 +53,7 @@ import org.slf4j.Logger;
* 2.append/subtract edge-property
*/
public abstract class InMemoryDBStore
extends AbstractBackendStore<BackendSession> {
extends AbstractBackendStore<BackendSession> {
private static final Logger LOG = Log.logger(InMemoryDBStore.class);
@ -125,7 +125,7 @@ public abstract class InMemoryDBStore
@Override
public void mutate(BackendMutation mutation) {
for (Iterator<BackendAction> it = mutation.mutation(); it.hasNext();) {
for (Iterator<BackendAction> it = mutation.mutation(); it.hasNext(); ) {
this.mutate(it.next());
}
}
@ -229,7 +229,7 @@ public abstract class InMemoryDBStore
@Override
public void rollbackTx() {
throw new UnsupportedOperationException(
"Unsupported rollback operation by InMemoryDBStore");
"Unsupported rollback operation by InMemoryDBStore");
}
@Override
@ -340,19 +340,19 @@ public abstract class InMemoryDBStore
@Override
public Id nextId(HugeType type) {
throw new UnsupportedOperationException(
"InMemoryGraphStore.nextId()");
"InMemoryGraphStore.nextId()");
}
@Override
public void increaseCounter(HugeType type, long num) {
throw new UnsupportedOperationException(
"InMemoryGraphStore.increaseCounter()");
"InMemoryGraphStore.increaseCounter()");
}
@Override
public long getCounter(HugeType type) {
throw new UnsupportedOperationException(
"InMemoryGraphStore.getCounter()");
"InMemoryGraphStore.getCounter()");
}
}

View File

@ -22,11 +22,11 @@ import java.util.concurrent.ConcurrentHashMap;
import org.apache.hugegraph.backend.store.AbstractBackendStoreProvider;
import org.apache.hugegraph.backend.store.BackendStore;
import org.apache.hugegraph.util.Events;
import org.apache.hugegraph.backend.store.memory.InMemoryDBStore.InMemoryGraphStore;
import org.apache.hugegraph.backend.store.memory.InMemoryDBStore.InMemorySchemaStore;
import org.apache.hugegraph.backend.store.memory.InMemoryDBStore.InMemorySystemStore;
import org.apache.hugegraph.config.HugeConfig;
import org.apache.hugegraph.util.Events;
public class InMemoryDBStoreProvider extends AbstractBackendStoreProvider {

View File

@ -27,15 +27,6 @@ import java.util.concurrent.ConcurrentHashMap;
import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.serializer.TextBackendEntry;
import org.apache.hugegraph.backend.store.BackendEntry;
import org.apache.hugegraph.backend.store.BackendSession;
import org.apache.hugegraph.backend.store.BackendTable;
import org.apache.hugegraph.backend.store.Shard;
import org.apache.hugegraph.exception.NotSupportException;
import org.apache.hugegraph.type.HugeType;
import org.slf4j.Logger;
import org.apache.hugegraph.backend.query.Aggregate;
import org.apache.hugegraph.backend.query.Aggregate.AggregateFunc;
import org.apache.hugegraph.backend.query.Condition;
@ -44,14 +35,23 @@ import org.apache.hugegraph.backend.query.IdPrefixQuery;
import org.apache.hugegraph.backend.query.IdRangeQuery;
import org.apache.hugegraph.backend.query.Query;
import org.apache.hugegraph.backend.query.QueryResults;
import org.apache.hugegraph.backend.serializer.TextBackendEntry;
import org.apache.hugegraph.backend.store.BackendEntry;
import org.apache.hugegraph.backend.store.BackendSession;
import org.apache.hugegraph.backend.store.BackendTable;
import org.apache.hugegraph.backend.store.Shard;
import org.apache.hugegraph.exception.NotSupportException;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.InsertionOrderUtil;
import org.apache.hugegraph.util.Log;
import org.slf4j.Logger;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
public class InMemoryDBTable extends BackendTable<BackendSession,
TextBackendEntry> {
TextBackendEntry> {
private static final Logger LOG = Log.logger(InMemoryDBTable.class);
@ -260,8 +260,8 @@ public class InMemoryDBTable extends BackendTable<BackendSession,
}
protected Map<Id, BackendEntry> queryByFilter(
Collection<Condition> conditions,
Map<Id, BackendEntry> entries) {
Collection<Condition> conditions,
Map<Id, BackendEntry> entries) {
assert conditions.size() > 0;
Map<Id, BackendEntry> rs = new HashMap<>();

View File

@ -32,23 +32,24 @@ import java.util.concurrent.ConcurrentSkipListMap;
import org.apache.hugegraph.backend.id.EdgeId;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.id.IdGenerator;
import org.apache.hugegraph.backend.serializer.TextBackendEntry;
import org.apache.hugegraph.backend.store.BackendEntry;
import org.apache.hugegraph.backend.store.BackendEntry.BackendColumn;
import org.apache.hugegraph.backend.store.BackendSession;
import org.apache.hugegraph.structure.HugeIndex;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.type.define.HugeKeys;
import org.apache.hugegraph.backend.query.Condition;
import org.apache.hugegraph.backend.query.Condition.RangeConditions;
import org.apache.hugegraph.backend.query.ConditionQuery;
import org.apache.hugegraph.backend.query.IdQuery;
import org.apache.hugegraph.backend.query.Query;
import org.apache.hugegraph.backend.query.QueryResults;
import org.apache.hugegraph.backend.serializer.TextBackendEntry;
import org.apache.hugegraph.backend.store.BackendEntry;
import org.apache.hugegraph.backend.store.BackendEntry.BackendColumn;
import org.apache.hugegraph.backend.store.BackendSession;
import org.apache.hugegraph.iterator.ExtendableIterator;
import org.apache.hugegraph.structure.HugeIndex;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.type.define.HugeKeys;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.InsertionOrderUtil;
import org.apache.hugegraph.util.NumericUtil;
import com.google.common.collect.ImmutableList;
public class InMemoryDBTables {
@ -103,18 +104,18 @@ public class InMemoryDBTables {
@Override
protected Map<Id, BackendEntry> queryById(
Collection<Id> ids,
Map<Id, BackendEntry> entries) {
Collection<Id> ids,
Map<Id, BackendEntry> entries) {
// Query edge(in a vertex) by id
return this.queryEdgeById(ids, false, entries);
}
@Override
protected Map<Id, BackendEntry> queryByIdPrefix(
Id start,
boolean inclusiveStart,
Id prefix,
Map<Id, BackendEntry> entries) {
Id start,
boolean inclusiveStart,
Id prefix,
Map<Id, BackendEntry> entries) {
// Query edge(in a vertex) by v-id + column-name-prefix
BackendEntry value = this.getEntryById(start, entries);
if (value == null) {
@ -145,11 +146,11 @@ public class InMemoryDBTables {
@Override
protected Map<Id, BackendEntry> queryByIdRange(
Id start,
boolean inclusiveStart,
Id end,
boolean inclusiveEnd,
Map<Id, BackendEntry> entries) {
Id start,
boolean inclusiveStart,
Id end,
boolean inclusiveEnd,
Map<Id, BackendEntry> entries) {
BackendEntry value = this.getEntryById(start, entries);
if (value == null) {
return Collections.emptyMap();
@ -178,8 +179,8 @@ public class InMemoryDBTables {
}
private Map<Id, BackendEntry> queryEdgeById(
Collection<Id> ids, boolean prefix,
Map<Id, BackendEntry> entries) {
Collection<Id> ids, boolean prefix,
Map<Id, BackendEntry> entries) {
assert ids.size() > 0;
Map<Id, BackendEntry> rs = InsertionOrderUtil.newMap();
@ -195,7 +196,7 @@ public class InMemoryDBTables {
} else if ((!prefix && entry.contains(column)) ||
(prefix && entry.containsPrefix(column))) {
BackendEntry edges = new TextBackendEntry(
HugeType.VERTEX, entry.id());
HugeType.VERTEX, entry.id());
if (prefix) {
// Some edges with specified prefix in the vertex
edges.columns(entry.columnsWithPrefix(column));
@ -229,8 +230,8 @@ public class InMemoryDBTables {
@Override
protected Map<Id, BackendEntry> queryByFilter(
Collection<Condition> conditions,
Map<Id, BackendEntry> entries) {
Collection<Condition> conditions,
Map<Id, BackendEntry> entries) {
if (conditions.isEmpty()) {
return entries;
}
@ -405,7 +406,7 @@ public class InMemoryDBTables {
E.checkState(indexLabel != null, "Expect index label");
Iterator<Entry<Id, BackendEntry>> iter;
for (iter = this.store().entrySet().iterator(); iter.hasNext();) {
for (iter = this.store().entrySet().iterator(); iter.hasNext(); ) {
Entry<Id, BackendEntry> e = iter.next();
// Delete if prefix with index label
if (e.getKey().asString().startsWith(indexLabel)) {
@ -535,7 +536,7 @@ public class InMemoryDBTables {
SortedMap<Id, BackendEntry> subStore;
subStore = this.store().subMap(min, max);
Iterator<Entry<Id, BackendEntry>> iter;
for (iter = subStore.entrySet().iterator(); iter.hasNext();) {
for (iter = subStore.entrySet().iterator(); iter.hasNext(); ) {
iter.next();
// Delete if prefix with index label
iter.remove();

View File

@ -20,6 +20,7 @@ package org.apache.hugegraph.backend.store.memory;
import java.util.Map;
import org.apache.hugegraph.backend.store.BackendMetrics;
import com.google.common.collect.ImmutableMap;
public class InMemoryMetrics implements BackendMetrics {

View File

@ -22,11 +22,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.function.Function;
import org.slf4j.Logger;
import com.alipay.sofa.jraft.Status;
import com.alipay.sofa.jraft.closure.ReadIndexClosure;
import com.alipay.sofa.jraft.util.BytesUtil;
import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.backend.query.Query;
import org.apache.hugegraph.backend.store.BackendEntry;
@ -41,6 +36,11 @@ import org.apache.hugegraph.config.HugeConfig;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.Log;
import org.slf4j.Logger;
import com.alipay.sofa.jraft.Status;
import com.alipay.sofa.jraft.closure.ReadIndexClosure;
import com.alipay.sofa.jraft.util.BytesUtil;
public class RaftBackendStore implements BackendStore {
@ -149,13 +149,13 @@ public class RaftBackendStore implements BackendStore {
@SuppressWarnings("unchecked")
public Iterator<BackendEntry> query(Query query) {
return (Iterator<BackendEntry>)
this.queryByRaft(query, o -> this.store.query(query));
this.queryByRaft(query, o -> this.store.query(query));
}
@Override
public Number queryNumber(Query query) {
return (Number)
this.queryByRaft(query, o -> this.store.queryNumber(query));
this.queryByRaft(query, o -> this.store.queryNumber(query));
}
@Override
@ -231,8 +231,8 @@ public class RaftBackendStore implements BackendStore {
future.complete(status, () -> func.apply(query));
} else {
future.failure(status, new BackendException(
"Failed to do raft read-index: %s",
status));
"Failed to do raft read-index: %s",
status));
}
}
};

View File

@ -20,9 +20,6 @@ package org.apache.hugegraph.backend.store.raft;
import java.util.Set;
import java.util.concurrent.Future;
import org.slf4j.Logger;
import com.alipay.remoting.rpc.RpcServer;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.backend.store.BackendStore;
@ -35,6 +32,9 @@ import org.apache.hugegraph.event.EventListener;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.Events;
import org.apache.hugegraph.util.Log;
import org.slf4j.Logger;
import com.alipay.remoting.rpc.RpcServer;
import com.google.common.collect.ImmutableSet;
public class RaftBackendStoreProvider implements BackendStoreProvider {
@ -47,6 +47,7 @@ public class RaftBackendStoreProvider implements BackendStoreProvider {
private RaftBackendStore schemaStore;
private RaftBackendStore graphStore;
private RaftBackendStore systemStore;
public RaftBackendStoreProvider(HugeGraphParams params,
BackendStoreProvider provider) {
this.provider = provider;

View File

@ -23,12 +23,12 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Supplier;
import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.util.Log;
import org.slf4j.Logger;
import com.alipay.sofa.jraft.Closure;
import com.alipay.sofa.jraft.Status;
import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.util.Log;
public class RaftClosure<T> implements Closure {

View File

@ -184,11 +184,11 @@ public final class RaftContext {
return this.raftNode;
}
protected RpcServer rpcServer() {
RpcServer rpcServer() {
return this.raftRpcServer;
}
protected RpcForwarder rpcForwarder() {
RpcForwarder rpcForwarder() {
return this.rpcForwarder;
}
@ -216,7 +216,7 @@ public final class RaftContext {
}
}
protected RaftBackendStore[] stores() {
RaftBackendStore[] stores() {
return this.stores;
}
@ -233,13 +233,13 @@ public final class RaftContext {
NodeOptions nodeOptions = new NodeOptions();
nodeOptions.setEnableMetrics(false);
nodeOptions.setRpcProcessorThreadPoolSize(
config.get(CoreOptions.RAFT_RPC_THREADS));
config.get(CoreOptions.RAFT_RPC_THREADS));
nodeOptions.setRpcConnectTimeoutMs(
config.get(CoreOptions.RAFT_RPC_CONNECT_TIMEOUT));
config.get(CoreOptions.RAFT_RPC_CONNECT_TIMEOUT));
nodeOptions.setRpcDefaultTimeout(
1000 * config.get(CoreOptions.RAFT_RPC_TIMEOUT));
1000 * config.get(CoreOptions.RAFT_RPC_TIMEOUT));
nodeOptions.setRpcInstallSnapshotTimeout(
1000 * config.get(CoreOptions.RAFT_INSTALL_SNAPSHOT_TIMEOUT));
1000 * config.get(CoreOptions.RAFT_INSTALL_SNAPSHOT_TIMEOUT));
int electionTimeout = config.get(CoreOptions.RAFT_ELECTION_TIMEOUT);
nodeOptions.setElectionTimeoutMs(electionTimeout);
@ -269,27 +269,27 @@ public final class RaftContext {
*/
raftOptions.setApplyBatch(config.get(CoreOptions.RAFT_APPLY_BATCH));
raftOptions.setDisruptorBufferSize(
config.get(CoreOptions.RAFT_QUEUE_SIZE));
config.get(CoreOptions.RAFT_QUEUE_SIZE));
raftOptions.setDisruptorPublishEventWaitTimeoutSecs(
config.get(CoreOptions.RAFT_QUEUE_PUBLISH_TIMEOUT));
config.get(CoreOptions.RAFT_QUEUE_PUBLISH_TIMEOUT));
raftOptions.setReplicatorPipeline(
config.get(CoreOptions.RAFT_REPLICATOR_PIPELINE));
config.get(CoreOptions.RAFT_REPLICATOR_PIPELINE));
raftOptions.setOpenStatistics(false);
raftOptions.setReadOnlyOptions(
ReadOnlyOption.valueOf(
config.get(CoreOptions.RAFT_READ_STRATEGY)));
ReadOnlyOption.valueOf(
config.get(CoreOptions.RAFT_READ_STRATEGY)));
return nodeOptions;
}
protected void clearCache() {
void clearCache() {
// Just choose two representatives used to represent schema and graph
this.notifyCache(Cache.ACTION_CLEAR, HugeType.VERTEX_LABEL, null);
this.notifyCache(Cache.ACTION_CLEAR, HugeType.VERTEX, null);
}
protected void updateCacheIfNeeded(BackendMutation mutation,
boolean forwarded) {
void updateCacheIfNeeded(BackendMutation mutation,
boolean forwarded) {
// Update cache only when graph run in general mode
if (this.graphMode() != GraphMode.NONE) {
return;
@ -317,7 +317,7 @@ public final class RaftContext {
}
}
protected void notifyCache(String action, HugeType type, List<Id> ids) {
private void notifyCache(String action, HugeType type, List<Id> ids) {
EventHub eventHub;
if (type.isGraph()) {
eventHub = this.params.graphEventHub();
@ -373,18 +373,18 @@ public final class RaftContext {
@SuppressWarnings("unused")
private RpcServer initAndStartRpcServer() {
Integer lowWaterMark = this.config().get(
CoreOptions.RAFT_RPC_BUF_LOW_WATER_MARK);
CoreOptions.RAFT_RPC_BUF_LOW_WATER_MARK);
System.setProperty("bolt.channel_write_buf_low_water_mark",
String.valueOf(lowWaterMark));
Integer highWaterMark = this.config().get(
CoreOptions.RAFT_RPC_BUF_HIGH_WATER_MARK);
CoreOptions.RAFT_RPC_BUF_HIGH_WATER_MARK);
System.setProperty("bolt.channel_write_buf_high_water_mark",
String.valueOf(highWaterMark));
PeerId endpoint = this.endpoint();
NodeManager.getInstance().addAddress(endpoint.getEndpoint());
RpcServer rpcServer = RaftRpcServerFactory.createAndStartRaftRpcServer(
endpoint.getEndpoint());
endpoint.getEndpoint());
LOG.info("Raft-RPC server is started successfully");
return rpcServer;
}
@ -392,11 +392,11 @@ public final class RaftContext {
private RpcServer wrapRpcServer(com.alipay.remoting.rpc.RpcServer rpcServer) {
// TODO: pass ServerOptions instead of CoreOptions, to share by graphs
Integer lowWaterMark = this.config().get(
CoreOptions.RAFT_RPC_BUF_LOW_WATER_MARK);
CoreOptions.RAFT_RPC_BUF_LOW_WATER_MARK);
System.setProperty("bolt.channel_write_buf_low_water_mark",
String.valueOf(lowWaterMark));
Integer highWaterMark = this.config().get(
CoreOptions.RAFT_RPC_BUF_HIGH_WATER_MARK);
CoreOptions.RAFT_RPC_BUF_HIGH_WATER_MARK);
System.setProperty("bolt.channel_write_buf_high_water_mark",
String.valueOf(highWaterMark));
@ -439,7 +439,7 @@ public final class RaftContext {
private ExecutorService createBackendExecutor(int threads) {
String name = "store-backend-executor";
RejectedExecutionHandler handler =
new ThreadPoolExecutor.CallerRunsPolicy();
new ThreadPoolExecutor.CallerRunsPolicy();
return newPool(threads, threads, name, handler);
}

View File

@ -45,7 +45,7 @@ public class RaftException extends HugeException {
public static final void check(boolean expression,
String message, Object... args)
throws RaftException {
throws RaftException {
if (!expression) {
throw new RaftException(message, args);
}

View File

@ -20,21 +20,19 @@ package org.apache.hugegraph.backend.store.raft;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.AddPeerRequest;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.ListPeersRequest;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.ListPeersResponse;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.RemovePeerRequest;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.SetLeaderRequest;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.SetLeaderResponse;
import org.apache.hugegraph.backend.store.raft.rpc.RpcForwarder;
import org.apache.hugegraph.util.E;
import com.alipay.sofa.jraft.Node;
import com.alipay.sofa.jraft.Status;
import com.alipay.sofa.jraft.entity.PeerId;
import org.apache.hugegraph.backend.store.raft.rpc.RpcForwarder;
import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.ListPeersRequest;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.ListPeersResponse;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.SetLeaderRequest;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.SetLeaderResponse;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.AddPeerRequest;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.AddPeerResponse;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.RemovePeerRequest;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.RemovePeerResponse;
import org.apache.hugegraph.util.E;
import com.google.protobuf.Message;
public class RaftGroupManagerImpl implements RaftGroupManager {
@ -87,8 +85,8 @@ public class RaftGroupManagerImpl implements RaftGroupManager {
Status status = this.raftNode.node().transferLeadershipTo(peerId);
if (!status.isOk()) {
throw new BackendException(
"Failed to transfer leader to '%s', raft error: %s",
endpoint, status.getErrorMsg());
"Failed to transfer leader to '%s', raft error: %s",
endpoint, status.getErrorMsg());
}
return peerId.toString();
}

View File

@ -24,6 +24,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.util.LZ4Util;
import org.apache.hugegraph.util.Log;
import org.slf4j.Logger;
import com.alipay.sofa.jraft.Node;
@ -37,9 +40,6 @@ import com.alipay.sofa.jraft.error.RaftError;
import com.alipay.sofa.jraft.option.NodeOptions;
import com.alipay.sofa.jraft.rpc.RpcServer;
import com.alipay.sofa.jraft.util.BytesUtil;
import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.util.LZ4Util;
import org.apache.hugegraph.util.Log;
public final class RaftNode {
@ -69,11 +69,11 @@ public final class RaftNode {
this.busyCounter = new AtomicInteger();
}
protected RaftContext context() {
private RaftContext context() {
return this.context;
}
protected Node node() {
Node node() {
assert this.node != null;
return this.node;
}
@ -105,7 +105,7 @@ public final class RaftNode {
this.raftGroupService.join();
} catch (final InterruptedException e) {
throw new RaftException(
"Interrupted while shutdown raftGroupService");
"Interrupted while shutdown raftGroupService");
}
}
}
@ -147,7 +147,7 @@ public final class RaftNode {
private void submitCommand(StoreCommand command, RaftStoreClosure future) {
// Wait leader elected
LeaderInfo leaderInfo = this.waitLeaderElected(
RaftContext.WAIT_LEADER_TIMEOUT);
RaftContext.WAIT_LEADER_TIMEOUT);
// If myself is not leader, forward to the leader
if (!leaderInfo.selfIsLeader) {
this.context.rpcForwarder().forwardToLeader(leaderInfo.leaderId,
@ -171,7 +171,7 @@ public final class RaftNode {
this.node.apply(task);
}
protected LeaderInfo waitLeaderElected(int timeout) {
LeaderInfo waitLeaderElected(int timeout) {
String group = this.context.group();
LeaderInfo leaderInfo = this.leaderInfo.get();
if (leaderInfo.leaderId != null) {
@ -189,8 +189,8 @@ public final class RaftNode {
long consumedTime = System.currentTimeMillis() - beginTime;
if (timeout > 0 && consumedTime >= timeout) {
throw new BackendException(
"Waiting for raft group '%s' election timeout(%sms)",
group, consumedTime);
"Waiting for raft group '%s' election timeout(%sms)",
group, consumedTime);
}
leaderInfo = this.leaderInfo.get();
assert leaderInfo != null;
@ -199,7 +199,7 @@ public final class RaftNode {
return leaderInfo;
}
protected void waitRaftLogSynced(int timeout) {
void waitRaftLogSynced(int timeout) {
String group = this.context.group();
LOG.info("Waiting for raft group '{}' log synced", group);
long beginTime = System.currentTimeMillis();
@ -219,8 +219,8 @@ public final class RaftNode {
long consumedTime = System.currentTimeMillis() - beginTime;
if (timeout > 0 && consumedTime >= timeout) {
throw new BackendException(
"Waiting for raft group '%s' log synced timeout(%sms)",
group, consumedTime);
"Waiting for raft group '%s' log synced timeout(%sms)",
group, consumedTime);
}
}
LOG.info("Waited for raft group '{}' log synced successfully", group);

View File

@ -19,9 +19,10 @@ package org.apache.hugegraph.backend.store.raft;
import java.util.function.Supplier;
import com.alipay.sofa.jraft.Status;
import org.apache.hugegraph.util.E;
import com.alipay.sofa.jraft.Status;
public final class RaftResult<T> {
private final Status status;

View File

@ -68,7 +68,7 @@ public final class StoreSerializer {
// write mutation size
buffer.writeVInt(mutation.size());
for (Iterator<BackendAction> items = mutation.mutation();
items.hasNext();) {
items.hasNext(); ) {
BackendAction item = items.next();
// write Action
buffer.write(item.action().code());

View File

@ -218,7 +218,7 @@ public class StoreSnapshotFile {
archiveFile, parentPath, (end - begin) / 1000.0F);
} catch (Throwable e) {
throw new RaftException(
"Failed to decompress snapshot, zip=%s", e, archiveFile);
"Failed to decompress snapshot, zip=%s", e, archiveFile);
}
if (meta.hasChecksum()) {

View File

@ -23,6 +23,16 @@ import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.backend.serializer.BytesBuffer;
import org.apache.hugegraph.backend.store.BackendMutation;
import org.apache.hugegraph.backend.store.BackendStore;
import org.apache.hugegraph.backend.store.raft.RaftBackendStore.IncrCounter;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.StoreAction;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.StoreType;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.LZ4Util;
import org.apache.hugegraph.util.Log;
import org.slf4j.Logger;
import com.alipay.sofa.jraft.Closure;
@ -35,16 +45,6 @@ import com.alipay.sofa.jraft.error.RaftError;
import com.alipay.sofa.jraft.error.RaftException;
import com.alipay.sofa.jraft.storage.snapshot.SnapshotReader;
import com.alipay.sofa.jraft.storage.snapshot.SnapshotWriter;
import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.backend.serializer.BytesBuffer;
import org.apache.hugegraph.backend.store.BackendMutation;
import org.apache.hugegraph.backend.store.BackendStore;
import org.apache.hugegraph.backend.store.raft.RaftBackendStore.IncrCounter;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.StoreAction;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.StoreType;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.LZ4Util;
import org.apache.hugegraph.util.Log;
public final class StoreStateMachine extends StateMachineAdapter {
@ -165,7 +165,7 @@ public final class StoreStateMachine extends StateMachineAdapter {
break;
case COMMIT_TX:
List<BackendMutation> mutations = StoreSerializer.readMutations(
buffer);
buffer);
// RaftBackendStore doesn't write raft log for beginTx
store.beginTx();
for (BackendMutation mutation : mutations) {

View File

@ -56,10 +56,10 @@ public class CompressStrategyManager {
// add parallel compress strategy
if (compressStrategies[PARALLEL_STRATEGY] == null) {
CompressStrategy compressStrategy = new ParallelCompressStrategy(
config.get(CoreOptions.RAFT_SNAPSHOT_COMPRESS_THREADS),
config.get(CoreOptions.RAFT_SNAPSHOT_DECOMPRESS_THREADS));
config.get(CoreOptions.RAFT_SNAPSHOT_COMPRESS_THREADS),
config.get(CoreOptions.RAFT_SNAPSHOT_DECOMPRESS_THREADS));
CompressStrategyManager.addCompressStrategy(
CompressStrategyManager.PARALLEL_STRATEGY, compressStrategy);
CompressStrategyManager.PARALLEL_STRATEGY, compressStrategy);
DEFAULT_STRATEGY = PARALLEL_STRATEGY;
}
}

View File

@ -104,10 +104,10 @@ public class ParallelCompressStrategy implements CompressStrategy {
FileUtils.forceMkdir(zipFile.getParentFile());
ExecutorService compressExecutor =
newFixedPool(compressThreads, compressThreads, "raft-snapshot-compress-executor",
new ThreadPoolExecutor.CallerRunsPolicy());
newFixedPool(compressThreads, compressThreads, "raft-snapshot-compress-executor",
new ThreadPoolExecutor.CallerRunsPolicy());
ZipArchiveScatterOutputStream scatterOutput =
new ZipArchiveScatterOutputStream(compressExecutor);
new ZipArchiveScatterOutputStream(compressExecutor);
compressDirectoryToZipFile(rootFile, scatterOutput, sourceDir, ZipEntry.DEFLATED);
try (FileOutputStream fos = new FileOutputStream(zipFile);
@ -127,9 +127,9 @@ public class ParallelCompressStrategy implements CompressStrategy {
Checksum checksum) throws Throwable {
LOG.info("Start to decompress snapshot in parallel mode");
ExecutorService decompressExecutor =
newFixedPool(decompressThreads, decompressThreads,
"raft-snapshot-decompress-executor",
new ThreadPoolExecutor.CallerRunsPolicy());
newFixedPool(decompressThreads, decompressThreads,
"raft-snapshot-decompress-executor",
new ThreadPoolExecutor.CallerRunsPolicy());
// compute the checksum in a single thread
Future<Boolean> checksumFuture = decompressExecutor.submit(() -> {
computeZipFileChecksumValue(sourceZipFile, checksum);
@ -209,7 +209,7 @@ public class ParallelCompressStrategy implements CompressStrategy {
try (InputStream is = zipFile.getInputStream(entry);
BufferedInputStream fis = new BufferedInputStream(is);
BufferedOutputStream bos =
new BufferedOutputStream(Files.newOutputStream(targetFile.toPath()))) {
new BufferedOutputStream(Files.newOutputStream(targetFile.toPath()))) {
IOUtils.copy(fis, bos);
}
}
@ -219,7 +219,7 @@ public class ParallelCompressStrategy implements CompressStrategy {
*/
private void computeZipFileChecksumValue(String zipPath, Checksum checksum) throws Exception {
try (BufferedInputStream bis =
new BufferedInputStream(Files.newInputStream(Paths.get(zipPath)));
new BufferedInputStream(Files.newInputStream(Paths.get(zipPath)));
CheckedInputStream cis = new CheckedInputStream(bis, checksum);
ZipArchiveInputStream zis = new ZipArchiveInputStream(cis)) {
// checksum is calculated in the process

View File

@ -17,19 +17,20 @@
package org.apache.hugegraph.backend.store.raft.rpc;
import com.alipay.sofa.jraft.rpc.RpcRequestClosure;
import com.alipay.sofa.jraft.rpc.RpcRequestProcessor;
import com.google.protobuf.Message;
import org.apache.hugegraph.backend.store.raft.RaftContext;
import org.apache.hugegraph.backend.store.raft.RaftGroupManager;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.CommonResponse;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.AddPeerRequest;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.AddPeerResponse;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.CommonResponse;
import org.apache.hugegraph.util.Log;
import org.slf4j.Logger;
import com.alipay.sofa.jraft.rpc.RpcRequestClosure;
import com.alipay.sofa.jraft.rpc.RpcRequestProcessor;
import com.google.protobuf.Message;
public class AddPeerProcessor
extends RpcRequestProcessor<AddPeerRequest> {
extends RpcRequestProcessor<AddPeerRequest> {
private static final Logger LOG = Log.logger(AddPeerProcessor.class);

View File

@ -17,21 +17,21 @@
package org.apache.hugegraph.backend.store.raft.rpc;
import org.slf4j.Logger;
import com.alipay.sofa.jraft.rpc.RpcRequestClosure;
import com.alipay.sofa.jraft.rpc.RpcRequestProcessor;
import org.apache.hugegraph.backend.store.raft.RaftGroupManager;
import org.apache.hugegraph.backend.store.raft.RaftContext;
import org.apache.hugegraph.backend.store.raft.RaftGroupManager;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.CommonResponse;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.ListPeersRequest;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.ListPeersResponse;
import org.apache.hugegraph.util.Log;
import org.slf4j.Logger;
import com.alipay.sofa.jraft.rpc.RpcRequestClosure;
import com.alipay.sofa.jraft.rpc.RpcRequestProcessor;
import com.google.common.collect.ImmutableList;
import com.google.protobuf.Message;
public class ListPeersProcessor
extends RpcRequestProcessor<ListPeersRequest> {
extends RpcRequestProcessor<ListPeersRequest> {
private static final Logger LOG = Log.logger(ListPeersProcessor.class);

View File

@ -17,19 +17,20 @@
package org.apache.hugegraph.backend.store.raft.rpc;
import com.alipay.sofa.jraft.rpc.RpcRequestClosure;
import com.alipay.sofa.jraft.rpc.RpcRequestProcessor;
import com.google.protobuf.Message;
import org.apache.hugegraph.backend.store.raft.RaftContext;
import org.apache.hugegraph.backend.store.raft.RaftGroupManager;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.CommonResponse;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.RemovePeerRequest;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.RemovePeerResponse;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.CommonResponse;
import org.apache.hugegraph.util.Log;
import org.slf4j.Logger;
import com.alipay.sofa.jraft.rpc.RpcRequestClosure;
import com.alipay.sofa.jraft.rpc.RpcRequestProcessor;
import com.google.protobuf.Message;
public class RemovePeerProcessor
extends RpcRequestProcessor<RemovePeerRequest> {
extends RpcRequestProcessor<RemovePeerRequest> {
private static final Logger LOG = Log.logger(RemovePeerProcessor.class);

View File

@ -19,8 +19,16 @@ package org.apache.hugegraph.backend.store.raft.rpc;
import java.util.concurrent.ExecutionException;
import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.backend.store.raft.RaftClosure;
import org.apache.hugegraph.backend.store.raft.RaftContext;
import org.apache.hugegraph.backend.store.raft.RaftStoreClosure;
import org.apache.hugegraph.backend.store.raft.StoreCommand;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.CommonResponse;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.StoreCommandRequest;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.StoreCommandResponse;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.Log;
import org.slf4j.Logger;
import com.alipay.sofa.jraft.Node;
@ -31,14 +39,6 @@ import com.alipay.sofa.jraft.error.RaftError;
import com.alipay.sofa.jraft.rpc.RaftClientService;
import com.alipay.sofa.jraft.rpc.RpcResponseClosure;
import com.alipay.sofa.jraft.util.Endpoint;
import org.apache.hugegraph.backend.BackendException;
import org.apache.hugegraph.backend.store.raft.RaftClosure;
import org.apache.hugegraph.backend.store.raft.RaftContext;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.CommonResponse;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.StoreCommandRequest;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.StoreCommandResponse;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.Log;
import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.Message;
import com.google.protobuf.ZeroByteStringHelper;
@ -77,10 +77,13 @@ public class RpcForwarder {
public void setResponse(StoreCommandResponse response) {
if (response.getStatus()) {
LOG.debug("StoreCommandResponse status ok");
// This code forwards the request to the Raft leader and considers the operation successful
// This code forwards the request to the Raft leader and considers the
// operation successful
// if it's forwarded successfully. It returns a RaftClosure because the calling
// logic expects a RaftClosure result. Specifically, if the current instance is the Raft leader,
// it executes the corresponding logic locally and notifies the calling logic asynchronously
// logic expects a RaftClosure result. Specifically, if the current instance
// is the Raft leader,
// it executes the corresponding logic locally and notifies the calling logic
// asynchronously
// via RaftClosure. Therefore, the result is returned as a RaftClosure here.
RaftClosure<Status> supplierFuture = new RaftClosure<>();
supplierFuture.complete(Status.OK());
@ -90,10 +93,10 @@ public class RpcForwarder {
Status status = new Status(RaftError.UNKNOWN,
"fowared request failed");
BackendException e = new BackendException(
"Current node isn't leader, leader " +
"is [%s], failed to forward request " +
"to leader: %s",
leaderId, response.getMessage());
"Current node isn't leader, leader " +
"is [%s], failed to forward request " +
"to leader: %s",
leaderId, response.getMessage());
future.failure(status, e);
}
}
@ -133,10 +136,10 @@ public class RpcForwarder {
Status status = new Status(RaftError.UNKNOWN,
"fowared request failed");
BackendException e = new BackendException(
"Current node isn't leader, leader " +
"is [%s], failed to forward request " +
"to leader: %s",
leaderId, commonResponse.getMessage());
"Current node isn't leader, leader " +
"is [%s], failed to forward request " +
"to leader: %s",
leaderId, commonResponse.getMessage());
future.failure(status, e);
}
}

View File

@ -22,15 +22,15 @@ import org.apache.hugegraph.backend.store.raft.RaftGroupManager;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.CommonResponse;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.SetLeaderRequest;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.SetLeaderResponse;
import org.apache.hugegraph.util.Log;
import org.slf4j.Logger;
import com.alipay.sofa.jraft.rpc.RpcRequestClosure;
import com.alipay.sofa.jraft.rpc.RpcRequestProcessor;
import org.apache.hugegraph.util.Log;
import com.google.protobuf.Message;
public class SetLeaderProcessor
extends RpcRequestProcessor<SetLeaderRequest> {
extends RpcRequestProcessor<SetLeaderRequest> {
private static final Logger LOG = Log.logger(SetLeaderProcessor.class);

View File

@ -25,18 +25,18 @@ import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.StoreAction;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.StoreCommandRequest;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.StoreCommandResponse;
import org.apache.hugegraph.backend.store.raft.rpc.RaftRequests.StoreType;
import org.apache.hugegraph.util.Log;
import org.slf4j.Logger;
import com.alipay.sofa.jraft.rpc.RpcRequestClosure;
import com.alipay.sofa.jraft.rpc.RpcRequestProcessor;
import org.apache.hugegraph.util.Log;
import com.google.protobuf.Message;
public class StoreCommandProcessor
extends RpcRequestProcessor<StoreCommandRequest> {
extends RpcRequestProcessor<StoreCommandRequest> {
private static final Logger LOG = Log.logger(
StoreCommandProcessor.class);
StoreCommandProcessor.class);
private final RaftContext context;
@ -60,8 +60,8 @@ public class StoreCommandProcessor
LOG.warn("Failed to process StoreCommandRequest: {}",
request.getAction(), e);
StoreCommandResponse.Builder builder = StoreCommandResponse
.newBuilder()
.setStatus(false);
.newBuilder()
.setStatus(false);
if (e.getMessage() != null) {
builder.setMessage(e.getMessage());
}

View File

@ -75,8 +75,8 @@ public final class RamTable {
private static final int NULL = 0;
private static final Condition BOTH_COND = Condition.or(
Condition.eq(HugeKeys.DIRECTION, Directions.OUT),
Condition.eq(HugeKeys.DIRECTION, Directions.IN));
Condition.eq(HugeKeys.DIRECTION, Directions.OUT),
Condition.eq(HugeKeys.DIRECTION, Directions.IN));
private final HugeGraph graph;
private final long verticesCapacity;
@ -145,7 +145,7 @@ public final class RamTable {
File file = Paths.get(EXPORT_PATH, fileName).toFile();
if (!file.exists() || !file.isFile() || !file.canRead()) {
throw new IllegalArgumentException(String.format(
"File '%s' does not existed or readable", fileName));
"File '%s' does not existed or readable", fileName));
}
try (FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
@ -301,7 +301,7 @@ public final class RamTable {
assert this.edgesSize() > 0;
List<ConditionQuery> cqs = ConditionQueryFlatten.flatten(
(ConditionQuery) query);
(ConditionQuery) query);
if (cqs.size() == 1) {
ConditionQuery cq = cqs.get(0);
return this.query(cq);

Some files were not shown because too many files have changed in this diff Show More