org.objectweb.cjdbc.controller.scheduler
Class AbstractScheduler

java.lang.Object
  extended byorg.objectweb.cjdbc.controller.scheduler.AbstractScheduler
All Implemented Interfaces:
XmlComponent
Direct Known Subclasses:
RAIDb0PassThroughLevelScheduler, RAIDb0PessimisticTransactionLevelScheduler, RAIDb1OptimisticQueryLevelScheduler, RAIDb1OptimisticTransactionLevelScheduler, RAIDb1PassThroughScheduler, RAIDb1PessimisticTransactionLevelScheduler, RAIDb1QueryLevelScheduler, RAIDb2PassThroughScheduler, RAIDb2PessimisticTransactionLevelScheduler, RAIDb2QueryLevelScheduler, SingleDBPassThroughScheduler, SingleDBPessimisticTransactionLevelScheduler

public abstract class AbstractScheduler
extends java.lang.Object
implements XmlComponent

The Request Scheduler should schedule the request according to a given policy.

The requests comes from the Request Controller and are sent later to the next ccontroller omponents (cache and load balancer).

Version:
1.0
Author:
Emmanuel Cecchet , Jean-Bernard van Zuylen

Field Summary
private  java.lang.Object endOfCurrentTransactions
           
private  java.lang.Object endOfCurrentWrites
           
protected static Trace logger
           
private  int numberRead
           
private  int numberWrite
           
protected  int parsingGranularity
           
private  int pendingTransactions
           
private  int pendingWrites
           
protected  int raidbLevel
           
private  int sid
           
private  boolean suspendedTransactions
           
private  boolean suspendedWrites
           
private  long tid
           
private  java.lang.Object transactionSync
           
private  java.lang.Object writesSync
           
 
Fields inherited from interface org.objectweb.cjdbc.common.xml.XmlComponent
DOCTYPE_CONTROLLER, DOCTYPE_DB, XML_VERSION
 
Constructor Summary
AbstractScheduler(int raidbLevel, int parsingGranularity)
          Default scheduler to assign scheduler RAIDb level, needed granularity and SQL macro handling (on the fly instanciation of NOW(), RAND(), ...).
 
Method Summary
 long begin(TransactionMarkerMetaData tm)
          Begin a new transaction and return the corresponding transaction identifier.
 void beginCompleted(long transactionId)
          Notify the completion of a begin command.
 void commit(TransactionMarkerMetaData tm)
          Commit a transaction.
 void commitCompleted(long transactionId)
          Notify the completion of a commit command.
protected abstract  void commitTransaction(long transactionId)
          Commit a transaction given its id.
 int getNumberRead()
           
 int getNumberWrite()
           
 int getParsingGranularity()
          Get the needed query parsing granularity.
 int getPendingTransactions()
           
 int getPendingWrites()
          Returns the number of pending writes.
 int getRAIDbLevel()
          Returns the RAIDbLevel.
 java.lang.String[] getSchedulerData()
          Returns live information on the scheduler
 java.lang.String getXml()
          Get information about the Request Scheduler in xml format
protected abstract  java.lang.String getXmlImpl()
           
 int incrementSavepointId()
          Increments the savepoint id for un-named savepoints
 void initializeTransactionId(long transactionId)
          Initialize the transaction id with the given value (usually retrieved from the recovery log).
 boolean isSuspendedTransactions()
           
 boolean isSuspendedWrites()
           
 void mergeDatabaseSchema(DatabaseSchema dbs)
          Merge the given DatabaseSchema with the current one.
abstract  void notifyStoredProcedureCompleted(StoredProcedure proc)
          Notify the completion of a stored procedure.
abstract  void notifyWriteCompleted(AbstractWriteRequest request)
          Notify the completion of a write statement.
 void readCompleted(SelectRequest request)
          Notify the completion of a read statement.
abstract  void readCompletedNotify(SelectRequest request)
          Notify the completion of a read statement.
 void releaseSavepoint(TransactionMarkerMetaData tm, java.lang.String name)
          Release a savepoint.
protected abstract  void releaseSavepointTransaction(long transactionId, java.lang.String name)
          Release a savepoint given its name from a transaction given its id.
 void resumeNewTransactions()
          Resume new transactions that were suspended by suspendNewTransactionsForCheckpoint().
 void resumeWrites()
          Resume the execution of write queries that were suspended by suspendWrites().
 void rollback(TransactionMarkerMetaData tm)
          Rollback a transaction.
 void rollback(TransactionMarkerMetaData tm, java.lang.String savepointName)
          Rollback a transaction to a savepoint.
 void rollbackCompleted(long transactionId)
          Notify the completion of a rollback command.
protected abstract  void rollbackTransaction(long transactionId)
          Rollback a transaction given its id.
protected abstract  void rollbackTransaction(long transactionId, java.lang.String savepointName)
          Rollback a transaction given its id to a savepoint given its name.
 void savepointCompleted(long transactionId)
          Notify the conpletion of a savepoint action.
abstract  void scheduleNonSuspendedStoredProcedure(StoredProcedure proc)
          Schedule a write request (implementation specific).
abstract  void scheduleNonSuspendedWriteRequest(AbstractWriteRequest request)
          Schedule a write request (implementation specific).
abstract  void scheduleReadRequest(SelectRequest request)
          Schedule a read request (implementation specific).
 void scheduleStoredProcedure(StoredProcedure proc)
          Schedule a write request.
 void scheduleWriteRequest(AbstractWriteRequest request)
          Schedule a write request.
 void setDatabaseSchema(DatabaseSchema dbs)
          Sets the DatabaseSchema of the current virtual database.
 void setParsingGranularity(int parsingGranularity)
          Set the needed query parsing granularity.
 void setRAIDbLevel(int raidbLevel)
          Sets the RAIDb level.
 int setSavepoint(TransactionMarkerMetaData tm)
          Set an unnamed savepoint.
 void setSavepoint(TransactionMarkerMetaData tm, java.lang.String name)
          Set a named savepoint.
protected abstract  void setSavepointTransaction(long transactionId, java.lang.String name)
          Set a savepoint given its name to a transaction given its id.
 void storedProcedureCompleted(StoredProcedure proc)
          Notify the completion of a stored procedure.
 void suspendNewTransactionsForCheckpoint()
          Suspend all calls to begin() until all current transactions are finished in order to store a checkpoint.
private  void suspendWriteIfNeeded(AbstractRequest request)
          Suspend write requests if suspendedWrites is active.
 void suspendWrites()
          Suspend all write queries.
 void writeCompleted(AbstractWriteRequest request)
          Notify the completion of a write statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

raidbLevel

protected int raidbLevel

parsingGranularity

protected int parsingGranularity

tid

private long tid

sid

private int sid

suspendedTransactions

private boolean suspendedTransactions

pendingTransactions

private int pendingTransactions

transactionSync

private java.lang.Object transactionSync

endOfCurrentTransactions

private java.lang.Object endOfCurrentTransactions

suspendedWrites

private boolean suspendedWrites

pendingWrites

private int pendingWrites

writesSync

private java.lang.Object writesSync

endOfCurrentWrites

private java.lang.Object endOfCurrentWrites

logger

protected static Trace logger

numberRead

private int numberRead

numberWrite

private int numberWrite
Constructor Detail

AbstractScheduler

public AbstractScheduler(int raidbLevel,
                         int parsingGranularity)
Default scheduler to assign scheduler RAIDb level, needed granularity and SQL macro handling (on the fly instanciation of NOW(), RAND(), ...).

Parameters:
raidbLevel - RAIDb level of this scheduler
parsingGranularity - Parsing granularity needed by the scheduler
Method Detail

initializeTransactionId

public final void initializeTransactionId(long transactionId)
Initialize the transaction id with the given value (usually retrieved from the recovery log).

Parameters:
transactionId - new current transaction identifier

getParsingGranularity

public final int getParsingGranularity()
Get the needed query parsing granularity.

Returns:
needed query parsing granularity

setParsingGranularity

public final void setParsingGranularity(int parsingGranularity)
Set the needed query parsing granularity.

Parameters:
parsingGranularity - Parsing granularity needed by the scheduler

getPendingWrites

public final int getPendingWrites()
Returns the number of pending writes.

Returns:
int

getRAIDbLevel

public final int getRAIDbLevel()
Returns the RAIDbLevel.

Returns:
int

setRAIDbLevel

public final void setRAIDbLevel(int raidbLevel)
Sets the RAIDb level.

Parameters:
raidbLevel - The RAIDbLevel to set

setDatabaseSchema

public void setDatabaseSchema(DatabaseSchema dbs)
Sets the DatabaseSchema of the current virtual database. This is only needed by some schedulers that will have to define their own scheduler schema

Parameters:
dbs - a DatabaseSchema value
See Also:
SchedulerDatabaseSchema

mergeDatabaseSchema

public void mergeDatabaseSchema(DatabaseSchema dbs)
Merge the given DatabaseSchema with the current one.

Parameters:
dbs - a DatabaseSchema value
See Also:
SchedulerDatabaseSchema

incrementSavepointId

public int incrementSavepointId()
Increments the savepoint id for un-named savepoints

Returns:
the next savepoint Id

scheduleReadRequest

public abstract void scheduleReadRequest(SelectRequest request)
                                  throws java.sql.SQLException
Schedule a read request (implementation specific). This method blocks until the read can be executed.

Parameters:
request - Select request to schedule (SQL macros are already handled if needed)
Throws:
java.sql.SQLException - if a timeout occurs

readCompletedNotify

public abstract void readCompletedNotify(SelectRequest request)
Notify the completion of a read statement.

Parameters:
request - the completed request

readCompleted

public final void readCompleted(SelectRequest request)
Notify the completion of a read statement.

Parameters:
request - the completed request

scheduleWriteRequest

public final void scheduleWriteRequest(AbstractWriteRequest request)
                                throws java.sql.SQLException,
                                       RollbackException
Schedule a write request. This method blocks if the writes are suspended. Then the number of pending writes is updated and the implementation specific scheduleNonSuspendedWriteRequest function is called. SQL macros are replaced in the request if the scheduler has needSQLMacroHandling set to true.

Parameters:
request - Write request to schedule
Throws:
java.sql.SQLException - if a timeout occurs
RollbackException - if an error occurs
See Also:
scheduleNonSuspendedWriteRequest(AbstractWriteRequest)

scheduleNonSuspendedWriteRequest

public abstract void scheduleNonSuspendedWriteRequest(AbstractWriteRequest request)
                                               throws java.sql.SQLException,
                                                      RollbackException
Schedule a write request (implementation specific). This method blocks until the request can be executed.

Parameters:
request - Write request to schedule (SQL macros are already handled if needed)
Throws:
java.sql.SQLException - if a timeout occurs
RollbackException - if the transaction must be rollbacked

writeCompleted

public final void writeCompleted(AbstractWriteRequest request)
Notify the completion of a write statement.

This method updates the number of pending writes and calls the implementation specific notifyWriteCompleted function.

Finally, the suspendWrites() function is notified if needed.

Parameters:
request - the completed request
See Also:
notifyWriteCompleted(AbstractWriteRequest), suspendWrites()

notifyWriteCompleted

public abstract void notifyWriteCompleted(AbstractWriteRequest request)
Notify the completion of a write statement. This method does not need to be synchronized, it is enforced by the caller.

Parameters:
request - the completed request
See Also:
writeCompleted(AbstractWriteRequest)

scheduleStoredProcedure

public final void scheduleStoredProcedure(StoredProcedure proc)
                                   throws java.sql.SQLException,
                                          RollbackException
Schedule a write request. This method blocks if the writes are suspended. Then the number of pending writes is updated and the implementation specific scheduleNonSuspendedWriteRequest function is called. SQL macros are replaced in the request if the scheduler has needSQLMacroHandling set to true.

Parameters:
proc - Stored procedure to schedule
Throws:
java.sql.SQLException - if a timeout occurs
RollbackException - if an error occurs
See Also:
scheduleNonSuspendedStoredProcedure(StoredProcedure)

scheduleNonSuspendedStoredProcedure

public abstract void scheduleNonSuspendedStoredProcedure(StoredProcedure proc)
                                                  throws java.sql.SQLException,
                                                         RollbackException
Schedule a write request (implementation specific). This method blocks until the request can be executed.

Parameters:
proc - Stored procedure to schedule
Throws:
java.sql.SQLException - if a timeout occurs
RollbackException - if the transaction must be rollbacked

storedProcedureCompleted

public final void storedProcedureCompleted(StoredProcedure proc)
Notify the completion of a stored procedure.

This method updates the number of pending writes and calls the implementation specific notifyStoredProcedureCompleted function.

Finally, the suspendWrites() function is notified if needed.

Parameters:
proc - the completed stored procedure
See Also:
notifyStoredProcedureCompleted(StoredProcedure), suspendWrites()

notifyStoredProcedureCompleted

public abstract void notifyStoredProcedureCompleted(StoredProcedure proc)
Notify the completion of a stored procedure. This method does not need to be synchronized, it is enforced by the caller.

Parameters:
proc - the completed stored procedure
See Also:
storedProcedureCompleted(StoredProcedure)

suspendWriteIfNeeded

private void suspendWriteIfNeeded(AbstractRequest request)
                           throws java.sql.SQLException
Suspend write requests if suspendedWrites is active.

Parameters:
request - the request to suspend (a write request or a stored procedure)
Throws:
java.sql.SQLException - if the request timeout has expired

begin

public final long begin(TransactionMarkerMetaData tm)
                 throws java.sql.SQLException
Begin a new transaction and return the corresponding transaction identifier. This method is called from the driver when setAutoCommit(false) is called.

Parameters:
tm - The transaction marker metadata
Returns:
the transaction identifier
Throws:
java.sql.SQLException - if an error occurs

beginCompleted

public final void beginCompleted(long transactionId)
Notify the completion of a begin command.

Parameters:
transactionId - of the completed begin

commit

public final void commit(TransactionMarkerMetaData tm)
                  throws java.sql.SQLException
Commit a transaction.

Calls the implementation specific commitTransaction()

Parameters:
tm - The transaction marker metadata
Throws:
java.sql.SQLException - if an error occurs
See Also:
commitTransaction(long)

commitTransaction

protected abstract void commitTransaction(long transactionId)
Commit a transaction given its id.

Parameters:
transactionId - the transaction id

commitCompleted

public final void commitCompleted(long transactionId)
Notify the completion of a commit command.

Parameters:
transactionId - of the completed commit

rollback

public final void rollback(TransactionMarkerMetaData tm)
                    throws java.sql.SQLException
Rollback a transaction.

Calls the implementation specific rollbackTransaction()

Parameters:
tm - The transaction marker metadata
Throws:
java.sql.SQLException - if an error occurs
See Also:
rollbackTransaction(long)

rollback

public final void rollback(TransactionMarkerMetaData tm,
                           java.lang.String savepointName)
                    throws java.sql.SQLException
Rollback a transaction to a savepoint.

Calls the implementation specific rollbackTransaction()

Parameters:
tm - transaction marker metadata
savepointName - name of the savepoint
Throws:
java.sql.SQLException - if an error occurs

rollbackTransaction

protected abstract void rollbackTransaction(long transactionId)
Rollback a transaction given its id.

Parameters:
transactionId - the transaction id

rollbackTransaction

protected abstract void rollbackTransaction(long transactionId,
                                            java.lang.String savepointName)
Rollback a transaction given its id to a savepoint given its name.

Parameters:
transactionId - the transaction id
savepointName - the name of the savepoint

rollbackCompleted

public final void rollbackCompleted(long transactionId)
Notify the completion of a rollback command.

Parameters:
transactionId - of the rollback commit

setSavepoint

public final int setSavepoint(TransactionMarkerMetaData tm)
                       throws java.sql.SQLException
Set an unnamed savepoint.

Calls the implementation specific setSavepointTransaction()

Parameters:
tm - transaction marker metadata
Returns:
savepoint Id
Throws:
java.sql.SQLException - if an error occurs

setSavepoint

public final void setSavepoint(TransactionMarkerMetaData tm,
                               java.lang.String name)
                        throws java.sql.SQLException
Set a named savepoint.

Calls the implementation specific setSavepointTransaction()

Parameters:
tm - transaction marker metadata
name - name of the savepoint
Throws:
java.sql.SQLException - if an error occurs

setSavepointTransaction

protected abstract void setSavepointTransaction(long transactionId,
                                                java.lang.String name)
Set a savepoint given its name to a transaction given its id.

Parameters:
transactionId - the transaction id
name - the name of the savepoint

releaseSavepoint

public final void releaseSavepoint(TransactionMarkerMetaData tm,
                                   java.lang.String name)
                            throws java.sql.SQLException
Release a savepoint.

Calls the implementation specific releaseSavepointTransaction()

Parameters:
tm - transaction marker metadata
name - name of the savepoint
Throws:
java.sql.SQLException - if an error occurs

releaseSavepointTransaction

protected abstract void releaseSavepointTransaction(long transactionId,
                                                    java.lang.String name)
Release a savepoint given its name from a transaction given its id.

Parameters:
transactionId - the transaction id
name - the name of the savepoint

savepointCompleted

public final void savepointCompleted(long transactionId)
Notify the conpletion of a savepoint action.

Parameters:
transactionId - the transaction identifier

suspendNewTransactionsForCheckpoint

public final void suspendNewTransactionsForCheckpoint()
                                               throws java.sql.SQLException
Suspend all calls to begin() until all current transactions are finished in order to store a checkpoint. This method returns when all pending transactions have finished.

New transactions remain suspended until resumeNewTransactions() is called.

Throws:
java.sql.SQLException - if an error occurs
See Also:
resumeNewTransactions()

resumeNewTransactions

public final void resumeNewTransactions()
Resume new transactions that were suspended by suspendNewTransactionsForCheckpoint().

See Also:
suspendNewTransactionsForCheckpoint()

suspendWrites

public void suspendWrites()
                   throws java.sql.SQLException
Suspend all write queries. This method blocks until all pending writes are completed.

Writes execution is resumed by calling resumeWrites()

Throws:
java.sql.SQLException - if an error occurs
See Also:
resumeWrites()

resumeWrites

public void resumeWrites()
Resume the execution of write queries that were suspended by suspendWrites().

See Also:
suspendWrites()

getXmlImpl

protected abstract java.lang.String getXmlImpl()

getXml

public java.lang.String getXml()
Get information about the Request Scheduler in xml format

Specified by:
getXml in interface XmlComponent
Returns:
String containing information in xml

getSchedulerData

public java.lang.String[] getSchedulerData()
Returns live information on the scheduler

Returns:
array of data

getNumberRead

public int getNumberRead()
Returns:
Returns the numberRead.

getNumberWrite

public int getNumberWrite()
Returns:
Returns the numberWrite.

getPendingTransactions

public int getPendingTransactions()
Returns:
Returns the pendingTransactions.

isSuspendedTransactions

public boolean isSuspendedTransactions()
Returns:
Returns the suspendedTransactions.

isSuspendedWrites

public boolean isSuspendedWrites()
Returns:
Returns the suspendedWrites.


Copyright © 2002, 2005 - ObjectWeb Consortium - All Rights Reserved.