I am going through the code of apache cassandra 2.2 branch, and unable to find where we can backup entire schema (including all keyspaces and tables).
If you only need to backup scheme than you can use DESCRIBE KEYSPACE in cqlsh
cqlsh $(hostname) -e "DESCRIBE KEYSPACE <keyspace>;" > backup.cql
To restore scheme you can simply do
cat backup.cql | cqlsh $(hostname)
EDIT
To describe keyspace programmatically via thrift client. Compile client and then you can use describe_keyspaces/describe_keyspace
Cassandra.Client client = ...
for (KDef keyspaceDefinition : client.describe_keyspaces()) {
// process keyspace data
}
Related
I am new to Cassandra, I wrote a blog in French that narrate all the unpleasant experiences that I have because of him (like always having Unable to find java executable when launching it after rebooting or the 7199 always already in use...). I created a github repository to share my cassandra directory.
But until now I can manage them unti this new one that didn't appeared last time I tried to launch Cassandra.
I try to create a keyspace about Cassandra with the help of the tutorialspoint tutorial but there is a problem: When I make the command to create a Keyspace:
;CREATE KEYSPACE k1 WITH
strategy_class = 'SimpleStrategy'
AND trategy_otpions:replication_factor = '1';
...
Or even :
cqlsh> CREATE KEYSPACE k1 WITH
... replication = {'class': 'strategy_class = 'SimpleStrategy'
... AND trategy_otpions:replication_factor = '1';
...
It just won't compile even after a semicolon ...
Do you have an idea ?
Do you have a good tutorial on Cassandra ?
Edit 28/11
I don't know why but this command worked :
cqlsh> CREATE KEYSPACE IF NOT EXISTS k1 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} AND durable_writes = true;
My next question will be on how to import a very large csv file one can found on the open platform of French public data there is at least 150 column which can all have the vartext type but the first one which is numeric.
I think your syntax for cqlsh it's wrong, if the one that you pasted is the one that you used.
The correct syntax for cqlsh is CREATE KEYSPACE test WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 3};.
For importing data from a csv file you should read on this https://docs.datastax.com/en/cql/3.3/cql/cql_using/useInsertCopyCSV.html
Just installed Cassandra (3.11.1) and Datastax node.js driver (3.3.0).
Created a simple structure:
CREATE KEYSPACE CaseBox
WITH REPLICATION={
'class': 'SimpleStrategy',
'replication_factor': 1};
USE CaseBox;
CREATE TABLE Regions (
regionId int,
name varchar,
PRIMARY KEY ((regionId))
);
Trying connect to the keyspace with no success:
const client = new cassandra.Client({
contactPoints: ['localhost'],
keyspace: 'CaseBox'
});
await client.connect();
Error: Keyspace 'CaseBox' does not exist.
If I change the desired kayspace to system it works.
What's wrong? Please assist.
You can find my full Cassandra config, CQL and js scripts here.
Keyspace names are forced lower case when unquoted in CQL.
Use CREATE KEYSPACE "CaseBox" in CQL or keyspace: 'casebox' in Node.
Generally just use snake_case names as you won't get trapped like this as often.
i created a key space named 'hello' in Cassandra and started using it(use command). so the commands were typed after cqlsh:hello> in the cql. i then dropped the key space hello, but still it is showing cqlsh:hello> at beginning of each command. why so ?
The keyspace is gone, but you need to reset your session context with the 'use' command.
cqlsh:test> create keyspace xyz with replication = {'class':'SimpleStrategy', 'replication_factor':1} ;
cqlsh:test> use xyz;
cqlsh:xyz> drop keyspace xyz;
cqlsh:xyz> describe keyspace
Keyspace 'xyz' not found.
cqlsh:xyz>
when I am trying to run "describe keyspace keyspacename" command using datastax driver 3.0, it gives me an error
Exception in thread "main" com.datastax.driver.core.exceptions.SyntaxError: line 1:0 no viable alternative at input 'DESCRIBE' ([DESCRIBE]...)
How to run "describe keyspace keyspacename" command?
DESCRIBE is a cqlsh extension.
You could query system table like this
SELECT * from system.schema_keyspaces
WHERE keyspace_name = 'keyspacename';
Datastax's Java Driver has a class KeyspaceMetadata which exposes the method exportAsString. So I used that method to get entire keyspace schema as string using this method.
I use Titan 0.4.0 All, running Rexster in shared VM mode on Ubuntu 12.04.
How could I properly delete a graph in Titan which is using the Cassandra storage backend?
I have tried the TitanCleanup.clear(graph), but it does not delete everything. The indices are still there. My real issue is that I have an index which I don't want (it crashes every query), however as I understand Titan's documentation it is impossible to remove an index once it is created.
You can clear all the edges/vertices with:
g.V.remove()
but as you have found that won't clear the types/indices previously created. The most cleanly option would be to just delete the Cassandra data directory.
If you are executing the delete via a unit test you might try to do this as part of your test setup:
this.config = new BaseConfiguration(){{
addProperty("storage.backend", "berkeleyje")
addProperty("storage.directory", "/tmp/titan-schema-test")
}}
GraphDatabaseConfiguration graphconfig = new GraphDatabaseConfiguration(config)
graphconfig.getBackend().clearStorage()
g = (StandardTitanGraph) TitanFactory.open(config)
Be sure to call g.shutdown() in your test teardown method.
Just to update this answer.
With Titan 1.0.0 this can be done programmatically in Java with:
TitanGraph graph = TitanFactory.open(config);
graph.close();
TitanCleanup.clear(graph);
For the continuation of Titan called JanusGraph, the command is JanusGraphFactory.clear(graph) but is soon to be JanusGraphCleanup.clear(graph).
As was mentioned in one of the comments to the earlier answer DROPping a keyspace titan using cqlsh should do it:
cqlsh> DROP KEYSPACE titan;
The name of the keyspace Titan uses is set up using storage.cassandra.keyspace configuration option. You can change it to whatever name you want and is acceptable by Cassandra.
storage.cassandra.keyspace=hello_titan
When Cassandra is getting up, it prints out the keyspace's name as follows:
INFO 19:50:32 Create new Keyspace: KSMetaData{name=hello_titan,
strategyClass=SimpleStrategy, strategyOptions={replication_factor=1},
cfMetaData={}, durableWrites=true,
userTypes=org.apache.cassandra.config.UTMetaData#767d6a9f}
In 0.9.0-M1, the name appears in Titan's log in DEBUG (set log4j.rootLogger=DEBUG, stdout in conf/log4j-server.properties):
[DEBUG] AstyanaxStoreManager - Found keyspace titan
or the following when it doesn't:
[DEBUG] AstyanaxStoreManager - Creating keyspace titan...
[DEBUG] AstyanaxStoreManager - Created keyspace titan