1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#ident "$Id$"
/*======
This file is part of TokuDB
Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.
TokuDBis is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2,
as published by the Free Software Foundation.
TokuDB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with TokuDB. If not, see <http://www.gnu.org/licenses/>.
======= */
#ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved."
// This program finds all of the tokudb status dictionary files and deletes the FRM from them.
//
// Requirements:
// The directory containing the tokudb environment is passed as a parameter.
// Needs the log*.tokulog* crash recovery log files.
// Needs a clean shutdown in the recovery log.
// Needs the tokudb.* metadata files.
//
// Effects:
// Deletes the FRM row from all of the tokudb status dictionaries.
// Creates a new crash recovery log.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <string.h>
#include <assert.h>
#include <db.h>
static int delete_frm_from_status(DB_ENV *env, DB_TXN *txn, const char *dname) {
int r;
DB *db = NULL;
r = db_create(&db, env, 0);
assert(r == 0);
r = db->open(db, txn, dname, NULL, DB_BTREE, 0, 0);
assert(r == 0);
uint64_t k = 5;
DBT delkey = { .data = &k, .size = sizeof k };
r = db->del(db, txn, &delkey, 0);
assert(r == 0);
r = db->close(db, 0);
assert(r == 0);
return 0;
}
static int find_status_and_delete_frm(DB_ENV *env, DB_TXN *txn) {
int r;
DBC *c = NULL;
r = env->get_cursor_for_directory(env, txn, &c);
assert(r == 0);
DBT key = { }; key.flags = DB_DBT_REALLOC;
DBT val = { }; val.flags = DB_DBT_REALLOC;
while (1) {
r = c->c_get(c, &key, &val, DB_NEXT);
if (r == DB_NOTFOUND)
break;
const char *dname = (const char *) key.data;
const char *iname = (const char *) val.data;
fprintf(stderr, "dname=%s iname=%s\n", dname, iname);
assert(r == 0);
if (strstr(iname, "_status_")) {
fprintf(stderr, "delete frm from %s\n", iname);
if (1) {
r = delete_frm_from_status(env, txn, dname);
assert(r == 0);
}
}
}
free(key.data);
free(val.data);
r = c->c_close(c);
assert(r == 0);
return 0;
}
int main(int argc, char *argv[]) {
if (argc != 2) {
fprintf(stderr, "datadir name missing\n");
return 1;
}
char *datadir = argv[1];
// open the env
int r;
DB_ENV *env = NULL;
r = db_env_create(&env, 0);
assert(r == 0);
env->set_errfile(env, stderr);
r = env->open(env, datadir, DB_INIT_LOCK+DB_INIT_MPOOL+DB_INIT_TXN+DB_INIT_LOG + DB_PRIVATE+DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO);
// open will fail if the recovery log was not cleanly shutdown
assert(r == 0);
// use a single txn to cover all of the status file changes
DB_TXN *txn = NULL;
r = env->txn_begin(env, NULL, &txn, 0);
assert(r == 0);
r = find_status_and_delete_frm(env, txn);
assert(r == 0);
r = txn->commit(txn, 0);
assert(r == 0);
// close the env
r = env->close(env, 0);
assert(r == 0);
return 0;
}
|