Skip to content

Commit

Permalink
Fix issue on unlimited connection retry attempts
Browse files Browse the repository at this point in the history
During fix on version 3.1/3.3, several issues concerning forwarding transfers
and FileMonitor introduce a endless repetition of attemps in case of lack
of connection.
This fixes this issue:

- After 3 attemps of failed connections, the transfer is in error and the
execution of the error task is launched
- For FileMonitor (SpooledDirectoryTransfer), a failed Submit transfer is handled
by the R66 server as usual (3 attempts). For Direct transfer, the retry after 3
attemps is done after a delay, as long as the file exists.
  • Loading branch information
fredericBregier committed May 13, 2020
1 parent 522a1cd commit b516581
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 259 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
public class DirectTransfer extends AbstractTransfer {
protected final NetworkTransaction networkTransaction;

protected boolean limitRetryConnection = true;

public DirectTransfer(R66Future future, String remoteHost, String filename,
String rulename, String fileinfo, boolean isMD5,
int blocksize, long id,
Expand All @@ -58,6 +60,23 @@ public DirectTransfer(R66Future future, String remoteHost, String filename,
this.networkTransaction = networkTransaction;
}

/**
*
* @return True if this DirectTransfer should limit the retry of connection
*/
public boolean isLimitRetryConnection() {
return limitRetryConnection;
}

/**
*
* @param limitRetryConnection True (default) for limited retry on
* connection, False to have no limit
*/
public void setLimitRetryConnection(final boolean limitRetryConnection) {
this.limitRetryConnection = limitRetryConnection;
}

/**
* Prior to call this method, the pipeline and NetworkTransaction must have
* been initialized. It is the
Expand All @@ -75,6 +94,8 @@ public void run() {
}
final ClientRunner runner =
new ClientRunner(networkTransaction, taskRunner, future);
// If retry indefinitely is useful
runner.setLimitRetryConnection(isLimitRetryConnection());
OpenR66ProtocolNotYetConnectionException exc = null;
for (int i = 0; i < Configuration.RETRYNB; i++) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,69 +532,42 @@ public void run(FileItem fileItem) {
transaction.run();
} else {
if (specialId != ILLEGALVALUE) {
boolean direct = false;
// Transfer try at least once
text = "Request Transfer try Restart: " + specialId + ' ' +
filename + ' ';
// Clean previously transfer if any
try {
final String srequester = Configuration.configuration
.getHostId(admin.getSession(), host);
// Try restart
final RequestTransfer transaction =
text =
"Request Transfer Cancelled: " + specialId +
' ' + filename + ' ';
// Cancel
logger.debug("Will try to cancel {}", specialId);
final RequestTransfer transaction2 =
new RequestTransfer(r66Future, specialId, host,
srequester, false, false, true,
srequester, true, false, false,
networkTransaction);
transaction.normalInfoAsWarn = normalInfoAsWarn;
logger.info(text + host);
transaction2.normalInfoAsWarn = normalInfoAsWarn;
logger.warn(text + host);
transaction2.run();
// special task
transaction.run();
r66Future.awaitOrInterruptible();
if (!r66Future.isSuccess()) {
direct = true;
text =
"Request Transfer Cancelled and Restart: " + specialId +
' ' + filename + ' ';
r66Future = new R66Future(true);
// Cancel
final RequestTransfer transaction2 =
new RequestTransfer(r66Future, specialId, host,
srequester, true, false, false,
networkTransaction);
transaction.normalInfoAsWarn = normalInfoAsWarn;
logger.warn(text + host);
transaction2.run();
// special task
r66Future.awaitOrInterruptible();
}
} catch (final WaarpDatabaseException e) {
direct = true;
if (admin.getSession() != null) {
admin.getSession().checkConnectionNoException();
}
logger.warn(Messages.getString("RequestTransfer.5") + host,
e); //$NON-NLS-1$
}
if (direct) {
text = "Direct Transfer: ";
r66Future = new R66Future(true);
final DirectTransfer transaction =
new DirectTransfer(r66Future, host, filename, ruleName,
fileInfo, isMD5, blocksize,
ILLEGALVALUE, networkTransaction);
transaction.normalInfoAsWarn = normalInfoAsWarn;
logger.info(text + host);
transaction.run();
}
} else {
text = "Direct Transfer: ";
final DirectTransfer transaction =
new DirectTransfer(r66Future, host, filename, ruleName,
fileInfo, isMD5, blocksize, ILLEGALVALUE,
networkTransaction);
transaction.normalInfoAsWarn = normalInfoAsWarn;
logger.info(text + host);
transaction.run();
}
text = "Direct Transfer: ";
r66Future = new R66Future(true);
final DirectTransfer transaction =
new DirectTransfer(r66Future, host, filename, ruleName,
fileInfo, isMD5, blocksize, ILLEGALVALUE,
networkTransaction);
// If retry indefinitely is useful transaction.setLimitRetryConnection(true)
transaction.normalInfoAsWarn = normalInfoAsWarn;
logger.info(text + host);
transaction.run();
}
r66Future.awaitOrInterruptible();
final R66Result r66result = r66Future.getResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public class ClientRunner extends Thread {

private final String nameTask;

private boolean limitRetryConnection = true;

public ClientRunner(NetworkTransaction networkTransaction,
DbTaskRunner taskRunner, R66Future futureRequest) {
this.networkTransaction = networkTransaction;
Expand Down Expand Up @@ -270,6 +272,9 @@ public void run() {
* @return True if the task was run less than limit, else False
*/
public boolean incrementTaskRunnerTry(DbTaskRunner runner, int limit) {
if (!isLimitRetryConnection()) {
return true;
}
final String key = runner.getKey();
Integer tries = taskRunnerRetryHashMap.get(key);
logger.debug("try to find integer: " + tries);
Expand All @@ -278,7 +283,8 @@ public boolean incrementTaskRunnerTry(DbTaskRunner runner, int limit) {
} else {
tries += 1;
}
if (limit <= tries || !Thread.interrupted()) {
logger.debug("Check: {} vs {}: {}", tries, limit, limit <= tries);
if (limit <= tries || Thread.interrupted()) {
taskRunnerRetryHashMap.remove(key);
return false;
} else {
Expand Down Expand Up @@ -544,27 +550,40 @@ public LocalChannelReference initRequest()
if (localChannelReference == null) {
// propose to redo
String retry;
logger.debug("Will retry since Cannot connect to {}", host);
retry = " but will retry";
// now wait
try {
Thread.sleep(Configuration.configuration.getDelayRetry());
} catch (final InterruptedException e) {//NOSONAR
SysErrLogger.FAKE_LOGGER.ignoreLog(e);
if (incrementTaskRunnerTry(taskRunner, Configuration.RETRYNB)) {

logger.debug("Will retry since Cannot connect to {}", host);
retry = " but will retry";
// now wait
try {
Thread.sleep(Configuration.configuration.getDelayRetry());
} catch (final InterruptedException e) {//NOSONAR
SysErrLogger.FAKE_LOGGER.ignoreLog(e);
logger.debug(
"Will not retry since an interruption occurs while connection " +
"to {}", host);
retry = " and retries gets an interruption so stop here";
changeUpdatedInfo(UpdatedInfo.INERROR, ErrorCode.ConnectionImpossible,
true);
taskRunner.setLocalChannelReference(new LocalChannelReference());
throw new OpenR66ProtocolNoConnectionException(
CANNOT_CONNECT_TO_SERVER + host + retry);
}
changeUpdatedInfo(UpdatedInfo.TOSUBMIT, ErrorCode.ConnectionImpossible,
true);
throw new OpenR66ProtocolNotYetConnectionException(
CANNOT_CONNECT_TO_SERVER + host + retry);
} else {
logger.debug(
"Will not retry since limit of connection attemtps is reached for {}",
host);
retry = " and retries gets an interruption so stop here";
retry = " and retries reach step limit so stop here";
changeUpdatedInfo(UpdatedInfo.INERROR, ErrorCode.ConnectionImpossible,
true);
taskRunner.setLocalChannelReference(new LocalChannelReference());
throw new OpenR66ProtocolNoConnectionException(
CANNOT_CONNECT_TO_SERVER + host + retry);
}
changeUpdatedInfo(UpdatedInfo.TOSUBMIT, ErrorCode.ConnectionImpossible,
true);
throw new OpenR66ProtocolNotYetConnectionException(
CANNOT_CONNECT_TO_SERVER + host + retry);
}
if (handler != null) {
localChannelReference.setRecvThroughHandler(handler);
Expand Down Expand Up @@ -656,4 +675,12 @@ public void setSendThroughMode() {
public boolean getSendThroughMode() {
return isSendThroughMode;
}

public boolean isLimitRetryConnection() {
return limitRetryConnection;
}

public void setLimitRetryConnection(final boolean limitRetryConnection) {
this.limitRetryConnection = limitRetryConnection;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,8 @@ public void update() throws WaarpDatabaseException {
if (Configuration.configuration.getR66Mib() != null) {
Configuration.configuration.getR66Mib().notifyInfoTask(
"Task is " + pojo.getUpdatedInfo().name(), this);
} else {
logger.debug("Could send a SNMP trap here since {}", pojo.getUpdatedInfo());
}
} else {
if (pojo.getGlobalStep() != Transfer.TASKSTEP.TRANSFERTASK ||
Expand Down
Loading

0 comments on commit b516581

Please sign in to comment.