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);
}
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations