Search in sources :

Example 6 with CheckResult

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

the class DbConsistencyChecker method checkObjectIndices.

/**
 * Scan all the data object records, to find out the object record is existing
 * but the related index is missing.
 *
 * @return The number of corrupted data
 * @throws ConnectionException
 */
private int checkObjectIndices() throws ConnectionException {
    CheckType checkType = CheckType.OBJECT_INDICES;
    helper.logMessage(DbConsistencyCheckerHelper.MSG_OBJECT_INDICES_START, false, toConsole);
    DbConsistencyStatus status = getStatusFromZk();
    Collection<DataObjectType> resumeDataCfs = resumeFromWorkingPoint(checkType, status.getWorkingPoint());
    CheckResult checkResult = new CheckResult();
    for (DataObjectType dataCf : resumeDataCfs) {
        helper.checkCFIndices(dataCf, toConsole, checkResult);
        status = getStatusFromZk();
        if (!toConsole && isCancelled(status)) {
            cancel(status);
        }
        if (!toConsole) {
            status.update(this.totalCount, checkType.name(), dataCf.getCF().getName(), checkResult.getTotal());
            persistStatus(status);
        }
    }
    String msg = String.format(DbConsistencyCheckerHelper.MSG_OBJECT_INDICES_END, resumeDataCfs.size(), checkResult.getTotal());
    helper.logMessage(checkResult.toString(), false, toConsole);
    helper.logMessage(msg, false, toConsole);
    return checkResult.getTotal();
}
Also used : DbConsistencyStatus(com.emc.storageos.coordinator.client.model.DbConsistencyStatus) CheckResult(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult)

Example 7 with CheckResult

use of com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult 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 8 with CheckResult

use of com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult 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 9 with CheckResult

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

the class DbConsistencyCheckerHelperTest method testClassNameTimeSeriesIndex.

@Test
public void testClassNameTimeSeriesIndex() throws Exception {
    DbConsistencyCheckerHelperMock mockHelper = new DbConsistencyCheckerHelperMock((DbClientImpl) getDbClient());
    Order order = new Order();
    order.setId(URIUtil.createId(Order.class));
    order.setLabel("order1");
    order.setSubmittedByUserId("root");
    getDbClient().createObject(order);
    Keyspace keyspace = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace();
    ColumnFamily<String, ClassNameTimeSeriesIndexColumnName> indexCF = new ColumnFamily<String, ClassNameTimeSeriesIndexColumnName>("UserToOrdersByTimeStamp", StringSerializer.get(), ClassNameTimeSeriesSerializer.get());
    ColumnFamily<String, CompositeColumnName> cf = new ColumnFamily<String, CompositeColumnName>("Order", StringSerializer.get(), CompositeColumnNameSerializer.get());
    IndexAndCf indexAndCf = new IndexAndCf(ClassNameTimeSeriesDBIndex.class, indexCF, keyspace);
    CheckResult checkResult = new CheckResult();
    mockHelper.checkIndexingCF(indexAndCf, false, checkResult);
    assertEquals(0, checkResult.getTotal());
    keyspace.prepareQuery(cf).withCql(String.format("delete from \"Order\" where key='%s'", order.getId())).execute();
    checkResult = new CheckResult();
    mockHelper.checkIndexingCF(indexAndCf, false, checkResult);
    assertEquals(1, checkResult.getTotal());
    keyspace.prepareQuery(indexCF).withCql(mockHelper.getCleanIndexCQL()).execute();
    checkResult = new CheckResult();
    mockHelper.checkIndexingCF(indexAndCf, false, checkResult);
    assertEquals(0, checkResult.getTotal());
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) Keyspace(com.netflix.astyanax.Keyspace) CheckResult(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult) IndexAndCf(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.IndexAndCf) ClassNameTimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) Test(org.junit.Test)

Example 10 with CheckResult

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

the class DbConsistencyCheckerHelperTest method testCFIndexForOrder.

@Test
public void testCFIndexForOrder() throws Exception {
    DbConsistencyCheckerHelperMock mockHelper = new DbConsistencyCheckerHelperMock((DbClientImpl) getDbClient());
    Order order = new Order();
    order.setId(URIUtil.createId(Order.class));
    order.setLabel("order2");
    order.setSubmittedByUserId("Tom");
    order.setTenant("urn:storageos:TenantOrg:128e0354-c26e-438b-b1e6-1a6ceaa9b380:global");
    order.setIndexed(true);
    getDbClient().createObject(order);
    Keyspace keyspace = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace();
    ColumnFamily<String, ClassNameTimeSeriesIndexColumnName> userToOrdersByTimeStampCF = new ColumnFamily<String, ClassNameTimeSeriesIndexColumnName>("UserToOrdersByTimeStamp", StringSerializer.get(), ClassNameTimeSeriesSerializer.get());
    ColumnFamily<String, TimeSeriesIndexColumnName> allOrdersByTimeStampCF = new ColumnFamily<String, TimeSeriesIndexColumnName>("AllOrdersByTimeStamp", StringSerializer.get(), TimeSeriesColumnNameSerializer.get());
    ColumnFamily<String, CompositeColumnName> cf = new ColumnFamily<String, CompositeColumnName>("Order", StringSerializer.get(), CompositeColumnNameSerializer.get());
    IndexAndCf indexAndCf = new IndexAndCf(TimeSeriesDbIndex.class, userToOrdersByTimeStampCF, keyspace);
    CheckResult checkResult = new CheckResult();
    mockHelper.checkCFIndices(TypeMap.getDoType(Order.class), true, checkResult);
    assertEquals(0, checkResult.getTotal());
    keyspace.prepareQuery(userToOrdersByTimeStampCF).withCql(String.format("delete from \"UserToOrdersByTimeStamp\" where key='%s'", order.getSubmittedByUserId())).execute();
    keyspace.prepareQuery(userToOrdersByTimeStampCF).withCql(String.format("delete from \"AllOrdersByTimeStamp\" where key='%s'", order.getTenant())).execute();
    checkResult = new CheckResult();
    mockHelper.checkCFIndices(TypeMap.getDoType(Order.class), true, checkResult);
    assertEquals(2, checkResult.getTotal());
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) ClassNameTimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) Keyspace(com.netflix.astyanax.Keyspace) CheckResult(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult) IndexAndCf(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.IndexAndCf) TimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.TimeSeriesIndexColumnName) ClassNameTimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName) Test(org.junit.Test)

Aggregations

CheckResult (com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult)10 CompositeColumnName (com.emc.storageos.db.client.impl.CompositeColumnName)6 IndexAndCf (com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.IndexAndCf)6 Keyspace (com.netflix.astyanax.Keyspace)6 ColumnFamily (com.netflix.astyanax.model.ColumnFamily)6 Test (org.junit.Test)6 ClassNameTimeSeriesIndexColumnName (com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName)5 TimeSeriesIndexColumnName (com.emc.storageos.db.client.impl.TimeSeriesIndexColumnName)4 DbConsistencyCheckerHelper (com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper)3 FileShare (com.emc.storageos.db.client.model.FileShare)3 Order (com.emc.storageos.db.client.model.uimodels.Order)3 DbConsistencyStatus (com.emc.storageos.coordinator.client.model.DbConsistencyStatus)2 CompositeIndexColumnName (com.emc.storageos.db.client.impl.CompositeIndexColumnName)2 DbClientImpl (com.emc.storageos.db.client.impl.DbClientImpl)2 IndexColumnName (com.emc.storageos.db.client.impl.IndexColumnName)2 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)2 DataObjectType (com.emc.storageos.db.client.impl.DataObjectType)1 MigrationCallbackException (com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException)1 MutationBatch (com.netflix.astyanax.MutationBatch)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1