Search in sources :

Example 21 with Keyspace

use of com.netflix.astyanax.Keyspace 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 Keyspace

use of com.netflix.astyanax.Keyspace 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());
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) Keyspace(com.netflix.astyanax.Keyspace) CheckResult(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult) IndexAndCf(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.IndexAndCf) ClassNameTimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) Test(org.junit.Test)

Example 23 with Keyspace

use of com.netflix.astyanax.Keyspace 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());
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) ClassNameTimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) Keyspace(com.netflix.astyanax.Keyspace) CheckResult(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult) IndexAndCf(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.IndexAndCf) TimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.TimeSeriesIndexColumnName) ClassNameTimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName) Test(org.junit.Test)

Example 24 with Keyspace

use of com.netflix.astyanax.Keyspace in project coprhd-controller by CoprHD.

the class InternalDbClientImpl method getLatestModifiedField.

public Column<CompositeColumnName> getLatestModifiedField(DataObjectType type, URI id, Set<String> ignoreList) {
    Column<CompositeColumnName> latestField = null;
    ColumnFamily<String, CompositeColumnName> cf = type.getCF();
    Keyspace ks = this.getKeyspace(type.getDataObjectClass());
    Rows<String, CompositeColumnName> rows = this.queryRowsWithAllColumns(ks, Lists.newArrayList(id), cf);
    if (rows.isEmpty()) {
        log.warn("Can not find the latest modified field of {}", id);
        return latestField;
    }
    long latestTimeStampe = 0;
    for (Column<CompositeColumnName> column : rows.iterator().next().getColumns()) {
        if (ignoreList != null && ignoreList.contains(column.getName().getOne())) {
            continue;
        }
        if (column.getTimestamp() > latestTimeStampe) {
            latestTimeStampe = column.getTimestamp();
            latestField = column;
        }
    }
    return latestField;
}
Also used : CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) Keyspace(com.netflix.astyanax.Keyspace)

Example 25 with Keyspace

use of com.netflix.astyanax.Keyspace in project coprhd-controller by CoprHD.

the class DbConsistencyCheckerHelper method checkCFIndices.

/**
 * Scan all the data object records, to find out the object record is existing but the related index is missing.
 *
 * @param doType
 * @param toConsole whether print out in the console
 * @return the number of corrupted data
 * @throws ConnectionException
 */
public void checkCFIndices(DataObjectType doType, boolean toConsole, CheckResult checkResult) throws ConnectionException {
    initSchemaVersions();
    Class objClass = doType.getDataObjectClass();
    if (skipCheckCFs.contains(objClass.getSimpleName())) {
        _log.info("Skip checking CF {}", objClass);
        return;
    } else {
        _log.info("Check Data Object CF {} with double confirmed option: {}", objClass, doubleConfirmed);
    }
    Map<String, ColumnField> indexedFields = new HashMap<String, ColumnField>();
    for (ColumnField field : doType.getColumnFields()) {
        if (field.getIndex() != null) {
            indexedFields.put(field.getName(), field);
        }
    }
    if (indexedFields.isEmpty()) {
        return;
    }
    Keyspace keyspace = dbClient.getKeyspace(objClass);
    ColumnFamilyQuery<String, CompositeColumnName> query = keyspace.prepareQuery(doType.getCF());
    OperationResult<Rows<String, CompositeColumnName>> result = query.getAllRows().setRowLimit(dbClient.DEFAULT_PAGE_SIZE).execute();
    int scannedRows = 0;
    long beginTime = System.currentTimeMillis();
    for (Row<String, CompositeColumnName> objRow : result.getResult()) {
        try {
            boolean inactiveObject = false;
            boolean hasStaleEntries = false;
            scannedRows++;
            Map<String, Column<CompositeColumnName>> distinctColumns = new HashMap<String, Column<CompositeColumnName>>();
            for (Column<CompositeColumnName> column : objRow.getColumns()) {
                distinctColumns.put(column.getName().getOne(), column);
            }
            hasStaleEntries = checkForStaleEntries(distinctColumns);
            if (hasStaleEntries) {
                _log.warn("Data object with key {} has stale entries, don't rebuild index for it.", objRow.getKey());
                continue;
            }
            for (Column<CompositeColumnName> column : objRow.getColumns()) {
                if (column.getName().getOne().equals(DataObject.INACTIVE_FIELD_NAME)) {
                    inactiveObject = column.getBooleanValue();
                    break;
                }
            }
            if (inactiveObject) {
                continue;
            }
            for (Column<CompositeColumnName> column : objRow.getColumns()) {
                if (!indexedFields.containsKey(column.getName().getOne())) {
                    continue;
                }
                // we don't build index if the value is null, refer to ColumnField.
                if (!column.hasValue()) {
                    continue;
                }
                ColumnField indexedField = indexedFields.get(column.getName().getOne());
                String indexKey = getIndexKey(indexedField, column, objRow);
                if (indexKey == null) {
                    continue;
                }
                boolean isColumnInIndex = isColumnInIndex(keyspace, indexedField.getIndexCF(), indexKey, getIndexColumns(indexedField, column, objRow.getKey()));
                if (!isColumnInIndex) {
                    if (doubleConfirmed && isDataObjectRemoved(doType.getDataObjectClass(), objRow.getKey())) {
                        continue;
                    }
                    String dbVersion = findDataCreatedInWhichDBVersion(column.getName().getTimeUUID());
                    checkResult.increaseByVersion(dbVersion);
                    logMessage(String.format("Inconsistency found Object(%s, id: %s, field: %s) is existing, but the related Index(%s, type: %s, id: %s) is missing. This entry is updated by version %s", indexedField.getDataObjectType().getSimpleName(), objRow.getKey(), indexedField.getName(), indexedField.getIndexCF().getName(), indexedField.getIndex().getClass().getSimpleName(), indexKey, dbVersion), true, toConsole);
                    DbCheckerFileWriter.writeTo(DbCheckerFileWriter.WRITER_REBUILD_INDEX, String.format("id:%s, cfName:%s", objRow.getKey(), doType.getCF().getName()));
                }
            }
            if (scannedRows >= THRESHHOLD_FOR_OUTPUT_DEBUG) {
                _log.info("{} data objects have been check with time {}", scannedRows, DurationFormatUtils.formatDurationHMS(System.currentTimeMillis() - beginTime));
                scannedRows = 0;
                beginTime = System.currentTimeMillis();
            }
        } catch (Exception e) {
            _log.warn("exception occurs when checking CF indexes", e);
        }
    }
}
Also used : HashMap(java.util.HashMap) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) NotFoundException(com.netflix.astyanax.connectionpool.exceptions.NotFoundException) Column(com.netflix.astyanax.model.Column) Keyspace(com.netflix.astyanax.Keyspace) Rows(com.netflix.astyanax.model.Rows)

Aggregations

Keyspace (com.netflix.astyanax.Keyspace)29 CompositeColumnName (com.emc.storageos.db.client.impl.CompositeColumnName)8 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)8 ColumnFamily (com.netflix.astyanax.model.ColumnFamily)8 Test (org.junit.Test)7 ClassNameTimeSeriesIndexColumnName (com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName)6 CheckResult (com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult)6 Column (com.netflix.astyanax.model.Column)6 Row (com.netflix.astyanax.model.Row)6 TimeSeriesIndexColumnName (com.emc.storageos.db.client.impl.TimeSeriesIndexColumnName)5 Rows (com.netflix.astyanax.model.Rows)5 IndexAndCf (com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.IndexAndCf)4 IndexColumnName (com.emc.storageos.db.client.impl.IndexColumnName)4 FileShare (com.emc.storageos.db.client.model.FileShare)4 Order (com.emc.storageos.db.client.model.uimodels.Order)4 CompositeIndexColumnName (com.emc.storageos.db.client.impl.CompositeIndexColumnName)3 DataObject (com.emc.storageos.db.client.model.DataObject)3 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)3 KeyspaceDefinition (com.netflix.astyanax.ddl.KeyspaceDefinition)3 URI (java.net.URI)3