Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
* reenable DHT if yet enough memory is available * reset treshold on reconfiguratoin (thanks to sixcooler)
lotuseac2daf2e8b2
diff --git a/htroot/Status.html b/htroot/Status.htmlindex dcf17a3e2..8265e176e 100644--- a/htroot/Status.html+++ b/htroot/Status.html@@ -93,6 +93,13 @@</dd>#(/warningDiskSpaceLow)#+ #(warningMemoryLow)#::+ <dt class="hintIcon"><img src="env/grafics/bad.png" width="32" height="32" alt="bad"/></dt>+ <dd class="hint">Free memory is lower than #[minSpace]#. DHT has been disabled. Please fix+ it as soon as possible and restart YaCy.+ </dd>+ #(/warningMemoryLow)#+<!-- hints -->#(hintVersionAvailable)#::diff --git a/htroot/Status.java b/htroot/Status.javaindex b7d96b7fa..8e897b406 100644--- a/htroot/Status.java+++ b/htroot/Status.java@@ -133,13 +133,20 @@ public class Status {prop.put("unrestrictedLocalAccess", 1);}- // free disk space- if ((adminaccess) && (!sb.observer.getDisksOK()))- {- final String minFree = Formatter.bytesToString(sb.observer.getMinFreeDiskSpace());- prop.put("warningDiskSpaceLow", "1");- prop.put("warningDiskSpaceLow_minSpace", minFree);- }+ // resource observer status+ if (adminaccess) {+ if (!sb.observer.getDisksOK()){+ final String minFree = Formatter.bytesToString(sb.observer.getMinFreeDiskSpace());+ prop.put("warningDiskSpaceLow", "1");+ prop.put("warningDiskSpaceLow_minSpace", minFree);+ }+ if (!sb.observer.getMemoryOK()){+ final String minFree = Formatter.bytesToString(sb.observer.getMinFreeMemory() * 1024L);+ prop.put("warningMemoryLow", "1");+ prop.put("warningMemoryLow_minSpace", minFree);+ }++ }// version informationdiff --git a/source/de/anomic/crawler/ResourceObserver.java b/source/de/anomic/crawler/ResourceObserver.javaindex af9ba5989..9f24eff9f 100644--- a/source/de/anomic/crawler/ResourceObserver.java+++ b/source/de/anomic/crawler/ResourceObserver.java@@ -56,6 +56,7 @@ public final class ResourceObserver {private int checkMemoryUsageCount;private int disksFree;private int memoryFree;+ private boolean disabledDHT = false;/*** The ResourceObserver checks the resources@@ -106,7 +107,7 @@ public final class ResourceObserver {* checks the resources and pauses crawls if necessary*/public void resourceObserverJob() {- MemoryControl.setDHTkbytes(sb.getConfigLong(SwitchboardConstants.MEMORY_ACCEPTDHT, 0));+ MemoryControl.setDHTkbytes(getMinFreeMemory());checkDiskUsageCount++;checkMemoryUsageCount++;@@ -136,11 +137,19 @@ public final class ResourceObserver {log.logInfo("disabling index receive");sb.setConfig(SwitchboardConstants.INDEX_RECEIVE_ALLOW, false);sb.peers.mySeed().setFlagAcceptRemoteIndex(false);+ disabledDHT = true;}}else {- if (DiskSpace.isUsable())+ if (DiskSpace.isUsable()) {+ if(disabledDHT) { // we were wrong!+ log.logInfo("enabling index receive");+ sb.setConfig(SwitchboardConstants.INDEX_RECEIVE_ALLOW, true);+ sb.peers.mySeed().setFlagAcceptRemoteIndex(true);+ disabledDHT = false;+ }log.logInfo("run completed; everything in order");+ }elselog.logInfo("The observer is out of order: " + DiskSpace.getErrorMessage());}@@ -161,19 +170,26 @@ public final class ResourceObserver {}/**- * @return amount of space (MiB) that should be kept free+ * @return amount of space (bytes) that should be kept free*/public long getMinFreeDiskSpace () {return sb.getConfigLong(SwitchboardConstants.DISK_FREE, 3000) /* MiB */ * 1024L * 1024L;}/**- * @return amount of space (MiB) that should at least be kept free+ * @return amount of space (bytes) that should at least be kept free*/public long getMinFreeDiskSpace_hardlimit () {return sb.getConfigLong(SwitchboardConstants.DISK_FREE_HARDLIMIT, 100) /* MiB */ * 1024L * 1024L;}+ /**+ * @return amount of space (KiB) that should at least be free+ */+ public long getMinFreeMemory() {+ return sb.getConfigLong(SwitchboardConstants.MEMORY_ACCEPTDHT, 0);+ }+/*** returns the amount of disk space available* @return <ul>diff --git a/source/net/yacy/kelondro/util/MemoryControl.java b/source/net/yacy/kelondro/util/MemoryControl.javaindex 0ebee28ea..08295dd04 100644--- a/source/net/yacy/kelondro/util/MemoryControl.java+++ b/source/net/yacy/kelondro/util/MemoryControl.java@@ -182,10 +182,12 @@ public class MemoryControl {public static void setDHTallowed() {allowDHT = true;+ DHTtresholdCount = 0;}public static void setDHTkbytes(final long kbytes) {DHTkbytes = kbytes;+ DHTtresholdCount = 0;}private static void checkDHTrule(final long available) {@@ -202,7 +204,8 @@ public class MemoryControl {log.logInfo("checkDHTrule: below treshold; tresholdCount: " + DHTtresholdCount + "; allowDHT: " + allowDHT);}- //allowDHT = ((available >> 10) < DHTkbytes) ? false : true; // stupid+ else if (!allowDHT && (available >> 10) > (DHTkbytes * 2L)) // we were wrong!+ setDHTallowed();}/**