.setCf_defs(new LinkedList<CfDef>()) // cannot be null but can be empty .setStrategy_class(storageConfig.get(REPLICATION_STRATEGY)) .setStrategy_options(strategyOptions);
.setName(keySpace) .setStrategy_class("org.apache.cassandra.locator.SimpleStrategy") .setStrategy_options(strategyOptions) .setCf_defs(cfs);
private static KsDef setNetworkStrategyIfCheckedTopology(KsDef ksDef, CassandraKeyValueServiceConfig config, Set<String> datacenters) { if (!config.ignoreNodeTopologyChecks()) { ksDef.setStrategy_class(CassandraConstants.NETWORK_STRATEGY); ksDef.setStrategy_options(ImmutableMap.of(Iterables.getOnlyElement(datacenters), "1")); } return ksDef; }
public KsDef toThrift() { KsDef def = new KsDef(name, strategyClass, ThriftCfDef.toThriftList(cfDefs)); def.setStrategy_options(strategyOptions); def.setDurable_writes(durableWrites ); return def; }
static KsDef createKsDefForFresh(CassandraClient client, CassandraKeyValueServiceConfig config) throws TException { KsDef ksDef = new KsDef(config.getKeyspaceOrThrow(), CassandraConstants.NETWORK_STRATEGY, ImmutableList.of()); Set<String> dcs = sanityCheckDatacenters(client, config); ksDef.setStrategy_options(Maps.asMap(dcs, ignore -> String.valueOf(config.replicationFactor()))); ksDef.setDurable_writes(true); return ksDef; }
/** * Creates keyspace. * * @throws Exception * the exception */ private void createKeyspace() throws Exception { if (cql_version != null && cql_version.equals(CassandraConstants.CQL_VERSION_3_0)) { onCql3CreateKeyspace(); } else { Map<String, String> strategy_options = new HashMap<String, String>(); List<CfDef> cfDefs = new ArrayList<CfDef>(); KsDef ksDef = new KsDef(databaseName, csmd.getPlacement_strategy(databaseName), cfDefs); setProperties(ksDef, strategy_options); ksDef.setStrategy_options(strategy_options); cassandra_client.system_add_keyspace(ksDef); } }
@Test public void noStrategyForDcThrows() { KsDef ksDef = new KsDef("test", CassandraConstants.SIMPLE_STRATEGY, ImmutableList.of()); ksDef.setStrategy_options(ImmutableMap.of(DC_1, "1")); assertThatThrownBy(() -> CassandraVerifier.sanityCheckReplicationFactor(ksDef, config, ImmutableSet.of(DC_1, DC_2))) .isInstanceOf(IllegalStateException.class); }
@Test public void simpleStrategyOneDcHighRfThrows() throws TException { KsDef ksDef = new KsDef("test", CassandraConstants.SIMPLE_STRATEGY, ImmutableList.of()); ksDef.setStrategy_options(ImmutableMap.of(CassandraConstants.REPLICATION_FACTOR_OPTION, "3")); assertThatThrownBy(() -> CassandraVerifier.checkAndSetReplicationFactor(client, ksDef, config)) .isInstanceOf(IllegalStateException.class); }
@Test public void differentRfThanConfigThrows() { KsDef ksDef = new KsDef("test", CassandraConstants.SIMPLE_STRATEGY, ImmutableList.of()); ksDef.setStrategy_options(ImmutableMap.of(DC_1, "1", DC_2, "2")); when(config.replicationFactor()).thenReturn(1); assertThatThrownBy(() -> CassandraVerifier.sanityCheckReplicationFactor(ksDef, config, ImmutableSortedSet.of(DC_1, DC_2))) .isInstanceOf(UnsupportedOperationException.class); }
@Test public void simpleStrategyOneDcOneRfSucceedsAndUpdatesKsDef() throws TException { setTopology(createDetails(DC_1, RACK_1, HOST_1)); when(config.replicationFactor()).thenReturn(1); KsDef ksDef = new KsDef("test", CassandraConstants.SIMPLE_STRATEGY, ImmutableList.of()); ImmutableMap<String, String> strategyOptions = ImmutableMap .of(CassandraConstants.REPLICATION_FACTOR_OPTION, "1"); ksDef.setStrategy_options(strategyOptions); ksDef = CassandraVerifier.checkAndSetReplicationFactor(client, ksDef, config); assertThat(ksDef.strategy_class).isEqualTo(CassandraConstants.NETWORK_STRATEGY); assertThat(ksDef.strategy_options).isEqualTo(ImmutableMap.of(DC_1, "1")); }
@Test public void returnSameKsDefIfNodeTopologyChecksIgnored() throws TException { setTopology(createDetails(DC_1, RACK_1, HOST_1)); when(config.replicationFactor()).thenReturn(7); when(config.ignoreNodeTopologyChecks()).thenReturn(true); KsDef ksDef = new KsDef("test", CassandraConstants.SIMPLE_STRATEGY, ImmutableList.of()); ImmutableMap<String, String> strategyOptions = ImmutableMap .of(CassandraConstants.REPLICATION_FACTOR_OPTION, "1", DC_1, "7"); ksDef.setStrategy_options(strategyOptions); ksDef = CassandraVerifier.checkAndSetReplicationFactor(client, ksDef, config); assertThat(ksDef.strategy_class).isEqualTo(CassandraConstants.SIMPLE_STRATEGY); assertThat(ksDef.strategy_options).isEqualTo(strategyOptions); }
@Test public void simpleStrategyMultipleDcsThrows() throws TException { setTopology(createDetails(DC_1, RACK_1, HOST_1), createDetails(DC_1, RACK_1, HOST_2), createDetails(DC_1, RACK_1, HOST_3), createDetails(DC_2, RACK_1, HOST_4)); when(config.replicationFactor()).thenReturn(1); KsDef ksDef = new KsDef("test", CassandraConstants.SIMPLE_STRATEGY, ImmutableList.of()); ksDef.setStrategy_options(ImmutableMap.of(CassandraConstants.REPLICATION_FACTOR_OPTION, "1")); assertThatThrownBy(() -> CassandraVerifier.checkAndSetReplicationFactor(client, ksDef, config)) .isInstanceOf(IllegalStateException.class); }
private void changeReplicationFactor(int replicationFactor) throws TException { clientPool.run((FunctionCheckedException<CassandraClient, Void, TException>) client -> { KsDef originalKsDef = client.describe_keyspace(CASSANDRA.getConfig().getKeyspaceOrThrow()); KsDef modifiedKsDef = originalKsDef.deepCopy(); modifiedKsDef.setStrategy_class(CassandraConstants.NETWORK_STRATEGY); modifiedKsDef.setStrategy_options(ImmutableMap.of("dc1", Integer.toString(replicationFactor))); modifiedKsDef.setCf_defs(ImmutableList.of()); client.system_update_keyspace(modifiedKsDef); return null; }); }
@Test public void networkStrategyMultipleDcsSucceeds() throws TException { setTopology(createDetails(DC_1, RACK_1, HOST_1), createDetails(DC_1, RACK_1, HOST_2), createDetails(DC_1, RACK_1, HOST_3), createDetails(DC_2, RACK_1, HOST_4)); when(config.replicationFactor()).thenReturn(3); KsDef ksDef = new KsDef("test", CassandraConstants.NETWORK_STRATEGY, ImmutableList.of()); ImmutableMap<String, String> strategyOptions = ImmutableMap.of( CassandraConstants.REPLICATION_FACTOR_OPTION, "3", DC_1, "3", DC_2, "3"); ksDef.setStrategy_options(strategyOptions); ksDef = CassandraVerifier.checkAndSetReplicationFactor(client, ksDef, config); assertThat(ksDef.strategy_options).isEqualTo(strategyOptions); }
Map<String, String> strategy_options = new HashMap<String, String>(); strategy_options.put("replication_factor", "1"); ksDef.setStrategy_options(strategy_options); CassandraCli.client.system_add_keyspace(ksDef);
Map<String, String> strategy_options = new HashMap<String, String>(); strategy_options.put("replication_factor", "1"); ksDef.setStrategy_options(strategy_options); CassandraCli.client.system_add_keyspace(ksDef);
private static KsDef setNetworkStrategyIfCheckedTopology(KsDef ksDef, CassandraKeyValueServiceConfig config, Set<String> datacenters) { if (!config.ignoreNodeTopologyChecks()) { ksDef.setStrategy_class(CassandraConstants.NETWORK_STRATEGY); ksDef.setStrategy_options(ImmutableMap.of(Iterables.getOnlyElement(datacenters), "1")); } return ksDef; }
public static KsDef toThrift(KeyspaceMetadata ksm) { List<CfDef> cfDefs = new ArrayList<>(); for (CFMetaData cfm : ksm.tables) // do not include views if (cfm.isThriftCompatible()) // Don't expose CF that cannot be correctly handle by thrift; see CASSANDRA-4377 for further details cfDefs.add(toThrift(cfm)); KsDef ksdef = new KsDef(ksm.name, ksm.params.replication.klass.getName(), cfDefs); ksdef.setStrategy_options(ksm.params.replication.options); ksdef.setDurable_writes(ksm.params.durableWrites); return ksdef; }
public KsDef toThrift() { KsDef def = new KsDef(name, strategyClass, ThriftCfDef.toThriftList(cfDefs)); def.setStrategy_options(strategyOptions); def.setDurable_writes(durableWrites ); return def; }
public KsDef toThrift() { KsDef def = new KsDef(name, strategyClass, ThriftCfDef.toThriftList(cfDefs)); def.setStrategy_options(strategyOptions); def.setDurable_writes(durableWrites ); return def; }