Commit 10c82d9f authored by Yoni Fogel's avatar Yoni Fogel

DbEnv.err

DbEnv.set_errfile

toku_db_env_err now writes to the file from set_errfile
toku_db_env_err calls toku_db_env_err_vararg

Fixed DbException.set_env, and callers of it.
Modified test1 to not use exceptions, since the test tried to use return codes.

Closes #214
Addresses #197
Addresses #215

git-svn-id: file:///svn/tokudb@1303 c7de825b-a66e-492c-adef-691d508d4ae1
parent 22e2a91e
#include <assert.h>
#include <db_cxx.h>
#include <stdarg.h>
DbEnv::DbEnv (u_int32_t flags)
: do_no_exceptions((flags&DB_CXX_NO_EXCEPTIONS)!=0)
......@@ -67,6 +68,21 @@ int DbEnv::maybe_throw_error(int err) {
if (err==0) return 0;
if (do_no_exceptions) return err;
DbException e(err);
e.set_env(the_env);
e.set_env(this);
throw e;
}
extern "C" {
void toku_db_env_err_vararg(const DB_ENV * env, int error, const char *fmt, va_list ap);
};
void DbEnv::err(int error, const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
toku_db_env_err_vararg(the_env, error, fmt, ap);
va_end(ap);
}
void DbEnv::set_errfile(FILE *errfile) {
the_env->set_errfile(the_env, errfile);
}
......@@ -36,3 +36,8 @@ DbEnv *DbException::get_env() const
{
return the_env;
}
void DbException::set_env(DbEnv *new_env)
{
the_env = new_env;
}
......@@ -27,7 +27,10 @@ int cmp(DB *db, const DBT *dbt1, const DBT *dbt2) {
}
void test_db(void) {
Db db(NULL, 0);
DbEnv env(DB_CXX_NO_EXCEPTIONS);
env.open(NULL, DB_PRIVATE, 0666);
Db db(&env, 0);
int r;
r = db.set_bt_compare(cmp); assert(r == 0);
......@@ -35,13 +38,15 @@ void test_db(void) {
}
void test_db_env(void) {
DbEnv dbenv(0);
DbEnv dbenv(DB_CXX_NO_EXCEPTIONS);
int r;
r = dbenv.set_data_dir("."); assert(r == 0);
r = dbenv.set_data_dir(".."); assert(r == 0);
r = dbenv.set_data_dir(NULL); assert(r == EINVAL);
dbenv.set_errpfx("Prefix");
dbenv.set_errfile(stdout);
dbenv.err(0, "Hello %s!\n", "Name");
}
int main()
......
......@@ -99,6 +99,8 @@ class DbEnv {
int txn_begin(DbTxn *, DbTxn **, u_int32_t);
int set_data_dir(const char *dir);
void set_errpfx(const char *errpfx);
void err(int error, const char *fmt, ...);
void set_errfile(FILE *errfile);
private:
int do_no_exceptions;
......@@ -146,6 +148,6 @@ class DbException : public std::exception
int the_err;
DbEnv *the_env;
void FillTheWhat(void);
void set_env(DB_ENV *);
void set_env(DbEnv *);
};
......@@ -59,12 +59,17 @@ static void do_error (DB_ENV *dbenv, const char *string) {
fprintf(dbenv->i->errfile, "%s\n", string);
}
void toku_db_env_err_vararg(const DB_ENV * env, int error, const char *fmt, va_list ap) {
FILE* ferr = env->i->errfile ? env->i->errfile : stderr;
if (env->i->errpfx && env->i->errpfx[0] != '\0') fprintf(stderr, "%s: ", env->i->errpfx);
fprintf(ferr, "YDB Error %d: ", error);
vfprintf(ferr, fmt, ap);
}
static void toku_db_env_err(const DB_ENV * env, int error, const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
if (env->i->errpfx && env->i->errpfx[0] != '\0') fprintf(stderr, "%s: ", env->i->errpfx);
fprintf(stderr, "YDB Error %d: ", error);
vfprintf(stderr, fmt, ap);
toku_db_env_err_vararg(env, error, fmt, ap);
va_end(ap);
}
......
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