Permalink
Browse files

Added changes for ISPN-2356 (pull request not yet processed)

  • Loading branch information...
1 parent 66c10c7 commit dc85c62c2faf8a63b7a24ecf96053d6cca38f90e Bela Ban committed Oct 1, 2012
@@ -82,7 +82,7 @@ public void waitForBackupToFinish() throws Exception {
errors.put(siteName, newTimeoutException(entry, entry.getKey().getTimeout()));
addCommunicationError(siteName);
} catch (ExecutionException ue) {
- log.tracef(ue.getCause(), "Communication error with site %s", siteName);
+ log.tracef("Communication error with site %s", siteName);
errors.put(siteName, ue.getCause());
addCommunicationError(siteName);
} finally {
@@ -21,6 +21,9 @@
import org.infinispan.remoting.RpcException;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* Exception to be used to signal failures to backup to remote sites.
*
@@ -29,23 +32,40 @@
*/
public class BackupFailureException extends RpcException {
- private String remoteSiteName;
- private String localCacheName;
+ private Map<String,Throwable> failures;
+ private String localCacheName;
+
- public BackupFailureException(Throwable cause, String remoteSiteName, String localCacheName) {
- super("The local cache" + localCacheName + " failed to backup data to the remote site " + remoteSiteName, cause);
- this.remoteSiteName = remoteSiteName;
- this.localCacheName = localCacheName;
+ public BackupFailureException(String localCacheName) {
+ this.localCacheName = localCacheName;
}
public BackupFailureException() {
}
- public String getRemoteSiteName() {
- return remoteSiteName;
+ public void addFailure(String site, Throwable t) {
+ if(site != null && t != null) {
+ if(failures == null)
+ failures = new HashMap<String,Throwable>(3);
+ failures.put(site, t);
+ }
+ }
+
+ public String getRemoteSiteNames() {
+ return failures != null? failures.keySet().toString() : null;
}
public String getLocalCacheName() {
return localCacheName;
}
+
+ @Override
+ public String toString() {
+ if(failures == null || failures.isEmpty())
+ return super.toString();
+ StringBuilder sb=new StringBuilder("The local cache " + localCacheName + " failed to backup data to the remote sites:\n");
+ for(Map.Entry<String,Throwable> entry: failures.entrySet())
+ sb.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n");
+ return sb.toString();
+ }
}
@@ -202,6 +202,8 @@ private void send1PcToAsyncBackups(CommitCommand command) throws Exception {
private void processFailedResponses(BackupResponse backupResponse, VisitableCommand command, Transaction transaction) throws Throwable {
SitesConfiguration sitesConfiguration = config.sites();
Map<String, Throwable> failures = backupResponse.getFailedBackups();
+
+ BackupFailureException backupException = null;
for (Map.Entry<String, Throwable> failure : failures.entrySet()) {
BackupFailurePolicy policy = sitesConfiguration.getFailurePolicy(failure.getKey());
if (policy == BackupFailurePolicy.CUSTOM) {
@@ -211,9 +213,13 @@ private void processFailedResponses(BackupResponse backupResponse, VisitableComm
if (policy == BackupFailurePolicy.WARN) {
log.warnXsiteBackupFailed(cacheName, failure.getKey(), failure.getValue());
} else if (policy == BackupFailurePolicy.FAIL) {
- throw new BackupFailureException(failure.getValue(), failure.getKey(), cacheName);
+ if(backupException == null)
+ backupException = new BackupFailureException(cacheName);
+ backupException.addFailure(failure.getKey(), failure.getValue());
}
}
+ if(backupException != null)
+ throw backupException;
}
private List<XSiteBackup> calculateBackupInfo(BackupFilter backupFilter) {
@@ -232,7 +238,7 @@ private void processFailedResponses(BackupResponse backupResponse, VisitableComm
if (!isSync) continue;
}
if (isOffline(bc.site())) {
- log.trace("The site '%s' is offline, not backing up information to it");
+ log.tracef("The site '%s' is offline, not backing up information to it", bc.site());
continue;
}
XSiteBackup bi = new XSiteBackup(bc.site(), isSync, bc.replicationTimeout());
@@ -85,7 +85,7 @@ public synchronized boolean minTimeHasElapsed() {
throw new IllegalStateException("Cannot invoke this method if minTimeToWait is not enabled");
long millis = millisSinceFirstFailure();
if (millis >= takeOffline.minTimeToWait()) {
- log.tracef("The minTimeToWait hasn't passed: minTime=%s, timeSinceFirstFailure=%s",
+ log.tracef("The minTimeToWait has passed: minTime=%s, timeSinceFirstFailure=%s",
takeOffline.minTimeToWait(), millis);
return true;
}
@@ -46,4 +46,8 @@ public boolean isSync() {
public long getTimeout() {
return timeout;
}
+
+ public String toString() {
+ return siteName + " (" + (sync? "sync" : "async") + ", timeout=" + timeout + ")";
+ }
}
@@ -167,15 +167,22 @@ public void actionPerformed(ActionEvent e) {
@Override
public void run() {
// based on the value of the radio button:
- if (putEntryRadioButton.isSelected()) {
- cache.put(keyTextField.getText(), valueTextField.getText(), lifespan(), TimeUnit.MILLISECONDS, maxIdle(), TimeUnit.MILLISECONDS);
- } else if (removeEntryRadioButton.isSelected()) {
- cache.remove(keyTextField.getText());
- } else if (getEntryRadioButton.isSelected()) {
- cache.get(keyTextField.getText());
+ try {
+ if (putEntryRadioButton.isSelected()) {
+ cache.put(keyTextField.getText(), valueTextField.getText(), lifespan(), TimeUnit.MILLISECONDS, maxIdle(), TimeUnit.MILLISECONDS);
+ } else if (removeEntryRadioButton.isSelected()) {
+ cache.remove(keyTextField.getText());
+ } else if (getEntryRadioButton.isSelected()) {
+ cache.get(keyTextField.getText());
+ }
+ }
+ catch(Throwable t) {
+ // log.error("failed to update cache", t);
+ }
+ finally {
+ dataViewTab.repaint();
+ processAction(goButton, false);
}
- dataViewTab.repaint();
- processAction(goButton, false);
// reset these values
lifespanSpinner.setValue(cache.getCacheConfiguration().expiration().lifespan());

0 comments on commit dc85c62

Please sign in to comment.