Search in sources :

Example 1 with BootstrapDatabaseTooYoungException

use of com.linkedin.databus2.core.container.request.BootstrapDatabaseTooYoungException in project databus by linkedin.

the class BootstrapProcessor method streamSnapShotRows.

// Get specificed number of snapshot rows
public boolean streamSnapShotRows(Checkpoint currState, BootstrapEventCallback callBack) throws SQLException, BootstrapProcessingException, BootstrapDatabaseTooOldException, BootstrapDatabaseTooYoungException {
    assert (currState.getConsumptionMode() == DbusClientMode.BOOTSTRAP_SNAPSHOT);
    boolean phaseCompleted = false;
    long startSCN = currState.getBootstrapStartScn();
    long sinceSCN = currState.getBootstrapSinceScn();
    if (startSCN <= sinceSCN) {
        LOG.info("StartSCN is less than or equal to sinceSCN. Bypassing snapshot phase !! startSCN:" + startSCN + ",sinceSCN:" + sinceSCN);
        return true;
    }
    Connection conn = _dbDao.getBootstrapConn().getDBConn();
    BootstrapDBMetaDataDAO.SourceStatusInfo srcIdStatusPair = _dbDao.getSrcIdStatusFromDB(currState.getSnapshotSource(), true);
    if (!srcIdStatusPair.isValidSource())
        throw new BootstrapProcessingException("Bootstrap DB not servicing source :" + currState.getCatchupSource());
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
        if (config.isEnableMinScnCheck()) {
            long minScn = _dbDao.getMinScnOfSnapshots(srcIdStatusPair.getSrcId());
            LOG.info("Min scn for tab tables is: " + minScn);
            if (minScn == BootstrapDBMetaDataDAO.DEFAULT_WINDOWSCN) {
                throw new BootstrapDatabaseTooYoungException("BootstrapDB has no minScn for these sources, but minScn check is enabled! minScn=" + minScn);
            }
            // sinceSCN should be greater than minScn, except when sinceSCN == minScn == 0.
            if ((sinceSCN <= minScn) && !(sinceSCN == 0 && minScn == 0)) {
                LOG.error("Bootstrap Snapshot doesn't have requested data . sinceScn too old! sinceScn is " + sinceSCN + " but minScn available is " + minScn);
                throw new BootstrapDatabaseTooYoungException("Min scn=" + minScn + " Since scn=" + sinceSCN);
            }
        } else {
            LOG.debug("Bypassing minScn check!");
        }
        String snapshotSQL = getSnapshotSQLString(_dbDao.getBootstrapConn().getSrcTableName(srcIdStatusPair.getSrcId()), currState.getSnapshotSource());
        stmt = conn.prepareStatement(snapshotSQL);
        long offset = currState.getSnapshotOffset();
        int i = 1;
        stmt.setLong(i++, offset);
        stmt.setLong(i++, currState.getBootstrapStartScn());
        stmt.setLong(i++, currState.getBootstrapSinceScn());
        stmt.setLong(i++, _maxSnapshotRowsPerFetch);
        LOG.info("SnapshotSQL string: " + snapshotSQL + ", " + offset + ", " + currState.getBootstrapStartScn() + ", " + currState.getBootstrapSinceScn() + ", " + _maxSnapshotRowsPerFetch);
        rs = new BootstrapDBTimedQuery(stmt, _queryTimeInSec).executeQuery();
        phaseCompleted = streamOutRows(currState, rs, callBack, _maxSnapshotRowsPerFetch);
    } catch (SQLException e) {
        DBHelper.close(rs, stmt, null);
        LOG.error("Exception occurred when getting snapshot rows" + e);
        throw e;
    } finally {
        if (stmt != null) {
            stmt.close();
            stmt = null;
        }
        mergeAndResetStats();
    }
    return phaseCompleted;
}
Also used : SQLException(java.sql.SQLException) BootstrapProcessingException(com.linkedin.databus.bootstrap.api.BootstrapProcessingException) Connection(java.sql.Connection) BootstrapDBMetaDataDAO(com.linkedin.databus.bootstrap.common.BootstrapDBMetaDataDAO) PreparedStatement(java.sql.PreparedStatement) Checkpoint(com.linkedin.databus.core.Checkpoint) ResultSet(java.sql.ResultSet) BootstrapDBTimedQuery(com.linkedin.databus.bootstrap.common.BootstrapDBTimedQuery) BootstrapDatabaseTooYoungException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooYoungException)

Example 2 with BootstrapDatabaseTooYoungException

use of com.linkedin.databus2.core.container.request.BootstrapDatabaseTooYoungException in project databus by linkedin.

the class StartSCNRequestProcessor method doProcess.

@Override
protected DatabusRequest doProcess(DatabusRequest request) throws IOException, RequestProcessingException {
    BootstrapHttpStatsCollector bootstrapStatsCollector = _bootstrapServer.getBootstrapStatsCollector();
    long startTime = System.currentTimeMillis();
    String sources = request.getRequiredStringParam(SOURCES_PARAM);
    List<String> srcList = getSources(sources);
    Checkpoint ckpt = new Checkpoint(request.getRequiredStringParam(CHECKPOINT_PARAM));
    LOG.info("StartSCN requested for sources : (" + sources + "). CheckPoint is :" + ckpt);
    long sinceScn = ckpt.getBootstrapSinceScn();
    ObjectMapper mapper = new ObjectMapper();
    StringWriter out = new StringWriter(1024);
    long startSCN = -1;
    BootstrapSCNProcessor processor = null;
    try {
        processor = new BootstrapSCNProcessor(_config, _bootstrapServer.getInboundEventStatisticsCollector());
        List<SourceStatusInfo> srcStatusPairs = null;
        try {
            srcStatusPairs = processor.getSourceIdAndStatusFromName(srcList);
            startSCN = processor.getMinApplierWindowScn(sinceScn, srcStatusPairs);
            if (processor.shouldBypassSnapshot(sinceScn, startSCN, srcStatusPairs)) {
                LOG.info("Bootstrap Snapshot phase will be bypassed for startScn request :" + request);
                LOG.info("Original startSCN is:" + startSCN + ", Setting startSCN to the sinceSCN:" + sinceScn);
                startSCN = sinceScn;
            } else {
                if (startSCN == BootstrapDBMetaDataDAO.DEFAULT_WINDOWSCN) {
                    throw new RequestProcessingException("Bootstrap DB is being initialized! startSCN=" + startSCN);
                }
                if (_config.isEnableMinScnCheck()) {
                    // snapshot isn't bypassed. Check if snapshot is possible from sinceScn by checking minScn
                    long minScn = processor.getBootstrapMetaDataDAO().getMinScnOfSnapshots(srcStatusPairs);
                    LOG.info("Min scn for tab tables is: " + minScn);
                    if (minScn == BootstrapDBMetaDataDAO.DEFAULT_WINDOWSCN) {
                        throw new BootstrapDatabaseTooYoungException("BootstrapDB has no minScn for these sources, but minScn check is enabled! minScn=" + minScn);
                    }
                    // sinceSCN should be greater than minScn, unless sinceScn=minScn=0
                    if ((sinceScn <= minScn) && !(sinceScn == 0 && minScn == 0)) {
                        LOG.error("Bootstrap Snapshot doesn't have requested data . sinceScn too old! sinceScn is " + sinceScn + " but minScn available is " + minScn);
                        throw new BootstrapDatabaseTooYoungException("Min scn=" + minScn + " Since scn=" + sinceScn);
                    }
                } else {
                    LOG.debug("Bypassing minScn check! ");
                }
            }
        } catch (BootstrapDatabaseTooOldException tooOldException) {
            if (bootstrapStatsCollector != null) {
                bootstrapStatsCollector.registerErrStartSCN();
                bootstrapStatsCollector.registerErrDatabaseTooOld();
            }
            LOG.error("The bootstrap database is too old!", tooOldException);
            throw new RequestProcessingException(tooOldException);
        } catch (BootstrapDatabaseTooYoungException e) {
            if (bootstrapStatsCollector != null) {
                bootstrapStatsCollector.registerErrStartSCN();
                bootstrapStatsCollector.registerErrBootstrap();
            }
            LOG.error("The bootstrap database is too young!", e);
            throw new RequestProcessingException(e);
        } catch (SQLException e) {
            if (bootstrapStatsCollector != null) {
                bootstrapStatsCollector.registerErrStartSCN();
                bootstrapStatsCollector.registerErrSqlException();
            }
            LOG.error("Error encountered while fetching startSCN from database.", e);
            throw new RequestProcessingException(e);
        }
        mapper.writeValue(out, String.valueOf(startSCN));
        byte[] resultBytes = out.toString().getBytes(Charset.defaultCharset());
        request.getResponseContent().write(ByteBuffer.wrap(resultBytes));
        LOG.info("startSCN: " + startSCN + " with server Info :" + _serverHostPort);
    } catch (RequestProcessingException ex) {
        LOG.error("Got exception while calculating startSCN", ex);
        throw ex;
    } catch (Exception ex) {
        LOG.error("Got exception while calculating startSCN", ex);
        throw new RequestProcessingException(ex);
    } finally {
        if (null != processor)
            processor.shutdown();
    }
    if (bootstrapStatsCollector != null) {
        bootstrapStatsCollector.registerStartSCNReq(System.currentTimeMillis() - startTime);
    }
    return request;
}
Also used : BootstrapHttpStatsCollector(com.linkedin.databus.bootstrap.common.BootstrapHttpStatsCollector) SQLException(java.sql.SQLException) IOException(java.io.IOException) BootstrapDatabaseTooOldException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException) SQLException(java.sql.SQLException) BootstrapDatabaseTooYoungException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooYoungException) RequestProcessingException(com.linkedin.databus2.core.container.request.RequestProcessingException) BootstrapDatabaseTooOldException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException) Checkpoint(com.linkedin.databus.core.Checkpoint) StringWriter(java.io.StringWriter) RequestProcessingException(com.linkedin.databus2.core.container.request.RequestProcessingException) BootstrapDatabaseTooYoungException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooYoungException) SourceStatusInfo(com.linkedin.databus.bootstrap.common.BootstrapDBMetaDataDAO.SourceStatusInfo) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 3 with BootstrapDatabaseTooYoungException

use of com.linkedin.databus2.core.container.request.BootstrapDatabaseTooYoungException in project databus by linkedin.

the class RemoteExceptionHandler method getException.

public Throwable getException(ChunkedBodyReadableByteChannel readChannel) {
    Throwable remoteException = null;
    String err = getExceptionName(readChannel);
    if (null != err) {
        // in theory, we shall be reading the actual exception from the read channel.
        if (err.equalsIgnoreCase(ScnNotFoundException.class.getName())) {
            remoteException = new ScnNotFoundException();
        } else if (err.equalsIgnoreCase(BootstrapDatabaseTooOldException.class.getName())) {
            remoteException = new BootstrapDatabaseTooOldException();
        } else if (err.equalsIgnoreCase(PullerRetriesExhaustedException.class.getName())) {
            remoteException = new PullerRetriesExhaustedException();
        } else if (err.equalsIgnoreCase(BootstrapDatabaseTooYoungException.class.getName())) {
            remoteException = new BootstrapDatabaseTooYoungException();
        } else if (err.equalsIgnoreCase(BootstrapDBException.class.getName())) {
            remoteException = new BootstrapDBException();
        } else if (err.equalsIgnoreCase(SQLException.class.getName())) {
            remoteException = new SQLException();
        } else {
            LOG.error("Unexpected remote error received: " + err);
        }
        LOG.info("Remote exception received: " + remoteException);
    }
    return remoteException;
}
Also used : BootstrapDatabaseTooOldException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException) SQLException(java.sql.SQLException) ScnNotFoundException(com.linkedin.databus.core.ScnNotFoundException) BootstrapDBException(com.linkedin.databus2.core.container.request.BootstrapDBException) BootstrapDatabaseTooYoungException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooYoungException) PullerRetriesExhaustedException(com.linkedin.databus.core.PullerRetriesExhaustedException)

Aggregations

BootstrapDatabaseTooYoungException (com.linkedin.databus2.core.container.request.BootstrapDatabaseTooYoungException)3 SQLException (java.sql.SQLException)3 Checkpoint (com.linkedin.databus.core.Checkpoint)2 BootstrapDatabaseTooOldException (com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException)2 BootstrapProcessingException (com.linkedin.databus.bootstrap.api.BootstrapProcessingException)1 BootstrapDBMetaDataDAO (com.linkedin.databus.bootstrap.common.BootstrapDBMetaDataDAO)1 SourceStatusInfo (com.linkedin.databus.bootstrap.common.BootstrapDBMetaDataDAO.SourceStatusInfo)1 BootstrapDBTimedQuery (com.linkedin.databus.bootstrap.common.BootstrapDBTimedQuery)1 BootstrapHttpStatsCollector (com.linkedin.databus.bootstrap.common.BootstrapHttpStatsCollector)1 PullerRetriesExhaustedException (com.linkedin.databus.core.PullerRetriesExhaustedException)1 ScnNotFoundException (com.linkedin.databus.core.ScnNotFoundException)1 BootstrapDBException (com.linkedin.databus2.core.container.request.BootstrapDBException)1 RequestProcessingException (com.linkedin.databus2.core.container.request.RequestProcessingException)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1