org.objectweb.cjdbc.controller.recoverylog
Class LoggerThread

java.lang.Object
  extended byjava.lang.Thread
      extended byorg.objectweb.cjdbc.controller.recoverylog.LoggerThread
All Implemented Interfaces:
java.lang.Runnable

public class LoggerThread
extends java.lang.Thread

Logger thread for the RecoveryLog.

Version:
1.0
Author:
Emmanuel Cecchet

Field Summary
private  boolean killed
           
private  Trace logger
           
private  java.util.LinkedList logQueue
           
private  java.sql.PreparedStatement logStmt
           
private  RecoveryLog recoveryLog
           
private  java.sql.PreparedStatement unlogStmt
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
LoggerThread(RecoveryLog log)
          Creates a new LoggerThread object
 
Method Summary
 void deleteCheckpointTable()
          Delete all entries from the CheckpointTable.
 void deleteLogEntriesBeforeId(long oldId)
          Delete all LogEntries with an identifier lower than oldId (inclusive).
 Trace getLogger()
          Returns the logger value.
 java.sql.PreparedStatement getLogPreparedStatement()
          Return a PreparedStatement to log an entry as follows: INSERT INTO LogTableName VALUES(?
 boolean getLogQueueIsEmpty()
          Tells whether there are pending logs
 RecoveryLog getRecoveryLog()
          Returns the recoveryLog value.
 java.sql.PreparedStatement getUnlogPreparedStatement()
          Return a PreparedStatement to unlog an entry as follows: DELETE FROM LogTableName WHERE id=?
 void invalidateLogStatements()
          Invalidate both logStmt and unlogStmt so that they can be renewed from a fresh connection.
 void log(LogEvent logObject)
          Log a write-query into the recovery log.
 void putBackAtHeadOfQueue(LogEvent event)
          Put back a log entry at the head of the queue in case a problem happened with this entry and we need to retry it right away.
 void removeQueriesOfTransactionFromQueue(long tid)
          Remove all queries that have not been logged yet and belonging to the specified transaction.
 void removeRollbackedTransaction(long transactionId)
          Remove a transaction that has rollbacked (no check is made if the transaction has really rollbacked or not).
 void run()
          Log the requests from queue until the thread is explicetly killed.
 void shiftLogEntriesIds(long shiftValue)
          Shift LogEntries identifiers from the specified value (value is added to existing identifiers).
 void shutdown()
          Shutdown the current thread.
 void storeCheckpoint(java.lang.String checkpointName, long checkpointId)
          Looks like a copy paste from RecoveryLog#storeCheckpoint(String, long), but does not wait for queue completion to store the checkpoint.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

killed

private boolean killed

logQueue

private java.util.LinkedList logQueue

logger

private Trace logger

logStmt

private java.sql.PreparedStatement logStmt

unlogStmt

private java.sql.PreparedStatement unlogStmt

recoveryLog

private RecoveryLog recoveryLog
Constructor Detail

LoggerThread

public LoggerThread(RecoveryLog log)
Creates a new LoggerThread object

Parameters:
log - the RecoveryLog that instanciates this thread
Method Detail

getLogger

public Trace getLogger()
Returns the logger value.

Returns:
Returns the logger.

getLogQueueIsEmpty

public boolean getLogQueueIsEmpty()
Tells whether there are pending logs

Returns:
true if no more jobs in the log queue

getLogPreparedStatement

public java.sql.PreparedStatement getLogPreparedStatement()
                                                   throws java.sql.SQLException
Return a PreparedStatement to log an entry as follows:

INSERT INTO LogTableName VALUES(?,?,?,?)

Returns:
a PreparedStatement
Throws:
java.sql.SQLException - if an error occurs

getRecoveryLog

public RecoveryLog getRecoveryLog()
Returns the recoveryLog value.

Returns:
Returns the recoveryLog.

getUnlogPreparedStatement

public java.sql.PreparedStatement getUnlogPreparedStatement()
                                                     throws java.sql.SQLException
Return a PreparedStatement to unlog an entry as follows:

DELETE FROM LogTableName WHERE id=? AND vlogin=? AND SqlColumnName=? AND transaction_id=?

Returns:
a PreparedStatement
Throws:
java.sql.SQLException - if an error occurs

invalidateLogStatements

public void invalidateLogStatements()
Invalidate both logStmt and unlogStmt so that they can be renewed from a fresh connection.

See Also:
getLogPreparedStatement(), getUnlogPreparedStatement()

log

public void log(LogEvent logObject)
Log a write-query into the recovery log. This posts the specified logObject (query) into this loggerThread queue. The actual write to the recoverly-log db is performed asynchronously by the thread.

Parameters:
logObject - the log event to be processed

putBackAtHeadOfQueue

public void putBackAtHeadOfQueue(LogEvent event)
Put back a log entry at the head of the queue in case a problem happened with this entry and we need to retry it right away.

Parameters:
event - the event to be used next by the logger thread.

removeQueriesOfTransactionFromQueue

public void removeQueriesOfTransactionFromQueue(long tid)
Remove all queries that have not been logged yet and belonging to the specified transaction.

Parameters:
tid - transaction id to rollback

removeRollbackedTransaction

public void removeRollbackedTransaction(long transactionId)
                                 throws java.sql.SQLException
Remove a transaction that has rollbacked (no check is made if the transaction has really rollbacked or not).

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

deleteCheckpointTable

public void deleteCheckpointTable()
                           throws java.sql.SQLException
Delete all entries from the CheckpointTable.

Throws:
java.sql.SQLException - if an error occurs

storeCheckpoint

public void storeCheckpoint(java.lang.String checkpointName,
                            long checkpointId)
                     throws java.sql.SQLException
Looks like a copy paste from RecoveryLog#storeCheckpoint(String, long), but does not wait for queue completion to store the checkpoint. Moreover, in case of error, additionely closes and invalidates log and unlog statements (internal) before calling RecoveryLog#invalidateInternalConnection().

Parameters:
checkpointName - checkpoint name to insert
checkpointId - checkpoint request identifier
Throws:
java.sql.SQLException - if a database access error occurs
See Also:
RecoveryLog.storeCheckpoint(String, long), invalidateLogStatements()

deleteLogEntriesBeforeId

public void deleteLogEntriesBeforeId(long oldId)
                              throws java.sql.SQLException
Delete all LogEntries with an identifier lower than oldId (inclusive). oldId is normally derived from a checkpoint name, which marks the last request before the checkpoint.

Parameters:
oldId - the id up to which entries should be removed.
Throws:
java.sql.SQLException - if an error occurs

shiftLogEntriesIds

public void shiftLogEntriesIds(long shiftValue)
                        throws java.sql.SQLException
Shift LogEntries identifiers from the specified value (value is added to existing identifiers).

Parameters:
shiftValue - the value to shift
Throws:
java.sql.SQLException - if an error occurs

run

public void run()
Log the requests from queue until the thread is explicetly killed. The logger used is the one of the RecoveryLog.


shutdown

public void shutdown()
Shutdown the current thread.



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