Skip to content

Commit

Permalink
Port cdb2_pgdump to master
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Hannum <[email protected]>
  • Loading branch information
markhannum committed Jul 25, 2022
1 parent 39ce80f commit 5e1dd84
Show file tree
Hide file tree
Showing 8 changed files with 706 additions and 34 deletions.
2 changes: 2 additions & 0 deletions bbinc/tohex.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ void hexdumpbuf(const char *key, int keylen, char **buf);
void hexdump(loglvl lvl, const char *key, int keylen);
void hexdumpdbt(DBT *dbt);
void hexdumpfp(FILE *fp, const unsigned char *key, int keylen);
void print_hex(const uint8_t *b, unsigned l);
void print_hex_nl(const uint8_t *b, unsigned l, int newline);
void fileid_str(u_int8_t *fileid, char *str);
#endif
36 changes: 12 additions & 24 deletions berkdb/btree/bt_prefix.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <db_config.h>
#include <db_int.h>
#include <build/db_config.h>
#include <build/db_int.h>
#include <dbinc/db_page.h>
#include <dbinc/db_shash.h>
#include <dbinc/log.h>
Expand All @@ -18,6 +18,7 @@
#include <assert.h>
#include <comdb2rle.h>
#include <logmsg.h>
#include <tohex.h>

struct pfx_type_t {
uint16_t npfx; /* pfx size */
Expand All @@ -30,19 +31,6 @@ struct pfx_type_t {
};


void
print_hex(uint8_t * b, unsigned l, int newline)
{
static char map[] = "0123456789abcdef";
int i;

for (i = 0; i < l; ++i) {
logmsg(LOGMSG_USER, "%c%c", map[b[i] >> 4], map[b[i] & 0x0f]);
}
if (newline)
logmsg(LOGMSG_USER, "\n");
}

void
inspect_bk(BKEYDATA *bk)
{
Expand All @@ -62,7 +50,7 @@ inspect_bk(BKEYDATA *bk)
logmsg(LOGMSG_USER, "not printing - too big");
break;
}
print_hex(bk->data, len, 0);
print_hex_nl(bk->data, len, 0);
logmsg(LOGMSG_USER, " [%s%s%s ]", B_PISSET(bk) ? "P" : " ",
B_RISSET(bk) ? "R" : " ", B_DISSET(bk) ? "X" : " ");
break;
Expand Down Expand Up @@ -100,15 +88,15 @@ inspect_page_hdr(DB *dbp, PAGE *h)

logmsg(LOGMSG_USER, "key-compression:yes pfx:0x");
if (pfx->nrle) {
print_hex(pfx->rle, pfx->nrle, 0);
print_hex_nl(pfx->rle, pfx->nrle, 0);
logmsg(LOGMSG_USER, " (uncompressed:0x");
}
print_hex(pfx->pfx, pfx->npfx, 0);
print_hex_nl(pfx->pfx, pfx->npfx, 0);
if (pfx->nrle)
logmsg(LOGMSG_USER, ")");
if (pfx->nsfx) {
logmsg(LOGMSG_USER, " sfx:0x");
print_hex(pfx->sfx, pfx->nsfx, 0);
print_hex_nl(pfx->sfx, pfx->nsfx, 0);
}
logmsg(LOGMSG_USER, " ");
} else {
Expand Down Expand Up @@ -477,19 +465,19 @@ find_pfx(DB *dbp, PAGE *h, pfx_t * pfx)
}
#if 0
printf("first: 0x");
print_hex(first->data, first->len, 1);
print_hex_nl(first->data, first->len, 1);
printf(" last: 0x");
print_hex(last->data, last->len, 1);
print_hex_nl(last->data, last->len, 1);
printf(" pfx: 0x");
print_hex(pfx->pfx, pfx->npfx, 0);
print_hex_nl(pfx->pfx, pfx->npfx, 0);
if (pfx->nsfx) {
printf("%.*s", 2 * (first->len - pfx->npfx - pfx->nsfx),
"----------------");
print_hex(pfx->sfx, pfx->nsfx, 0);
print_hex_nl(pfx->sfx, pfx->nsfx, 0);
}
if (pfx->nrle) {
printf(" -> 0x");
print_hex(pfx->rle, pfx->nrle, 0);
print_hex_nl(pfx->rle, pfx->nrle, 0);
}
puts("");
#endif
Expand Down
9 changes: 1 addition & 8 deletions comdb2rle/comdb2rle.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@
#endif

#ifdef CRLE_VERBOSE
static void print_hex(uint8_t *b, unsigned l)
{
static char map[] = "0123456789abcdef";
for (unsigned i = 0; i < l; ++i) {
fprintf(stderr, "%c%c", map[b[i] >> 4], map[b[i] & 0x0f]);
}
fprintf(stderr, "\n");
}
#include <tohex.h>

static int doprint = 0;
#endif
Expand Down
3 changes: 2 additions & 1 deletion db/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ set(src
${PROJECT_SOURCE_DIR}/tools/cdb2_printlog/comdb2_dbprintlog.c
${PROJECT_SOURCE_DIR}/tools/cdb2_stat/cdb2_stat.c
${PROJECT_SOURCE_DIR}/tools/cdb2_verify/cdb2_verify.c
${PROJECT_SOURCE_DIR}/tools/cdb2_pgdump/cdb2_pgdump.c
)

option(DEBUG_TYPES "Build types.c independent of sqlglue.c" OFF)
Expand Down Expand Up @@ -245,7 +246,7 @@ endif()
configure_file(copycomdb2 copycomdb2 @ONLY)

install(TARGETS comdb2 RUNTIME DESTINATION bin)
foreach(tool dump load printlog stat verify)
foreach(tool dump load printlog stat verify pgdump)
add_custom_command(
TARGET comdb2 POST_BUILD
COMMAND ln -f comdb2 cdb2_${tool}
Expand Down
3 changes: 2 additions & 1 deletion db/comdb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -5419,7 +5419,8 @@ static void goodbye()
TOOL(cdb2_load) \
TOOL(cdb2_printlog) \
TOOL(cdb2_stat) \
TOOL(cdb2_verify)
TOOL(cdb2_verify) \
TOOL(cdb2_pgdump)

#undef TOOL
#define TOOL(x) int tool_ ##x ##_main(int argc, char *argv[]);
Expand Down
1 change: 1 addition & 0 deletions docs/pages/overview/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Installing (from source or a package) creates a directory structure like this:
├── bin
│   ├── cdb2_dump
│   ├── cdb2_printlog
│   ├── cdb2_pgdump
│   ├── cdb2sql
│   ├── cdb2_stat
│   ├── cdb2_verify
Expand Down
Loading

0 comments on commit 5e1dd84

Please sign in to comment.