How to clean FoundationDB?
Asked Answered
C

3

8

Is there any fast way to remove all data from the local database? Like SQL 'drop database'?

I was looking through the documentation but haven't found anythig interesting yet.

Confabulation answered 28/1, 2014 at 21:57 Comment(0)
L
7

You can do this by clearing the entire range of keys.

In Python, it looks like this:

Database.clear_range('', '\xFF')

Where '' is the default slice begin, and '\xFF' is the default slice end, according to the clear_range documentation.

You can find the more information on clear_range for the API you're using in the documentation.

Laciniate answered 29/1, 2014 at 3:35 Comment(1)
Java version: public void clearDB() { db.run(new Function<Transaction, Void>() { public Void apply(final Transaction tr) { tr.clear(new Range(Tuple.from("").pack(), Tuple.from("xFF").pack())); return null; } }); }Confabulation
D
14

The "CLI" way

Using the provided fdbcli interface, you can clear all the keys in the database using a single clearrange command, like this:

fdb> writemode on
fdb> clearrange "" \xFF
Committed (68666816293119)

Be warned that it executes instantly and that there is no undo possible!

Also, any application still connected to the database may continue reading/writing data using cached directory subspace prefixes, which may introduce data corruption! You should make sure to only use this method when nothing is actively using the cluster.

This method requires that your cluster be in a working state, and it will not immediately reclaim the space used on disk, and also will not reset the cluster's read version.

The "hard" way

If you have a single-node cluster, you can stop the fdb service, remove all files in its data_dir folder, restart the service, and then using fdbcli, execute the configure new single ssd command.

This will reclaim the disk space used previously, and reset everything back to the post-install state.

Dorie answered 12/7, 2018 at 12:54 Comment(2)
"execute the create new single ssd command." That should be " execute the configure new single ssd command"Pamphylia
You are correct, I fixed the command with the correct keyword.Dorie
L
7

You can do this by clearing the entire range of keys.

In Python, it looks like this:

Database.clear_range('', '\xFF')

Where '' is the default slice begin, and '\xFF' is the default slice end, according to the clear_range documentation.

You can find the more information on clear_range for the API you're using in the documentation.

Laciniate answered 29/1, 2014 at 3:35 Comment(1)
Java version: public void clearDB() { db.run(new Function<Transaction, Void>() { public Void apply(final Transaction tr) { tr.clear(new Range(Tuple.from("").pack(), Tuple.from("xFF").pack())); return null; } }); }Confabulation
E
1

To do this programmatically in Java:

db.run(tx -> {
            final byte[] st = new Subspace(new byte[]{(byte) 0x00}).getKey();
            final byte[] en = new Subspace(new byte[]{(byte) 0xFF}).getKey();
            tx.clear(st, en);
            return null;
        });
Espinosa answered 30/7, 2018 at 2:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.