Refine search
@Override public List<String> getListOfQueues() { logger.trace( "getListOfQueues " ); Statement select = QueryBuilder.select().all().from( TABLE_QUEUES ); ResultSet rs = cassandraClient.getApplicationSession().execute( select ); return rs.all().stream() .map( row -> row.getString( COLUMN_QUEUE_NAME )) .collect( Collectors.toList() ); }
private <T> T getValuesCQL( final MapScope scope, final Collection<String> keys, final ResultsBuilderCQL<T> builder ) { final List<ByteBuffer> serializedKeys = new ArrayList<>(); keys.forEach(key -> serializedKeys.add(getMapEntryPartitionKey(scope,key))); Clause in = QueryBuilder.in("key", serializedKeys ); Statement statement = QueryBuilder.select().all().from(MAP_ENTRIES_TABLE) .where(in); ResultSet resultSet = session.execute(statement); return builder.buildResultsCQL( resultSet ); }
@Override public List<SizeEstimate> getSizeEstimates(String keyspaceName, String tableName) { checkSizeEstimatesTableExist(); Statement statement = select("range_start", "range_end", "mean_partition_size", "partitions_count") .from(SYSTEM, SIZE_ESTIMATES) .where(eq("keyspace_name", keyspaceName)) .and(eq("table_name", tableName)); ResultSet result = executeWithSession(session -> session.execute(statement)); ImmutableList.Builder<SizeEstimate> estimates = ImmutableList.builder(); for (Row row : result.all()) { SizeEstimate estimate = new SizeEstimate( row.getString("range_start"), row.getString("range_end"), row.getLong("mean_partition_size"), row.getLong("partitions_count")); estimates.add(estimate); } return estimates.build(); }
private V readValueCQL(CacheScope scope, K key, TypeReference typeRef){ Preconditions.checkNotNull(scope, "scope is required"); Preconditions.checkNotNull(key, "key is required"); final String rowKeyString = scope.getApplication().getUuid().toString(); final int bucket = BUCKET_LOCATOR.getCurrentBucket(rowKeyString); // determine column name based on K key to string final String columnName = key.toString(); final Clause inKey = QueryBuilder.eq("key", getPartitionKey(scope, rowKeyString, bucket) ); final Clause inColumn = QueryBuilder.eq("column1", DataType.text().serialize(columnName, ProtocolVersion.NEWEST_SUPPORTED) ); final Statement statement = QueryBuilder.select().all().from(SCOPED_CACHE_TABLE) .where(inKey) .and(inColumn) .setConsistencyLevel(cassandraConfig.getDataStaxReadCl()); final ResultSet resultSet = session.execute(statement); final com.datastax.driver.core.Row row = resultSet.one(); if (row == null){ if(logger.isDebugEnabled()){ logger.debug("Cache value not found for key {}", key ); } return null; } try { return MAPPER.readValue(row.getBytes("value").array(), typeRef); } catch (IOException ioe) { logger.error("Unable to read cached value", ioe); throw new RuntimeException("Unable to read cached value", ioe); } }
@Override public Iterator<UniqueValue> getAllUniqueFields( final ApplicationScope collectionScope, final Id entityId ) { Preconditions.checkNotNull( collectionScope, "collectionScope is required" ); Preconditions.checkNotNull( entityId, "entity id is required" ); Clause inKey = QueryBuilder.in("key", getLogPartitionKey(collectionScope.getApplication(), entityId)); Statement statement = QueryBuilder.select().all().from(TABLE_UNIQUE_VALUES_LOG) .where(inKey); return new AllUniqueFieldsIterator(session, statement, entityId); }
@Override public void removeTransferLog( String queueName, String source, String dest, UUID messageId ) throws QakkaException { Statement query = QueryBuilder.select().all().from(TABLE_TRANSFER_LOG) .where( QueryBuilder.eq( COLUMN_QUEUE_NAME, queueName )) .and( QueryBuilder.eq( COLUMN_DEST_REGION, dest )) .and( QueryBuilder.eq( COLUMN_MESSAGE_ID, messageId )); ResultSet rs = cassandraClient.getApplicationSession().execute( query ); if ( rs.getAvailableWithoutFetching() == 0 ) { StringBuilder sb = new StringBuilder(); sb.append( "Transfer log entry not found for queueName=" ).append( queueName ); sb.append( " dest=" ).append( dest ); sb.append( " messageId=" ).append( messageId ); throw new QakkaException( sb.toString() ); } Statement deleteQuery = QueryBuilder.delete().from(TABLE_TRANSFER_LOG) .where( QueryBuilder.eq( COLUMN_QUEUE_NAME, queueName )) .and( QueryBuilder.eq( COLUMN_DEST_REGION, dest )) .and( QueryBuilder.eq( COLUMN_MESSAGE_ID, messageId )); cassandraClient.getApplicationSession().execute( deleteQuery ); }
@Override public Map<String, Object> getTokenInfo(UUID tokenUUID){ Preconditions.checkNotNull(tokenUUID, "token UUID is required"); List<ByteBuffer> tokenProperties = new ArrayList<>(); TOKEN_PROPERTIES.forEach( prop -> tokenProperties.add(DataType.serializeValue(prop, ProtocolVersion.NEWEST_SUPPORTED))); final ByteBuffer key = DataType.uuid().serialize(tokenUUID, ProtocolVersion.NEWEST_SUPPORTED); final Clause inKey = QueryBuilder.eq("key", key); final Clause inColumn = QueryBuilder.in("column1", tokenProperties ); final Statement statement = QueryBuilder.select().all().from(TOKENS_TABLE) .where(inKey) .and(inColumn) .setConsistencyLevel(cassandraConfig.getDataStaxReadCl()); final ResultSet resultSet = session.execute(statement); final List<Row> rows = resultSet.all(); Map<String, Object> tokenInfo = new HashMap<>(); rows.forEach( row -> { final String name = (String)DataType.text() .deserialize(row.getBytes("column1"), ProtocolVersion.NEWEST_SUPPORTED); final Object value = deserializeColumnValue(name, row.getBytes("value")); if (value == null){ throw new RuntimeException("error deserializing token info for property: "+name); } tokenInfo.put(name, value); }); logger.trace("getTokenInfo, info: {}", tokenInfo); return tokenInfo; }
/** * Get all entities from cassandra database. * @return <code>List</code> of entities */ public List<T> find() { LOG.debug("Get all entities from column family {}", getColumnFamilyName()); return findListByStatement( QueryBuilder.select() .all().from(getColumnFamilyName()) .setConsistencyLevel(getReadConsistencyLevel())); }
@Override public MapKeyResults getAllKeys(final MapScope scope, final String cursor, final int limit ){ final int[] buckets = BUCKET_LOCATOR.getAllBuckets( scope.getName() ); final List<ByteBuffer> partitionKeys = new ArrayList<>(NUM_BUCKETS.length); for (int bucket : buckets) { partitionKeys.add(getMapKeyPartitionKey(scope, bucket)); } Clause in = QueryBuilder.in("key", partitionKeys); Statement statement; if( isBlank(cursor) ){ statement = QueryBuilder.select().all().from(MAP_KEYS_TABLE) .where(in) .setFetchSize(limit); }else{ statement = QueryBuilder.select().all().from(MAP_KEYS_TABLE) .where(in) .setFetchSize(limit) .setPagingState(PagingState.fromString(cursor)); } ResultSet resultSet = session.execute(statement); PagingState pagingState = resultSet.getExecutionInfo().getPagingState(); final List<String> keys = new ArrayList<>(); Iterator<Row> resultIterator = resultSet.iterator(); int size = 0; while( resultIterator.hasNext() && size < limit){ size++; keys.add((String)DataType.text().deserialize(resultIterator.next().getBytes("column1"), ProtocolVersion.NEWEST_SUPPORTED)); } return new MapKeyResults(pagingState != null ? pagingState.toString() : null, keys); }
@Override public Result<AuditLog> getAuditLogs( UUID messageId ) { Statement query = QueryBuilder.select().all().from(TABLE_AUDIT_LOG) .where( QueryBuilder.eq( COLUMN_MESSAGE_ID, messageId ) ); ResultSet rs = cassandraClient.getApplicationSession().execute( query ); final List<AuditLog> auditLogs = rs.all().stream().map( row -> new AuditLog( AuditLog.Action.valueOf( row.getString( COLUMN_ACTION )), AuditLog.Status.valueOf( row.getString( COLUMN_STATUS )), row.getString( COLUMN_QUEUE_NAME ), row.getString( COLUMN_REGION ), row.getUUID( COLUMN_MESSAGE_ID ), row.getUUID( COLUMN_QUEUE_MESSAGE_ID ), row.getLong( COLUMN_TRANSFER_TIME ) ) ).collect( Collectors.toList() ); return new Result<AuditLog>() { @Override public PagingState getPagingState() { return null; // no paging } @Override public List<AuditLog> getEntities() { return auditLogs; } }; }
private ByteBuffer getValueCQL( MapScope scope, String key, final ConsistencyLevel consistencyLevel ) { Clause in = QueryBuilder.in("key", getMapEntryPartitionKey(scope, key) ); Statement statement = QueryBuilder.select().all().from(MAP_ENTRIES_TABLE) .where(in) .setConsistencyLevel(consistencyLevel); ResultSet resultSet = session.execute(statement); com.datastax.driver.core.Row row = resultSet.one(); return row != null ? row.getBytes("value") : null; }
@Override public CassandraEndpointProfile findEndpointIdByKeyHash(byte[] endpointKeyHash) { LOG.debug("Try to check if endpoint profile exists with key hash [{}]", Utils.encodeHexString(endpointKeyHash)); CassandraEndpointProfile profile = null; ResultSet resultSet = execute(select(EP_ENDPOINT_ID_PROPERTY).from(getColumnFamilyName()) .where(eq(EP_EP_KEY_HASH_PROPERTY, getByteBuffer(endpointKeyHash)))); Row row = resultSet.one(); if (row != null) { profile = new CassandraEndpointProfile(); profile.setId(row.getString(EP_ENDPOINT_ID_PROPERTY)); } LOG.debug("{} endpoint profile exists with key hash [{}]", Utils.encodeHexString(endpointKeyHash), profile); return profile; }
private void advance(){ Clause queueNameClause = QueryBuilder.eq( ShardSerializationImpl.COLUMN_QUEUE_NAME, queueName); Clause regionClause = QueryBuilder.eq( ShardSerializationImpl.COLUMN_REGION, region); Clause activeClause = QueryBuilder.eq( ShardSerializationImpl.COLUMN_ACTIVE, 1); Clause shardIdClause; if (nextStart == 0L && lastShardId.isPresent()) { shardIdClause = QueryBuilder.gt( ShardSerializationImpl.COLUMN_SHARD_ID, lastShardId.get() ); } else if (nextStart == 0L && !lastShardId.isPresent()) { shardIdClause = QueryBuilder.gte( ShardSerializationImpl.COLUMN_SHARD_ID, 0L ); } else { shardIdClause = QueryBuilder.gt( ShardSerializationImpl.COLUMN_SHARD_ID, nextStart ); } Statement query = QueryBuilder.select().all().from(ShardSerializationImpl.getTableName(shardType)) .where(queueNameClause) .and(regionClause) .and(activeClause) .and(shardIdClause) .limit(PAGE_SIZE); List<Row> rows = cassandraClient.getQueueMessageSession().execute(query).all(); currentIterator = getIteratorFromRows(rows); }
/** * @return cql query statement to retrieve the workflow_id for a particular task_id from the "task_lookup" table */ public String getSelectTaskFromLookupTableStatement() { return QueryBuilder.select(WORKFLOW_ID_KEY) .from(keyspace, TABLE_TASK_LOOKUP) .where(eq(TASK_ID_KEY, bindMarker())) .getQueryString(); }