com.continuent.tungsten.replicator.thl.log
Class LogConnection

java.lang.Object
  extended by com.continuent.tungsten.replicator.thl.log.LogConnection

public class LogConnection
extends java.lang.Object

Implements client operations on the log. Each individual client of the log must instantiate a separate connection. The client must be released after use to avoid resource leaks.

Version:
1.0
Author:
Stephane Giron

Field Summary
static long FIRST
          Symbol representing the first seqno in a new log.
static long UNINITIALIZED
          Simple representing base seqno of uninitialized log.
 
Method Summary
 void commit()
          Commit transactions stored in the log.
 void delete(java.lang.Long low, java.lang.Long high)
          Delete a range of events from the log.
 boolean isDone()
          Returns true if connection is no longer in use.
 boolean isReadonly()
          Returns true if this is a read-only client.
 THLEvent next()
          Convenience method to return the next event with blocking enabled.
 THLEvent next(boolean block)
          Returns the next event in the log.
 void release()
          Releases the client connection.
 void releaseInternal()
          Releases the client connection.
 void rollback()
          Rollback transactions stored in the log.
 boolean seek(long seqno)
          Positions cursor on first fragment of a specific event.
 boolean seek(long seqno, short fragno)
          Finds a specific THLEvent and position client cursor on the event.
 boolean seek(java.lang.String name)
          Opens a log file and positions client cursor on the event.
 void setLogRotateMillis(int logRotateMillis)
          Sets the local connection value for reading a new file after a log rotation.
 void setReadFilter(LogEventReadFilter readFilter)
          Sets the read filter, which determines whether events are fully deserialized on read.
 void setTimeoutMillis(int timeoutMillis)
          Sets the timeout in milliseconds for blocking reads on this connection.
 void store(THLEvent event, boolean commit)
          Store a THL event at the end of the log.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNINITIALIZED

public static long UNINITIALIZED
Simple representing base seqno of uninitialized log.


FIRST

public static long FIRST
Symbol representing the first seqno in a new log.

Method Detail

isReadonly

public boolean isReadonly()
Returns true if this is a read-only client.


setReadFilter

public void setReadFilter(LogEventReadFilter readFilter)
Sets the read filter, which determines whether events are fully deserialized on read. This implements query logic on scanned events.


setTimeoutMillis

public void setTimeoutMillis(int timeoutMillis)
Sets the timeout in milliseconds for blocking reads on this connection. The value overrides the read timeout for the log as a whole.


setLogRotateMillis

public void setLogRotateMillis(int logRotateMillis)
Sets the local connection value for reading a new file after a log rotation.


release

public void release()
Releases the client connection. This must be called to avoid resource leaks.


releaseInternal

public void releaseInternal()
Releases the client connection. This must be called to avoid resource leaks.


isDone

public boolean isDone()
Returns true if connection is no longer in use.


seek

public boolean seek(long seqno,
                    short fragno)
             throws ReplicatorException,
                    java.lang.InterruptedException
Finds a specific THLEvent and position client cursor on the event. The event in question may be past the end of the current log, in which case we position at the end. It is not possible to seek on an event that is before the beginning of the log.

The current log seek semantics are slightly ambiguous due to the presence of filtered events, which introduce gaps in the log. The log seek may falsely report that it has found an event in the log if it hits a log rotate event at the end before finding a non-existent event. In this case it will place the cursor at the last event in the log, if it exists. This ambiguous case only occurs under the following circumstances:

  1. The log file is still open for writing when the seek starts.
  2. The log rotates while the seek operation is being processed.
  3. The sought-for event ends up being written to the next log file.

Conversely, seek may fail to find a filtered event if that event is the last event in the last log file and the filtered event includes a span of more than one sequence number.

These ambiguities will be addressed in a future version of the log.

Parameters:
seqno - Desired sequence number
fragno - Desired fragment
Returns:
True if seek is successful and next() may be called; false if event does not exist, i.e., is before the beginning of the log
Throws:
ReplicatorException - thrown if log cannot be read
java.lang.InterruptedException

seek

public boolean seek(long seqno)
             throws ReplicatorException,
                    java.lang.InterruptedException
Positions cursor on first fragment of a specific event.

Parameters:
seqno - Desired sequence number
Returns:
True if seek is successful and next() may be called; false if event does not exist
Throws:
ReplicatorException - thrown if log cannot be read
java.lang.InterruptedException

seek

public boolean seek(java.lang.String name)
             throws ReplicatorException,
                    java.io.IOException,
                    java.lang.InterruptedException
Opens a log file and positions client cursor on the event. Clients may call next to read events.

Parameters:
name - The short name of a current log file
Returns:
True if seek is successful and next() may be called
Throws:
ReplicatorException - Thrown if the log cannot be read
java.io.IOException - Thrown if file cannot be found
java.lang.InterruptedException

next

public THLEvent next(boolean block)
              throws ReplicatorException,
                     java.lang.InterruptedException
Returns the next event in the log. If blocking is enabled, this will wait for a new event to arrive. If disabled, this call returns immediately if there is no next event. This method never returns an event with a seqno earlier than the client requested. If clients call next() after seeking past the end of the log, we therefore return the event corresponding to the seek() call or nothing.

Parameters:
block - If true, read blocks until next event is available
Returns:
A THLEvent or null if we are non-blocking
Throws:
ReplicatorException
java.lang.InterruptedException

next

public THLEvent next()
              throws ReplicatorException,
                     java.lang.InterruptedException
Convenience method to return the next event with blocking enabled.

Returns:
A THLEvent or null if we are non-blocking
Throws:
ReplicatorException
java.lang.InterruptedException

store

public void store(THLEvent event,
                  boolean commit)
           throws ReplicatorException,
                  java.lang.InterruptedException
Store a THL event at the end of the log.

Parameters:
event - THLEvent to store
commit - If true, flush to storage
Throws:
ReplicatorException
java.lang.InterruptedException

commit

public void commit()
            throws ReplicatorException,
                   java.lang.InterruptedException
Commit transactions stored in the log.

Throws:
ReplicatorException
java.lang.InterruptedException

rollback

public void rollback()
              throws ReplicatorException
Rollback transactions stored in the log.

Throws:
ReplicatorException

delete

public void delete(java.lang.Long low,
                   java.lang.Long high)
            throws ReplicatorException,
                   java.lang.InterruptedException
Delete a range of events from the log.

Throws:
ReplicatorException
java.lang.InterruptedException