Search in sources :

Example 21 with DbClientImpl

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());
}
Also used : CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) DbConsistencyCheckerHelper(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper) FileShare(com.emc.storageos.db.client.model.FileShare) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) CompositeIndexColumnName(com.emc.storageos.db.client.impl.CompositeIndexColumnName) TimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.TimeSeriesIndexColumnName) ClassNameTimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName) IndexColumnName(com.emc.storageos.db.client.impl.IndexColumnName) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) Keyspace(com.netflix.astyanax.Keyspace) CheckResult(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult) Test(org.junit.Test)

Example 22 with DbClientImpl

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);
    }
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 23 with DbClientImpl

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;
}
Also used : DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) GlobalLockImpl(com.emc.storageos.db.client.impl.GlobalLockImpl)

Example 24 with DbClientImpl

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));
    }
}
Also used : CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) ColumnList(com.netflix.astyanax.model.ColumnList) RebuildIndexDuplicatedCFNameMigration(com.emc.storageos.db.client.upgrade.callbacks.RebuildIndexDuplicatedCFNameMigration) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) FileShare(com.emc.storageos.db.client.model.FileShare) Test(org.junit.Test)

Example 25 with DbClientImpl

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);
}
Also used : DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) GlobalLockImpl(com.emc.storageos.db.client.impl.GlobalLockImpl) Test(org.junit.Test)

Aggregations

DbClientImpl (com.emc.storageos.db.client.impl.DbClientImpl)27 Test (org.junit.Test)11 URI (java.net.URI)9 IndexColumnName (com.emc.storageos.db.client.impl.IndexColumnName)6 CompositeColumnName (com.emc.storageos.db.client.impl.CompositeColumnName)5 Order (com.emc.storageos.db.client.model.uimodels.Order)5 TimeSeriesConstraint (com.emc.storageos.db.client.constraint.TimeSeriesConstraint)4 DataObjectType (com.emc.storageos.db.client.impl.DataObjectType)4 Volume (com.emc.storageos.db.client.model.Volume)4 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)4 MigrationCallbackException (com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException)4 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)4 ClassNameTimeSeriesIndexColumnName (com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName)3 DbClientContext (com.emc.storageos.db.client.impl.DbClientContext)3 DbConsistencyCheckerHelper (com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper)3 GlobalLockImpl (com.emc.storageos.db.client.impl.GlobalLockImpl)3 FileShare (com.emc.storageos.db.client.model.FileShare)3 ColumnFamily (com.netflix.astyanax.model.ColumnFamily)3 DbVersionInfo (com.emc.storageos.coordinator.client.model.DbVersionInfo)2 NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)2