update to resource observer:

- returns high/medium/low disk space
- pauses crawling on medium disk space
- disables index receive on low disk space

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5310 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
lotus 17 years ago
parent 83967f8c77
commit 8d07607d1d

@ -4,6 +4,8 @@
// (C) by Detlef Reichl; detlef!reichl()gmx!org // (C) by Detlef Reichl; detlef!reichl()gmx!org
// Pforzheim, Germany, 2008 // Pforzheim, Germany, 2008
// //
// changes by David Wieditz
//
// This program is free software; you can redistribute it and/or modify // 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 // it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or // the Free Software Foundation; either version 2 of the License, or
@ -40,13 +42,18 @@ public final class ResourceObserver {
// The memory usage should be checked on every run // The memory usage should be checked on every run
private static final int CHECK_MEMORY_USAGE_FREQ = 1; private 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 serverLog log = new serverLog("RESOURCE OBSERVER");
private final plasmaSwitchboard sb; private final plasmaSwitchboard sb;
private int checkDiskUsageCount; private int checkDiskUsageCount;
private int checkMemoryUsageCount; private int checkMemoryUsageCount;
private boolean disksOK; private int disksFree;
private boolean memoryOK; private int memoryFree;
public ResourceObserver(final plasmaSwitchboard sb) { public ResourceObserver(final plasmaSwitchboard sb) {
this.sb = sb; this.sb = sb;
@ -76,35 +83,40 @@ public final class ResourceObserver {
checkDiskUsageCount = 0; checkDiskUsageCount = 0;
checkMemoryUsageCount = 0; checkMemoryUsageCount = 0;
disksOK = true; disksFree = HIGH;
memoryOK = true; memoryFree = HIGH;
} }
public void resourceObserverJob() { public void resourceObserverJob() {
checkDiskUsageCount++; checkDiskUsageCount++;
checkMemoryUsageCount++; checkMemoryUsageCount++;
boolean tmpDisksOK = true; int tmpDisksFree = HIGH;
boolean tmpMemoryOK = true; int tmpMemoryFree = HIGH;
if (checkDiskUsageCount >= CHECK_DISK_USAGE_FREQ) { if (checkDiskUsageCount >= CHECK_DISK_USAGE_FREQ) {
checkDiskUsageCount = 0; checkDiskUsageCount = 0;
tmpDisksOK = checkDisks(); tmpDisksFree = checkDisks();
disksOK = tmpDisksOK; disksFree = tmpDisksFree;
} }
if (checkMemoryUsageCount >= CHECK_MEMORY_USAGE_FREQ) { if (checkMemoryUsageCount >= CHECK_MEMORY_USAGE_FREQ) {
checkMemoryUsageCount = 0; checkMemoryUsageCount = 0;
tmpMemoryOK = checkMemory(); tmpMemoryFree = checkMemory();
memoryOK = tmpMemoryOK; memoryFree = tmpMemoryFree;
} }
if (!tmpDisksOK || !tmpMemoryOK) { if (tmpDisksFree < HIGH || tmpMemoryFree < HIGH) {
if (!sb.crawlJobIsPaused(plasmaSwitchboardConstants.CRAWLJOB_LOCAL_CRAWL)) { 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); sb.pauseCrawlJob(plasmaSwitchboardConstants.CRAWLJOB_LOCAL_CRAWL);
} }
if (!sb.crawlJobIsPaused(plasmaSwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_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); 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 { else {
if (diskUsage.isUsable()) if (diskUsage.isUsable())
@ -115,11 +127,11 @@ public final class ResourceObserver {
} }
public boolean getDisksOK () { public boolean getDisksOK () {
return disksOK; return disksFree == HIGH;
} }
public boolean getMemoryOK () { 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 ()) if (!diskUsage.isUsable ())
return true; return HIGH;
final HashMap<String, long[]> usage = diskUsage.getDiskUsage(); final HashMap<String, long[]> usage = diskUsage.getDiskUsage();
long[] val; long[] val;
@ -145,14 +163,17 @@ public final class ResourceObserver {
this.log.logInfo("df of Volume " + entry.getKey() + ": " + (val[1] / 1024 / 1024) + " MB"); this.log.logInfo("df of Volume " + entry.getKey() + ": " + (val[1] / 1024 / 1024) + " MB");
if (val[1] < getMinFreeDiskSpace()) { if (val[1] < getMinFreeDiskSpace()) {
this.log.logWarning("Volume " + entry.getKey() + ": free space (" + (val[1] / 1024 / 1024) + " MB) is too low (< " + (getMinFreeDiskSpace() / 1024 / 1024) + " MB)"); 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() { private int checkMemory() {
return true; return HIGH;
} }
} }

Loading…
Cancel
Save