Search in sources :

Example 1 with DbConsistencyCheckerHelper

use of com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper in project coprhd-controller by CoprHD.

the class DbConsistencyCheckerHelperTest method setUp.

@Before
public void setUp() throws Exception {
    Map<Long, String> timeStampVersionMap = new TreeMap<Long, String>();
    timeStampVersionMap.put(TIME_STAMP_2_4_1, "2.4.1");
    timeStampVersionMap.put(TIME_STAMP_3_0, "3.0");
    timeStampVersionMap.put(TIME_STAMP_3_5, "3.5");
    timeStampVersionMap.put(TIME_STAMP_3_6, "3.6");
    helper = new DbConsistencyCheckerHelper((DbClientImpl) getDbClient()) {

        @Override
        protected Map<Long, String> querySchemaVersions() {
            return timeStampVersionMap;
        }
    };
}
Also used : DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) DbConsistencyCheckerHelper(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper) TreeMap(java.util.TreeMap) TypeMap(com.emc.storageos.db.client.impl.TypeMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Before(org.junit.Before)

Example 2 with DbConsistencyCheckerHelper

use of com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper in project coprhd-controller by CoprHD.

the class StaleIndexCleanerMigration method process.

@Override
public void process() throws MigrationCallbackException {
    checkHelper = new DbConsistencyCheckerHelper((DbClientImpl) getDbClient());
    checkHelper.setDoubleConfirmed(false);
    Map<String, IndexAndCf> allIdxCfs = getAllIndexCFs();
    CheckResult checkResult = new CheckResult();
    try {
        for (IndexAndCf indexAndCf : allIdxCfs.values()) {
            try {
                checkHelper.checkIndexingCF(indexAndCf, false, checkResult, true);
            } catch (ConnectionException e) {
                log.error("Failed to check stale index CF {}", indexAndCf, e);
            }
        }
        ThreadPoolExecutor executor = checkHelper.getExecutor();
        executor.shutdown();
        try {
            if (!executor.awaitTermination(120, TimeUnit.SECONDS)) {
                executor.shutdownNow();
            }
        } catch (Exception e) {
            executor.shutdownNow();
        }
        log.info("Totally find {} stale index", checkResult.getTotal());
        if (checkResult.getTotal() > 0) {
            executeCleanupScripts();
        }
    } catch (Exception e) {
        log.error("failed to cleanup stale/invalid index:", e);
    } finally {
        DbCheckerFileWriter.close();
    }
}
Also used : DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) CheckResult(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult) DbConsistencyCheckerHelper(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper) IndexAndCf(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.IndexAndCf) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 3 with DbConsistencyCheckerHelper

use of com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper in project coprhd-controller by CoprHD.

the class DBClient method checkDB.

/**
 * This db consistency check is for a specific CF,
 * It could also detect the 2 paths same as {@link DBClient#checkDB()}
 *
 * @param cfName
 */
public void checkDB(String cfName) {
    final Class clazz = getClassFromCFName(cfName);
    if (clazz == null) {
        return;
    }
    DataObjectType dataCf = TypeMap.getDoType(clazz);
    DbConsistencyCheckerHelper helper = new DbConsistencyCheckerHelper(_dbClient);
    int corruptedCount = 0;
    try {
        logMsg(DbConsistencyCheckerHelper.MSG_OBJECT_ID_START);
        int illegalCount = helper.checkDataObject(dataCf, true);
        logMsg(String.format(DbConsistencyCheckerHelper.MSG_OBJECT_ID_END_SPECIFIED, dataCf.getCF().getName(), illegalCount));
        corruptedCount += illegalCount;
        logMsg(DbConsistencyCheckerHelper.MSG_OBJECT_INDICES_START);
        CheckResult checkResult = new CheckResult();
        helper.checkCFIndices(dataCf, true, checkResult);
        logMsg(checkResult.toString());
        logMsg(String.format(DbConsistencyCheckerHelper.MSG_OBJECT_INDICES_END_SPECIFIED, dataCf.getCF().getName(), checkResult.getTotal()));
        corruptedCount += checkResult.getTotal();
        logMsg(DbConsistencyCheckerHelper.MSG_INDEX_OBJECTS_START);
        Collection<DbConsistencyCheckerHelper.IndexAndCf> idxCfs = helper.getIndicesOfCF(dataCf).values();
        checkResult = new CheckResult();
        for (DbConsistencyCheckerHelper.IndexAndCf indexAndCf : idxCfs) {
            helper.checkIndexingCF(indexAndCf, true, checkResult);
        }
        logMsg(checkResult.toString());
        logMsg(String.format(DbConsistencyCheckerHelper.MSG_INDEX_OBJECTS_END_SPECIFIED, idxCfs.size(), dataCf.getCF().getName(), checkResult.getTotal()));
        corruptedCount += checkResult.getTotal();
        String msg = generateSummaryForDBChecker(corruptedCount != 0);
        System.out.println(msg);
        log.info(msg);
    } catch (ConnectionException e) {
        log.error("Database connection exception happens, fail to connect: ", e);
        System.err.println("The checker has been stopped by database connection exception. " + "Please see the log for more information.");
    } finally {
        DbCheckerFileWriter.close();
    }
}
Also used : CheckResult(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult) DbConsistencyCheckerHelper(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 4 with DbConsistencyCheckerHelper

use of com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper in project coprhd-controller by CoprHD.

the class DbConsistencyCheckerHelperTest method testCheckCFIndexing.

@Test
public void testCheckCFIndexing() throws Exception {
    ColumnFamily<String, CompositeColumnName> cf = new ColumnFamily<String, CompositeColumnName>("FileShare", StringSerializer.get(), CompositeColumnNameSerializer.get());
    ColumnFamily<String, IndexColumnName> indexCF = new ColumnFamily<String, IndexColumnName>("AltIdIndex", StringSerializer.get(), IndexColumnNameSerializer.get());
    Keyspace keyspace = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace();
    FileShare testData = new FileShare();
    testData.setId(URIUtil.createId(FileShare.class));
    testData.setPath("A1");
    testData.setMountPath("A2");
    getDbClient().createObject(testData);
    keyspace.prepareQuery(indexCF).withCql(String.format("delete from \"AltIdIndex\" where key='%s'", "A1")).execute();
    CheckResult checkResult = new CheckResult();
    helper.checkCFIndices(TypeMap.getDoType(FileShare.class), false, checkResult);
    assertEquals(1, checkResult.getTotal());
    keyspace.prepareQuery(indexCF).withCql(String.format("delete from \"AltIdIndex\" where key='%s'", "A2")).execute();
    checkResult = new CheckResult();
    helper.checkCFIndices(TypeMap.getDoType(FileShare.class), false, checkResult);
    assertEquals(2, checkResult.getTotal());
    helper = new DbConsistencyCheckerHelper((DbClientImpl) getDbClient()) {

        @Override
        protected boolean isDataObjectRemoved(Class<? extends DataObject> clazz, String key) {
            return true;
        }
    };
    checkResult = new CheckResult();
    helper.checkCFIndices(TypeMap.getDoType(FileShare.class), false, checkResult);
    assertEquals(0, checkResult.getTotal());
    testData = new FileShare();
    testData.setId(URIUtil.createId(FileShare.class));
    testData.setPath("A'A'");
    testData.setMountPath("A2");
    getDbClient().createObject(testData);
    checkResult = new CheckResult();
    helper.checkCFIndices(TypeMap.getDoType(FileShare.class), false, checkResult);
    assertEquals(0, checkResult.getTotal());
}
Also used : CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) DbConsistencyCheckerHelper(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper) FileShare(com.emc.storageos.db.client.model.FileShare) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) CompositeIndexColumnName(com.emc.storageos.db.client.impl.CompositeIndexColumnName) TimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.TimeSeriesIndexColumnName) ClassNameTimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName) IndexColumnName(com.emc.storageos.db.client.impl.IndexColumnName) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) Keyspace(com.netflix.astyanax.Keyspace) CheckResult(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult) Test(org.junit.Test)

Example 5 with DbConsistencyCheckerHelper

use of com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper in project coprhd-controller by CoprHD.

the class DBClient method checkDB.

/**
 * This db consistency check is for the whole database and we could detect,
 * 1. The data object record exists but related indices are missing, the scope is the whole db, it will scan all the CFs, from one to
 * next.
 * 2. The index exists but related data object records are missing, the scope is the whole db too, it will scan from one index to next.
 *
 * The indices here means all the indices of each filed of the data object record. If inconsistency found, it will generate several
 * files to do the cleanup work, including rebuilding index.
 */
public void checkDB() {
    try {
        DbConsistencyCheckerHelper helper = new DbConsistencyCheckerHelper(_dbClient);
        DbConsistencyChecker checker = new DbConsistencyChecker(helper, true);
        int corruptedCount = checker.check();
        String msg = generateSummaryForDBChecker(corruptedCount != 0);
        System.out.println(msg);
        log.info(msg);
    } catch (ConnectionException e) {
        log.error("Database connection exception happens, fail to connect: ", e);
        System.err.println("The checker has been stopped by database connection exception. " + "Please see the log for more information.");
    } finally {
        DbCheckerFileWriter.close();
    }
}
Also used : DbConsistencyCheckerHelper(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper) DbConsistencyChecker(com.emc.storageos.db.client.impl.DbConsistencyChecker) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Aggregations

DbConsistencyCheckerHelper (com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper)5 DbClientImpl (com.emc.storageos.db.client.impl.DbClientImpl)3 CheckResult (com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult)3 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)3 ClassNameTimeSeriesIndexColumnName (com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName)1 CompositeColumnName (com.emc.storageos.db.client.impl.CompositeColumnName)1 CompositeIndexColumnName (com.emc.storageos.db.client.impl.CompositeIndexColumnName)1 DataObjectType (com.emc.storageos.db.client.impl.DataObjectType)1 DbConsistencyChecker (com.emc.storageos.db.client.impl.DbConsistencyChecker)1 IndexAndCf (com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.IndexAndCf)1 IndexColumnName (com.emc.storageos.db.client.impl.IndexColumnName)1 TimeSeriesIndexColumnName (com.emc.storageos.db.client.impl.TimeSeriesIndexColumnName)1 TypeMap (com.emc.storageos.db.client.impl.TypeMap)1 FileShare (com.emc.storageos.db.client.model.FileShare)1 MigrationCallbackException (com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException)1 Keyspace (com.netflix.astyanax.Keyspace)1 ColumnFamily (com.netflix.astyanax.model.ColumnFamily)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1