com.continuent.tungsten.replicator.storage
Class InMemoryTransactionalQueue

java.lang.Object
  extended by com.continuent.tungsten.replicator.storage.InMemoryTransactionalQueue
All Implemented Interfaces:
ReplicatorPlugin, Store

public class InMemoryTransactionalQueue
extends java.lang.Object
implements Store

Implements an in-memory queue store that applies events from multiple task threads (i.e., channels) into a single centralized queue. The queue has transactional semantics in the sense that it buffers events from each task thread and them applies them in a single operation upon commit. This is helpful for detecting out-of-order apply due to errors in the synchronization of parallel tasks.

To further simulate DBMS behavior this queue supports commit actions, which may perform arbitrary actions such as delaying or throwing exceptions.

Version:
1.0
Author:
Robert Hodges

Constructor Summary
InMemoryTransactionalQueue()
           
 
Method Summary
 void commit(int taskId)
          Commits all pending events for a particular task.
 void configure(PluginContext context)
          Complete plug-in configuration.
 ReplDBMSEvent get()
          Removes and returns next event from the queue, blocking if empty.
 CommitAction getCommitAction()
          An action to invoke prior to commit.
 int getCommitTimeout()
          Maximum commit timeout (fails after this) in seconds.
 ReplDBMSHeader getLastHeader(int taskId)
          Returns the last header processed.
 int getMaxSize()
          Maximum number of events permitted in serial queue.
 long getMaxStoredSeqno()
          Returns the maximum persistently stored sequence number.
 long getMinStoredSeqno()
          Returns the minimum persistently stored sequence number.
 java.lang.String getName()
          Gets the storage name.
 int getPartitions()
          Number of partitions supported by the queue.
 ReplDBMSEvent peek()
          Returns but does not remove next event from the queue if it exists or returns null if queue is empty.
 void prepare(PluginContext context)
          Allocate an in-memory queue.
 void put(int taskId, ReplDBMSEvent event)
          Puts an event in the local task queue, where it is buffered in order until commit or rollback.
 void release(PluginContext context)
          Release queue.
 void rollback(int taskId)
          Rolls back pending events for a particular task.
 void setCommitAction(CommitAction commitAction)
           
 void setCommitTimeout(int commitTimeout)
           
 void setLastHeader(int taskId, ReplDBMSHeader header)
          Sets the last header processed.
 void setMaxSize(int size)
           
 void setName(java.lang.String name)
          Sets the storage name.
 void setPartitions(int partitions)
           
 int size()
          Returns the current serial queue size.
 TungstenProperties status()
          Returns status information as a set of named properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InMemoryTransactionalQueue

public InMemoryTransactionalQueue()
Method Detail

getName

public java.lang.String getName()
Gets the storage name.

Specified by:
getName in interface Store
See Also:
Store.getName()

setName

public void setName(java.lang.String name)
Sets the storage name.

Specified by:
setName in interface Store
See Also:
Store.setName(java.lang.String)

getMaxSize

public int getMaxSize()
Maximum number of events permitted in serial queue.


setMaxSize

public void setMaxSize(int size)

getPartitions

public int getPartitions()
Number of partitions supported by the queue.


setPartitions

public void setPartitions(int partitions)

getCommitTimeout

public int getCommitTimeout()
Maximum commit timeout (fails after this) in seconds.


setCommitTimeout

public void setCommitTimeout(int commitTimeout)

getCommitAction

public CommitAction getCommitAction()
An action to invoke prior to commit.


setCommitAction

public void setCommitAction(CommitAction commitAction)

setLastHeader

public void setLastHeader(int taskId,
                          ReplDBMSHeader header)
Sets the last header processed. This is required for restart.


getLastHeader

public ReplDBMSHeader getLastHeader(int taskId)
Returns the last header processed.


getMaxStoredSeqno

public long getMaxStoredSeqno()
Returns the maximum persistently stored sequence number.

Specified by:
getMaxStoredSeqno in interface Store
See Also:
Store.getMaxStoredSeqno()

getMinStoredSeqno

public long getMinStoredSeqno()
Returns the minimum persistently stored sequence number.

Specified by:
getMinStoredSeqno in interface Store
See Also:
Store.getMinStoredSeqno()

put

public void put(int taskId,
                ReplDBMSEvent event)
         throws java.lang.InterruptedException,
                ReplicatorException
Puts an event in the local task queue, where it is buffered in order until commit or rollback.

Throws:
java.lang.InterruptedException
ReplicatorException

commit

public void commit(int taskId)
            throws java.lang.InterruptedException,
                   ReplicatorException
Commits all pending events for a particular task.

Throws:
java.lang.InterruptedException
ReplicatorException

rollback

public void rollback(int taskId)
Rolls back pending events for a particular task.

Throws:
java.lang.InterruptedException

get

public ReplDBMSEvent get()
                  throws java.lang.InterruptedException
Removes and returns next event from the queue, blocking if empty.

Throws:
java.lang.InterruptedException

peek

public ReplDBMSEvent peek()
Returns but does not remove next event from the queue if it exists or returns null if queue is empty.


size

public int size()
Returns the current serial queue size.


configure

public void configure(PluginContext context)
               throws ReplicatorException
Complete plug-in configuration. This is called after setters are invoked at the time that the replicator goes through configuration.

Specified by:
configure in interface ReplicatorPlugin
Throws:
ReplicatorException - Thrown if configuration is incomplete or fails
See Also:
ReplicatorPlugin.configure(com.continuent.tungsten.replicator.plugin.PluginContext)

prepare

public void prepare(PluginContext context)
             throws ReplicatorException
Allocate an in-memory queue. Prepare plug-in for use. This method is assumed to allocate all required resources. It is called before the plug-in performs any operations.

Specified by:
prepare in interface ReplicatorPlugin
Throws:
ReplicatorException - Thrown if resource allocation fails
See Also:
ReplicatorPlugin.prepare(com.continuent.tungsten.replicator.plugin.PluginContext)

release

public void release(PluginContext context)
             throws ReplicatorException
Release queue. Release all resources used by plug-in. This is called before the plug-in is deallocated.

Specified by:
release in interface ReplicatorPlugin
Throws:
ReplicatorException - Thrown if resource deallocation fails
See Also:
ReplicatorPlugin.release(com.continuent.tungsten.replicator.plugin.PluginContext)

status

public TungstenProperties status()
Returns status information as a set of named properties.

Specified by:
status in interface Store
See Also:
Store.status()