com.netflix.astyanax.ddl.ColumnFamilyDefinition Java Examples

The following examples show how to use com.netflix.astyanax.ddl.ColumnFamilyDefinition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractPlacementFactory.java    From emodb with Apache License 2.0 6 votes vote down vote up
protected <C> ColumnFamily<ByteBuffer, C> getColumnFamily(KeyspaceDefinition keyspaceDef,
                                                          String prefix, String suffix, String placement,
                                                          Serializer<C> columnSerializer) throws IllegalArgumentException {
    // Create the column family object.  It must be keyed by a ByteBuffer because that's what
    // the AstyanaxTable.getRowKey() method returns.
    ColumnFamily<ByteBuffer, C> cf = new ColumnFamily<>(prefix + "_" + suffix,
            ByteBufferSerializer.get(), columnSerializer);

    // Verify that the column family exists in the Cassandra schema.
    ColumnFamilyDefinition cfDef = keyspaceDef.getColumnFamily(cf.getName());
    if (cfDef == null) {
        throw new UnknownPlacementException(format(
                "Placement string '%s' refers to unknown Cassandra %s column family in keyspace '%s': %s",
                placement, suffix, keyspaceDef.getName(), cf.getName()), placement);
    }
    return cf;
}
 
Example #2
Source File: AstyanaxStoreManager.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Override
public void clearStorage() throws BackendException {
    try {
        Cluster cluster = clusterContext.getClient();

        Keyspace ks = cluster.getKeyspace(keySpaceName);

        // Not a big deal if Keyspace doesn't not exist (dropped manually by user or tests).
        // This is called on per test setup basis to make sure that previous test cleaned
        // everything up, so first invocation would always fail as Keyspace doesn't yet exist.
        if (ks == null)
            return;

        for (ColumnFamilyDefinition cf : cluster.describeKeyspace(keySpaceName).getColumnFamilyList()) {
            ks.truncateColumnFamily(new ColumnFamily<Object, Object>(cf.getName(), null, null));
        }
    } catch (ConnectionException e) {
        throw new PermanentBackendException(e);
    }
}
 
Example #3
Source File: AstyanaxStoreManager.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, String> getCompressionOptions(String cf) throws BackendException {
    try {
        Keyspace k = keyspaceContext.getClient();

        KeyspaceDefinition kdef = k.describeKeyspace();

        if (null == kdef) {
            throw new PermanentBackendException("Keyspace " + k.getKeyspaceName() + " is undefined");
        }

        ColumnFamilyDefinition cfdef = kdef.getColumnFamily(cf);

        if (null == cfdef) {
            throw new PermanentBackendException("Column family " + cf + " is undefined");
        }

        return cfdef.getCompressionOptions();
    } catch (ConnectionException e) {
        throw new PermanentBackendException(e);
    }
}
 
Example #4
Source File: MigrationManagerImpl.java    From usergrid with Apache License 2.0 6 votes vote down vote up
/**
 * Check if the column family exists.  If it dosn't create it
 */
private void testAndCreateColumnFamilyDef( MultiTenantColumnFamilyDefinition columnFamily )
        throws ConnectionException {
    final KeyspaceDefinition keyspaceDefinition = keyspace.describeKeyspace();

    final ColumnFamilyDefinition existing =
            keyspaceDefinition.getColumnFamily( columnFamily.getColumnFamily().getName() );

    if ( existing != null ) {
        logger.info("Not creating columnfamily {}, it already exists.", columnFamily.getColumnFamily().getName());
        return;
    }

    keyspace.createColumnFamily( columnFamily.getColumnFamily(), columnFamily.getOptions() );

    // the CF def creation uses Asytanax, so manually check the schema agreement
    astyanaxWaitForSchemaAgreement();

    logger.info( "Created column family {}", columnFamily.getColumnFamily().getName() );

}
 
Example #5
Source File: AstyanaxLockManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
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;
    }
 
Example #6
Source File: AstyanaxLockManagerImpl.java    From usergrid with Apache License 2.0 3 votes vote down vote up
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;
    }