com.continuent.tungsten.replicator.prefetch
Class PrefetchApplier

java.lang.Object
  extended by com.continuent.tungsten.replicator.prefetch.PrefetchApplier
All Implemented Interfaces:
RawApplier, ReplicatorPlugin

public class PrefetchApplier
extends java.lang.Object
implements RawApplier

Implements a JDBC prefetcher. This class is currently for MySQL only as it assumes MySQL syntax and index structure.

Version:
1.0
Author:
Stephane Giron

Field Summary
protected  Database conn
           
protected  java.util.HashMap<java.lang.String,java.lang.String> currentOptions
           
protected  java.lang.String currentSchema
           
protected  long currentTimestamp
           
protected  java.lang.String driver
           
protected  java.util.regex.Pattern ignoreSessionPattern
           
protected  java.lang.String ignoreSessionVars
           
protected  int maxErrors
           
protected  int maxSQLLogLength
          Maximum length of SQL string to log in case of an error.
protected  java.lang.String metadataSchema
           
protected  java.lang.String password
           
protected  int prefetchRowLimit
           
protected  PluginContext runtime
           
protected  int slowQueryCacheDuration
           
protected  int slowQueryCacheSize
           
protected  int slowQueryRows
           
protected  double slowQuerySelectivity
           
protected  java.sql.Statement statement
           
protected  int taskId
           
protected  java.lang.String url
           
protected  java.lang.String user
           
 
Constructor Summary
PrefetchApplier()
           
 
Method Summary
 void apply(DBMSEvent event, ReplDBMSHeader header, boolean doCommit, boolean doRollback)
          Apply the proffered event to the replication target.
 void commit()
          Commits current open transaction to ensure data applied up to current point are durable.
 void configure(PluginContext context)
          Complete plug-in configuration.
 Database getDatabase()
           
 ReplDBMSHeader getLastEvent()
          Return header information corresponding to last committed event.
 int getMaxErrors()
           
 int getPrefetchRowLimit()
           
 void prepare(PluginContext context)
          Prepare plug-in for use.
 void release(PluginContext context)
          Release all resources used by plug-in.
 void rollback()
          Rolls back any current work.
 void setDriver(java.lang.String driver)
           
 void setIgnoreSessionVars(java.lang.String ignoreSessionVars)
           
 void setMaxErrors(int maxErrors)
           
 void setPassword(java.lang.String password)
           
 void setPrefetchRowLimit(int prefetchRowLimit)
           
 void setSlowQueryCacheDuration(int slowQueryCacheDuration)
           
 void setSlowQueryCacheSize(int slowQueryCacheSize)
           
 void setSlowQueryRows(int slowQueryRows)
           
 void setSlowQuerySelectivity(double slowQuerySelectivity)
           
 void setTaskId(int id)
          Sets the ID of the task using this raw applier.
 void setUrl(java.lang.String url)
           
 void setUser(java.lang.String user)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

taskId

protected int taskId

driver

protected java.lang.String driver

url

protected java.lang.String url

user

protected java.lang.String user

password

protected java.lang.String password

ignoreSessionVars

protected java.lang.String ignoreSessionVars

slowQueryCacheSize

protected int slowQueryCacheSize

slowQueryRows

protected int slowQueryRows

slowQuerySelectivity

protected double slowQuerySelectivity

slowQueryCacheDuration

protected int slowQueryCacheDuration

prefetchRowLimit

protected int prefetchRowLimit

maxErrors

protected int maxErrors

runtime

protected PluginContext runtime

metadataSchema

protected java.lang.String metadataSchema

conn

protected Database conn

statement

protected java.sql.Statement statement

ignoreSessionPattern

protected java.util.regex.Pattern ignoreSessionPattern

currentSchema

protected java.lang.String currentSchema

currentTimestamp

protected long currentTimestamp

currentOptions

protected java.util.HashMap<java.lang.String,java.lang.String> currentOptions

maxSQLLogLength

protected int maxSQLLogLength
Maximum length of SQL string to log in case of an error. This is needed because some statements may be very large. TODO: make this configurable via replicator.properties

Constructor Detail

PrefetchApplier

public PrefetchApplier()
Method Detail

setTaskId

public void setTaskId(int id)
Sets the ID of the task using this raw applier.

Specified by:
setTaskId in interface RawApplier
Parameters:
id - Task ID
See Also:
RawApplier.setTaskId(int)

setDriver

public void setDriver(java.lang.String driver)

getDatabase

public Database getDatabase()

setUrl

public void setUrl(java.lang.String url)

setUser

public void setUser(java.lang.String user)

setPassword

public void setPassword(java.lang.String password)

setIgnoreSessionVars

public void setIgnoreSessionVars(java.lang.String ignoreSessionVars)

setSlowQueryCacheSize

public void setSlowQueryCacheSize(int slowQueryCacheSize)

setSlowQueryRows

public void setSlowQueryRows(int slowQueryRows)

setSlowQuerySelectivity

public void setSlowQuerySelectivity(double slowQuerySelectivity)

setSlowQueryCacheDuration

public void setSlowQueryCacheDuration(int slowQueryCacheDuration)

getPrefetchRowLimit

public int getPrefetchRowLimit()

setPrefetchRowLimit

public void setPrefetchRowLimit(int prefetchRowLimit)

getMaxErrors

public int getMaxErrors()

setMaxErrors

public void setMaxErrors(int maxErrors)

apply

public void apply(DBMSEvent event,
                  ReplDBMSHeader header,
                  boolean doCommit,
                  boolean doRollback)
           throws ReplicatorException
Apply the proffered event to the replication target.

Specified by:
apply in interface RawApplier
Parameters:
event - Event to be applied. If a DBMSEmptyEvent, just mark the apply position.
header - Header data corresponding to event
doCommit - Boolean flag indicating whether this is the last part of multi-part event
doRollback - Boolean flag indicating whether this transaction should rollback
Throws:
ReplicatorException - Thrown if applier processing fails
ConsistencyException - Thrown if the applier detects that a consistency check has failed
See Also:
RawApplier.apply(com.continuent.tungsten.replicator.event.DBMSEvent, com.continuent.tungsten.replicator.event.ReplDBMSHeader, boolean, boolean)

commit

public void commit()
            throws ReplicatorException,
                   java.lang.InterruptedException
Commits current open transaction to ensure data applied up to current point are durable.

Specified by:
commit in interface RawApplier
Throws:
ReplicatorException - Thrown if applier processing fails
java.lang.InterruptedException - Thrown if the applier is interrupted
See Also:
RawApplier.commit()

rollback

public void rollback()
              throws java.lang.InterruptedException
Rolls back any current work.

Specified by:
rollback in interface RawApplier
Throws:
java.lang.InterruptedException - Thrown if the applier is interrupted.
See Also:
RawApplier.rollback()

getLastEvent

public ReplDBMSHeader getLastEvent()
                            throws ReplicatorException
Return header information corresponding to last committed event.

Specified by:
getLastEvent in interface RawApplier
Returns:
Header data for last committed event.
Throws:
ReplicatorException - Thrown if getting sequence number fails
See Also:
RawApplier.getLastEvent()

prepare

public void prepare(PluginContext context)
             throws ReplicatorException
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)

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)

release

public void release(PluginContext context)
             throws ReplicatorException
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)