diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/EdgeId.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/EdgeId.java index 60a5aa7194..f7a98d69ed 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/EdgeId.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/EdgeId.java @@ -38,11 +38,11 @@ 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 + HugeKeys.OWNER_VERTEX, + HugeKeys.DIRECTION, + HugeKeys.LABEL, + HugeKeys.SORT_VALUES, + HugeKeys.OTHER_VERTEX }; private final Id ownerVertexId; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Condition.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Condition.java index 6be1b6eb4c..fbeddaa02a 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Condition.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Condition.java @@ -54,37 +54,60 @@ public enum ConditionType { public enum RelationType implements BiPredicate { - EQ("==", (v1, v2) -> {return equals(v1, v2); }), - GT(">", (v1, v2) -> { return compare(v1, v2) > 0; }), - GTE(">=", (v1, v2) -> { return compare(v1, v2) >= 0; }), - LT("<", (v1, v2) -> { return compare(v1, v2) < 0; }), - LTE("<=", (v1, v2) -> { return compare(v1, v2) <= 0; }), - NEQ("!=", (v1, v2) -> { return compare(v1, v2) != 0; }), + EQ("==", (v1, v2) -> { + return equals(v1, v2); + }), + + GT(">", (v1, v2) -> { + return compare(v1, v2) > 0; + }), + + GTE(">=", (v1, v2) -> { + return compare(v1, v2) >= 0; + }), + + LT("<", (v1, v2) -> { + return compare(v1, v2) < 0; + }), + + LTE("<=", (v1, v2) -> { + return compare(v1, v2) <= 0; + }), + + NEQ("!=", (v1, v2) -> { + return compare(v1, v2) != 0; + }), + IN("in", null, Collection.class, (v1, v2) -> { assert v2 != null; return ((Collection) v2).contains(v1); }), + NOT_IN("notin", null, Collection.class, (v1, v2) -> { assert v2 != null; return !((Collection) v2).contains(v1); }), + PREFIX("prefix", Id.class, Id.class, (v1, v2) -> { assert v2 != null; return v1 != null && Bytes.prefixWith(((Id) v2).asBytes(), ((Id) v1).asBytes()); }), + TEXT_CONTAINS("textcontains", String.class, String.class, (v1, v2) -> { // TODO: support collection-property textcontains return v1 != null && ((String) v1).contains((String) v2); }), - TEXT_CONTAINS_ANY("textcontainsany", String.class, Collection.class, - (v1, v2) -> { + + TEXT_CONTAINS_ANY("textcontainsany", String.class, Collection.class, (v1, v2) -> { assert v2 != null; if (v1 == null) { return false; } + @SuppressWarnings("unchecked") Collection words = (Collection) v2; + for (String word : words) { if (((String) v1).contains(word)) { return true; @@ -92,18 +115,22 @@ public enum RelationType implements BiPredicate { } return false; }), + CONTAINS("contains", Collection.class, null, (v1, v2) -> { assert v2 != null; return v1 != null && ((Collection) v1).contains(v2); }), + CONTAINS_VALUE("containsv", Map.class, null, (v1, v2) -> { assert v2 != null; return v1 != null && ((Map) v1).containsValue(v2); }), + CONTAINS_KEY("containsk", Map.class, null, (v1, v2) -> { assert v2 != null; return v1 != null && ((Map) v1).containsKey(v2); }), + SCAN("scan", (v1, v2) -> { assert v2 != null; /* @@ -118,12 +145,12 @@ public enum RelationType implements BiPredicate { private final Class v1Class; private final Class v2Class; - private RelationType(String op, + RelationType(String op, BiFunction tester) { this(op, null, null, tester); } - private RelationType(String op, Class v1Class, Class v2Class, + RelationType(String op, Class v1Class, Class v2Class, BiFunction tester) { this.operator = op; this.tester = tester; @@ -390,7 +417,7 @@ public static Condition contains(Id key, Object value) { /** * Condition defines */ - public static abstract class BinCondition extends Condition { + public abstract static class BinCondition extends Condition { private Condition left; private Condition right; @@ -741,11 +768,15 @@ public RangeConditions(List conditions) { break; case GTE: this.keyMinEq = true; + this.keyMin = r.value(); + break; case GT: this.keyMin = r.value(); break; case LTE: this.keyMaxEq = true; + this.keyMax = r.value(); + break; case LT: this.keyMax = r.value(); break; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java index fcb2fe9507..7deb444bc2 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java @@ -212,7 +212,7 @@ public List relations() { return relations; } - public Relation relation(Id key){ + public Relation relation(Id key) { for (Relation r : this.relations()) { if (r.key().equals(key)) { return r; @@ -831,7 +831,7 @@ public boolean checkRangeIndex(HugeElement element, Condition cond) { } private static boolean removeFieldValue(Set values, - Object value){ + Object value) { for (Object elem : values) { if (numberEquals(elem, value)) { values.remove(elem); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQueryFlatten.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQueryFlatten.java index d112a73ec8..d9639b36ea 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQueryFlatten.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQueryFlatten.java @@ -186,7 +186,8 @@ private static Condition convTextContainsAny2Or(Relation relation) { assert relation.relation() == Condition.RelationType.TEXT_CONTAINS_ANY; @SuppressWarnings("unchecked") Collection words = (Collection) relation.value(); - Condition cond, conds = null; + Condition cond = null; + Condition conds = null; for (String word : words) { assert relation.key() instanceof Id; cond = Condition.textContains((Id) relation.key(), word); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/IdRangeQuery.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/IdRangeQuery.java index 5dd8b7ab83..340f14ba87 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/IdRangeQuery.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/IdRangeQuery.java @@ -98,16 +98,16 @@ public IdRangeQuery copy() { @Override public String toString() { - StringBuilder sb = new StringBuilder(super.toString()); - assert sb.length() > 0; - sb.deleteCharAt(sb.length() - 1); // Remove the last "`" - sb.append(" id in range ") - .append(this.inclusiveStart ? "[" : "(") - .append(this.start) - .append(", ") - .append(this.end) - .append(this.inclusiveEnd ? "]" : ")") - .append("`"); - return sb.toString(); + StringBuilder builder = new StringBuilder(super.toString()); + assert builder.length() > 0; + builder.deleteCharAt(builder.length() - 1); // Remove the last "`" + builder.append(" id in range ") + .append(this.inclusiveStart ? "[" : "(") + .append(this.start) + .append(", ") + .append(this.end) + .append(this.inclusiveEnd ? "]" : ")") + .append("`"); + return builder.toString(); } } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Query.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Query.java index 103a27f0b7..49e1fd8f41 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Query.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Query.java @@ -51,7 +51,7 @@ public class Query implements Cloneable { public static final long NO_CAPACITY = -1L; public static final long DEFAULT_CAPACITY = 800000L; // HugeGraph-777 - private static final ThreadLocal capacityContext = new ThreadLocal<>(); + private static final ThreadLocal CAPACITY_CONTEXT = new ThreadLocal<>(); protected static final Query NONE = new Query(HugeType.UNKNOWN); @@ -558,17 +558,17 @@ public String toString() { } public static long defaultCapacity(long capacity) { - Long old = capacityContext.get(); - capacityContext.set(capacity); + Long old = CAPACITY_CONTEXT.get(); + CAPACITY_CONTEXT.set(capacity); return old != null ? old : DEFAULT_CAPACITY; } public static long defaultCapacity() { - Long capacity = capacityContext.get(); + Long capacity = CAPACITY_CONTEXT.get(); return capacity != null ? capacity : DEFAULT_CAPACITY; } - public final static void checkForceCapacity(long count) + public static final void checkForceCapacity(long count) throws LimitExceedException { if (count > Query.DEFAULT_CAPACITY) { throw new LimitExceedException( diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinaryEntryIterator.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinaryEntryIterator.java index c9817a36a5..c4f87516bf 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinaryEntryIterator.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinaryEntryIterator.java @@ -129,7 +129,7 @@ private void removeLastRecord() { ((BinaryBackendEntry) this.current).removeColumn(lastOne); } - public final static long sizeOfEntry(BackendEntry entry) { + public static final long sizeOfEntry(BackendEntry entry) { /* * 3 cases: * 1) one vertex per entry diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinarySerializer.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinarySerializer.java index bdfb6d2e88..4702d3a978 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinarySerializer.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinarySerializer.java @@ -301,7 +301,6 @@ protected void parseEdge(BackendColumn col, HugeVertex vertex, } } - protected void parseVertex(byte[] value, HugeVertex vertex) { BytesBuffer buffer = BytesBuffer.wrap(value); @@ -871,9 +870,9 @@ public BackendEntry parse(BackendEntry originEntry) { BytesBuffer buffer = BytesBuffer.allocate(BytesBuffer.BUF_EDGE_ID); buffer.write(parsedEntry.id().asBytes()); buffer.write(bytes); - parsedEntry = new BinaryBackendEntry(originEntry.type(), - new BinaryId(buffer.bytes(), - BytesBuffer.wrap(buffer.bytes()).readEdgeId())); + parsedEntry = new BinaryBackendEntry(originEntry.type(), new BinaryId(buffer.bytes(), + BytesBuffer.wrap(buffer.bytes()).readEdgeId())); + for (BackendEntry.BackendColumn col : originEntry.columns()) { parsedEntry.column(buffer.bytes(), col.value); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/GraphSerializer.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/GraphSerializer.java index 35a96395cf..166fcb22c1 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/GraphSerializer.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/GraphSerializer.java @@ -33,19 +33,25 @@ public interface GraphSerializer { - public BackendEntry writeVertex(HugeVertex vertex); - public BackendEntry writeOlapVertex(HugeVertex vertex); - public BackendEntry writeVertexProperty(HugeVertexProperty prop); - public HugeVertex readVertex(HugeGraph graph, BackendEntry entry); + BackendEntry writeVertex(HugeVertex vertex); - public BackendEntry writeEdge(HugeEdge edge); - public BackendEntry writeEdgeProperty(HugeEdgeProperty prop); - public HugeEdge readEdge(HugeGraph graph, BackendEntry entry); + BackendEntry writeOlapVertex(HugeVertex vertex); - public BackendEntry writeIndex(HugeIndex index); - public HugeIndex readIndex(HugeGraph graph, ConditionQuery query, - BackendEntry entry); + BackendEntry writeVertexProperty(HugeVertexProperty prop); - public BackendEntry writeId(HugeType type, Id id); - public Query writeQuery(Query query); + HugeVertex readVertex(HugeGraph graph, BackendEntry entry); + + BackendEntry writeEdge(HugeEdge edge); + + BackendEntry writeEdgeProperty(HugeEdgeProperty prop); + + HugeEdge readEdge(HugeGraph graph, BackendEntry entry); + + BackendEntry writeIndex(HugeIndex index); + + HugeIndex readIndex(HugeGraph graph, ConditionQuery query, BackendEntry entry); + + BackendEntry writeId(HugeType type, Id id); + + Query writeQuery(Query query); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/SchemaSerializer.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/SchemaSerializer.java index 9e3bcc4d8a..045f065da8 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/SchemaSerializer.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/SchemaSerializer.java @@ -28,15 +28,19 @@ public interface SchemaSerializer { - public BackendEntry writeVertexLabel(VertexLabel vertexLabel); - public VertexLabel readVertexLabel(HugeGraph graph, BackendEntry entry); + BackendEntry writeVertexLabel(VertexLabel vertexLabel); - public BackendEntry writeEdgeLabel(EdgeLabel edgeLabel); - public EdgeLabel readEdgeLabel(HugeGraph graph, BackendEntry entry); + VertexLabel readVertexLabel(HugeGraph graph, BackendEntry entry); - public BackendEntry writePropertyKey(PropertyKey propertyKey); - public PropertyKey readPropertyKey(HugeGraph graph, BackendEntry entry); + BackendEntry writeEdgeLabel(EdgeLabel edgeLabel); - public BackendEntry writeIndexLabel(IndexLabel indexLabel); - public IndexLabel readIndexLabel(HugeGraph graph, BackendEntry entry); + EdgeLabel readEdgeLabel(HugeGraph graph, BackendEntry entry); + + BackendEntry writePropertyKey(PropertyKey propertyKey); + + PropertyKey readPropertyKey(HugeGraph graph, BackendEntry entry); + + BackendEntry writeIndexLabel(IndexLabel indexLabel); + + IndexLabel readIndexLabel(HugeGraph graph, BackendEntry entry); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendEntry.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendEntry.java index 1ab839973d..38393d9f92 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendEntry.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendEntry.java @@ -33,7 +33,7 @@ public interface BackendEntry extends Idfiable { - public static class BackendColumn implements Comparable { + class BackendColumn implements Comparable { public byte[] name; public byte[] value; @@ -69,65 +69,72 @@ public boolean equals(Object obj) { return Bytes.equals(this.name, other.name) && Bytes.equals(this.value, other.value); } + + public int hashCode() { + return this.name.hashCode() ^ + this.value.hashCode(); + } + } - public HugeType type(); + HugeType type(); @Override - public Id id(); + Id id(); + + Id originId(); + + Id subId(); + + long ttl(); - public Id originId(); + int columnsSize(); - public Id subId(); + Collection columns(); - public long ttl(); + void columns(Collection columns); - public int columnsSize(); - public Collection columns(); + void columns(BackendColumn column); - public void columns(Collection columns); - public void columns(BackendColumn column); + void merge(BackendEntry other); - public void merge(BackendEntry other); - public boolean mergeable(BackendEntry other); + boolean mergeable(BackendEntry other); - public void clear(); + void clear(); - public default boolean belongToMe(BackendColumn column) { + default boolean belongToMe(BackendColumn column) { return Bytes.prefixWith(column.name, id().asBytes()); } - public default boolean olap() { + default boolean olap() { return false; } - public interface BackendIterator extends Iterator, AutoCloseable { + interface BackendIterator extends Iterator, AutoCloseable { @Override - public void close(); + void close(); - public byte[] position(); + byte[] position(); } - public interface BackendColumnIterator - extends BackendIterator { + interface BackendColumnIterator extends BackendIterator { - public static BackendColumnIterator empty() { + static BackendColumnIterator empty() { return EMPTY; } - public static BackendColumnIterator iterator(BackendColumn element) { + static BackendColumnIterator iterator(BackendColumn element) { return new OneColumnIterator(element); } - public static BackendColumnIterator wrap(Iterator iter) { + static BackendColumnIterator wrap(Iterator iter) { return new BackendColumnIteratorWrapper(iter); } - public static final BackendColumnIterator EMPTY = new EmptyIterator(); + BackendColumnIterator EMPTY = new EmptyIterator(); - public static final class EmptyIterator - implements BackendColumnIterator { + final class EmptyIterator implements BackendColumnIterator { @Override public boolean hasNext() { @@ -150,8 +157,7 @@ public byte[] position() { } } - public static final class OneColumnIterator - implements BackendColumnIterator { + final class OneColumnIterator implements BackendColumnIterator { private BackendColumn element; @@ -186,8 +192,7 @@ public byte[] position() { } } - public static final class BackendColumnIteratorWrapper - implements BackendColumnIterator { + final class BackendColumnIteratorWrapper implements BackendColumnIterator { private final Iterator iter; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendMutation.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendMutation.java index 58c907545f..e371b3ad7c 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendMutation.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendMutation.java @@ -111,6 +111,19 @@ private void optimizeUpdates(BackendEntry entry, Action action) { " transaction between %s and %s", entry, originItem.entry())); } + + if (originAction == Action.INSERT || + originAction == Action.DELETE) { + throw incompatibleActionException(action, originAction); + } else { + Id subId = entry.subId(); + Id originSubId = originItem.entry().subId(); + assert subId != null; + if (subId == originSubId || subId.equals(originSubId)) { + iter.remove(); + } + } + break; case ELIMINATE: if (originAction == Action.INSERT || originAction == Action.DELETE) { diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendSession.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendSession.java index a340730a40..65258bfea2 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendSession.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendSession.java @@ -26,34 +26,39 @@ */ public interface BackendSession { - public void open(); - public void close(); + void open(); - public boolean opened(); - public boolean closed(); + void close(); - public Object commit(); + boolean opened(); - public void rollback(); + boolean closed(); - public boolean hasChanges(); + Object commit(); - public int attach(); - public int detach(); + void rollback(); - public long created(); - public long updated(); - public void update(); + boolean hasChanges(); - public default void reconnectIfNeeded() { + int attach(); + + int detach(); + + long created(); + + long updated(); + + void update(); + + default void reconnectIfNeeded() { // pass } - public default void reset() { + default void reset() { // pass } - public abstract class AbstractBackendSession implements BackendSession { + abstract class AbstractBackendSession implements BackendSession { protected boolean opened; private int refs; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendStore.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendStore.java index eff4e9f02c..9f8e1e4967 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendStore.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendStore.java @@ -32,55 +32,62 @@ public interface BackendStore { // Store name - public String store(); + String store(); // Database name - public String database(); + String database(); // Get the parent provider - public BackendStoreProvider provider(); + BackendStoreProvider provider(); // Whether it is the storage of schema - public boolean isSchemaStore(); + boolean isSchemaStore(); // Open/close database - public void open(HugeConfig config); - public void close(); - public boolean opened(); + void open(HugeConfig config); + + void close(); + + boolean opened(); // Initialize/clear database - public void init(); - public void clear(boolean clearSpace); - public boolean initialized(); + void init(); + + void clear(boolean clearSpace); + + boolean initialized(); // Delete all data of database (keep table structure) - public void truncate(); + void truncate(); // Add/delete data - public void mutate(BackendMutation mutation); + void mutate(BackendMutation mutation); // Query data - public Iterator query(Query query); - public Number queryNumber(Query query); + Iterator query(Query query); + + Number queryNumber(Query query); // Transaction - public void beginTx(); - public void commitTx(); - public void rollbackTx(); + void beginTx(); + + void commitTx(); + + void rollbackTx(); // Get metadata by key - public R metadata(HugeType type, String meta, Object[] args); + R metadata(HugeType type, String meta, Object[] args); // Backend features - public BackendFeatures features(); + BackendFeatures features(); // Generate an id for a specific type - public default Id nextId(HugeType type) { + default Id nextId(HugeType type) { final int MAX_TIMES = 1000; // Do get-increase-get-compare operation long counter = 0L; long expect = -1L; - synchronized(this) { + synchronized (this) { for (int i = 0; i < MAX_TIMES; i++) { counter = this.getCounter(type); @@ -95,14 +102,16 @@ public default Id nextId(HugeType type) { } 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()); + return IdGenerator.of(expect); } // Set next id >= lowest for a specific type - public default void setCounterLowest(HugeType type, long lowest) { + default void setCounterLowest(HugeType type, long lowest) { long current = this.getCounter(type); if (current >= lowest) { return; @@ -111,62 +120,57 @@ public default void setCounterLowest(HugeType type, long lowest) { this.increaseCounter(type, increment); } - public default String olapTableName(HugeType type) { - StringBuilder sb = new StringBuilder(7); - sb.append(this.store()) - .append("_") - .append(HugeType.OLAP.string()) - .append("_") - .append(type.string()); - return sb.toString().toLowerCase(); + default String olapTableName(HugeType type) { + StringBuilder builder = new StringBuilder(7); + builder.append(this.store()) + .append("_") + .append(HugeType.OLAP.string()) + .append("_") + .append(type.string()); + return builder.toString().toLowerCase(); } - public default String olapTableName(Id id) { - StringBuilder sb = new StringBuilder(5 + 4); - sb.append(this.store()) - .append("_") - .append(HugeType.OLAP.string()) - .append("_") - .append(id.asLong()); - return sb.toString().toLowerCase(); + default String olapTableName(Id id) { + StringBuilder builder = new StringBuilder(5 + 4); + builder.append(this.store()) + .append("_") + .append(HugeType.OLAP.string()) + .append("_") + .append(id.asLong()); + return builder.toString().toLowerCase(); } // Increase next id for specific type - public void increaseCounter(HugeType type, long increment); + void increaseCounter(HugeType type, long increment); // Get current counter for a specific type - public long getCounter(HugeType type); + long getCounter(HugeType type); - public default void createOlapTable(Id pkId) { - throw new UnsupportedOperationException( - "BackendStore.createOlapTable()"); + default void createOlapTable(Id pkId) { + throw new UnsupportedOperationException("BackendStore.createOlapTable()"); } - public default void checkAndRegisterOlapTable(Id pkId) { - throw new UnsupportedOperationException( - "BackendStore.checkAndRegisterOlapTable()"); + default void checkAndRegisterOlapTable(Id pkId) { + throw new UnsupportedOperationException("BackendStore.checkAndRegisterOlapTable()"); } - public default void clearOlapTable(Id pkId) { - throw new UnsupportedOperationException( - "BackendStore.clearOlapTable()"); + default void clearOlapTable(Id pkId) { + throw new UnsupportedOperationException("BackendStore.clearOlapTable()"); } - public default void removeOlapTable(Id pkId) { - throw new UnsupportedOperationException( - "BackendStore.removeOlapTable()"); + default void removeOlapTable(Id pkId) { + throw new UnsupportedOperationException("BackendStore.removeOlapTable()"); } - public default Map createSnapshot(String snapshotDir) { + default Map createSnapshot(String snapshotDir) { throw new UnsupportedOperationException("createSnapshot"); } - public default void resumeSnapshot(String snapshotDir, - boolean deleteSnapshot) { + default void resumeSnapshot(String snapshotDir, boolean deleteSnapshot) { throw new UnsupportedOperationException("resumeSnapshot"); } - static enum TxState { + enum TxState { BEGIN, COMMITTING, COMMITT_FAIL, ROLLBACKING, ROLLBACK_FAIL, CLEAN } } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendStoreProvider.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendStoreProvider.java index a4027e17ac..3d794d2c9d 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendStoreProvider.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendStoreProvider.java @@ -27,46 +27,45 @@ public interface BackendStoreProvider { // Backend store type - public String type(); + String type(); // Backend store version - public String version(); + String version(); // Graph name (that's database name) - public String graph(); + String graph(); - public BackendStore loadSystemStore(HugeConfig config, String name); + BackendStore loadSystemStore(HugeConfig config, String name); - public BackendStore loadSchemaStore(HugeConfig config, String name); + BackendStore loadSchemaStore(HugeConfig config, String name); - public BackendStore loadGraphStore(HugeConfig config, String name); + BackendStore loadGraphStore(HugeConfig config, String name); + void open(String name); - public void open(String name); + void waitStoreStarted(); - public void waitStoreStarted(); + void close(); - public void close(); + void init(); - public void init(); + void clear(); - public void clear(); + void truncate(); - public void truncate(); + void initSystemInfo(HugeGraph graph); - public void initSystemInfo(HugeGraph graph); + void createSnapshot(); - public void createSnapshot(); + void resumeSnapshot(); - public void resumeSnapshot(); + void listen(EventListener listener); - public void listen(EventListener listener); + void unlisten(EventListener listener); - public void unlisten(EventListener listener); + EventHub storeEventHub(); - public EventHub storeEventHub(); + void onCloneConfig(HugeConfig config, String newGraph); - public void onCloneConfig(HugeConfig config, String newGraph); - - public void onDeleteConfig(HugeConfig config); + void onDeleteConfig(HugeConfig config); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendTable.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendTable.java index 334194741d..7126e4a632 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendTable.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendTable.java @@ -122,7 +122,7 @@ public static final String joinTableName(String prefix, String table) { /****************************** ShardSplitter ******************************/ - public static abstract class ShardSplitter { + public abstract static class ShardSplitter { // The min shard size should >= 1M to prevent too many number of shards protected static final int MIN_SHARD_SIZE = (int) Bytes.MB; @@ -220,7 +220,8 @@ public List splitEven(int count) { endKey(this.endKey), 0)); } - byte[] start, end; + byte[] start; + byte[] end; boolean startChanged = false; boolean endChanged = false; int length; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/MetaHandler.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/MetaHandler.java index f19270a450..1436f0bd73 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/MetaHandler.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/MetaHandler.java @@ -21,5 +21,5 @@ public interface MetaHandler { - public Object handle(Session session, String meta, Object... args); + Object handle(Session session, String meta, Object... args); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/raft/RaftBackendStore.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/raft/RaftBackendStore.java index c21e3f58e7..06ddf9e20b 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/raft/RaftBackendStore.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/raft/RaftBackendStore.java @@ -189,10 +189,9 @@ public void increaseCounter(HugeType type, long increment) { @Override public long getCounter(HugeType type) { - Object counter = this.queryByRaft(type, true, - o -> this.store.getCounter(type)); - assert counter instanceof Long; - return (Long) counter; + Object counter = this.queryByRaft(type, true, o -> this.store.getCounter(type)); + assert counter instanceof Long; + return (Long) counter; } private Object submitAndWait(StoreAction action, byte[] data) { diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/RamTable.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/RamTable.java index 9fd2f14764..ba2bbc4bd1 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/RamTable.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/RamTable.java @@ -542,7 +542,9 @@ private void addVertex(Id vertex) { if (this.vertices.size() > 0) { lastId = this.vertices.get(this.vertices.size() - 1); } - LOG.info("scan from hbase source {} lastId value: {} compare {} size {}", vertex, lastId, vertex.compareTo(lastId), this.vertices.size()); + LOG.info("scan from hbase source {} lastId value: {} compare {} size {}", + vertex, lastId, vertex.compareTo(lastId), this.vertices.size()); + if (vertex.compareTo(lastId) < 0) { throw new HugeException("The ramtable feature is not " + "supported by %s backend", diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphIndexTransaction.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphIndexTransaction.java index 3397cc3f6a..26b896d46f 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphIndexTransaction.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphIndexTransaction.java @@ -211,7 +211,7 @@ protected void updateIndex(Id ilId, HugeElement element, boolean removed) { if (property == null) { E.checkState(hasNullableProp(element, fieldId), "Non-null property '%s' is null for '%s'", - this.graph().propertyKey(fieldId) , element); + this.graph().propertyKey(fieldId), element); if (firstNullField == fieldsNum) { firstNullField = allPropValues.size(); } @@ -328,8 +328,7 @@ private boolean hasEliminateInTx(IndexLabel indexLabel, Object value, return this.mutation().contains(entry, Action.ELIMINATE); } - private boolean existUniqueValueInStore(IndexLabel indexLabel, - Object value) { + private boolean existUniqueValueInStore(IndexLabel indexLabel, Object value) { ConditionQuery query = new ConditionQuery(HugeType.UNIQUE_INDEX); query.eq(HugeKeys.INDEX_LABEL_ID, indexLabel.id()); query.eq(HugeKeys.FIELD_VALUES, value); @@ -349,8 +348,7 @@ private boolean existUniqueValueInStore(IndexLabel indexLabel, index.elementId()); } while (iterator.hasNext()) { - LOG.warn("Unique constraint conflict found by record {}", - iterator.next()); + LOG.warn("Unique constraint conflict found by record {}", iterator.next()); } } finally { CloseableIterator.closeIterator(iterator); @@ -423,10 +421,10 @@ private IdHolderList queryByLabel(ConditionQuery query) { "label index is disabled", schemaLabel); } - ConditionQuery indexQuery; - indexQuery = new ConditionQuery(indexType , query); + ConditionQuery indexQuery = new ConditionQuery(indexType, query); indexQuery.eq(HugeKeys.INDEX_LABEL_ID, il.id()); indexQuery.eq(HugeKeys.FIELD_VALUES, label); + /* * We can avoid redundant element ids if set limit, but if there are * label index overridden by other vertices with different label, @@ -825,9 +823,7 @@ private MatchedIndex collectMatchedIndex(SchemaLabel schemaLabel, return null; } - - private ConditionQuery constructSearchQuery(ConditionQuery query, - MatchedIndex index) { + private ConditionQuery constructSearchQuery(ConditionQuery query, MatchedIndex index) { ConditionQuery newQuery = query; Set indexFields = new HashSet<>(); // Convert has(key, text) to has(key, textContainsAny(word1, word2)) @@ -1818,11 +1814,11 @@ private IndexLabel findMatchedIndexLabel(ConditionQuery query, leftIndex) { Set matchedIndexes = this.tx.collectMatchedIndexes(query); for (MatchedIndex index : matchedIndexes) { - for (IndexLabel label : index.indexLabels()){ - if (label.indexField().equals(leftIndex.indexField())){ - return label; - } - } + for (IndexLabel label : index.indexLabels()) { + if (label.indexField().equals(leftIndex.indexField())) { + return label; + } + } } return null; } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java index 55be0ce0ab..ade53c1dcb 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java @@ -610,7 +610,7 @@ public HugeVertex addVertex(HugeVertex vertex) { this.beforeWrite(); this.addedVertices.put(vertex.id(), vertex); this.afterWrite(); - } catch (Throwable e){ + } catch (Throwable e) { this.locksTable.unlock(); throw e; }