Search in sources :

Example 6 with SourceInfo

use of com.linkedin.databus.bootstrap.common.SourceInfo in project databus by linkedin.

the class BootstrapProducerCallback method onEndDataEventSequence.

@Override
public ConsumerCallbackResult onEndDataEventSequence(SCN endScn) {
    try {
        // Update the metadata for all sources
        updateAllProducerSourcesMetaData();
        _oldWindowScn = _newWindowScn;
        // Update all the sources info in the database.
        // If we need to create new log file for a source, create one.
        updateSourcesInDB();
        boolean markActive = false;
        if (_state == BootstrapProducerStatus.SEEDING_CATCHUP) {
            if (_newWindowScn > _seedCatchupScn) {
                LOG.info("Bootstrap DB for sources (" + _trackedSources.values() + ") has completed the seeding catchup phase. Marking them active in bootstrap_sources table !! SeedCatchupSCN was :" + _seedCatchupScn);
                markActive = true;
            }
        } else if (_state == BootstrapProducerStatus.FELL_OFF_RELAY) {
            if (_newWindowScn > _producerStartScn) {
                LOG.info("Bootstrap DB for sources (" + _trackedSources.values() + ") has started getting events since last fell-off relay !! Marking them active !!");
                markActive = true;
            }
        }
        if (markActive)
            _bootstrapDao.updateSourcesStatus(_trackedSources.keySet(), BootstrapProducerStatus.ACTIVE);
        Connection conn = getConnection();
        try {
            DBHelper.commit(conn);
        } catch (SQLException s) {
            DBHelper.rollback(conn);
            throw s;
        }
        if (markActive) {
            _state = BootstrapProducerStatus.ACTIVE;
            for (SourceInfo info : _trackedSources.values()) {
                info.setStatus(BootstrapProducerStatus.ACTIVE);
            }
        }
        LOG.info("bootstrap producer upto scn " + _newWindowScn);
    } catch (SQLException e) {
        if (null != _statsCollector)
            _statsCollector.registerSQLException();
        LOG.error("Got SQLException in endDataEventSequence Handler !! 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;
    } finally {
        _totalRm.stop();
        long latency = _totalRm.getDuration() / 1000000L;
        if (null != _statsCollector) {
            _statsCollector.registerEndWindow(latency, _totalNumEvents, _newWindowScn);
        }
    }
    return ConsumerCallbackResult.SUCCESS;
}
Also used : SourceInfo(com.linkedin.databus.bootstrap.common.SourceInfo) DatabusException(com.linkedin.databus2.core.DatabusException) SQLException(java.sql.SQLException) Connection(java.sql.Connection)

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