|                                                                                                              1
 23
 24  package org.continuent.sequoia.controller.scheduler.raidb1;
 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 RAIDb1PessimisticTransactionLevelScheduler
 51      extends AbstractScheduler
 52  {
 53
 54
 64    TransactionExclusiveLock lock = new TransactionExclusiveLock();
 65
 66
 70
 73    public RAIDb1PessimisticTransactionLevelScheduler()
 74    {
 75      super(RAIDbLevels.RAIDb1, 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
 105   public void scheduleNonSuspendedWriteRequest(AbstractWriteRequest request)
 106       throws SQLException
  107   {
 108     if (request.isCreate())
 109     {
 110       return;
 111     }
 112
 113     if (lock.acquire(request))
 114     {
 115       if (logger.isDebugEnabled())
 116         logger.debug("Request " + request.getId() + " scheduled for write ("
 117             + getPendingWrites() + " pending writes)");
 118     }
 119     else
 120     {
 121       if (logger.isWarnEnabled())
 122         logger.warn("Request " + request.getId() + " timed out ("
 123             + request.getTimeout() + " s)");
 124       throw new SQLException
  ("Timeout (" + request.getTimeout() 125           + ") for request: "
 126           + request.getSqlShortForm(ControllerConstants.SQL_SHORT_FORM_LENGTH));
 127     }
 128   }
 129
 130
 133   public final synchronized void notifyWriteCompleted(
 134       AbstractWriteRequest request)
 135   {
 136             if (request.isAutoCommit() && (!request.isCreate()))
 139       releaseLock(request.getTransactionId());
 140   }
 141
 142
 145   public final void scheduleNonSuspendedStoredProcedure(StoredProcedure proc)
 146       throws SQLException
  , RollbackException 147   {
 148     if (lock.acquire(proc))
 149     {
 150       if (logger.isDebugEnabled())
 151         logger.debug("Stored procedure " + proc.getId()
 152             + " scheduled for write (" + getPendingWrites()
 153             + " pending writes)");
 154     }
 155     else
 156     {
 157       if (logger.isWarnEnabled())
 158         logger.warn("Stored procedure " + proc.getId() + " timed out ("
 159             + proc.getTimeout() + " s)");
 160       throw new SQLException
  ("Timeout (" + proc.getTimeout() 161           + ") for request: "
 162           + proc.getSqlShortForm(ControllerConstants.SQL_SHORT_FORM_LENGTH));
 163     }
 164   }
 165
 166
 169   public final void notifyStoredProcedureCompleted(StoredProcedure proc)
 170   {
 171             if (proc.isAutoCommit() && (!proc.isCreate()))
 174       releaseLock(proc.getTransactionId());
 175   }
 176
 177
 181
 184   protected final void commitTransaction(long transactionId)
 185   {
 186     if (lock.isLocked())
 187       releaseLock(transactionId);
 188       }
 190
 191
 194   protected final void rollbackTransaction(long transactionId)
 195   {
 196     if (lock.isLocked())
 197       releaseLock(transactionId);
 198       }
 200
 201
 205   protected final void rollbackTransaction(long transactionId,
 206       String
  savepointName) 207   {
 208   }
 209
 210
 214   protected final void setSavepointTransaction(long transactionId, String
  name) 215   {
 216   }
 217
 218
 222   protected final void releaseSavepointTransaction(long transactionId,
 223       String
  name) 224   {
 225   }
 226
 227
 232   private void releaseLock(long transactionId)
 233   {
 234         if (lock.isLocked())
 236     {
 237       if (lock.getLocker() == transactionId)
 238         lock.release();
 239
 240                         else if (logger.isDebugEnabled())
 244         logger.debug("Transaction " + transactionId
 245             + " wants to release the lock held by transaction "
 246             + lock.getLocker());
 247     }
 248     else if (logger.isDebugEnabled())
 249       logger.warn("Transaction " + transactionId
 250           + " tries to release a lock that has not been acquired.");
 251   }
 252
 253
 259   public String
  getXmlImpl() 260   {
 261     return "<" + DatabasesXmlTags.ELT_RAIDb1Scheduler + " "
 262         + DatabasesXmlTags.ATT_level + "=\""
 263         + DatabasesXmlTags.VAL_pessimisticTransaction + "\"/>";
 264   }
 265 }
 266
                                                                                                                                                                                                             |                                                                       
 
 
 
 
 
                                                                                   Popular Tags                                                                                                                                                                                              |