Search in sources :

Example 26 with Keyspace

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

the class DbConsistencyCheckerHelper method getIndicesOfCF.

public Map<String, IndexAndCf> getIndicesOfCF(DataObjectType objType) {
    Map<String, IndexAndCf> idxCfs = new TreeMap<>();
    Keyspace keyspace = dbClient.getKeyspace(objType.getDataObjectClass());
    for (ColumnField field : objType.getColumnFields()) {
        DbIndex index = field.getIndex();
        if (index == null) {
            continue;
        }
        IndexAndCf indexAndCf = new IndexAndCf(index.getClass(), field.getIndexCF(), keyspace);
        String key = indexAndCf.generateKey();
        IndexAndCf idxAndCf = idxCfs.get(key);
        if (idxAndCf == null) {
            idxAndCf = new IndexAndCf(index.getClass(), field.getIndexCF(), keyspace);
            idxCfs.put(key, idxAndCf);
        }
    }
    return idxCfs;
}
Also used : Keyspace(com.netflix.astyanax.Keyspace) TreeMap(java.util.TreeMap)

Example 27 with Keyspace

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

the class DbClientImpl method scanRowsByType.

private <T extends DataObject> Iterable<Row<String, CompositeColumnName>> scanRowsByType(Class<T> clazz, Boolean inactiveValue, URI startId, int count) {
    DataObjectType doType = TypeMap.getDoType(clazz);
    if (doType == null) {
        throw new IllegalArgumentException();
    }
    try {
        ColumnFamily<String, CompositeColumnName> cf = doType.getCF();
        Keyspace ks = getKeyspace(clazz);
        ColumnFamilyQuery<String, CompositeColumnName> query = ks.prepareQuery(cf);
        // Column filter, get only last .inactive column, or get any column
        ByteBufferRange columnRange = inactiveValue == null ? CompositeColumnNameSerializer.get().buildRange().limit(1).build() : CompositeColumnNameSerializer.get().buildRange().greaterThanEquals(DataObject.INACTIVE_FIELD_NAME).lessThanEquals(DataObject.INACTIVE_FIELD_NAME).reverse().limit(1).build();
        Execution<Rows<String, CompositeColumnName>> exec;
        if (count == Integer.MAX_VALUE) {
            exec = query.getAllRows().withColumnRange(columnRange);
        } else {
            Partitioner partitioner = ks.getPartitioner();
            String strKey = startId != null ? startId.toString() : null;
            String startToken = strKey != null ? partitioner.getTokenForKey(cf.getKeySerializer().toByteBuffer(strKey)) : partitioner.getMinToken();
            exec = query.getRowRange(strKey, null, startToken, partitioner.getMaxToken(), count).withColumnRange(columnRange);
        }
        return exec.execute().getResult();
    } catch (ConnectionException e) {
        throw DatabaseException.retryables.connectionFailed(e);
    }
}
Also used : Keyspace(com.netflix.astyanax.Keyspace) ByteBufferRange(com.netflix.astyanax.model.ByteBufferRange) Partitioner(com.netflix.astyanax.partitioner.Partitioner) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) Rows(com.netflix.astyanax.model.Rows)

Example 28 with Keyspace

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

the class DbClientImpl method aggregateObjectField.

@Override
public <T extends DataObject> void aggregateObjectField(Class<T> clazz, Iterator<URI> ids, DbAggregatorItf aggregator) {
    tracer.newTracer("read");
    DataObjectType doType = TypeMap.getDoType(clazz);
    if (doType == null) {
        throw new IllegalArgumentException();
    }
    boolean buildRange = false;
    String[] fields = aggregator.getAggregatedFields();
    CompositeColumnName[] columns = new CompositeColumnName[fields.length];
    for (int ii = 0; ii < fields.length; ii++) {
        ColumnField columnField = doType.getColumnField(fields[ii]);
        if (columnField == null) {
            throw new IllegalArgumentException();
        }
        if (fields.length > 1) {
            // ***** multiple columns aggregation can be done only for non-indexed columns. ******
            if (columnField.getIndex() != null || columnField.getType() != ColumnField.ColumnType.Primitive) {
                throw DatabaseException.fatals.queryFailed(new Exception("... "));
            }
        } else if (columnField.getIndex() != null) {
            buildRange = true;
        }
        columns[ii] = new CompositeColumnName(columnField.getName());
    }
    List<String> idList = new ArrayList<String>();
    while (ids.hasNext()) {
        idList.clear();
        for (int ii = 0; ii < DEFAULT_BATCH_SIZE && ids.hasNext(); ii++) {
            idList.add(ids.next().toString());
        }
        Keyspace ks = getKeyspace(clazz);
        aggregateObjectFieldBatch(aggregator, ks, idList, doType, buildRange, columns);
    }
}
Also used : Constraint(com.emc.storageos.db.client.constraint.Constraint) DecommissionedConstraint(com.emc.storageos.db.client.constraint.DecommissionedConstraint) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) IOException(java.io.IOException) FatalDatabaseException(com.emc.storageos.db.exceptions.FatalDatabaseException) Keyspace(com.netflix.astyanax.Keyspace)

Example 29 with Keyspace

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

the class InternalDbClient method getGeoStrategyOptions.

public Map<String, String> getGeoStrategyOptions() throws ConnectionException {
    Keyspace ks = getGeoKeyspace();
    KeyspaceDefinition ksDef = ks.describeKeyspace();
    return ksDef.getStrategyOptions();
}
Also used : KeyspaceDefinition(com.netflix.astyanax.ddl.KeyspaceDefinition) Keyspace(com.netflix.astyanax.Keyspace)

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