Skip to content

Commit

Permalink
MODE-1858 Building query results should work when nodes are concurren…
Browse files Browse the repository at this point in the history
…tly removed

When the query results are being processed/produced, any node that is not
found is simply ignored (treated as non-existant from the perspective
of the query). However, in certain cases, the timing of a removal could
occur within the method that obtains the document from the cache, causing
an exception. This was rectified to return null in such cases. Thus,
the existing code in the BasicTupleCollector that handles null nodes
will continue to work in all cases.

I was not able to come up with a test case able to replicate this scenario,
however. That's because the failure occurs within a single WorkspaceCache
method, after the SchematicEntry is obtained but before the SchematicEntry's
content document can be obtained. A test case cannot reliably ensure
this condition occurs (without adding junk code within the WorkspaceCache).
  • Loading branch information
rhauch committed Mar 18, 2013
1 parent 6333ac2 commit 8ad30ef
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Expand Up @@ -165,7 +165,13 @@ final Document documentFor( String key ) {
// There is no such node ... // There is no such node ...
return null; return null;
} }
return entry.getContentAsDocument(); try {
return entry.getContentAsDocument();
} catch (IllegalStateException e) {
LOGGER.debug("The document '{0}' was concurrently removed; returning null.", key);
// The document was already removed
return null;
}
} }


final Document blockFor( String key ) { final Document blockFor( String key ) {
Expand Down
Expand Up @@ -190,6 +190,7 @@ public float doCollect( int doc ) throws IOException {


// Every tuple has the location ... // Every tuple has the location ...
if (node != null) { if (node != null) {
// The node was found in the cache/store ...
try { try {
Path path = lastWorkspacePathCache.getPath(node); Path path = lastWorkspacePathCache.getPath(node);
Location location = new Location(path, key); Location location = new Location(path, key);
Expand Down Expand Up @@ -223,6 +224,7 @@ public float doCollect( int doc ) throws IOException {
tuples.add(tuple); tuples.add(tuple);
return score; return score;
} catch (NodeNotFoundException e) { } catch (NodeNotFoundException e) {
// The node was removed while we're trying to read it, so just ignore this error and return 0.0f
} }
} }
return 0.0f; return 0.0f;
Expand Down
Expand Up @@ -133,6 +133,7 @@ protected CacheEntry lookupEntryFromCurrentTransaction() {
* returns the persisted and available entry. * returns the persisted and available entry.
* *
* @return the literal entry * @return the literal entry
* @throws IllegalStateException if the entry no longer exists ...
*/ */
private SchematicEntryLiteral getDeltaValueForRead() { private SchematicEntryLiteral getDeltaValueForRead() {
SchematicEntryLiteral value = toValue(context.getCache().get(key)); SchematicEntryLiteral value = toValue(context.getCache().get(key));
Expand Down

0 comments on commit 8ad30ef

Please sign in to comment.