rename keyspace and columnfamily in cassandra 1.2 - cassandra

How to rename keyspace and columnfamily in cassandra 1.2? I know that cassandra-cli rename api is no longer supported - How to rename keyspace in Cassandra. Maybe there are some api in CQL3? Or some api for creating new columnfamily and coping all data from old to new columnfamily?

Renaming is disabled internally, not just within the thrift API. So there isn't a CQL command to do it either.
However, there is a manual process which is described here:
https://issues.apache.org/jira/browse/CASSANDRA-1585

For rename only a column family also you can follow the next instructions:
http://mail-archives.apache.org/mod_mbox/cassandra-user/201201.mbox/%3C4EF306AC-98D5-45BE-A29C-B68187FBA9C9#thelastpickle.com%3E
Basically is create the new CF, copy the SStables from the old column family to the one renaming the files.

Related

Is recreating table/ keyspace with same name in Cassandra not good?

I was going to a blog by Datastax which says it is not recommended to recreate table with same name. That is drop the table and create with the same name. Here is the link for Datastax recreate table faq.
It talks about jira ticket CASSANDRA-5202. It was fixed in 2.1.
I have questions, I am on Cassandra 2.1.16
Is it safe to recreate table or keyspace with same name after dropping?
What precautions we must take if we recreate table or keyspace with same name?
I wrote that post 6 years ago. :)
As it clearly states, the problem existed in older versions of Cassandra. In C* 2.1 (and newer), a table ID (time UUID) is added to the table directory name on disk to prevent the problems I outlined in that post (CASSANDRA-5202). Cheers!

nodetool snapshot takes schema snapshot (backup) too?

Cassandra doc mentions that "nodetool snapshot" command takes snapshot of table data. However, I am also able to see schema.cql and manifest.json file in my snapshot directory where all snapshot files are generated.
Is this expected behavior? Also can I use this schema.cql file to restore the schema if needed?
My cassandra version
cqlsh> show version
[cqlsh 5.0.1 | Cassandra 3.0.9 | CQL spec 3.4.0 | Native protocol v4]
>nodetool version
ReleaseVersion: 3.0.9
EDIT:
Is it mandatory to use cql file from snapshot while restoring data? Suppose I have create table cql stored somewhere else. Can I use that?
I performed some tests. When I re-created table using cql from snapshot, ID in table name remains same "employee-42a71380966111e8870f97a01282a56a". However when I re-created table using my original cql, ID in table name changed. Can this be a problem and that's why we should use cql from snapshot?
Note-: When I restored data from snapshot, it loaded fine in both above cases
This cql file is for table. Can we get cql from snapshot to create keyspace?
Does cql file gets generated only for user defined table? I can't see cql file getting generated for system tables..
Yes, these files are necessary for restoring this particular table. And schema.cql captures the structure of table on the time of the snapshot because you need to restore snapshot to table with the same structure.
You can find more detailed description in the DataStax documentation.
Update after addition of more questions:
Presence of schema in snapshot makes life easier - quite often the schema evolve, and you can use non-snapshot schema if you guarantee that schema will match to data in snapshot;
nodetool snapshot generates only table's schemas
It's better not to mess-up with system tables...
Here is detailed knowledge base article from DataStax support about backup/restore.
Doc link you have given is for apache Cassandra, while the answer given is with reference to Datastax, I have done taking snaphosts and restore it back in apache-cassandra 2.0.4, It doesn't take any schema backup. All schemas need to be copied separately and need to be created manually in new cluster.

Is there a way to rename a keyspace while cloning a cluster using OpsCenter?

I am working on a project which requires me to clone an existing cassandra cluster using OpsCenter. But at the same time I want to rename the keyspace that I want to clone. Is there a way to do that? I have gone through the documentation. But not able to find a solution. Any help would be appreciated . Thanks!!
I don't think so. Also renaming keyspace/column family may lead to problems like race condition.please go through the link rename-keyspace-and-columnfamily.
Though you can find workaround for these here.
There was no direct way to do this. So finally ended up with a roundabout solution.
Created a new cluster.
Used cassandradump to export data from the old cluster keyspace.
Created a keyspace with a new name in the new cluster
Modified the exported cql files using sed to replace the old keyspace names with the new keyspace names.
Imported the cql files to the new cluster using 'SOURCE' CQL command

DROP COLUMN FAMILY from cassandra CLI will not drop the CF

We tried to drop CF's using cassandra cli
DROP COLUMN FAMILY cfName
And when we list the CF from CLI it was not there and when i tried to get the existing CF's via hector
I still could see the CF name
KeyspaceDefinition keyspaceDefinition = newConnection().describeKeyspace(keyspaceName);
keyspaceDefinition.getCfDefs();
Data inside the CF is not there however, the CF is still listed, after listing the CFs via hector if i do a cassandra -cli list column families i can see my deleted CF again
I had to deal with this issue back on Cassandra 1.1 as well. Basically, my column family had become corrupted, and the only way to alter its schema, was to drop/restore the keyspace (which DataStax walked me through, at the time).
If you have a support contract with DataStax, I would HIGHLY recommend contacting them before proceeding. The first thing they'll tell you, is that this is a bug in specific versions of Cassandra 1.1, and that you should upgrade. I haven't tested it, but according to them an in-place upgrade would allow you to modify your schema in the new version. So you might be able to fix this by upgrading to 1.2 or 2.0.
In my case (production, enterprise environment) upgrading on-the-spot was not an option. To fix this, I basically had to drop my entire keyspace, re-create it (and my column families), and recover from a snapshot. I loosely followed the instructions found here:
Take a snapshot of the keyspace on each node. The snapshot files should be stored in the [keyspaceName]/snapshots dir, but I copied mine to another non-Cassandra location just to be on the safe side.
DROP your keyspace.
Stop all nodes.
On each node, delete the .db files in the keyspace directory (but not the snapshot dir).
Copy the files from the snapshot directory back into the keyspace directory.
Restart one node
From that node's cassandra-cli re-create your keyspace.
Verify that your data is there.
Restart the remaining nodes.

Enabling Caching in Cassandra Column family through hector-API?

I am using hector-core1.0-5 from prettyprint for connecting to cassandra. Using this API I am able to create the keyspace. But I am unable to find the method which configures the "caching" property of column family. So as default it assigns "KEYS_ONLY" as "caching" value for all column families created. I wan to change this property value to "ALL" so that I can use both the key cache and row cache in cassandra.My cassandra version1.2.0. Anyone help me in finding the way to alter the "caching" property at the time a keyspace is created.
There is not support for get or set caching in ColumnFamilyDefinition interface. Hector community has to patch the code.
No idea about Hector as such. But we are using Playorm for Cassandra and it uses Caches like hibernate. Read more information at http://buffalosw.com/wiki/Caching-in-Playorm/.

Resources