From: Fredrik Tolf Date: Mon, 13 Jun 2011 20:41:52 +0000 (+0200) Subject: Added the ability to specify database page size. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=ea4e0b7174a8372eaa3b9519e7ca98e6ba78c6d7;p=statserve.git Added the ability to specify database page size. --- diff --git a/dbsrc.c b/dbsrc.c index fa9899c..bb239ae 100644 --- a/dbsrc.c +++ b/dbsrc.c @@ -15,6 +15,8 @@ struct dbsrc { time_t lastcp, lastar; }; +int dbpagesize = 0; + static struct fileinfo dbserve(struct source *src, char *nm) { struct dbsrc *d = src->pdata; @@ -142,6 +144,12 @@ struct source *mkdbsrc(char *path, char *envpath) flog(LOG_ERR, "could not create bdb database: %s", db_strerror(ret)); exit(1); } + if(dbpagesize) { + if((ret = d->db->set_pagesize(d->db, dbpagesize)) != 0) { + flog(LOG_ERR, "could not set bdb page size (to %i): %s", dbpagesize, db_strerror(ret)); + exit(1); + } + } if((ret = d->db->open(d->db, NULL, path, NULL, DB_HASH, DB_AUTO_COMMIT | DB_CREATE, 0666)) != 0) { flog(LOG_ERR, "could not open bdb database: %s", db_strerror(ret)); exit(1); diff --git a/statdbput.c b/statdbput.c index 8369efe..569afe1 100644 --- a/statdbput.c +++ b/statdbput.c @@ -15,7 +15,7 @@ static DB_TXN *txn; static struct charvbuf files; static int verbose = 0; -static void opendb(char *path) +static void opendb(char *path, int pagesize) { char *envpath, *p; int ret; @@ -40,6 +40,12 @@ static void opendb(char *path) fprintf(stderr, "statdbput: could not create db handle: %s\n", db_strerror(ret)); exit(1); } + if(pagesize) { + if((ret = db->set_pagesize(db, pagesize)) != 0) { + fprintf(stderr, "statdbput: could not set db page size (to %i): %s", pagesize, db_strerror(ret)); + exit(1); + } + } if((ret = db->open(db, NULL, path, NULL, DB_HASH, DB_AUTO_COMMIT | DB_CREATE, 0666)) != 0) { fprintf(stderr, "statdbput: %s: %s\n", path, db_strerror(ret)); exit(1); @@ -157,8 +163,8 @@ static int dodir(char *path, char *ctype) static void usage(FILE *out) { - fprintf(out, "usage: statdbput [-hvD] [-n NAME] DB CONTENT-TYPE {FILE|-}...\n"); - fprintf(out, " statdbput [-hvD] [-d] DB CONTENT-TYPE DIR...\n"); + fprintf(out, "usage: statdbput [-hvD] [-P PAGESIZE] [-n NAME] DB CONTENT-TYPE {FILE|-}...\n"); + fprintf(out, " statdbput [-hvD] [-P PAGESIZE] [-d] DB CONTENT-TYPE DIR...\n"); } int main(int argc, char **argv) @@ -166,10 +172,12 @@ int main(int argc, char **argv) int c, rv, ret; int dm, ul, i, a; char *name, *ctype, *dbpath; + int pagesize; dm = ul = 0; name = NULL; - while((c = getopt(argc, argv, "+hvDdn:")) >= 0) { + pagesize = 0; + while((c = getopt(argc, argv, "+hvDdn:P:")) >= 0) { switch(c) { case 'd': dm = 1; @@ -183,6 +191,9 @@ int main(int argc, char **argv) case 'n': name = optarg; break; + case 'P': + pagesize = atoi(optarg); + break; case 'h': usage(stdout); return(0); @@ -197,7 +208,7 @@ int main(int argc, char **argv) } dbpath = argv[optind++]; ctype = argv[optind++]; - opendb(dbpath); + opendb(dbpath, pagesize); while(1) { if((ret = env->txn_begin(env, NULL, &txn, 0)) != 0) { fprintf(stderr, "statdbput: could not begin transaction in %s: %s\n", dbpath, db_strerror(ret)); diff --git a/statserve.c b/statserve.c index ed49388..ab3b346 100644 --- a/statserve.c +++ b/statserve.c @@ -59,7 +59,7 @@ out: static void usage(FILE *out) { - fprintf(out, "usage: statserve [-h] SOURCE...\n"); + fprintf(out, "usage: statserve [-h] [-P PAGESIZE] SOURCE...\n"); } static void listenloop(struct muth *muth, va_list args) @@ -89,8 +89,11 @@ int main(int argc, char **argv) int c; struct source *last, *src; - while((c = getopt(argc, argv, "+h")) >= 0) { + while((c = getopt(argc, argv, "+hP:")) >= 0) { switch(c) { + case 'P': + dbpagesize = atoi(optarg); + break; case 'h': usage(stdout); return(0); diff --git a/statserve.h b/statserve.h index d092422..b276bc0 100644 --- a/statserve.h +++ b/statserve.h @@ -21,4 +21,6 @@ struct source { struct source *mkdbsrc(char *path, char *envpath); struct source *mkfssrc(char *path); +extern int dbpagesize; + #endif