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

java.lang.Object
  extended byorg.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer
      extended byorg.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2
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

Field Summary
protected  java.util.ArrayList backendBlockingThreads
           
protected  ReadPrioritaryFIFOWriteLock backendBlockingThreadsRWLock
           
protected  java.util.ArrayList backendNonBlockingThreads
           
protected  ReadPrioritaryFIFOWriteLock backendNonBlockingThreadsRWLock
           
protected  CreateTablePolicy createTablePolicy
           
private  int execWriteRequestResult
           
private  java.sql.ResultSet execWriteRequestWithKeysResult
           
protected static Trace logger
           
protected  WaitForCompletionPolicy waitForCompletionPolicy
           
 
Fields inherited from class org.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer
parsingGranularity, raidbLevel, vdb
 
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)
          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)
          Enables a Backend that was previously disabled.
abstract  java.sql.ResultSet execReadRequest(SelectRequest request)
          Implementation specific load balanced read execution.
 java.sql.ResultSet execReadStoredProcedure(StoredProcedure proc)
          Call a stored procedure that returns a ResultSet.
protected  java.sql.ResultSet executeRequest(SelectRequest request, DatabaseBackend backend)
          Execute a read request on the selected backend.
 int execWriteRequest(AbstractWriteRequest request)
          Performs a write request.
private  void execWriteRequest(AbstractWriteRequest request, boolean useKeys)
          Common code for execWriteRequest(AbstractWriteRequest) and execWriteRequestWithKeys(AbstractWriteRequest).
 java.sql.ResultSet 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.
private  int getNbToWait(int nbOfThreads)
          Returns the number of nodes to wait for according to the defined waitForCompletion policy.
abstract  java.lang.String getRaidb2Xml()
          return xml formatted information about this raidb2 load balancer
 java.lang.String getXmlCreateTable()
          get xml information on create table policy
 java.lang.String getXmlInformation()
          Get information about the Request Load Balancer in xml
 java.lang.String getXmlWaitPolicy()
          get xml formatted wait policy according to c-jdbc.dtd
 void rollback(TransactionMarkerMetaData tm)
          Rollbacks a transaction.
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, int 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(int 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
getInformation, getParsingGranularity, getRAIDbLevel, setParsingGranularity, setRAIDbLevel, setWeight
 
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

execWriteRequestResult

private int execWriteRequestResult

execWriteRequestWithKeysResult

private java.sql.ResultSet execWriteRequestWithKeysResult
Constructor Detail

RAIDb2

public RAIDb2(VirtualDatabase vdb,
              WaitForCompletionPolicy waitForCompletionPolicy,
              CreateTablePolicy createTablePolicy)
       throws java.sql.SQLException
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.sql.SQLException - if an error occurs
Method Detail

getNbToWait

private final 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 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:
java.sql.SQLException - if an error occurs

execWriteRequestWithKeys

public java.sql.ResultSet execWriteRequestWithKeys(AbstractWriteRequest request)
                                            throws 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
Returns:
auto generated keys.
Throws:
java.sql.SQLException - if an error occurs

execWriteRequest

private void execWriteRequest(AbstractWriteRequest request,
                              boolean useKeys)
                       throws java.sql.SQLException
Common code for execWriteRequest(AbstractWriteRequest) and execWriteRequestWithKeys(AbstractWriteRequest). The result is given back using member variables execWriteRequestResult and execWriteRequestWithKeysResult defined above.

Parameters:
request - the request to execute
useKeys - true if this must give an auto generated keys ResultSet
Throws:
java.sql.SQLException - if an error occurs

execReadRequest

public abstract java.sql.ResultSet execReadRequest(SelectRequest request)
                                            throws java.sql.SQLException
Implementation specific load balanced read execution.

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

executeRequest

protected java.sql.ResultSet executeRequest(SelectRequest request,
                                            DatabaseBackend backend)
                                     throws java.sql.SQLException
Execute a read request on the selected backend.

Parameters:
request - the request to execute
backend - the backend that will execute the request
Returns:
the ResultSet
Throws:
java.sql.SQLException - if an error occurs

execReadStoredProcedure

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

Specified by:
execReadStoredProcedure in class AbstractLoadBalancer
Parameters:
proc - the stored procedure call
Returns:
a java.sql.ResultSet value
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractLoadBalancer.execReadStoredProcedure(org.objectweb.cjdbc.sql.StoredProcedure)

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(org.objectweb.cjdbc.sql.StoredProcedure)

callStoredProcedure

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

Parameters:
proc - the stored procedure to call
isRead - true if the call returns a ResultSet
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

waitForAllWritesToComplete

protected void waitForAllWritesToComplete(int 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

waitForAllWritesToComplete

protected void waitForAllWritesToComplete(DatabaseBackend backend,
                                          int 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
See Also:
executeRequest(SelectRequest, DatabaseBackend)

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
See Also:
executeRequest(SelectRequest, DatabaseBackend)

enableBackend

public void enableBackend(DatabaseBackend db)
                   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
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

getXmlInformation

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

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

getXmlWaitPolicy

public java.lang.String getXmlWaitPolicy()
get xml formatted wait policy according to c-jdbc.dtd

Returns:
xml formatted string of ""

getRaidb2Xml

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

Returns:
xml formatted string

getXmlCreateTable

public java.lang.String getXmlCreateTable()
get xml information on create table policy

Returns:
xml formatted string


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