Siv*_*y M 3 cassandra datastax-java-driver datastax cassandra-2.0 cassandra-2.1
我在删除表中的所有记录时遇到问题.
我可以使用Truncate表.但truncate会创建数据的快照,这可能是我方案中存储空间的浪费.
如果任何节点关闭,截断也会失败.
所以我想知道是否有任何方法可以删除表中的所有记录而不创建在节点关闭时有效的快照.
要在截断之前更改创建快照的行为,可以更改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
Run Code Online (Sandbox Code Playgroud)
默认情况下,此值设置为true.如果您不想这样,您只需将其设置为false即可.这里只是一个小小的警告,这个标志是为了确保在丢弃或截断之后你的数据不会丢失而不再考虑.因此,如果您真的想要禁用该功能,请仔细考虑.
小智 -3
像这样简单的使用
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");
}
}
Run Code Online (Sandbox Code Playgroud)
我想这会对你有帮助
| 归档时间: |
|
| 查看次数: |
2373 次 |
| 最近记录: |