org.objectweb.cjdbc.controller.loadbalancer.raidb2
Class RAIDb2

java.lang.Object
  extended byjavax.management.StandardMBean
      extended byorg.objectweb.cjdbc.controller.jmx.AbstractStandardMBean
          extended byorg.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer
              extended byorg.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2
All Implemented Interfaces:
AbstractLoadBalancerMBean, javax.management.DynamicMBean, javax.management.NotificationBroadcaster, javax.management.NotificationEmitter, XmlComponent
Direct Known Subclasses:
RAIDb2_LPRF, RAIDb2_RR, RAIDb2_WRR, RAIDb2ec

public abstract class RAIDb2
extends AbstractLoadBalancer

RAIDb-2 load balancer.

This class is an abstract call because the read requests coming from the Request Manager are NOT treated here but in the subclasses. Transaction management and write requests are broadcasted to all backends owning the written table.

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

Nested Class Summary
 
Nested classes inherited from class javax.management.StandardMBean
 
Field Summary
protected  java.util.ArrayList backendBlockingThreads
           
protected  ReadPrioritaryFIFOWriteLock backendBlockingThreadsRWLock
           
protected  java.util.ArrayList backendNonBlockingThreads
           
protected  ReadPrioritaryFIFOWriteLock backendNonBlockingThreadsRWLock
           
protected  CreateTablePolicy createTablePolicy
           
protected static Trace logger
           
protected  WaitForCompletionPolicy waitForCompletionPolicy
           
 
Fields inherited from class org.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer
macroHandler, parsingGranularity, raidbLevel, totalOrderQueue, vdb
 
Fields inherited from class org.objectweb.cjdbc.controller.jmx.AbstractStandardMBean
 
Fields inherited from class javax.management.StandardMBean
 
Fields inherited from interface org.objectweb.cjdbc.common.xml.XmlComponent
DOCTYPE_CONTROLLER, DOCTYPE_DB, XML_VERSION
 
Constructor Summary
RAIDb2(VirtualDatabase vdb, WaitForCompletionPolicy waitForCompletionPolicy, CreateTablePolicy createTablePolicy)
          Creates a new RAIDb-1 Round Robin request load balancer.
 
Method Summary
 void begin(TransactionMarkerMetaData tm)
          Begins a new transaction.
private  AbstractTask callStoredProcedure(StoredProcedure proc, boolean isRead, MetadataCache metadataCache)
          Post the stored procedure call in the threads task list.
 void commit(TransactionMarkerMetaData tm)
          Commits a transaction.
 void disableBackend(DatabaseBackend db)
          Disables a backend that was previously enabled.
 void enableBackend(DatabaseBackend db, boolean writeEnabled)
          Enables a Backend that was previously disabled.
abstract  ControllerResultSet execReadRequest(SelectRequest request, MetadataCache metadataCache)
          Implementation specific load balanced read execution.
 ControllerResultSet execReadStoredProcedure(StoredProcedure proc, MetadataCache metadataCache)
          Call a stored procedure that returns a ResultSet.
protected  ControllerResultSet executeRequestOnBackend(SelectRequest request, DatabaseBackend backend, MetadataCache metadataCache)
          Execute a read request on the selected backend.
protected  ControllerResultSet executeStoredProcedureOnBackend(StoredProcedure proc, DatabaseBackend backend, MetadataCache metadataCache)
          Execute a stored procedure on the selected backend.
 int execWriteRequest(AbstractWriteRequest request)
          Performs a write request.
private  AbstractTask execWriteRequest(AbstractWriteRequest request, boolean useKeys, MetadataCache metadataCache)
          Common code for execWriteRequest(AbstractWriteRequest) and execWriteRequestWithKeys(AbstractWriteRequest).
 ControllerResultSet execWriteRequestWithKeys(AbstractWriteRequest request, MetadataCache metadataCache)
          Perform a write request and return the auto generated keys.
 int execWriteStoredProcedure(StoredProcedure proc)
          Call a stored procedure that performs an update.
private  int getNbToWait(int nbOfThreads)
          Returns the number of nodes to wait for according to the defined waitForCompletion policy.
 int getNumberOfEnabledBackends()
          Get the number of currently enabled backends. 0 means that no backend is available.
abstract  java.lang.String getRaidb2Xml()
          return xml formatted information about this raidb2 load balancer
 java.lang.String getXmlImpl()
          Get information about the Request Load Balancer in xml
 void releaseSavepoint(TransactionMarkerMetaData tm, java.lang.String name)
          Release a savepoint from a transaction
 void rollback(TransactionMarkerMetaData tm)
          Rollbacks a transaction.
 void rollback(TransactionMarkerMetaData tm, java.lang.String savepointName)
          Rollback a transaction to a savepoint
 void setSavepoint(TransactionMarkerMetaData tm, java.lang.String name)
          Set a savepoint to a transaction.
private  void waitForAllWritesToBePostedOnBackendBlockingThreads()
          Wait for all writes to be posted on BackendBlockingThreads by simply acquiring the RW lock in write and releasing it.
protected  void waitForAllWritesToComplete(DatabaseBackend backend)
          Waits for all writes in the blocking thread queue of the given backend to complete.
protected  void waitForAllWritesToComplete(DatabaseBackend backend, long transactionId)
          Waits for all writes of the given transaction in the blocking thread queue of the given backend to complete before being able to complete the transaction.
protected  void waitForAllWritesToComplete(long transactionId)
          Waits for all writes of the given transaction in the blocking thread queue to complete before being able to complete the transaction.
 
Methods inherited from class org.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer
execReadOnlyReadStoredProcedure, executeReadStoredProcedureOnBackend, executeSelectRequestOnBackend, executeUpdateRequestOnBackend, executeUpdateRequestOnBackendWithKeys, executeWriteStoredProcedureOnBackend, getAssociatedString, getConnectionAndBeginTransaction, getInformation, getParsingGranularity, getRAIDbLevel, getXml, handleMacros, removeHeadFromAndNotifyTotalOrderQueue, setMacroHandler, setParsingGranularity, setRAIDbLevel, setWeight, waitForTotalOrder
 
Methods inherited from class org.objectweb.cjdbc.controller.jmx.AbstractStandardMBean
addNotificationListener, getDescription, getDescription, getDescription, getDescription, getDescription, getDescription, getNotificationInfo, getParameterName, getParameterName, removeNotificationListener, removeNotificationListener, sendNotification
 
Methods inherited from class javax.management.StandardMBean
cacheMBeanInfo, getAttribute, getAttributes, getCachedMBeanInfo, getClassName, getConstructors, getDescription, getImpact, getImplementation, getImplementationClass, getMBeanInfo, getMBeanInterface, invoke, setAttribute, setAttributes, setImplementation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

backendBlockingThreads

protected java.util.ArrayList backendBlockingThreads

backendNonBlockingThreads

protected java.util.ArrayList backendNonBlockingThreads

backendBlockingThreadsRWLock

protected ReadPrioritaryFIFOWriteLock backendBlockingThreadsRWLock

backendNonBlockingThreadsRWLock

protected ReadPrioritaryFIFOWriteLock backendNonBlockingThreadsRWLock

waitForCompletionPolicy

protected WaitForCompletionPolicy waitForCompletionPolicy

createTablePolicy

protected CreateTablePolicy createTablePolicy

logger

protected static Trace logger
Constructor Detail

RAIDb2

public RAIDb2(VirtualDatabase vdb,
              WaitForCompletionPolicy waitForCompletionPolicy,
              CreateTablePolicy createTablePolicy)
       throws java.lang.Exception
Creates a new RAIDb-1 Round Robin request load balancer. A new backend worker thread is created for each backend.

Parameters:
vdb - the virtual database this load balancer belongs to.
waitForCompletionPolicy - how many backends must complete before returning the result ?
createTablePolicy - the policy defining how 'create table' statements should be handled
Throws:
java.lang.Exception - if an error occurs
Method Detail

getNbToWait

private int getNbToWait(int nbOfThreads)
Returns the number of nodes to wait for according to the defined waitForCompletion policy.

Parameters:
nbOfThreads - total number of threads
Returns:
int number of threads to wait for

execWriteRequest

public int execWriteRequest(AbstractWriteRequest request)
                     throws AllBackendsFailedException,
                            java.sql.SQLException
Performs a write request. This request is broadcasted to all nodes that owns the table to be written.

Specified by:
execWriteRequest in class AbstractLoadBalancer
Parameters:
request - an AbstractWriteRequest
Returns:
number of rows affected by the request
Throws:
AllBackendsFailedException - if all backends failed to execute the request
java.sql.SQLException - if an error occurs

execWriteRequestWithKeys

public ControllerResultSet execWriteRequestWithKeys(AbstractWriteRequest request,
                                                    MetadataCache metadataCache)
                                             throws AllBackendsFailedException,
                                                    java.sql.SQLException
Perform a write request and return the auto generated keys.

Specified by:
execWriteRequestWithKeys in class AbstractLoadBalancer
Parameters:
request - the request to execute
metadataCache - the metadataCache if any or null
Returns:
auto generated keys.
Throws:
AllBackendsFailedException - if all backends failed to execute the request
java.sql.SQLException - if an error occurs

execWriteRequest

private AbstractTask execWriteRequest(AbstractWriteRequest request,
                                      boolean useKeys,
                                      MetadataCache metadataCache)
                               throws AllBackendsFailedException,
                                      java.sql.SQLException
Common code for execWriteRequest(AbstractWriteRequest) and execWriteRequestWithKeys(AbstractWriteRequest).

Note that macros are processed here.

The result is given back in AbstractTask.getResult().

Parameters:
request - the request to execute
useKeys - true if this must give an auto generated keys ResultSet
metadataCache - the metadataCache if any or null
Throws:
AllBackendsFailedException - if all backends failed to execute the request
java.sql.SQLException - if an error occurs

execReadRequest

public abstract ControllerResultSet execReadRequest(SelectRequest request,
                                                    MetadataCache metadataCache)
                                             throws java.sql.SQLException
Implementation specific load balanced read execution.

Specified by:
execReadRequest in class AbstractLoadBalancer
Parameters:
request - an SelectRequest
metadataCache - the metadataCache if any or null
Returns:
the corresponding java.sql.ResultSet
Throws:
java.sql.SQLException - if an error occurs

executeRequestOnBackend

protected ControllerResultSet executeRequestOnBackend(SelectRequest request,
                                                      DatabaseBackend backend,
                                                      MetadataCache metadataCache)
                                               throws java.sql.SQLException,
                                                      UnreachableBackendException
Execute a read request on the selected backend.

Parameters:
request - the request to execute
backend - the backend that will execute the request
metadataCache - a metadataCache if any or null
Returns:
the ResultSet
Throws:
java.sql.SQLException - if an error occurs
UnreachableBackendException

executeStoredProcedureOnBackend

protected ControllerResultSet executeStoredProcedureOnBackend(StoredProcedure proc,
                                                              DatabaseBackend backend,
                                                              MetadataCache metadataCache)
                                                       throws java.sql.SQLException,
                                                              UnreachableBackendException
Execute a stored procedure on the selected backend.

Parameters:
proc - the stored procedure to execute
backend - the backend that will execute the request
metadataCache - the metadataCache if any or null
Returns:
the ResultSet
Throws:
java.sql.SQLException - if an error occurs
UnreachableBackendException

execReadStoredProcedure

public ControllerResultSet execReadStoredProcedure(StoredProcedure proc,
                                                   MetadataCache metadataCache)
                                            throws java.sql.SQLException
Description copied from class: AbstractLoadBalancer
Call a stored procedure that returns a ResultSet. This stored procedure can possibly perform writes and will therefore be executed by all nodes.

Specified by:
execReadStoredProcedure in class AbstractLoadBalancer
Parameters:
proc - the stored procedure call
metadataCache - MetadataCache (null if none)
Returns:
a ControllerResultSet value
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractLoadBalancer.execReadStoredProcedure(StoredProcedure, MetadataCache)

execWriteStoredProcedure

public int execWriteStoredProcedure(StoredProcedure proc)
                             throws java.sql.SQLException
Description copied from class: AbstractLoadBalancer
Call a stored procedure that performs an update.

Specified by:
execWriteStoredProcedure in class AbstractLoadBalancer
Parameters:
proc - the stored procedure call
Returns:
number of rows affected
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractLoadBalancer.execWriteStoredProcedure(StoredProcedure)

callStoredProcedure

private AbstractTask callStoredProcedure(StoredProcedure proc,
                                         boolean isRead,
                                         MetadataCache metadataCache)
                                  throws java.sql.SQLException
Post the stored procedure call in the threads task list.

Note that macros are processed here.

Parameters:
proc - the stored procedure to call
isRead - true if the call returns a ResultSet
metadataCache - the metadataCache if any or null
Returns:
the task that has been executed (caller can get the result by calling getResult())
Throws:
java.sql.SQLException - if an error occurs

begin

public final void begin(TransactionMarkerMetaData tm)
                 throws java.sql.SQLException
Begins a new transaction.

Specified by:
begin in class AbstractLoadBalancer
Parameters:
tm - the transaction marker metadata
Throws:
java.sql.SQLException - if an error occurs

commit

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

Specified by:
commit in class AbstractLoadBalancer
Parameters:
tm - the transaction marker metadata
Throws:
java.sql.SQLException - if an error occurs

rollback

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

Specified by:
rollback in class AbstractLoadBalancer
Parameters:
tm - the transaction marker metadata
Throws:
java.sql.SQLException - if an error occurs

rollback

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

Specified by:
rollback in class AbstractLoadBalancer
Parameters:
tm - The transaction marker metadata
savepointName - The name of the savepoint
Throws:
AllBackendsFailedException - if all backends failed to perform the rollback
java.sql.SQLException - if an error occurs

releaseSavepoint

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

Specified by:
releaseSavepoint in class AbstractLoadBalancer
Parameters:
tm - The transaction marker metadata
name - The name of the savepoint ro release
Throws:
java.sql.SQLException - if an error occurs

setSavepoint

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

Specified by:
setSavepoint in class AbstractLoadBalancer
Parameters:
tm - The transaction marker metadata
name - The name of the new savepoint
Throws:
java.sql.SQLException - if an error occurs

waitForAllWritesToBePostedOnBackendBlockingThreads

private void waitForAllWritesToBePostedOnBackendBlockingThreads()
                                                         throws java.sql.SQLException
Wait for all writes to be posted on BackendBlockingThreads by simply acquiring the RW lock in write and releasing it.

Throws:
java.sql.SQLException - if we fail to acquire the lock

waitForAllWritesToComplete

protected void waitForAllWritesToComplete(long transactionId)
                                   throws java.sql.SQLException
Waits for all writes of the given transaction in the blocking thread queue to complete before being able to complete the transaction.

Throws:
java.sql.SQLException - if a locking error occurs

waitForAllWritesToComplete

protected void waitForAllWritesToComplete(DatabaseBackend backend,
                                          long transactionId)
                                   throws java.sql.SQLException
Waits for all writes of the given transaction in the blocking thread queue of the given backend to complete before being able to complete the transaction.

Throws:
java.sql.SQLException - if we fail to acquire the lock
See Also:
executeRequestOnBackend(org.objectweb.cjdbc.common.sql.SelectRequest, org.objectweb.cjdbc.controller.backend.DatabaseBackend, org.objectweb.cjdbc.controller.cache.metadata.MetadataCache)

waitForAllWritesToComplete

protected void waitForAllWritesToComplete(DatabaseBackend backend)
                                   throws java.sql.SQLException
Waits for all writes in the blocking thread queue of the given backend to complete.

Throws:
java.sql.SQLException - if we fail to acquire the lock
See Also:
executeRequestOnBackend(org.objectweb.cjdbc.common.sql.SelectRequest, org.objectweb.cjdbc.controller.backend.DatabaseBackend, org.objectweb.cjdbc.controller.cache.metadata.MetadataCache)

enableBackend

public void enableBackend(DatabaseBackend db,
                          boolean writeEnabled)
                   throws java.sql.SQLException
Enables a Backend that was previously disabled.

Ask the corresponding connection manager to initialize the connections if needed.

No sanity checks are performed by this function.

Specified by:
enableBackend in class AbstractLoadBalancer
Parameters:
db - The database backend to enable
writeEnabled - True if the backend must be enabled for writes
Throws:
java.sql.SQLException - if an error occurs

disableBackend

public void disableBackend(DatabaseBackend db)
                    throws java.sql.SQLException
Disables a backend that was previously enabled.

Ask the corresponding connection manager to finalize the connections if needed.

No sanity checks are performed by this function.

Specified by:
disableBackend in class AbstractLoadBalancer
Parameters:
db - the database backend to disable
Throws:
java.sql.SQLException - if an error occurs

getNumberOfEnabledBackends

public int getNumberOfEnabledBackends()
Description copied from class: AbstractLoadBalancer
Get the number of currently enabled backends. 0 means that no backend is available.

Specified by:
getNumberOfEnabledBackends in class AbstractLoadBalancer
Returns:
number of currently enabled backends
See Also:
AbstractLoadBalancer.getNumberOfEnabledBackends()

getXmlImpl

public java.lang.String getXmlImpl()
Description copied from class: AbstractLoadBalancer
Get information about the Request Load Balancer in xml

Specified by:
getXmlImpl in class AbstractLoadBalancer
Returns:
String containing information, xml formatted
See Also:
AbstractLoadBalancer.getXmlImpl()

getRaidb2Xml

public abstract java.lang.String getRaidb2Xml()
return xml formatted information about this raidb2 load balancer

Returns:
xml formatted string


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