use of com.airbnb.spinaltap.mysql.validator.EventOrderValidator 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;
}
use of com.airbnb.spinaltap.mysql.validator.EventOrderValidator in project SpinalTap by airbnb.
the class EventOrderValidatorTest method testReset.
@Test
public void testReset() throws Exception {
List<SourceEvent> unorderedEvents = Lists.newArrayList();
when(firstEvent.getOffset()).thenReturn(1L);
when(secondEvent.getOffset()).thenReturn(2L);
EventOrderValidator validator = new EventOrderValidator(unorderedEvents::add);
validator.validate(firstEvent);
validator.validate(secondEvent);
validator.reset();
validator.validate(firstEvent);
validator.validate(secondEvent);
assertTrue(unorderedEvents.isEmpty());
}
use of com.airbnb.spinaltap.mysql.validator.EventOrderValidator in project SpinalTap by airbnb.
the class EventOrderValidatorTest method testEventInOrder.
@Test
public void testEventInOrder() throws Exception {
List<SourceEvent> unorderedEvents = Lists.newArrayList();
when(firstEvent.getOffset()).thenReturn(1L);
when(secondEvent.getOffset()).thenReturn(2L);
EventOrderValidator validator = new EventOrderValidator(unorderedEvents::add);
validator.validate(firstEvent);
validator.validate(secondEvent);
assertTrue(unorderedEvents.isEmpty());
}
use of com.airbnb.spinaltap.mysql.validator.EventOrderValidator in project SpinalTap by airbnb.
the class EventOrderValidatorTest method testEventOutOfOrder.
@Test
public void testEventOutOfOrder() throws Exception {
List<SourceEvent> unorderedEvents = Lists.newArrayList();
when(firstEvent.getOffset()).thenReturn(2L);
when(secondEvent.getOffset()).thenReturn(1L);
EventOrderValidator validator = new EventOrderValidator(unorderedEvents::add);
validator.validate(firstEvent);
validator.validate(secondEvent);
assertEquals(Collections.singletonList(secondEvent), unorderedEvents);
}
Aggregations