org.objectweb.cjdbc.controller.requestmanager.distributed
Class DistributedRequestManager

java.lang.Object
  extended byjavax.management.StandardMBean
      extended byorg.objectweb.cjdbc.controller.jmx.AbstractStandardMBean
          extended byorg.objectweb.cjdbc.controller.requestmanager.RequestManager
              extended byorg.objectweb.cjdbc.controller.requestmanager.distributed.DistributedRequestManager
All Implemented Interfaces:
javax.management.DynamicMBean, javax.management.NotificationBroadcaster, javax.management.NotificationEmitter, RequestManagerMBean, XmlComponent
Direct Known Subclasses:
RAIDb1DistributedRequestManager, RAIDb2DistributedRequestManager

public abstract class DistributedRequestManager
extends RequestManager

This class defines a Distributed Request Manager.

The DRM is composed of a Request Scheduler, an optional Query Cache, and a Load Balancer and an optional Recovery Log. Unlike a non-dsitributed Request Manager, this implementation is responsible for synchronizing the different controllers components (schedulers, ...). Functions that are RAIDb level dependent are implemented in sub-classes.

Version:
1.0
Author:
Emmanuel Cecchet

Nested Class Summary
 
Nested classes inherited from class javax.management.StandardMBean
 
Field Summary
private  long controllerId
          Unique controller identifier
protected  DistributedVirtualDatabase dvdb
           
private  java.util.Vector failedOnAllBackends
          List of queries that failed on all backends
private  java.util.ArrayList writeTransactions
          List of transactions that have executed at least one write query
 
Fields inherited from class org.objectweb.cjdbc.controller.requestmanager.RequestManager
backupManager, beginTimeout, commitTimeout, dbs, loadBalancer, logger, parsingCache, recoveryLog, requiredGranularity, resultCache, rollbackTimeout, scheduler, schedulerParsingranularity, tidLoginTable, 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_DB, XML_VERSION
 
Constructor Summary
DistributedRequestManager(DistributedVirtualDatabase vdb, AbstractScheduler scheduler, AbstractResultCache cache, AbstractLoadBalancer loadBalancer, AbstractRecoveryLog recoveryLog, long beginTimeout, long commitTimeout, long rollbackTimeout)
          Builds a new DistributedRequestManager instance without cache.
 
Method Summary
 void addFailedOnAllBackends(AbstractRequest request)
          Add a request that failed on all backends.
 long begin(java.lang.String login)
          Begin a new transaction and return the corresponding transaction identifier.
 void commit(long transactionId)
          Commit a transaction given its id.
 void completeFailedOnAllBackends(AbstractRequest request, boolean success)
          Notify completion of a request that failed on all backends.
abstract  void distributedCommit(long transactionId)
          Distributed implementation of a commit
abstract  void distributedRollback(long transactionId)
          Distributed implementation of a rollback
 void enableBackend(DatabaseBackend db)
          Enable a backend that has been previously added to this virtual database and that is in the disabled state.
abstract  ControllerResultSet execDistributedReadStoredProcedure(StoredProcedure proc)
          Distributed implementation of a read stored procedure execution.
 ControllerResultSet execDistributedReadStoredProcedureLocally(StoredProcedure proc)
          Once the request has been dispatched, it can be executed using the code from RequestManager
abstract  int execDistributedWriteRequest(AbstractWriteRequest request)
          Distributed implementation of a write request execution.
abstract  ControllerResultSet execDistributedWriteRequestWithKeys(AbstractWriteRequest request)
          Distributed implementation of a write request execution that returns auto-generated keys.
abstract  int execDistributedWriteStoredProcedure(StoredProcedure proc)
          Distributed implementation of a write stored procedure execution.
 int execDistributedWriteStoredProcedureLocally(StoredProcedure proc)
          Once the request has been dispatched, it can be executed using the code from RequestManager
 ControllerResultSet execReadStoredProcedure(StoredProcedure proc)
          Call a stored procedure that returns a ResultSet.
 int execWriteRequest(AbstractWriteRequest request)
          Perform a write request and return the number of rows affected Call first the scheduler (if defined), then notify the cache (if defined) and finally call the load balancer.
 ControllerResultSet execWriteRequestWithKeys(AbstractWriteRequest request)
          Perform a write request and return the auto generated keys.
 int execWriteStoredProcedure(StoredProcedure proc)
          Call a stored procedure that performs an update.
 Trace getLogger()
          Get the trace logger of this DistributedRequestManager
 VirtualDatabase getVirtualDatabase()
          Returns the vdb value.
 void lazyTransactionStart(AbstractRequest request)
          Check if the transaction corresponding to the given query has been started remotely and start the transaction locally in a lazy manner if needed.
 void rollback(long transactionId)
          Rollback a transaction given its id.
 void scheduleExecWriteRequest(AbstractWriteRequest request)
          Schedule a request for execution.
 void setControllerId(int id)
          Sets the controller identifier value (this id must be unique).
 
Methods inherited from class org.objectweb.cjdbc.controller.requestmanager.RequestManager
abort, backupBackendWithCheckpoint, callBackupManager, completeTransaction, disableBackend, disableBackendForCheckpoint, disableBackendsForCheckpoint, enableBackendFromCheckpoint, execReadRequest, getAssociatedString, getBackendStateListener, getBackupManager, getBeginTimeout, getCacheParsingranularity, getCommitTimeout, getDatabaseSchema, getLoadBalancer, getLoadBalancerParsingranularity, getMetadataCache, getRecoveryLog, getRequiredGranularity, getRequiredParsingGranularity, getResultCache, getRollbackTimeout, getScheduler, getSchedulerParsingranularity, getTransactionMarker, getXml, isCaseSensitiveParsing, isSchemaIsStatic, loadBalanceExecWriteRequest, loadBalanceExecWriteRequestWithKeys, mergeDatabaseSchema, removeCheckpoint, restoreBackendFromBackupCheckpoint, setBackupManager, setBeginTimeout, setCacheParsingranularity, setCaseSensitiveParsing, setCommitTimeout, setDatabaseSchema, setLoadBalancer, setLoadBalancerParsingranularity, setMetadataCache, setParsingCache, setRecoveryLog, setRequiredGranularity, setResultCache, setRollbackTimeout, setScheduler, setSchedulerParsingranularity, setSchemaIsStatic, storeBackendsInfo, updateAndNotifyExecWriteRequest
 
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

dvdb

protected DistributedVirtualDatabase dvdb

failedOnAllBackends

private java.util.Vector failedOnAllBackends
List of queries that failed on all backends


controllerId

private long controllerId
Unique controller identifier


writeTransactions

private java.util.ArrayList writeTransactions
List of transactions that have executed at least one write query

Constructor Detail

DistributedRequestManager

public DistributedRequestManager(DistributedVirtualDatabase vdb,
                                 AbstractScheduler scheduler,
                                 AbstractResultCache cache,
                                 AbstractLoadBalancer loadBalancer,
                                 AbstractRecoveryLog recoveryLog,
                                 long beginTimeout,
                                 long commitTimeout,
                                 long rollbackTimeout)
                          throws java.sql.SQLException,
                                 javax.management.NotCompliantMBeanException
Builds a new DistributedRequestManager instance without cache.

Parameters:
vdb - the virtual database this request manager belongs to
scheduler - the Request Scheduler to use
cache - a Query Cache implementation
loadBalancer - the Request Load Balancer to use
recoveryLog - the Log Recovery to use
beginTimeout - timeout in seconds for begin
commitTimeout - timeout in seconds for commit
rollbackTimeout - timeout in seconds for rollback
Throws:
java.sql.SQLException - if an error occurs
javax.management.NotCompliantMBeanException - if this class is not a compliant JMX MBean
Method Detail

getLogger

public Trace getLogger()
Get the trace logger of this DistributedRequestManager

Returns:
a Trace object

getVirtualDatabase

public VirtualDatabase getVirtualDatabase()
Returns the vdb value.

Overrides:
getVirtualDatabase in class RequestManager
Returns:
Returns the vdb.

enableBackend

public void enableBackend(DatabaseBackend db)
                   throws java.sql.SQLException
Enable a backend that has been previously added to this virtual database and that is in the disabled state. We check we the other controllers if this backend must be enabled in read-only or read-write. The current policy is that the first one to enable this backend will have read-write access to it and others will be in read-only.

Overrides:
enableBackend in class RequestManager
Parameters:
db - The database backend to enable
Throws:
java.sql.SQLException - if an error occurs

addFailedOnAllBackends

public void addFailedOnAllBackends(AbstractRequest request)
Add a request that failed on all backends.

Parameters:
request - the request that failed

completeFailedOnAllBackends

public void completeFailedOnAllBackends(AbstractRequest request,
                                        boolean success)
Notify completion of a request that failed on all backends. If completion was successful, all local backends are disabled.

Parameters:
request - request that completed
success - true if completion is successful

setControllerId

public void setControllerId(int id)
Sets the controller identifier value (this id must be unique).

Parameters:
id - The controllerId to set.

begin

public long begin(java.lang.String login)
           throws java.sql.SQLException
Description copied from class: RequestManager
Begin a new transaction and return the corresponding transaction identifier. This method is called from the driver when setAutoCommit(false) is called.

Overrides:
begin in class RequestManager
Parameters:
login - the login used by the connection
Returns:
int a unique transaction identifier
Throws:
java.sql.SQLException - if an error occurs
See Also:
RequestManager.begin(java.lang.String)

commit

public void commit(long transactionId)
            throws java.sql.SQLException
Description copied from class: RequestManager
Commit a transaction given its id.

Overrides:
commit in class RequestManager
Parameters:
transactionId - the transaction id
Throws:
java.sql.SQLException - if an error occurs
See Also:
RequestManager.commit(long)

rollback

public void rollback(long transactionId)
              throws java.sql.SQLException
Description copied from class: RequestManager
Rollback a transaction given its id.

Overrides:
rollback in class RequestManager
Parameters:
transactionId - the transaction id
Throws:
java.sql.SQLException - if an error occurs
See Also:
RequestManager.rollback(long)

scheduleExecWriteRequest

public void scheduleExecWriteRequest(AbstractWriteRequest request)
                              throws java.sql.SQLException
Description copied from class: RequestManager
Schedule a request for execution.

Overrides:
scheduleExecWriteRequest in class RequestManager
Parameters:
request - the request to execute
Throws:
java.sql.SQLException - if an error occurs
See Also:
RequestManager.scheduleExecWriteRequest(org.objectweb.cjdbc.common.sql.AbstractWriteRequest)

lazyTransactionStart

public void lazyTransactionStart(AbstractRequest request)
                          throws java.sql.SQLException
Check if the transaction corresponding to the given query has been started remotely and start the transaction locally in a lazy manner if needed.

Parameters:
request - query to execute
Throws:
java.sql.SQLException - if an error occurs

execWriteRequest

public int execWriteRequest(AbstractWriteRequest request)
                     throws java.sql.SQLException
Description copied from class: RequestManager
Perform a write request and return the number of rows affected Call first the scheduler (if defined), then notify the cache (if defined) and finally call the load balancer.

Overrides:
execWriteRequest in class RequestManager
Parameters:
request - the request to execute
Returns:
number of rows affected
Throws:
java.sql.SQLException - if an error occurs
See Also:
RequestManager.execWriteRequest(org.objectweb.cjdbc.common.sql.AbstractWriteRequest)

execWriteRequestWithKeys

public ControllerResultSet execWriteRequestWithKeys(AbstractWriteRequest request)
                                             throws java.sql.SQLException
Description copied from class: RequestManager
Perform a write request and return the auto generated keys. Call first the scheduler (if defined), then notify the cache (if defined) and finally call the load balancer.

Overrides:
execWriteRequestWithKeys in class RequestManager
Parameters:
request - the request to execute
Returns:
auto generated keys.
Throws:
java.sql.SQLException - if an error occurs
See Also:
RequestManager.execWriteRequestWithKeys(org.objectweb.cjdbc.common.sql.AbstractWriteRequest)

execReadStoredProcedure

public ControllerResultSet execReadStoredProcedure(StoredProcedure proc)
                                            throws java.sql.SQLException
Description copied from class: RequestManager
Call a stored procedure that returns a ResultSet.

Overrides:
execReadStoredProcedure in class RequestManager
Parameters:
proc - the stored procedure call
Returns:
a ControllerResultSet value
Throws:
java.sql.SQLException - if an error occurs
See Also:
RequestManager.execReadStoredProcedure(StoredProcedure)

execWriteStoredProcedure

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

Overrides:
execWriteStoredProcedure in class RequestManager
Parameters:
proc - the stored procedure call
Returns:
number of rows affected
Throws:
java.sql.SQLException - if an error occurs
See Also:
RequestManager.execWriteStoredProcedure(org.objectweb.cjdbc.common.sql.StoredProcedure)

distributedCommit

public abstract void distributedCommit(long transactionId)
                                throws java.sql.SQLException
Distributed implementation of a commit

Parameters:
transactionId - id of the commiting transaction
Throws:
java.sql.SQLException - if an error occurs

distributedRollback

public abstract void distributedRollback(long transactionId)
                                  throws java.sql.SQLException
Distributed implementation of a rollback

Parameters:
transactionId - id of the rollbacking transaction
Throws:
java.sql.SQLException - if an error occurs

execDistributedWriteRequest

public abstract int execDistributedWriteRequest(AbstractWriteRequest request)
                                         throws java.sql.SQLException
Distributed implementation of a write request execution.

Parameters:
request - request to execute
Returns:
number of modified rows
Throws:
java.sql.SQLException - if an error occurs

execDistributedWriteRequestWithKeys

public abstract ControllerResultSet execDistributedWriteRequestWithKeys(AbstractWriteRequest request)
                                                                 throws java.sql.SQLException
Distributed implementation of a write request execution that returns auto-generated keys.

Parameters:
request - request to execute
Returns:
ResultSet containing the auto-generated keys.
Throws:
java.sql.SQLException - if an error occurs

execDistributedReadStoredProcedure

public abstract ControllerResultSet execDistributedReadStoredProcedure(StoredProcedure proc)
                                                                throws java.sql.SQLException
Distributed implementation of a read stored procedure execution.

Parameters:
proc - stored procedure to execute
Returns:
ResultSet corresponding to this stored procedure execution
Throws:
java.sql.SQLException - if an error occurs

execDistributedWriteStoredProcedure

public abstract int execDistributedWriteStoredProcedure(StoredProcedure proc)
                                                 throws java.sql.SQLException
Distributed implementation of a write stored procedure execution.

Parameters:
proc - stored procedure to execute
Returns:
number of modified rows
Throws:
java.sql.SQLException - if an error occurs

execDistributedReadStoredProcedureLocally

public ControllerResultSet execDistributedReadStoredProcedureLocally(StoredProcedure proc)
                                                              throws java.sql.SQLException
Once the request has been dispatched, it can be executed using the code from RequestManager

Parameters:
proc - stored procedure to execute
Returns:
ResultSet corresponding to this stored procedure execution
Throws:
java.sql.SQLException - if an error occurs

execDistributedWriteStoredProcedureLocally

public int execDistributedWriteStoredProcedureLocally(StoredProcedure proc)
                                               throws java.sql.SQLException
Once the request has been dispatched, it can be executed using the code from RequestManager

Parameters:
proc - stored procedure to execute
Returns:
number of modified rows
Throws:
java.sql.SQLException - if an error occurs


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