use of com.airbnb.spinaltap.common.validator.MutationOrderValidator in project SpinalTap by airbnb.
the class MysqlSource method create.
public static Source create(String name, String host, int port, int socketTimeoutInSeconds, String user, String password, long serverId, List<String> tableNames, Repository<SourceState> stateRepo, Repository<Collection<SourceState>> stateHistoryRepo, BinlogFilePos initialBinlogPosition, boolean isSchemaVersionEnabled, MysqlSchemaStoreConfiguration schemaStoreConfig, MysqlSourceMetrics metrics, long leaderEpoch) {
DBI mysqlDBI = MysqlSchemaUtil.createMysqlDBI(host, port, user, password, null);
BinaryLogClient client = new BinaryLogClient(host, port, user, password);
// Set different server_id for staging and production environment.
// Conflict occurs when more than one client of same server_id connect to a MySQL server.
client.setServerId(serverId);
DataSource dataSource = new DataSource(host, port, name);
StateRepository stateRepository = new StateRepository(name, stateRepo, metrics);
StateHistory stateHistory = new StateHistory(name, stateHistoryRepo, metrics);
LatestMysqlSchemaStore schemaReader = new LatestMysqlSchemaStore(name, mysqlDBI, metrics);
SchemaStore<MysqlTableSchema> schemaStore;
SchemaTracker schemaTracker;
if (isSchemaVersionEnabled) {
DBI schemaStoreDBI = MysqlSchemaUtil.createMysqlDBI(schemaStoreConfig.getHost(), schemaStoreConfig.getPort(), user, password, schemaStoreConfig.getDatabase());
MysqlSchemaStore mysqlSchemaStore = new MysqlSchemaStore(name, schemaStoreDBI, schemaStoreConfig.getArchiveDatabase(), metrics);
DBI schemaDatabaseDBI = MysqlSchemaUtil.createMysqlDBI(schemaStoreConfig.getHost(), schemaStoreConfig.getPort(), user, password, null);
MysqlSchemaDatabase schemaDatabase = new MysqlSchemaDatabase(name, schemaDatabaseDBI, metrics);
if (!mysqlSchemaStore.isCreated()) {
MysqlSchemaStoreManager schemaStoreManager = new MysqlSchemaStoreManager(name, schemaReader, mysqlSchemaStore, schemaDatabase);
schemaStoreManager.bootstrapAll();
}
schemaStore = new CachedMysqlSchemaStore(name, mysqlSchemaStore, metrics);
schemaTracker = new MysqlSchemaTracker(schemaStore, schemaDatabase);
} else {
schemaStore = schemaReader;
schemaTracker = (event) -> {
};
}
TableCache tableCache = new TableCache(schemaStore);
MysqlSource source = new MysqlSource(name, dataSource, client, new HashSet<>(tableNames), tableCache, stateRepository, stateHistory, initialBinlogPosition, schemaTracker, metrics, new AtomicLong(leaderEpoch), socketTimeoutInSeconds);
source.addEventValidator(new EventOrderValidator(metrics::outOfOrder));
source.addMutationValidator(new MutationOrderValidator(metrics::outOfOrder));
source.addMutationValidator(new MutationSchemaValidator(metrics::invalidSchema));
return source;
}
Aggregations