1 24 25 package org.continuent.sequoia.controller.virtualdatabase.protocol; 26 27 import java.io.Serializable ; 28 import java.sql.SQLException ; 29 import java.util.LinkedList ; 30 31 import org.continuent.sequoia.common.exceptions.NoMoreBackendException; 32 import org.continuent.sequoia.common.i18n.Translate; 33 import org.continuent.sequoia.controller.loadbalancer.AllBackendsFailedException; 34 import org.continuent.sequoia.controller.requestmanager.TransactionMetaData; 35 import org.continuent.sequoia.controller.requestmanager.distributed.DistributedRequestManager; 36 import org.continuent.sequoia.controller.requests.AbstractRequest; 37 import org.continuent.sequoia.controller.requests.UnknownWriteRequest; 38 39 48 public class DistributedReleaseSavepoint extends DistributedTransactionMarker 49 { 50 private static final long serialVersionUID = 3025352266902951038L; 51 52 private String savepointName; 53 54 60 public DistributedReleaseSavepoint(long transactionId, String savepointName) 61 { 62 super(transactionId); 63 this.savepointName = savepointName; 64 } 65 66 69 public Object scheduleCommand(DistributedRequestManager drm) 70 throws SQLException 71 { 72 LinkedList totalOrderQueue = drm.getVirtualDatabase().getTotalOrderQueue(); 73 if (totalOrderQueue != null) 74 { 75 synchronized (totalOrderQueue) 76 { 77 totalOrderQueue.addLast(this); 78 } 79 } 80 return this; 81 } 82 83 86 public Serializable executeCommand(DistributedRequestManager drm) 87 throws SQLException 88 { 89 boolean hasBeenScheduled = false; 90 91 Long tid = new Long (transactionId); 94 TransactionMetaData tm; 95 try 96 { 97 tm = drm.getTransactionMetaData(tid); 98 } 99 catch (SQLException e) 100 { 101 drm.getLoadBalancer().removeObjectFromAndNotifyTotalOrderQueue(this); 103 throw e; 104 } 105 106 if (!drm.hasSavepoint(tid, savepointName)) 108 throw new SQLException (Translate.get("transaction.savepoint.not.found", 109 new String []{savepointName, String.valueOf(transactionId)})); 110 111 try 112 { 113 drm.getScheduler().releaseSavepoint(tm, savepointName, this); 115 hasBeenScheduled = true; 116 117 if (drm.getLogger().isDebugEnabled()) 118 drm.getLogger().debug( 119 Translate.get("transaction.releasesavepoint", new String []{ 120 savepointName, String.valueOf(transactionId)})); 121 122 drm.getLoadBalancer().releaseSavepoint(tm, savepointName); 124 125 drm.getRecoveryLog().logRequestCompletion(tm.getLogId(), true, 0); 127 128 drm.getScheduler().savepointCompleted(transactionId); 130 } 131 catch (NoMoreBackendException e) 132 { 133 addFailureOnAllBackends(drm, hasBeenScheduled, tm); 134 if (drm.getLogger().isDebugEnabled()) 135 drm.getLogger().debug( 136 Translate.get( 137 "virtualdatabase.distributed.releasesavepoint.logging.only", 138 new String []{savepointName, String.valueOf(transactionId)})); 139 throw e; 140 } 141 catch (SQLException e) 142 { 143 addFailureOnAllBackends(drm, hasBeenScheduled, tm); 144 drm 145 .getLogger() 146 .warn( 147 Translate 148 .get("virtualdatabase.distributed.releasesavepoint.sqlexception"), 149 e); 150 return e; 151 } 152 catch (RuntimeException re) 153 { 154 addFailureOnAllBackends(drm, hasBeenScheduled, tm); 155 drm.getLogger().warn( 156 Translate 157 .get("virtualdatabase.distributed.releasesavepoint.exception"), 158 re); 159 throw new SQLException (re.getMessage()); 160 } 161 catch (AllBackendsFailedException e) 162 { 163 addFailureOnAllBackends(drm, hasBeenScheduled, tm); 164 if (drm.getLogger().isDebugEnabled()) 165 drm 166 .getLogger() 167 .debug( 168 Translate 169 .get( 170 "virtualdatabase.distributed.releasesavepoint.all.backends.locally.failed", 171 new String []{savepointName, 172 String.valueOf(transactionId)})); 173 return e; 174 } 175 finally 176 { 177 drm.removeSavepoint(tid, savepointName); 179 } 180 return Boolean.TRUE; 181 } 182 183 private void addFailureOnAllBackends(DistributedRequestManager drm, 184 boolean hasBeenScheduled, TransactionMetaData tm) 185 { 186 AbstractRequest request = new UnknownWriteRequest("release " 187 + savepointName, false, 0, "\n"); 188 request.setTransactionId(transactionId); 189 request.setLogId(tm.getLogId()); 190 drm.addFailedOnAllBackends(request, hasBeenScheduled); 191 } 192 193 198 public String getSavepointName() 199 { 200 return savepointName; 201 } 202 203 206 public boolean equals(Object obj) 207 { 208 if (super.equals(obj)) 209 return savepointName.equals(((DistributedReleaseSavepoint) obj) 210 .getSavepointName()); 211 else 212 return false; 213 } 214 215 218 public String toString() 219 { 220 return "Release savepoint " + savepointName + " from transaction " 221 + transactionId; 222 } 223 } 224 | Popular Tags |