dump/load need mapsize etc.

incre
Howard Chu 11 years ago
parent c5be1292ac
commit 4d65cf1326
  1. 8
      libraries/liblmdb/mdb_dump.c
  2. 54
      libraries/liblmdb/mdb_load.c

@ -91,6 +91,7 @@ static int dumpit(MDB_txn *txn, MDB_dbi dbi, char *name)
MDB_cursor *mc; MDB_cursor *mc;
MDB_stat ms; MDB_stat ms;
MDB_val key, data; MDB_val key, data;
MDB_envinfo info;
unsigned int flags; unsigned int flags;
int rc, i; int rc, i;
@ -100,11 +101,18 @@ static int dumpit(MDB_txn *txn, MDB_dbi dbi, char *name)
rc = mdb_stat(txn, dbi, &ms); rc = mdb_stat(txn, dbi, &ms);
if (rc) return rc; if (rc) return rc;
rc = mdb_env_info(mdb_txn_env(txn), &info);
if (rc) return rc;
printf("VERSION=3\n"); printf("VERSION=3\n");
printf("format=%s\n", mode & PRINT ? "print" : "bytevalue"); printf("format=%s\n", mode & PRINT ? "print" : "bytevalue");
if (name) if (name)
printf("database=%s\n", name); printf("database=%s\n", name);
printf("type=btree\n"); printf("type=btree\n");
printf("mapsize=%zu\n", info.me_mapsize);
if (info.me_mapaddr)
printf("mapaddr=%p\n", info.me_mapaddr);
printf("maxreaders=%u\n", info.me_maxreaders);
if (flags & MDB_DUPSORT) if (flags & MDB_DUPSORT)
printf("duplicates=1\n"); printf("duplicates=1\n");

@ -34,6 +34,8 @@ static char *prog;
static int eof; static int eof;
static MDB_envinfo info;
static MDB_val kbuf, dbuf; static MDB_val kbuf, dbuf;
#define STRLENOF(s) (sizeof(s)-1) #define STRLENOF(s) (sizeof(s)-1)
@ -92,6 +94,36 @@ static void readhdr()
prog, lineno, (char *)dbuf.mv_data+STRLENOF("type=")); prog, lineno, (char *)dbuf.mv_data+STRLENOF("type="));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else if (!strncmp(dbuf.mv_data, "mapaddr=", STRLENOF("mapaddr="))) {
int i;
ptr = memchr(dbuf.mv_data, '\n', dbuf.mv_size);
if (ptr) *ptr = '\0';
i = sscanf((char *)dbuf.mv_data+STRLENOF("mapaddr="), "%p", &info.me_mapaddr);
if (i != 1) {
fprintf(stderr, "%s: line %zd: invalid mapaddr %s\n",
prog, lineno, (char *)dbuf.mv_data+STRLENOF("mapaddr="));
exit(EXIT_FAILURE);
}
} else if (!strncmp(dbuf.mv_data, "mapsize=", STRLENOF("mapsize="))) {
int i;
ptr = memchr(dbuf.mv_data, '\n', dbuf.mv_size);
if (ptr) *ptr = '\0';
i = sscanf((char *)dbuf.mv_data+STRLENOF("mapsize="), "%zu", &info.me_mapsize);
if (i != 1) {
fprintf(stderr, "%s: line %zd: invalid mapsize %s\n",
prog, lineno, (char *)dbuf.mv_data+STRLENOF("mapsize="));
exit(EXIT_FAILURE);
}
} else if (!strncmp(dbuf.mv_data, "maxreaders=", STRLENOF("maxreaders="))) {
int i;
ptr = memchr(dbuf.mv_data, '\n', dbuf.mv_size);
if (ptr) *ptr = '\0';
i = sscanf((char *)dbuf.mv_data+STRLENOF("maxreaders="), "%u", &info.me_maxreaders);
if (i != 1) {
fprintf(stderr, "%s: line %zd: invalid maxreaders %s\n",
prog, lineno, (char *)dbuf.mv_data+STRLENOF("maxreaders="));
exit(EXIT_FAILURE);
}
} else { } else {
int i; int i;
for (i=0; dbflags[i].bit; i++) { for (i=0; dbflags[i].bit; i++) {
@ -251,6 +283,7 @@ int main(int argc, char *argv[])
MDB_dbi dbi; MDB_dbi dbi;
char *envname; char *envname;
int envflags = 0, putflags = 0; int envflags = 0, putflags = 0;
int dohdr = 0;
prog = argv[0]; prog = argv[0];
@ -298,11 +331,26 @@ int main(int argc, char *argv[])
if (optind != argc - 1) if (optind != argc - 1)
usage(prog); usage(prog);
dbuf.mv_size = 4096;
dbuf.mv_data = malloc(dbuf.mv_size);
if (!(mode & NOHDR))
readhdr();
envname = argv[optind]; envname = argv[optind];
rc = mdb_env_create(&env); rc = mdb_env_create(&env);
mdb_env_set_maxdbs(env, 2); mdb_env_set_maxdbs(env, 2);
if (info.me_maxreaders)
mdb_env_set_maxreaders(env, info.me_maxreaders);
if (info.me_mapsize)
mdb_env_set_mapsize(env, info.me_mapsize);
if (info.me_mapaddr)
envflags |= MDB_FIXEDMAP;
rc = mdb_env_open(env, envname, envflags, 0664); rc = mdb_env_open(env, envname, envflags, 0664);
if (rc) { if (rc) {
fprintf(stderr, "mdb_env_open failed, error %d %s\n", rc, mdb_strerror(rc)); fprintf(stderr, "mdb_env_open failed, error %d %s\n", rc, mdb_strerror(rc));
@ -311,15 +359,15 @@ int main(int argc, char *argv[])
kbuf.mv_size = mdb_env_get_maxkeysize(env) * 2 + 2; kbuf.mv_size = mdb_env_get_maxkeysize(env) * 2 + 2;
kbuf.mv_data = malloc(kbuf.mv_size); kbuf.mv_data = malloc(kbuf.mv_size);
dbuf.mv_size = 4096;
dbuf.mv_data = malloc(dbuf.mv_size);
while(!eof) { while(!eof) {
MDB_val key, data; MDB_val key, data;
int batch = 0; int batch = 0;
flags = 0; flags = 0;
if (!(mode & NOHDR)) if (!dohdr) {
dohdr = 1;
} else if (!(mode & NOHDR))
readhdr(); readhdr();
rc = mdb_txn_begin(env, NULL, 0, &txn); rc = mdb_txn_begin(env, NULL, 0, &txn);

Loading…
Cancel
Save