docker-library / cassandra

Docker Official Image packaging for Cassandra
Apache License 2.0
263 stars 281 forks source link

Unable to set “consistency LOCAL_ONE;” to cassandra container startup #200

Closed neekhraashish closed 4 years ago

neekhraashish commented 4 years ago

I am new to Cassandra DB and want to run YCSB benchmarking tool on a single Cassandra container within docker for testing purposes. I am doing this with docker-compose and also come-up with the required yml file which will deploy Cassandra container, create "ycsb" keyspace with required fields then will setup consistency level to LOCAL_ONE, I guess this level is mandatory for single cassandra instance. The official Cassandra image version is "3.11.5".

# cat docker-compose.yml
.
.
  cas-1:
    image: cassandra:latest
    ports:
       - 7000:7000
       - 9042:9042
    restart: always
    volumes:
      - ./CAS_1/db:/var/lib/cassandra
      - ./cassandra-init.sh:/cassandra-init.sh
    command: "sh /cassandra-init.sh"
.
.

cassandra-init.sh file contains;

# cat cassandra-init.sh
CQL="DROP keyspace ycsb;
CREATE KEYSPACE IF NOT EXISTS ycsb WITH replication =
{'class':'SimpleStrategy','replication_factor':'1'};

CREATE TABLE IF NOT EXISTS ycsb.usertable
(
    y_id varchar primary key,
    field0 varchar,
    field1 varchar,
    field2 varchar,
    field3 varchar,
    field4 varchar,
    field5 varchar,
    field6 varchar,
    field7 varchar,
    field8 varchar,
    field9 varchar,
    field10 varchar,
    field11 varchar,
    field12 varchar,
    field13 varchar,
    field14 varchar,
    field15 varchar,
    field16 varchar,
    field17 varchar,
    field18 varchar,
    field19 varchar);

consistency LOCAL_ONE;"

until echo $CQL | cqlsh; do
  echo "cqlsh: Cassandra is unavailable to initialize - will retry later"
  sleep 2
done &

exec /docker-entrypoint.sh "$@"

While starting cassandra container I am able to see consistency level changed to LOCAL_ONE.

cas-1_1   | INFO  [Native-Transport-Requests-2] 2020-02-25 08:45:12,834 MigrationManager.java:337 - Create new Keyspace: KeyspaceMetadata{name=ycsb, params=KeyspaceParams{durable_writes=true, replication=ReplicationParams{class=org.apache.cassandra.locator.SimpleStrategy, replication_factor=1}}, tables=[], views=[], functions=[], types=[]}
cas-1_1   | INFO  [Native-Transport-Requests-3] 2020-02-25 08:45:12,932 MigrationManager.java:382 - Create new table: org.apache.cassandra.config.CFMetaData@9458964[cfId=232bab30-57ab-11ea-a38a-c9e252fad434,ksName=ycsb,cfName=usertable,flags=[COMPOUND],params=TableParams{comment=, read_repair_chance=0.0, dclocal_read_repair_chance=0.1, bloom_filter_fp_chance=0.01, crc_check_chance=1.0, gc_grace_seconds=864000, default_time_to_live=0, memtable_flush_period_in_ms=0, min_index_interval=128, max_index_interval=2048, speculative_retry=99PERCENTILE, caching={'keys' : 'ALL', 'rows_per_partition' : 'NONE'}, compaction=CompactionParams{class=org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy, options={min_threshold=4, max_threshold=32}}, compression=org.apache.cassandra.schema.CompressionParams@f6a855f5, extensions={}, cdc=false},comparator=comparator(),partitionColumns=[[] | [field0 field1 field10 field11 field12 field13 field14 field15 field16 field17 field18 field19 field2 field3 field4 field5 field6 field7 field8 field9]],partitionKeyColumns=[y_id],clusteringColumns=[],keyValidator=org.apache.cassandra.db.marshal.UTF8Type,columnMetadata=[field15, field10, field2, field0, field3, field14, field8, field13, field5, field18, field12, field7, field4, field19, field17, field11, field6, field16, field9, y_id, field1],droppedColumns={},triggers=[],indexes=[]]
cas-1_1   | INFO  [MigrationStage:1] 2020-02-25 08:45:13,087 ColumnFamilyStore.java:426 - Initializing ycsb.usertable
cas-1_1   | Consistency level set to LOCAL_ONE.

But when I am attaching to Cassandra container and doing verification is shows:

[root@Docker IO-Tool]# docker exec -it 5c359e6d23dd bash
root@5c359e6d23dd:/# cqlsh
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.11.5 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh> consistency;
Current consistency level is ONE.

I also configured it manually:

cqlsh> consistency LOCAL_ONE;
Consistency level set to LOCAL_ONE.
cqlsh> consistency;
Current consistency level is LOCAL_ONE.

it sets-up to consistency level to LOCAL_ONE, but once I exit and come out of the container and again attach it, this changes to consistency level ONE.

I am not sure why this is not setting up within container, please any help appreciated.

Thanks

wglambert commented 4 years ago

https://docs.datastax.com/en/archived/cassandra/3.x/cassandra/dml/dmlConfigConsistency.html

Within cqlsh, use CONSISTENCY, to set the consistency level for all queries in the current cqlsh session. For programming client applications, set the consistency level using an appropriate driver.

CONSISTENCY is only for the session, to set global consistency you need a Java driver to configure it https://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/QueryOptions.html#DEFAULT_CONSISTENCY_LEVEL

https://stackoverflow.com/a/50994940/9959005