1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

ctdb:vacuum: remove now unused ctdb_repack_tdb().

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
Michael Adam 2014-04-19 02:57:00 +02:00
parent 368683d7af
commit 413f99f86e

View File

@ -1295,135 +1295,6 @@ static int ctdb_vacuum_db(struct ctdb_db_context *ctdb_db,
return 0;
}
/*
* traverse function for repacking
*/
static int repack_traverse(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
void *private_data)
{
struct vacuum_data *vdata = (struct vacuum_data *)private_data;
if (vdata->vacuum) {
uint32_t hash = ctdb_hash(&key);
struct delete_record_data *kd;
/*
* check if we can ignore this record because it's in the delete_list
*/
kd = (struct delete_record_data *)trbt_lookup32(vdata->delete_list, hash);
/*
* there might be hash collisions so we have to compare the keys here to be sure
*/
if (kd && kd->key.dsize == key.dsize && memcmp(kd->key.dptr, key.dptr, key.dsize) == 0) {
struct ctdb_ltdb_header *hdr = (struct ctdb_ltdb_header *)data.dptr;
/*
* we have to check if the record hasn't changed in the meantime in order to
* savely remove it from the database
*/
if (data.dsize == sizeof(struct ctdb_ltdb_header) &&
hdr->dmaster == kd->ctdb->pnn &&
ctdb_lmaster(kd->ctdb, &(kd->key)) == kd->ctdb->pnn &&
kd->hdr.rsn == hdr->rsn) {
vdata->count.repack.vacuumed++;
return 0;
}
}
}
if (tdb_store(vdata->dest_db, key, data, TDB_INSERT) != 0) {
vdata->traverse_error = true;
return -1;
}
vdata->count.repack.copied++;
return 0;
}
/*
* repack a tdb
*/
static int ctdb_repack_tdb(struct tdb_context *tdb, TALLOC_CTX *mem_ctx, struct vacuum_data *vdata)
{
struct tdb_context *tmp_db;
if (tdb_transaction_start(tdb) != 0) {
DEBUG(DEBUG_ERR,(__location__ " Failed to start transaction\n"));
return -1;
}
tmp_db = tdb_open("tmpdb", tdb_hash_size(tdb),
TDB_INTERNAL|TDB_DISALLOW_NESTING,
O_RDWR|O_CREAT, 0);
if (tmp_db == NULL) {
DEBUG(DEBUG_ERR,(__location__ " Failed to create tmp_db\n"));
tdb_transaction_cancel(tdb);
return -1;
}
vdata->traverse_error = false;
vdata->dest_db = tmp_db;
vdata->vacuum = true;
vdata->count.repack.vacuumed = 0;
vdata->count.repack.copied = 0;
/*
* repack and vacuum on-the-fly by not writing the records that are
* no longer needed
*/
if (tdb_traverse_read(tdb, repack_traverse, vdata) == -1) {
DEBUG(DEBUG_ERR,(__location__ " Failed to traverse copying out\n"));
tdb_transaction_cancel(tdb);
tdb_close(tmp_db);
return -1;
}
DEBUG(DEBUG_INFO,(__location__ " %u records vacuumed\n",
vdata->count.repack.vacuumed));
if (vdata->traverse_error) {
DEBUG(DEBUG_ERR,(__location__ " Error during traversal\n"));
tdb_transaction_cancel(tdb);
tdb_close(tmp_db);
return -1;
}
if (tdb_wipe_all(tdb) != 0) {
DEBUG(DEBUG_ERR,(__location__ " Failed to wipe database\n"));
tdb_transaction_cancel(tdb);
tdb_close(tmp_db);
return -1;
}
vdata->traverse_error = false;
vdata->dest_db = tdb;
vdata->vacuum = false;
vdata->count.repack.copied = 0;
if (tdb_traverse_read(tmp_db, repack_traverse, vdata) == -1) {
DEBUG(DEBUG_ERR,(__location__ " Failed to traverse copying back\n"));
tdb_transaction_cancel(tdb);
tdb_close(tmp_db);
return -1;
}
if (vdata->traverse_error) {
DEBUG(DEBUG_ERR,(__location__ " Error during second traversal\n"));
tdb_transaction_cancel(tdb);
tdb_close(tmp_db);
return -1;
}
tdb_close(tmp_db);
if (tdb_transaction_commit(tdb) != 0) {
DEBUG(DEBUG_ERR,(__location__ " Failed to commit\n"));
return -1;
}
DEBUG(DEBUG_INFO,(__location__ " %u records copied\n",
vdata->count.repack.copied));
return 0;
}
/*
* repack and vaccum a db
* called from the child context