Skip to content

Commit a183571

Browse files
committed
fix(core): skip stale index entries
1 parent b10e3c2 commit a183571

1 file changed

Lines changed: 38 additions & 4 deletions

File tree

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,11 @@ private IdHolder doIndexQueryBatch(IndexLabel indexLabel,
685685
Set<Id> ids = InsertionOrderUtil.newSet();
686686
while ((batch == Query.NO_LIMIT || ids.size() < batch) &&
687687
entries.hasNext()) {
688-
HugeIndex index = this.serializer.readIndex(graph(), query,
689-
entries.next());
688+
HugeIndex index = this.readMatchedIndex(indexLabel, query,
689+
entries.next());
690+
if (index == null) {
691+
continue;
692+
}
690693
this.removeExpiredIndexIfNeeded(index, query.showExpired());
691694
ids.addAll(index.elementIds());
692695
Query.checkForceCapacity(ids.size());
@@ -727,8 +730,11 @@ private PageIds doIndexQueryOnce(IndexLabel indexLabel,
727730
Set<Id> ids = InsertionOrderUtil.newSet();
728731
entries = super.query(query).iterator();
729732
while (entries.hasNext()) {
730-
HugeIndex index = this.serializer.readIndex(graph(), query,
731-
entries.next());
733+
HugeIndex index = this.readMatchedIndex(indexLabel, query,
734+
entries.next());
735+
if (index == null) {
736+
continue;
737+
}
732738
this.removeExpiredIndexIfNeeded(index, query.showExpired());
733739
ids.addAll(index.elementIds());
734740
if (query.reachLimit(ids.size())) {
@@ -756,6 +762,34 @@ private PageIds doIndexQueryOnce(IndexLabel indexLabel,
756762
}
757763
}
758764

765+
private HugeIndex readMatchedIndex(IndexLabel indexLabel,
766+
ConditionQuery query,
767+
BackendEntry entry) {
768+
HugeIndex index;
769+
try {
770+
index = this.serializer.readIndex(graph(), query, entry);
771+
} catch (IllegalArgumentException e) {
772+
if (!missingIndexLabel(e)) {
773+
throw e;
774+
}
775+
LOG.debug("Skip stale index entry with missing index label while " +
776+
"querying index label '{}'", indexLabel.id(), e);
777+
return null;
778+
}
779+
if (!Objects.equals(index.indexLabelId(), indexLabel.id())) {
780+
LOG.debug("Skip stale index entry of index label '{}' while " +
781+
"querying index label '{}'",
782+
index.indexLabelId(), indexLabel.id());
783+
return null;
784+
}
785+
return index;
786+
}
787+
788+
private static boolean missingIndexLabel(IllegalArgumentException e) {
789+
String message = e.getMessage();
790+
return message != null && message.contains("Undefined index label");
791+
}
792+
759793
@Watched(prefix = "index")
760794
private Set<MatchedIndex> collectMatchedIndexes(ConditionQuery query) {
761795
ISchemaTransaction schema = this.params().schemaTransaction();

0 commit comments

Comments
 (0)