public Connection getMaxwellConnection() throws SQLException { return this.maxwellConnectionPool.getConnection(); }
private ConnectionPool getConnectionPool(MaxwellBootstrapUtilityConfig config) { String name = "MaxwellBootstrapConnectionPool"; int maxPool = 10; int maxSize = 0; int idleTimeout = 10; String connectionURI = config.getConnectionURI(); return new ConnectionPool(name, maxPool, maxSize, idleTimeout, connectionURI, config.mysql.user, config.mysql.password); }
private void shutdown(AtomicBoolean complete) { try { taskManager.stop(this.error); this.replicationConnectionPool.release(); this.maxwellConnectionPool.release(); this.rawMaxwellConnectionPool.release(); complete.set(true); } catch (Exception e) { LOGGER.error("Exception occurred during shutdown:", e); } }
public Connection getReplicationConnection() throws SQLException { return this.replicationConnectionPool.getConnection(); }
public Connection getRawMaxwellConnection() throws SQLException { return rawMaxwellConnectionPool.getConnection(); }
protected List<RecoveryInfo> getAllRecoveryInfos() throws SQLException { try ( Connection c = connectionPool.getConnection() ) { return getAllRecoveryInfos(c); } }
/** * grabs a position from a different server_id */ public RecoveryInfo getRecoveryInfo(MaxwellConfig config) throws SQLException { try ( Connection c = connectionPool.getConnection() ) { return getRecoveryInfo(config, c); } }
public synchronized void heartbeat(long heartbeatValue) throws Exception { try ( Connection c = connectionPool.getConnection() ) { heartbeat(c, heartbeatValue); } }
public Position get() throws SQLException { try ( Connection c = connectionPool.getConnection() ) { PreparedStatement s = c.prepareStatement("SELECT * from `positions` where server_id = ? and client_id = ?"); s.setLong(1, serverID); s.setString(2, clientID); return positionFromResultSet(s.executeQuery()); } }
public Position getLatestFromAnyClient() throws SQLException { try ( Connection c = connectionPool.getConnection() ) { PreparedStatement s = c.prepareStatement("SELECT * from `positions` where server_id = ? ORDER BY last_heartbeat_read desc limit 1"); s.setLong(1, serverID); return positionFromResultSet(s.executeQuery()); } }
private Long saveSchema(Schema updatedSchema, List<ResolvedSchemaChange> changes, Position p) throws SQLException { if ( readOnly ) return null; try (Connection c = maxwellConnectionPool.getConnection()) { this.savedSchema = this.savedSchema.createDerivedSchema(updatedSchema, p, changes); return this.savedSchema.save(c); } }
private void probePool( ConnectionPool pool, String uri ) throws SQLException { try (Connection c = pool.getConnection()) { c.createStatement().execute("SELECT 1"); } catch (SQLException e) { LOGGER.error("Could not connect to " + uri + ": " + e.getLocalizedMessage()); throw (e); } }
protected Schema captureSchema() throws SQLException { try(Connection connection = schemaConnectionPool.getConnection()) { LOGGER.info("Maxwell is capturing initial schema"); SchemaCapturer capturer = new SchemaCapturer(connection, caseSensitivity); return capturer.capture(); } }
public void cleanupOldRecoveryInfos() throws SQLException { List<RecoveryInfo> allRecoveryInfos = getAllRecoveryInfos(); if (allRecoveryInfos.size() > 1) { LOGGER.warn("Multiple recovery infos found: " + allRecoveryInfos); LOGGER.info("Removing entries where server_id != " + serverID); try (Connection c = connectionPool.getConnection()) { PreparedStatement s = c.prepareStatement( "DELETE FROM `positions` WHERE server_id <> ? AND client_id = ?" ); s.setLong(1, serverID); s.setString(2, clientID); s.execute(); } } } }
/** * fetch a list of binlog positions representing the start of each binlog file * * @return a list of binlog positions to attempt recovery at * */ private List<BinlogPosition> getBinlogInfo() throws SQLException { ArrayList<BinlogPosition> list = new ArrayList<>(); try ( Connection c = replicationConnectionPool.getConnection() ) { ResultSet rs = c.createStatement().executeQuery("SHOW BINARY LOGS"); while ( rs.next() ) { list.add(BinlogPosition.at(4, rs.getString("Log_name"))); } } return list; } }
public MysqlSavedSchema captureAndSaveSchema() throws SQLException { try ( Connection conn = maxwellConnectionPool.getConnection() ) { MysqlSavedSchema savedSchema = new MysqlSavedSchema(serverID, caseSensitivity, captureSchema(), initialPosition); if (!readOnly) if (conn.isValid(30)) { savedSchema.save(conn); } else { // The capture time might be long and the conn connection might be closed already. Consulting the pool // again for a new connection Connection newConn = maxwellConnectionPool.getConnection(); savedSchema.save(newConn); newConn.close(); } return savedSchema; } }
@Override public Schema getSchema() throws SchemaStoreException { if ( maxwellOnlySchema != null ) return maxwellOnlySchema; try(Connection conn = replicationConnectionPool.getConnection() ) { SchemaCapturer capturer = new SchemaCapturer(conn, caseSensitivity, maxwellDatabaseName); maxwellOnlySchema = capturer.capture(); } catch (SQLException e) { throw new SchemaStoreException(e); } return maxwellOnlySchema; }
public static MysqlSavedSchema restoreFromSchemaID(MysqlSavedSchema savedSchema, MaxwellContext context) throws SQLException, InvalidSchemaError { try ( Connection conn = context.getMaxwellConnectionPool().getConnection() ) { Long schemaID = savedSchema.getSchemaID(); if (schemaID == null) return null; savedSchema.restoreFromSchemaID(conn, schemaID); return savedSchema; } }
public void clone(Long serverID, Position position) throws SchemaStoreException { List<ResolvedSchemaChange> empty = Collections.emptyList(); try (Connection c = maxwellConnectionPool.getConnection()) { getSchema(); MysqlSavedSchema cloned = new MysqlSavedSchema(serverID, caseSensitivity, getSchema(), position, savedSchema.getSchemaID(), empty); Long schemaId = cloned.save(c); LOGGER.info("clone schema @" + position + " based on id " + savedSchema.getSchemaID() + ", new schema id is " + schemaId); } catch ( SQLException e ) { throw new SchemaStoreException(e); } } }
public static MysqlSavedSchema restore( ConnectionPool pool, Long serverID, CaseSensitivity caseSensitivity, Position targetPosition ) throws SQLException, InvalidSchemaError { try ( Connection conn = pool.getConnection() ) { Long schemaID = findSchema(conn, targetPosition, serverID); if (schemaID == null) return null; MysqlSavedSchema savedSchema = new MysqlSavedSchema(serverID, caseSensitivity); savedSchema.restoreFromSchemaID(conn, schemaID); savedSchema.handleVersionUpgrades(conn); return savedSchema; } }