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