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