ALTER TABLE returns "ConfigurationException: Column family ID" - cassandra

I am getting error while executing alter table script.
ALTER TABLE user.employee ADD salary text;
ServerError: java.lang.RuntimeException: java.util.concurrent.ExecutionException: org.apache.cassandra.exceptions.ConfigurationException: Column family ID mismatch (found e5da3980-83eb-11ec-8c56-1b3845d1a791; expected c8ac48d0-83eb-11ec-8c56-1b3845d1a791)
When I describe table ,I am seeing newly created column present. But I am bot able to access the new column.Its throwing below error InvalidRequest: Error from server: code=2200 [Invalid query] message="Undefined name xxxxxxxxx in selection clause"
We have close to 100GB of data.

This looks like the same question asked on https://community.datastax.com/questions/13220/ so I'm re-posting my answer here.
This exception indicates that you have a schema disagreement in your cluster:
ConfigurationException: Column family ID mismatch (\
found e5da3980-83eb-11ec-8c56-1b3845d1a791; \
expected c8ac48d0-83eb-11ec-8c56-1b3845d1a791 \
)
In my experience, the most common cause of this problem is that you dropped and re-created the table without waiting for the schema to propagate to all nodes in the cluster in between the DROP and CREATE. Alternatively, it's possible that you've tried to create the table and assumed it didn't work then tried to create it again.
In any case, Cassandra thinks the table was created at 05:48 GMT but found a version created at 05:49 GMT. For what it's worth:
e5da3980-83eb-11ec-8c56-1b3845d1a791 = February 2, 2022 at 5:49:33 AM GMT
c8ac48d0-83eb-11ec-8c56-1b3845d1a791 = February 2, 2022 at 5:48:44 AM GMT
You'll need to resolve the schema disagreement. Depending on the Cassandra version you can either (a) run nodetool resetlocalschema on nodes which have a different schema version based on the output of nodetool describecluster, or (b) perform a rolling restart of all nodes. Cheers!

ExecutionException: org.apache.cassandra.exceptions.ConfigurationException: Column family ID mismatch (found e5da3980-83eb-11ec-8c56-1b3845d1a791; expected c8ac48d0-83eb-11ec-8c56-1b3845d1a791)
Has that column been deleted/added more than once? Cassandra (especially the pre 3.0 versions) is notorious for problems with that.
Check the output of nodetool describecluster. Are there multiple schema versions being reported?
If there are multiple schema versions, then run a rolling restart of the cluster. That's a sure-fire way to force schema agreement. Check the table, and see if that column is there. If not, try to add it.
The other solution, would be to try adding it with a different name (ex: "salary2").

Related

How to have specific information in mariadb.Error [Python]

I'm trying to have some specific information on a mariadb.Error. After the execution of an INSERT, with executemany(), I want to have, every time, the information about the problematical line. But I received two different types of errors.
For example when I have an error about a wrong data type, I have something like:
Invalid parameter type at row 2, column 4
When I have an error about a constraint not respected, I have something like:
Cannot add or update a child row: a foreign key constraint fails
But on the second case, I would like to have something like :
Cannot add or update a child row: a foreign key constraint fails at row X, column Y
Is it possible ? Can I configure mariadb.Error to have, always, the row/column detail ?
No, this is not possible.
The first error (Invalid parameter type at row 2, column 4) is generated by the MariaDB python driver: Before sending the execution request and data to the server, the driver checks if all columns have the same datatype, if not he will raise the exception above.
Afterwards, the driver sends a COM_STMT_BULK_EXECUTE command followed by all data to the server. The second error message (a foreign key constraint fails) was generated by the server, since the specified data violated one or more constraints. Unfortunately, the server doesn't give any hint which value in which row caused this error, so the driver can only raise this exception.
I agree, that this would be a useful feature and have submitted an issue (MDEV-29945) to the MariaDB bug tracking system.

Why I can't create a UDT with name profiles?

CREATE TYPE IF NOT EXISTS myks.profiles (
"field" text
);
It gives me the below exception when I try to create a UDT with name profiles com.datastax.driver.core.exceptions.SyntaxError: line 1:17 no viable alternative at input 'profiles' (CREATE TYPE myks.[profiles]...)
Update: it looks like a bug. I suggest to use word profile instead...
Original answer:
Keyspaces in Cassandra are created with CREATE KEYSPACE command, and you're trying to create a new user-defined type instead. This error is returned because the keyspace myks is not yet defined.
In your case full command will be:
CREATE KEYSPACE IF NOT EXISTS profiles WITH replication =
{'class': 'NetworkTopologyStrategy', 'your_dc': 'rep_factor'};
you need to substitute the name of your datacenter(s) instead of your_dc, and adjust rep_factor to match number of nodes.
But for beginning I suggest to watch at least DS201 course on DatStax Academy - it should give your overview of basic operations, etc.

Same query doesn't run on restored Cassandra database

I am working on Cassandra migration.
I built a new Cassandra cluster - Cassandra 2.1.8 on Ubuntu 14.04. Database was restored from snapshots.
Source Cassandra cluster is also version 2.1.8.
I am facing with this weird issue.
On the original cluster I can run following query using cqlsh without any errors. cqlsh is version 5.0.1.
SELECT * FROM "featureitems" WHERE "categoryId" = 2 LIMIT 100;
On a new cluster same query throws error:
InvalidRequest: code=2200 [Invalid query] message="Undefined name categoryId in where clause ('categoryId = 2')"
but it runs perfectly fine when I remove double quotes
SELECT * FROM featureitems WHERE categoryId = 2 LIMIT 100;
It looks like some configuration issue, but I don't know where to look. Any suggestion in that sense is appreciated.
Cassandra converts all column/table/keyspace names to lowercase if not provided in double quotes.
So if you need uppercase character in column/table/keyspace name use double quotes.
You can use DESC TABLE featureitems command to describe table.
In your first query you have enclosed categoryId in double quotes, hence it looks for column with capital I.
In your second query categoryId is not enclosed in double quotes, hence it will be converted to categoryid... which is present in table and hence working.

phpcassa: cassandra\NotFoundException when instantiating ColumnFamily class

I'm trying to query a Cassandra 2.0.2 server using the phpcassa libraray.
I do the following:
<?php
require('phpcassa/lib/autoload.php');
use phpcassa\ColumnFamily;
use phpcassa\ColumnSlice;
use phpcassa\Connection\ConnectionPool;
$pool = new ConnectionPool('Cronnection', array('MY_SERVER_IP:9160'));
$conversations = new ColumnFamily($pool, 'conversations');
var_dump( $conversations->get('2521b0f0-8e36-11e3-a489-8f038e859082') );
When I do this I get an uncaught 'cassandra\NotFoundException' exception.
After reading in the source I see that this is because the column family 'conversations' is not getting loaded into the cloumn families array created by the ConnectionPool::describe_keyspace() method.
When I print the result of "describe_keyspace", using the following code, I can see that only one of my column families, called user_profiles, is getting loaded into my column families array.
<?php
require('phpcassa/lib/autoload.php');
use phpcassa\ColumnFamily;
use phpcassa\ColumnSlice;
use phpcassa\Connection\ConnectionPool;
$pool = new ConnectionPool('Cronnection', array('MY_SERVER_IP:9160'));
echo '<pre>';
var_dump($pool->describe_keyspace());
There are 6 column families defined in that keyspace but phpcassa is only listing "user_profiles"; the only difference between "user_profiles" and the other CFs is that "user_profiles" is using the "WITH COMPACT STORAGE" property.
Any thoughts on how to solve this or why is this happenning?
Thanks!
PS: I created the column families using CQL3 through cqlsh, when I do "describe" using cassandra-cli I can't see my column families, only the "user_profiles" one that I mentioned, could this somehow be related?
Yes, this is in fact related to COMPACT STORAGE and cassandra-cli not showing your other column families. phpcassa and other Thrift-based clients (such as cassandra-cli) can only use tables created through CQL3 if they are created WITH COMPACT STORAGE.
In short, I suggest sticking to COMPACT STORAGE tables if you will be working with phpcassa. If you want to read more, there is a somewhat advanced article that shows explains how Thrift, CQL3 and compact storage fit together.

Cannot modify CompositeType comparator on Cassandra column family

Using cassandra-cli, an attempt to modify a CompositeType comparator (eg., to add or remove a field) fails with an error:
[default#KS] describe CF;
ColumnFamily: CF
Cells sorted by:
org.apache.cassandra.db.marshal.CompositeType(
org.apache.cassandra.db.marshal.LongType,
org.apache.cassandra.db.marshal.LongType,
org.apache.cassandra.db.marshal.UTF8Type)
[default#KS] truncate CF;
CF truncated.
[default#KS] update column family CF with comparator =
'CompositeType(
org.apache.cassandra.db.marshal.LongType,
org.apache.cassandra.db.marshal.UTF8Type)';
comparators do not match or are not compatible.
An attempt to work around this by dropping and recreating the column family worked fine until restarting, apparently caused by this issue:
cassandra Exception encountered during startup: index (1) must be less than size (1)
How should this case be handled properly? I suppose doing a nodetool flush after the drop would prevent issues with the commit log having incompatible data? Is there a way to modify the CompositeType comparator without doing a drop/create?
There is no way to modify the CompositeType comparator without doing a drop/create? After drop, you need do a nodetool clearsnapshot. Check this link
http://wiki.apache.org/cassandra/CassandraCli08

Resources