use of com.linkedin.databus.bootstrap.utils.BootstrapAuditTableReader.ResultSetEntry in project databus by linkedin.
the class BootstrapAuditMain method main.
/**
* @param args
*/
public static void main(String[] args) throws Exception {
BootstrapSeederMain.init(args);
BootstrapSeederMain.StaticConfig staticConfig = BootstrapSeederMain.getStaticConfig();
int interval = staticConfig.getController().getCommitInterval();
int sourceChunkSize = staticConfig.getController().getNumRowsPerQuery();
List<OracleTriggerMonitoredSourceInfo> sources = BootstrapSeederMain.getSources();
BootstrapDBSeeder seeder = BootstrapSeederMain.getSeeder();
BootstrapSrcDBEventReader seedController = BootstrapSeederMain.getReader();
Map<String, String> pKeyNameMap = seedController.getpKeyNameMap();
Map<String, DbusEventKey.KeyType> pKeyTypeMap = seedController.getpKeyTypeMap();
for (OracleTriggerMonitoredSourceInfo source : sources) {
short srcId = source.getSourceId();
new ConcurrentHashMap<Long, ResultSetEntry>();
OracleTableReader oracleReader = null;
MySQLTableReader mySQLReader = null;
try {
SchemaRegistryService schemaRegistry = FileSystemSchemaRegistryService.build(staticConfig.getSchemaRegistry().getFileSystem());
Map<Short, String> schemaSet = schemaRegistry.fetchAllSchemaVersionsBySourceName(source.getSourceName());
VersionedSchemaSet vSchemaSet = new VersionedSchemaSet();
Iterator<Map.Entry<Short, String>> it = schemaSet.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Short, String> pairs = it.next();
Schema s = Schema.parse(pairs.getValue());
VersionedSchema vs = new VersionedSchema(s.getFullName(), pairs.getKey(), s, null);
vSchemaSet.add(vs);
}
/* Try and identify the schema key */
VersionedSchema vschema = schemaRegistry.fetchLatestVersionedSchemaBySourceName(source.getSourceName());
Schema schema = Schema.parse(vschema.getSchema().toString());
LOG.info("Schema =" + vschema.getSchema() + "version=" + vschema.getVersion() + " name=" + vschema.getSchemaBaseName());
/* Determine type of field txn */
Field txnFieldType = schema.getField("txn");
if (txnFieldType == null) {
throw new Exception("Unable to find field called 'txn'. Cannot proceeed\n");
}
Type txnType = SchemaHelper.getAnyType(txnFieldType);
/*
* Determine primary key of schema. This is assumed to be invariant
* across versions
*/
String keyOverrideName = SchemaHelper.getMetaField(schema, "pk");
String keyColumnName = "key";
if (null != keyOverrideName) {
keyColumnName = keyOverrideName;
}
Field pkeyField = schema.getField(keyColumnName);
if (null == pkeyField) {
keyColumnName = "id";
pkeyField = schema.getField("id");
}
if (null == pkeyField) {
throw new Exception("Unable to get the primary key for schema. Schema is :" + schema);
}
DbusEventAvroDecoder decoder = new DbusEventAvroDecoder(vSchemaSet);
BootstrapAuditTester auditor = new BootstrapAuditTester(schema, BootstrapSrcDBEventReader.getTableName(source));
List<BootstrapAuditTester> auditors = new ArrayList<BootstrapAuditTester>();
auditors.add(auditor);
oracleReader = new OracleTableReader(BootstrapSeederMain.getDataStore().getConnection(), BootstrapSrcDBEventReader.getTableName(source), pkeyField, SchemaHelper.getMetaField(pkeyField, "dbFieldName"), SchemaHelper.getAnyType(pkeyField), sourceChunkSize, seedController.getPKIndex(source), seedController.getQueryHint(source));
mySQLReader = new MySQLTableReader(seeder.getConnection(), // THis is the primary
seeder.getTableName(srcId), // THis is the primary
pkeyField, // THis is the primary
"id", // bootstrapDB
SchemaHelper.getAnyType(pkeyField), interval);
double samplePct = BootstrapSeederMain.getValidationSamplePct();
TableComparator comparator = new TableComparator(oracleReader, mySQLReader, auditor, decoder, interval, pKeyNameMap.get(source.getEventView()), pKeyTypeMap.get(source.getEventView()), txnType, samplePct);
boolean success = false;
if (BootstrapSeederMain.getValidationType().equals("point")) {
success = comparator.compareRecordsPoint();
} else if (BootstrapSeederMain.getValidationType().equals("pointBs")) {
success = comparator.compareRecordsPointBs();
} else {
success = comparator.compareRecordsNew();
}
if (success)
LOG.info("Audit completed successfully");
else
LOG.error("Audit FAILED !!! ");
} catch (Exception ex) {
LOG.error("Caught an exception ex", ex);
throw ex;
} finally {
if (null != oracleReader)
oracleReader.close();
}
}
DBHelper.close(seeder.getConnection());
}
Aggregations