private void initFirstRun(Connection connection) throws SQLException, IOException, SchemaSyncError { LOGGER.info("Maxwell is capturing initial schema"); SchemaCapturer capturer = new SchemaCapturer(connection); this.schema = capturer.capture(); BinlogPosition pos = BinlogPosition.capture(connection); SchemaStore store = new SchemaStore(connection, this.maxwellContext.getServerID(), this.schema, pos); store.save(); this.maxwellContext.setPosition(pos); }
@Override public void start(Map<String, String> props) { try { OffsetStorageReader offsetStorageReader = this.context.offsetStorageReader(); Map<String, Object> offsetFromCopycat = offsetStorageReader.offset(sourcePartition()); // XXX Need an API to pass values to Maxwell. For now, do it the dumb // way. String[] argv = new String[] { "--user="******"--password="******"--host=" + props.get(MySqlSourceConnector.HOST_CONFIG), "--port=" + props.get(MySqlSourceConnector.PORT_CONFIG) }; this.config = new MaxwellConfig(argv); if (this.config.log_level != null) MaxwellLogging.setLevel(this.config.log_level); this.maxwellContext = new MaxwellContext(this.config); BinlogPosition startAt; try (Connection connection = this.maxwellContext.getConnectionPool().getConnection()) { MaxwellMysqlStatus.ensureMysqlState(connection); SchemaStore.ensureMaxwellSchema(connection); SchemaStore.upgradeSchemaStoreSchema(connection); SchemaStore.handleMasterChange(connection, maxwellContext.getServerID()); if (offsetFromCopycat != null) { System.out.println("have copycat offsets! " + offsetFromCopycat); startAt = new BinlogPosition( (long) offsetFromCopycat.get(POSITION_FIELD), (String) offsetFromCopycat.get(FILENAME_FIELD)); LOGGER.info("Maxwell is booting, starting at " + startAt); SchemaStore store = SchemaStore.restore(connection, this.maxwellContext.getServerID(), startAt); this.schema = store.getSchema(); } else { System.out.println("no copycat offsets!"); LOGGER.info("Maxwell is capturing initial schema"); SchemaCapturer capturer = new SchemaCapturer(connection); this.schema = capturer.capture(); startAt = BinlogPosition.capture(connection); SchemaStore store = new SchemaStore(connection, this.maxwellContext.getServerID(), this.schema, startAt); store.save(); } } catch (SQLException e) { LOGGER.error("Failed to connect to mysql server @ " + this.config.getConnectionURI()); LOGGER.error(e.getLocalizedMessage()); throw e; } // TODO Auto-generated method stub this.replicator = new MaxwellReplicator(this.schema, null /* producer */, this.maxwellContext, startAt); this.maxwellContext.start(); this.replicator.beforeStart(); // starts open replicator } catch (Exception e) { throw new ConnectException("Error Initializing Maxwell", e); } }