Search in sources :

Example 1 with MutationSchemaValidator

use of com.airbnb.spinaltap.mysql.validator.MutationSchemaValidator 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;
}
Also used : MysqlSchemaStoreManager(com.airbnb.spinaltap.mysql.schema.MysqlSchemaStoreManager) MysqlTableSchema(com.airbnb.spinaltap.mysql.schema.MysqlTableSchema) MysqlSchemaTracker(com.airbnb.spinaltap.mysql.schema.MysqlSchemaTracker) SchemaTracker(com.airbnb.spinaltap.mysql.schema.SchemaTracker) DBI(org.skife.jdbi.v2.DBI) MutationSchemaValidator(com.airbnb.spinaltap.mysql.validator.MutationSchemaValidator) EventOrderValidator(com.airbnb.spinaltap.mysql.validator.EventOrderValidator) BinaryLogClient(com.github.shyiko.mysql.binlog.BinaryLogClient) MysqlSchemaTracker(com.airbnb.spinaltap.mysql.schema.MysqlSchemaTracker) CachedMysqlSchemaStore(com.airbnb.spinaltap.mysql.schema.CachedMysqlSchemaStore) MutationOrderValidator(com.airbnb.spinaltap.common.validator.MutationOrderValidator) AtomicLong(java.util.concurrent.atomic.AtomicLong) MysqlSchemaDatabase(com.airbnb.spinaltap.mysql.schema.MysqlSchemaDatabase) LatestMysqlSchemaStore(com.airbnb.spinaltap.mysql.schema.LatestMysqlSchemaStore) CachedMysqlSchemaStore(com.airbnb.spinaltap.mysql.schema.CachedMysqlSchemaStore) MysqlSchemaStore(com.airbnb.spinaltap.mysql.schema.MysqlSchemaStore) LatestMysqlSchemaStore(com.airbnb.spinaltap.mysql.schema.LatestMysqlSchemaStore)

Aggregations

MutationOrderValidator (com.airbnb.spinaltap.common.validator.MutationOrderValidator)1 CachedMysqlSchemaStore (com.airbnb.spinaltap.mysql.schema.CachedMysqlSchemaStore)1 LatestMysqlSchemaStore (com.airbnb.spinaltap.mysql.schema.LatestMysqlSchemaStore)1 MysqlSchemaDatabase (com.airbnb.spinaltap.mysql.schema.MysqlSchemaDatabase)1 MysqlSchemaStore (com.airbnb.spinaltap.mysql.schema.MysqlSchemaStore)1 MysqlSchemaStoreManager (com.airbnb.spinaltap.mysql.schema.MysqlSchemaStoreManager)1 MysqlSchemaTracker (com.airbnb.spinaltap.mysql.schema.MysqlSchemaTracker)1 MysqlTableSchema (com.airbnb.spinaltap.mysql.schema.MysqlTableSchema)1 SchemaTracker (com.airbnb.spinaltap.mysql.schema.SchemaTracker)1 EventOrderValidator (com.airbnb.spinaltap.mysql.validator.EventOrderValidator)1 MutationSchemaValidator (com.airbnb.spinaltap.mysql.validator.MutationSchemaValidator)1 BinaryLogClient (com.github.shyiko.mysql.binlog.BinaryLogClient)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 DBI (org.skife.jdbi.v2.DBI)1