@Override public String readString() { return read( StringSerializer.get() ); }
private ColumnFamily getLocksColumnFamily() { if ( columnFamily == null ) { columnFamily = ColumnFamily.newColumnFamily( CF_NAME, StringSerializer.get(), StringSerializer.get() ); if ( logger.isDebugEnabled() ) { try { final KeyspaceDefinition kd = keyspace.describeKeyspace(); final ColumnFamilyDefinition cfd = kd.getColumnFamily( columnFamily.getName() ); Map<String, Object> options = new HashMap<>( 1 ); options.put( "gc_grace_seconds", cfd.getGcGraceSeconds() ); options.put( "caching", cfd.getCaching() ); options.put( "compaction_strategy", cfd.getCompactionStrategy() ); options.put( "compaction_strategy_options", cfd.getCompactionStrategyOptions() ); logger.debug( "Locks column family {} exists with options: {}", cfd.getName(), options); } catch ( ConnectionException ce ) { logger.warn("Error connecting to Cassandra for debug column family info", ce); } } } return columnFamily; }
@Override public Health getHealth() { try { ColumnFamily<String, String> CF_SYSTEM_LOCAL = new ColumnFamily<String, String>( "system.local", StringSerializer.get(), StringSerializer.get(), StringSerializer.get() ); OperationResult<CqlResult<String, String>> result = keyspace.prepareQuery( CF_SYSTEM_LOCAL ) .setConsistencyLevel(ConsistencyLevel.CL_ONE) .withCql( "SELECT now() FROM system.local;" ) .execute(); if ( result.getResult().getRows().size() > 0 ) { return Health.GREEN; } } catch ( ConnectionException ex ) { logger.error( "Error connecting to Cassandra", ex ); } return Health.RED; } }
private ColumnFamily createLocksColumnFamily() throws ConnectionException { ColumnFamily<String, String> cflocks = ColumnFamily.newColumnFamily( CF_NAME, StringSerializer.get(), StringSerializer.get() ); final KeyspaceDefinition kd = keyspace.describeKeyspace(); final ColumnFamilyDefinition cfdef = kd.getColumnFamily( cflocks.getName() ); if ( cfdef == null ) { // create only if does not already exist MultiTenantColumnFamilyDefinition mtcfd = new MultiTenantColumnFamilyDefinition( cflocks, BytesType.class.getSimpleName(), UTF8Type.class.getSimpleName(), BytesType.class.getSimpleName(), MultiTenantColumnFamilyDefinition.CacheOption.ALL ); Map<String, Object> cfOptions = mtcfd.getOptions(); // Additionally set the gc grace low cfOptions.put( "gc_grace_seconds", 60 ); keyspace.createColumnFamily( mtcfd.getColumnFamily(), cfOptions ); logger.info( "Created column family {}", mtcfd.getOptions() ); cflocks = mtcfd.getColumnFamily(); } else { return getLocksColumnFamily(); } return cflocks; }
log.debug("Entity Wrapper Deserialized: " + StringSerializer.get().fromByteBuffer(byteBuffer));
@Override public EntityVersion fromByteBuffer(final ByteBuffer byteBuffer) { // would use Composites.newDynamicCompositeParser(byteBuffer) but it is not implemented DynamicComposite composite = DynamicComposite.fromByteBuffer(byteBuffer); Preconditions.checkArgument(composite.size() == 3, "Composite should have 3 elements"); final UUID version = composite.get( 0, UUIDSerializer.get() ); final UUID entityId = composite.get( 1, UUIDSerializer.get() ); final String entityType = composite.get( 2, StringSerializer.get() ); return new EntityVersion( new SimpleId( entityId, entityType ), version); }
public CassandraStorage(CassandraDataSegmentConfig config) { this.astyanaxContext = new AstyanaxContext.Builder() .forCluster(CLUSTER_NAME) .forKeyspace(config.getKeyspace()) .withAstyanaxConfiguration(new AstyanaxConfigurationImpl().setDiscoveryType(NodeDiscoveryType.NONE)) .withConnectionPoolConfiguration( new ConnectionPoolConfigurationImpl("MyConnectionPool").setMaxConnsPerHost(10) .setSeeds(config.getHost())).withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildKeyspace(ThriftFamilyFactory.getInstance()); this.astyanaxContext.start(); this.keyspace = this.astyanaxContext.getEntity(); this.config = config; indexStorage = new CassandraChunkedStorageProvider(keyspace, INDEX_TABLE_NAME); descriptorStorage = new ColumnFamily<String, String>(DESCRIPTOR_TABLE_NAME, StringSerializer.get(), StringSerializer.get()); } }
@Override public PreparedIndexExpression<K, C> value(String value) { this.value = StringSerializer.get().toByteBuffer(value); return this; }
@Override public CqlStatement withCql(String cql) { query = StringSerializer.get().toByteBuffer(cql); return this; }
public Collection<ByteBuffer> build() { List<ByteBuffer> shards = Lists.newArrayListWithExpectedSize(shardCount); for (int i = 0; i < shardCount; i++) { shards.add(StringSerializer.get().toByteBuffer(prefix + i)); } return shards; } }
@Override public CqlStatement withCql(String cql) { query = StringSerializer.get().toByteBuffer(cql); return this; }
@Override public CqlStatement withCql(String cql) { query = StringSerializer.get().toByteBuffer(cql); return this; }
@Override public V getValue() { //TODO: support types other than String as well return (V)astyanaxColumn.getValue(StringSerializer.get()); } @Override
final StringSerializer STR_SER = StringSerializer.get();
@Override protected org.apache.cassandra.thrift.CqlResult execute_cql_query(Client client) throws InvalidRequestException, UnavailableException, TimedOutException, SchemaDisagreementException, TException { return client.execute_cql_query( StringSerializer.get().toByteBuffer(cql), useCompression ? Compression.GZIP : Compression.NONE); } }
public AstyanaxCheckpointManager(Keyspace keyspace, String columnFamily, ByteBuffer bbKey) { this.keyspace = keyspace; this.bbKey = bbKey; this.columnFamily = ColumnFamily.newColumnFamily(columnFamily, ByteBufferSerializer.get(), StringSerializer.get()); }
private static Serializer getSerializer(CmbSerializer s) throws PersistenceException { if (s instanceof CmbStringSerializer) { return StringSerializer.get(); } else if (s instanceof CmbCompositeSerializer) { return CompositeSerializer.get(); } else if (s instanceof CmbLongSerializer) { return LongSerializer.get(); } throw new PersistenceException(CMBErrorCodes.InternalError, "Unknown serializer " + s); }
@Override public IndexQuery<K, C> value(String value) { internalExpression.setValue(StringSerializer.get().toBytes(value)); indexClause.addToExpressions(internalExpression); return getThisQuery(); }
private Composite toKeyName(List<Object> key) { Composite keyName = new Composite(); List<String> keyStrings = toKeyStrings(key); for (String componentString : keyStrings) { keyName.addComponent(componentString, StringSerializer.get()); } return keyName; }