Search in sources :

Example 1 with SourceInfo

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);
}
Also used : SourceInfo(com.linkedin.databus.bootstrap.common.SourceInfo)

Example 2 with SourceInfo

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);
    }
}
Also used : SourceInfo(com.linkedin.databus.bootstrap.common.SourceInfo) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet)

Example 3 with SourceInfo

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());
        }
    }
}
Also used : SourceInfo(com.linkedin.databus.bootstrap.common.SourceInfo) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with SourceInfo

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;
}
Also used : SourceInfo(com.linkedin.databus.bootstrap.common.SourceInfo) DatabusException(com.linkedin.databus2.core.DatabusException) SQLException(java.sql.SQLException)

Example 5 with SourceInfo

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();
}
Also used : SourceInfo(com.linkedin.databus.bootstrap.common.SourceInfo) HashSet(java.util.HashSet)

Aggregations

SourceInfo (com.linkedin.databus.bootstrap.common.SourceInfo)6 SQLException (java.sql.SQLException)3 DatabusException (com.linkedin.databus2.core.DatabusException)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1