com.continuent.tungsten.replicator.pipeline
Class StageProgressTracker

java.lang.Object
  extended by com.continuent.tungsten.replicator.pipeline.StageProgressTracker

public class StageProgressTracker
extends java.lang.Object

Tracks the current status of replication and implements event watches. This class maintains a clear distinction between the latest event processed and the latest event committed. The methods to get these values are designated "dirty" and "committed" respectively to make this distinction as clear as possible.

Author:
Robert Hodges

Constructor Summary
StageProgressTracker(java.lang.String name, int threadCount)
          Creates a new stage process tracker.
 
Method Summary
 boolean allCancelled()
          Return true if all task are cancelled.
 void cancel(int taskId)
          Signal that task has been cancelled.
 void cancelAll()
          Signal that all tasks have been cancelled.
 java.util.List<TaskProgress> cloneTaskProgress()
          Returns a list of cloned task progress instances ordered by task ID.
 void commit(int taskId)
          Records the last committed event.
 long getCommittedApplyLatency()
          Return the latency of the last committed event.
 ReplDBMSHeader getCommittedMinEvent()
          Return the last committed event.
 long getCommittedMinSeqno()
          Return the last safely committed sequence number.
 ReplDBMSHeader getDirtyLastProcessedEvent(int taskId)
          Return last event that we have seen.
 ReplDBMSHeader getDirtyMinLastEvent()
          Return the last processed event or null if none such exists.
 long getDirtyMinLastSeqno()
          Return the last processed sequence number or -1 if no event exists.
 java.util.List<ShardProgress> getShardProgress()
          Returns a list of shard progress instances ordered by shard ID.
 TaskProgress getTaskProgress(int taskId)
          Return underlying progress instance for a particular task.
 java.util.List<Watch<?>> getWatches(boolean committed)
          Returns current watches.
 boolean isCancelled(int taskId)
          Return true if task has been cancelled.
 void release()
          Release progress tracker resources.
 void setApplySkipCount(long applySkipCount)
          Set the number of events to skip after going online.
 void setInitialLastProcessedEvent(int taskId, ReplDBMSHeader replEvent)
           
 void setLastProcessedEvent(int taskId, ReplDBMSHeader replEvent)
          Set the last processed event, which triggers checks for watches.
 void setLoggingInterval(long loggingInterval)
          Print a log message every time we process this many events.
 void setSeqnosToBeSkipped(java.util.SortedSet<java.lang.Long> seqnosToBeSkipped)
          Set a list of one or more events to skip.
 void setUpstreamStore(ParallelStore upstreamStore)
          Sets the upstream parallel store, if such a thing exists.
 boolean shouldInterruptTask()
          Return true if we need to interrupt the task(s) after cancellation.
 boolean skip(ReplDBMSEvent event)
          Returns false if the current event should be skipped.
 java.util.concurrent.Future<ReplDBMSHeader> watchForCommittedSequenceNumber(long seqno, boolean cancel)
          Sets a watch for a particular sequence number to be safely committed on all channels.
 java.util.concurrent.Future<ReplDBMSHeader> watchForProcessedEventId(java.lang.String eventId, boolean cancel)
          Sets a watch for a particular event ID to be processed.
 java.util.concurrent.Future<ReplDBMSHeader> watchForProcessedHeartbeat(java.lang.String name, boolean cancel)
          Sets a watch for a heartbeat event to be extracted.
 java.util.concurrent.Future<ReplDBMSHeader> watchForProcessedSequenceNumber(long seqno, boolean cancel)
          Sets a watch for a particular sequence number to be processed.
 java.util.concurrent.Future<ReplDBMSHeader> watchForProcessedTimestamp(java.sql.Timestamp timestamp, boolean cancel)
          Sets a watch for a particular source timestamp to be extracted.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StageProgressTracker

public StageProgressTracker(java.lang.String name,
                            int threadCount)
Creates a new stage process tracker.

Parameters:
name -
Method Detail

setUpstreamStore

public void setUpstreamStore(ParallelStore upstreamStore)
Sets the upstream parallel store, if such a thing exists.


setLoggingInterval

public void setLoggingInterval(long loggingInterval)
Print a log message every time we process this many events.


setApplySkipCount

public void setApplySkipCount(long applySkipCount)
Set the number of events to skip after going online.


setSeqnosToBeSkipped

public void setSeqnosToBeSkipped(java.util.SortedSet<java.lang.Long> seqnosToBeSkipped)
Set a list of one or more events to skip.


getDirtyLastProcessedEvent

public ReplDBMSHeader getDirtyLastProcessedEvent(int taskId)
Return last event that we have seen.


getDirtyMinLastEvent

public ReplDBMSHeader getDirtyMinLastEvent()
Return the last processed event or null if none such exists. This event may not be committed.


getDirtyMinLastSeqno

public long getDirtyMinLastSeqno()
Return the last processed sequence number or -1 if no event exists. This event is the minimum value that has been reached.


getCommittedMinSeqno

public long getCommittedMinSeqno()
Return the last safely committed sequence number. This value represents the minimum value across tasks. It is very fast and minimizes lock contention.


getCommittedApplyLatency

public long getCommittedApplyLatency()
Return the latency of the last committed event. This is the maximum latency as it fetches the minimum committed event.


getCommittedMinEvent

public ReplDBMSHeader getCommittedMinEvent()
Return the last committed event. This is the minimum committed event across tasks.


cloneTaskProgress

public java.util.List<TaskProgress> cloneTaskProgress()
Returns a list of cloned task progress instances ordered by task ID.


getTaskProgress

public TaskProgress getTaskProgress(int taskId)
Return underlying progress instance for a particular task.


getShardProgress

public java.util.List<ShardProgress> getShardProgress()
Returns a list of shard progress instances ordered by shard ID.


setLastProcessedEvent

public void setLastProcessedEvent(int taskId,
                                  ReplDBMSHeader replEvent)
                           throws java.lang.InterruptedException
Set the last processed event, which triggers checks for watches.

Throws:
java.lang.InterruptedException

setInitialLastProcessedEvent

public void setInitialLastProcessedEvent(int taskId,
                                         ReplDBMSHeader replEvent)
                                  throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

commit

public void commit(int taskId)
            throws java.lang.InterruptedException
Records the last committed event.

Throws:
java.lang.InterruptedException

cancel

public void cancel(int taskId)
Signal that task has been cancelled.


isCancelled

public boolean isCancelled(int taskId)
Return true if task has been cancelled.


cancelAll

public void cancelAll()
Signal that all tasks have been cancelled.


allCancelled

public boolean allCancelled()
Return true if all task are cancelled.


shouldInterruptTask

public boolean shouldInterruptTask()
Return true if we need to interrupt the task(s) after cancellation.


release

public void release()
Release progress tracker resources.


watchForProcessedSequenceNumber

public java.util.concurrent.Future<ReplDBMSHeader> watchForProcessedSequenceNumber(long seqno,
                                                                                   boolean cancel)
                                                                            throws java.lang.InterruptedException
Sets a watch for a particular sequence number to be processed.

Parameters:
seqno - Sequence number to watch for
cancel - If true, terminate task when watch is successful
Returns:
Returns a watch on the matching event
Throws:
java.lang.InterruptedException

watchForCommittedSequenceNumber

public java.util.concurrent.Future<ReplDBMSHeader> watchForCommittedSequenceNumber(long seqno,
                                                                                   boolean cancel)
                                                                            throws java.lang.InterruptedException
Sets a watch for a particular sequence number to be safely committed on all channels.

Parameters:
seqno - Sequence number to watch for
cancel - If true, terminate task when watch is successful
Returns:
Returns a watch on the matching event
Throws:
java.lang.InterruptedException

watchForProcessedEventId

public java.util.concurrent.Future<ReplDBMSHeader> watchForProcessedEventId(java.lang.String eventId,
                                                                            boolean cancel)
                                                                     throws java.lang.InterruptedException
Sets a watch for a particular event ID to be processed.

Parameters:
eventId - Native event ID to watch for
cancel - If true, terminate task when watch is successful
Returns:
Returns a watch on the matching event
Throws:
java.lang.InterruptedException

watchForProcessedHeartbeat

public java.util.concurrent.Future<ReplDBMSHeader> watchForProcessedHeartbeat(java.lang.String name,
                                                                              boolean cancel)
                                                                       throws java.lang.InterruptedException
Sets a watch for a heartbeat event to be extracted.

Parameters:
cancel - If true, terminate task when watch is successful
Returns:
Returns a watch on the matching event
Throws:
java.lang.InterruptedException

watchForProcessedTimestamp

public java.util.concurrent.Future<ReplDBMSHeader> watchForProcessedTimestamp(java.sql.Timestamp timestamp,
                                                                              boolean cancel)
                                                                       throws java.lang.InterruptedException
Sets a watch for a particular source timestamp to be extracted.

Parameters:
timestamp - Timestame to watch for
cancel - If true, terminate task when watch is successful
Returns:
Returns a watch on the matching event
Throws:
java.lang.InterruptedException

getWatches

public java.util.List<Watch<?>> getWatches(boolean committed)
Returns current watches.

Parameters:
committed - If true returned watches for committed events

skip

public boolean skip(ReplDBMSEvent event)
Returns false if the current event should be skipped.