2008-01-18 16:01:25 +00:00
|
|
|
/* Tell me the diff between two brt files. */
|
2008-01-22 19:30:02 +00:00
|
|
|
#include <ctype.h>
|
2008-01-18 16:01:25 +00:00
|
|
|
#include <fcntl.h>
|
2008-02-06 20:09:23 +00:00
|
|
|
#include <inttypes.h>
|
2008-02-08 03:17:38 +00:00
|
|
|
|
|
|
|
#include "toku_assert.h"
|
2008-01-18 16:01:25 +00:00
|
|
|
#include "key.h"
|
|
|
|
#include "brt-internal.h"
|
|
|
|
|
2008-04-30 13:23:04 +00:00
|
|
|
static int dump_data = 1;
|
|
|
|
|
2008-04-27 17:54:24 +00:00
|
|
|
void print_item (bytevec val, ITEMLEN len) {
|
|
|
|
printf("\"");
|
|
|
|
ITEMLEN i;
|
|
|
|
for (i=0; i<len; i++) {
|
|
|
|
unsigned char ch = ((unsigned char*)val)[i];
|
|
|
|
if (isprint(ch) && ch!='\\' && ch!='"') {
|
|
|
|
printf("%c", ch);
|
|
|
|
} else {
|
|
|
|
printf("\\%03o", ch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("\"");
|
|
|
|
}
|
|
|
|
|
2008-01-22 16:27:54 +00:00
|
|
|
void dump_header (int f, struct brt_header **header) {
|
2008-01-18 16:01:25 +00:00
|
|
|
struct brt_header *h;
|
|
|
|
int r;
|
|
|
|
r = toku_deserialize_brtheader_from (f, 0, &h); assert(r==0);
|
|
|
|
printf("brtheader:\n");
|
2008-05-22 21:28:00 +00:00
|
|
|
if (h->layout_version==BRT_LAYOUT_VERSION_6) printf(" layout_version<=6\n");
|
|
|
|
else printf(" layout_version=%d\n", h->layout_version);
|
2008-01-18 16:01:25 +00:00
|
|
|
printf(" dirty=%d\n", h->dirty);
|
|
|
|
printf(" nodesize=%d\n", h->nodesize);
|
|
|
|
printf(" freelist=%lld\n", h->freelist);
|
|
|
|
printf(" unused_memory=%lld\n", h->unused_memory);
|
2008-05-22 21:28:00 +00:00
|
|
|
if (h->n_named_roots==-1) {
|
|
|
|
printf(" unnamed_root=%lld\n", h->roots[0]);
|
|
|
|
printf(" flags=%d\n", h->flags_array[0]);
|
|
|
|
} else {
|
|
|
|
printf(" n_named_roots=%d\n", h->n_named_roots);
|
|
|
|
if (h->n_named_roots>=0) {
|
|
|
|
int i;
|
|
|
|
for (i=0; i<h->n_named_roots; i++) {
|
|
|
|
printf(" %s -> %lld\n", h->names[i], h->roots[i]);
|
|
|
|
printf(" flags=%d\n", h->flags_array[i]);
|
|
|
|
}
|
2008-01-22 16:27:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
*header = h;
|
2008-04-27 17:54:24 +00:00
|
|
|
printf("Fifo:\n");
|
|
|
|
r = toku_deserialize_fifo_at(f, h->unused_memory, &h->fifo);
|
|
|
|
printf(" fifo has %d entries\n", toku_fifo_n_entries(h->fifo));
|
2008-04-30 13:23:04 +00:00
|
|
|
if (dump_data) {
|
|
|
|
FIFO_ITERATE(h->fifo, key, keylen, data, datalen, type, xid,
|
|
|
|
({
|
|
|
|
printf(" ");
|
|
|
|
switch (type) {
|
|
|
|
case BRT_NONE: printf("NONE"); goto ok;
|
|
|
|
case BRT_INSERT: printf("INSERT"); goto ok;
|
|
|
|
case BRT_DELETE_ANY: printf("DELETE_ANY"); goto ok;
|
|
|
|
case BRT_DELETE_BOTH: printf("DELETE_BOTH"); goto ok;
|
|
|
|
case BRT_ABORT_ANY: printf("ABORT_ANY"); goto ok;
|
|
|
|
case BRT_ABORT_BOTH: printf("ABORT_BOTH"); goto ok;
|
|
|
|
case BRT_COMMIT_ANY: printf("COMMIT_ANY"); goto ok;
|
|
|
|
case BRT_COMMIT_BOTH: printf("COMMIT_BOTH"); goto ok;
|
|
|
|
}
|
|
|
|
printf("huh?");
|
|
|
|
ok:
|
|
|
|
printf(" %lld ", (long long)xid);
|
|
|
|
print_item(key, keylen);
|
|
|
|
printf(" ");
|
|
|
|
print_item(data, datalen);
|
|
|
|
printf("\n");
|
|
|
|
}));
|
|
|
|
}
|
2008-01-22 19:30:02 +00:00
|
|
|
}
|
|
|
|
|
2008-04-17 03:11:55 +00:00
|
|
|
void dump_node (int f, DISKOFF off) {
|
2008-01-22 16:27:54 +00:00
|
|
|
BRTNODE n;
|
2008-04-17 03:11:55 +00:00
|
|
|
int r = toku_deserialize_brtnode_from (f, off, &n);
|
2008-01-22 16:27:54 +00:00
|
|
|
assert(r==0);
|
2008-03-17 02:40:59 +00:00
|
|
|
assert(n!=0);
|
2008-01-22 19:30:02 +00:00
|
|
|
printf("brtnode\n");
|
|
|
|
printf(" nodesize =%u\n", n->nodesize);
|
2008-02-25 22:46:48 +00:00
|
|
|
printf(" sizeonddisk =%d\n", toku_serialize_brtnode_size(n));
|
2008-01-22 19:30:02 +00:00
|
|
|
printf(" flags =%u\n", n->flags);
|
|
|
|
printf(" thisnodename=%lld\n", n->thisnodename);
|
2008-02-06 20:09:23 +00:00
|
|
|
printf(" disk_lsn =%" PRId64 "\n", n->disk_lsn.lsn);
|
2008-01-23 18:06:23 +00:00
|
|
|
//printf(" log_lsn =%lld\n", n->log_lsn.lsn); // The log_lsn is a memory-only value.
|
2008-01-22 19:30:02 +00:00
|
|
|
printf(" height =%d\n", n->height);
|
2008-04-24 15:44:10 +00:00
|
|
|
printf(" layout_version=%d\n", n->layout_version);
|
2008-01-22 19:30:02 +00:00
|
|
|
printf(" rand4fp =%08x\n", n->rand4fingerprint);
|
|
|
|
printf(" localfp =%08x\n", n->local_fingerprint);
|
|
|
|
if (n->height>0) {
|
|
|
|
printf(" n_children=%d\n", n->u.n.n_children);
|
|
|
|
printf(" total_childkeylens=%u\n", n->u.n.totalchildkeylens);
|
|
|
|
printf(" n_bytes_in_buffers=%u\n", n->u.n.n_bytes_in_buffers);
|
|
|
|
int i;
|
|
|
|
printf(" subfingerprints={");
|
|
|
|
for (i=0; i<n->u.n.n_children; i++) {
|
|
|
|
if (i>0) printf(" ");
|
2008-01-31 22:05:43 +00:00
|
|
|
printf("%08x", BNC_SUBTREE_FINGERPRINT(n, i));
|
2008-01-22 19:30:02 +00:00
|
|
|
}
|
|
|
|
printf("}\n");
|
2008-04-30 13:23:04 +00:00
|
|
|
printf(" subleafentry_estimates={");
|
|
|
|
for (i=0; i<n->u.n.n_children; i++) {
|
|
|
|
if (i>0) printf(" ");
|
|
|
|
printf("%lld", (unsigned long long)(BNC_SUBTREE_LEAFENTRY_ESTIMATE(n, i)));
|
|
|
|
}
|
|
|
|
printf("}\n");
|
2008-01-22 19:30:02 +00:00
|
|
|
printf(" pivots:\n");
|
|
|
|
for (i=0; i<n->u.n.n_children-1; i++) {
|
|
|
|
struct kv_pair *piv = n->u.n.childkeys[i];
|
|
|
|
printf(" pivot %d:", i);
|
|
|
|
print_item(kv_pair_key_const(piv), kv_pair_keylen(piv));
|
|
|
|
assert(n->flags==0); // if not zero, we must print the other part of the pivot.
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
printf(" children:\n");
|
|
|
|
for (i=0; i<n->u.n.n_children; i++) {
|
2008-01-31 22:05:43 +00:00
|
|
|
printf(" child %d: %lld\n", i, BNC_DISKOFF(n, i));
|
2008-02-06 19:28:01 +00:00
|
|
|
printf(" buffer contains %d bytes (%d items)\n", BNC_NBYTESINBUF(n, i), toku_fifo_n_entries(BNC_BUFFER(n,i)));
|
2008-04-30 13:23:04 +00:00
|
|
|
if (dump_data) {
|
|
|
|
FIFO_ITERATE(BNC_BUFFER(n,i), key, keylen, data, datalen, typ, xid,
|
|
|
|
({
|
|
|
|
printf(" TYPE=");
|
|
|
|
switch ((enum brt_cmd_type)typ) {
|
|
|
|
case BRT_NONE: printf("NONE"); goto ok;
|
|
|
|
case BRT_INSERT: printf("INSERT"); goto ok;
|
|
|
|
case BRT_DELETE_ANY: printf("DELETE_ANY"); goto ok;
|
|
|
|
case BRT_DELETE_BOTH: printf("DELETE_BOTH"); goto ok;
|
|
|
|
case BRT_ABORT_ANY: printf("ABORT_ANY"); goto ok;
|
|
|
|
case BRT_ABORT_BOTH: printf("ABORT_BOTH"); goto ok;
|
|
|
|
case BRT_COMMIT_ANY: printf("COMMIT_ANY"); goto ok;
|
|
|
|
case BRT_COMMIT_BOTH: printf("COMMIT_BOTH"); goto ok;
|
|
|
|
}
|
|
|
|
printf("HUH?");
|
|
|
|
ok:
|
|
|
|
printf(" xid=%"PRId64" ", xid);
|
|
|
|
print_item(key, keylen);
|
|
|
|
if (datalen>0) {
|
|
|
|
printf(" ");
|
|
|
|
print_item(data, datalen);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2008-01-22 19:30:02 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printf(" n_bytes_in_buffer=%d\n", n->u.l.n_bytes_in_buffer);
|
2008-04-22 20:39:50 +00:00
|
|
|
printf(" items_in_buffer =%d\n", toku_omt_size(n->u.l.buffer));
|
2008-04-25 13:45:55 +00:00
|
|
|
int print_le(OMTVALUE lev, u_int32_t UU(idx), void *UU(v)) {
|
|
|
|
LEAFENTRY le=lev;
|
2008-04-22 20:39:50 +00:00
|
|
|
print_leafentry(stdout, le);
|
|
|
|
printf("\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2008-04-30 13:23:04 +00:00
|
|
|
if (dump_data) toku_omt_iterate(n->u.l.buffer, print_le, 0);
|
2008-01-22 19:30:02 +00:00
|
|
|
}
|
2008-05-22 21:28:00 +00:00
|
|
|
toku_brtnode_free(&n);
|
2008-01-18 16:01:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, const char *argv[]) {
|
2008-04-30 13:23:04 +00:00
|
|
|
const char *arg0 = argv[0];
|
|
|
|
argc--; argv++;
|
|
|
|
while (argc>1) {
|
|
|
|
if (strcmp(argv[0], "--nodata")==0) {
|
|
|
|
dump_data = 0;
|
|
|
|
} else {
|
|
|
|
printf("Usage: %s [--nodata] brtfilename\n", arg0);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
argc--; argv++;
|
|
|
|
}
|
|
|
|
assert(argc==1);
|
|
|
|
const char *n = argv[0];
|
2008-01-18 16:01:25 +00:00
|
|
|
int f = open(n, O_RDONLY); assert(f>=0);
|
2008-01-22 16:27:54 +00:00
|
|
|
struct brt_header *h;
|
|
|
|
dump_header(f, &h);
|
2008-01-22 19:30:02 +00:00
|
|
|
DISKOFF off;
|
|
|
|
for (off=h->nodesize; off<h->unused_memory; off+=h->nodesize) {
|
2008-04-17 03:11:55 +00:00
|
|
|
dump_node(f, off);
|
2008-01-22 19:30:02 +00:00
|
|
|
}
|
2008-05-22 21:28:00 +00:00
|
|
|
toku_brtheader_free(h);
|
|
|
|
toku_malloc_cleanup();
|
2008-01-18 16:01:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|