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();
}
}
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();
}
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();
}
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());
}
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());
}
Aggregations