Commit a3fd9a14 authored by Libor Peltan's avatar Libor Peltan Committed by Daniel Salzman

kjournalprint: in debugmode print all history branches

parent ad730712
......@@ -19,7 +19,6 @@
#include <stdarg.h>
#include "knot/journal/journal.h"
#include "knot/zone/serial.h"
#include "knot/common/log.h"
#include "contrib/files.h"
#include "contrib/endian.h"
......@@ -1796,12 +1795,27 @@ scrape_end:
return txn->ret;
}
void journal_metadata_info(journal_t *j, bool *is_empty, uint32_t *serial_from, uint32_t *serial_to)
void journal_metadata_info(journal_t *j, bool *has_bootstrap, kserial_t *merged_serial,
kserial_t *first_serial, kserial_t *last_flushed, kserial_t *serial_to)
{
// NOTE: there is NEVER the situation that only merged changeset would be present and no common changeset in db.
if (j == NULL || j->db == NULL) {
*is_empty = true;
if (has_bootstrap != NULL) {
*has_bootstrap = false;
}
if (merged_serial != NULL) {
merged_serial->valid = false;
}
if (first_serial != NULL) {
first_serial->valid = false;
}
if (last_flushed != NULL) {
last_flushed->valid = false;
}
if (serial_to != NULL) {
serial_to->valid = false;
}
return;
}
......@@ -1809,13 +1823,26 @@ void journal_metadata_info(journal_t *j, bool *is_empty, uint32_t *serial_from,
txn_begin(txn, false);
txn_check_open(txn);
*is_empty = !md_flag(txn, SERIAL_TO_VALID);
*serial_from = txn->shadow_md.first_serial;
*serial_to = txn->shadow_md.last_serial_to;
if (md_flag(txn, MERGED_SERIAL_VALID)) {
*serial_from = txn->shadow_md.merged_serial;
if (has_bootstrap != NULL) {
*has_bootstrap = has_bootstrap_changeset(j, txn);
}
if (merged_serial != NULL) {
merged_serial->valid = md_flag(txn, MERGED_SERIAL_VALID);
merged_serial->serial = txn->shadow_md.merged_serial;
}
if (first_serial != NULL) {
first_serial->valid = !md_flag(txn, FIRST_SERIAL_INVALID);
first_serial->serial = txn->shadow_md.first_serial;
}
if (last_flushed != NULL) {
last_flushed->valid = md_flag(txn, LAST_FLUSHED_VALID);
last_flushed->serial = txn->shadow_md.last_flushed;
}
if (serial_to != NULL) {
serial_to->valid = md_flag(txn, SERIAL_TO_VALID);
serial_to->serial = txn->shadow_md.last_serial_to;
}
txn_abort(txn);
}
......
......@@ -22,6 +22,7 @@
#include "contrib/ucw/lists.h"
#include "knot/updates/changesets.h"
#include "knot/journal/serialization.h"
#include "knot/zone/serial.h"
/*! \brief Minimum journal size. */
#define JOURNAL_MIN_FSLIMIT (1 * 1024 * 1024)
......@@ -215,7 +216,8 @@ int journal_scrape(journal_t *j);
* \param[out] serial_from [if !is_empty] starting serial of changesets history
* \param[out] serial_to [if !is_empty] ending serial of changesets history
*/
void journal_metadata_info(journal_t *j, bool *is_empty, uint32_t *serial_from, uint32_t *serial_to);
void journal_metadata_info(journal_t *j, bool *is_empty, kserial_t *merged_serial,
kserial_t *first_serial, kserial_t *last_flushed, kserial_t *serial_to);
/*! \brief Check the journal consistency, errors to stderr.
*
......
......@@ -188,17 +188,23 @@ int print_journal(char *path, knot_dname_t *name, uint32_t limit, bool color, bo
return ret;
}
bool is_empty;
uint32_t serial_from, serial_to;
journal_metadata_info(j, &is_empty, &serial_from, &serial_to);
bool has_bootstrap;
kserial_t merged_serial, serial_from, last_flushed, serial_to;
journal_metadata_info(j, &has_bootstrap, &merged_serial, &serial_from, &last_flushed, &serial_to);
bool alternative_from = (has_bootstrap || merged_serial.valid);
bool is_empty = (!alternative_from && !serial_from.valid);
if (is_empty) {
ret = KNOT_ENOENT;
goto pj_finally;
}
ret = journal_load_bootstrap(j, &db);
if (ret == KNOT_ENOENT) {
ret = journal_load_changesets(j, &db, serial_from);
if (has_bootstrap) {
ret = journal_load_bootstrap(j, &db);
} else if (merged_serial.valid) {
ret = journal_load_changesets(j, &db, merged_serial.serial);
} else {
ret = journal_load_changesets(j, &db, serial_from.serial);
}
if (ret != KNOT_EOK) {
goto pj_finally;
......@@ -221,6 +227,24 @@ int print_journal(char *path, knot_dname_t *name, uint32_t limit, bool color, bo
changesets_free(&db);
if ((debugmode && alternative_from && serial_from.valid) ||
kserial_equal(serial_from, last_flushed)) {
printf("---------------------------------------------------------------------------------------\n");
init_list(&db);
ret = journal_load_changesets(j, &db, serial_from.serial);
if (ret != KNOT_EOK) {
goto pj_finally;
}
WALK_LIST(chs, db) {
print_changeset_debugmode(chs);
if (last_flushed.valid && serial_equal(knot_soa_serial(&chs->soa_from->rrs), last_flushed.serial)) {
break;
}
}
changesets_free(&db);
}
pj_finally:
journal_close(j);
journal_free(&j);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment