Search in sources :

Example 16 with Keyspace

use of com.netflix.astyanax.Keyspace in project janusgraph by JanusGraph.

the class AstyanaxStoreManager method getCompressionOptions.

@Override
public Map<String, String> getCompressionOptions(String cf) throws BackendException {
    try {
        Keyspace k = keyspaceContext.getClient();
        KeyspaceDefinition keyspaceDefinition = k.describeKeyspace();
        if (null == keyspaceDefinition) {
            throw new PermanentBackendException("Keyspace " + k.getKeyspaceName() + " is undefined");
        }
        ColumnFamilyDefinition columnFamilyDefinition = keyspaceDefinition.getColumnFamily(cf);
        if (null == columnFamilyDefinition) {
            throw new PermanentBackendException("Column family " + cf + " is undefined");
        }
        return columnFamilyDefinition.getCompressionOptions();
    } catch (ConnectionException e) {
        throw new PermanentBackendException(e);
    }
}
Also used : KeyspaceDefinition(com.netflix.astyanax.ddl.KeyspaceDefinition) ColumnFamilyDefinition(com.netflix.astyanax.ddl.ColumnFamilyDefinition) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) Keyspace(com.netflix.astyanax.Keyspace) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 17 with Keyspace

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

the class PersistingChangesTest method getIndexRecordCount.

private int getIndexRecordCount(String fieldName) throws ConnectionException {
    Keyspace keyspace = ((DbClientTest.DbClientImplUnitTester) dbClient).getLocalContext().getKeyspace();
    DataObjectType doType = TypeMap.getDoType(Volume.class);
    ColumnField field = doType.getColumnField(fieldName);
    ColumnFamilyQuery<String, IndexColumnName> query = keyspace.prepareQuery(field.getIndexCF());
    OperationResult<Rows<String, IndexColumnName>> result = query.getAllRows().execute();
    int count = 0;
    for (Row<String, IndexColumnName> row : result.getResult()) {
        _log.debug("{}, RowKey={}, Columns Size={}", ++count, row.getKey(), row.getColumns().size());
        for (Column<IndexColumnName> column : row.getColumns()) {
            _log.debug("\t, Column Name={}, String Value={}.", column.getName(), column.getStringValue());
        }
    }
    return count;
}
Also used : IndexColumnName(com.emc.storageos.db.client.impl.IndexColumnName) Keyspace(com.netflix.astyanax.Keyspace) ColumnField(com.emc.storageos.db.client.impl.ColumnField) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) com.emc.storageos.db.client.constraint(com.emc.storageos.db.client.constraint) DbClientTest(com.emc.storageos.db.server.DbClientTest) Rows(com.netflix.astyanax.model.Rows)

Example 18 with Keyspace

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

the class InternalDbClient method removeFieldIndex.

public <T extends DataObject> void removeFieldIndex(Class<T> clazz, String fieldName, String indexCf) {
    log.debug("removing index records for " + clazz.getSimpleName() + ":" + fieldName + " from index cf table: " + indexCf);
    DataObjectType doType = TypeMap.getDoType(clazz);
    if (doType == null) {
        throw new IllegalArgumentException();
    }
    ColumnField columnField = doType.getColumnField(fieldName);
    if (columnField == null) {
        throw new IllegalArgumentException();
    }
    List<URI> allrecs = queryByType(clazz, false);
    Keyspace ks = getKeyspace(clazz);
    Iterator<URI> recIt = allrecs.iterator();
    List<URI> batch = getNextBatch(recIt);
    while (!batch.isEmpty()) {
        Rows<String, CompositeColumnName> rows = queryRowsWithAColumn(ks, batch, doType.getCF(), columnField);
        Iterator<Row<String, CompositeColumnName>> it = rows.iterator();
        Map<String, List<Column<CompositeColumnName>>> removeList = new HashMap<String, List<Column<CompositeColumnName>>>();
        while (it.hasNext()) {
            Row<String, CompositeColumnName> row = it.next();
            if (row.getColumns().size() == 0) {
                continue;
            }
            Iterator<Column<CompositeColumnName>> columnIterator = row.getColumns().iterator();
            while (columnIterator.hasNext()) {
                Column<CompositeColumnName> column = columnIterator.next();
                if (removeList.get(row.getKey()) == null) {
                    removeList.put(row.getKey(), new ArrayList<Column<CompositeColumnName>>());
                }
                removeList.get(row.getKey()).add(column);
            }
        }
        boolean retryFailedWriteWithLocalQuorum = shouldRetryFailedWriteWithLocalQuorum(clazz);
        RowMutator mutator = new RowMutator(ks, retryFailedWriteWithLocalQuorum);
        _indexCleaner.removeOldIndex(mutator, doType, removeList, indexCf);
        batch = getNextBatch(recIt);
    }
}
Also used : URI(java.net.URI) Column(com.netflix.astyanax.model.Column) Keyspace(com.netflix.astyanax.Keyspace) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Row(com.netflix.astyanax.model.Row)

Example 19 with Keyspace

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

the class MigrationHandlerImpl method disableGeoAccess.

/*
     * don't allow geo db migration callback.
     */
private DbClientContext disableGeoAccess() {
    log.info("disable geo access temporary since we don't support geo db migration callback now");
    DbClientContext geoContext = this.dbClient.getGeoContext();
    this.dbClient.setGeoContext(new DbClientContext() {

        @Override
        public Keyspace getKeyspace() {
            log.error("doesn't support migration callback for Geo");
            for (StackTraceElement st : Thread.currentThread().getStackTrace()) {
                log.error(st.getClassName() + ":" + st.getMethodName() + ", (" + st.getLineNumber() + ") \n");
            }
            throw new IllegalArgumentException("doesn't support migration callback for Geo");
        }
    });
    return geoContext;
}
Also used : DbClientContext(com.emc.storageos.db.client.impl.DbClientContext) Keyspace(com.netflix.astyanax.Keyspace)

Example 20 with Keyspace

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

the class TimeSeriesIndexMigration method process.

@Override
public void process() throws MigrationCallbackException {
    log.info("Adding new index records for class: {} field: {} annotation: {}", new Object[] { Order.class.getName(), Order.SUBMITTED, TimeSeriesAlternateId.class.getName() });
    ColumnFamily<String, IndexColumnName> tenantToOrder = new ColumnFamily<>(SOURCE_INDEX_CF_NAME, StringSerializer.get(), IndexColumnNameSerializer.get());
    ColumnFamily<String, IndexColumnName> timeseriesIndex = new ColumnFamily<>(SOURCE_INDEX_CF_NAME2, StringSerializer.get(), IndexColumnNameSerializer.get());
    DataObjectType doType = TypeMap.getDoType(Order.class);
    ColumnField field = doType.getColumnField(Order.SUBMITTED);
    ColumnFamily<String, TimeSeriesIndexColumnName> newIndexCF = field.getIndexCF();
    DbClientImpl client = (DbClientImpl) dbClient;
    Keyspace ks = client.getKeyspace(Order.class);
    List<CompletableFuture<Void>> tasks = new ArrayList(TASK_SIZE);
    try {
        OperationResult<Rows<String, IndexColumnName>> result = ks.prepareQuery(tenantToOrder).getAllRows().setRowLimit(1000).withColumnRange(new RangeBuilder().setLimit(0).build()).execute();
        for (Row<String, IndexColumnName> row : result.getResult()) {
            RowQuery<String, IndexColumnName> rowQuery = ks.prepareQuery(tenantToOrder).getKey(row.getKey()).autoPaginate(true).withColumnRange(new RangeBuilder().setLimit(5).build());
            ColumnList<IndexColumnName> cols = rowQuery.execute().getResult();
            while (!cols.isEmpty()) {
                if (tasks.size() < TASK_SIZE) {
                    CompletableFuture<Void> task = CompletableFuture.runAsync(new MigrationTask(ks, row.getKey(), cols, tenantToOrder, timeseriesIndex, newIndexCF));
                    tasks.add(task);
                } else {
                    CompletableFuture.allOf(tasks.toArray(new CompletableFuture[0])).join();
                    tasks = new ArrayList(TASK_SIZE);
                }
                cols = rowQuery.execute().getResult();
            }
        }
        if (!tasks.isEmpty()) {
            CompletableFuture.allOf(tasks.toArray(new CompletableFuture[0])).join();
        }
    } catch (Exception e) {
        log.error("Migration to {} failed e=", newIndexCF.getName(), e);
    }
}
Also used : RangeBuilder(com.netflix.astyanax.util.RangeBuilder) CompositeRangeBuilder(com.netflix.astyanax.serializers.CompositeRangeBuilder) ArrayList(java.util.ArrayList) CompletableFuture(java.util.concurrent.CompletableFuture) Order(com.emc.storageos.db.client.model.uimodels.Order) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) TimeSeriesAlternateId(com.emc.storageos.db.client.model.TimeSeriesAlternateId) 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