static int visit_node(Db *db, int depth, const DocInfo* docinfo, uint64_t subtreeSize, const sized_buf* reduceValue, void *ctx) { (void) db; for (int i = 0; i < depth; ++i) printf(" "); if (reduceValue) { // This is a tree node: printf("+ (%llu) ", (unsigned long long) subtreeSize); printsbhex(reduceValue, 0); } else if (docinfo->bp > 0) { // This is a document: printf("%c (%llu) ", (docinfo->deleted ? 'x' : '*'), (unsigned long long) docinfo->size); if (mode == DumpBySequence) { printf("#%llu ", (unsigned long long) docinfo->db_seq); } printsb(&docinfo->id); int *count = (int *) ctx; (*count)++; } else { // Document, but not in a known format: printf("**corrupt?** "); printsbhex(&docinfo->rev_meta, 1); } return 0; }
static int foldprint(Db *db, DocInfo *docinfo, void *ctx) { int *count = (int *) ctx; (*count)++; Doc *doc = NULL; uint64_t cas; uint32_t expiry, flags; if (mode == DumpBySequence) { printf("Doc seq: %"PRIu64"\n", docinfo->db_seq); printf(" id: "); printsb(&docinfo->id); } else { printf(" Doc ID: "); printsb(&docinfo->id); if (docinfo->db_seq > 0) { printf(" seq: %"PRIu64"\n", docinfo->db_seq); } } if (docinfo->bp == 0 && docinfo->deleted == 0) { printf(" ** This b-tree node is corrupt; raw node value follows:*\n"); printf(" raw: "); printsbhex(&docinfo->rev_meta, 1); return 0; } printf(" rev: %"PRIu64"\n", docinfo->rev_seq); printf(" content_meta: %d\n", docinfo->content_meta); if (docinfo->rev_meta.size == sizeof(CouchbaseRevMeta)) { const CouchbaseRevMeta* meta = (const CouchbaseRevMeta*)docinfo->rev_meta.buf; cas = decode_raw64(meta->cas); expiry = decode_raw32(meta->expiry); flags = decode_raw32(meta->flags); printf(" cas: %"PRIu64", expiry: %"PRIu32", flags: %"PRIu32"\n", cas, expiry, flags); } if (docinfo->deleted) { printf(" doc deleted\n"); } couchstore_error_t docerr = couchstore_open_doc_with_docinfo(db, docinfo, &doc, 0); if(docerr != COUCHSTORE_SUCCESS) { printf(" could not read document body: %s\n", couchstore_strerror(docerr)); } else if (doc && (docinfo->content_meta & COUCH_DOC_IS_COMPRESSED)) { size_t rlen; snappy_uncompressed_length(doc->data.buf, doc->data.size, &rlen); char *decbuf = (char *) malloc(rlen); size_t uncompr_len; snappy_uncompress(doc->data.buf, doc->data.size, decbuf, &uncompr_len); printf(" data: (snappy) %.*s\n", (int) uncompr_len, decbuf); free(decbuf); } else if(doc) { printf(" data: "); printsb(&doc->data); } couchstore_free_document(doc); return 0; }
static int foldprint(Db *db, DocInfo *docinfo, void *ctx) { int *count = (int *) ctx; Doc *doc = NULL; uint64_t cas; uint32_t expiry, flags; couchstore_error_t docerr; (*count)++; if (dumpJson) { printf("{\"seq\":%"PRIu64",\"id\":\"", docinfo->db_seq); printjquote(&docinfo->id); printf("\","); } else { if (mode == DumpBySequence) { printf("Doc seq: %"PRIu64"\n", docinfo->db_seq); printf(" id: "); printsb(&docinfo->id); } else { printf(" Doc ID: "); printsb(&docinfo->id); if (docinfo->db_seq > 0) { printf(" seq: %"PRIu64"\n", docinfo->db_seq); } } } if (docinfo->bp == 0 && docinfo->deleted == 0 && !dumpJson) { printf(" ** This b-tree node is corrupt; raw node value follows:*\n"); printf(" raw: "); printsbhex(&docinfo->rev_meta, 1); return 0; } if (dumpJson) { printf("\"rev\":%"PRIu64",\"content_meta\":%d,", docinfo->rev_seq, docinfo->content_meta); printf("\"physical_size\":%zu,", docinfo->size); } else { printf(" rev: %"PRIu64"\n", docinfo->rev_seq); printf(" content_meta: %d\n", docinfo->content_meta); printf(" size (on disk): %zu\n", docinfo->size); } if (docinfo->rev_meta.size >= sizeof(CouchbaseRevMeta)) { const CouchbaseRevMeta* meta = (const CouchbaseRevMeta*)docinfo->rev_meta.buf; cas = decode_raw64(meta->cas); expiry = decode_raw32(meta->expiry); flags = decode_raw32(meta->flags); if (dumpJson) { printf("\"cas\":\"%"PRIu64"\",\"expiry\":%"PRIu32",\"flags\":%"PRIu32",", cas, expiry, flags); } else { printf(" cas: %"PRIu64", expiry: %"PRIu32", flags: %"PRIu32"\n", cas, expiry, flags); } } if (docinfo->deleted) { if (dumpJson) { printf("\"deleted\":true,"); } else { printf(" doc deleted\n"); } } if (!noBody) { docerr = couchstore_open_doc_with_docinfo(db, docinfo, &doc, 0); if (docerr != COUCHSTORE_SUCCESS) { if (dumpJson) { printf("\"body\":null}\n"); } else { printf(" could not read document body: %s\n", couchstore_strerror(docerr)); } } else if (doc && (docinfo->content_meta & COUCH_DOC_IS_COMPRESSED)) { size_t rlen; snappy_uncompressed_length(doc->data.buf, doc->data.size, &rlen); char *decbuf = (char *) malloc(rlen); size_t uncompr_len; snappy_uncompress(doc->data.buf, doc->data.size, decbuf, &uncompr_len); sized_buf uncompr_body; uncompr_body.size = uncompr_len; uncompr_body.buf = decbuf; if (dumpJson) { printf("\"size\":%zu,", uncompr_body.size); printf("\"snappy\":true,\"body\":\""); if (dumpHex) { printsbhexraw(&uncompr_body); } else { printjquote(&uncompr_body); } printf("\"}\n"); } else { printf(" size: %zu\n", uncompr_body.size); printf(" data: (snappy) "); if (dumpHex) { printsbhexraw(&uncompr_body); printf("\n"); } else { printsb(&uncompr_body); } } } else if (doc) { if (dumpJson) { printf("\"size\":%zu,", doc->data.size); printf("\"body\":\""); printjquote(&doc->data); printf("\"}\n"); } else { printf(" size: %zu\n", doc->data.size); printf(" data: "); if (dumpHex) { printsbhexraw(&doc->data); printf("\n"); } else { printsb(&doc->data); } } } } else { if (dumpJson) { printf("\"body\":null}\n"); } else { printf("\n"); } } couchstore_free_document(doc); return 0; }