Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set indexlabel invalid if create or rebuild failed #1226

Merged
merged 6 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ private void rebuildIndex(SchemaLabel label, Collection<Id> 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) {
Expand Down Expand Up @@ -166,9 +166,9 @@ private void removeIndex(Collection<Id> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

throw t;
this.graph().addIndexLabel(schemaLabel, indexLabel);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

schemaTx.updateSchemaStatus(indexLabel, SchemaStatus.INVALID);

throw e;
}
});
}
Expand Down