use of com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.IndexAndCf 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());
}
use of com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.IndexAndCf in project coprhd-controller by CoprHD.
the class DbConsistencyCheckerHelperTest method testCheckIndexingCF.
@Test
public void testCheckIndexingCF() 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();
// delete data object
MutationBatch mutationBatch = keyspace.prepareMutationBatch();
mutationBatch.withRow(cf, testData.getId().toString()).delete();
mutationBatch.execute();
CheckResult checkResult = new CheckResult();
ColumnFamily<String, IndexColumnName> indexCF = new ColumnFamily<String, IndexColumnName>("AltIdIndex", StringSerializer.get(), IndexColumnNameSerializer.get());
// find inconsistency: index exits but data object is deleted
IndexAndCf indexAndCf = new IndexAndCf(AltIdDbIndex.class, indexCF, keyspace);
helper.checkIndexingCF(indexAndCf, false, checkResult);
assertEquals(2, checkResult.getTotal());
testData = new FileShare();
testData.setId(URIUtil.createId(FileShare.class));
testData.setPath("path2");
testData.setMountPath("mountPath2");
getDbClient().createObject(testData);
// create duplicated index
keyspace.prepareQuery(indexCF).withCql(String.format("INSERT INTO \"AltIdIndex\" (key, column1, column2, column3, column4, column5, value) VALUES ('pa', 'FileShare', '%s', '', '', now(), intasblob(10));", testData.getId().toString())).execute();
checkResult = new CheckResult();
helper.checkIndexingCF(indexAndCf, false, checkResult);
assertEquals(3, checkResult.getTotal());
keyspace.prepareQuery(indexCF).withCql("TRUNCATE \"AltIdIndex\"").execute();
// test large columns for single row key
for (int i = 0; i < 123; i++) {
keyspace.prepareQuery(indexCF).withCql(String.format("INSERT INTO \"AltIdIndex\" (key, column1, column2, column3, column4, column5, value) VALUES ('sa', 'FileShare', '%s', '', '', now(), intasblob(10));", i)).execute();
}
checkResult = new CheckResult();
helper.checkIndexingCF(indexAndCf, false, checkResult);
assertEquals(123, checkResult.getTotal());
}
use of com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.IndexAndCf 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.IndexAndCf in project coprhd-controller by CoprHD.
the class StaleIndexCleanerMigration method getAllIndexCFs.
private Map<String, IndexAndCf> getAllIndexCFs() {
Map<String, IndexAndCf> allIdxCfs = new TreeMap<>();
for (DataObjectType objType : TypeMap.getAllDoTypes()) {
if (KeyspaceUtil.isLocal(objType.getDataObjectClass())) {
Map<String, IndexAndCf> idxCfs = checkHelper.getIndicesOfCF(objType);
allIdxCfs.putAll(idxCfs);
}
}
return allIdxCfs;
}
use of com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.IndexAndCf 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();
}
Aggregations