Skip to content

Commit

Permalink
Router: bypass the negative cache when the db is a subdb
Browse files Browse the repository at this point in the history
  • Loading branch information
eyedeekay committed Oct 17, 2023
1 parent 00e3390 commit 284bdcb
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,10 @@ public synchronized void startup() {
} catch (IOException ioe) {
throw new RuntimeException("Unable to initialize netdb storage", ioe);
}
_negativeCache = new NegativeLookupCache(_context);
if (isMainDb())
if (isMainDb()) {
_negativeCache = new NegativeLookupCache(_context);
blindCache().startup();
}

createHandlers();

Expand Down Expand Up @@ -802,7 +803,8 @@ public Destination lookupDestinationLocally(Hash key) {
return ls.getDestination();
}
} else {
return _negativeCache.getBadDest(key);
if (_negativeCache != null)
return _negativeCache.getBadDest(key);
}
return null;
}
Expand Down Expand Up @@ -1514,7 +1516,8 @@ protected void lookupBeforeDropping(Hash peer, RouterInfo info) {
*/
void dropAfterLookupFailed(Hash peer) {
_context.peerManager().removeCapabilities(peer);
_negativeCache.cache(peer);
if (_negativeCache != null)
_negativeCache.cache(peer);
_kb.remove(peer);
//if (removed) {
// if (_log.shouldLog(Log.INFO))
Expand Down Expand Up @@ -1656,7 +1659,8 @@ else if (responseTime < MIN_PER_PEER_TIMEOUT)
* @since 0.9.4 moved from FNDF to KNDF in 0.9.16
*/
void lookupFailed(Hash key) {
_negativeCache.lookupFailed(key);
if (_negativeCache != null)
_negativeCache.lookupFailed(key);
}

/**
Expand All @@ -1666,6 +1670,8 @@ void lookupFailed(Hash key) {
* @since 0.9.4 moved from FNDF to KNDF in 0.9.16
*/
boolean isNegativeCached(Hash key) {
if (_negativeCache == null)
return false;
boolean rv = _negativeCache.isCached(key);
if (rv)
_context.statManager().addRateData("netDb.negativeCache", 1);
Expand All @@ -1677,6 +1683,8 @@ boolean isNegativeCached(Hash key) {
* @since 0.9.16
*/
void failPermanently(Destination dest) {
if (_negativeCache != null)
return;
_negativeCache.failPermanently(dest);
}

Expand All @@ -1687,6 +1695,8 @@ void failPermanently(Destination dest) {
* @since 0.9.16
*/
public boolean isNegativeCachedForever(Hash key) {
if (_negativeCache != null)
return false;
return _negativeCache.getBadDest(key) != null;
}

Expand Down

0 comments on commit 284bdcb

Please sign in to comment.