*) another little fix for DHT-Transfer

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1943 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
hydrox 19 years ago
parent 77f3237de3
commit 9411961eec

@ -1,210 +1,212 @@
// plasmaDHTTransfer.java // plasmaDHTTransfer.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, 2005, 2006 // Frankfurt, Germany, 2005, 2006
// //
// This class was provided by Martin Thelian // This class was provided by Martin Thelian
// //
// 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.
package de.anomic.plasma; package de.anomic.plasma;
import de.anomic.server.logging.serverLog; import de.anomic.server.logging.serverLog;
import de.anomic.yacy.yacyClient; import de.anomic.yacy.yacyClient;
import de.anomic.yacy.yacyCore; import de.anomic.yacy.yacyCore;
import de.anomic.yacy.yacySeed; import de.anomic.yacy.yacySeed;
public class plasmaDHTTransfer extends Thread { public class plasmaDHTTransfer extends Thread {
// connection properties // connection properties
private boolean gzipBody4Transfer = false; private boolean gzipBody4Transfer = false;
private int timeout4Transfer = 60000; private int timeout4Transfer = 60000;
// status fields // status fields
private boolean stopped = false; private boolean stopped = false;
private long transferTime = 0; private long transferTime = 0;
private int transferStatus = plasmaDHTChunk.chunkStatus_UNDEFINED; private int transferStatus = plasmaDHTChunk.chunkStatus_UNDEFINED;
private String transferStatusMessage = ""; private String transferStatusMessage = "";
// delivery destination // delivery destination
private yacySeed [] seeds = null; private yacySeed [] seeds = null;
private static int seedcount = 0; private static int seedcount = 0;
private yacySeed seed = null; private yacySeed seed = null;
// word chunk // word chunk
plasmaDHTChunk dhtChunk; plasmaDHTChunk dhtChunk;
// other fields // other fields
private int maxRetry; private int maxRetry;
serverLog log; serverLog log;
public plasmaDHTTransfer(serverLog log, yacySeed seed, plasmaDHTChunk dhtChunk, boolean gzipBody, int timeout, int retries) { public plasmaDHTTransfer(serverLog log, yacySeed seed, plasmaDHTChunk dhtChunk, boolean gzipBody, int timeout, int retries) {
super(new ThreadGroup("TransferIndexThreadGroup"), "TransferIndexWorker_" + seed.getName()); super(new ThreadGroup("TransferIndexThreadGroup"), "TransferIndexWorker_" + seed.getName());
this.log = log; this.log = log;
this.gzipBody4Transfer = gzipBody; this.gzipBody4Transfer = gzipBody;
this.timeout4Transfer = timeout; this.timeout4Transfer = timeout;
this.dhtChunk = dhtChunk; this.dhtChunk = dhtChunk;
this.maxRetry = retries; this.maxRetry = retries;
seeds = new yacySeed[1]; seeds = new yacySeed[1];
seeds[0] = seed; seeds[0] = seed;
} }
public plasmaDHTTransfer(serverLog log, yacySeed [] seeds, plasmaDHTChunk dhtChunk, boolean gzipBody, int timeout, int retries) { public plasmaDHTTransfer(serverLog log, yacySeed [] seeds, plasmaDHTChunk dhtChunk, boolean gzipBody, int timeout, int retries) {
super(new ThreadGroup("TransferIndexThreadGroup"), "TransferIndexWorker_" + seedcount); super(new ThreadGroup("TransferIndexThreadGroup"), "TransferIndexWorker_" + seedcount);
this.log = log; this.log = log;
this.gzipBody4Transfer = gzipBody; this.gzipBody4Transfer = gzipBody;
this.timeout4Transfer = timeout; this.timeout4Transfer = timeout;
this.dhtChunk = dhtChunk; this.dhtChunk = dhtChunk;
this.maxRetry = retries; this.maxRetry = retries;
this.seeds = seeds; this.seeds = seeds;
} }
public void run() { public void run() {
while (getStatus() != plasmaDHTChunk.chunkStatus_COMPLETE && seedcount < seeds.length)try { while (getStatus() != plasmaDHTChunk.chunkStatus_COMPLETE && seedcount < seeds.length)try {
seed = seeds[seedcount++]; synchronized(seed) {
uploadIndex(); seed = seeds[seedcount++];
} catch (InterruptedException e) { }
// TODO Auto-generated catch block uploadIndex();
e.printStackTrace(); } catch (InterruptedException e) {
} finally { // TODO Auto-generated catch block
e.printStackTrace();
} } finally {
}
}
private boolean isAborted() { }
if (stopped || Thread.currentThread().isInterrupted()) {
return true; private boolean isAborted() {
} if (stopped || Thread.currentThread().isInterrupted()) {
return false; return true;
} }
return false;
public void stopIt() { }
this.stopped = true;
} public void stopIt() {
this.stopped = true;
public long getTransferTime() { }
return this.transferTime;
} public long getTransferTime() {
return this.transferTime;
public int getStatus() { }
return transferStatus;
} public int getStatus() {
return transferStatus;
public String getStatusMessage() { }
return transferStatusMessage;
} public String getStatusMessage() {
return transferStatusMessage;
public void uploadIndex() throws InterruptedException { }
/* loop until we public void uploadIndex() throws InterruptedException {
* - have successfully transfered the words list or
* - the retry counter limit was exceeded /* loop until we
*/ * - have successfully transfered the words list or
transferStatus = plasmaDHTChunk.chunkStatus_RUNNING; * - the retry counter limit was exceeded
long retryCount = 0, start = System.currentTimeMillis(); */
while (true) { transferStatus = plasmaDHTChunk.chunkStatus_RUNNING;
// testing if we were aborted long retryCount = 0, start = System.currentTimeMillis();
if (isAborted()) return; while (true) {
// testing if we were aborted
// transfering seleted words to remote peer if (isAborted()) return;
transferStatusMessage = "Running: Transfering chunk to target " + seed.hash + "/" + seed.getName();
String error = yacyClient.transferIndex(seed, dhtChunk.containers(), dhtChunk.urlCacheMap(), gzipBody4Transfer, timeout4Transfer); // transfering seleted words to remote peer
if (error == null) { transferStatusMessage = "Running: Transfering chunk to target " + seed.hash + "/" + seed.getName();
// words successfully transfered String error = yacyClient.transferIndex(seed, dhtChunk.containers(), dhtChunk.urlCacheMap(), gzipBody4Transfer, timeout4Transfer);
transferTime = System.currentTimeMillis() - start; if (error == null) {
this.log.logInfo("Index transfer of " + dhtChunk.indexCount() + " words [" + dhtChunk.firstContainer().wordHash() + " .. " + dhtChunk.lastContainer().wordHash() + "]" + " to peer " + seed.getName() + ":" + seed.hash + " in " + (transferTime / 1000) + " seconds successfull (" // words successfully transfered
+ (1000 * dhtChunk.indexCount() / (transferTime + 1)) + " words/s)"); transferTime = System.currentTimeMillis() - start;
retryCount = 0; this.log.logInfo("Index transfer of " + dhtChunk.indexCount() + " words [" + dhtChunk.firstContainer().wordHash() + " .. " + dhtChunk.lastContainer().wordHash() + "]" + " to peer " + seed.getName() + ":" + seed.hash + " in " + (transferTime / 1000) + " seconds successfull ("
transferStatusMessage = "Finished: Transfer of chunk to target " + seed.hash + "/" + seed.getName(); + (1000 * dhtChunk.indexCount() / (transferTime + 1)) + " words/s)");
transferStatus = plasmaDHTChunk.chunkStatus_COMPLETE; retryCount = 0;
break; transferStatusMessage = "Finished: Transfer of chunk to target " + seed.hash + "/" + seed.getName();
} else { transferStatus = plasmaDHTChunk.chunkStatus_COMPLETE;
// words transfer failed break;
} else {
// inc retry counter // words transfer failed
retryCount++;
// inc retry counter
// testing if we were aborted ... retryCount++;
if (isAborted()) return;
// testing if we were aborted ...
// we have lost the connection to the remote peer. Adding peer to disconnected list if (isAborted()) return;
this.log.logWarning("Index transfer to peer " + seed.getName() + ":" + seed.hash + " failed:'" + error + "', disconnecting peer");
yacyCore.peerActions.peerDeparture(seed); // we have lost the connection to the remote peer. Adding peer to disconnected list
this.log.logWarning("Index transfer to peer " + seed.getName() + ":" + seed.hash + " failed:'" + error + "', disconnecting peer");
// if the retry counter limit was not exceeded we'll retry it in a few seconds yacyCore.peerActions.peerDeparture(seed);
transferStatusMessage = "Disconnected peer: " + ((retryCount > 5) ? error + ". Transfer aborted" : "Retry " + retryCount);
if (retryCount > maxRetry) { // if the retry counter limit was not exceeded we'll retry it in a few seconds
transferStatus = plasmaDHTChunk.chunkStatus_FAILED; transferStatusMessage = "Disconnected peer: " + ((retryCount > 5) ? error + ". Transfer aborted" : "Retry " + retryCount);
return; if (retryCount > maxRetry) {
} transferStatus = plasmaDHTChunk.chunkStatus_FAILED;
Thread.sleep(retryCount * 5000); return;
}
/* loop until Thread.sleep(retryCount * 5000);
* - we have successfully done a peer ping or
* - the retry counter limit was exceeded /* loop until
*/ * - we have successfully done a peer ping or
while (true) { * - the retry counter limit was exceeded
// testing if we were aborted ... */
if (isAborted()) while (true) {
return; // testing if we were aborted ...
if (isAborted())
// doing a peer ping to the remote seed return;
int added = yacyClient.publishMySeed(seed.getAddress(), seed.hash);
if (added < 0) { // doing a peer ping to the remote seed
// inc. retry counter int added = yacyClient.publishMySeed(seed.getAddress(), seed.hash);
retryCount++; if (added < 0) {
transferStatusMessage = "Disconnected peer: Peer ping failed. " + ((retryCount > 5) ? "Transfer aborted." : "Retry " + retryCount); // inc. retry counter
if (retryCount > maxRetry) return; retryCount++;
Thread.sleep(retryCount * 5000); transferStatusMessage = "Disconnected peer: Peer ping failed. " + ((retryCount > 5) ? "Transfer aborted." : "Retry " + retryCount);
continue; if (retryCount > maxRetry) return;
} else { Thread.sleep(retryCount * 5000);
yacyCore.seedDB.getConnected(seed.hash); continue;
transferStatusMessage = "running"; } else {
break; yacyCore.seedDB.getConnected(seed.hash);
} transferStatusMessage = "running";
} break;
} }
} }
} }
}
public static void setSeedcount(int seedcount) { }
plasmaDHTTransfer.seedcount = seedcount;
} public static void setSeedcount(int seedcount) {
plasmaDHTTransfer.seedcount = seedcount;
public static int getSeedcount() { }
return seedcount;
} public static int getSeedcount() {
} return seedcount;
}
}

Loading…
Cancel
Save