Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Dump file read posisitions/sizes from dbdump

Change-Id: I142148ab8b91ea4f38f3ebb911599af34e402a48
  • Loading branch information...
commit dd4f4f96cb1ee595600c39631148c9d0f83821fb 1 parent 2c8a2a8
@apage43 authored
Showing with 26 additions and 2 deletions.
  1. +26 −2 src/dbdump.c
View
28 src/dbdump.c
@@ -117,7 +117,6 @@ static int foldprint(Db *db, DocInfo *docinfo, void *ctx)
return 0;
}
-
static int visit_node(Db *db,
int depth,
const DocInfo* docinfo,
@@ -150,12 +149,28 @@ static int visit_node(Db *db,
return 0;
}
+static FILE* dumpfile = NULL;
+static couch_file_ops* default_ops = NULL;
+
+static ssize_t dump_pread(couch_file_handle h, void *buf, size_t nbytes, off_t offset) {
+ if(dumpfile) {
+ fprintf(dumpfile,"%llu, %ld\n", offset, nbytes);
+ }
+ return default_ops->pread(h, buf, nbytes, offset);
+}
static int process_file(const char *file, int *total)
{
Db *db;
couchstore_error_t errcode;
- errcode = couchstore_open_db(file, COUCHSTORE_OPEN_FLAG_RDONLY, &db);
+ int dump_reads = (getenv("DBDUMP_DUMP_READS") != NULL);
+ couch_file_ops ops = *default_ops;
+ if(dump_reads) {
+ fprintf(dumpfile, "#%s\n", file);
+ ops.pread = dump_pread;
+ }
+
+ errcode = couchstore_open_db_ex(file, COUCHSTORE_OPEN_FLAG_RDONLY, &ops, &db);
if (errcode != COUCHSTORE_SUCCESS) {
fprintf(stderr, "Failed to open \"%s\": %s\n",
file, couchstore_strerror(errcode));
@@ -206,6 +221,11 @@ int main(int argc, char **argv)
if (argc < 2) {
usage();
}
+ default_ops = couchstore_get_default_file_ops();
+ int dump_reads = (getenv("DBDUMP_DUMP_READS") != NULL);
+ if(dump_reads) {
+ dumpfile = fopen("readdump.txt", "a");
+ }
int ii = 1;
while (strncmp(argv[ii], "-", 1) == 0) {
@@ -231,6 +251,10 @@ int main(int argc, char **argv)
error += process_file(argv[ii], &count);
}
+ if(dump_reads) {
+ fclose(dumpfile);
+ }
+
printf("\nTotal docs: %d\n", count);
if (error) {
exit(EXIT_FAILURE);
Please sign in to comment.
Something went wrong with that request. Please try again.