From e8fb9f08d427ea01e588b159f9dd81b4d2697cb5 Mon Sep 17 00:00:00 2001 From: zhangyi51 Date: Tue, 27 Oct 2020 11:40:47 +0800 Subject: [PATCH 1/6] set indexlabel invalid if create or rebuild failed also check if indexlabel invalid when query by index Change-Id: If890b3bd8c441b63642a2006479cf4ccca9ddf67 --- .../backend/tx/GraphIndexTransaction.java | 12 +++++++ .../job/schema/RebuildIndexCallable.java | 35 ++++++++++++------- .../schema/builder/IndexLabelBuilder.java | 16 ++++++--- .../hugegraph/type/define/SchemaStatus.java | 4 ++- 4 files changed, 49 insertions(+), 18 deletions(-) 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 2ab6a07ea5..993355195a 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 @@ -86,6 +86,7 @@ import com.baidu.hugegraph.type.define.Action; import com.baidu.hugegraph.type.define.HugeKeys; import com.baidu.hugegraph.type.define.IndexType; +import com.baidu.hugegraph.type.define.SchemaStatus; import com.baidu.hugegraph.util.CollectionUtil; import com.baidu.hugegraph.util.E; import com.baidu.hugegraph.util.InsertionOrderUtil; @@ -369,6 +370,7 @@ public IdHolderList queryIndex(ConditionQuery query) { private IdHolderList queryByLabel(ConditionQuery query) { HugeType queryType = query.resultType(); IndexLabel il = IndexLabel.label(queryType); + validIndexLabel(il); Id label = query.condition(HugeKeys.LABEL); assert label != null; @@ -426,6 +428,9 @@ private IdHolderList queryByUserprop(ConditionQuery query) { // Do index query IdHolderList holders = new IdHolderList(paging); for (MatchedIndex index : indexes) { + for (IndexLabel il : index.indexLabels()) { + validIndexLabel(il); + } if (paging && index.indexLabels().size() > 1) { throw new NotSupportException("joint index query in paging"); } @@ -1349,6 +1354,13 @@ private static NoIndexException noIndexException(HugeGraph graph, name, String.join("/", mismatched)); } + private static void validIndexLabel(IndexLabel indexLabel) { + if (indexLabel.status() == SchemaStatus.INVALID) { + throw new HugeException("The label index %s is invalid", + indexLabel); + } + } + private static boolean hasNullableProp(HugeElement element, Id key) { return element.schemaLabel().nullableKeys().contains(key); } 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 cfb931ef73..32066827a1 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 @@ -119,19 +119,27 @@ private void rebuildIndex(SchemaLabel label, Collection indexLabelIds) { * They have different id lead to it can't compare and optimize */ graphTx.commit(); - if (label.type() == HugeType.VERTEX_LABEL) { - @SuppressWarnings("unchecked") - Consumer consumer = (Consumer) indexUpdater; - graphTx.traverseVerticesByLabel((VertexLabel) label, - consumer, false); - } else { - assert label.type() == HugeType.EDGE_LABEL; - @SuppressWarnings("unchecked") - Consumer consumer = (Consumer) indexUpdater; - graphTx.traverseEdgesByLabel((EdgeLabel) label, - consumer, false); + + try { + if (label.type() == HugeType.VERTEX_LABEL) { + @SuppressWarnings("unchecked") + Consumer consumer = (Consumer) indexUpdater; + graphTx.traverseVerticesByLabel((VertexLabel) label, + consumer, false); + } else { + assert label.type() == HugeType.EDGE_LABEL; + @SuppressWarnings("unchecked") + Consumer consumer = (Consumer) indexUpdater; + graphTx.traverseEdgesByLabel((EdgeLabel) label, + consumer, false); + } + graphTx.commit(); + } catch (Throwable t) { + for (IndexLabel il : ils) { + schemaTx.updateSchemaStatus(il, SchemaStatus.INVALID); + } + throw t; } - graphTx.commit(); for (IndexLabel il : ils) { schemaTx.updateSchemaStatus(il, SchemaStatus.CREATED); @@ -158,6 +166,9 @@ private void removeIndex(Collection indexLabelIds) { try { locks.lockWrites(LockUtil.INDEX_LABEL_DELETE, indexLabelIds); graphTx.removeIndex(il); + } catch (Throwable t) { + il.status(SchemaStatus.INVALID); + throw t; } finally { locks.unlock(); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/IndexLabelBuilder.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/IndexLabelBuilder.java index 5c20056a3c..7c868acada 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/IndexLabelBuilder.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/IndexLabelBuilder.java @@ -222,13 +222,19 @@ public IndexLabel.CreatedIndexLabel createWithTask() { // Create index label (just schema) indexLabel.status(SchemaStatus.CREATING); - this.graph().addIndexLabel(schemaLabel, indexLabel); + try { + this.graph().addIndexLabel(schemaLabel, indexLabel); - // Async rebuild index - Id rebuildTask = this.rebuildIndex(indexLabel, removeTasks); - E.checkNotNull(rebuildTask, "rebuild-index task"); + // Async rebuild index + Id rebuildTask = this.rebuildIndex(indexLabel, removeTasks); + E.checkNotNull(rebuildTask, "rebuild-index task"); - return new IndexLabel.CreatedIndexLabel(indexLabel, rebuildTask); + return new IndexLabel.CreatedIndexLabel(indexLabel, + rebuildTask); + } catch (Throwable t) { + indexLabel.status(SchemaStatus.INVALID); + throw t; + } }); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/SchemaStatus.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/SchemaStatus.java index f6cf218456..2cadc29d11 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/SchemaStatus.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/SchemaStatus.java @@ -27,7 +27,9 @@ public enum SchemaStatus implements SerialEnum { REBUILDING(3, "rebuilding"), - DELETING(4, "deleting"); + DELETING(4, "deleting"), + + INVALID(5, "invalid"); private byte code = 0; private String name = null; From e81ea8842d2352e043900514f5f6ecea80c62f27 Mon Sep 17 00:00:00 2001 From: zhangyi51 Date: Tue, 27 Oct 2020 19:03:08 +0800 Subject: [PATCH 2/6] improve Change-Id: Ib8ee461872a463480fdc03faf3240a4254cc66f9 --- .../hugegraph/backend/tx/GraphIndexTransaction.java | 10 +++++----- .../hugegraph/job/schema/RebuildIndexCallable.java | 10 +++++----- .../hugegraph/schema/builder/IndexLabelBuilder.java | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) 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 993355195a..0789eb7e36 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 @@ -370,7 +370,7 @@ public IdHolderList queryIndex(ConditionQuery query) { private IdHolderList queryByLabel(ConditionQuery query) { HugeType queryType = query.resultType(); IndexLabel il = IndexLabel.label(queryType); - validIndexLabel(il); + validateIndexLabel(il); Id label = query.condition(HugeKeys.LABEL); assert label != null; @@ -429,7 +429,7 @@ private IdHolderList queryByUserprop(ConditionQuery query) { IdHolderList holders = new IdHolderList(paging); for (MatchedIndex index : indexes) { for (IndexLabel il : index.indexLabels()) { - validIndexLabel(il); + validateIndexLabel(il); } if (paging && index.indexLabels().size() > 1) { throw new NotSupportException("joint index query in paging"); @@ -1354,10 +1354,10 @@ private static NoIndexException noIndexException(HugeGraph graph, name, String.join("/", mismatched)); } - private static void validIndexLabel(IndexLabel indexLabel) { + private static void validateIndexLabel(IndexLabel indexLabel) { if (indexLabel.status() == SchemaStatus.INVALID) { - throw new HugeException("The label index %s is invalid", - indexLabel); + throw new HugeException("Can't query by label index '%s' due to " + + "it is in invalid status", indexLabel); } } 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 32066827a1..da6477170f 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 @@ -134,11 +134,11 @@ private void rebuildIndex(SchemaLabel label, Collection indexLabelIds) { consumer, false); } graphTx.commit(); - } catch (Throwable t) { + } catch (Throwable e) { for (IndexLabel il : ils) { schemaTx.updateSchemaStatus(il, SchemaStatus.INVALID); } - throw t; + throw e; } for (IndexLabel il : ils) { @@ -166,9 +166,9 @@ private void removeIndex(Collection indexLabelIds) { try { locks.lockWrites(LockUtil.INDEX_LABEL_DELETE, indexLabelIds); graphTx.removeIndex(il); - } catch (Throwable t) { - il.status(SchemaStatus.INVALID); - throw t; + } catch (Throwable e) { + schemaTx.updateSchemaStatus(il, SchemaStatus.INVALID); + throw e; } finally { locks.unlock(); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/IndexLabelBuilder.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/IndexLabelBuilder.java index 7c868acada..8d28fe5354 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/IndexLabelBuilder.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/IndexLabelBuilder.java @@ -222,18 +222,18 @@ public IndexLabel.CreatedIndexLabel createWithTask() { // Create index label (just schema) indexLabel.status(SchemaStatus.CREATING); + this.graph().addIndexLabel(schemaLabel, indexLabel); try { - this.graph().addIndexLabel(schemaLabel, indexLabel); - // Async rebuild index Id rebuildTask = this.rebuildIndex(indexLabel, removeTasks); E.checkNotNull(rebuildTask, "rebuild-index task"); return new IndexLabel.CreatedIndexLabel(indexLabel, rebuildTask); - } catch (Throwable t) { + } catch (Throwable e) { indexLabel.status(SchemaStatus.INVALID); - throw t; + this.graph().addIndexLabel(schemaLabel, indexLabel); + throw e; } }); } From 381aefe5ad7db83be300a4ddf58cb77e43167c23 Mon Sep 17 00:00:00 2001 From: zhangyi51 Date: Tue, 27 Oct 2020 21:11:21 +0800 Subject: [PATCH 3/6] improve Change-Id: I57331425089e18582f5938536c5026e703ce34c6 --- .../baidu/hugegraph/schema/builder/AbstractBuilder.java | 7 +++++++ .../baidu/hugegraph/schema/builder/IndexLabelBuilder.java | 3 +-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/AbstractBuilder.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/AbstractBuilder.java index 9674a05096..a6b49e03e4 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/AbstractBuilder.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/AbstractBuilder.java @@ -30,9 +30,11 @@ import com.baidu.hugegraph.schema.EdgeLabel; import com.baidu.hugegraph.schema.IndexLabel; import com.baidu.hugegraph.schema.PropertyKey; +import com.baidu.hugegraph.schema.SchemaElement; import com.baidu.hugegraph.schema.VertexLabel; import com.baidu.hugegraph.type.HugeType; import com.baidu.hugegraph.type.define.GraphMode; +import com.baidu.hugegraph.type.define.SchemaStatus; import com.baidu.hugegraph.util.E; import com.baidu.hugegraph.util.LockUtil; @@ -77,6 +79,11 @@ protected V lockCheckAndCreateSchema(HugeType type, String name, } } + protected void updateSchemaStatus(SchemaElement element, + SchemaStatus status) { + this.transaction.updateSchemaStatus(element, status); + } + protected void checkSchemaIdIfRestoringMode(HugeType type, Id id) { if (this.transaction.graphMode() == GraphMode.RESTORING) { E.checkArgument(id != null, diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/IndexLabelBuilder.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/IndexLabelBuilder.java index 8d28fe5354..86393efa4b 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/IndexLabelBuilder.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/IndexLabelBuilder.java @@ -231,8 +231,7 @@ public IndexLabel.CreatedIndexLabel createWithTask() { return new IndexLabel.CreatedIndexLabel(indexLabel, rebuildTask); } catch (Throwable e) { - indexLabel.status(SchemaStatus.INVALID); - this.graph().addIndexLabel(schemaLabel, indexLabel); + this.updateSchemaStatus(indexLabel, SchemaStatus.INVALID); throw e; } }); From 077fa8500a97936f23b8fb8ad4779d4b8224654a Mon Sep 17 00:00:00 2001 From: zhangyi51 Date: Wed, 28 Oct 2020 14:55:28 +0800 Subject: [PATCH 4/6] improve Change-Id: I6aeaabe6325c336e947fa0d09a824a4138473fa4 --- .../job/schema/IndexLabelRemoveCallable.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/IndexLabelRemoveCallable.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/IndexLabelRemoveCallable.java index f94b7ee368..3cf464dd3d 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/IndexLabelRemoveCallable.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/IndexLabelRemoveCallable.java @@ -54,14 +54,20 @@ protected static void removeIndexLabel(HugeGraphParams graph, Id id) { // TODO add update lock // Set index label to "deleting" status schemaTx.updateSchemaStatus(indexLabel, SchemaStatus.DELETING); - // Remove index data - // TODO: use event to replace direct call - graphTx.removeIndex(indexLabel); - // Remove label from indexLabels of vertex or edge label - removeIndexLabelFromBaseLabel(schemaTx, indexLabel); - removeSchema(schemaTx, indexLabel); - // Should commit changes to backend store before release delete lock - graph.graph().tx().commit(); + try { + // Remove index data + // TODO: use event to replace direct call + graphTx.removeIndex(indexLabel); + // Remove label from indexLabels of vertex or edge label + removeIndexLabelFromBaseLabel(schemaTx, indexLabel); + removeSchema(schemaTx, indexLabel); + // Should commit changes to backend store + // before release delete lock + graph.graph().tx().commit(); + } catch (Throwable e) { + schemaTx.updateSchemaStatus(indexLabel, SchemaStatus.INVALID); + throw e; + } } finally { locks.unlock(); } From 0b3742f47439d456c09f5e7a9130860448251c22 Mon Sep 17 00:00:00 2001 From: zhangyi51 Date: Wed, 28 Oct 2020 15:14:56 +0800 Subject: [PATCH 5/6] improve Change-Id: I855e51feda284ba74522cd98f11b11975dcb80d9 --- .../hugegraph/job/schema/IndexLabelRemoveCallable.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/IndexLabelRemoveCallable.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/IndexLabelRemoveCallable.java index 3cf464dd3d..56f18846f1 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/IndexLabelRemoveCallable.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/IndexLabelRemoveCallable.java @@ -61,8 +61,10 @@ protected static void removeIndexLabel(HugeGraphParams graph, Id id) { // Remove label from indexLabels of vertex or edge label removeIndexLabelFromBaseLabel(schemaTx, indexLabel); removeSchema(schemaTx, indexLabel); - // Should commit changes to backend store - // before release delete lock + /* + * Should commit changes to backend store + * before release delete lock + */ graph.graph().tx().commit(); } catch (Throwable e) { schemaTx.updateSchemaStatus(indexLabel, SchemaStatus.INVALID); From d20e5770f2d41ff95c3c853ce70cbf3f0f691000 Mon Sep 17 00:00:00 2001 From: zhangyi51 Date: Wed, 28 Oct 2020 16:06:57 +0800 Subject: [PATCH 6/6] set vl/el to UNDELETED if fail to delete Change-Id: I7537bd5aff2b43e8a3ba26c88f83761889386ff3 --- .../backend/tx/GraphIndexTransaction.java | 8 +++--- .../backend/tx/GraphTransaction.java | 2 +- .../job/schema/EdgeLabelRemoveCallable.java | 22 ++++++++++------ .../job/schema/IndexLabelRemoveCallable.java | 4 +-- .../job/schema/VertexLabelRemoveCallable.java | 25 ++++++++++++------- .../hugegraph/type/define/SchemaStatus.java | 12 ++++++++- 6 files changed, 49 insertions(+), 24 deletions(-) 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 0789eb7e36..0bb19acb4c 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 @@ -1355,10 +1355,10 @@ private static NoIndexException noIndexException(HugeGraph graph, } private static void validateIndexLabel(IndexLabel indexLabel) { - if (indexLabel.status() == SchemaStatus.INVALID) { - throw new HugeException("Can't query by label index '%s' due to " + - "it is in invalid status", indexLabel); - } + E.checkArgument(indexLabel.status().ok(), + "Can't query by label index '%s' due to " + + "it's in status %s(CREATED expected)", + indexLabel, indexLabel.status()); } private static boolean hasNullableProp(HugeElement element, Id key) { 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 b0351016e8..971e4efec9 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 @@ -1594,7 +1594,7 @@ private Iterator filterUnmatchedRecords( return false; } // Filter vertices/edges of deleting label - if (elem.schemaLabel().status() == SchemaStatus.DELETING && + if (elem.schemaLabel().status().deleting() && !query.showDeleting()) { return false; } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/EdgeLabelRemoveCallable.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/EdgeLabelRemoveCallable.java index 4697c98f97..2af51a57dc 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/EdgeLabelRemoveCallable.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/EdgeLabelRemoveCallable.java @@ -58,14 +58,22 @@ protected static void removeEdgeLabel(HugeGraphParams graph, Id id) { try { locks.lockWrites(LockUtil.EDGE_LABEL_DELETE, id); schemaTx.updateSchemaStatus(edgeLabel, SchemaStatus.DELETING); - for (Id indexId : indexIds) { - IndexLabelRemoveCallable.removeIndexLabel(graph, indexId); + try { + for (Id indexId : indexIds) { + IndexLabelRemoveCallable.removeIndexLabel(graph, indexId); + } + // Remove all edges which has matched label + graphTx.removeEdges(edgeLabel); + removeSchema(schemaTx, edgeLabel); + /* + * Should commit changes to backend store before release + * delete lock + */ + graph.graph().tx().commit(); + } catch (Throwable e) { + schemaTx.updateSchemaStatus(edgeLabel, SchemaStatus.UNDELETED); + throw e; } - // Remove all edges which has matched label - graphTx.removeEdges(edgeLabel); - removeSchema(schemaTx, edgeLabel); - // Should commit changes to backend store before release delete lock - graph.graph().tx().commit(); } finally { locks.unlock(); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/IndexLabelRemoveCallable.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/IndexLabelRemoveCallable.java index 56f18846f1..f1eb3683c3 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/IndexLabelRemoveCallable.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/IndexLabelRemoveCallable.java @@ -62,8 +62,8 @@ protected static void removeIndexLabel(HugeGraphParams graph, Id id) { removeIndexLabelFromBaseLabel(schemaTx, indexLabel); removeSchema(schemaTx, indexLabel); /* - * Should commit changes to backend store - * before release delete lock + * Should commit changes to backend store before release + * delete lock */ graph.graph().tx().commit(); } catch (Throwable e) { diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/VertexLabelRemoveCallable.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/VertexLabelRemoveCallable.java index 713cb797a9..7d3cf80205 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/VertexLabelRemoveCallable.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/schema/VertexLabelRemoveCallable.java @@ -74,16 +74,23 @@ protected static void removeVertexLabel(HugeGraphParams graph, Id id) { try { locks.lockWrites(LockUtil.VERTEX_LABEL_DELETE, id); schemaTx.updateSchemaStatus(vertexLabel, SchemaStatus.DELETING); - for (Id indexLabelId : indexLabelIds) { - IndexLabelRemoveCallable.removeIndexLabel(graph, indexLabelId); + try { + for (Id ilId : indexLabelIds) { + IndexLabelRemoveCallable.removeIndexLabel(graph, ilId); + } + // TODO: use event to replace direct call + // Deleting a vertex will automatically deletes the held edge + graphTx.removeVertices(vertexLabel); + removeSchema(schemaTx, vertexLabel); + /* + * Should commit changes to backend store before release + * delete lock + */ + graph.graph().tx().commit(); + } catch (Throwable e) { + schemaTx.updateSchemaStatus(vertexLabel, SchemaStatus.UNDELETED); + throw e; } - - // TODO: use event to replace direct call - // Deleting a vertex will automatically deletes the held edge - graphTx.removeVertices(vertexLabel); - removeSchema(schemaTx, vertexLabel); - // Should commit changes to backend store before release delete lock - graph.graph().tx().commit(); } finally { locks.unlock(); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/SchemaStatus.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/SchemaStatus.java index 2cadc29d11..be906dfede 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/SchemaStatus.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/SchemaStatus.java @@ -29,7 +29,9 @@ public enum SchemaStatus implements SerialEnum { DELETING(4, "deleting"), - INVALID(5, "invalid"); + UNDELETED(5, "undeleted"), + + INVALID(6, "invalid"); private byte code = 0; private String name = null; @@ -44,6 +46,14 @@ public enum SchemaStatus implements SerialEnum { this.name = name; } + public boolean ok() { + return this == CREATED; + } + + public boolean deleting() { + return this == DELETING || this == UNDELETED; + } + @Override public byte code() { return this.code;