use of com.emc.storageos.db.client.impl.DbClientImpl 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.DbClientImpl in project coprhd-controller by CoprHD.
the class GarbageCollectionRunnable method run.
@Override
public void run() {
log.info("Starting GC loop: type: {}", type.getSimpleName());
try {
URIQueryResultList list = getDecommissionedObjectsOfType(type);
int found = 0, deleted = 0;
for (Iterator<URI> iterator = list.iterator(); iterator.hasNext(); ) {
URI uri = iterator.next();
found++;
log.debug("GC checks dependencies for {}", uri);
try {
if (!canBeGC(uri)) {
continue;
}
DataObject obj = dbClient.queryObject(type, uri);
if (obj != null) {
log.info("No dependencies found. Removing {}", uri);
((DbClientImpl) dbClient).internalRemoveObjects(obj);
deleted++;
}
} catch (DatabaseException ex) {
log.warn("Exception from database access: ", ex);
// To Do - we should skip the whole loop and retry later?
}
}
if (found > 0) {
log.info(String.format("Done GC loop: type: %s, processed %s, deleted %s", type.getSimpleName(), found, deleted));
}
} catch (Exception e) {
log.error("Exception e=", e);
}
}
use of com.emc.storageos.db.client.impl.DbClientImpl in project coprhd-controller by CoprHD.
the class GlobalGCExecutorLoop method preGC.
@Override
protected boolean preGC() {
log.info("PrepareGC for geo DB");
dbClient.start();
VdcUtil.setDbClient(dbClient);
locked = false;
try {
String myVdcId = VdcUtil.getLocalShortVdcId();
glock = new GlobalLockImpl((DbClientImpl) dbClient, GeoLockName, GlobalLock.GL_Mode.GL_VdcShared_MODE, 0, myVdcId);
log.info("Set global VdcShared lock owner to {} vdcId={}", dbServiceId, myVdcId);
glock.acquire(dbServiceId);
locked = true;
} catch (Exception e) {
log.error("Failed to generate the global Geo GC lock e=", e);
}
log.info("Get global lock for Geo GC {}", locked);
// get the lock
return locked;
}
use of com.emc.storageos.db.client.impl.DbClientImpl in project coprhd-controller by CoprHD.
the class RebuildIndexDuplicatedCFNameMigrationTest method testHandleDataObjectClass.
@Test
public void testHandleDataObjectClass() throws Exception {
DataObjectType doType = TypeMap.getDoType(FileShare.class);
for (int i = 0; i < 5; i++) {
FileShare testData = new FileShare();
testData.setId(URIUtil.createId(FileShare.class));
testData.setPath("duplicated_value" + i);
testData.setMountPath("duplicated_value" + i);
getDbClient().updateObject(testData);
}
// create data object whose index are neede to be rebuild
resetRowMutatorTimeStampOffSet(0);
FileShare[] testDataArray = new FileShare[10];
for (int i = 0; i < 10; i++) {
FileShare testData = new FileShare();
testData.setId(URIUtil.createId(FileShare.class));
testData.setPath("duplicated_value" + i);
testData.setMountPath("duplicated_value" + i);
testDataArray[i] = testData;
getDbClient().updateObject(testData);
}
resetRowMutatorTimeStampOffSet(1);
target = new RebuildIndexDuplicatedCFNameMigration();
target.setDbClient(getDbClient());
target.process();
assertEquals(testDataArray.length, target.getTotalProcessedIndexCount());
for (FileShare testData : testDataArray) {
FileShare targetData = (FileShare) getDbClient().queryObject(testData.getId());
assertEquals(testData.getPath(), targetData.getPath());
assertEquals(testData.getMountPath(), targetData.getMountPath());
OperationResult<ColumnList<CompositeColumnName>> result = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace().prepareQuery(doType.getCF()).getKey(testData.getId().toString()).execute();
long pathTime = 0;
long mountPathTime = 0;
for (Column<CompositeColumnName> column : result.getResult()) {
if (column.getName().getOne().equals("path")) {
pathTime = TimeUUIDUtils.getMicrosTimeFromUUID(column.getName().getTimeUUID());
} else if (column.getName().getOne().equals("mountPath")) {
mountPathTime = TimeUUIDUtils.getMicrosTimeFromUUID(column.getName().getTimeUUID());
}
}
assertEquals(1, Math.abs(pathTime - mountPathTime));
}
}
use of com.emc.storageos.db.client.impl.DbClientImpl in project coprhd-controller by CoprHD.
the class DbGlobalLockTest method testVdcSharedGlobalLock.
@Test
public void testVdcSharedGlobalLock() throws Exception {
// VdcShared MODE
_logger.info("Starting vdc shared global lock test");
DbClientImpl dbClient = (DbClientImpl) getDbClient();
boolean flag;
String vdc = "vdc1";
String lockname = "testlock2";
GlobalLockImpl glock = new GlobalLockImpl(dbClient, lockname, GlobalLock.GL_Mode.GL_VdcShared_MODE, 0, vdc);
// acquire the lock
flag = glock.acquire("vipr1");
Assert.assertTrue(flag);
// get lock owner
String owner = null;
owner = glock.getOwner();
Assert.assertEquals(owner, vdc);
// re-enter the lock again with the same owner
flag = glock.acquire("vipr2");
Assert.assertTrue(flag);
// acquire the lock with a different local owner within the same Vdc
GlobalLockImpl glock2 = new GlobalLockImpl(dbClient, lockname, GlobalLock.GL_Mode.GL_VdcShared_MODE, 0, vdc);
flag = glock2.acquire("vipr2");
Assert.assertTrue(flag);
// try to acquire the lock from a different vdc
GlobalLockImpl glock3 = new GlobalLockImpl(dbClient, lockname, GlobalLock.GL_Mode.GL_VdcShared_MODE, 0, "vdc2");
flag = glock3.acquire("vipr2");
Assert.assertFalse(flag);
// release the lock from vipr2
flag = glock2.release("vipr2");
Assert.assertTrue(flag);
// get lock owner
owner = glock.getOwner();
Assert.assertEquals(owner, vdc);
// release the lock from vipr1
flag = glock.release("vipr1");
Assert.assertTrue(flag);
// get lock owner again
owner = glock.getOwner();
Assert.assertEquals(owner, null);
}
Aggregations