|
|
@ -63,6 +63,7 @@ import de.anomic.server.logging.serverLog;
|
|
|
|
import de.anomic.server.serverFileUtils;
|
|
|
|
import de.anomic.server.serverFileUtils;
|
|
|
|
import de.anomic.server.serverInstantThread;
|
|
|
|
import de.anomic.server.serverInstantThread;
|
|
|
|
import de.anomic.server.serverSystem;
|
|
|
|
import de.anomic.server.serverSystem;
|
|
|
|
|
|
|
|
import de.anomic.server.serverThread;
|
|
|
|
import de.anomic.tools.enumerateFiles;
|
|
|
|
import de.anomic.tools.enumerateFiles;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
@ -98,6 +99,7 @@ public final class plasmaHTCache {
|
|
|
|
public static final HashSet filesInUse = new HashSet(); // can we delete this file
|
|
|
|
public static final HashSet filesInUse = new HashSet(); // can we delete this file
|
|
|
|
|
|
|
|
|
|
|
|
private ResourceInfoFactory objFactory;
|
|
|
|
private ResourceInfoFactory objFactory;
|
|
|
|
|
|
|
|
private serverThread cacheScanThread;
|
|
|
|
|
|
|
|
|
|
|
|
public plasmaHTCache(File htCachePath, long maxCacheSize, int bufferkb, long preloadTime) {
|
|
|
|
public plasmaHTCache(File htCachePath, long maxCacheSize, int bufferkb, long preloadTime) {
|
|
|
|
// this.switchboard = switchboard;
|
|
|
|
// this.switchboard = switchboard;
|
|
|
@ -176,7 +178,7 @@ public final class plasmaHTCache {
|
|
|
|
|
|
|
|
|
|
|
|
// start the cache startup thread
|
|
|
|
// start the cache startup thread
|
|
|
|
// this will collect information about the current cache size and elements
|
|
|
|
// this will collect information about the current cache size and elements
|
|
|
|
serverInstantThread.oneTimeJob(this, "cacheScan", this.log, 120000);
|
|
|
|
this.cacheScanThread = serverInstantThread.oneTimeJob(this, "cacheScan", this.log, 120000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void deleteOldHTCache(File directory) {
|
|
|
|
private void deleteOldHTCache(File directory) {
|
|
|
@ -329,27 +331,29 @@ public final class plasmaHTCache {
|
|
|
|
private void cleanupDoIt(long newCacheSize) {
|
|
|
|
private void cleanupDoIt(long newCacheSize) {
|
|
|
|
File obj;
|
|
|
|
File obj;
|
|
|
|
synchronized (cacheAge) {
|
|
|
|
synchronized (cacheAge) {
|
|
|
|
Iterator iter = this.cacheAge.keySet().iterator();
|
|
|
|
Iterator iter = this.cacheAge.keySet().iterator();
|
|
|
|
while (iter.hasNext() && this.curCacheSize >= newCacheSize) {
|
|
|
|
while (iter.hasNext() && this.curCacheSize >= newCacheSize) {
|
|
|
|
Object key = iter.next();
|
|
|
|
if (Thread.currentThread().isInterrupted()) return;
|
|
|
|
obj = (File) this.cacheAge.get(key);
|
|
|
|
|
|
|
|
if (obj != null) {
|
|
|
|
Object key = iter.next();
|
|
|
|
if (filesInUse.contains(obj)) continue;
|
|
|
|
obj = (File) this.cacheAge.get(key);
|
|
|
|
this.log.logFinest("Trying to delete old file: " + obj.toString());
|
|
|
|
if (obj != null) {
|
|
|
|
if (deleteFileandDirs (obj, "OLD")) {
|
|
|
|
if (filesInUse.contains(obj)) continue;
|
|
|
|
try {
|
|
|
|
this.log.logFinest("Trying to delete old file: " + obj.toString());
|
|
|
|
// As the file is gone, the entry in responseHeader.db is not needed anymore
|
|
|
|
if (deleteFileandDirs (obj, "OLD")) {
|
|
|
|
this.log.logFinest("Trying to remove responseHeader for URL: " +
|
|
|
|
try {
|
|
|
|
getURL(this.cachePath ,obj).toString());
|
|
|
|
// As the file is gone, the entry in responseHeader.db is not needed anymore
|
|
|
|
this.responseHeaderDB.remove(indexURL.urlHash(getURL(this.cachePath ,obj)));
|
|
|
|
this.log.logFinest("Trying to remove responseHeader for URL: " +
|
|
|
|
} catch (IOException e) {
|
|
|
|
getURL(this.cachePath ,obj).toString());
|
|
|
|
this.log.logInfo("IOExeption removing response header from DB: " +
|
|
|
|
this.responseHeaderDB.remove(indexURL.urlHash(getURL(this.cachePath ,obj)));
|
|
|
|
e.getMessage(), e);
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
this.log.logInfo("IOExeption removing response header from DB: " +
|
|
|
|
|
|
|
|
e.getMessage(), e);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
iter.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
iter.remove();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -363,6 +367,12 @@ public final class plasmaHTCache {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void close() {
|
|
|
|
public void close() {
|
|
|
|
|
|
|
|
// closing cache scan if still running
|
|
|
|
|
|
|
|
if ((this.cacheScanThread != null) && (this.cacheScanThread.isAlive())) {
|
|
|
|
|
|
|
|
this.cacheScanThread.terminate(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// closing DB
|
|
|
|
try {this.responseHeaderDB.close();} catch (IOException e) {}
|
|
|
|
try {this.responseHeaderDB.close();} catch (IOException e) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -380,18 +390,22 @@ public final class plasmaHTCache {
|
|
|
|
public void cacheScan() {
|
|
|
|
public void cacheScan() {
|
|
|
|
log.logConfig("STARTING HTCACHE SCANNING");
|
|
|
|
log.logConfig("STARTING HTCACHE SCANNING");
|
|
|
|
kelondroMScoreCluster doms = new kelondroMScoreCluster();
|
|
|
|
kelondroMScoreCluster doms = new kelondroMScoreCluster();
|
|
|
|
int c = 0;
|
|
|
|
int fileCount = 0;
|
|
|
|
enumerateFiles ef = new enumerateFiles(this.cachePath, true, false, true, true);
|
|
|
|
enumerateFiles fileEnum = new enumerateFiles(this.cachePath, true, false, true, true);
|
|
|
|
File f;
|
|
|
|
while (fileEnum.hasMoreElements()) {
|
|
|
|
while (ef.hasMoreElements()) {
|
|
|
|
if (Thread.currentThread().isInterrupted()) return;
|
|
|
|
c++;
|
|
|
|
fileCount++;
|
|
|
|
f = (File) ef.nextElement();
|
|
|
|
File nextFile = (File) fileEnum.nextElement();
|
|
|
|
long d = f.lastModified();
|
|
|
|
long nextFileModDate = nextFile.lastModified();
|
|
|
|
//System.out.println("Cache: " + dom(f));
|
|
|
|
//System.out.println("Cache: " + dom(f));
|
|
|
|
doms.incScore(dom(f));
|
|
|
|
doms.incScore(dom(nextFile));
|
|
|
|
this.curCacheSize += f.length();
|
|
|
|
this.curCacheSize += nextFile.length();
|
|
|
|
this.cacheAge.put(ageString(d, f), f);
|
|
|
|
this.cacheAge.put(ageString(nextFileModDate, nextFile), nextFile);
|
|
|
|
try {Thread.sleep(10);} catch (InterruptedException e) {}
|
|
|
|
try {
|
|
|
|
|
|
|
|
Thread.sleep(10);
|
|
|
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//System.out.println("%" + (String) cacheAge.firstKey() + "=" + cacheAge.get(cacheAge.firstKey()));
|
|
|
|
//System.out.println("%" + (String) cacheAge.firstKey() + "=" + cacheAge.get(cacheAge.firstKey()));
|
|
|
|
long ageHours = 0;
|
|
|
|
long ageHours = 0;
|
|
|
@ -401,7 +415,7 @@ public final class plasmaHTCache {
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
//e.printStackTrace();
|
|
|
|
//e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.log.logConfig("CACHE SCANNED, CONTAINS " + c +
|
|
|
|
this.log.logConfig("CACHE SCANNED, CONTAINS " + fileCount +
|
|
|
|
" FILES = " + this.curCacheSize/1048576 + "MB, OLDEST IS " +
|
|
|
|
" FILES = " + this.curCacheSize/1048576 + "MB, OLDEST IS " +
|
|
|
|
((ageHours < 24) ? (ageHours + " HOURS") : ((ageHours / 24) + " DAYS")) + " OLD");
|
|
|
|
((ageHours < 24) ? (ageHours + " HOURS") : ((ageHours / 24) + " DAYS")) + " OLD");
|
|
|
|
cleanup();
|
|
|
|
cleanup();
|
|
|
@ -411,19 +425,24 @@ public final class plasmaHTCache {
|
|
|
|
String dom;
|
|
|
|
String dom;
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
String result = "";
|
|
|
|
String result = "";
|
|
|
|
c = 0;
|
|
|
|
fileCount = 0;
|
|
|
|
while ((doms.size() > 0) && (c < 50) && ((System.currentTimeMillis() - start) < 60000)) {
|
|
|
|
while ((doms.size() > 0) && (fileCount < 50) && ((System.currentTimeMillis() - start) < 60000)) {
|
|
|
|
|
|
|
|
if (Thread.currentThread().isInterrupted()) return;
|
|
|
|
dom = (String) doms.getMaxObject();
|
|
|
|
dom = (String) doms.getMaxObject();
|
|
|
|
InetAddress ip = httpc.dnsResolve(dom);
|
|
|
|
InetAddress ip = httpc.dnsResolve(dom);
|
|
|
|
if (ip == null) continue;
|
|
|
|
if (ip == null) continue;
|
|
|
|
result += ", " + dom + "=" + ip.getHostAddress();
|
|
|
|
result += ", " + dom + "=" + ip.getHostAddress();
|
|
|
|
this.log.logConfig("PRE-FILLED " + dom + "=" + ip.getHostAddress());
|
|
|
|
this.log.logConfig("PRE-FILLED " + dom + "=" + ip.getHostAddress());
|
|
|
|
c++;
|
|
|
|
fileCount++;
|
|
|
|
doms.deleteScore(dom);
|
|
|
|
doms.deleteScore(dom);
|
|
|
|
// wait a short while to prevent that this looks like a DoS
|
|
|
|
// wait a short while to prevent that this looks like a DoS
|
|
|
|
try {Thread.sleep(100);} catch (InterruptedException e) {}
|
|
|
|
try {
|
|
|
|
|
|
|
|
Thread.sleep(100);
|
|
|
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result.length() > 2) this.log.logConfig("PRE-FILLED DNS CACHE, FETCHED " + c +
|
|
|
|
if (result.length() > 2) this.log.logConfig("PRE-FILLED DNS CACHE, FETCHED " + fileCount +
|
|
|
|
" ADDRESSES: " + result.substring(2));
|
|
|
|
" ADDRESSES: " + result.substring(2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|