mdbx-load: add -p option (purge subDB).

Change-Id: I678950c99c8b4aea1add4ce548c9b4fe4ab8bfe6
This commit is contained in:
Leonid Yuriev 2020-12-03 21:52:22 +03:00
parent 90309ec0bf
commit d9bd306da3
2 changed files with 20 additions and 6 deletions

View File

@ -21,11 +21,12 @@ Removed options and features:
- Drop `MDBX_HUGE_TRANSACTIONS` build-option (now no longer required).
Added features:
New features:
- Package for FreeBSD is available now by Mahlon E. Smith.
- New API functions to get/set various options (https://github.com/erthink/libmdbx/issues/128).
- Unlimited/Dynamic size of retired and dirty page lists (https://github.com/erthink/libmdbx/issues/123).
- Added `-p` option (purge subDB before loading) to `mdbx_load` tool.
Fixes:

View File

@ -448,16 +448,17 @@ static int readline(MDBX_val *out, MDBX_val *buf) {
static void usage(void) {
fprintf(stderr,
"usage: %s [-V] [-q] [-a] [-f file] [-s name] [-N] [-T] [-r] [-n]"
" dbpath\n"
"usage: %s "
"[-V] [-q] [-a] [-f file] [-s name] [-N] [-p] [-T] [-r] [-n] dbpath\n"
" -V\t\tprint version and exit\n"
" -q\t\tbe quiet\n"
" -a\t\tappend records in input order (required for custom "
"comparators)\n"
" -f file\tread from file instead of stdin\n"
" -s name\tload into named subDB\n"
" -N\t\tdon't overwrite existing records when loading (), just skip "
"them\n"
" -N\t\tdon't overwrite existing records when loading, just skip "
"ones\n"
" -p\t\tpurge subDB before loading\n"
" -T\t\tread plaintext\n"
" -r\t\trescue mode (ignore errors to load corrupted DB dump)\n"
" -n\t\tdon't use subdirectory for newly created database "
@ -483,12 +484,13 @@ int main(int argc, char *argv[]) {
int envflags = MDBX_SAFE_NOSYNC | MDBX_ACCEDE, putflags = MDBX_UPSERT;
bool quiet = false;
bool rescue = false;
bool purge = false;
prog = argv[0];
if (argc < 2)
usage();
while ((i = getopt(argc, argv, "af:ns:NTVrq")) != EOF) {
while ((i = getopt(argc, argv, "af:ns:NpTVrq")) != EOF) {
switch (i) {
case 'V':
printf("mdbx_load version %d.%d.%d.%d\n"
@ -523,6 +525,9 @@ int main(int argc, char *argv[]) {
case 'N':
putflags |= MDBX_NOOVERWRITE | MDBX_NODUPDATA;
break;
case 'p':
purge = true;
break;
case 'T':
mode |= NOHDR | PRINT;
break;
@ -696,6 +701,14 @@ int main(int argc, char *argv[]) {
}
}
if (purge) {
rc = mdbx_drop(txn, dbi, false);
if (unlikely(rc != MDBX_SUCCESS)) {
error("mdbx_drop", rc);
goto txn_abort;
}
}
if (putflags & MDBX_APPEND)
putflags = (dbi_flags & MDBX_DUPSORT) ? putflags | MDBX_APPENDDUP
: putflags & ~MDBX_APPENDDUP;