Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 680 Vote(s) - 3.43 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to delete all the records from cassandra table without creating a snapshot

#1
I am facing a problem with deleting all the records from a table.

I can use Truncate table. But truncate would create a snapshot of the data which would be a wastage of storage space in my scenario.

Also truncate would fail if any of the nodes are down.

So I would like to know if there is any way to delete all the records in a table without creating a snapshot that works if a node is down.
Reply

#2
simple use like this

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;

public class Truncate_Table {

public static void main(String args[]){

//Query
String query = "Truncate student;";

//Creating Cluster object
Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build();

//Creating Session object
Session session = cluster.connect("tp");

//Executing the query
session.execute(query);
System.out.println("Table truncated");
}
}

i think this will help you
Reply

#3
To alter the behavior of creating a snapshot before truncate you can change your cassandra.yaml

# Whether or not a snapshot is taken of the data before keyspace truncation
# or dropping of column families. The STRONGLY advised default of true
# should be used to provide data safety. If you set this flag to false, you will
# lose data on truncation or drop.
auto_snapshot: true

This value is set to true by default. If you don't want this, you can simply set it to false. Just a little warning here, this flag is to make sure that after a drop or a truncate your data is not lost without a second thought. So think really carefully if you really want to disable that feature.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through