*) Bugfix for "wrong seed-upload timestamp" problem

http://www.yacy-forum.de/viewtopic.php?t=817

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@480 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
theli 20 years ago
parent 34f449e6f1
commit 228b04b499

@ -1,47 +1,47 @@
// Performace_p.java //Performace_p.java
// ----------------------- //-----------------------
// part of YaCy //part of YaCy
// (C) by Michael Peter Christen; mc@anomic.de //(C) by Michael Peter Christen; mc@anomic.de
// first published on http://www.anomic.de //first published on http://www.anomic.de
// Frankfurt, Germany, 2004, 2005 //Frankfurt, Germany, 2004, 2005
// last major change: 16.02.2005 //last major change: 16.02.2005
// //
// 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
// (at your option) any later version. //(at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, //This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of //but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. //GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License //You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software //along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// //
// Using this software in any meaning (reading, learning, copying, compiling, //Using this software in any meaning (reading, learning, copying, compiling,
// running) means that you agree that the Author(s) is (are) not responsible //running) means that you agree that the Author(s) is (are) not responsible
// for cost, loss of data or any harm that may be caused directly or indirectly //for cost, loss of data or any harm that may be caused directly or indirectly
// by usage of this softare or this documentation. The usage of this software //by usage of this softare or this documentation. The usage of this software
// is on your own risk. The installation and usage (starting/running) of this //is on your own risk. The installation and usage (starting/running) of this
// software may allow other people or application to access your computer and //software may allow other people or application to access your computer and
// any attached devices and is highly dependent on the configuration of the //any attached devices and is highly dependent on the configuration of the
// software which must be done by the user of the software; the author(s) is //software which must be done by the user of the software; the author(s) is
// (are) also not responsible for proper configuration and usage of the //(are) also not responsible for proper configuration and usage of the
// software, even if provoked by documentation provided together with //software, even if provoked by documentation provided together with
// the software. //the software.
// //
// Any changes to this file according to the GPL as documented in the file //Any changes to this file according to the GPL as documented in the file
// gpl.txt aside this file in the shipment you received can be done to the //gpl.txt aside this file in the shipment you received can be done to the
// lines that follows this copyright notice here, but changes must not be //lines that follows this copyright notice here, but changes must not be
// done inside the copyright notive above. A re-distribution must contain //done inside the copyright notive above. A re-distribution must contain
// the intact and unchanged copyright notice. //the intact and unchanged copyright notice.
// Contributions and changes to the program code must be marked as such. //Contributions and changes to the program code must be marked as such.
// You must compile this file with //You must compile this file with
// javac -classpath .:../classes Network.java //javac -classpath .:../classes Network.java
// if the shell's current path is HTROOT //if the shell's current path is HTROOT
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
@ -70,7 +70,7 @@ public class Performance_p {
Iterator threads = switchboard.threadNames(); Iterator threads = switchboard.threadNames();
String threadName; String threadName;
serverThread thread; serverThread thread;
// calculate totals // calculate totals
long blocktime_total = 0, sleeptime_total = 0, exectime_total = 0; long blocktime_total = 0, sleeptime_total = 0, exectime_total = 0;
while (threads.hasNext()) { while (threads.hasNext()) {
@ -127,10 +127,10 @@ public class Performance_p {
busysleep = Long.parseLong((String) post.get(threadName + "_busysleep", "100")); busysleep = Long.parseLong((String) post.get(threadName + "_busysleep", "100"));
memprereq = Long.parseLong((String) post.get(threadName + "_memprereq", "0")); memprereq = Long.parseLong((String) post.get(threadName + "_memprereq", "0"));
// check values to prevent short-cut loops // check values to prevent short-cut loops
if (idlesleep < 1000) idlesleep = 1000; if (idlesleep < 1000) idlesleep = 1000;
if (threadName.equals("10_httpd")) { idlesleep = 0; busysleep = 0; memprereq = 0; } if (threadName.equals("10_httpd")) { idlesleep = 0; busysleep = 0; memprereq = 0; }
// on-the-fly re-configuration // on-the-fly re-configuration
switchboard.setThreadPerformance(threadName, idlesleep, busysleep, memprereq); switchboard.setThreadPerformance(threadName, idlesleep, busysleep, memprereq);
switchboard.setConfig(threadName + "_idlesleep", idlesleep); switchboard.setConfig(threadName + "_idlesleep", idlesleep);
@ -142,8 +142,8 @@ public class Performance_p {
busysleep = Long.parseLong(d((String) defaultSettings.get(threadName + "_busysleep"), "100")); busysleep = Long.parseLong(d((String) defaultSettings.get(threadName + "_busysleep"), "100"));
memprereq = Long.parseLong(d((String) defaultSettings.get(threadName + "_memprereq"), "0")); memprereq = Long.parseLong(d((String) defaultSettings.get(threadName + "_memprereq"), "0"));
// check values to prevent short-cut loops // check values to prevent short-cut loops
if (idlesleep < 1000) idlesleep = 1000; if (idlesleep < 1000) idlesleep = 1000;
if (threadName.equals("10_httpd")) { idlesleep = 0; busysleep = 0; memprereq = 0; } if (threadName.equals("10_httpd")) { idlesleep = 0; busysleep = 0; memprereq = 0; }
if ((threadName.equals("50_localcrawl")) && (busysleep < 100)) busysleep = 100; if ((threadName.equals("50_localcrawl")) && (busysleep < 100)) busysleep = 100;
if ((threadName.equals("61_globalcrawltrigger")) && (busysleep < 100)) busysleep = 100; if ((threadName.equals("61_globalcrawltrigger")) && (busysleep < 100)) busysleep = 100;

@ -346,7 +346,7 @@ public class SettingsAck_p {
if (post.containsKey("seedUploadRetry")) { if (post.containsKey("seedUploadRetry")) {
String error; String error;
if ((error = yacyCore.saveSeedList(env)) == null) { if ((error = ((plasmaSwitchboard)env).yc.saveSeedList(env)) == null) {
// trying to upload the seed-list file // trying to upload the seed-list file
prop.put("info", 13); prop.put("info", 13);
prop.put("info_success",1); prop.put("info_success",1);
@ -377,7 +377,7 @@ public class SettingsAck_p {
// try an upload // try an upload
String error; String error;
if ((error = yacyCore.saveSeedList(env)) == null) { if ((error = ((plasmaSwitchboard)env).yc.saveSeedList(env)) == null) {
// we have successfully uploaded the seed-list file // we have successfully uploaded the seed-list file
prop.put("info_seedUploadMethod",newSeedUploadMethod); prop.put("info_seedUploadMethod",newSeedUploadMethod);
prop.put("info_seedURL",newSeedURLStr); prop.put("info_seedURL",newSeedURLStr);
@ -423,7 +423,7 @@ public class SettingsAck_p {
// were changed, we now try to upload the seed list with the new settings // were changed, we now try to upload the seed list with the new settings
if (env.getConfig("seedUploadMethod","none").equalsIgnoreCase(uploaderName)) { if (env.getConfig("seedUploadMethod","none").equalsIgnoreCase(uploaderName)) {
String error; String error;
if ((error = yacyCore.saveSeedList(env)) == null) {; if ((error = ((plasmaSwitchboard)env).yc.saveSeedList(env)) == null) {;
// we have successfully uploaded the seed file // we have successfully uploaded the seed file
prop.put("info", 13); prop.put("info", 13);

@ -179,7 +179,7 @@ public class Status {
prop.put("seedServer_seedFile", env.getConfig("seedFilePath","")); prop.put("seedServer_seedFile", env.getConfig("seedFilePath",""));
} }
prop.put("seedServer_lastUpload", prop.put("seedServer_lastUpload",
serverDate.intervalToString(System.currentTimeMillis()-yacyCore.lastSeedUpload_timeStamp)); serverDate.intervalToString(System.currentTimeMillis()-((plasmaSwitchboard)env).yc.lastSeedUpload_timeStamp));
} else { } else {
prop.put("seedServer", 0);//disabled prop.put("seedServer", 0);//disabled
} }

@ -156,7 +156,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser
public static TreeSet stopwords = null; public static TreeSet stopwords = null;
public static plasmaURLPattern urlBlacklist; public static plasmaURLPattern urlBlacklist;
// storage management // storage management
private File cachePath; private File cachePath;
private File plasmaPath; private File plasmaPath;
public File listsPath; public File listsPath;
@ -181,6 +181,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser
public plasmaParser parser; public plasmaParser parser;
public plasmaWordIndexClassicCacheMigration classicCache; public plasmaWordIndexClassicCacheMigration classicCache;
public long proxyLastAccess; public long proxyLastAccess;
public yacyCore yc;
private serverSemaphore shutdownSync = new serverSemaphore(0); private serverSemaphore shutdownSync = new serverSemaphore(0);
private boolean terminate = false; private boolean terminate = false;
@ -342,7 +343,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser
// start yacy core // start yacy core
log.logSystem("Starting YaCy Protocol Core"); log.logSystem("Starting YaCy Protocol Core");
//try{Thread.currentThread().sleep(5000);} catch (InterruptedException e) {} // for profiler //try{Thread.currentThread().sleep(5000);} catch (InterruptedException e) {} // for profiler
yacyCore yc = new yacyCore(this); this.yc = new yacyCore(this);
//log.logSystem("Started YaCy Protocol Core"); //log.logSystem("Started YaCy Protocol Core");
//System.gc(); try{Thread.currentThread().sleep(5000);} catch (InterruptedException e) {} // for profiler //System.gc(); try{Thread.currentThread().sleep(5000);} catch (InterruptedException e) {} // for profiler
serverInstantThread.oneTimeJob(yc, "loadSeeds", yc.log, 3000); serverInstantThread.oneTimeJob(yc, "loadSeeds", yc.log, 3000);

@ -98,7 +98,7 @@ public class yacyCore {
// class variables // class variables
private int lastSeedUpload_seedDBSize = 0; private int lastSeedUpload_seedDBSize = 0;
public static long lastSeedUpload_timeStamp = System.currentTimeMillis(); public long lastSeedUpload_timeStamp = System.currentTimeMillis();
private String lastSeedUpload_myPeerType = ""; private String lastSeedUpload_myPeerType = "";
private String lastSeedUpload_myIP = ""; private String lastSeedUpload_myIP = "";
@ -238,7 +238,7 @@ public class yacyCore {
(this.lastSeedUpload_myIP.equals(seedDB.mySeed.get("IP", "127.0.0.1"))) && (this.lastSeedUpload_myIP.equals(seedDB.mySeed.get("IP", "127.0.0.1"))) &&
(this.lastSeedUpload_seedDBSize == seedDB.sizeConnected()) && (this.lastSeedUpload_seedDBSize == seedDB.sizeConnected()) &&
(canReachMyself()) && (canReachMyself()) &&
(System.currentTimeMillis() - yacyCore.lastSeedUpload_timeStamp < 1000*60*60*24) && (System.currentTimeMillis() - this.lastSeedUpload_timeStamp < 1000*60*60*24) &&
(seedDB.mySeed.isPrincipal()) (seedDB.mySeed.isPrincipal())
) { ) {
log.logDebug("yacyCore.publishSeedList: not necessary to publish: oldIP is equal, sizeConnected is equal and I can reach myself under the old IP."); log.logDebug("yacyCore.publishSeedList: not necessary to publish: oldIP is equal, sizeConnected is equal and I can reach myself under the old IP.");
@ -260,14 +260,7 @@ public class yacyCore {
this.switchboard.setConfig("seedUploadMethod","File"); this.switchboard.setConfig("seedUploadMethod","File");
} }
// we want to be a principal... // we want to be a principal...
saveSeedList(); saveSeedList();
this.lastSeedUpload_seedDBSize = seedDB.sizeConnected();
this.lastSeedUpload_timeStamp = System.currentTimeMillis();
this.lastSeedUpload_myIP = seedDB.mySeed.get("IP", "127.0.0.1");
this.lastSeedUpload_myPeerType = seedDB.mySeed.get("PeerType", yacySeed.PEERTYPE_JUNIOR);
} else { } else {
if (seedUploadMethod.equals("")) this.switchboard.setConfig("seedUploadMethod","none"); if (seedUploadMethod.equals("")) this.switchboard.setConfig("seedUploadMethod","none");
log.logDebug("yacyCore.publishSeedList: No uploading method configured"); log.logDebug("yacyCore.publishSeedList: No uploading method configured");
@ -629,91 +622,99 @@ public class yacyCore {
return saveSeedList(this.switchboard); return saveSeedList(this.switchboard);
} }
public static String saveSeedList(serverSwitch sb) { public String saveSeedList(serverSwitch sb) {
// return an error if this is not successful, and NULL if everything is fine
String logt;
// be shure that we have something to say
if (seedDB.mySeed.getAddress() == null) {
String errorMsg = "We have no valid IP address until now";
log.logWarning("SaveSeedList: " + errorMsg);
return errorMsg;
}
// getting the configured seed uploader
String seedUploadMethod = sb.getConfig("seedUploadMethod","");
// for backward compatiblity ....
if (
(seedUploadMethod.equalsIgnoreCase("Ftp")) ||
((seedUploadMethod.equals("")) &&
(sb.getConfig("seedFTPPassword","").length() > 0))
) {
seedUploadMethod = "Ftp";
sb.setConfig("seedUploadMethod",seedUploadMethod);
} else if (
(seedUploadMethod.equalsIgnoreCase("File")) ||
((seedUploadMethod.equals("")) &&
(sb.getConfig("seedFilePath", "").length() > 0))
) {
seedUploadMethod = "File";
sb.setConfig("seedUploadMethod",seedUploadMethod);
}
// determine the seed uploader that should be used ...
if (seedUploadMethod.equalsIgnoreCase("none")) return "no uploader specified";
yacySeedUploader uploader = getSeedUploader(seedUploadMethod);
if (uploader == null) {
String errorMsg = "Unable to get the proper uploader-class for seed uploading method '" + seedUploadMethod + "'.";
log.logWarning("SaveSeedList: " + errorMsg);
return errorMsg;
}
// ensure that the seed file url is configured properly
URL seedURL;
try{
String seedURLStr = sb.getConfig("seedURL","");
if (seedURLStr.length() == 0) throw new MalformedURLException("The seed-file url must not be empty.");
if (!seedURLStr.toLowerCase().startsWith("http://")) throw new MalformedURLException("Unsupported protocol.");
seedURL = new URL(seedURLStr);
}catch(MalformedURLException e){
String errorMsg = "Malformed seed file URL '" + sb.getConfig("seedURL","") + "'. " + e.getMessage();
log.logWarning("SaveSeedList: " + errorMsg);
return errorMsg;
}
// upload the seed-list using the configured uploader class
String prevStatus = seedDB.mySeed.get("PeerType", "junior");
if (prevStatus.equals("principal")) prevStatus = "senior";
try { try {
seedDB.mySeed.put("PeerType", "principal"); // this information shall also be uploaded // return an error if this is not successful, and NULL if everything is fine
String logt;
log.logDebug("SaveSeedList: Using seed uploading method '" + seedUploadMethod + "' for seed-list uploading." + // be shure that we have something to say
"\n\tPrevious peerType is '" + seedDB.mySeed.get("PeerType", "junior") + "'."); if (seedDB.mySeed.getAddress() == null) {
String errorMsg = "We have no valid IP address until now";
log.logWarning("SaveSeedList: " + errorMsg);
return errorMsg;
}
// getting the configured seed uploader
String seedUploadMethod = sb.getConfig("seedUploadMethod","");
// for backward compatiblity ....
if (
(seedUploadMethod.equalsIgnoreCase("Ftp")) ||
((seedUploadMethod.equals("")) &&
(sb.getConfig("seedFTPPassword","").length() > 0))
) {
seedUploadMethod = "Ftp";
sb.setConfig("seedUploadMethod",seedUploadMethod);
} else if (
(seedUploadMethod.equalsIgnoreCase("File")) ||
((seedUploadMethod.equals("")) &&
(sb.getConfig("seedFilePath", "").length() > 0))
) {
seedUploadMethod = "File";
sb.setConfig("seedUploadMethod",seedUploadMethod);
}
// determine the seed uploader that should be used ...
if (seedUploadMethod.equalsIgnoreCase("none")) return "no uploader specified";
//logt = seedDB.uploadCache(seedFTPServer, seedFTPAccount, seedFTPPassword, seedFTPPath, seedURL); yacySeedUploader uploader = getSeedUploader(seedUploadMethod);
logt = seedDB.uploadCache(uploader,sb, seedDB, seedURL); if (uploader == null) {
if (logt != null) { String errorMsg = "Unable to get the proper uploader-class for seed uploading method '" + seedUploadMethod + "'.";
if (logt.indexOf("Error") >= 0) { log.logWarning("SaveSeedList: " + errorMsg);
seedDB.mySeed.put("PeerType", prevStatus); return errorMsg;
String errorMsg = "SaveSeedList: seed upload failed using " + uploader.getClass().getName() + " (error): " + logt.substring(logt.indexOf("Error") + 6); }
log.logError(errorMsg);
return errorMsg; // ensure that the seed file url is configured properly
URL seedURL;
try{
String seedURLStr = sb.getConfig("seedURL","");
if (seedURLStr.length() == 0) throw new MalformedURLException("The seed-file url must not be empty.");
if (!seedURLStr.toLowerCase().startsWith("http://")) throw new MalformedURLException("Unsupported protocol.");
seedURL = new URL(seedURLStr);
}catch(MalformedURLException e){
String errorMsg = "Malformed seed file URL '" + sb.getConfig("seedURL","") + "'. " + e.getMessage();
log.logWarning("SaveSeedList: " + errorMsg);
return errorMsg;
}
// upload the seed-list using the configured uploader class
String prevStatus = seedDB.mySeed.get("PeerType", "junior");
if (prevStatus.equals("principal")) prevStatus = "senior";
try {
seedDB.mySeed.put("PeerType", "principal"); // this information shall also be uploaded
log.logDebug("SaveSeedList: Using seed uploading method '" + seedUploadMethod + "' for seed-list uploading." +
"\n\tPrevious peerType is '" + seedDB.mySeed.get("PeerType", "junior") + "'.");
//logt = seedDB.uploadCache(seedFTPServer, seedFTPAccount, seedFTPPassword, seedFTPPath, seedURL);
logt = seedDB.uploadCache(uploader,sb, seedDB, seedURL);
if (logt != null) {
if (logt.indexOf("Error") >= 0) {
seedDB.mySeed.put("PeerType", prevStatus);
String errorMsg = "SaveSeedList: seed upload failed using " + uploader.getClass().getName() + " (error): " + logt.substring(logt.indexOf("Error") + 6);
log.logError(errorMsg);
return errorMsg;
}
log.logInfo(logt);
} }
log.logInfo(logt);
// finally, set the principal status
sb.setConfig("yacyStatus","principal");
return null;
} catch (Exception e) {
seedDB.mySeed.put("PeerType", prevStatus);
sb.setConfig("yacyStatus", prevStatus);
String errorMsg = "SaveSeedList: Seed upload failed (IO error): " + e.getMessage();
log.logInfo(errorMsg);
return errorMsg;
} }
} finally {
this.lastSeedUpload_seedDBSize = seedDB.sizeConnected();
this.lastSeedUpload_timeStamp = System.currentTimeMillis();
// finally, set the principal status this.lastSeedUpload_myIP = seedDB.mySeed.get("IP", "127.0.0.1");
sb.setConfig("yacyStatus","principal"); this.lastSeedUpload_myPeerType = seedDB.mySeed.get("PeerType", yacySeed.PEERTYPE_JUNIOR);
return null;
} catch (Exception e) {
seedDB.mySeed.put("PeerType", prevStatus);
sb.setConfig("yacyStatus", prevStatus);
String errorMsg = "SaveSeedList: Seed upload failed (IO error): " + e.getMessage();
log.logInfo(errorMsg);
return errorMsg;
} }
} }

Loading…
Cancel
Save