Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
update to resource observer: - returns high/medium/low disk space - pauses crawling on medium disk space - disables index receive on low disk space
lotus8d07607d1dea
diff --git a/source/de/anomic/crawler/ResourceObserver.java b/source/de/anomic/crawler/ResourceObserver.javaindex 0dc923a8e..b228986b5 100644--- a/source/de/anomic/crawler/ResourceObserver.java+++ b/source/de/anomic/crawler/ResourceObserver.java@@ -4,6 +4,8 @@// (C) by Detlef Reichl; detlef!reichl()gmx!org// Pforzheim, Germany, 2008//+// changes by David Wieditz+//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or@@ -39,14 +41,19 @@ public final class ResourceObserver {private static final int CHECK_DISK_USAGE_FREQ = 1;// The memory usage should be checked on every runprivate static final int CHECK_MEMORY_USAGE_FREQ = 1;++ // return values for available disk/memory+ private static final int LOW = 0;+ private static final int MEDIUM = 1;+ private static final int HIGH = 2;private final serverLog log = new serverLog("RESOURCE OBSERVER");private final plasmaSwitchboard sb;private int checkDiskUsageCount;private int checkMemoryUsageCount;- private boolean disksOK;- private boolean memoryOK;+ private int disksFree;+ private int memoryFree;public ResourceObserver(final plasmaSwitchboard sb) {this.sb = sb;@@ -76,35 +83,40 @@ public final class ResourceObserver {checkDiskUsageCount = 0;checkMemoryUsageCount = 0;- disksOK = true;- memoryOK = true;+ disksFree = HIGH;+ memoryFree = HIGH;}public void resourceObserverJob() {checkDiskUsageCount++;checkMemoryUsageCount++;- boolean tmpDisksOK = true;- boolean tmpMemoryOK = true;+ int tmpDisksFree = HIGH;+ int tmpMemoryFree = HIGH;if (checkDiskUsageCount >= CHECK_DISK_USAGE_FREQ) {checkDiskUsageCount = 0;- tmpDisksOK = checkDisks();- disksOK = tmpDisksOK;+ tmpDisksFree = checkDisks();+ disksFree = tmpDisksFree;}if (checkMemoryUsageCount >= CHECK_MEMORY_USAGE_FREQ) {checkMemoryUsageCount = 0;- tmpMemoryOK = checkMemory();- memoryOK = tmpMemoryOK;+ tmpMemoryFree = checkMemory();+ memoryFree = tmpMemoryFree;}- if (!tmpDisksOK || !tmpMemoryOK) {+ if (tmpDisksFree < HIGH || tmpMemoryFree < HIGH) {if (!sb.crawlJobIsPaused(plasmaSwitchboardConstants.CRAWLJOB_LOCAL_CRAWL)) {- this.log.logInfo("disabling local crawls");+ this.log.logInfo("pausing local crawls");sb.pauseCrawlJob(plasmaSwitchboardConstants.CRAWLJOB_LOCAL_CRAWL);}if (!sb.crawlJobIsPaused(plasmaSwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL)) {- this.log.logInfo("disabling remote triggered crawls");+ this.log.logInfo("pausing remote triggered crawls");sb.pauseCrawlJob(plasmaSwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL);}+ if (tmpDisksFree == LOW && sb.getConfigBool(plasmaSwitchboardConstants.INDEX_RECEIVE_ALLOW, false)) {+ this.log.logInfo("disabling index receive");+ sb.setConfig(plasmaSwitchboardConstants.INDEX_RECEIVE_ALLOW, false);+ sb.webIndex.seedDB.mySeed().setFlagAcceptRemoteIndex(false);+ }}else {if (diskUsage.isUsable())@@ -115,11 +127,11 @@ public final class ResourceObserver {}public boolean getDisksOK () {- return disksOK;+ return disksFree == HIGH;}public boolean getMemoryOK () {- return memoryOK;+ return memoryFree == HIGH;}/**@@ -130,13 +142,19 @@ public final class ResourceObserver {}/**- * @return enough disk space available?+ * returns the amount of disk space available+ * @return <ul>+ * <li><code>HIGH</code> if disk space is available</li>+ * <li><code>MEDIUM</code> if low disk space is available</li>+ * <li><code>LOW</code> if lower than 100MB or 1/5 disk space is available</li>+ * </ul>*/- private boolean checkDisks() {- boolean below = false;++ private int checkDisks() {+ int ret = HIGH;if (!diskUsage.isUsable ())- return true;+ return HIGH;final HashMap<String, long[]> usage = diskUsage.getDiskUsage();long[] val;@@ -145,14 +163,17 @@ public final class ResourceObserver {this.log.logInfo("df of Volume " + entry.getKey() + ": " + (val[1] / 1024 / 1024) + " MB");if (val[1] < getMinFreeDiskSpace()) {this.log.logWarning("Volume " + entry.getKey() + ": free space (" + (val[1] / 1024 / 1024) + " MB) is too low (< " + (getMinFreeDiskSpace() / 1024 / 1024) + " MB)");- below = true;+ ret = MEDIUM;+ }+ if (val[1] < Math.min(getMinFreeDiskSpace() / 5L, 100L)) {+ ret = LOW;}}- return !below;+ return ret;}- private boolean checkMemory() {- return true;+ private int checkMemory() {+ return HIGH;}}