com.continuent.tungsten.replicator.conf
Class ReplicatorRuntime

java.lang.Object
  extended by com.continuent.tungsten.replicator.conf.ReplicatorRuntime
All Implemented Interfaces:
PluginContext

public class ReplicatorRuntime
extends java.lang.Object
implements PluginContext

Contains run-time data for the replicator, including properties and all active plugins. The runtime is created at configuration time and is discarded when the replicator goes off-line. The run-time handles basic life cycle management for plug-ins, which are managed through this class.

Version:
1.0
Author:
Robert Hodges

Constructor Summary
ReplicatorRuntime(TungstenProperties properties, OpenReplicatorContext context, ReplicatorMonitor monitor)
          Creates a new Runtime instance.
 
Method Summary
protected  java.lang.String assertPropertyDefault(java.lang.String key, java.lang.String value)
          Ensures that a required property has a default if unspecified.
protected  java.lang.String assertPropertySet(java.lang.String key)
           
 void configure()
          Process configuration properties and instantiate/configure all plug-ins.
static void configurePlugin(ReplicatorPlugin plugin, PluginContext context)
          Call configure method on a plugin class.
 FailurePolicy getApplierFailurePolicy()
          Returns the applier failure policy.
 FailurePolicy getApplierFailurePolicyOn0RowUpdates()
          Returns the applierFailurePolicyOn0Updates value.
 int getChannels()
          Returns the number of channels in the tail stage of the pipeline or -1 if pipeline is not active.
 java.lang.String getClusterName()
          Cluster name to which replicator belongs.
 long getCommittedSeqno()
          Returns the minimum safely committed sequence number from the end of the pipeline.
 com.continuent.tungsten.fsm.event.EventDispatcher getEventDispatcher()
          Returns the event dispatcher for reporting interesting events.
 ReplicatorPlugin getExtension(java.lang.String name)
          Returns the named extension or null if the extension does not exist.
 java.util.List<java.lang.String> getExtensionNames()
          Returns the current list of extensions.
 FailurePolicy getExtractorFailurePolicy()
          Returns the extractorFailurePolicy value.
 java.lang.String getJdbcPassword()
          Returns a password suitable for login to local data source.
 java.lang.String getJdbcUrl(java.lang.String database)
          Returns a JDBC URL suitable for login to local data source.
 java.lang.String getJdbcUser()
          Returns a user for login to local data source.
 java.lang.String getLastOnlineRoleName()
          Returns the role as of the last time the replicator went online or null if the role is not known.
 ReplicatorMonitor getMonitor()
          Returns the monitoring data object.
 TungstenProperties getOnlineOptions()
          Returns current online options or null if the replication service has not gone online.
 OpenReplicatorContext getOpenReplicatorContext()
          Returns OpenReplicatorContext used for registering current runtime.
 Pipeline getPipeline()
          Returns the pipeline.
 java.lang.String getPipelineSource()
          Returns the transaction source of the head stage in the pipeline.
 TungstenProperties getReplicatorProperties()
          Returns the current replicator properties.
 java.lang.String getReplicatorSchemaName()
          Schema name for storing replicator catalogs.
 java.lang.String getRoleName()
          Returns the role name.
 PipelineService getService(java.lang.String name)
          Returns a named pipeline service component.
 java.lang.String getServiceName()
          Service name to which replication belongs.
 java.util.List<PipelineService> getServices()
          Returns all pipeline service components.
 java.lang.String getSourceId()
          Source ID for this replicator.
 java.util.List<Stage> getStages()
          Returns stages in pipeline order.
 Store getStore(java.lang.String name)
          Returns a named storage component.
 java.util.List<Store> getStores()
          Returns all stores.
 java.lang.String getTungstenTableType()
          Returns the table type used for Tungsten catalog databases.
protected  void instantiateAndConfigurePipeline(java.lang.String name)
          Instantiates a pipeline consisting of one or more stages.
protected  void instantiateExtensions()
          Load extension classes, if defined.
 boolean isAutoEnable()
          Returns true if replicator should go on-line automatically.
 boolean isConsistencyCheckColumnNames()
          Should consistency check be sensitive to column names?
 boolean isConsistencyCheckColumnTypes()
          Should consistency check be sensitive to column types?
 boolean isConsistencyFailureStop()
          True if the replicator should stop on checksum failure.
 boolean isDoChecksum()
          Are checksums enabled? If false this overrides any local checksum setting.
 boolean isMaster()
          Returns true if the replicator role is master.
 boolean isPrivilegedSlaveUpdate()
          Returns true if the JDBC login for slave apply is a superuser.
 boolean isRemoteService()
          Returns true if the current replication pipeline belongs to a remote data service.
 boolean isSlave()
          Returns true if the replicator role is slave.
protected  ReplicatorPlugin loadAndConfigurePlugin(java.lang.String prefix, java.lang.String name)
          Generic code to load and configure a plugin.
 boolean logReplicatorUpdates()
          Returns true if we want to log replicator updates.
 boolean nativeSlaveTakeover()
          Return true if operating in native slave takeover mode.
 void prepare()
          Prepares pipeline for use.
static void preparePlugin(ReplicatorPlugin plugin, PluginContext context)
          Call prepare method on a plugin class.
 void registerMBean(java.lang.Object mbean, java.lang.Class<?> mbeanClass, java.lang.String name)
          Registers a JMX MBean from a lower-level component.
 void release()
          Releases all plug-ins stored in runtime by calling their release() methods and setting the storage locations to null so they can be garbage-collected.
static void releasePlugin(ReplicatorPlugin plugin, PluginContext context)
          Call release method on a plugin class, warning on errors.
 void setLastOnlineRoleName(java.lang.String roleName)
          Writes the value of the last online role to storage.
 void setOnlineOptions(TungstenProperties onlineOptions)
          Sets online options.
 void setPipelineSource(java.lang.String source)
          Registers the transaction source (if any) for the head of the current pipeline.
protected  PluginSpecification specifyPlugin(java.lang.String prefix, java.lang.String name)
          Generic code to load and configure a plugin.
 java.util.concurrent.Future<ReplDBMSHeader> waitForCommitted(long seqno)
          Returns a future to allow clients to wait until the pipeline has safely committed the requested seqno.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReplicatorRuntime

public ReplicatorRuntime(TungstenProperties properties,
                         OpenReplicatorContext context,
                         ReplicatorMonitor monitor)
Creates a new Runtime instance.

Parameters:
properties - Current system properties, which are copied rather than used directly
Method Detail

configure

public void configure()
               throws ReplicatorException
Process configuration properties and instantiate/configure all plug-ins. This method must be called before the configuration is usable.

Throws:
ReplicatorException - Thrown if configuration fails

instantiateExtensions

protected void instantiateExtensions()
                              throws ReplicatorException
Load extension classes, if defined.

Throws:
ReplicatorException

instantiateAndConfigurePipeline

protected void instantiateAndConfigurePipeline(java.lang.String name)
                                        throws ReplicatorException
Instantiates a pipeline consisting of one or more stages.

Throws:
ReplicatorException

prepare

public void prepare()
             throws ReplicatorException,
                    java.lang.InterruptedException
Prepares pipeline for use.

Throws:
ReplicatorException
java.lang.InterruptedException

release

public void release()
Releases all plug-ins stored in runtime by calling their release() methods and setting the storage locations to null so they can be garbage-collected. This method is idempotent and may therefore be called multiple times.


getPipeline

public Pipeline getPipeline()
Returns the pipeline.


assertPropertyDefault

protected java.lang.String assertPropertyDefault(java.lang.String key,
                                                 java.lang.String value)
Ensures that a required property has a default if unspecified.


assertPropertySet

protected java.lang.String assertPropertySet(java.lang.String key)
                                      throws ReplicatorException
Throws:
ReplicatorException

loadAndConfigurePlugin

protected ReplicatorPlugin loadAndConfigurePlugin(java.lang.String prefix,
                                                  java.lang.String name)
                                           throws ReplicatorException
Generic code to load and configure a plugin.

Throws:
ReplicatorException

specifyPlugin

protected PluginSpecification specifyPlugin(java.lang.String prefix,
                                            java.lang.String name)
                                     throws ReplicatorException
Generic code to load and configure a plugin.

Throws:
ReplicatorException

getOpenReplicatorContext

public OpenReplicatorContext getOpenReplicatorContext()
Returns OpenReplicatorContext used for registering current runtime.


getReplicatorProperties

public TungstenProperties getReplicatorProperties()
Returns the current replicator properties.

Specified by:
getReplicatorProperties in interface PluginContext

getOnlineOptions

public TungstenProperties getOnlineOptions()
Returns current online options or null if the replication service has not gone online. These options are ephemeral and reset each time the replication service goes online.

Specified by:
getOnlineOptions in interface PluginContext
See Also:
PluginContext.getOnlineOptions()

setOnlineOptions

public void setOnlineOptions(TungstenProperties onlineOptions)
Sets online options.

Parameters:
onlineOptions - Tungsten properties containing options from the online command

getMonitor

public ReplicatorMonitor getMonitor()
Returns the monitoring data object.

Specified by:
getMonitor in interface PluginContext

isConsistencyFailureStop

public boolean isConsistencyFailureStop()
True if the replicator should stop on checksum failure.

Specified by:
isConsistencyFailureStop in interface PluginContext
See Also:
PluginContext.isConsistencyFailureStop()

isConsistencyCheckColumnNames

public boolean isConsistencyCheckColumnNames()
Should consistency check be sensitive to column names?

Specified by:
isConsistencyCheckColumnNames in interface PluginContext
See Also:
PluginContext.isConsistencyCheckColumnNames()

isConsistencyCheckColumnTypes

public boolean isConsistencyCheckColumnTypes()
Should consistency check be sensitive to column types?

Specified by:
isConsistencyCheckColumnTypes in interface PluginContext
See Also:
PluginContext.isConsistencyCheckColumnTypes()

isDoChecksum

public boolean isDoChecksum()
Are checksums enabled? If false this overrides any local checksum setting.

Specified by:
isDoChecksum in interface PluginContext
See Also:
PluginContext.isDoChecksum()

getJdbcUrl

public java.lang.String getJdbcUrl(java.lang.String database)
Returns a JDBC URL suitable for login to local data source.

Specified by:
getJdbcUrl in interface PluginContext
See Also:
PluginContext.getJdbcUrl(java.lang.String)

getJdbcUser

public java.lang.String getJdbcUser()
Returns a user for login to local data source.

Specified by:
getJdbcUser in interface PluginContext
See Also:
PluginContext.getJdbcUser()

getJdbcPassword

public java.lang.String getJdbcPassword()
Returns a password suitable for login to local data source.

Specified by:
getJdbcPassword in interface PluginContext
See Also:
PluginContext.getJdbcPassword()

getReplicatorSchemaName

public java.lang.String getReplicatorSchemaName()
Schema name for storing replicator catalogs.

Specified by:
getReplicatorSchemaName in interface PluginContext
See Also:
PluginContext.getReplicatorSchemaName()

getRoleName

public java.lang.String getRoleName()
Returns the role name.

Specified by:
getRoleName in interface PluginContext
See Also:
PluginContext.getRoleName()

getLastOnlineRoleName

public java.lang.String getLastOnlineRoleName()
Returns the role as of the last time the replicator went online or null if the role is not known. When the replicator is in the ONLINE state the is the same as PluginContext.getRoleName(). This value is used to help with recovery when transitioning between states.

Specified by:
getLastOnlineRoleName in interface PluginContext
See Also:
PluginContext.getLastOnlineRoleName()

setLastOnlineRoleName

public void setLastOnlineRoleName(java.lang.String roleName)
                           throws ReplicatorException
Writes the value of the last online role to storage.

Throws:
ReplicatorException

getSourceId

public java.lang.String getSourceId()
Source ID for this replicator.

Specified by:
getSourceId in interface PluginContext
See Also:
PluginContext.getSourceId()

getClusterName

public java.lang.String getClusterName()
Cluster name to which replicator belongs.

Specified by:
getClusterName in interface PluginContext
See Also:
PluginContext.getClusterName()

getServiceName

public java.lang.String getServiceName()
Service name to which replication belongs.

Specified by:
getServiceName in interface PluginContext
See Also:
PluginContext.getServiceName()

isSlave

public boolean isSlave()
Returns true if the replicator role is slave.

Specified by:
isSlave in interface PluginContext
See Also:
PluginContext.isSlave()

isMaster

public boolean isMaster()
Returns true if the replicator role is master.

Specified by:
isMaster in interface PluginContext
See Also:
PluginContext.isMaster()

isAutoEnable

public boolean isAutoEnable()
Returns true if replicator should go on-line automatically.

Specified by:
isAutoEnable in interface PluginContext
See Also:
PluginContext.isAutoEnable()

getStages

public java.util.List<Stage> getStages()
Returns stages in pipeline order.

Specified by:
getStages in interface PluginContext
See Also:
PluginContext.getStages()

getStore

public Store getStore(java.lang.String name)
Returns a named storage component.

Specified by:
getStore in interface PluginContext
See Also:
PluginContext.getStore(java.lang.String)

getStores

public java.util.List<Store> getStores()
Returns all stores.

Specified by:
getStores in interface PluginContext
See Also:
PluginContext.getStores()

getService

public PipelineService getService(java.lang.String name)
Returns a named pipeline service component.

Specified by:
getService in interface PluginContext
See Also:
PluginContext.getService(java.lang.String)

getServices

public java.util.List<PipelineService> getServices()
Returns all pipeline service components.

Specified by:
getServices in interface PluginContext
See Also:
PluginContext.getServices()

getEventDispatcher

public com.continuent.tungsten.fsm.event.EventDispatcher getEventDispatcher()
Returns the event dispatcher for reporting interesting events.

Specified by:
getEventDispatcher in interface PluginContext
See Also:
PluginContext.getEventDispatcher()

isRemoteService

public boolean isRemoteService()
Returns true if the current replication pipeline belongs to a remote data service. If so, applied updates must be logged to ensure correct multi-master behavior.

Specified by:
isRemoteService in interface PluginContext
See Also:
PluginContext.isRemoteService()

getCommittedSeqno

public long getCommittedSeqno()
Returns the minimum safely committed sequence number from the end of the pipeline. This sequence number can be used to free resources such as log files used in upstream stages.

Specified by:
getCommittedSeqno in interface PluginContext
See Also:
PluginContext.getCommittedSeqno()

waitForCommitted

public java.util.concurrent.Future<ReplDBMSHeader> waitForCommitted(long seqno)
                                                             throws java.lang.InterruptedException
Returns a future to allow clients to wait until the pipeline has safely committed the requested seqno.

Specified by:
waitForCommitted in interface PluginContext
Throws:
java.lang.InterruptedException
See Also:
PluginContext.waitForCommitted(long)

getApplierFailurePolicy

public FailurePolicy getApplierFailurePolicy()
Returns the applier failure policy.

Specified by:
getApplierFailurePolicy in interface PluginContext
See Also:
PluginContext.getApplierFailurePolicy()

getExtractorFailurePolicy

public FailurePolicy getExtractorFailurePolicy()
Returns the extractorFailurePolicy value.

Specified by:
getExtractorFailurePolicy in interface PluginContext
See Also:
PluginContext.getExtractorFailurePolicy()

getApplierFailurePolicyOn0RowUpdates

public FailurePolicy getApplierFailurePolicyOn0RowUpdates()
Returns the applierFailurePolicyOn0Updates value.

Returns:
Returns the applierFailurePolicyOn0Updates.

getTungstenTableType

public java.lang.String getTungstenTableType()
Returns the table type used for Tungsten catalog databases. This value is meaningful only for MySQL databases and related data warehouse offspring like InfiniDB and InfoBright.

Specified by:
getTungstenTableType in interface PluginContext
See Also:
PluginContext.getTungstenTableType()

getChannels

public int getChannels()
Returns the number of channels in the tail stage of the pipeline or -1 if pipeline is not active.

Specified by:
getChannels in interface PluginContext
See Also:
PluginContext.getChannels()

getExtension

public ReplicatorPlugin getExtension(java.lang.String name)
Returns the named extension or null if the extension does not exist.

Specified by:
getExtension in interface PluginContext
See Also:
PluginContext.getExtension(java.lang.String)

getExtensionNames

public java.util.List<java.lang.String> getExtensionNames()
Returns the current list of extensions.

Specified by:
getExtensionNames in interface PluginContext
See Also:
PluginContext.getExtensionNames()

registerMBean

public void registerMBean(java.lang.Object mbean,
                          java.lang.Class<?> mbeanClass,
                          java.lang.String name)
Registers a JMX MBean from a lower-level component.

Specified by:
registerMBean in interface PluginContext
See Also:
java.lang.String)

configurePlugin

public static void configurePlugin(ReplicatorPlugin plugin,
                                   PluginContext context)
                            throws ReplicatorException
Call configure method on a plugin class.

Throws:
ReplicatorException

preparePlugin

public static void preparePlugin(ReplicatorPlugin plugin,
                                 PluginContext context)
                          throws ReplicatorException
Call prepare method on a plugin class.

Throws:
ReplicatorException

releasePlugin

public static void releasePlugin(ReplicatorPlugin plugin,
                                 PluginContext context)
Call release method on a plugin class, warning on errors.


logReplicatorUpdates

public boolean logReplicatorUpdates()
Returns true if we want to log replicator updates. This is equivalent to MySQL's log_slave_updates option.

Specified by:
logReplicatorUpdates in interface PluginContext
See Also:
PluginContext.logReplicatorUpdates()

isPrivilegedSlaveUpdate

public boolean isPrivilegedSlaveUpdate()
Returns true if the JDBC login for slave apply is a superuser.

Specified by:
isPrivilegedSlaveUpdate in interface PluginContext
See Also:
PluginContext.isPrivilegedSlaveUpdate()

nativeSlaveTakeover

public boolean nativeSlaveTakeover()
Return true if operating in native slave takeover mode.

Specified by:
nativeSlaveTakeover in interface PluginContext
See Also:
PluginContext.nativeSlaveTakeover()

setPipelineSource

public void setPipelineSource(java.lang.String source)
Registers the transaction source (if any) for the head of the current pipeline. Should be used by head stage only to avoid confusion. For best usability, head stages should set this as soon as it is known.

Specified by:
setPipelineSource in interface PluginContext
Parameters:
source - Typical value is a URI of some kind
See Also:
PluginContext.setPipelineSource(java.lang.String)

getPipelineSource

public java.lang.String getPipelineSource()
Returns the transaction source of the head stage in the pipeline.

Specified by:
getPipelineSource in interface PluginContext
See Also:
PluginContext.setPipelineSource(java.lang.String)