private String getCreateKeyspaceStatement() { return SchemaBuilder.createKeyspace(config.getCassandraKeyspace()) .ifNotExists() .with() .replication(ImmutableMap.of("class", config.getReplicationStrategy(), config.getReplicationFactorKey(), config.getReplicationFactorValue())) .durableWrites(true) .getQueryString(); }
protected void initKeyspace() { // Replication strategy: SimpleStrategy or NetworkTopologyStrategy String strategy = this.conf.get(CassandraOptions.CASSANDRA_STRATEGY); // Replication factor int factor = this.conf.get(CassandraOptions.CASSANDRA_REPLICATION); Map<String, Object> replication = new HashMap<>(); replication.putIfAbsent("class", strategy); replication.putIfAbsent("replication_factor", factor); Statement stmt = SchemaBuilder.createKeyspace(this.keyspace) .ifNotExists().with() .replication(replication); // Create keyspace with non-keyspace-session LOG.debug("Create keyspace: {}", stmt); Session session = this.cluster().connect(); try { session.execute(stmt); } finally { if (!session.isClosed()) { session.close(); } } }
public void initKeyspace() { // TODO consider exposing important keyspace options through commandline // such as understanding how to properly enable cassandra in production // - with data centers and snitch, for now because this is only creating // a keyspace "if not exists" a user can create a keyspace matching // their geowave namespace with any settings they want manually session.execute( SchemaBuilder.createKeyspace(gwNamespace).ifNotExists().with().replication( ImmutableMap.of( "class", "SimpleStrategy", "replication_factor", options.getReplicationFactor())).durableWrites(options.isDurableWrites())); }
protected void initKeyspace() { // Replication strategy: SimpleStrategy or NetworkTopologyStrategy String strategy = this.conf.get(CassandraOptions.CASSANDRA_STRATEGY); // Replication factor int factor = this.conf.get(CassandraOptions.CASSANDRA_REPLICATION); Map<String, Object> replication = new HashMap<>(); replication.putIfAbsent("class", strategy); replication.putIfAbsent("replication_factor", factor); Statement stmt = SchemaBuilder.createKeyspace(this.keyspace) .ifNotExists().with() .replication(replication); // Create keyspace with non-keyspace-session LOG.debug("Create keyspace: {}", stmt); Session session = this.cluster().connect(); try { session.execute(stmt); } finally { if (!session.isClosed()) { session.close(); } } }
Session initializeSession(final String keyspaceName) { final Session s = this.cluster.connect(); // if the keyspace already exists, just return the session if (this.cluster.getMetadata().getKeyspace(keyspaceName) != null) { return s; } final Configuration configuration = getStorageConfig(); // Setting replication strategy based on value reading from the configuration: either "SimpleStrategy" or "NetworkTopologyStrategy" final Map<String, Object> replication = Match(configuration.get(REPLICATION_STRATEGY)).of( Case($("SimpleStrategy"), strategy -> HashMap.<String, Object> of("class", strategy, "replication_factor", configuration.get(REPLICATION_FACTOR))), Case($("NetworkTopologyStrategy"), strategy -> HashMap.<String, Object> of("class", strategy) .merge(Array.of(configuration.get(REPLICATION_OPTIONS)) .grouped(2) .toMap(array -> Tuple.of(array.get(0), Integer.parseInt(array.get(1))))))) .toJavaMap(); s.execute(createKeyspace(keyspaceName) .ifNotExists() .with() .replication(replication)); return s; }