Skip to content
Snippets Groups Projects
Commit 428fe5d1 authored by Daniel Salzman's avatar Daniel Salzman
Browse files

Merge branch 'kjournalprint_fix_limit' into 'master'

kjournalprint: fix changeset history depth limitation

See merge request knot/knot-dns!1013
parents fa4c9ae1 a810af5e
No related branches found
No related tags found
1 merge request!1013kjournalprint: fix changeset history depth limitation
Pipeline #48591 passed
......@@ -53,6 +53,9 @@ Removes changes coloring.
Instead of reading jurnal, display the list of zones in the DB.
(\fIzone_name\fP not needed)
.TP
\fB\-c\fP, \fB\-\-check\fP
Enable additional journal semantic checks during printing.
.TP
\fB\-h\fP, \fB\-\-help\fP
Print the program help.
.TP
......
......@@ -30,6 +30,9 @@ Options
Instead of reading jurnal, display the list of zones in the DB.
(*zone_name* not needed)
**-c**, **--check**
Enable additional journal semantic checks during printing.
**-h**, **--help**
Print the program help.
......
......@@ -45,15 +45,24 @@ static void print_help(void)
" -n, --no-color Get output without terminal coloring.\n"
" -z, --zone-list Instead of reading jurnal, display the list\n"
" of zones in the DB (<zone_name> not needed).\n"
" -c, --check Additional journal semantic checks.\n"
" -d, --debug Debug mode output.\n"
" -h, --help Print the program help.\n"
" -V, --version Print the program version.\n",
PROGRAM_NAME);
}
static void print_changeset(const changeset_t *chs, bool color)
typedef struct {
bool debug;
bool color;
bool check;
int limit;
int counter;
} print_params_t;
static void print_changeset(const changeset_t *chs, print_params_t *params)
{
printf(color ? YLW : "");
printf(params->color ? YLW : "");
if (chs->soa_from == NULL) {
printf(";; Zone-in-journal, serial: %u\n",
knot_soa_serial(chs->soa_to->rrs.rdata));
......@@ -62,7 +71,7 @@ static void print_changeset(const changeset_t *chs, bool color)
knot_soa_serial(chs->soa_from->rrs.rdata),
knot_soa_serial(chs->soa_to->rrs.rdata));
}
changeset_print(chs, stdout, color);
changeset_print(chs, stdout, params->color);
}
dynarray_declare(rrtype, uint16_t, DYNARRAY_VISIBILITY_STATIC, 100)
......@@ -125,23 +134,34 @@ static void print_changeset_debugmode(const changeset_t *chs)
printf("\n");
}
static int print_changeset_cb(bool special, const changeset_t *ch, void *ctx)
static int count_changeset_cb(bool special, const changeset_t *ch, void *ctx)
{
bool *parm = ctx;
UNUSED(special);
print_params_t *params = ctx;
if (ch != NULL) {
if (parm[0]) {
params->counter++;
}
return KNOT_EOK;
}
static int print_changeset_cb(bool special, const changeset_t *ch, void *ctx)
{
print_params_t *params = ctx;
if (ch != NULL && params->counter++ >= params->limit) {
if (params->debug) {
print_changeset_debugmode(ch);
} else {
print_changeset(ch, parm[1]);
print_changeset(ch, params);
}
if (special && parm[0]) {
if (special && params->debug) {
printf("---------------------------------------------\n");
}
}
return KNOT_EOK;
}
int print_journal(char *path, knot_dname_t *name, uint32_t limit, bool color, bool debugmode, bool do_check)
int print_journal(char *path, knot_dname_t *name, print_params_t *params)
{
knot_lmdb_db_t jdb = { 0 };
zone_journal_t j = { &jdb, name };
......@@ -162,19 +182,29 @@ int print_journal(char *path, knot_dname_t *name, uint32_t limit, bool color, bo
return ret == KNOT_EOK ? KNOT_ENOENT : ret;
}
if (do_check) {
if (params->check) {
ret = journal_sem_check(j);
if (ret > 0) {
fprintf(stderr, "Journal semantic check error: %d\n", ret);
} else if (ret != KNOT_EOK) {
fprintf(stderr, "Journal semnatic check failed (%s).\n", knot_strerror(ret));
fprintf(stderr, "Journal semantic check failed (%s).\n", knot_strerror(ret));
}
}
bool parm[2] = { debugmode, color };
ret = journal_walk(j, print_changeset_cb, (void *)parm);
if (params->limit >= 0 && ret == KNOT_EOK) {
ret = journal_walk(j, count_changeset_cb, params);
}
if (ret == KNOT_EOK) {
if (params->limit < 0 || params->counter <= params->limit) {
params->limit = 0;
} else {
params->limit = params->counter - params->limit;
}
params->counter = 0;
ret = journal_walk(j, print_changeset_cb, params);
}
if (debugmode && ret == KNOT_EOK) {
if (params->debug && ret == KNOT_EOK) {
printf("Occupied this zone (approx): %"PRIu64" KiB\n", occupied / 1024);
printf("Occupied all zones together: %"PRIu64" KiB\n", occupied_all / 1024);
}
......@@ -203,13 +233,20 @@ int list_zones(char *path)
int main(int argc, char *argv[])
{
uint32_t limit = 0;
bool color = true, justlist = false, debugmode = false, docheck = false;
bool justlist = false;
print_params_t params = {
.debug = false,
.color = true,
.check = false,
.limit = -1,
};
struct option opts[] = {
{ "limit", required_argument, NULL, 'l' },
{ "no-color", no_argument, NULL, 'n' },
{ "zone-list", no_argument, NULL, 'z' },
{ "check", no_argument, NULL, 'c' },
{ "debug", no_argument, NULL, 'd' },
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
......@@ -220,22 +257,22 @@ int main(int argc, char *argv[])
while ((opt = getopt_long(argc, argv, "l:nzcdhV", opts, NULL)) != -1) {
switch (opt) {
case 'l':
if (str_to_u32(optarg, &limit) != KNOT_EOK) {
if (str_to_int(optarg, &params.limit, 0, INT_MAX) != KNOT_EOK) {
print_help();
return EXIT_FAILURE;
}
break;
case 'n':
color = false;
params.color = false;
break;
case 'z':
justlist = true;
break;
case 'c':
docheck = true;
params.check = true;
break;
case 'd':
debugmode = true;
params.debug = true;
break;
case 'h':
print_help();
......@@ -292,7 +329,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
int ret = print_journal(db, name, limit, color, debugmode, docheck);
int ret = print_journal(db, name, &params);
free(name);
switch (ret) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment