NetDB: Improve handling of deferred search result jobs

This commit is contained in:
zzz
2016-03-20 13:41:26 +00:00
parent ed72847374
commit 557f16b8d5
3 changed files with 13 additions and 2 deletions

View File

@ -232,6 +232,7 @@ class FloodOnlySearchJob extends FloodSearchJob {
synchronized (this) {
if (_dead) return;
_dead = true;
super.success();
}
if (_log.shouldLog(Log.INFO))
_log.info(getJobId() + ": Floodfill search for " + _key + " successful");

View File

@ -33,6 +33,7 @@ public class FloodSearchJob extends JobImpl {
protected final AtomicInteger _lookupsRemaining = new AtomicInteger();
protected volatile boolean _dead;
protected final long _created;
protected boolean _success;
/**
* @param onFind may be null
@ -69,6 +70,7 @@ public class FloodSearchJob extends JobImpl {
* @param isLease ignored
*/
void addDeferred(Job onFind, Job onFailed, long timeoutMs, boolean isLease) {
boolean success;
synchronized (this) {
if (!_dead) {
if (onFind != null)
@ -77,9 +79,13 @@ public class FloodSearchJob extends JobImpl {
_onFailed.add(onFailed);
return;
}
success = _success;
}
// outside synch to avoid deadlock with job queue
getContext().jobQueue().addJob(onFailed);
if (success && onFind != null)
getContext().jobQueue().addJob(onFind);
else if (!success && onFailed != null)
getContext().jobQueue().addJob(onFailed);
}
/** using context clock */
@ -193,8 +199,11 @@ public class FloodSearchJob extends JobImpl {
* Deprecated, unused, see FOSJ override
*/
void success() {
throw new UnsupportedOperationException("use override");
synchronized(this) {
_success = true;
}
/****
throw new UnsupportedOperationException("use override");
if (_dead) return;
if (_log.shouldLog(Log.INFO))
_log.info(getJobId() + ": Floodfill search for " + _key.toBase64() + " successful");

View File

@ -587,6 +587,7 @@ class IterativeSearchJob extends FloodSearchJob {
synchronized(this) {
if (_dead) return;
_dead = true;
_success = true;
tries = _unheardFrom.size() + _failedPeers.size();
if (_unheardFrom.size() == 1) {
peer = _unheardFrom.iterator().next();