Package com.zendesk.maxwell
Class MaxwellContext
- java.lang.Object
-
- com.zendesk.maxwell.MaxwellContext
-
public class MaxwellContext extends Object
Class containing runtime state
-
-
Field Summary
Fields Modifier and Type Field Description com.codahale.metrics.health.HealthCheckRegistry
healthCheckRegistry
Contains Maxwell health checkscom.codahale.metrics.MetricRegistry
metricRegistry
Contains various Maxwell metrics
-
Constructor Summary
Constructors Constructor Description MaxwellContext(MaxwellConfig config)
Create a runtime context from a configuration object
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTask(StoppableTask task)
Add a task (usually a thread) that will be stopped upon shutdownBootstrapController
getBootstrapController(Long currentSchemaID)
get or start aBootstrapController
CaseSensitivity
getCaseSensitivity()
Get the replication connection's case sensitivity settingsMaxwellConfig
getConfig()
Get Maxwell configuration used in this contextMaxwellDiagnosticContext
getDiagnosticContext()
Get the context for maxwell diagnosticsException
getError()
Get the Exception that triggered shutdownFilter
getFilter()
get the current active filterHeartbeatNotifier
getHeartbeatNotifier()
Get the heartbeat notifier object, which can be asked to broadcast heartbeatsPosition
getInitialPosition()
Retrieve Maxwell's starting position from the metadata databaseConnection
getMaxwellConnection()
get a connection from the maxwell poolConnectionPool
getMaxwellConnectionPool()
Get a connection from the maxwell (metadata) poolMetrics
getMetrics()
Get the current metrics registryMysqlVersion
getMysqlVersion()
Get the replication connection's mysql versionPosition
getOtherClientPosition()
Finds the most recent position any client has reached on the serverPosition
getPosition()
Get the last stored binlog positionMysqlPositionStore
getPositionStore()
Get the position store service objectPositionStoreThread
getPositionStoreThread()
Get or spawn a thread that persists the current position into the metadata database.AbstractProducer
getProducer()
get or build anAbstractProducer
based on settings inconfig
Connection
getRawMaxwellConnection()
get a database-less connection from the maxwell pool Used to create the maxwell schema.RecoveryInfo
getRecoveryInfo()
Build aRecoveryInfo
object, used in non-GTID master failoverboolean
getReplayMode()
Get the replayMode flagConnection
getReplicationConnection()
Get the a connection from the replication poolConnectionPool
getReplicationConnectionPool()
Get the replication poolConnectionPool
getSchemaConnectionPool()
Get a connection from the schema poolLong
getServerID()
Get the replication connection's server idlong
heartbeat()
Manually trigger a heartbeat to be sentboolean
isMariaDB()
Is the replication host running MariaDB?void
runBootstrapNow()
only used in test code.void
setPosition(Position position)
Set Maxwell's next binlog positionvoid
setPosition(RowMap r)
If the passedRowMap
is a transaction-commit, update maxwell's positionvoid
setReplicator(Replicator replicator)
Set the current binlog replicatorvoid
start()
Start the HTTP server and position store threadvoid
startSchemaCompactor()
get or start aMysqlSchemaCompactor
Thread
terminate()
Begin the maxwell shutdown process.Thread
terminate(Exception error)
Begin the Maxwell shutdown process
-
-
-
Constructor Detail
-
MaxwellContext
public MaxwellContext(MaxwellConfig config) throws SQLException, URISyntaxException
Create a runtime context from a configuration object- Parameters:
config
- Maxwell configuration- Throws:
SQLException
- if there's issues connecting to the databaseURISyntaxException
- if there's issues building database URIs
-
-
Method Detail
-
getConfig
public MaxwellConfig getConfig()
Get Maxwell configuration used in this context- Returns:
- the Maxwell configuration
-
getReplicationConnection
public Connection getReplicationConnection() throws SQLException
Get the a connection from the replication pool- Returns:
- a connection to the replication pool
- Throws:
SQLException
- if we can't connect
-
getReplicationConnectionPool
public ConnectionPool getReplicationConnectionPool()
Get the replication pool- Returns:
- the replication (connection to replicate from) connection pool
-
getMaxwellConnectionPool
public ConnectionPool getMaxwellConnectionPool()
Get a connection from the maxwell (metadata) pool- Returns:
- the maxwell (connection to store metadata in) connection pool
-
getSchemaConnectionPool
public ConnectionPool getSchemaConnectionPool()
Get a connection from the schema pool- Returns:
- the schema (connection to capture from) connection pool
-
getMaxwellConnection
public Connection getMaxwellConnection() throws SQLException
get a connection from the maxwell pool- Returns:
- a connection from the maxwell pool
- Throws:
SQLException
- if we can't connect
-
getRawMaxwellConnection
public Connection getRawMaxwellConnection() throws SQLException
get a database-less connection from the maxwell pool Used to create the maxwell schema.- Returns:
- a connection to the maxwell pool, without a database name specific
- Throws:
SQLException
- if we can't connect
-
start
public void start() throws IOException
Start the HTTP server and position store thread- Throws:
IOException
- if the HTTP server can't be started
-
heartbeat
public long heartbeat() throws Exception
Manually trigger a heartbeat to be sent- Returns:
- Timestamp of the heartbeeat
- Throws:
Exception
- If we can't send a heartbeat
-
addTask
public void addTask(StoppableTask task)
Add a task (usually a thread) that will be stopped upon shutdown- Parameters:
task
- The task
-
terminate
public Thread terminate()
Begin the maxwell shutdown process.- Shuts down the
replicator
- Calls
TaskManager.stop(java.lang.Exception)
- Stops metrics collection
- Destroys all database pools
- Returns:
- A thread that will complete shutdown.
- Shuts down the
-
terminate
public Thread terminate(Exception error)
Begin the Maxwell shutdown process- Parameters:
error
- An exception that caused the shutdown, or null- Returns:
- A thread that will complete shutdown.
- See Also:
terminate()
-
getError
public Exception getError()
Get the Exception that triggered shutdown- Returns:
- An error that caused maxwell to shutdown
-
getPositionStoreThread
public PositionStoreThread getPositionStoreThread()
Get or spawn a thread that persists the current position into the metadata database.- Returns:
- Position store thread
-
getInitialPosition
public Position getInitialPosition() throws SQLException
Retrieve Maxwell's starting position from the metadata database- Returns:
- The initial binlog position
- Throws:
SQLException
- If the position can't be retrieved from the database
-
getOtherClientPosition
public Position getOtherClientPosition() throws SQLException
Finds the most recent position any client has reached on the server- Returns:
- A binlog position or NULL
- Throws:
SQLException
- If an error is encountered fetching the position- See Also:
MysqlPositionStore.getLatestFromAnyClient()
-
getRecoveryInfo
public RecoveryInfo getRecoveryInfo() throws SQLException
Build aRecoveryInfo
object, used in non-GTID master failover- Returns:
- Information used to recover a master position, or NULL
- Throws:
SQLException
- If we have database issues- See Also:
MysqlPositionStore.getRecoveryInfo(MaxwellConfig)
-
setPosition
public void setPosition(RowMap r)
If the passedRowMap
is a transaction-commit, update maxwell's position- Parameters:
r
- A processed Rowmap
-
setPosition
public void setPosition(Position position)
Set Maxwell's next binlog position- Parameters:
position
- The new position
-
getPosition
public Position getPosition() throws SQLException
Get the last stored binlog position- Returns:
- The last binlog position set
- Throws:
SQLException
- If we have database issues
-
getPositionStore
public MysqlPositionStore getPositionStore()
Get the position store service object- Returns:
- The mysql position store
-
getServerID
public Long getServerID() throws SQLException
Get the replication connection's server id- Returns:
- a server id
- Throws:
SQLException
- if we have connection issues
-
getMysqlVersion
public MysqlVersion getMysqlVersion() throws SQLException
Get the replication connection's mysql version- Returns:
- The mysql version
- Throws:
SQLException
- if we have connection issues
-
getCaseSensitivity
public CaseSensitivity getCaseSensitivity() throws SQLException
Get the replication connection's case sensitivity settings- Returns:
- case sensitivity settings
- Throws:
SQLException
- if we have connection issues
-
getProducer
public AbstractProducer getProducer() throws IOException
get or build anAbstractProducer
based on settings inconfig
- Returns:
- A producer
- Throws:
IOException
- if there's trouble instantiating the producer
-
runBootstrapNow
public void runBootstrapNow()
only used in test code. interrupt the bootstrap thread to quicken tests.
-
getBootstrapController
public BootstrapController getBootstrapController(Long currentSchemaID) throws IOException
get or start aBootstrapController
- Parameters:
currentSchemaID
- the currently active mysql schema- Returns:
- a bootstrap controller
- Throws:
IOException
- if the bootstrap thread can't be started
-
startSchemaCompactor
public void startSchemaCompactor() throws SQLException
get or start aMysqlSchemaCompactor
- Throws:
SQLException
- if we have connection issues
-
getFilter
public Filter getFilter()
get the current active filter- Returns:
- the currently active Filter
-
getReplayMode
public boolean getReplayMode()
Get the replayMode flag- Returns:
- whether we are in "replay mode" (--replay)
-
setReplicator
public void setReplicator(Replicator replicator)
Set the current binlog replicator- Parameters:
replicator
- the replicator
-
getMetrics
public Metrics getMetrics()
Get the current metrics registry- Returns:
- the current metrics registry
-
getHeartbeatNotifier
public HeartbeatNotifier getHeartbeatNotifier()
Get the heartbeat notifier object, which can be asked to broadcast heartbeats- Returns:
- a heartbeat notifier
-
getDiagnosticContext
public MaxwellDiagnosticContext getDiagnosticContext()
Get the context for maxwell diagnostics- Returns:
- the maxwell diagnostic context
-
isMariaDB
public boolean isMariaDB()
Is the replication host running MariaDB?- Returns:
- mariadbornot
-
-