Commit 201cb08a authored by Yoni Fogel's avatar Yoni Fogel

Preliminary db_dump.

Ouputs without transactions, does not dump a header.

git-svn-id: file:///svn/tokudb@441 c7de825b-a66e-492c-adef-691d508d4ae1
parent 58917535
...@@ -7,7 +7,7 @@ BDB_LOAD=/usr/local/Berkeleydb.4.1/bin/db_load ...@@ -7,7 +7,7 @@ BDB_LOAD=/usr/local/Berkeleydb.4.1/bin/db_load
UTILS= \ UTILS= \
tokudb_gen \ tokudb_gen \
tokudb_load \ tokudb_load \
# tokudb_dump \ tokudb_dump \
#End #End
.PHONY: all clean test test_gen test_gen_hex test_load .PHONY: all clean test test_gen test_gen_hex test_load
......
...@@ -18,68 +18,4 @@ typedef uint8_t bool; ...@@ -18,68 +18,4 @@ typedef uint8_t bool;
#define IS_POWER_OF_2(num) ((num) > 0 && ((num) & ((num) - 1)) == 0) #define IS_POWER_OF_2(num) ((num) > 0 && ((num) & ((num) - 1)) == 0)
int strtoint32 (DB_ENV* dbenv, char* progname, char* str, int32_t* num, int32_t min, int32_t max, int base);
int strtouint32 (DB_ENV* dbenv, char* progname, char* str, uint32_t* num, uint32_t min, uint32_t max, int base);
int strtoint64 (DB_ENV* dbenv, char* progname, char* str, int64_t* num, int64_t min, int64_t max, int base);
int strtouint64 (DB_ENV* dbenv, char* progname, char* str, uint64_t* num, uint64_t min, uint64_t max, int base);
/*
* Convert a string to an integer of type "type".
*
*
* Sets errno and returns:
* EINVAL: str == NULL, num == NULL, or string not of the form [ \t]*[+-]?[0-9]+
* ERANGE: value out of range specified. (Range of [min, max])
*
* *num is unchanged on error.
* Returns:
*
*/
#define DEF_STR_TO(name, type, bigtype, strtofunc, frmt) \
int name(DB_ENV* dbenv, char* progname, char* str, type* num, type min, type max, int base) \
{ \
char* test; \
bigtype value; \
\
assert(str); \
assert(num); \
assert(min <= max); \
assert(dbenv || progname); \
assert(base == 0 || (base >= 2 && base <= 36)); \
\
errno = 0; \
while (isspace(*str)) str++; \
value = strtofunc(str, &test, base); \
if ((*test != '\0' && *test != '\n') || test == str) { \
if (dbenv == NULL) fprintf(stderr, "%s: %s: Invalid numeric argument\n", progname, str); \
else dbenv->err(dbenv, 0, "%s: Invalid numeric argument", str); \
errno = EINVAL; \
goto error; \
} \
if (errno != 0) { \
if (dbenv == NULL) fprintf(stderr, "%s: %s: %s\n", progname, str, strerror(errno)); \
else dbenv->err(dbenv, errno, "%s", str); \
goto error; \
} \
if (value < min) { \
if (dbenv == NULL) fprintf(stderr, "%s: %s: Less than minimum value (%" frmt ")\n", progname, str, min); \
else dbenv->err(dbenv, 0, "%s: Less than minimum value (%" frmt ")", str, min); \
goto error; \
} \
if (value > max) { \
if (dbenv == NULL) fprintf(stderr, "%s: %s: Greater than maximum value (%" frmt ")\n", progname, str, max); \
else dbenv->err(dbenv, 0, "%s: Greater than maximum value (%" frmt ")", str, max); \
goto error; \
} \
*num = value; \
return EXIT_SUCCESS; \
error: \
return errno; \
}
DEF_STR_TO(strtoint32, int32_t, int64_t, strtoll, "d");
DEF_STR_TO(strtouint32, uint32_t, uint64_t, strtoull, "u");
DEF_STR_TO(strtoint64, int64_t, int64_t, strtoll, "lld");
DEF_STR_TO(strtouint64, uint64_t, uint64_t, strtoull, "llu");
#endif /* #if !defined(TOKUDB_COMMON_H) */ #endif /* #if !defined(TOKUDB_COMMON_H) */
#if !defined(TOKUDB_COMMON_FUNCS_H)
#define TOKUDB_COMMON_FUNCS_H
#include "tokudb_common.h"
int strtoint32 (DB_ENV* dbenv, char* progname, char* str, int32_t* num, int32_t min, int32_t max, int base);
int strtouint32 (DB_ENV* dbenv, char* progname, char* str, uint32_t* num, uint32_t min, uint32_t max, int base);
int strtoint64 (DB_ENV* dbenv, char* progname, char* str, int64_t* num, int64_t min, int64_t max, int base);
int strtouint64 (DB_ENV* dbenv, char* progname, char* str, uint64_t* num, uint64_t min, uint64_t max, int base);
/*
* Convert a string to an integer of type "type".
*
*
* Sets errno and returns:
* EINVAL: str == NULL, num == NULL, or string not of the form [ \t]*[+-]?[0-9]+
* ERANGE: value out of range specified. (Range of [min, max])
*
* *num is unchanged on error.
* Returns:
*
*/
#define DEF_STR_TO(name, type, bigtype, strtofunc, frmt) \
int name(DB_ENV* dbenv, char* progname, char* str, type* num, type min, type max, int base) \
{ \
char* test; \
bigtype value; \
\
assert(str); \
assert(num); \
assert(min <= max); \
assert(dbenv || progname); \
assert(base == 0 || (base >= 2 && base <= 36)); \
\
errno = 0; \
while (isspace(*str)) str++; \
value = strtofunc(str, &test, base); \
if ((*test != '\0' && *test != '\n') || test == str) { \
if (dbenv == NULL) fprintf(stderr, "%s: %s: Invalid numeric argument\n", progname, str); \
else dbenv->err(dbenv, 0, "%s: Invalid numeric argument", str); \
errno = EINVAL; \
goto error; \
} \
if (errno != 0) { \
if (dbenv == NULL) fprintf(stderr, "%s: %s: %s\n", progname, str, strerror(errno)); \
else dbenv->err(dbenv, errno, "%s", str); \
goto error; \
} \
if (value < min) { \
if (dbenv == NULL) fprintf(stderr, "%s: %s: Less than minimum value (%" frmt ")\n", progname, str, min); \
else dbenv->err(dbenv, 0, "%s: Less than minimum value (%" frmt ")", str, min); \
goto error; \
} \
if (value > max) { \
if (dbenv == NULL) fprintf(stderr, "%s: %s: Greater than maximum value (%" frmt ")\n", progname, str, max); \
else dbenv->err(dbenv, 0, "%s: Greater than maximum value (%" frmt ")", str, max); \
goto error; \
} \
*num = value; \
return EXIT_SUCCESS; \
error: \
return errno; \
}
DEF_STR_TO(strtoint32, int32_t, int64_t, strtoll, "d");
DEF_STR_TO(strtouint32, uint32_t, uint64_t, strtoull, "u");
DEF_STR_TO(strtoint64, int64_t, int64_t, strtoll, "lld");
DEF_STR_TO(strtouint64, uint64_t, uint64_t, strtoull, "llu");
void outputbyte(uint8_t ch)
{
if (g.plaintext) {
if (ch == '\\') printf("\\\\");
else if (isprint(ch)) printf("%c", ch);
else printf("\\%02x", ch);
}
else printf("%02x", ch);
}
#endif /* #if !defined(TOKUDB_COMMON_H) */
This diff is collapsed.
...@@ -14,14 +14,23 @@ extern int optopt; ...@@ -14,14 +14,23 @@ extern int optopt;
extern int opterr; extern int opterr;
extern int optreset; extern int optreset;
typedef struct {
bool plaintext;
} gen_globals;
gen_globals g;
#include "tokudb_common_funcs.h"
int usage(void); int usage(void);
void generate_keys(void); void generate_keys(void);
int get_delimiter(char* str); int get_delimiter(char* str);
char dbt_delimiter = '\n'; char dbt_delimiter = '\n';
char sort_delimiter[2]; char sort_delimiter[2];
char* progname; char* progname;
bool plaintext = false;
uint32_t lengthmin = 0; uint32_t lengthmin = 0;
bool set_lengthmin = false; bool set_lengthmin = false;
uint32_t lengthlimit = 0; uint32_t lengthlimit = 0;
...@@ -38,9 +47,13 @@ bool set_seed = false; ...@@ -38,9 +47,13 @@ bool set_seed = false;
bool printableonly = false; bool printableonly = false;
bool leadingspace = true; bool leadingspace = true;
int main (int argc, char *argv[]) { int main (int argc, char *argv[]) {
int ch; int ch;
/* Set up the globals. */
memset(&g, 0, sizeof(g));
progname = argv[0]; progname = argv[0];
strcpy(sort_delimiter, ""); strcpy(sort_delimiter, "");
...@@ -67,14 +80,14 @@ int main (int argc, char *argv[]) { ...@@ -67,14 +80,14 @@ int main (int argc, char *argv[]) {
break; break;
} }
case ('T'): { case ('T'): {
plaintext = true; g.plaintext = true;
leadingspace = false; leadingspace = false;
header = false; header = false;
footer = false; footer = false;
break; break;
} }
case ('p'): { case ('p'): {
plaintext = true; g.plaintext = true;
leadingspace = true; leadingspace = true;
break; break;
} }
...@@ -239,7 +252,7 @@ int main (int argc, char *argv[]) { ...@@ -239,7 +252,7 @@ int main (int argc, char *argv[]) {
"type=btree\n" "type=btree\n"
"db_pagesize=4096\n" "db_pagesize=4096\n"
"HEADER=END\n", "HEADER=END\n",
plaintext ? "print" : "bytevalue"); g.plaintext ? "print" : "bytevalue");
} }
if (outputkeys) generate_keys(); if (outputkeys) generate_keys();
if (footer) printf("DATA=END\n"); if (footer) printf("DATA=END\n");
...@@ -283,16 +296,6 @@ int32_t random_below(int32_t limit) ...@@ -283,16 +296,6 @@ int32_t random_below(int32_t limit)
return random() % limit; return random() % limit;
} }
void outputbyte(uint8_t ch)
{
if (plaintext) {
if (ch == '\\') printf("\\\\");
else if (isprint(ch)) printf("%c", ch);
else printf("\\%02x", ch);
}
else printf("%02x", ch);
}
void outputstring(char* str) void outputstring(char* str)
{ {
char* p; char* p;
......
...@@ -45,6 +45,7 @@ typedef struct { ...@@ -45,6 +45,7 @@ typedef struct {
} load_globals; } load_globals;
load_globals g; load_globals g;
#include "tokudb_common_funcs.h"
int usage (); int usage ();
int longusage (); int longusage ();
...@@ -287,11 +288,11 @@ int create_init_env() ...@@ -287,11 +288,11 @@ int create_init_env()
/* /*
///TODO: UNCOMMENT/IMPLEMENT ///TODO: UNCOMMENT/IMPLEMENT
retval = dbenv->set_cachesize(dbenv, 0, cache, 1); retval = dbenv->set_cachesize(dbenv, 0, cache, 1);
*/
if (retval) { if (retval) {
dbenv->err(dbenv, retval, "DB_ENV->set_cachesize"); dbenv->err(dbenv, retval, "DB_ENV->set_cachesize");
goto error; goto error;
} }
*/
g.is_private = true; g.is_private = true;
//TODO: Do we want to support transactions/logging even in single-process mode? //TODO: Do we want to support transactions/logging even in single-process mode?
//Maybe if the db already exists. //Maybe if the db already exists.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment