diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/JsonSerializer.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/JsonSerializer.java index 1be4062245..0e0835193f 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/JsonSerializer.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/JsonSerializer.java @@ -33,9 +33,7 @@ import com.baidu.hugegraph.HugeException; import com.baidu.hugegraph.api.API; -import com.baidu.hugegraph.backend.id.Id; import com.baidu.hugegraph.backend.page.PageState; -import com.baidu.hugegraph.backend.store.Shard; import com.baidu.hugegraph.iterator.Metadatable; import com.baidu.hugegraph.schema.EdgeLabel; import com.baidu.hugegraph.schema.IndexLabel; diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/Serializer.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/Serializer.java index 7e51a9efd5..40c45f145f 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/Serializer.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/Serializer.java @@ -27,8 +27,6 @@ import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Vertex; -import com.baidu.hugegraph.backend.id.Id; -import com.baidu.hugegraph.backend.store.Shard; import com.baidu.hugegraph.schema.EdgeLabel; import com.baidu.hugegraph.schema.IndexLabel; import com.baidu.hugegraph.schema.PropertyKey; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextSerializer.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextSerializer.java index 4ba3b8eb20..6ba192dcce 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextSerializer.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextSerializer.java @@ -328,7 +328,7 @@ public BackendEntry writeIndex(HugeIndex index) { * meaningful for deletion of index data in secondary/range index. */ if (index.fieldValues() == null && index.elementIds().size() == 0) { - entry.column(formatSyspropName(HugeKeys.INDEX_LABEL_ID), + entry.column(HugeKeys.INDEX_LABEL_ID, writeId(index.indexLabel())); } else { // TODO: field-values may be a number (range index) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/memory/InMemoryDBTables.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/memory/InMemoryDBTables.java index 8ca66d8093..aa314a2375 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/memory/InMemoryDBTables.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/memory/InMemoryDBTables.java @@ -26,8 +26,10 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.NavigableMap; import java.util.Set; +import java.util.SortedMap; import java.util.concurrent.ConcurrentSkipListMap; import com.baidu.hugegraph.backend.id.EdgeId; @@ -358,7 +360,8 @@ protected SecondaryIndex(HugeType type) { } @Override - public Iterator query(BackendSession session, Query query) { + public Iterator query(BackendSession session, + Query query) { Set conditions = query.conditions(); E.checkState(query instanceof ConditionQuery && conditions.size() == 2, @@ -387,6 +390,23 @@ public Iterator query(BackendSession session, Query query) { q.limit(query.limit()); return super.query(session, q); } + + @Override + public void delete(BackendSession session, TextBackendEntry entry) { + // Delete by index label + assert entry.columnsSize() == 1; + String indexLabel = entry.column(HugeKeys.INDEX_LABEL_ID); + E.checkState(indexLabel != null, "Expect index label"); + + Iterator> iter; + for (iter = this.store().entrySet().iterator(); iter.hasNext();) { + Entry e = iter.next(); + // Delete if prefix with index label + if (e.getKey().asString().startsWith(indexLabel)) { + iter.remove(); + } + } + } } public static class SearchIndex extends SecondaryIndex { @@ -408,7 +428,8 @@ protected NavigableMap store() { } @Override - public Iterator query(BackendSession session, Query query) { + public Iterator query(BackendSession session, + Query query) { Set conditions = query.conditions(); E.checkState(query instanceof ConditionQuery && (conditions.size() == 3 || conditions.size() == 2), @@ -559,5 +580,28 @@ private Iterator betweenQuery(Id indexLabelId, } return results.values().iterator(); } + + @Override + public void delete(BackendSession session, TextBackendEntry entry) { + // Delete by index label + assert entry.columnsSize() == 1; + String indexLabel = entry.column(HugeKeys.INDEX_LABEL_ID); + E.checkState(indexLabel != null, "Expect index label"); + + Id indexLabelId = IdGenerator.of(indexLabel); + Id min = HugeIndex.formatIndexId(HugeType.RANGE_INDEX, + indexLabelId, 0L); + indexLabelId = IdGenerator.of(indexLabelId.asLong() + 1L); + Id max = HugeIndex.formatIndexId(HugeType.RANGE_INDEX, + indexLabelId, 0L); + SortedMap subStore; + subStore = this.store().subMap(min, max); + Iterator> iter; + for (iter = subStore.entrySet().iterator(); iter.hasNext();) { + iter.next(); + // Delete if prefix with index label + iter.remove(); + } + } } } 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 3ee581a73c..ec491d1ede 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 @@ -229,7 +229,7 @@ private void updateIndex(IndexLabel indexLabel, Object propValue, * @return converted id query */ @Watched(prefix = "index") - public List indexQuery(ConditionQuery query) { + public List queryIndex(ConditionQuery query) { // Index query must have been flattened in Graph tx query.checkFlattened(); 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 dc37a58b63..62e063caa3 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 @@ -1042,7 +1042,7 @@ private List indexQuery(ConditionQuery query) { */ this.beforeRead(); try { - return this.indexTx.indexQuery(query); + return this.indexTx.queryIndex(query); } finally { this.afterRead(); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/RebuildIndexCallable.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/RebuildIndexCallable.java index 1fbb49d00c..6c97dbe3d6 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/RebuildIndexCallable.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/RebuildIndexCallable.java @@ -100,7 +100,7 @@ private void rebuildIndex(SchemaLabel label, Collection indexLabelIds) { locks.lockWrites(LockUtil.INDEX_LABEL_DELETE, indexLabelIds); Set ils = indexLabelIds.stream() - .map(schemaTx::getIndexLabel) + .map(this.graph()::indexLabel) .collect(Collectors.toSet()); for (IndexLabel il : ils) { if (il.status() == SchemaStatus.CREATING) { @@ -147,15 +147,15 @@ private void removeIndex(Collection indexLabelIds) { GraphTransaction graphTx = this.graph().graphTransaction(); for (Id id : indexLabelIds) { - IndexLabel indexLabel = schemaTx.getIndexLabel(id); - if (indexLabel == null) { + IndexLabel il = schemaTx.getIndexLabel(id); + if (il == null || il.status() == SchemaStatus.CREATING) { /* * TODO: How to deal with non-existent index name: * continue or throw exception? */ continue; } - graphTx.removeIndex(indexLabel); + graphTx.removeIndex(il); } } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/NeighborRankTraverser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/NeighborRankTraverser.java index 5bebb02287..1e24a9418a 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/NeighborRankTraverser.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/NeighborRankTraverser.java @@ -278,8 +278,8 @@ public void add(Node node) { } public long degree() { - E.checkArgument(degree > 0, - "The degree must be > 0, but got %s", degree); + E.checkArgument(this.degree > 0, + "The degree must be > 0, but got %s", this.degree); return this.degree; } @@ -290,6 +290,8 @@ public void degree(long degree) { private static class Ranks extends OrderLimitMap { + private static final long serialVersionUID = 2041529946017356029L; + public Ranks(int capacity) { super(capacity); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/PersonalRankTraverser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/PersonalRankTraverser.java index ab96e984af..5e084cb554 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/PersonalRankTraverser.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/PersonalRankTraverser.java @@ -109,7 +109,7 @@ private Map calcNewRanks(Set outSeeds, Set inSeeds, newRanks.put(seed, oldRank); continue; } - double incrRank = oldRank * alpha / degree; + double incrRank = oldRank * this.alpha / degree; // Collect all neighbors increment for (Id neighbor : neighbors) { @@ -159,11 +159,6 @@ private Directions getStartDirection(Id source, String label) { } } - private long degreeOfVertex(Id source, Directions dir, Id label) { - return IteratorUtils.count(this.edgesOfVertex(source, dir, label, - this.degree)); - } - private static void removeAll(Map map, Set keys) { for (Id key : keys) { map.remove(key); diff --git a/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java b/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java index 1d03b79851..b66fceb34f 100644 --- a/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java +++ b/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java @@ -64,7 +64,6 @@ import org.apache.hadoop.hbase.util.VersionInfo; import com.baidu.hugegraph.backend.BackendException; -import com.baidu.hugegraph.backend.serializer.BinarySerializer; import com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn; import com.baidu.hugegraph.backend.store.BackendEntry.BackendIterator; import com.baidu.hugegraph.backend.store.BackendSession;