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.HealthCheckRegistryhealthCheckRegistryContains Maxwell health checkscom.codahale.metrics.MetricRegistrymetricRegistryContains 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 voidaddTask(StoppableTask task)Add a task (usually a thread) that will be stopped upon shutdownBootstrapControllergetBootstrapController(Long currentSchemaID)get or start aBootstrapControllerCaseSensitivitygetCaseSensitivity()Get the replication connection's case sensitivity settingsMaxwellConfiggetConfig()Get Maxwell configuration used in this contextMaxwellDiagnosticContextgetDiagnosticContext()Get the context for maxwell diagnosticsExceptiongetError()Get the Exception that triggered shutdownFiltergetFilter()get the current active filterHeartbeatNotifiergetHeartbeatNotifier()Get the heartbeat notifier object, which can be asked to broadcast heartbeatsPositiongetInitialPosition()Retrieve Maxwell's starting position from the metadata databaseConnectiongetMaxwellConnection()get a connection from the maxwell poolConnectionPoolgetMaxwellConnectionPool()Get a connection from the maxwell (metadata) poolMetricsgetMetrics()Get the current metrics registryMysqlVersiongetMysqlVersion()Get the replication connection's mysql versionPositiongetOtherClientPosition()Finds the most recent position any client has reached on the serverPositiongetPosition()Get the last stored binlog positionMysqlPositionStoregetPositionStore()Get the position store service objectPositionStoreThreadgetPositionStoreThread()Get or spawn a thread that persists the current position into the metadata database.AbstractProducergetProducer()get or build anAbstractProducerbased on settings inconfigConnectiongetRawMaxwellConnection()get a database-less connection from the maxwell pool Used to create the maxwell schema.RecoveryInfogetRecoveryInfo()Build aRecoveryInfoobject, used in non-GTID master failoverbooleangetReplayMode()Get the replayMode flagConnectiongetReplicationConnection()Get the a connection from the replication poolConnectionPoolgetReplicationConnectionPool()Get the replication poolConnectionPoolgetSchemaConnectionPool()Get a connection from the schema poolLonggetServerID()Get the replication connection's server idlongheartbeat()Manually trigger a heartbeat to be sentbooleanisMariaDB()Is the replication host running MariaDB?voidrunBootstrapNow()only used in test code.voidsetPosition(Position position)Set Maxwell's next binlog positionvoidsetPosition(RowMap r)If the passedRowMapis a transaction-commit, update maxwell's positionvoidsetReplicator(Replicator replicator)Set the current binlog replicatorvoidstart()Start the HTTP server and position store threadvoidstartSchemaCompactor()get or start aMysqlSchemaCompactorThreadterminate()Begin the maxwell shutdown process.Threadterminate(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 IOExceptionStart the HTTP server and position store thread- Throws:
IOException- if the HTTP server can't be started
-
heartbeat
public long heartbeat() throws ExceptionManually 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 aRecoveryInfoobject, 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 passedRowMapis 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 anAbstractProducerbased 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 SQLExceptionget 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
-
-