Refine search
public CfDef toThrift() { CfDef d = new CfDef(keyspace, name); d.setColumn_metadata(ThriftColumnDef.toThriftList(columnMetadata)); d.setColumn_type(columnType.getValue()); d.setComment(comment); d.setComparator_type(comparatorType.getClassName() + comparatorTypeAlias); d.setDefault_validation_class(defaultValidationClass); d.setGc_grace_seconds(gcGraceSeconds); if ( id != 0) d.setId(id); d.setKey_cache_size(keyCacheSize); d.setKey_cache_save_period_in_seconds(keyCacheSavePeriodInSeconds); if(false || keyValidationClass != null) { d.setKey_validation_class(keyValidationClass + keyValidationAlias); } else { d.setKey_validation_class(keyValidationClass); d.setMax_compaction_threshold(maxCompactionThreshold); d.setMin_compaction_threshold(minCompactionThreshold); d.setRead_repair_chance(readRepairChance); d.setRow_cache_size(rowCacheSize); d.setReplicate_on_write(replicateOnWrite); d.setSubcomparator_type(subComparatorType.getClassName() + subComparatorTypeAlias); d.setCompaction_strategy(compactionStrategy); d.setCompaction_strategy_options(compactionStrategyOptions); d.setCompression_options(compressionOptions);
private void ensureColumnFamilyExists(String ksName, String cfName, String comparator) throws BackendException { CTConnection conn = null; try { KsDef keyspaceDef = ensureKeyspaceExists(ksName); conn = pool.borrowObject(ksName); Cassandra.Client client = conn.getClient(); log.debug("Looking up metadata on keyspace {}...", ksName); boolean foundColumnFamily = false; for (CfDef cfDef : keyspaceDef.getCf_defs()) { String curCfName = cfDef.getName(); if (curCfName.equals(cfName)) foundColumnFamily = true; } if (!foundColumnFamily) { createColumnFamily(client, ksName, cfName, comparator); } else { log.debug("Keyspace {} and ColumnFamily {} were found.", ksName, cfName); } } catch (SchemaDisagreementException e) { throw new TemporaryBackendException(e); } catch (Exception e) { throw new PermanentBackendException(e); } finally { pool.returnObjectUnsafe(ksName, conn); } }
private void createColumnFamily(Cassandra.Client client, String ksName, String cfName, String comparator) throws BackendException { CfDef createColumnFamily = new CfDef(); createColumnFamily.setName(cfName); createColumnFamily.setKeyspace(ksName); createColumnFamily.setComparator_type(comparator); ImmutableMap.Builder<String, String> compressionOptions = new ImmutableMap.Builder<String, String>(); if (compressionEnabled) { compressionOptions.put("sstable_compression", compressionClass) .put("chunk_length_kb", Integer.toString(compressionChunkSizeKB)); } createColumnFamily.setCompression_options(compressionOptions.build()); // Hard-coded caching settings if (cfName.startsWith(Backend.EDGESTORE_NAME)) { createColumnFamily.setCaching("keys_only"); } else if (cfName.startsWith(Backend.INDEXSTORE_NAME)) { createColumnFamily.setCaching("rows_only"); } log.debug("Adding column family {} to keyspace {}...", cfName, ksName); try { client.system_add_column_family(createColumnFamily); } catch (SchemaDisagreementException e) { throw new TemporaryBackendException("Error in setting up column family", e); } catch (Exception e) { throw new PermanentBackendException(e); } log.debug("Added column family {} to keyspace {}.", cfName, ksName); }
CfDef cf = new CfDef(); cf.setName(docColumnFamily); cf.setComparator_type("BytesType"); cf.setKey_cache_size(0); cf.setRow_cache_size(0); cf.setComment("Stores the document and field data for each doc with docId as key"); cf.setKeyspace(keySpace); cf = new CfDef(); cf.setName(termVecColumnFamily); cf.setComparator_type("lucandra.VIntType"); cf.setKey_cache_size(0); cf.setRow_cache_size(0); cf.setComment("Stores term information with indexName/field/term as composite key"); cf.setKeyspace(keySpace); cf = new CfDef(); cf.setName(fieldCacheColumnFamily); cf.setComparator_type("lucandra.VIntType"); cf.setKey_cache_size(0); cf.setRow_cache_size(0); cf.setComment("Stores term per doc per field"); cf.setKeyspace(keySpace); cf = new CfDef(); cf.setName(metaInfoColumnFamily); cf.setComparator_type("BytesType"); cf.setKey_cache_size(0); cf.setRow_cache_size(0);
@Override public Map<String, String> getCompressionOptions(String cf) throws BackendException { CTConnection conn = null; Map<String, String> result = null; try { conn = pool.borrowObject(keySpaceName); Cassandra.Client client = conn.getClient(); KsDef ksDef = client.describe_keyspace(keySpaceName); for (CfDef cfDef : ksDef.getCf_defs()) { if (null != cfDef && cfDef.getName().equals(cf)) { result = cfDef.getCompression_options(); break; } } return result; } catch (InvalidRequestException e) { log.debug("Keyspace {} does not exist", keySpaceName); return null; } catch (Exception e) { throw new TemporaryBackendException(e); } finally { pool.returnObjectUnsafe(keySpaceName, conn); } }
.getProperty(CassandraConstants.DEFAULT_VALIDATION_CLASS) : null; cfDef.setColumn_type(STANDARDCOLUMNFAMILY); cfDef.setComparator_type(UTF8Type.class.getSimpleName()); if (isCounterColumnType(tableInfo, defaultValidationClass)) ColumnDef columnDef = new ColumnDef(); if (columnInfo.isIndexable()) columnDef.setIndex_type(CassandraIndexHelper.getIndexType(indexInfo.getIndexType())); columnDef.setName(columnInfo.getColumnName().getBytes()); columnDef.setValidation_class(CassandraValidationClassMapper.getValidationClass( columnInfo.getType(), isCql3Enabled(tableInfo))); cfDef.setColumn_metadata(columnDefs);
String maxCompactionThreshold = cfProperties.getProperty(CassandraConstants.MAX_COMPACTION_THRESHOLD); if (maxCompactionThreshold != null) cfDef.setMax_compaction_threshold(Integer.parseInt(maxCompactionThreshold)); String minCompactionThreshold = cfProperties.getProperty(CassandraConstants.MIN_COMPACTION_THRESHOLD); if (minCompactionThreshold != null) cfDef.setMin_compaction_threshold(Integer.parseInt(minCompactionThreshold));
/** * On set comparator type. * * @param cfDef * the cf def * @param cfProperties * the cf properties * @param builder * the builder */ private void onSetComparatorType(CfDef cfDef, Properties cfProperties, StringBuilder builder) { String comparatorType = cfProperties.getProperty(CassandraConstants.COMPARATOR_TYPE); if (comparatorType != null) { if (builder != null) { // TODO:::nothing available. } else { cfDef.setComparator_type(comparatorType); } } }
/** * On set key validation. * * @param cfDef * the cf def * @param cfProperties * the cf properties * @param builder * the builder */ private void onSetKeyValidation(CfDef cfDef, Properties cfProperties, StringBuilder builder) { String keyValidationClass = cfProperties.getProperty(CassandraConstants.KEY_VALIDATION_CLASS); if (keyValidationClass != null) { if (builder != null) { // nothing available. } else { cfDef.setKey_validation_class(keyValidationClass); } } }
String gcGraceSeconds = cfProperties.getProperty(CassandraConstants.GC_GRACE_SECONDS); if (gcGraceSeconds != null) cfDef.setGc_grace_seconds(Integer.parseInt(gcGraceSeconds));
String comment = cfProperties.getProperty(CassandraConstants.COMMENT); if (comment != null) cfDef.setComment(comment);
String compactionStrategy = cfProperties.getProperty(CassandraConstants.COMPACTION_STRATEGY); if (compactionStrategy != null) cfDef.setCompaction_strategy(compactionStrategy);
CfDef user_Def = new CfDef(); user_Def.name = "PERSON"; user_Def.keyspace = "KunderaExamples"; user_Def.setComparator_type("UTF8Type"); user_Def.setDefault_validation_class("UTF8Type"); ColumnDef personName = new ColumnDef(ByteBuffer.wrap("PERSON_NAME".getBytes()), "UTF8Type"); personName.index_type = IndexType.KEYS; user_Def.addToColumn_metadata(personName); ColumnDef age = new ColumnDef(ByteBuffer.wrap("AGE".getBytes()), "IntegerType"); age.index_type = IndexType.KEYS; user_Def.addToColumn_metadata(age); ColumnDef reference_key = new ColumnDef(ByteBuffer.wrap("MANAGER_ID".getBytes()), "UTF8Type"); reference_key.index_type = IndexType.KEYS; user_Def.addToColumn_metadata(reference_key); ksDef = CassandraCli.client.describe_keyspace("KunderaExamples"); List<CfDef> cfDefn = ksDef.getCf_defs(); if (cfDef1.getName().equalsIgnoreCase("PERSON")) CassandraCli.client.system_drop_column_family("PERSON"); CassandraCli.client.system_add_column_family(user_Def); ksDef = new KsDef("KunderaExamples", "org.apache.cassandra.locator.SimpleStrategy", cfDefs);
org.apache.cassandra.thrift.CfDef def = new org.apache.cassandra.thrift.CfDef(ksName, cfName); def.setColumn_type(cfType.name()); def.setComparator_type(comparator.subtype(0).toString()); def.setSubcomparator_type(comparator.subtype(1).toString()); def.setComparator_type(comparator.toString()); def.setComment(Strings.nullToEmpty(comment)); def.setRead_repair_chance(readRepairChance); def.setDclocal_read_repair_chance(dcLocalReadRepairChance); def.setGc_grace_seconds(gcGraceSeconds); def.setDefault_validation_class(defaultValidator == null ? null : defaultValidator.toString()); def.setKey_validation_class(keyValidator.toString()); def.setMin_compaction_threshold(minCompactionThreshold); def.setMax_compaction_threshold(maxCompactionThreshold); def.setKey_alias(partitionKeyColumns.get(0).name.bytes); def.setColumn_metadata(ColumnDefinition.toThrift(columnMetadata)); def.setCompaction_strategy(compactionStrategyClass.getName()); def.setCompaction_strategy_options(new HashMap<>(compactionStrategyOptions)); def.setCompression_options(compressionParameters.asThriftOptions()); if (bloomFilterFpChance != null) def.setBloom_filter_fp_chance(bloomFilterFpChance); def.setMin_index_interval(minIndexInterval); def.setMax_index_interval(maxIndexInterval); def.setMemtable_flush_period_in_ms(memtableFlushPeriod); def.setCaching(caching.toThriftCaching()); def.setCells_per_row_to_cache(caching.toThriftCellsPerRow());
/** * Provides a basic column family definition. This is a subset of #getCfDef, and does not * include compression options, but also does not require raw metadata to be passed in. * * Warning to developers: you must update CKVS.isMatchingCf if you update this method */ static CfDef getStandardCfDef(String keyspace, String internalTableName) { CfDef cf = new CfDef(keyspace, internalTableName); cf.setComparator_type("CompositeType(BytesType,LongType)"); cf.setCompaction_strategy(CassandraConstants.LEVELED_COMPACTION_STRATEGY); cf.setCompression_options(Maps.<String, String>newHashMap()); cf.setGc_grace_seconds(CassandraConstants.DEFAULT_GC_GRACE_SECONDS); // explicitly set fields to default values cf.setCaching("KEYS_ONLY"); cf.setDclocal_read_repair_chance(0.1); cf.setTriggers(ImmutableList.of()); cf.setCells_per_row_to_cache("0"); cf.setMin_index_interval(128); cf.setMax_index_interval(2048); cf.setComment(""); cf.setColumn_metadata(ImmutableList.of()); cf.setMin_compaction_threshold(4); cf.setMax_compaction_threshold(32); cf.setKey_validation_class("org.apache.cassandra.db.marshal.BytesType"); cf.setCompaction_strategy_options(ImmutableMap.of()); cf.setDefault_validation_class("org.apache.cassandra.db.marshal.BytesType"); return cf; }
CfDef cfDef = new CfDef(cfDefToUpdate); cfDef.setColumn_type(CliUtils.unescapeSQLString(mValue)); break; case COMPARATOR: cfDef.setComparator_type(CliUtils.unescapeSQLString(mValue)); break; case SUBCOMPARATOR: cfDef.setSubcomparator_type(CliUtils.unescapeSQLString(mValue)); break; case COMMENT: cfDef.setComment(CliUtils.unescapeSQLString(mValue)); break; case READ_REPAIR_CHANCE: cfDef.setRead_repair_chance(chance); break; case DCLOCAL_READ_REPAIR_CHANCE: cfDef.setDclocal_read_repair_chance(localChance); break; case GC_GRACE: cfDef.setGc_grace_seconds(Integer.parseInt(mValue)); break; case COLUMN_METADATA: if (!arrayOfMetaAttributes.getText().equals("ARRAY")) throw new RuntimeException("'column_metadata' format - [{ k:v, k:v, ..}, { ... }, ...]"); cfDef.setColumn_metadata(getCFColumnMetaFromTree(cfDef, arrayOfMetaAttributes));
if (!cf_def.isSetComment()) cf_def.setComment(""); if (!cf_def.isSetMin_compaction_threshold()) cf_def.setMin_compaction_threshold(CompactionParams.DEFAULT_MIN_THRESHOLD); if (!cf_def.isSetMax_compaction_threshold()) cf_def.setMax_compaction_threshold(CompactionParams.DEFAULT_MAX_THRESHOLD); if (!cf_def.isSetCompaction_strategy()) cf_def.setCompaction_strategy(CompactionParams.DEFAULT.klass().getSimpleName()); if (!cf_def.isSetCompaction_strategy_options()) cf_def.setCompaction_strategy_options(Collections.emptyMap()); if (!cf_def.isSetCompression_options()) cf_def.setCompression_options(Collections.singletonMap(CompressionParams.SSTABLE_COMPRESSION, CompressionParams.DEFAULT.klass().getCanonicalName())); if (!cf_def.isSetDefault_time_to_live()) cf_def.setDefault_time_to_live(TableParams.DEFAULT_DEFAULT_TIME_TO_LIVE); if (!cf_def.isSetDclocal_read_repair_chance()) cf_def.setDclocal_read_repair_chance(TableParams.DEFAULT_DCLOCAL_READ_REPAIR_CHANCE); if (!cf_def.isSetMin_index_interval()) if (cf_def.isSetIndex_interval()) cf_def.setMin_index_interval(cf_def.getIndex_interval()); else cf_def.setMin_index_interval(TableParams.DEFAULT_MIN_INDEX_INTERVAL); if (!cf_def.isSetMax_index_interval()) cf_def.setMax_index_interval(Math.max(cf_def.min_index_interval, TableParams.DEFAULT_MAX_INDEX_INTERVAL));
client.set_keyspace("KunderaCoreExmples"); org.apache.cassandra.thrift.CfDef cf_def = new org.apache.cassandra.thrift.CfDef("KunderaCoreExmples", "CassandraEntitySimple"); cf_def.column_type = "Standard"; List<ColumnDef> column_metadata = new ArrayList<ColumnDef>(); ColumnDef def = new ColumnDef(); def.setName("AGE".getBytes()); def.setValidation_class("UTF8Type"); def.setIndex_type(IndexType.KEYS); cf_def.setColumn_metadata(column_metadata); client.system_add_column_family(cf_def); org.apache.cassandra.thrift.CfDef actor = new org.apache.cassandra.thrift.CfDef("KunderaCoreExmples", "Actor"); actor.column_type = "Super"; org.apache.cassandra.thrift.KsDef ksDef = client.describe_keyspace("KunderaCoreExmples"); Assert.assertEquals(2, ksDef.getCf_defs().size()); Assert.assertTrue(2 == ksDef.getCf_defs().get(0).getColumn_metadata().size() || 0 == ksDef.getCf_defs().get(0).getColumn_metadata().size()); Assert.assertTrue(1 == ksDef.getCf_defs().get(1).getColumn_metadata().size() || 1 == ksDef.getCf_defs().get(1).getColumn_metadata().size()); if ("CassandraEntitySimple".equals(cfDef.getName())) Assert.assertEquals("CassandraEntitySimple", cfDef.getName()); Assert.assertEquals("Standard", cfDef.getColumn_type());
CfDef user_Def = new CfDef(); user_Def.name = "users"; user_Def.keyspace = "KunderaExamples"; user_Def.setComparator_type("UTF8Type"); user_Def.setDefault_validation_class("UTF8Type"); user_Def.setKey_validation_class("UTF8Type"); ColumnDef columnDef = new ColumnDef(ByteBuffer.wrap("birth_date".getBytes()), "Int32Type"); columnDef.index_type = IndexType.KEYS; user_Def.addToColumn_metadata(columnDef); ColumnDef columnDef1 = new ColumnDef(ByteBuffer.wrap("state".getBytes()), "UTF8Type"); columnDef1.index_type = IndexType.KEYS; user_Def.addToColumn_metadata(columnDef1); ColumnDef columnDef2 = new ColumnDef(ByteBuffer.wrap("full_name".getBytes()), "UTF8Type"); columnDef2.index_type = IndexType.KEYS; user_Def.addToColumn_metadata(columnDef2); ksDef = new KsDef("KunderaExamples", "org.apache.cassandra.locator.SimpleStrategy", cfDefs); CassandraCli.client.system_add_keyspace(ksDef);
/** * Private helper to initialize a column family definition */ protected void initializeColumnFamilyDefinition() throws ClassNotFoundException { columnFamilyDefinition = new CfDef(); columnFamilyDefinition.setName(columnFamily); columnFamilyDefinition.setKeyspace(getKeySpace()); ColumnFamily cfAnnotation = target.getAnnotation(ColumnFamily.class); String comparatorType = cfAnnotation.compareWith().getName(); if (cfAnnotation.reversed()) { comparatorType = String.format("%s(reversed=true)", comparatorType); } columnFamilyDefinition.setComparator_type(comparatorType); columnFamilyDefinition.setKey_cache_size(cfAnnotation.keysCached()); columnFamilyDefinition.setRow_cache_size(cfAnnotation.rowsCached()); columnFamilyDefinition.setComment(StringUtils.defaultIfEmpty(cfAnnotation.comment(), null)); columnFamilyDefinition.setComparator_type(cfAnnotation.compareWith().getName()); columnFamilyDefinition.setRead_repair_chance(cfAnnotation.readRepairChance()); columnFamilyDefinition.setGc_grace_seconds(cfAnnotation.gcGraceSeconds()); columnFamilyDefinition.setDefault_validation_class(StringUtils.defaultIfEmpty(cfAnnotation.defaultValidationClass().getName(), null)); columnFamilyDefinition.setKey_validation_class(StringUtils.defaultIfEmpty(cfAnnotation.defaultKeyValidationClass().getName(), null)); columnFamilyDefinition.setMin_compaction_threshold(cfAnnotation.minCompactionThreshold()); columnFamilyDefinition.setMax_compaction_threshold(cfAnnotation.maxCompactionThreshold()); columnFamilyDefinition.setReplicate_on_write(cfAnnotation.replicateOnWrite()); }