private void createLocksKeyspace() throws ConnectionException { try { KeyspaceDefinition keyspaceDefinition = keyspace.describeKeyspace(); if ( keyspaceDefinition != null ) { logger.info("Keyspace {} already exists", keyspace.getKeyspaceName()); return; } } catch (ConnectionException ce){ logger.debug( "Received a NotFoundException when attempting to describe keyspace. It does not exist" ); } ImmutableMap.Builder<String, Object> strategyOptions = getKeySpaceProps(); ImmutableMap<String, Object> options = ImmutableMap.<String, Object>builder().put("strategy_class", cassandraFig.getLocksKeyspaceStrategy()) .put("strategy_options", strategyOptions.build()).build(); keyspace.createKeyspace(options); logger.info("Keyspace {} created with options {}", keyspace.getKeyspaceName(), options.toString()); }
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; }
public static <K, C> void createColumnFamiliy(final Keyspace keyspace, final ColumnFamily<K, C> columnFamily, final Map<String, Object> options){ try{ if(keyspace.describeKeyspace().getColumnFamily(columnFamily.getName()) == null){ keyspace.createColumnFamily( columnFamily, new HashMap<String, Object>() ); } }catch(Exception e){ logger.error( "Error on creating column family, ignoring" , e); } } }
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; }
@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); } } }
/** * 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() ); }
if ( keyspace.describeKeyspace().getColumnFamily( "test" ) == null ) { keyspace.createColumnFamily( cf, new HashMap<String, Object>() );
private KeyspaceDefinition describe(CassandraKeyspace keyspace) { try { return keyspace.getAstyanaxKeyspace().describeKeyspace(); } catch (ConnectionException e) { throw Throwables.propagate(e); } } }
@Override public KeyspaceDefinition describeKeyspace() throws ConnectionException { return getPrimaryKS().describeKeyspace(); }
private KeyspaceDefinition describe(CassandraKeyspace keyspace) { try { return keyspace.getAstyanaxKeyspace().describeKeyspace(); } catch (ConnectionException e) { throw Throwables.propagate(e); } } }
private Keyspace createKeyspaceIfNotExists() { // Don't do in production; better to create from cqlsh to avoid parallel issues from eventual consistency. Keyspace ks = null; try { ks = keyspaceContext.getClient(); Properties props = new Properties(); props.setProperty("name", KEYSPACE_NAME); props.setProperty("strategy_class", "SimpleStrategy"); props.setProperty("strategy_options.replication_factor", "1"); ks.createKeyspaceIfNotExists(props); KeyspaceDefinition ksDef = ks.describeKeyspace(); } catch (Exception e) { logger.info("Didn't (re)create keyspace, message={}", e.getMessage()); } return ks; }
private Keyspace createKeyspaceIfNotExists() { // Don't do in production; better to create from cqlsh to avoid parallel issues from eventual consistency. Keyspace ks = null; try { ks = keyspaceContext.getClient(); Properties props = new Properties(); props.setProperty("name", KEYSPACE_NAME); props.setProperty("strategy_class", "SimpleStrategy"); props.setProperty("strategy_options.replication_factor", "1"); ks.createKeyspaceIfNotExists(props); KeyspaceDefinition ksDef = ks.describeKeyspace(); } catch (Exception e) { logger.info("Didn't (re)create keyspace, message={}", e.getMessage()); } return ks; }
if ( keyspace.describeKeyspace().getColumnFamily( CF_NAME ) == null ) { keyspace.createColumnFamily( testCf, null );
private void initColumnFamily() { try { final KeyspaceDefinition keyspaceDefinition = keyspace.describeKeyspace(); if (keyspaceDefinition.getColumnFamily(columnFamily.getName()) == null) { final Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("default_validation_class", "UTF8Type"); parameters.put("key_validation_class", "UTF8Type"); parameters.put("comparator_type", "UTF8Type"); keyspace.createColumnFamily(columnFamily, parameters); } } catch (final ConnectionException e) { throw new RuntimeException(e); } }
public ColumnFamilyDefinition describe(Keyspace keyspace) throws ConnectionException { KeyspaceDefinition ksDef = keyspace.describeKeyspace(); cfDef = ksDef.getColumnFamily(this.getName()); return cfDef; }
@Override public Placement newPlacement(String placement) throws ConnectionException { String[] parsed = PlacementUtil.parsePlacement(placement); String keyspaceName = parsed[0]; String cfPrefix = parsed[1]; CassandraKeyspace keyspace = _keyspaceMap.get(keyspaceName); if (keyspace == null) { throw new UnknownPlacementException(format( "Placement string refers to unknown or non-local Cassandra keyspace: %s", keyspaceName), placement); } KeyspaceDefinition keyspaceDef = keyspace.getAstyanaxKeyspace().describeKeyspace(); ColumnFamily<ByteBuffer,Composite> columnFamily = getColumnFamily(keyspaceDef, cfPrefix, "blob", placement, new SpecificCompositeSerializer(CompositeType.getInstance(Arrays.<AbstractType<?>>asList( AsciiType.instance, IntegerType.instance)))); return new BlobPlacement(placement, keyspace, columnFamily); }
public void start(Map<String, Object> config) { try { List<AstyanaxContext<Keyspace>> contexts = createContext(config); for (AstyanaxContext<Keyspace> context : contexts) { this.addAstyanaxContext(context.getKeyspaceName(), context); this.getAstyanaxContext(context.getKeyspaceName()).start(); // test the connection this.getKeyspace(context.getKeyspaceName()).describeKeyspace(); } } catch (Throwable e) { LOG.warn("Astyanax initialization failed.", e); throw new IllegalStateException("Failed to prepare Astyanax", e); } }
public void start() throws Exception { // Astyanax _astyanaxKeyspace = _astyanaxCluster.connect(_keyspaceName); _replication = new CassandraReplication(_astyanaxKeyspace.describeKeyspace()); _topologyAdapter = new ConsistencyTopologyAdapter(_replication); // CQL driver _cqlSession = _cqlCluster.connect(_keyspaceName); errorIfPartitionerMisconfigured(); }
public void start() throws Exception { // Astyanax _astyanaxKeyspace = _astyanaxCluster.connect(_keyspaceName); _replication = new CassandraReplication(_astyanaxKeyspace.describeKeyspace()); _topologyAdapter = new ConsistencyTopologyAdapter(_replication); // CQL driver _cqlSession = _cqlCluster.connect(_keyspaceName); errorIfPartitionerMisconfigured(); }
@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); } } }