stargate / docker-images

https://stargate.io
Apache License 2.0
16 stars 14 forks source link

Stargate docker image: Environment variable to enable materialized views #105

Closed caniko closed 2 years ago

caniko commented 2 years ago

I need an environment variable that I can use to enable materialized views for testing; ENABLE_MATERIALIZED_VIEWS.

mpenick commented 2 years ago

I believe this can be enabled by passing a cassandra.yaml using the system property stargate.unsafe.cassandra_config_path:

JAVA_OPTS="-Dstargate.unsafe.cassandra_config_path=/path/to/cassandra.yml" starctl ...

cassandra.yaml:

# ...
enable_materialized_views: true
caniko commented 2 years ago

Many thanks! However, do I need to add all required fields or is it OK to just pass this field alone?

I'll try it later today

mpenick commented 2 years ago

yes, that field alone will work (I justed tested it with C* 4.0). btw, I messed up the field name before (I edited my previous comment too), this is the correct field:

enable_materialized_views: true
caniko commented 2 years ago

I justed tested it with C* 4.0

@mpenick: Strange, this didn't work for me. Do I have to mount the file? I am using docker-py:

path_to_cassandra_yaml = Path(__file__).absolute().parent / "cassandra.yaml"
client.containers.run(
        "stargateio/stargate-4_0:v1.0.55",
        detach=True,
        name="stargate",
        ports={8081: 8081, 8082: 8082, 9042: 9042},
        environment={
            "CLUSTER_NAME": "stargate",
            "CLUSTER_VERSION": "4.0",
            "CQLENG_ALLOW_SCHEMA_MANAGEMENT": "1",
            "DEVELOPER_MODE": "1",
            "JAVA_OPTS": f"-Dstargate.unsafe.cassandra_config_path={path_to_cassandra_yaml}",
        },
    )

Error:

cassandra.InvalidRequest: Error from server: code=2200 [Invalid query] message="Materialized views are disabled. Enable in cassandra.yaml to use."

cassandra.yaml is on the same directory as the script above:

# ...
enable_materialized_views: true
mpenick commented 2 years ago

. Do I have to mount the file?

Yes, that's my guess. Just for reference, here's the experiment I ran (using v1.0.55):

JAVA_OPTS="-Dstargate.unsafe.cassandra_config_path=/path/to/cassandra.yaml" ./starctl \
 --cluster-name cluster --cluster-version 4.0  --developer-mode --listen 127.0.0.1

cassandra.yaml

enable_materialized_views: true

Using cqlsh to verify materialized views:

cqlsh> CREATE KEYSPACE ks WITH REPLICATION = {     'class' : 'SimpleStrategy',  'replication_factor': 1   };
cqlsh> CREATE TABLE ks.test (k text, v1 text, v2 text,  PRIMARY KEY (k, v1));
cqlsh> CREATE MATERIALIZED VIEW ks.test_v1 AS SELECT k,v1 FROM ks.test WHERE k IS NOT NULL AND v1 IS NOT NULL PRIMARY KEY (v1, k);

Warnings :
Materialized views are experimental and are not recommended for production use.

cqlsh> INSERT INTO ks.test (k, v1 , v2) VALUES ('a', '1', '2');
cqlsh> INSERT INTO ks.test (k, v1 , v2) VALUES ('b', '3', '4');
cqlsh> SELECT * FROM ks.test_v1 ;

 v1 | k
----+---
  3 | b
  1 | a

(2 rows)
mpenick commented 2 years ago

Docker version (using -v $(pwd)/cassandra.yaml:/cassandra.yaml to mount the yaml file):

docker run -e CLUSTER_NAME=stargate \
  -e CLUSTER_VERSION=4.0 -e DEVELOPER_MODE=1 \
  -e JAVA_OPTS=-Dstargate.unsafe.cassandra_config_path=/cassandra.yaml \
  -v $(pwd)/cassandra.yaml:/cassandra.yaml \
  -p 9042:9042 stargateio/stargate-4_0:v1.0.55