1 23 24 package org.continuent.sequoia.controller.scheduler.raidb0; 25 26 import java.sql.SQLException ; 27 28 import org.continuent.sequoia.common.exceptions.RollbackException; 29 import org.continuent.sequoia.common.xml.DatabasesXmlTags; 30 import org.continuent.sequoia.controller.core.ControllerConstants; 31 import org.continuent.sequoia.controller.requestmanager.RAIDbLevels; 32 import org.continuent.sequoia.controller.requests.AbstractWriteRequest; 33 import org.continuent.sequoia.controller.requests.ParsingGranularities; 34 import org.continuent.sequoia.controller.requests.SelectRequest; 35 import org.continuent.sequoia.controller.requests.StoredProcedure; 36 import org.continuent.sequoia.controller.scheduler.AbstractScheduler; 37 import org.continuent.sequoia.controller.scheduler.schema.TransactionExclusiveLock; 38 39 50 public class RAIDb0PessimisticTransactionLevelScheduler 51 extends AbstractScheduler 52 { 53 54 64 private TransactionExclusiveLock lock = new TransactionExclusiveLock(); 65 66 70 73 public RAIDb0PessimisticTransactionLevelScheduler() 74 { 75 super(RAIDbLevels.RAIDb0, ParsingGranularities.NO_PARSING); 76 } 77 78 82 88 public final void scheduleNonSuspendedReadRequest(SelectRequest request) 89 throws SQLException 90 { 91 } 92 93 96 public final void readCompletedNotify(SelectRequest request) 97 { 98 } 99 100 107 public void scheduleNonSuspendedWriteRequest(AbstractWriteRequest request) 108 throws SQLException 109 { 110 if (request.isCreate()) 111 { 112 return; 113 } 114 115 if (lock.acquire(request)) 116 { 117 if (logger.isDebugEnabled()) 118 logger.debug("Request " + request.getId() + " scheduled for write (" 119 + getPendingWrites() + " pending writes)"); 120 } 121 else 122 { 123 if (logger.isWarnEnabled()) 124 logger.warn("Request " + request.getId() + " timed out (" 125 + request.getTimeout() + " s)"); 126 throw new SQLException ("Timeout (" + request.getTimeout() 127 + ") for request: " 128 + request.getSqlShortForm(ControllerConstants.SQL_SHORT_FORM_LENGTH)); 129 } 130 } 131 132 135 public final synchronized void notifyWriteCompleted( 136 AbstractWriteRequest request) 137 { 138 if (request.isAutoCommit() && (!request.isCreate())) 141 releaseLock(request.getTransactionId()); 142 } 143 144 147 public final void scheduleNonSuspendedStoredProcedure(StoredProcedure proc) 148 throws SQLException , RollbackException 149 { 150 if (lock.acquire(proc)) 151 { 152 if (logger.isDebugEnabled()) 153 logger.debug("Stored procedure " + proc.getId() 154 + " scheduled for write (" + getPendingWrites() 155 + " pending writes)"); 156 } 157 else 158 { 159 if (logger.isWarnEnabled()) 160 logger.warn("Stored procedure " + proc.getId() + " timed out (" 161 + proc.getTimeout() + " s)"); 162 throw new SQLException ("Timeout (" + proc.getTimeout() 163 + ") for request: " 164 + proc.getSqlShortForm(ControllerConstants.SQL_SHORT_FORM_LENGTH)); 165 } 166 } 167 168 171 public final void notifyStoredProcedureCompleted(StoredProcedure proc) 172 { 173 if (proc.isAutoCommit() && (!proc.isCreate())) 176 releaseLock(proc.getTransactionId()); 177 } 178 179 183 186 protected final void commitTransaction(long transactionId) 187 { 188 releaseLock(transactionId); 189 } 190 191 194 protected final void rollbackTransaction(long transactionId) 195 { 196 releaseLock(transactionId); 197 } 198 199 203 protected final void rollbackTransaction(long transactionId, 204 String savepointName) 205 { 206 } 207 208 212 protected final void setSavepointTransaction(long transactionId, String name) 213 { 214 } 215 216 220 protected final void releaseSavepointTransaction(long transactionId, 221 String name) 222 { 223 } 224 225 230 private void releaseLock(long transactionId) 231 { 232 if (lock.isLocked()) 234 { 235 if (lock.getLocker() == transactionId) 236 lock.release(); 237 238 else if (logger.isDebugEnabled()) 243 logger.debug("Transaction " + transactionId 244 + " wants to release the lock held by transaction " 245 + lock.getLocker()); 246 } 247 else if (logger.isDebugEnabled()) 248 logger.warn("Transaction " + transactionId 249 + " tries to release a lock that has not been acquired."); 250 } 251 252 256 259 public String getXmlImpl() 260 { 261 StringBuffer info = new StringBuffer (); 262 info.append("<" + DatabasesXmlTags.ELT_RAIDb0Scheduler + " " 263 + DatabasesXmlTags.ATT_level + "=\"" 264 + DatabasesXmlTags.VAL_pessimisticTransaction + "\"/>"); 265 return info.toString(); 266 } 267 } 268 | Popular Tags |