public static CachingOptions fromMap(Map<String, String> cacheConfig) throws ConfigurationException { validateCacheConfig(cacheConfig); if (!cacheConfig.containsKey("keys") && !cacheConfig.containsKey("rows_per_partition")) return CachingOptions.NONE; if (!cacheConfig.containsKey("keys")) return new CachingOptions(new KeyCache(KeyCache.Type.NONE), RowCache.fromString(cacheConfig.get("rows_per_partition"))); if (!cacheConfig.containsKey("rows_per_partition")) return CachingOptions.KEYS_ONLY; return new CachingOptions(KeyCache.fromString(cacheConfig.get("keys")), RowCache.fromString(cacheConfig.get("rows_per_partition"))); }
public static CachingOptions fromString(String cache) throws ConfigurationException { if (legacyOptions.contains(cache.toUpperCase())) return fromLegacyOption(cache.toUpperCase()); return fromMap(fromJsonMap(cache)); }
private static void migrateCachingOption() { for (UntypedResultSet.Row row : executeOnceInternal(String.format("SELECT * FROM system.%s", SCHEMA_COLUMNFAMILIES_CF))) { if (!row.has("caching")) continue; if (!CachingOptions.isLegacy(row.getString("caching"))) continue; try { CachingOptions caching = CachingOptions.fromString(row.getString("caching")); CFMetaData table = CFMetaData.fromSchema(row); logger.info("Migrating caching option {} to {} for {}.{}", row.getString("caching"), caching.toString(), table.ksName, table.cfName); String query = String.format("SELECT writetime(type) FROM system.%s WHERE keyspace_name = ? AND columnfamily_name = ?", SCHEMA_COLUMNFAMILIES_CF); long timestamp = executeOnceInternal(query, table.ksName, table.cfName).one().getLong("writetime(type)"); table.toSchema(timestamp).apply(); } catch (ConfigurationException e) { // shouldn't happen } } }
public CachingOptions getCachingOptions() throws SyntaxException, ConfigurationException { CachingOptions options = null; Object val = properties.get(KW_CACHING); if (val == null) return null; else if (val instanceof Map) options = CachingOptions.fromMap(getMap(KW_CACHING)); else if (val instanceof String) // legacy syntax { options = CachingOptions.fromString(getSimple(KW_CACHING)); logger.warn("Setting caching options with deprecated syntax."); } return options; }
public static CachingOptions fromThrift(String caching, String cellsPerRow) throws ConfigurationException { RowCache rc = new RowCache(RowCache.Type.NONE); KeyCache kc = new KeyCache(KeyCache.Type.ALL); // if we get a caching string from thrift it is legacy, "ALL", "KEYS_ONLY" etc, fromString handles those if (caching != null) { CachingOptions givenOptions = CachingOptions.fromString(caching); rc = givenOptions.rowCache; kc = givenOptions.keyCache; } // if we get cells_per_row from thrift, it is either "ALL" or "<number of cells to cache>". if (cellsPerRow != null && rc.isEnabled()) rc = RowCache.fromString(cellsPerRow); return new CachingOptions(kc, rc); }
cfm.minCompactionThreshold(minCompactionThreshold); cfm.maxCompactionThreshold(maxCompactionThreshold); cfm.caching(CachingOptions.fromString(cfProps.getPropertyString(CFPropDefs.KW_CACHING, cfm.getCaching().toString()))); cfm.defaultTimeToLive(cfProps.getPropertyInt(CFPropDefs.KW_DEFAULT_TIME_TO_LIVE, cfm.getDefaultTimeToLive())); cfm.speculativeRetry(CFMetaData.SpeculativeRetry.fromString(cfProps.getPropertyString(CFPropDefs.KW_SPECULATIVE_RETRY, cfm.getSpeculativeRetry().toString())));
def.setMax_index_interval(maxIndexInterval); def.setMemtable_flush_period_in_ms(memtableFlushPeriod); def.setCaching(caching.toThriftCaching()); def.setCells_per_row_to_cache(caching.toThriftCellsPerRow()); def.setDefault_time_to_live(defaultTimeToLive); def.setSpeculative_retry(speculativeRetry.toString());
.compactionStrategyOptions(cfProps.compactionStrategyOptions) .compressionParameters(CompressionParameters.create(cfProps.compressionParameters)) .caching(CachingOptions.fromString(getPropertyString(CFPropDefs.KW_CACHING, CFMetaData.DEFAULT_CACHING_STRATEGY.toString()))) .speculativeRetry(CFMetaData.SpeculativeRetry.fromString(getPropertyString(CFPropDefs.KW_SPECULATIVE_RETRY, CFMetaData.DEFAULT_SPECULATIVE_RETRY.toString()))) .bloomFilterFpChance(getPropertyDouble(CFPropDefs.KW_BF_FP_CHANCE, null))
adder.add("caching", caching.toString()); adder.add("default_time_to_live", defaultTimeToLive); adder.add("compaction_strategy_class", compactionStrategyClass.getName());
newCFMD.memtableFlushPeriod(cf_def.memtable_flush_period_in_ms); if (cf_def.isSetCaching() || cf_def.isSetCells_per_row_to_cache()) newCFMD.caching(CachingOptions.fromThrift(cf_def.caching, cf_def.cells_per_row_to_cache)); if (cf_def.isSetRead_repair_chance()) newCFMD.readRepairChance(cf_def.read_repair_chance);
if (result.has("memtable_flush_period_in_ms")) cfm.memtableFlushPeriod(result.getInt("memtable_flush_period_in_ms")); cfm.caching(CachingOptions.fromString(result.getString("caching"))); if (result.has("default_time_to_live")) cfm.defaultTimeToLive(result.getInt("default_time_to_live"));