Search in sources :

Example 1 with CheckResult

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

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

the class DbConsistencyChecker method checkIndexObjects.

/**
 * Scan all the indices and related data object records, to find out
 * the index record is existing but the related data object records is missing.
 *
 * @return the number of the corrupted rows in the index CFs
 * @throws ConnectionException
 */
private int checkIndexObjects() throws ConnectionException {
    CheckType checkType = CheckType.INDEX_OBJECTS;
    helper.logMessage(DbConsistencyCheckerHelper.MSG_INDEX_OBJECTS_START, false, toConsole);
    DbConsistencyStatus status = getStatusFromZk();
    Collection<IndexAndCf> resumeIdxCfs = resumeFromWorkingPoint(checkType, status.getWorkingPoint());
    CheckResult checkResult = new CheckResult();
    for (IndexAndCf indexAndCf : resumeIdxCfs) {
        helper.checkIndexingCF(indexAndCf, toConsole, checkResult);
        status = getStatusFromZk();
        if (!toConsole && isCancelled(status)) {
            cancel(status);
        }
        if (!toConsole) {
            status.update(this.totalCount, checkType.name(), indexAndCf.generateKey(), checkResult.getTotal());
            persistStatus(status);
        }
    }
    String msg = String.format(DbConsistencyCheckerHelper.MSG_INDEX_OBJECTS_END, resumeIdxCfs.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) IndexAndCf(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.IndexAndCf)

Example 4 with CheckResult

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

the class DbConsistencyCheckerHelperTest method testCheckIndexingCF_SkipRecordWithNoInactiveColumn.

@Test
public void testCheckIndexingCF_SkipRecordWithNoInactiveColumn() throws Exception {
    ColumnFamily<String, CompositeColumnName> cf = new ColumnFamily<String, CompositeColumnName>("FileShare", StringSerializer.get(), CompositeColumnNameSerializer.get());
    FileShare testData = new FileShare();
    testData.setId(URIUtil.createId(FileShare.class));
    testData.setPath("path1");
    testData.setMountPath("mountPath1");
    getDbClient().createObject(testData);
    Keyspace keyspace = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace();
    keyspace.prepareQuery(cf).withCql(String.format("delete from \"FileShare\" where key='%s' and column1='inactive'", testData.getId().toString())).execute();
    CheckResult 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("path1");
    testData.setMountPath("mountPath1");
    getDbClient().createObject(testData);
    testData = (FileShare) getDbClient().queryObject(testData.getId());
    testData.setInactive(true);
    getDbClient().updateObject(testData);
    helper.checkCFIndices(TypeMap.getDoType(FileShare.class), false, checkResult);
    assertEquals(0, checkResult.getTotal());
}
Also used : CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) Keyspace(com.netflix.astyanax.Keyspace) CheckResult(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult) FileShare(com.emc.storageos.db.client.model.FileShare) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) Test(org.junit.Test)

Example 5 with CheckResult

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

the class DbConsistencyCheckerHelperTest method testTimeSeriesAlternateId.

@Test
public void testTimeSeriesAlternateId() throws Exception {
    DbConsistencyCheckerHelperMock mockHelper = new DbConsistencyCheckerHelperMock((DbClientImpl) getDbClient());
    Order order = new Order();
    order.setId(URIUtil.createId(Order.class));
    order.setLabel("order2");
    order.setTenant("tenant");
    order.setIndexed(true);
    getDbClient().createObject(order);
    Keyspace keyspace = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace();
    ColumnFamily<String, TimeSeriesIndexColumnName> indexCF = 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, 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) TimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.TimeSeriesIndexColumnName) ClassNameTimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) 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