private KeyspaceDefinition describe(CassandraKeyspace keyspace) { try { return keyspace.getAstyanaxKeyspace().describeKeyspace(); } catch (ConnectionException e) { throw Throwables.propagate(e); } } }
private ResultSet pingCql() throws Exception { return _keyspace.getCqlSession().execute(_healthCheckCql); } }
private MutationBatch mutation() { checkState(_open); if (_mutation == null) { _mutation = _keyspace.prepareMutationBatch(_consistencyLevel); } return _mutation; }
public void warnIfPartitionerMismatch(Class<? extends IPartitioner> expectedPartitioner) { String mismatchedPartitioner = getMismatchedPartitioner(expectedPartitioner); if (mismatchedPartitioner != null) { LoggerFactory.getLogger(CassandraKeyspace.class).warn( "Cassandra keyspace '{}' would perform better if it was configured with the {}. It currently uses the {}.", getName(), expectedPartitioner.getSimpleName(), mismatchedPartitioner); } }
@BeforeMethod public void setUp() throws Exception { CassandraKeyspace keyspace = mock(CassandraKeyspace.class); _astyanaxStatement = mock(CqlStatement.class); when(_astyanaxStatement.withCql(_queryString)).thenReturn(_astyanaxStatement); when(_astyanaxStatement.withConsistencyLevel(any())).thenReturn(_astyanaxStatement); Keyspace astyanaxKeyspace = mock(Keyspace.class); when(astyanaxKeyspace.prepareCqlStatement()).thenReturn(_astyanaxStatement); when(keyspace.getAstyanaxKeyspace()).thenReturn(astyanaxKeyspace); _cqlSession = mock(Session.class); when(keyspace.getCqlSession()).thenReturn(_cqlSession); _clock = mock(Clock.class); _healthCheck = new CassandraHealthCheck(keyspace, _queryString, _clock); }
try { List<CfSplit> splits = getCfSplits( keyspace.getAstyanaxKeyspace(), cf, splitWork.range.getStartToken(), splitWork.range.getEndToken(), splitWork.desiredRecordsPerSplit, allTokenRanges); splitWorkQueue.push( new ScanRangeSplitWorkItem(newWorkTokenRange, newWorkDesiredSize, false)); _log.debug("Decreasing scan range split to {} for keyspace {} and range {}", newWorkDesiredSize, keyspace.getName(), newWorkTokenRange); boolean retryOnTimeout = retryDesiredRecordsPerSplit < desiredRecordsPerSplit * 1000 && retryDesiredRecordsPerSplit != Integer.MAX_VALUE; splitWorkQueue.push(new ScanRangeSplitWorkItem(splitWork.range, retryDesiredRecordsPerSplit, retryOnTimeout)); _log.debug("Increasing scan range split to {} for keyspace {} and range {}", retryDesiredRecordsPerSplit, keyspace.getName(), splitWork.range); } else { builder.addScanRange(rack, rangeStart, ScanRange.create(begin, finish)); _log.warn("Unable to generate scan range split below {} for keyspace {} and range {}", splitWork.desiredRecordsPerSplit, keyspace.getName(), splitWork.range);
@Override public Map<UUID, String> loadSegments(String queue) { Map<UUID, String> resultMap = Maps.newHashMap(); Iterator<Column<UUID>> iter = executePaginated( _keyspace.prepareQuery(CF_DEDUP_MD, ConsistencyLevel.CL_LOCAL_QUORUM) .getKey(queue) .withColumnRange(new RangeBuilder().setLimit(100).build()) .autoPaginate(true)); while (iter.hasNext()) { Column<UUID> column = iter.next(); resultMap.put(column.getName(), column.getStringValue()); } return resultMap; }
@Override public String apply(CassandraKeyspace keyspace) { return keyspace.getClusterName(); } })));
/** * Because of the way databus tables were created historically using Astyanax and Cassandra 1.2 there may be * inconsistency in the names of the CQL columns in the subscription table. To be safe read the table metadata * to get the column names. */ private void getColumnNames() { TableMetadata table = _keyspace.getKeyspaceMetadata().getTable(CF_NAME); _rowkeyColumn = table.getPrimaryKey().get(0).getName(); _subscriptionNameColumn = table.getPrimaryKey().get(1).getName(); _subscriptionColumn = table.getColumns().get(2).getName(); } }
private void errorIfPartitionerMisconfigured() { String cassandraPartitioner = _cqlSession.getCluster().getMetadata().getPartitioner(); List<CassandraPartitioner> compatible = Lists.newArrayList(); for (CassandraPartitioner partitioner : CassandraPartitioner.values()) { if (partitioner.matches(cassandraPartitioner)) { return; } compatible.add(partitioner); } throw new IllegalStateException(format( "Cassandra keyspace '%s' uses the %s. The application connection pool 'partitioner' setting must be set to %s.", getName(), cassandraPartitioner.substring(cassandraPartitioner.lastIndexOf('.') + 1), Joiner.on(" or ").join(Collections2.transform(compatible, new Function<CassandraPartitioner, Object>() { @Override public Object apply(CassandraPartitioner partitioner) { return "'" + partitioner.name().toLowerCase() + "'"; } })))); }
@Override public void start() throws Exception { // Range queries depend on using the ByteOrderedPartitioner. Hard fail if something else is configured. for (CassandraKeyspace keyspace : _keyspaceMap.values()) { keyspace.errorIfPartitionerMismatch(ByteOrderedPartitioner.class); } }
try { List<CfSplit> splits = getCfSplits( keyspace.getAstyanaxKeyspace(), cf, splitWork.range.getStartToken(), splitWork.range.getEndToken(), splitWork.desiredRecordsPerSplit, allTokenRanges); splitWorkQueue.push( new AstyanaxBlockedDataReaderDAO.ScanRangeSplitWorkItem(newWorkTokenRange, newWorkDesiredSize, false)); _log.debug("Decreasing scan range split to {} for keyspace {} and range {}", newWorkDesiredSize, keyspace.getName(), newWorkTokenRange); boolean retryOnTimeout = retryDesiredRecordsPerSplit < desiredRecordsPerSplit * 1000 && retryDesiredRecordsPerSplit != Integer.MAX_VALUE; splitWorkQueue.push(new AstyanaxBlockedDataReaderDAO.ScanRangeSplitWorkItem(splitWork.range, retryDesiredRecordsPerSplit, retryOnTimeout)); _log.debug("Increasing scan range split to {} for keyspace {} and range {}", retryDesiredRecordsPerSplit, keyspace.getName(), splitWork.range); } else { builder.addScanRange(rack, rangeStart, ScanRange.create(begin, finish)); _log.warn("Unable to generate scan range split below {} for keyspace {} and range {}", splitWork.desiredRecordsPerSplit, keyspace.getName(), splitWork.range);
@Override public Map<UUID, String> loadSegments(String queue) { Map<UUID, String> resultMap = Maps.newHashMap(); Iterator<Column<UUID>> iter = executePaginated( _keyspace.prepareQuery(CF_DEDUP_MD, ConsistencyLevel.CL_LOCAL_QUORUM) .getKey(queue) .withColumnRange(new RangeBuilder().setLimit(100).build()) .autoPaginate(true)); while (iter.hasNext()) { Column<UUID> column = iter.next(); resultMap.put(column.getName(), column.getStringValue()); } return resultMap; }
@Override public String apply(CassandraKeyspace keyspace) { return keyspace.getClusterName(); } })));
public void errorIfPartitionerMismatch(Class<? extends IPartitioner> expectedPartitioner) { String mismatchedPartitioner = getMismatchedPartitioner(expectedPartitioner); if (mismatchedPartitioner != null) { throw new IllegalStateException(format( "Cassandra keyspace '%s' must be configured with the %s. It currently uses %s.", getName(), expectedPartitioner.getSimpleName(), mismatchedPartitioner)); } }
/** * Because of the way databus tables were created historically using Astyanax and Cassandra 1.2 there may be * inconsistency in the names of the CQL columns in the subscription table. To be safe read the table metadata * to get the column names. */ private void getColumnNames() { TableMetadata table = _keyspace.getKeyspaceMetadata().getTable(CF_NAME); _rowkeyColumn = table.getPrimaryKey().get(0).getName(); _subscriptionNameColumn = table.getPrimaryKey().get(1).getName(); _subscriptionColumn = table.getColumns().get(2).getName(); } }
private void errorIfPartitionerMisconfigured() { String cassandraPartitioner = _cqlSession.getCluster().getMetadata().getPartitioner(); List<CassandraPartitioner> compatible = Lists.newArrayList(); for (CassandraPartitioner partitioner : CassandraPartitioner.values()) { if (partitioner.matches(cassandraPartitioner)) { return; } compatible.add(partitioner); } throw new IllegalStateException(format( "Cassandra keyspace '%s' uses the %s. The application connection pool 'partitioner' setting must be set to %s.", getName(), cassandraPartitioner.substring(cassandraPartitioner.lastIndexOf('.') + 1), Joiner.on(" or ").join(Collections2.transform(compatible, new Function<CassandraPartitioner, Object>() { @Override public Object apply(CassandraPartitioner partitioner) { return "'" + partitioner.name().toLowerCase() + "'"; } })))); }
@Override public void start() throws Exception { // Range queries depend on using the ByteOrderedPartitioner. Hard fail if something else is configured. for (CassandraKeyspace keyspace : _keyspaceMap.values()) { keyspace.errorIfPartitionerMismatch(ByteOrderedPartitioner.class); } }
private ResultSet pingCql() throws Exception { return _keyspace.getCqlSession().execute(_healthCheckCql); } }
private KeyspaceDefinition describe(CassandraKeyspace keyspace) { try { return keyspace.getAstyanaxKeyspace().describeKeyspace(); } catch (ConnectionException e) { throw Throwables.propagate(e); } } }