Cassandra Keyspace system_schema does not exist - cassandra

I am getting the error that Cassandra keyspace system_schema does not exist. Why this happens and how to resolve it?
SELECT * FROM system_schema.keyspaces;
InvalidRequest: code=2200 [Invalid query] message="Keyspace system_schema does not exist"
I follow the command from this tutorial exactly. But it does not turn out successfully. I worry if I missed anything during the installation process.

Related

How to list the available tables in different keyspaces in Amazon Keyspaces/Cassandra?

I am trying to implement an application using AWS Keyspace Cassandra and Cassandra Python driver. I had created 3 keyspaces in my AWS console.
I am trying to find if there is any query which can list down all the available tables in all 3 keyspaces in one go.
I tried below query but it's failing.
SELECT table_name, keyspace_name from system_schema.tables where keyspace_name IN ('mykeyspace','cycling')
Does CQL editor in AWS Keyspace not allow use of IN keyword? Anybody knows such a query or command?
It does allow us to use IN clause in Cassandra and even I am able to access the tables with the same query.
cassandra#cqlsh> SELECT table_name, keyspace_name from system_schema.tables where keyspace_name in ('system_traces','youkudbhelper');
table_name | keyspace_name
------------------------+---------------
(10 rows)
cassandra#cqlsh> exit
bash-4.2$ cqlsh --version
cqlsh 5.0.1
bash-4.2$
References:
https://docs.datastax.com/en/cql-oss/3.3/cql/cql_using/useQueryIN.html
The below query works in Cassandra to list the available tables in different keyspaces.
SELECT table_name, keyspace_name from system_schema.tables where keyspace_name IN ('mykeyspace','cycling');
But it fails for AWS Keyspaces as IN keyword is not supported in AWS Keyspaces yet.

Cassandra - Every command issued in CQLSH throws errors

Cassandra gives me serious headache. Yesterday, everything was running fine and then I dropped a table, ran a CQLSSTableWriter which somehow threw errors about my Lucene index (for not being on classpath or the like) several times and now, every command I issue in the cqlsh is throwing errors.
CREATE KEYSPACE IF NOT EXISTS mydata WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'};
takes a while and then throws:
Warning: schema version mismatch detected, which might be caused by DOWN nodes;
if this is not the case, check the schema versions of your nodes in system.local and system.peers.
OperationTimedOut: errors={}, last_host=XXX.XXX.XXX.20
After that I will create a new table and it will also throw the same error.
cqlsh:mydata> create table test (id text PRIMARY KEY, id2 text);
Warning: schema version mismatch detected, which might be caused by DOWN nodes; if this is not the case, check the schema versions of your nodes in system.local and system.peers.
OperationTimedOut: errors={}, last_host=XXX.XXX.XXX.20
last_host always shows the ip of the host where I run the cqlsh on. I have tried the same commands with different nodes too.
The keyspace and table however is still being created! The error says something about mismatching schema versions, so I made sure and ran:
nodetool describecluster
And the output of it shows that all my nodes are on the same schema. No schema mismatches. I also issued nodetool resetlocalschema before, without any luck though.
When I go ahead and insert some data into the newly created table, following error arises. Note that the insert statement does not return an error.
cqlsh:mydata> insert into test(id, id2) values('test1', 'test2');
cqlsh:mydata> select * from mydata.test ;
Traceback (most recent call last):
File "/usr/bin/cqlsh.py", line 1314, in perform_simple_statement
result = future.result()
File "/usr/share/cassandra/lib/cassandra-driver-internal-only-3.0.0-6af642d.zip/cassandra-driver-3.0.0-6af642d/cassandra/cluster.py", line 3122, in result
raise self._final_exception
Unavailable: code=1000 [Unavailable exception] message="Cannot achieve consistency level ONE" info={'required_replicas': 1, 'alive_replicas': 0, 'consistency': 'ONE'}
Note that I have one datacenter and five nodes. I do not plan to use more than one datacenter in the future. [cqlsh 5.0.1 | Cassandra 3.0.8 | CQL spec 3.4.0 | Native protocol v4]
I have also restarted Cassandra multiple times. nodetool status shows that all nodes are up and running. Does anyone have a clue about what's going on?
I fixed this by...
dropping all tables in the keyspace
running alter keyspace mydata WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1': '1'}; instead of SimpleStrategy
restarting the cassandra service on all nodes
recreating all tables
runnning nodetool repair
Now I am able to insert data and query data again. Still not quite sure what was the cause of all this to be honest though.

Cassandra cluster simple query error

I'm learning Cassandra and I have a problem. I have a cluster with 2 computers (node A and node B). On a computer I can create new users and keyspaces and on the other one I can use this users and keyspaces. But if i create a new table on any of these computers (inside cassandra, on a keyspace), i can't see this new table with a simple query statement like SELECT * FROM table or SELECT * FROM keyspace.table. Cassandra displays this error "ServerError: <ErrorMessage code=0000 [Server error] message='java.lang.AssertionError">"
if i use nodetool status on the node A (node+seeder) displays an error:
java.lang.RuntimeException: No nodes present in the cluster. Has this node finished startin up?
but if i use nodetool status on the node B (only node), displays a node: the node B.
Keyspace stamement:
CREATE KEYSPACE demo WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
Cassandra 3.2 is installed on Debian
What can i do? any ideas? I can't fix it

Cassandra: Insert fails for consistency level "Quorum"

We get an error "cannot achieve consistency level QUORUM" (details below)
in following configuration:
Two datacenters with 6 nodes each, all nodes on same rack.
It works when CL is set as "Local Quorum".
Basically, as far as we use consistency level that require cross DC consistency, it fails to insert data. "Nodetool status" command shows that all 12 nodes are up and running.
What can be wrong?
Your help is much appreciated!
Thanks
Dimitry
Keyspace
CREATE KEYSPACE test6 WITH replication = {'class': 'NetworkTopologyStrategy', 'C
entralUS': '3', 'EastUs': '3'} AND durable_writes = true;
Query
INSERT INTO glsitems (itemid,itemkey) VALUES('1', 'LL');
Error
cassandra-driver-2.7.2\cassandra\cluster.py", line 3347, in result
raise self._final_exception
Unavailable: code=1000 [Unavailable exception] message="Cannot achieve
consistency level QUORUM" info={'required_replicas':
4, 'alive_replicas':3, 'consistency': 'QUORUM'}
It could be that Cassandra thinks all nodes are in the same datacenter. In this case LOCAL_QUORUM would always work properly but not QUORUM.
Did you correctly configure the snitch ?
Snitch – For multi-data center deployments, it is important to make
sure the snitch has complete and accurate information about the
network, either by automatic detection (RackInferringSnitch) or
details specified in a properties file (PropertyFileSnitch). link
You can find which snitch is used in the cassandra yaml file, property endpoint_snitch.
Here is the datastax documentation about existing snitches with Cassandra 2.0.

How to list all the available keyspaces in Cassandra?

I am newbie in Cassandra and trying to implement one toy application using Cassandra. I had created one keyspace and few column families in my Cassandra DB but I forgot the name of my cluster.
I am trying to find if there is any query which can list down all the available keyspaces.
Anybody knows such a query or command?
[cqlsh 4.1.0 | Cassandra 2.0.4 | CQL spec 3.1.1 | Thrift protocol 19.39.0]
Currently, the command to use is:
DESC[RIBE] keyspaces;
If you want to do this outside of the cqlsh tool you can query the schema_keyspaces table in the system keyspace. There's also a table called schema_columnfamilies which contains information about all tables.
The DESCRIBE and SHOW commands only work in cqlsh and cassandra-cli.
Its very simple. Just give the below command for listing all keyspaces.
Cqlsh> Describe keyspaces;
If you want to check the keyspace in the system schema using the SQL query
below is the command.
SELECT * FROM system_schema.keyspaces;
Hope this will answer your question...
You can go through the explanation on understanding and creating the keyspaces from below resources.
Documentation:
https://docs.datastax.com/en/cql/3.1/cql/cql_reference/create_keyspace_r.html
https://www.i2tutorials.com/cassandra-tutorial/cassandra-create-keyspace/
Found it...show keyspaces command lists down all the keyspaces. I think earlier when I tried this command, I forgot to give last 's' in 'keyspaces'
To see all the keyspaces on your Apache Cassandra NoSQL Database Server use the command:
> DESCRIBE KEYSPACES
Once logged in to cqlsh or cassandra-cli.
run below commands
On cqlsh
desc keyspaces;
or
describe keyspaces;
or
select * from system_schema.keyspaces;
On cassandra-cli
show keyspaces;
The DESCRIBE command is your friend. You can describe one keyspace, list keyspaces, one table or list all tables in keyspace, the cluster and much more.
You can get the full idea by typing
HELP DESCRIBE in cqlsh.
Connected to mscluster at 127.0.0.1:9042. [cqlsh 5.0.1 | Cassandra 3.8
| CQL spec 3.4.2 | Native protocol v4] Use HELP for help.
cqlsh> HELP DESCRIBE
DESCRIBE [cqlsh only]
(DESC may be used as a shorthand.)
Outputs information about the connected Cassandra cluster, or about
the data objects stored in the cluster. Use in one of the following ways:...<omitted for brevity>
DESCRIBE <your key space name> - describes the command used to create keyspace
cqlsh> DESCRIBE testkeyspace;
CREATE KEYSPACE testkeyspace WITH
replication = {'class':'SimpleStrategy', 'replication_factor': '3'}
AND durable_writes = true;
DESCRIBE keyspaces - lists all keyspaces
cqlsh> DESCRIBE KEYSPACES
system_schema system testkeyspace system_auth
system_distributed system_traces
DESCRIBE TABLES - List all tables in current keyspace
cqlsh:system> DESCRIBE TABLES;
available_ranges peers paxos
range_xfers batches compaction_history batchlog
local "IndexInfo" sstable_activity
size_estimates hints views_builds_in_progress peer_events
built_views
DESCRIBE your table name or DESCRIBE TABLE your table name - Gives the table details
cqlsh:system> DESCRIBE TABLE batchlog
CREATE TABLE system.batchlog (
id uuid PRIMARY KEY,
data blob,
version int,
written_at timestamp ) WITH bloom_filter_fp_chance = 0.01
AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
AND comment = 'DEPRECATED batchlog entries' ....omitted for brevity
DESC KEYSPACES will do the job.
Also, If you want to describe schema of a particular keyspace you can use
DESC
To List all the available keyspaces in cassandra using cqlsh in CLI mode.
Command : DESCRIBE keyspaces;
Example :
cqlsh> DESCRIBE keyspaces;
login to cqlsh
use below command to get names/list of keyspaces present
SELECT keyspace_name FROM system_schema.keyspaces;
login to cqlsh
desc keyspaces;
select * from system_schema.keyspaces ;
desc keyspaces will do it for you.
DESCRIBE keyspaces to list all keysapces
DESCRIBE keyspace
https://docs.datastax.com/en/dse/5.1/cql/cql/cql_reference/cqlsh_commands/cqlshDescribeKeyspace.html
I suggest a combination of grep and awk:
root#DC1-Node1:/home# nodetool tablestats | grep "Keyspace :" | awk -F ":" '{print $2}'
system_traces
system
system_distributed
system_schema
device_tool
system_tool
Apart from above method, if you have opscenter installed,
Go to data tab > there you will see all keyspcaces created by you and some system keyspaces.
You can see all tables under individual keyspaces and also replicator factor for keyspace.
for more details check below link.
https://docs.datastax.com/en/opscenter/6.1/opsc/online_help/opscDataModelingManagingKeyspace_t.html
describes and desc command will give list of keyspaces in the cluster.Please find below output for more details.
cqlsh> describe keyspaces
reaper_db system_auth system_distributed
system_schema system system_traces
OR
cqlsh> desc keyspaces
reaper_db system_auth system_distributed
system_schema system system_traces

Resources