Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[bugfix] Allow some potentially long-running index scans in structura…

…l index to abort immediately if requested to do so (e.g. during shutdown).
  • Loading branch information...
commit 679eb3c7a6e0f480e9688ae648e0986cc3af3f90 1 parent d1337e9
@wolfgangmm wolfgangmm authored
View
4 src/org/exist/dom/DocumentImpl.java
@@ -779,7 +779,7 @@ protected NodeList findElementsByTagName(StoredNode root, QName qname) {
docs.add(this);
final NodeProxy p = new NodeProxy(this, root.getNodeId(), root.getInternalAddress());
final NodeSelector selector = new DescendantSelector(p, Expression.NO_CONTEXT_ID);
- return broker.getStructuralIndex().findElementsByTagName(ElementValue.ELEMENT, docs, qname, selector);
+ return broker.getStructuralIndex().findElementsByTagName(ElementValue.ELEMENT, docs, qname, selector, null);
} catch (final Exception e) {
LOG.warn("Exception while finding elements: " + e.getMessage(), e);
} finally {
@@ -998,7 +998,7 @@ public NodeList getElementsByTagNameNS(String namespaceURI, String localName) {
final MutableDocumentSet docs = new DefaultDocumentSet();
docs.add(this);
final QName qname = new QName(localName, namespaceURI, null);
- return broker.getStructuralIndex().findElementsByTagName(ElementValue.ELEMENT, docs, qname, null);
+ return broker.getStructuralIndex().findElementsByTagName(ElementValue.ELEMENT, docs, qname, null, null);
} catch (final Exception e) {
LOG.warn("Exception while finding elements: " + e.getMessage(), e);
//TODO : throw exception ?
View
6 src/org/exist/indexing/StructuralIndex.java
@@ -4,6 +4,7 @@
import org.exist.dom.ExtNodeSet;
import org.exist.dom.NodeSet;
import org.exist.dom.QName;
+import org.exist.xquery.Expression;
import org.exist.xquery.NodeSelector;
import org.exist.xquery.NodeTest;
@@ -24,9 +25,14 @@ public boolean matchDescendantsByTagName(byte type, QName qname, int axis,
public NodeSet findElementsByTagName(byte type, DocumentSet docs, QName qname, NodeSelector selector);
+ public NodeSet findElementsByTagName(byte type, DocumentSet docs, QName qname, NodeSelector selector, Expression parent);
+
public NodeSet findDescendantsByTagName(byte type, QName qname, int axis,
DocumentSet docs, NodeSet contextSet, int contextId);
+ public NodeSet findDescendantsByTagName(byte type, QName qname, int axis,
+ DocumentSet docs, NodeSet contextSet, int contextId, Expression parent);
+
public NodeSet findAncestorsByTagName(byte type, QName qname, int axis,
DocumentSet docs, NodeSet contextSet, int contextId);
View
32 src/org/exist/storage/structural/NativeStructuralIndexWorker.java
@@ -62,9 +62,13 @@ public boolean matchDescendantsByTagName(byte type, QName qname, int axis, Docum
* @return nodeset
*/
public NodeSet findElementsByTagName(byte type, DocumentSet docs, QName qname, NodeSelector selector) {
+ return findElementsByTagName(type, docs, qname, selector, null);
+ }
+
+ public NodeSet findElementsByTagName(byte type, DocumentSet docs, QName qname, NodeSelector selector, Expression parent) {
final Lock lock = index.btree.getLock();
final NewArrayNodeSet result = new NewArrayNodeSet(docs.getDocumentCount(), 256);
- final FindElementsCallback callback = new FindElementsCallback(type, result, docs, selector);
+ final FindElementsCallback callback = new FindElementsCallback(type, result, docs, selector, parent);
// scan the document set to find document id ranges to query
final List<Range> ranges = new ArrayList<Range>();
Range next = null;
@@ -125,9 +129,13 @@ private Range(int start) {
* the index.
*/
public NodeSet findDescendantsByTagName(byte type, QName qname, int axis, DocumentSet docs, NodeSet contextSet, int contextId) {
+ return findDescendantsByTagName(type, qname, axis, docs, contextSet, contextId, null);
+ }
+
+ public NodeSet findDescendantsByTagName(byte type, QName qname, int axis, DocumentSet docs, NodeSet contextSet, int contextId, Expression parent) {
final Lock lock = index.btree.getLock();
final NewArrayNodeSet result = new NewArrayNodeSet(docs.getDocumentCount(), 256);
- final FindDescendantsCallback callback = new FindDescendantsCallback(type, axis, contextId, result);
+ final FindDescendantsCallback callback = new FindDescendantsCallback(type, axis, contextId, result, parent);
try {
lock.acquire(Lock.READ_LOCK);
for (final NodeProxy ancestor : contextSet) {
@@ -207,7 +215,7 @@ public NodeSet scanByType(byte type, int axis, NodeTest test, boolean useSelfAsC
NodeSet contextSet, int contextId) {
final Lock lock = index.btree.getLock();
final NewArrayNodeSet result = new NewArrayNodeSet(docs.getDocumentCount(), 256);
- final FindDescendantsCallback callback = new FindDescendantsCallback(type, axis, contextId, useSelfAsContext, result);
+ final FindDescendantsCallback callback = new FindDescendantsCallback(type, axis, contextId, useSelfAsContext, result, null);
for (final NodeProxy ancestor : contextSet) {
final DocumentImpl doc = ancestor.getDocument();
final NodeId ancestorId = ancestor.getNodeId();
@@ -248,15 +256,20 @@ public NodeSet scanByType(byte type, int axis, NodeTest test, boolean useSelfAsC
DocumentSet docs;
NewArrayNodeSet result;
NodeSelector selector;
+ Expression parent;
- FindElementsCallback(byte type, NewArrayNodeSet result, DocumentSet docs, NodeSelector selector) {
+ FindElementsCallback(byte type, NewArrayNodeSet result, DocumentSet docs, NodeSelector selector, Expression parent) {
this.type = type;
this.result = result;
this.docs = docs;
this.selector = selector;
+ this.parent = parent;
}
public boolean indexInfo(Value value, long pointer) throws TerminatedException {
+ if (parent != null) {
+ parent.getContext().proceed(parent);
+ }
final byte[] key = value.getData();
final NodeId nodeId = readNodeId(key, pointer);
final DocumentImpl doc = docs.getDoc(readDocId(key));
@@ -286,17 +299,19 @@ public boolean indexInfo(Value value, long pointer) throws TerminatedException {
int contextId;
NewArrayNodeSet result;
boolean selfAsContext = false;
+ Expression parent;
- FindDescendantsCallback(byte type, int axis, int contextId, NewArrayNodeSet result) {
- this(type, axis, contextId, false, result);
+ FindDescendantsCallback(byte type, int axis, int contextId, NewArrayNodeSet result, Expression parent) {
+ this(type, axis, contextId, false, result, parent);
};
- FindDescendantsCallback(byte type, int axis, int contextId, boolean selfAsContext, NewArrayNodeSet result) {
+ FindDescendantsCallback(byte type, int axis, int contextId, boolean selfAsContext, NewArrayNodeSet result, Expression parent) {
this.type = type;
this.axis = axis;
this.contextId = contextId;
this.result = result;
this.selfAsContext = selfAsContext;
+ this.parent = parent;
}
void setAncestor(DocumentImpl doc, NodeProxy ancestor) {
@@ -305,6 +320,9 @@ void setAncestor(DocumentImpl doc, NodeProxy ancestor) {
}
public boolean indexInfo(Value value, long pointer) throws TerminatedException {
+ if (parent != null) {
+ parent.getContext().proceed(parent);
+ }
final NodeId nodeId = readNodeId(value.getData(), pointer);
boolean match = axis == Constants.DESCENDANT_SELF_AXIS || axis == Constants.DESCENDANT_ATTRIBUTE_AXIS;
View
35 src/org/exist/xquery/LocationStep.java
@@ -570,7 +570,7 @@ protected Sequence getSelf(XQueryContext context, Sequence contextSequence)
"Using structural index '" + index.toString() + "'");}
final NodeSelector selector = new SelfSelector(contextSet, contextId);
return index.findElementsByTagName(ElementValue.ELEMENT, docs, test
- .getName(), selector);
+ .getName(), selector, this);
}
}
@@ -618,8 +618,7 @@ protected Sequence getAttributes(XQueryContext context,
"Using structural index '" + index.toString()
+ "'");}
// TODO : why a null selector here ? We have one below !
- currentSet = index.findElementsByTagName(
- ElementValue.ATTRIBUTE, docs, test.getName(), null);
+ currentSet = index.findElementsByTagName(ElementValue.ATTRIBUTE, docs, test.getName(), null, this);
currentDocs = docs;
registerUpdateListener();
}
@@ -645,7 +644,7 @@ protected Sequence getAttributes(XQueryContext context,
if (!contextSet.getProcessInReverseOrder()) {
return index.findDescendantsByTagName(ElementValue.ATTRIBUTE,
test.getName(), axis, docs, contextSet,
- contextId);
+ contextId, this);
} else {
NodeSelector selector;
switch (axis) {
@@ -659,8 +658,7 @@ protected Sequence getAttributes(XQueryContext context,
throw new IllegalArgumentException(
"Unsupported axis specified");
}
- return index.findElementsByTagName(ElementValue.ATTRIBUTE,
- docs, test.getName(), selector);
+ return index.findElementsByTagName(ElementValue.ATTRIBUTE, docs, test.getName(), selector, this);
}
}
}
@@ -723,7 +721,7 @@ protected Sequence getChildren(XQueryContext context,
"Using structural index '" + index.toString()
+ "'");}
currentSet = index.findElementsByTagName(
- ElementValue.ELEMENT, docs, test.getName(), null);
+ ElementValue.ELEMENT, docs, test.getName(), null, this);
currentDocs = docs;
registerUpdateListener();
}
@@ -741,13 +739,13 @@ protected Sequence getChildren(XQueryContext context,
contextSet.getLength() < INDEX_SCAN_THRESHOLD) {
return index.findDescendantsByTagName(ElementValue.ELEMENT,
test.getName(), axis, docs, contextSet,
- contextId);
+ contextId, parent);
} else {
// if (contextSet instanceof VirtualNodeSet)
// ((VirtualNodeSet)contextSet).realize();
final NodeSelector selector = new ChildSelector(contextSet, contextId);
return index.findElementsByTagName(ElementValue.ELEMENT, docs,
- test.getName(), selector);
+ test.getName(), selector, this);
}
}
}
@@ -797,7 +795,7 @@ protected Sequence getDescendants(XQueryContext context,
"Using structural index '" + index.toString()
+ "'");}
currentSet = index.findElementsByTagName(
- ElementValue.ELEMENT, docs, test.getName(), null);
+ ElementValue.ELEMENT, docs, test.getName(), null, this);
currentDocs = docs;
registerUpdateListener();
}
@@ -826,7 +824,7 @@ protected Sequence getDescendants(XQueryContext context,
if (!contextSet.getProcessInReverseOrder() && (contextSet instanceof VirtualNodeSet || contextSet.getLength() < INDEX_SCAN_THRESHOLD)) {
return index.findDescendantsByTagName(ElementValue.ELEMENT,
test.getName(), axis, docs, contextSet,
- contextId);
+ contextId, this);
} else {
NodeSelector selector;
switch (axis) {
@@ -842,7 +840,7 @@ protected Sequence getDescendants(XQueryContext context,
"Unsupported axis specified");
}
return index.findElementsByTagName(ElementValue.ELEMENT, docs,
- test.getName(), selector);
+ test.getName(), selector, this);
}
}
@@ -917,7 +915,7 @@ protected Sequence getSiblings(XQueryContext context,
"Using structural index '" + index.toString()
+ "'");}
currentSet = index.findElementsByTagName(
- ElementValue.ELEMENT, docs, test.getName(), null);
+ ElementValue.ELEMENT, docs, test.getName(), null, this);
currentDocs = docs;
registerUpdateListener();
}
@@ -1052,7 +1050,7 @@ protected Sequence getPreceding(XQueryContext context,
"Using structural index '" + index.toString()
+ "'");}
currentSet = index.findElementsByTagName(
- ElementValue.ELEMENT, docs, test.getName(), null);
+ ElementValue.ELEMENT, docs, test.getName(), null, this);
currentDocs = docs;
registerUpdateListener();
}
@@ -1148,7 +1146,7 @@ protected Sequence getFollowing(XQueryContext context,
"Using structural index '" + index.toString()
+ "'");}
currentSet = index.findElementsByTagName(
- ElementValue.ELEMENT, docs, test.getName(), null);
+ ElementValue.ELEMENT, docs, test.getName(), null, this);
currentDocs = docs;
registerUpdateListener();
}
@@ -1250,8 +1248,7 @@ protected Sequence getAncestors(XQueryContext context,
"OPTIMIZATION",
"Using structural index '" + index.toString()
+ "'");}
- currentSet = index.findElementsByTagName(
- ElementValue.ELEMENT, docs, test.getName(), null);
+ currentSet = index.findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null, this);
currentDocs = docs;
registerUpdateListener();
}
@@ -1322,7 +1319,7 @@ protected Sequence getParents(XQueryContext context,
"Using structural index '" + index.toString()
+ "'");}
currentSet = index.findElementsByTagName(
- ElementValue.ELEMENT, docs, test.getName(), null);
+ ElementValue.ELEMENT, docs, test.getName(), null, this);
currentDocs = docs;
registerUpdateListener();
}
@@ -1908,7 +1905,7 @@ protected boolean matchAttributes(XQueryContext context,
+ "'");}
// TODO : why a null selector here ? We have one below !
currentSet = index.findElementsByTagName(
- ElementValue.ATTRIBUTE, docs, test.getName(), null);
+ ElementValue.ATTRIBUTE, docs, test.getName(), null, this);
currentDocs = docs;
registerUpdateListener();
}
Please sign in to comment.
Something went wrong with that request. Please try again.