use of com.linkedin.databus.bootstrap.common.SourceInfo in project databus by linkedin.
the class BootstrapProducerCallback method updateProducerSourceMetaData.
private void updateProducerSourceMetaData(String source) throws SQLException {
// Update the metadata for this source
SourceInfo srcinfo = _trackedSources.get(source);
_currentRowId = getLastLogEntry(source);
_currentLogId = srcinfo.getCurrLogId();
setLogPosition(_currentLogId, _currentRowId, _newWindowScn, source);
// Update the source info for this source
srcinfo.setMaxRowId(_currentRowId);
srcinfo.setWindowScn(_newWindowScn);
}
use of com.linkedin.databus.bootstrap.common.SourceInfo in project databus by linkedin.
the class BootstrapProducerCallback method initWindowScn.
private void initWindowScn() throws SQLException {
ResultSet rs = null;
StringBuilder sql = new StringBuilder();
Statement stmt = null;
try {
sql.append("select max(p.windowscn), max(s.endscn) from bootstrap_producer_state p, bootstrap_seeder_state s ");
sql.append("where p.srcid = s.srcid and p.srcid in (");
int count = _trackedSources.size();
for (SourceInfo srcInfo : _trackedSources.values()) {
count--;
sql.append(srcInfo.getSrcId());
if (count > 0)
sql.append(",");
}
sql.append(")");
stmt = getConnection().createStatement();
LOG.info("sql query = " + sql.toString());
rs = stmt.executeQuery(sql.toString());
if (rs.next()) {
_producerStartScn = _oldWindowScn = _newWindowScn = rs.getLong(1);
_seedCatchupScn = rs.getLong(2);
}
} catch (SQLException e) {
if (null != _statsCollector)
_statsCollector.registerSQLException();
LOG.error("Unable to select producer's max windowscn. Setting windowscn to -1", e);
_oldWindowScn = -1;
_newWindowScn = -1;
_producerStartScn = -1;
throw e;
} finally {
DBHelper.close(rs, stmt, null);
}
}
use of com.linkedin.databus.bootstrap.common.SourceInfo in project databus by linkedin.
the class BootstrapProducerCallback method updateSourcesInDB.
private void updateSourcesInDB() throws SQLException {
for (Map.Entry<String, SourceInfo> entry : _trackedSources.entrySet()) {
SourceInfo srcinfo = entry.getValue();
srcinfo.saveToDB(getConnection());
}
for (Map.Entry<String, SourceInfo> entry : _trackedSources.entrySet()) {
SourceInfo srcinfo = entry.getValue();
if (srcinfo.getNumRows() >= _maxRowsInLog) {
srcinfo.switchLogFile(getConnection());
setLogPosition(srcinfo.getCurrLogId(), 0, _newWindowScn, entry.getKey());
// getConnection().commit();
_bootstrapDao.createNewLogTable(srcinfo.getSrcId());
}
}
}
use of com.linkedin.databus.bootstrap.common.SourceInfo in project databus by linkedin.
the class BootstrapProducerCallback method onStartSource.
@Override
public ConsumerCallbackResult onStartSource(String source, Schema sourceSchema) {
_numEvents = 0;
boolean ret = false;
SourceInfo srcInfo = null;
_currentSource = source;
_srcRm.start();
try {
srcInfo = _trackedSources.get(source);
if (null == srcInfo) {
LOG.error("Source :" + source + " not managed in this bootstrap DB instance !! Managed Sources : (" + _trackedSources + ")");
return ConsumerCallbackResult.ERROR;
}
ret = prepareStatement(srcInfo.getSrcId());
} catch (SQLException e) {
if (null != _statsCollector)
_statsCollector.registerSQLException();
LOG.error("Got SQLException in startSource Hanlder!! Connections will be reset !!", e);
try {
reset();
} catch (DatabusException e2) {
DbusPrettyLogUtils.logExceptionAtError("Unable to reset connection", e2, LOG);
} catch (SQLException sqlEx) {
LOG.error("Got exception while resetting connections. Stopping Client !!", sqlEx);
return ConsumerCallbackResult.ERROR_FATAL;
}
return ConsumerCallbackResult.ERROR;
}
return ret ? ConsumerCallbackResult.SUCCESS : ConsumerCallbackResult.ERROR;
}
use of com.linkedin.databus.bootstrap.common.SourceInfo in project databus by linkedin.
the class BootstrapProducerCallback method init.
public void init() throws SQLException, DatabusException {
Set<String> configedSources = new HashSet<String>(_logicalSources);
_trackedSources = _bootstrapDao.getDBTrackedSources(configedSources);
_trackedSrcIdsToNames = new HashMap<Integer, String>();
for (Entry<String, SourceInfo> entry : _trackedSources.entrySet()) {
_trackedSrcIdsToNames.put(entry.getValue().getSrcId(), entry.getKey());
}
LOG.info("maxRowsInLog=" + _maxRowsInLog);
LOG.info("trackedSources: ");
int lastState = BootstrapProducerStatus.UNKNOWN;
int curr = 0;
for (SourceInfo info : _trackedSources.values()) {
if (0 == curr) {
lastState = info.getStatus();
} else {
if (info.getStatus() != lastState) {
String msg = "Bootstrap Source state does not seem to be consistent for all the sources that this producer listens to. " + " Found atleast 2 different states :" + lastState + "," + info.getStatus();
LOG.error(msg);
throw new RuntimeException(msg);
}
}
curr++;
LOG.info(info.toString());
}
_state = lastState;
initWindowScn();
}
Aggregations