Search in sources :

Example 6 with BootstrapDBMetaDataDAO

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

the class BootstrapAddSource method getConnection.

/*
	 * @return a bootstrapDB connection object.
	 * Note: The connection object is still owned by BootstrapConn. SO dont close it
	 */
public Connection getConnection() {
    Connection conn = null;
    if (_dbDao == null) {
        LOG.info("<<<< Creating Bootstrap Connection!! >>>>");
        BootstrapConn dbConn = new BootstrapConn();
        try {
            dbConn.initBootstrapConn(false, _config.getBootstrapDBUsername(), _config.getBootstrapDBPassword(), _config.getBootstrapDBHostname(), _config.getBootstrapDBName());
            _dbDao = new BootstrapDBMetaDataDAO(dbConn, _config.getBootstrapDBHostname(), _config.getBootstrapDBUsername(), _config.getBootstrapDBPassword(), _config.getBootstrapDBName(), false);
        } catch (Exception e) {
            LOG.fatal("Unable to open BootstrapDB Connection !!", e);
            throw new RuntimeException("Got exception when getting bootstrap DB Connection.", e);
        }
    }
    try {
        conn = _dbDao.getBootstrapConn().getDBConn();
    } catch (SQLException e) {
        LOG.fatal("Not able to open BootstrapDB Connection !!", e);
        throw new RuntimeException("Got exception when getting bootstrap DB Connection.", e);
    }
    return conn;
}
Also used : SQLException(java.sql.SQLException) BootstrapConn(com.linkedin.databus.bootstrap.common.BootstrapConn) Connection(java.sql.Connection) BootstrapDBMetaDataDAO(com.linkedin.databus.bootstrap.common.BootstrapDBMetaDataDAO) SQLException(java.sql.SQLException) ParseException(org.apache.commons.cli.ParseException)

Example 7 with BootstrapDBMetaDataDAO

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

the class BootstrapProducerCallback method getConnection.

private Connection getConnection() throws SQLException {
    Connection conn = null;
    if (_bootstrapDao == null) {
        BootstrapConn dbConn = new BootstrapConn();
        try {
            final boolean autoCommit = false;
            dbConn.initBootstrapConn(autoCommit, _config.getBootstrapDBUsername(), _config.getBootstrapDBPassword(), _config.getBootstrapDBHostname(), _config.getBootstrapDBName());
            _bootstrapDao = new BootstrapDBMetaDataDAO(dbConn, _config.getBootstrapDBHostname(), _config.getBootstrapDBUsername(), _config.getBootstrapDBPassword(), _config.getBootstrapDBName(), autoCommit);
        } catch (Exception e) {
            LOG.fatal("Unable to open BootstrapDB Connection !!", e);
            return null;
        }
    }
    try {
        conn = _bootstrapDao.getBootstrapConn().getDBConn();
    } catch (SQLException e) {
        if (null != _statsCollector)
            _statsCollector.registerSQLException();
        LOG.fatal("Not able to open BootstrapDB Connection !!", e);
        throw e;
    }
    return conn;
}
Also used : SQLException(java.sql.SQLException) BootstrapConn(com.linkedin.databus.bootstrap.common.BootstrapConn) Connection(java.sql.Connection) BootstrapDBMetaDataDAO(com.linkedin.databus.bootstrap.common.BootstrapDBMetaDataDAO) ScnNotFoundException(com.linkedin.databus.core.ScnNotFoundException) SQLException(java.sql.SQLException) DatabusException(com.linkedin.databus2.core.DatabusException)

Example 8 with BootstrapDBMetaDataDAO

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

the class TestBootstrapSCNProcessor method testShouldBypassSnapshot.

@Test
public void testShouldBypassSnapshot() throws SQLException, BootstrapProcessingException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException {
    BootstrapSCNProcessor bsp = new BootstrapSCNProcessor();
    Long defaultRowsThresholdForSnapshotBypass = Long.MAX_VALUE;
    Map<String, Long> rowsThresholdForSnapshotBypass = new HashMap<String, Long>();
    Map<String, Boolean> disableSnapshotBypass = new HashMap<String, Boolean>();
    boolean predicatePushDown = false;
    Map<String, Boolean> predicatePushDownBypass = new HashMap<String, Boolean>();
    int queryTimeoutInSec = 10;
    BootstrapReadOnlyConfig db = null;
    boolean enableMinScnCheck = false;
    final long longestDbTxnTimeMins = 240L;
    BootstrapServerStaticConfig bssc = new BootstrapServerStaticConfig(defaultRowsThresholdForSnapshotBypass, rowsThresholdForSnapshotBypass, disableSnapshotBypass, predicatePushDown, predicatePushDownBypass, queryTimeoutInSec, enableMinScnCheck, db, longestDbTxnTimeMins);
    Field field = bsp.getClass().getDeclaredField("_config");
    field.setAccessible(true);
    field.set(bsp, bssc);
    int srcId = 101;
    long sinceScn = 5;
    long startScn = 10;
    BootstrapDBMetaDataDAO bmdd = EasyMock.createMock(BootstrapDBMetaDataDAO.class);
    EasyMock.expect(bmdd.getLogIdToCatchup(srcId, startScn)).andReturn(0).anyTimes();
    EasyMock.expect(bmdd.getLogIdToCatchup(srcId, sinceScn)).andReturn(0).anyTimes();
    EasyMock.replay(bmdd);
    Field dbDaoField = bsp.getClass().getDeclaredField("_dbDao");
    dbDaoField.setAccessible(true);
    dbDaoField.set(bsp, bmdd);
    List<SourceStatusInfo> srcList = new ArrayList<SourceStatusInfo>();
    String name = "foo";
    SourceStatusInfo ssi = new SourceStatusInfo(name, srcId, 4);
    srcList.add(ssi);
    // case 1. Single source, defaultRowsThresholdForSnapshotBypass set to Long.MAX_VALUE,
    // individual overrides not set
    boolean sbs = bsp.shouldBypassSnapshot(sinceScn, startScn, srcList);
    Assert.assertEquals(true, sbs);
    // case 2. Single source, defaultRowsThresholdForSnapshotBypass set to finite value,
    // individual overrides set for the source
    rowsThresholdForSnapshotBypass.put(name, Long.MAX_VALUE);
    BootstrapServerStaticConfig bssc2 = new BootstrapServerStaticConfig(defaultRowsThresholdForSnapshotBypass, rowsThresholdForSnapshotBypass, disableSnapshotBypass, predicatePushDown, predicatePushDownBypass, queryTimeoutInSec, enableMinScnCheck, db, longestDbTxnTimeMins);
    field.set(bsp, bssc2);
    sbs = bsp.shouldBypassSnapshot(sinceScn, startScn, srcList);
    Assert.assertEquals(true, sbs);
    // Case 3:  Detect case when the log is not available on log tables ( so it should NOT bypass snapshot )
    BootstrapDBMetaDataDAO bmdd2 = EasyMock.createMock(BootstrapDBMetaDataDAO.class);
    EasyMock.expect(bmdd2.getLogIdToCatchup(srcId, startScn)).andReturn(2).anyTimes();
    EasyMock.expect(bmdd2.getLogIdToCatchup(srcId, sinceScn)).andThrow(new BootstrapProcessingException(""));
    EasyMock.replay(bmdd2);
    Field dbDaoField2 = bsp.getClass().getDeclaredField("_dbDao");
    dbDaoField2.setAccessible(true);
    dbDaoField2.set(bsp, bmdd2);
    sbs = bsp.shouldBypassSnapshot(sinceScn, startScn, srcList);
    Assert.assertEquals(false, sbs);
}
Also used : HashMap(java.util.HashMap) BootstrapProcessingException(com.linkedin.databus.bootstrap.api.BootstrapProcessingException) ArrayList(java.util.ArrayList) BootstrapDBMetaDataDAO(com.linkedin.databus.bootstrap.common.BootstrapDBMetaDataDAO) BootstrapReadOnlyConfig(com.linkedin.databus.bootstrap.common.BootstrapReadOnlyConfig) Field(java.lang.reflect.Field) SourceStatusInfo(com.linkedin.databus.bootstrap.common.BootstrapDBMetaDataDAO.SourceStatusInfo) Test(org.testng.annotations.Test)

Example 9 with BootstrapDBMetaDataDAO

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

the class TestBootstrap method testBootstrapProcessor.

@Test
public void testBootstrapProcessor() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, IOException, BootstrapProcessingException, DatabusException, BootstrapDatabaseTooOldException, BootstrapDBException {
    EventProcessor processorCallback = new EventProcessor();
    BootstrapConfig config = new BootstrapConfig();
    BootstrapReadOnlyConfig staticConfig = config.build();
    BootstrapServerConfig configBuilder = new BootstrapServerConfig();
    configBuilder.setEnableMinScnCheck(false);
    BootstrapServerStaticConfig staticServerConfig = configBuilder.build();
    BootstrapProcessor processor = new BootstrapProcessor(staticServerConfig, null);
    String sourceName = "TestBootstrap.testBootstrapProcessor.events";
    // Create the tables for all the sources before starting up the threads
    BootstrapConn _bootstrapConn = new BootstrapConn();
    boolean autoCommit = true;
    _bootstrapConn.initBootstrapConn(autoCommit, staticConfig.getBootstrapDBUsername(), staticConfig.getBootstrapDBPassword(), staticConfig.getBootstrapDBHostname(), staticConfig.getBootstrapDBName());
    BootstrapDBMetaDataDAO dao = new BootstrapDBMetaDataDAO(_bootstrapConn, staticConfig.getBootstrapDBHostname(), staticConfig.getBootstrapDBUsername(), staticConfig.getBootstrapDBPassword(), staticConfig.getBootstrapDBName(), autoCommit);
    SourceStatusInfo srcStatusInfo = dao.getSrcIdStatusFromDB(sourceName, false);
    if (srcStatusInfo.getSrcId() >= 0) {
        dao.dropSourceInDB(srcStatusInfo.getSrcId());
    }
    dao.addNewSourceInDB(sourceName, BootstrapProducerStatus.ACTIVE);
    srcStatusInfo = dao.getSrcIdStatusFromDB(sourceName, false);
    setBootstrapLoginfoTable(_bootstrapConn, 0, Long.MAX_VALUE);
    //insert one row
    insertOneSnapshotEvent(dao, srcStatusInfo.getSrcId(), Long.MAX_VALUE - 10, Long.MAX_VALUE - 100, "check", "test_payload_data");
    BootstrapCheckpointHandler bstCheckpointHandler = new BootstrapCheckpointHandler(sourceName);
    Checkpoint c = bstCheckpointHandler.createInitialBootstrapCheckpoint(null, 0L);
    c.setConsumptionMode(DbusClientMode.BOOTSTRAP_SNAPSHOT);
    c.setBootstrapStartScn(Long.MAX_VALUE - 10);
    c.setSnapshotOffset(Long.MAX_VALUE - 1000);
    // System.out.println("Snapshot");
    processor.streamSnapShotRows(c, processorCallback);
    Assert.assertEquals(processorCallback.getrIds().size(), 1);
    Assert.assertEquals(Long.MAX_VALUE - 10, processorCallback.getrIds().get(0).longValue());
    Assert.assertEquals(Long.MAX_VALUE - 100, processorCallback.getSequences().get(0).longValue());
    Assert.assertEquals("check", processorCallback.getSrcKeys().get(0));
    Assert.assertEquals("test_payload_data", new String(processorCallback.getValues().get(0)));
    processorCallback.reset();
    c.setSnapshotOffset(Checkpoint.FULLY_CONSUMED_WINDOW_OFFSET);
    c.setBootstrapTargetScn(c.getBootstrapStartScn().longValue());
    bstCheckpointHandler.advanceAfterTargetScn(c);
    bstCheckpointHandler.advanceAfterSnapshotPhase(c);
    //		  c.setConsumptionMode(DbusClientMode.BOOTSTRAP_CATCHUP);
    //		  c.setCatchupSource(sourceName);
    //		  c.setWindowScn(0L);
    //		  c.setWindowOffset(0);
    // System.out.println("Catchup");
    boolean phaseCompleted = processor.streamCatchupRows(c, processorCallback);
    Assert.assertEquals(true, phaseCompleted);
}
Also used : BootstrapProcessor(com.linkedin.databus.bootstrap.server.BootstrapProcessor) BootstrapConn(com.linkedin.databus.bootstrap.common.BootstrapConn) BootstrapConfig(com.linkedin.databus.bootstrap.common.BootstrapConfig) BootstrapDBMetaDataDAO(com.linkedin.databus.bootstrap.common.BootstrapDBMetaDataDAO) BootstrapCheckpointHandler(com.linkedin.databus.core.BootstrapCheckpointHandler) BootstrapReadOnlyConfig(com.linkedin.databus.bootstrap.common.BootstrapReadOnlyConfig) BootstrapServerConfig(com.linkedin.databus.bootstrap.server.BootstrapServerConfig) Checkpoint(com.linkedin.databus.core.Checkpoint) BootstrapServerStaticConfig(com.linkedin.databus.bootstrap.server.BootstrapServerStaticConfig) SourceStatusInfo(com.linkedin.databus.bootstrap.common.BootstrapDBMetaDataDAO.SourceStatusInfo) Test(org.testng.annotations.Test)

Example 10 with BootstrapDBMetaDataDAO

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

the class BootstrapApplierThread method getConnection.

private Connection getConnection() throws SQLException {
    Connection conn = null;
    BootstrapConn bsConn = null;
    if (_bootstrapDao == null) {
        bsConn = new BootstrapConn();
        try {
            final boolean autoCommit = false;
            bsConn.initBootstrapConn(autoCommit, java.sql.Connection.TRANSACTION_READ_COMMITTED, _config.getBootstrapDBUsername(), _config.getBootstrapDBPassword(), _config.getBootstrapDBHostname(), _config.getBootstrapDBName());
            _bootstrapDao = new BootstrapDBMetaDataDAO(bsConn, _config.getBootstrapDBHostname(), _config.getBootstrapDBUsername(), _config.getBootstrapDBPassword(), _config.getBootstrapDBName(), autoCommit);
        } catch (SQLException e) {
            LOG.fatal("Unable to get Bootstrap DB Connection", e);
            throw e;
        } catch (Exception ex) {
            LOG.fatal("Unable to get Bootstrap DB Connection", ex);
            return null;
        }
    }
    try {
        conn = _bootstrapDao.getBootstrapConn().getDBConn();
    } catch (SQLException sqlEx) {
        LOG.fatal("NOT able to get Bootstrap DB Connection", sqlEx);
        throw sqlEx;
    }
    return conn;
}
Also used : SQLException(java.sql.SQLException) BootstrapConn(com.linkedin.databus.bootstrap.common.BootstrapConn) Connection(java.sql.Connection) BootstrapDBMetaDataDAO(com.linkedin.databus.bootstrap.common.BootstrapDBMetaDataDAO) BootstrapDatabaseTooOldException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException) SQLException(java.sql.SQLException)

Aggregations

BootstrapDBMetaDataDAO (com.linkedin.databus.bootstrap.common.BootstrapDBMetaDataDAO)10 BootstrapConn (com.linkedin.databus.bootstrap.common.BootstrapConn)9 SQLException (java.sql.SQLException)6 Connection (java.sql.Connection)5 SourceStatusInfo (com.linkedin.databus.bootstrap.common.BootstrapDBMetaDataDAO.SourceStatusInfo)4 BootstrapReadOnlyConfig (com.linkedin.databus.bootstrap.common.BootstrapReadOnlyConfig)4 BootstrapConfig (com.linkedin.databus.bootstrap.common.BootstrapConfig)3 ParseException (org.apache.commons.cli.ParseException)3 Test (org.testng.annotations.Test)3 Checkpoint (com.linkedin.databus.core.Checkpoint)2 BootstrapProcessingException (com.linkedin.databus.bootstrap.api.BootstrapProcessingException)1 BootstrapProcessor (com.linkedin.databus.bootstrap.server.BootstrapProcessor)1 BootstrapServerConfig (com.linkedin.databus.bootstrap.server.BootstrapServerConfig)1 BootstrapServerStaticConfig (com.linkedin.databus.bootstrap.server.BootstrapServerStaticConfig)1 BootstrapCheckpointHandler (com.linkedin.databus.core.BootstrapCheckpointHandler)1 InvalidEventException (com.linkedin.databus.core.InvalidEventException)1 KeyTypeNotImplementedException (com.linkedin.databus.core.KeyTypeNotImplementedException)1 ScnNotFoundException (com.linkedin.databus.core.ScnNotFoundException)1 ConfigLoader (com.linkedin.databus.core.util.ConfigLoader)1 DatabusException (com.linkedin.databus2.core.DatabusException)1