Commit 750e6534 authored by Rich Prohaska's avatar Rich Prohaska

remove c++ api and db-benchmark-test

parent 31c311e0
# -*- Mode: Makefile -*-
# standard build: make
#ident "Copyright (c) 2007 Tokutek Inc. All rights reserved."
.DEFAULT_GOAL= default
TOKUROOT=../
INCLUDEDIRS=-I.
DEPEND_COMPILE += \
./*.h \
#end
HERE = cxx
include $(TOKUROOT)toku_include/Makefile.include
#
#
# OPTFLAGS = -O2
# GCOV_FLAGS = -fprofile-arcs -ftest-coverage
CPPFLAGS = -I../include -I../toku_include
CXXFLAGS = $(GCC_VERSION_SPECIFIC) -Werror -Wall -g $(OPTFLAGS) $(GCOV_FLAGS)
LDFLAGS = -lz
SRCS = $(wildcard *.cpp)
OBJS = $(patsubst %.cpp, %.o, $(SRCS))
ifeq ($(CC),icc)
CXXFLAGS += -diag-disable 981
CXX=icc
endif
LIBNAME = libtokudb_cxx
default: install build
build: $(LIBNAME).a
if ! diff $(LIBNAME).a ../lib/$(LIBNAME).a >/dev/null 2>&1; then cp $< ../lib/; fi
cd tests; $(MAKE) build
check:
cd tests; $(MAKE) check
install: $(LIBNAME).a
cp $< ../lib/
$(OBJS): ../include/db_cxx.h
test1: test1.o dbt.o db.o dbenv.o ../lib/libdb.a
$(LIBNAME).a: $(OBJS)
$(AR) cr $@ $(OBJS)
clean:
rm -f $(OBJS) $(LIBNAME).a $(LIBNAME).so *.gcno *.gcda *.gcov
cd tests && $(MAKE) clean
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <assert.h>
#include <db.h>
#include <errno.h>
#include <db_cxx.h>
#define do_maybe_error(errno)
Db::Db(DbEnv *env, u_int32_t flags)
: the_Env(env)
{
assert(env); // modern versions of TokuDB require an env.
the_db = 0;
is_private_env = (the_Env == 0);
DB *tmp_db;
int ret = db_create(&tmp_db, the_Env->get_DB_ENV(), flags & ~(DB_CXX_NO_EXCEPTIONS));
if (ret!=0) {
the_Env->maybe_throw_error(ret);
// Otherwise cannot do much
return;
}
the_db = tmp_db;
tmp_db->api_internal = this;
if (is_private_env) {
the_Env = new DbEnv(tmp_db->dbenv, flags & DB_CXX_NO_EXCEPTIONS);
}
}
Db::~Db() {
if (the_db) {
close(0); // the user should have called close, but we do it here if not done.
assert(the_db==0);
}
if (is_private_env && the_Env) {
the_Env->close(0);
delete the_Env;
}
}
int Db::set_flags(u_int32_t flags) {
int ret = the_db->set_flags(the_db, flags);
return the_Env->maybe_throw_error(ret);
}
int Db::get_flags(u_int32_t *flags) {
int ret = the_db->get_flags(the_db, flags);
return the_Env->maybe_throw_error(ret);
}
int Db::close (u_int32_t flags) {
if (!the_db) {
return the_Env->maybe_throw_error(EINVAL);
}
the_db->api_internal = 0;
int ret = the_db->close(the_db, flags);
the_db = 0;
int no_exceptions = the_Env->do_no_exceptions; // Get this out before possibly deleting the env
if (is_private_env) {
// The env was closed by the_db->close, we have to tell the DbEnv that the DB_ENV is gone, and delete it.
the_Env->the_env = 0;
delete the_Env;
the_Env=0;
}
// Do we need to clean up "private environments"?
// What about cursors? They should be cleaned up already, but who did it?
// This maybe_throw must be the static one because the env is gone.
return DbEnv::maybe_throw_error(ret, NULL, no_exceptions);
}
int Db::open(DbTxn *txn, const char *filename, const char *subname, DBTYPE typ, u_int32_t flags, int mode) {
int ret = the_db->open(the_db, txn->get_DB_TXN(), filename, subname, typ, flags, mode);
return the_Env->maybe_throw_error(ret);
}
int Db::del(DbTxn *txn, Dbt *key, u_int32_t flags) {
int ret = the_db->del(the_db, txn->get_DB_TXN(), key->get_DBT(), flags);
return the_Env->maybe_throw_error(ret);
}
int Db::get(DbTxn *txn, Dbt *key, Dbt *data, u_int32_t flags) {
int ret = the_db->get(the_db, txn->get_DB_TXN(), key->get_DBT(), data->get_DBT(), flags);
return the_Env->maybe_throw_error(ret);
}
int Db::put(DbTxn *txn, Dbt *key, Dbt *data, u_int32_t flags) {
int ret = the_db->put(the_db, txn->get_DB_TXN(), key->get_DBT(), data->get_DBT(), flags);
return the_Env->maybe_throw_error(ret);
}
int Db::cursor(DbTxn *txn, Dbc **cursorp, u_int32_t flags) {
int ret = the_db->cursor(the_db, txn->get_DB_TXN(), (DBC**)cursorp, flags);
return the_Env->maybe_throw_error(ret);
}
int Db::set_pagesize(u_int32_t size) {
int ret = the_db->set_pagesize(the_db, size);
return the_Env->maybe_throw_error(ret);
}
int Db::remove(const char *file, const char *database, u_int32_t flags) {
int ret = the_db->remove(the_db, file, database, flags);
the_db = 0;
return the_Env->maybe_throw_error(ret);
}
#if 0
extern "C" int toku_bt_compare_callback_c(DB *db_c, const DBT *a, const DBT *b) {
Db *db_cxx=Db::get_Db(db_c);
return db_cxx->do_bt_compare_callback_cxx(db_cxx, Dbt::get_const_Dbt(a), Dbt::get_const_Dbt(b));
}
int Db::do_bt_compare_callback_cxx(Db *db, const Dbt *a, const Dbt *b) {
return the_Env->bt_compare_callback_cxx(db, a, b);
}
int Db::set_bt_compare(int (*bt_compare_callback)(Db *, const Dbt *, const Dbt *)) {
bt_compare_callback_cxx = bt_compare_callback;
int ret = the_db->set_bt_compare(the_db, toku_bt_compare_callback_c);
return the_Env->maybe_throw_error(ret);
}
int Db::set_bt_compare(bt_compare_fcn_type bt_compare_fcn) {
int ret = the_db->set_bt_compare(the_db, bt_compare_fcn);
return the_Env->maybe_throw_error(ret);
}
#endif
int Db::fd(int *fdp) {
int ret = the_db->fd(the_db, fdp);
return the_Env->maybe_throw_error(ret);
}
extern "C" int toku_dup_compare_callback_c(DB *db_c, const DBT *a, const DBT *b) {
Db *db_cxx=Db::get_Db(db_c);
return db_cxx->dup_compare_callback_cxx(db_cxx, Dbt::get_const_Dbt(a), Dbt::get_const_Dbt(b));
}
void Db::set_errpfx(const char *errpfx) {
the_Env->set_errpfx(errpfx);
}
void Db::set_error_stream(std::ostream *new_error_stream) {
the_Env->set_error_stream(new_error_stream);
}
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <db_cxx.h>
int Dbc::close (void) {
DBC *dbc = this;
DbEnv *env = (DbEnv*)dbc->dbp->api_internal; // Must grab the env before closing the cursor.
int ret = dbc->c_close(dbc);
return env->maybe_throw_error(ret);
}
int Dbc::get(Dbt* key, Dbt *data, u_int32_t flags) {
DBC *dbc = this;
int ret = dbc->c_get(dbc, key, data, flags);
DB_ENV *dbenv_c=dbc->dbp->dbenv;
DbEnv *env = (DbEnv*)dbenv_c->api1_internal;
return env->maybe_throw_error(ret);
}
#if 0
// No longer present (see #4576)
int Dbc::del(u_int32_t flags) {
DBC *dbc = this;
int ret = dbc->c_del(dbc, flags);
DB_ENV *dbenv_c=dbc->dbp->dbenv;
DbEnv *env = (DbEnv*)dbenv_c->api1_internal;
return env->maybe_throw_error(ret);
}
#endif
int Dbc::count(db_recno_t *count, u_int32_t flags) {
DBC *dbc = this;
int ret = dbc->c_count(dbc, count, flags);
DB_ENV *dbenv_c=dbc->dbp->dbenv;
DbEnv *env = (DbEnv*)dbenv_c->api1_internal;
return env->maybe_throw_error(ret);
}
// Not callable, but some compilers require it to be defined anyway.
Dbc::~Dbc()
{
}
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <stdarg.h>
#include <errno.h>
#include <toku_assert.h>
#include "../ft/fttypes.h"
#include <db_cxx.h>
DbEnv::DbEnv (u_int32_t flags)
: do_no_exceptions((flags&DB_CXX_NO_EXCEPTIONS)!=0),
errcall(NULL)
{
int ret = db_env_create(&the_env, flags & ~DB_CXX_NO_EXCEPTIONS);
assert(ret==0); // should do an error.
the_env->api1_internal = this;
}
DbEnv::DbEnv(DB_ENV *env, u_int32_t flags)
: do_no_exceptions((flags&DB_CXX_NO_EXCEPTIONS)!=0), _error_stream(0)
{
the_env = env;
if (env == 0) {
DB_ENV *new_env;
int ret = db_env_create(&new_env, flags & ~DB_CXX_NO_EXCEPTIONS);
assert(ret==0); // should do an error.
the_env = new_env;
}
the_env->api1_internal = this;
}
// If still open, close it. In most cases, the caller should call close explicitly so that they can catch the exceptions.
DbEnv::~DbEnv(void)
{
if (the_env!=NULL) {
(void)the_env->close(the_env, 0);
the_env = 0;
}
}
int DbEnv::close(u_int32_t flags) {
int ret = EINVAL;
if (the_env)
ret = the_env->close(the_env, flags);
the_env = 0; /* get rid of the env ref, so we don't touch it (even if we failed, or when the destructor is called) */
return maybe_throw_error(ret);
}
int DbEnv::open(const char *home, u_int32_t flags, int mode) {
int ret = the_env->open(the_env, home, flags, mode);
return maybe_throw_error(ret);
}
int DbEnv::set_cachesize(u_int32_t gbytes, u_int32_t bytes, int ncache) {
int ret = the_env->set_cachesize(the_env, gbytes, bytes, ncache);
return maybe_throw_error(ret);
}
int DbEnv::set_redzone(u_int32_t percent) {
int ret = the_env->set_redzone(the_env, percent);
return maybe_throw_error(ret);
}
int DbEnv::set_flags(u_int32_t flags, int onoff) {
int ret = the_env->set_flags(the_env, flags, onoff);
return maybe_throw_error(ret);
}
#if DB_VERSION_MAJOR<4 || (DB_VERSION_MAJOR==4 && DB_VERSION_MINOR<=4)
int DbEnv::set_lk_max(u_int32_t flags) {
int ret = the_env->set_lk_max(the_env, flags);
return maybe_throw_error(ret);
}
#endif
int DbEnv::txn_begin(DbTxn *parenttxn, DbTxn **txnp, u_int32_t flags) {
DB_TXN *txn;
int ret = the_env->txn_begin(the_env, parenttxn->get_DB_TXN(), &txn, flags);
if (ret==0) {
*txnp = new DbTxn(txn);
}
return maybe_throw_error(ret);
}
int DbEnv::set_default_bt_compare(bt_compare_fcn_type bt_compare_fcn) {
int ret = the_env->set_default_bt_compare(the_env, bt_compare_fcn);
return maybe_throw_error(ret);
}
int DbEnv::set_data_dir(const char *dir) {
int ret = the_env->set_data_dir(the_env, dir);
return maybe_throw_error(ret);
}
void DbEnv::set_errpfx(const char *errpfx) {
the_env->set_errpfx(the_env, errpfx);
}
int DbEnv::maybe_throw_error(int err, DbEnv *env, int no_exceptions) throw (DbException) {
if (err==0 || err==DB_NOTFOUND || err==DB_KEYEXIST) return err;
if (no_exceptions) return err;
if (err==DB_LOCK_DEADLOCK) {
DbDeadlockException e(env);
throw e;
} else {
DbException e(err);
e.set_env(env);
throw e;
}
}
int DbEnv::maybe_throw_error(int err) throw (DbException) {
return maybe_throw_error(err, this, do_no_exceptions);
}
extern "C" void toku_ydb_error_all_cases(const DB_ENV * env,
int error,
BOOL include_stderrstring,
BOOL use_stderr_if_nothing_else,
const char *fmt, va_list ap);
void DbEnv::err(int error, const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
toku_ydb_error_all_cases(the_env, error, TRUE, TRUE, fmt, ap);
va_end(ap);
}
void DbEnv::set_errfile(FILE *errfile) {
the_env->set_errfile(the_env, errfile);
}
int DbEnv::get_flags(u_int32_t *flagsp) {
int ret = the_env->get_flags(the_env, flagsp);
return maybe_throw_error(ret);
}
extern "C" void toku_db_env_errcall_c(const DB_ENV *dbenv_c, const char *errpfx, const char *msg) {
DbEnv *dbenv = (DbEnv *) dbenv_c->api1_internal;
dbenv->errcall(dbenv, errpfx, msg);
}
void DbEnv::set_errcall(void (*db_errcall_fcn)(const DbEnv *, const char *, const char *)) {
errcall = db_errcall_fcn;
the_env->set_errcall(the_env, toku_db_env_errcall_c);
}
extern "C" void toku_db_env_error_stream_c(const DB_ENV *dbenv_c, const char *errpfx, const char *msg) {
DbEnv *dbenv = (DbEnv *) dbenv_c->api1_internal;
if (dbenv->_error_stream) {
if (errpfx) *(dbenv->_error_stream) << errpfx;
if (msg) *(dbenv->_error_stream) << ":" << msg << "\n";
}
}
void DbEnv::set_error_stream(std::ostream *new_error_stream) {
_error_stream = new_error_stream;
the_env->set_errcall(the_env, toku_db_env_error_stream_c);
}
int DbEnv::set_lk_max_locks(u_int32_t max_locks) {
int ret = the_env->set_lk_max_locks(the_env, max_locks);
return maybe_throw_error(ret);
}
int DbEnv::get_lk_max_locks(u_int32_t *max_locks) {
int ret = the_env->get_lk_max_locks(the_env, max_locks);
return maybe_throw_error(ret);
}
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <db_cxx.h>
Dbt::Dbt(void) {
DBT *dbt = this;
memset(dbt, 0, sizeof(*dbt));
}
Dbt::Dbt(void *data, u_int32_t size) {
DBT *dbt = this;
memset(dbt, 0, sizeof(*dbt));
set_data(data);
set_size(size);
}
Dbt::~Dbt(void)
{
}
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <db.h>
#include <db_cxx.h>
static char*cpp_strdup (const char *s)
{
int l=strlen(s)+1;
char *r = new char[l];
strncpy(r, s, l);
return r;
}
DbException::~DbException() throw()
{
if (the_what!=0) {
delete [] the_what;
}
}
DbException::DbException(int err)
: the_err(err),
the_env(0)
{
FillTheWhat();
}
void DbException::FillTheWhat(void)
{
if (the_err!=0) {
the_what = cpp_strdup(db_strerror(the_err));
}
}
int DbException::get_errno() const
{
return the_err;
}
const char *DbException::what() const throw()
{
return the_what;
}
DbEnv *DbException::get_env() const
{
return the_env;
}
void DbException::set_env(DbEnv *new_env)
{
the_env = new_env;
}
// Must define a copy constructor so that the delete[] of the same the_what doesn't happen
DbException::DbException (const DbException &that)
: std::exception(),
the_what(cpp_strdup(that.the_what)),
the_err(that.the_err),
the_env(that.the_env)
{
}
DbException &DbException::operator = (const DbException &that)
{
if (this != &that) {
delete [] the_what;
the_what = cpp_strdup(that.the_what);
the_err = that.the_err;
the_env = that.the_env;
}
return (*this);
}
DbDeadlockException::DbDeadlockException (DbEnv *env)
: DbException(DB_LOCK_DEADLOCK)
{
this->set_env(env);
}
# -*- Mode: Makefile -*-
# standard build: make
#ident "Copyright (c) 2007 Tokutek Inc. All rights reserved."
.DEFAULT_GOAL= default
TOKUROOT=../../
INCLUDEDIRS=-I.
DEPEND_COMPILE += \
../*.h \
./*.h \
#end
HERE = cxx/tests
include $(TOKUROOT)toku_include/Makefile.include
SHELL=/bin/bash #Use of &> is a bash feature
SHOULD_FAIL = check_exceptions
$(SHOULD_FAIL): MAYBEINVERTER=;test $$? -ne 0
$(SHOULD_FAIL): VGRIND=
HERE = cxx/tests
ifeq ($(SUMMARIZE),1)
SUMMARIZE_CMD = ;if test $$? = 0; then printf "%-60sPASS\n" $(HERE)/$@; else printf "%-60sFAIL\n" $(HERE)/$@ ; test 0 = 1; fi
$(SHOULD_FAIL): SUMMARIZE_CMD = ;if test $$? = 0; then printf "%-60sXFAIL\n" $(HERE)/$@; else printf "%-60sXPASS\n" $(HERE)/$@ ; test 0 = 1; fi
else
SUMMARIZE_CMD =
endif
SRCS = $(wildcard *.cpp)
TARGETS = $(patsubst %.cpp,%,$(SRCS))
# OPTFLAGS = -O0
# GCOV_FLAGS = -fprofile-arcs -ftest-coverage
CPPFLAGS = -I../ -I../../include -I../../linux -I$(TOKUROOT)toku_include -DUSE_ENV
CXXFLAGS = $(GCC_VERSION_SPECIFIC) -Werror -Wall $(OPTFLAGS) -g $(GCOV_FLAGS)
LDLIBS = ../../lib/libtokudb_cxx.a -ltokudb -lz -lpthread -ltokuportability
RPATH_DIRS=$(TOKUROOT)lib
ifeq ($(CC),icc)
CXXFLAGS += -diag-disable 981
CXX=icc
endif
ifneq ($(OSX),)
VGRIND=
else
VGRIND=valgrind --quiet --error-exitcode=1 --leak-check=yes --suppressions=../../ft/valgrind.suppressions
endif
default: build
build all: $(TARGETS)
$(TARGETS): $(DBCXX)
$(DBCXX):
cd ..;make
clean:
rm -rf $(TARGETS) *.gcno *.gcda *.gcov *.db dir.test.db.assoc3 test_reverse_compare_fun.cpp.dir *.tdb.clean *.tdb.dirty
rm -rf *.dir
rm -rf *.out
rm -rf \
*.tokudb \
tokudb.environment \
tokudb.directory \
test_no_env \
#this line left blank
check_test1: test1
$(VGRIND) ./$< $(SUMMARIZE_CMD)
check_test_errpfx: test_errpfx
$(VGRIND) ./$< > errpfxactual.out && \
(echo "Prefix: Hello Name!";echo -n ": Success") > errpfxexpect.out && \
diff errpfxactual.out errpfxexpect.out \
$(SUMMARIZE_CMD)
check_test_db_assoc3: test_db_assoc3
$(VGRIND) ./test_db_assoc3 && \
$(VGRIND) ./test_db_assoc3 --more \
$(SUMMARIZE_CMD)
check_test_cursor_count: test_cursor_count
$(VGRIND) ./test_cursor_count $(MAYBEINVERTER) $(SUMMARIZE_CMD)
check_test_error_stream: test_error_stream
$(VGRIND) ./test_error_stream 2> $@.out $(SUMMARIZE_CMD)
check_test1e: test1e
$(VGRIND) ./test1e > test1eactual.out && \
(echo "Prefix: Hello Name!";echo -n ": Success") > test1expect.out
diff test1eactual.out test1expect.out \
$(SUMMARIZE_CMD)
check_create_dump_diff: db_create db_dump db_dump_e
rm -rf $@.dir
mkdir $@.dir
$(VGRIND) ./db_create --env_dir $@.dir cdd.tdb a b c d && \
$(VGRIND) ./db_dump --env_dir $@.dir cdd.tdb > cdd.out && \
(echo " 61";echo " 62";echo " 63";echo " 64")>cddexpect.out && \
diff cdd.out cddexpect.out && \
$(VGRIND) ./db_dump_e --env_dir $@.dir cdd.tdb > cdd.out && \
diff cdd.out cddexpect.out \
$(SUMMARIZE_CMD)
check_test_reverse_compare_fun: test_reverse_compare_fun
$(VGRIND) ./test_reverse_compare_fun $(SUMMARIZE_CMD)
check: $(TARGETS) \
check_create_dump_diff \
check_test1 \
check_test_errpfx \
check_test_cursor_count \
check_test_error_stream \
check_test_reverse_compare_fun \
check_test1e \
check_db_create \
check_db_create_1 check_db_create_2 check_db_create_3 check_db_create_4 \
check_permissions \
check_exceptions \
check_test_db_delete \
check_test_get_not_found \
# line intentionally left blank
check_test_get_not_found: test_get_not_found
$(VGRIND) ./test_get_not_found $(SUMMARIZE_CMD)
check_test_db_delete: test_db_delete
$(VGRIND) ./test_db_delete $(SUMMARIZE_CMD)
check_exceptions: exceptions
$(VGRIND) ./exceptions $(MAYBEINVERTER) $(SUMMARIZE_CMD)
check_db_create: db_create
rm -rf $@.dir
mkdir $@.dir
$(VGRIND) ./db_create --env_dir $@.dir -s main $@.tdb $(SUMMARIZE_CMD)
# These don't need to set the env dir
check_db_create_1: db_create
$(VGRIND) ./db_create &> $@.out ; test $$? -ne 0 $(SUMMARIZE_CMD)
check_db_create_2: db_create
$(VGRIND) ./db_create -h &> $@.out ; test $$? -ne 0 $(SUMMARIZE_CMD)
check_db_create_3: db_create
$(VGRIND) ./db_create --help &> $@.out; test $$? -ne 0 $(SUMMARIZE_CMD)
check_db_create_4: db_create
$(VGRIND) ./db_create -s &> $@.out ; test $$? -ne 0 $(SUMMARIZE_CMD)
check_permissions: db_create
rm -rf $@.dir && mkdir $@.dir && \
./db_create --env_dir $@.dir permissions.tdb 1 1 && \
chmod -w $@.dir/*.tokudb && \
(./db_create --env_dir $@.dir permissions.tdb 2 2 &> check_permissions.out 2>&1 ; test $$? -ne 0) \
$(SUMMARIZE_CMD)
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <assert.h>
#include <db_cxx.h>
char *data_dir, *env_dir=NULL;
static int dbcreate(char *dbfile, char *dbname, int dbflags, int argc, char *argv[]) {
int r;
DbEnv *env = new DbEnv(DB_CXX_NO_EXCEPTIONS);
if (data_dir) {
r = env->set_data_dir(data_dir); assert(r == 0);
}
r = env->set_redzone(0); assert(r==0);
r = env->open(env_dir ? env_dir : ".", DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
Db *db = new Db(env, DB_CXX_NO_EXCEPTIONS);
r = db->set_flags(dbflags); assert(r == 0);
r = db->open(0, dbfile, dbname, DB_BTREE, DB_CREATE, 0777);
if (r != 0) {
printf("db->open %s(%s) %d %s\n", dbfile, dbname, r, db_strerror(r));
db->close(0); delete db;
env->close(0); delete env;
return 1;
}
int i = 0;
while (i < argc) {
char *k = argv[i++];
if (i < argc) {
char *v = argv[i++];
Dbt key(k, strlen(k)); Dbt val(v, strlen(v));
r = db->put(0, &key, &val, 0); assert(r == 0);
}
}
r = db->close(0); assert(r == 0);
delete db;
r = env->close(0); assert(r == 0);
delete env;
return 0;
}
static int usage() {
fprintf(stderr, "db_create [-s DBNAME] DBFILE [KEY VAL]*\n");
fprintf(stderr, "[--set_data_dir DIRNAME]\n");
return 1;
}
int main(int argc, char *argv[]) {
char *dbname = 0;
int dbflags = 0;
int i;
for (i=1; i<argc; i++) {
char *arg = argv[i];
if (0 == strcmp(arg, "-h") || 0 == strcmp(arg, "--help"))
return usage();
if (0 == strcmp(arg, "-s")) {
if (i+1 >= argc)
return usage();
dbname = argv[++i];
continue;
}
if (0 == strcmp(arg, "--env_dir")) {
if (i+1 >= argc)
return usage();
env_dir = argv[++i];
continue;
}
if (0 == strcmp(arg, "--set_data_dir")) {
if (i+1 >= argc)
return usage();
data_dir = argv[++i];
continue;
}
if (arg[0]=='-') {
printf("I don't understand this argument: %s\n", arg);
return 1;
}
break;
}
if (i >= argc)
return usage();
char *dbfile = argv[i++];
return dbcreate(dbfile, dbname, dbflags, argc-i, &argv[i]);
}
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <stdlib.h>
#include <assert.h>
#include <db_cxx.h>
#include <memory.h>
static void hexdump(Dbt *d) {
unsigned char *cp = (unsigned char *) d->get_data();
int n = d->get_size();
printf(" ");
for (int i=0; i<n; i++)
printf("%2.2x", cp[i]);
printf("\n");
}
static int dbdump(const char *env_dir, const char *dbfile, const char *dbname) {
int r;
#if defined(USE_ENV) && USE_ENV
DbEnv env(DB_CXX_NO_EXCEPTIONS);
r = env.set_redzone(0); assert(r==0);
r = env.open(env_dir, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
Db db(&env, DB_CXX_NO_EXCEPTIONS);
#else
Db db(0, DB_CXX_NO_EXCEPTIONS);
#endif
r = db.open(0, dbfile, dbname, DB_UNKNOWN, 0, 0777);
if (r != 0) {
printf("cant open %s:%s %d:%s\n", dbfile, dbname, r, db_strerror(r));
#if defined(USE_ENV) && USE_ENV
r = env.close(0); assert(r == 0);
#endif
return 1;
}
u_int32_t dbflags;
r = db.get_flags(&dbflags); assert(r == 0);
#ifndef TOKUDB
if (dbflags & DB_DUP)
printf("duplicates=1\n");
if (dbflags & DB_DUPSORT)
printf("dupsort=1\n");
#endif
#if 0
u_int32_t nodesize;
r = db.get_nodesize(&nodesize); assert(r == 0);
printf("nodesize=%d\n", nodesize);
#endif
Dbc *cursor;
r = db.cursor(0, &cursor, 0); assert(r == 0);
Dbt key; key.set_flags(DB_DBT_REALLOC);
Dbt val; val.set_flags(DB_DBT_REALLOC);
for (;;) {
r = cursor->get(&key, &val, DB_NEXT);
if (r != 0) break;
// printf("%.*s\n", key.get_size(), (char *)key.get_data());
hexdump(&key);
// printf("%.*s\n", val.get_size(), (char *)val.get_data());
hexdump(&val);
}
if (key.get_data()) toku_free(key.get_data());
if (val.get_data()) toku_free(val.get_data());
r = cursor->close(); assert(r == 0);
r = db.close(0); assert(r == 0);
#if defined(USE_ENV) && USE_ENV
r = env.close(0); assert(r == 0);
#endif
return 0;
}
static int usage() {
printf("db_dump [-s DBNAME] DBFILE\n");
return 1;
}
int main(int argc, const char *argv[]) {
const char *dbname = 0;
const char *env_dir = ".";
int i;
for (i=1; i<argc; i++) {
const char *arg = argv[i];
if (0 == strcmp(arg, "-h") || 0 == strcmp(arg, "--help"))
return usage();
if (0 == strcmp(arg, "-s")) {
if (i+1 >= argc)
return usage();
dbname = argv[++i];
continue;
}
if (0 == strcmp(arg, "--env_dir")) {
if (i+1 >= argc)
return usage();
env_dir = argv[++i];
continue;
}
break;
}
if (i >= argc)
return usage();
return dbdump(env_dir, argv[i], dbname);
}
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
/* Just like db_dump.cpp except use exceptions. */
#include <stdlib.h>
#include <assert.h>
#include <db_cxx.h>
#include <memory.h>
static void hexdump(Dbt *d) {
unsigned char *cp = (unsigned char *) d->get_data();
int n = d->get_size();
printf(" ");
for (int i=0; i<n; i++)
printf("%2.2x", cp[i]);
printf("\n");
}
static int dbdump(const char *env_dir, const char *dbfile, const char *dbname) {
int r;
#if defined(USE_ENV) && USE_ENV
DbEnv env(0);
r = env.set_redzone(0); assert(r==0);
r = env.open(env_dir, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
Db db(&env, 0);
#else
Db db(0, 0);
#endif
try {
r = db.open(0, dbfile, dbname, DB_BTREE, 0, 0777);
assert(r==0);
} catch (DbException e) {
printf("Cannot open %s:%s due to error %d\n", dbfile, dbname, e.get_errno());
#if defined(USE_ENV) && USE_ENV
r = env.close(0); assert(r == 0);
#endif
return 1;
}
Dbc *cursor;
r = db.cursor(0, &cursor, 0); assert(r == 0);
Dbt key; key.set_flags(DB_DBT_REALLOC);
Dbt val; val.set_flags(DB_DBT_REALLOC);
try {
for (;;) {
r = cursor->get(&key, &val, DB_NEXT);
if (r == DB_NOTFOUND) break;
assert(r==0);
// printf("%.*s\n", key.get_size(), (char *)key.get_data());
hexdump(&key);
// printf("%.*s\n", val.get_size(), (char *)val.get_data());
hexdump(&val);
}
} catch (DbException ) {
/* Nothing, that's just how we got out of the loop. */
}
toku_free(key.get_data());
toku_free(val.get_data());
r = cursor->close(); assert(r == 0);
r = db.close(0); assert(r == 0);
#if defined(USE_ENV) && USE_ENV
r = env.close(0); assert(r == 0);
#endif
return 0;
}
static int usage() {
printf("db_dump [-s DBNAME] DBFILE\n");
return 1;
}
int main(int argc, char *argv[]) {
int i;
const char *env_dir = ".";
const char *dbname = 0;
for (i=1; i<argc; i++) {
const char *arg = argv[i];
if (0 == strcmp(arg, "-h") || 0 == strcmp(arg, "--help"))
return usage();
if (0 == strcmp(arg, "-s")) {
i++;
if (i >= argc)
return usage();
dbname = argv[i];
continue;
}
if (0 == strcmp(arg, "--env_dir")) {
if (i+1 >= argc)
return usage();
env_dir = argv[++i];
continue;
}
break;
}
if (i >= argc)
return usage();
return dbdump(env_dir, argv[i], dbname);
}
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <stdlib.h>
#include <assert.h>
#include <db_cxx.h>
#include <memory.h>
static inline void hexdump(Dbt *d) {
unsigned char *cp = (unsigned char *) d->get_data();
int n = d->get_size();
printf(" ");
for (int i=0; i<n; i++)
printf("%2.2x", cp[i]);
printf("\n");
}
static void hexput(Dbt *d, int c) {
unsigned char *cp = (unsigned char *) d->get_data();
int n = d->get_size();
int ulen = d->get_ulen();
if (n+1 >= ulen) {
int newulen = ulen == 0 ? 1 : ulen*2;
cp = (unsigned char *) toku_realloc(cp, newulen); assert(cp);
d->set_data(cp);
d->set_ulen(newulen);
}
cp[n++] = (unsigned char)c;
d->set_size(n);
}
static int hextrans(int c) {
if ('0' <= c && c <= '9') return c - '0';
if ('a' <= c && c <= 'f') return c - 'a' + 10;
if ('A' <= c && c <= 'F') return c - 'A' + 10;
return 0;
}
static int hexload(Dbt *d) {
d->set_size(0);
int c = getchar();
if (c == EOF || c != ' ') return 0;
for (;;) {
int c0 = getchar();
if (c0 == EOF) return 0;
if (c0 == '\n') break;
int c1 = getchar();
if (c1 == EOF) return 0;
if (c1 == '\n') break;
hexput(d, (hextrans(c0) << 4) + hextrans(c1));
}
return 1;
}
static int dbload(const char *envdir, const char *dbfile, const char *dbname) {
int r;
#if defined(USE_ENV) && USE_ENV
DbEnv env(DB_CXX_NO_EXCEPTIONS);
r = env.open(envdir, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
Db db(&env, DB_CXX_NO_EXCEPTIONS);
#else
Db db(0, DB_CXX_NO_EXCEPTIONS);
#endif
r = db.open(0, dbfile, dbname, DB_BTREE, DB_CREATE, 0777);
if (r != 0) {
printf("cant open %s:%s\n", dbfile, dbname);
#if defined(USE_ENV) && USE_ENV
r = env.close(0); assert(r == 0);
#endif
return 1;
}
Dbt key, val;
for (;;) {
if (!hexload(&key)) break;
// hexdump(&key);
if (!hexload(&val)) break;
// hexdump(&val);
r = db.put(0, &key, &val, 0);
assert(r == 0);
}
if (key.get_data()) toku_free(key.get_data());
if (val.get_data()) toku_free(val.get_data());
r = db.close(0); assert(r == 0);
#if defined(USE_ENV) && USE_ENV
r = env.close(0); assert(r == 0);
#endif
return 0;
}
static int usage() {
printf("db_load [-s DBNAME] DBFILE\n");
return 1;
}
int main(int argc, const char *argv[]) {
int i;
const char *dbname = 0;
const char *env_dir = ".";
for (i=1; i<argc; i++) {
const char *arg = argv[i];
if (0 == strcmp(arg, "-h") || 0 == strcmp(arg, "--help"))
return usage();
if (0 == strcmp(arg, "-s")) {
i++;
if (i >= argc)
return usage();
dbname = argv[i];
continue;
}
if (0 == strcmp(arg, "--env_dir")) {
if (i+1 >= argc)
return usage();
env_dir = argv[++i];
continue;
}
break;
}
if (i >= argc)
return usage();
return dbload(env_dir, argv[i], dbname);
}
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <assert.h>
#include <db_cxx.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <memory.h>
#define FNAME __FILE__ ".tdb"
#define FNAME2 __FILE__ "2.tdb"
#ifndef DB_DELETE_ANY
#define DB_DELETE_ANY 0
#endif
#ifndef DB_KEYEMPTY
#define DB_KEYEMPTY DB_NOTFOUND
#endif
#define DIR __FILE__ ".dir"
int verbose = 0;
#define TC(expr, expect) \
if (verbose) printf("%s expect %d\n", #expr, expect); \
try { \
expr; \
assert(expect==0); \
} catch (DbException e) { \
if (e.get_errno()!=expect) fprintf(stderr, "err=%d %s\n", e.get_errno(), db_strerror(e.get_errno())); \
assert(e.get_errno()==expect); \
}
#define TCRET(expr, expect) \
if (verbose) printf("%s expect %d\n", #expr, expect); \
try { \
int r = expr; \
assert(expect==r); \
} catch (DbException e) { \
if (e.get_errno()!=expect) fprintf(stderr, "err=%d %s\n", e.get_errno(), db_strerror(e.get_errno())); \
assert(e.get_errno()==expect); \
}
static void test_env_exceptions (void) {
{
DbEnv env(0);
int r = env.set_redzone(0); assert(r==0);
TC(env.open(DIR "no.such.dir", DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE, 0777), ENOENT);
}
{
DbEnv env(0);
int r = env.set_redzone(0); assert(r==0);
TC(env.open(DIR "no.such.dir", (u_int32_t)-1, 0777), EINVAL);
}
{
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
DbEnv env(0);
int r = env.set_redzone(0); assert(r==0);
TC(env.open(DIR, DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE, 0777), 0);
DbTxn *txn;
TC(env.txn_begin(0, &txn, 0), EINVAL); // not configured for transactions
}
{
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
DbEnv env(0);
int r = env.set_redzone(0); assert(r==0);
TC(env.open(DIR, DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE | DB_INIT_LOG, 0777), EINVAL); // cannot do logging without txns
}
{
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
DbEnv env(0);
int r = env.set_redzone(0); assert(r==0);
TC(env.open(DIR, DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE | DB_INIT_LOG | DB_INIT_TXN, 0777), 0);
DbTxn *txn;
TC(env.txn_begin(0, &txn, 0), 0);
TC(txn->commit(0), 0);
delete txn;
}
{
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
DbEnv env(0);
env.set_errfile(stderr);
int r = env.set_redzone(0); assert(r==0);
TC(env.open(DIR, DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE | DB_INIT_LOG | DB_INIT_LOCK | DB_INIT_TXN, 0777), 0);
DbTxn *txn;
TC(env.txn_begin(0, &txn, 0), 0);
TC(txn->commit(0), 0);
delete txn;
}
{
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
DbEnv env(0);
int r = env.set_redzone(0); assert(r==0);
TC(env.open(DIR, DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE | DB_INIT_LOG | DB_INIT_TXN, 0777), 0);
DbTxn *txn;
TC(env.txn_begin(0, &txn, 0), 0);
TC(txn->commit((u_int32_t)-1), EINVAL);
delete txn;
}
system("rm -rf " DIR);
}
static void test_db_exceptions (void) {
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
DbEnv env(0);
int r = env.set_redzone(0); assert(r==0);
TC(env.open(DIR, DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE , 0777), 0);
env.set_errfile(stderr);
TC( { Db db(&env, (u_int32_t)-1); assert(0); }, EINVAL); // Create with flags=-1 should do an EINVAL
Db db(&env, 0);
DB *dbdb=db.get_DB();
assert(dbdb!=0);
assert(dbdb==db.get_const_DB());
assert(&db==Db::get_const_Db(dbdb));
unlink(FNAME);
TC(db.open(0, FNAME, 0, DB_BTREE, DB_CREATE, 0777), 0);
TC(db.open(0, FNAME, 0, DB_BTREE, DB_CREATE, 0777), EINVAL); // it was already open
{
Db db2(&env, 0);
TC(db2.open(0, FNAME2, 0, DB_BTREE, 0, 0777), ENOENT); // it doesn't exist
}
{
Db db2(&env, 0);
TC(db2.open(0, FNAME, 0, DB_BTREE, 0, 0777), 0); // it does exist
}
{
Db db2(&env, 0);
TC(db2.open(0, FNAME, 0, DB_BTREE, (u_int32_t)-1, 0777), EINVAL); // bad flags
}
{
Db db2(&env, 0);
TC(db2.open(0, FNAME, 0, (DBTYPE)-1, 0, 0777), EINVAL); // bad type
}
{
Db db2(&env, 0);
TC(db2.open(0, FNAME, "sub.db", DB_BTREE, DB_CREATE, 0777), ENOTDIR); // sub DB cannot exist
}
{
Db db2(&env, 0);
TC(db2.open(0, FNAME, "sub.db", DB_BTREE, 0, 0777), ENOTDIR); // sub DB cannot exist withou DB_CREATE
}
{
Dbc *curs;
TC(db.cursor(0, &curs, (u_int32_t)-1), EINVAL);
}
{
Dbc *curs;
TC(db.cursor(0, &curs, 0), 0);
Dbt key,val;
// TC(curs->get(&key, &val, DB_FIRST), DB_NOTFOUND);
TC(curs->get(&key, &val, (u_int32_t)-1), EINVAL); // bad flags
curs->close(); // no deleting cursors.
}
{
Dbt key,val;
TC(db.del(0, &key, (u_int32_t)-1), EINVAL);
TC(db.get(0, &key, &val, (u_int32_t)-1), EINVAL);
TC(db.put(0, &key, &val, (u_int32_t)-1), EINVAL);
}
{
Dbt key((char*)"hello", 6);
Dbt val((char*)"there", 6);
Dbt valget;
TC(db.put(0, &key, &val, 0), 0);
TC(db.get(0, &key, &valget, 0), 0);
assert(strcmp((const char*)(valget.get_data()), "there")==0);
}
}
static void test_dbc_exceptions () {
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
DbEnv env(0);
TC(env.open(DIR, DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE , 0777), 0);
Db db(&env, 0);
unlink(FNAME);
TC(db.open(0, FNAME, 0, DB_BTREE, DB_CREATE, 0777), 0);
for (int k = 1; k<4; k++) {
Dbt key(&k, sizeof k);
Dbt val(&k, sizeof k);
TC(db.put(0, &key, &val, 0), 0);
}
Dbc *curs;
TC(db.cursor(0, &curs, 0), 0);
Dbt key; key.set_flags(DB_DBT_MALLOC);
Dbt val; val.set_flags(DB_DBT_MALLOC);
TC(curs->get(&key, &val, DB_FIRST), 0);
toku_free(key.get_data());
toku_free(val.get_data());
#if 0
// c_del no longer supported. See #4576.
TC(curs->del(DB_DELETE_ANY), 0);
TCRET(curs->get(&key, &val, DB_CURRENT), DB_KEYEMPTY);
TCRET(curs->del(0), DB_KEYEMPTY);
TCRET(curs->del(DB_DELETE_ANY), 0);
#endif
curs->close(); // no deleting cursors.
}
int main(int argc, char *argv[]) {
for (int i = 1; i < argc; i++) {
char *arg = argv[i];
if (0 == strcmp(arg, "-v")) {
verbose++;
continue;
}
}
test_env_exceptions();
test_db_exceptions();
test_dbc_exceptions();
system("rm -rf " DIR);
return 0;
}
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <db_cxx.h>
#include <errno.h>
#include <assert.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <iostream>
using namespace std;
void test_dbt(void) {
u_int32_t size = 3;
u_int32_t flags = 5;
u_int32_t ulen = 7;
void* data = &size;
Dbt dbt;
dbt.set_size(size);
dbt.set_flags(flags);
dbt.set_data(data);
dbt.set_ulen(ulen);
assert(dbt.get_size() == size);
assert(dbt.get_flags() == flags);
assert(dbt.get_data() == data);
assert(dbt.get_ulen() == ulen);
}
int cmp(DB *db, const DBT *dbt1, const DBT *dbt2) {
return 0;
}
void test_db(void) {
DbEnv env(DB_CXX_NO_EXCEPTIONS);
{ int r = env.set_redzone(0); assert(r==0); }
{ int r = env.set_default_bt_compare(cmp); assert(r == 0); }
int r = env.open("test1.dir", DB_CREATE|DB_PRIVATE, 0666);
assert(r==0);
Db db(&env, 0);
r = db.remove("DoesNotExist.db", NULL, 0); assert(r == ENOENT);
// The db is closed
r = env.close(0); assert(r== 0);
}
int main()
{
system("rm -rf test1.dir");
mkdir("test1.dir", 0777);
test_dbt();
test_db();
return 0;
}
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <db_cxx.h>
#include <errno.h>
#include <assert.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <iostream>
using namespace std;
int cmp(DB *db, const DBT *dbt1, const DBT *dbt2) {
return 0;
}
#define DIR "test1e.dir"
void test_db(void) {
system("rm -rf " DIR);
mkdir(DIR, 0777);
DbEnv env(0);
{ int r = env.set_redzone(0); assert(r==0); }
{ int r = env.set_default_bt_compare(cmp); assert(r == 0); }
env.open(DIR, DB_CREATE|DB_PRIVATE, 0666);
Db db(&env, 0);
try {
db.remove("DoesNotExist.db", NULL, 0);
abort(); // must not make it here.
} catch (DbException e) {
assert(e.get_errno() == ENOENT);
}
// The db is closed.
env.close(0);
}
void test_db_env(void) {
DbEnv dbenv(0);
int r;
r = dbenv.set_data_dir("."); assert(r == 0);
try {
r = dbenv.set_data_dir(NULL);
abort();
} catch (DbException e) {
assert(e.get_errno() == EINVAL);
}
dbenv.set_errpfx("Prefix");
dbenv.set_errfile(stdout);
dbenv.err(0, "Hello %s!\n", "Name");
dbenv.close(0);
}
int main()
{
test_db();
test_db_env();
return 0;
}
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <arpa/inet.h>
#include <assert.h>
#include <db_cxx.h>
#include <memory.h>
#include <sys/stat.h>
int verbose;
#define FNAME __FILE__ ".tdb"
int keyeq(Dbt *a, Dbt *b) {
if (a->get_size() != b->get_size()) return 0;
return memcmp(a->get_data(), b->get_data(), a->get_size()) == 0;
}
int my_cursor_count(Dbc *cursor, db_recno_t *count, Db *db) {
int r;
Dbt key; key.set_flags(DB_DBT_REALLOC);
Dbt val; val.set_flags(DB_DBT_REALLOC);
r = cursor->get(&key, &val, DB_CURRENT); assert(r == 0);
Dbc *count_cursor;
r = db->cursor(0, &count_cursor, 0); assert(r == 0);
r = count_cursor->get(&key, &val, DB_SET); assert(r == 0);
*count = 0;
Dbt nkey, nval;
for (;; ) {
*count += 1;
nkey.set_flags(DB_DBT_REALLOC);
nval.set_flags(DB_DBT_REALLOC);
r = count_cursor->get(&nkey, &nval, DB_NEXT);
if (r != 0) break;
if (!keyeq(&key, &nkey)) break;
}
r = 0;
if (nkey.get_data()) toku_free(nkey.get_data());
if (nval.get_data()) toku_free(nval.get_data());
if (key.get_data()) toku_free(key.get_data());
if (val.get_data()) toku_free(val.get_data());
int rr = count_cursor->close(); assert(rr == 0);
return r;
}
int my_next_nodup(Dbc *cursor, Dbt *key, Dbt *val) {
int r;
Dbt currentkey; currentkey.set_flags(DB_DBT_REALLOC);
Dbt currentval; currentval.set_flags(DB_DBT_REALLOC);
r = cursor->get(&currentkey, &currentval, DB_CURRENT); assert(r == 0);
Dbt nkey; nkey.set_flags(DB_DBT_REALLOC);
Dbt nval; nval.set_flags(DB_DBT_REALLOC);
for (;;) {
r = cursor->get(&nkey, &nval, DB_NEXT);
if (r != 0) break;
if (!keyeq(&currentkey, &nkey)) break;
}
if (nkey.get_data()) toku_free(nkey.get_data());
if (nval.get_data()) toku_free(nval.get_data());
if (currentkey.get_data()) toku_free(currentkey.get_data());
if (currentval.get_data()) toku_free(currentval.get_data());
if (r == 0) r = cursor->get(key, val, DB_CURRENT);
return r;
}
int my_prev_nodup(Dbc *cursor, Dbt *key, Dbt *val) {
int r;
Dbt currentkey; currentkey.set_flags(DB_DBT_REALLOC);
Dbt currentval; currentval.set_flags(DB_DBT_REALLOC);
r = cursor->get(&currentkey, &currentval, DB_CURRENT); assert(r == 0);
Dbt nkey; nkey.set_flags(DB_DBT_REALLOC);
Dbt nval; nval.set_flags(DB_DBT_REALLOC);
for (;;) {
r = cursor->get(&nkey, &nval, DB_PREV);
if (r != 0) break;
if (!keyeq(&currentkey, &nkey)) break;
}
if (nkey.get_data()) toku_free(nkey.get_data());
if (nval.get_data()) toku_free(nval.get_data());
if (currentkey.get_data()) toku_free(currentkey.get_data());
if (currentval.get_data()) toku_free(currentval.get_data());
if (r == 0) r = cursor->get(key, val, DB_CURRENT);
return r;
}
int my_next_dup(Dbc *cursor, Dbt *key, Dbt *val) {
int r;
Dbt currentkey; currentkey.set_flags(DB_DBT_REALLOC);
Dbt currentval; currentval.set_flags(DB_DBT_REALLOC);
r = cursor->get(&currentkey, &currentval, DB_CURRENT); assert(r == 0);
Dbt nkey; nkey.set_flags(DB_DBT_REALLOC);
Dbt nval; nval.set_flags(DB_DBT_REALLOC);
r = cursor->get(&nkey, &nval, DB_NEXT);
if (r == 0 && !keyeq(&currentkey, &nkey)) r = DB_NOTFOUND;
if (nkey.get_data()) toku_free(nkey.get_data());
if (nval.get_data()) toku_free(nval.get_data());
if (currentkey.get_data()) toku_free(currentkey.get_data());
if (currentval.get_data()) toku_free(currentval.get_data());
if (r == 0) r = cursor->get(key, val, DB_CURRENT);
return r;
}
int my_prev_dup(Dbc *cursor, Dbt *key, Dbt *val) {
int r;
Dbt currentkey; currentkey.set_flags(DB_DBT_REALLOC);
Dbt currentval; currentval.set_flags(DB_DBT_REALLOC);
r = cursor->get(&currentkey, &currentval, DB_CURRENT); assert(r == 0);
Dbt nkey; nkey.set_flags(DB_DBT_REALLOC);
Dbt nval; nval.set_flags(DB_DBT_REALLOC);
r = cursor->get(&nkey, &nval, DB_PREV);
if (r == 0 && !keyeq(&currentkey, &nkey)) r = DB_NOTFOUND;
if (nkey.get_data()) toku_free(nkey.get_data());
if (nval.get_data()) toku_free(nval.get_data());
if (currentkey.get_data()) toku_free(currentkey.get_data());
if (currentval.get_data()) toku_free(currentval.get_data());
if (r == 0) r = cursor->get(key, val, DB_CURRENT);
return r;
}
void load(Db *db, int n) {
if (verbose) printf("load\n");
int i;
for (i=0; i<n; i++) {
if (i == n/2) continue;
int k = htonl(i);
Dbt key(&k, sizeof k);
int v = i;
Dbt val(&v, sizeof v);
int r = db->put(0, &key, &val, 0); assert(r == 0);
}
for (i=0; i<n; i++) {
int k = htonl(n/2);
int v = i;
Dbt key(&k, sizeof k);
Dbt val(&v, sizeof v);
int r = db->put(0, &key, &val, 0); assert(r == 0);
}
}
void test_cursor_count_flags(Db *db) {
int r;
Dbc *cursor;
r = db->cursor(0, &cursor, 0); assert(r == 0);
Dbt key; key.set_flags(DB_DBT_MALLOC);
Dbt val; val.set_flags(DB_DBT_MALLOC);
r = cursor->get(&key, &val, DB_FIRST); assert(r == 0);
if (key.get_data()) toku_free(key.get_data());
if (val.get_data()) toku_free(val.get_data());
db_recno_t n;
r = cursor->count(&n, 1); assert(r == EINVAL);
r = cursor->count(&n, 0); assert(r == 0);
if (verbose) printf("n=%d\n", n);
r = cursor->close(); assert(r == 0);
}
void walk(Db *db, int n) {
if (verbose) printf("walk\n");
Dbc *cursor;
int r = db->cursor(0, &cursor, 0); assert(r == 0);
Dbt key, val;
int i;
for (i=0;;i++) {
key.set_flags(DB_DBT_REALLOC);
val.set_flags(DB_DBT_REALLOC);
r = cursor->get(&key, &val, DB_NEXT);
if (r != 0) break;
int k;
assert(key.get_size() == sizeof k);
memcpy(&k, key.get_data(), key.get_size());
k = htonl(k);
int v;
assert(val.get_size() == sizeof v);
memcpy(&v, val.get_data(), val.get_size());
db_recno_t count;
r = cursor->count(&count, 0); assert(r == 0);
if (verbose) printf("%d %d %d\n", k, v, count);
#if 0
db_recno_t mycount;
r = my_cursor_count(cursor, &mycount, db); assert(r == 0);
assert(mycount == count);
#endif
assert(count==1); // we support only NODUP databases now.
}
toku_free(key.get_data());
toku_free(val.get_data());
r = cursor->close(); assert(r == 0);
}
int cursor_set(Dbc *cursor, int k) {
Dbt key(&k, sizeof k);
Dbt val;
int r = cursor->get(&key, &val, DB_SET);
return r;
}
void test_zero_count(Db *db, int n) {
if (verbose) printf("test_zero_count\n");
Dbc *cursor;
int r = db->cursor(0, &cursor, 0); assert(r == 0);
r = cursor_set(cursor, htonl(n/2)); assert(r == 0);
db_recno_t count;
r = cursor->count(&count, 0); assert(r == 0);
assert((int)count == 1);
Dbt key; key.set_flags(DB_DBT_REALLOC);
Dbt val; val.set_flags(DB_DBT_REALLOC);
#if 0
// c->del no longer supported. See #4576.
int i;
for (i=1; count > 0; i++) {
r = cursor->del(0); assert(r == 0);
db_recno_t newcount;
r = cursor->count(&newcount, 0);
if (r != 0)
break;
assert(newcount == count - 1);
count = newcount;
r = cursor->get(&key, &val, DB_NEXT);
if (r != 0) break;
}
assert(i == 2);
#endif
if (key.get_data()) toku_free(key.get_data());
if (val.get_data()) toku_free(val.get_data());
r = cursor->close(); assert(r == 0);
}
void test_next_nodup(Db *db, int n) {
if (verbose) printf("test_next_nodup\n");
int r;
Dbc *cursor;
r = db->cursor(0, &cursor, 0); assert(r == 0);
Dbt key; key.set_flags(DB_DBT_REALLOC);
Dbt val; val.set_flags(DB_DBT_REALLOC);
r = cursor->get(&key, &val, DB_FIRST); assert(r == 0);
int i = 0;
while (r == 0) {
int k = htonl(*(int*)key.get_data());
int v = *(int*)val.get_data();
if (verbose) printf("%d %d\n", k, v);
assert(k == i);
if (k == n/2) assert(v == n-1); else assert(v == i);
i += 1;
// r = my_next_nodup(cursor, &key, &val);
r = cursor->get(&key, &val, DB_NEXT_NODUP);
}
assert(i == n);
if (key.get_data()) toku_free(key.get_data());
if (val.get_data()) toku_free(val.get_data());
r = cursor->close(); assert(r == 0);
}
void test_prev_nodup(Db *db, int n) {
if (verbose) printf("test_prev_nodup\n");
int r;
Dbc *cursor;
r = db->cursor(0, &cursor, 0); assert(r == 0);
Dbt key; key.set_flags(DB_DBT_REALLOC);
Dbt val; val.set_flags(DB_DBT_REALLOC);
r = cursor->get(&key, &val, DB_LAST); assert(r == 0);
int i = n-1;
while (r == 0) {
int k = htonl(*(int*)key.get_data());
int v = *(int*)val.get_data();
if (verbose) printf("%d %d\n", k, v);
assert(k == i);
if (k == n/2) assert(v == n-1); else assert(v == i);
i -= 1;
// r = my_next_nodup(cursor, &key, &val);
r = cursor->get(&key, &val, DB_PREV_NODUP);
}
assert(i == -1);
if (key.get_data()) toku_free(key.get_data());
if (val.get_data()) toku_free(val.get_data());
r = cursor->close(); assert(r == 0);
}
#define DIR "test_cursor_count.dir"
int main(int argc, char *argv[]) {
for (int i=1; i<argc; i++) {
char *arg = argv[i];
if (strcmp(arg, "-v") == 0 || strcmp(arg, "--verbose") == 0)
verbose = 1;
}
int r;
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
#if defined(USE_ENV) && USE_ENV
DbEnv env(DB_CXX_NO_EXCEPTIONS);
r = env.set_redzone(0); assert(r==0);
r = env.open(DIR, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
Db db(&env, DB_CXX_NO_EXCEPTIONS);
#else
Db db(0, DB_CXX_NO_EXCEPTIONS);
#endif
unlink(FNAME);
r = db.open(0, FNAME, 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0);
load(&db, 10);
test_cursor_count_flags(&db);
walk(&db, 10);
test_next_nodup(&db, 10);
test_prev_nodup(&db, 10);
test_zero_count(&db, 10);
return 0;
}
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <stdio.h>
#include <assert.h>
#include <db_cxx.h>
#include <stdlib.h>
#include <memory.h>
#define DIR __FILE__ ".dir"
#define FNAME "test.tdb"
void test_new_delete() {
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
DbEnv env(0);
{ int r = env.set_redzone(0); assert(r==0); }
{ int r = env.open(DIR, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0); }
Db *db = new Db(&env, 0); assert(db != 0);
delete db;
}
void test_new_open_delete() {
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
DbEnv env(0);
{ int r = env.set_redzone(0); assert(r==0); }
{ int r = env.open(DIR, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0); }
Db *db = new Db(&env, 0); assert(db != 0);
{ int r = db->open(NULL, FNAME, 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0); }
{ int r = db->close(0); assert(r == 0); }
delete db;
}
int main() {
test_new_delete();
test_new_open_delete();
return 0;
}
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <assert.h>
#include <db_cxx.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int r;
DbEnv env(DB_CXX_NO_EXCEPTIONS);
r = env.set_flags(0, 0); assert(r == 0);
r = env.set_flags(0, 1); assert(r == 0);
return 0;
}
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <iostream>
#include <fcntl.h>
#include <assert.h>
#include <errno.h>
#include <db_cxx.h>
#include <memory.h>
int verbose;
#define DIR __FILE__ ".dir"
#define FNAME "test.tdb"
int test_error_stream(void) {
int r;
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
DbEnv env(DB_CXX_NO_EXCEPTIONS);
env.set_errpfx("my_env_error_stream");
env.set_error_stream(&std::cerr);
r = env.open(DIR, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
r = env.open(DIR, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == EINVAL);
Db db(&env, 0);
db.set_errpfx("my_db_error_stream");
db.set_error_stream(&std::cerr);
r = db.open(NULL, FNAME, 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0);
r = db.close(0); assert(r == 0);
r = db.close(0); assert(r == EINVAL);
r = env.close(0); assert(r == 0);
r = env.close(0); assert(r == EINVAL);
return 0;
}
int usage() {
printf("test_error_stream [-v] [--verbose]\n");
return 1;
}
int main(int argc, char *argv[]) {
for (int i=1; i<argc; i++) {
char *arg = argv[i];
if (0 == strcmp(arg, "-h") || 0 == strcmp(arg, "--help")) {
return usage();
}
if (0 == strcmp(arg, "-v") || 0 == strcmp(arg, "--verbose")) {
verbose = 1; continue;
}
}
return test_error_stream();
}
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <db_cxx.h>
#include <errno.h>
#include <assert.h>
#include <iostream>
using namespace std;
void test_db_env(void) {
DbEnv dbenv(DB_CXX_NO_EXCEPTIONS);
int r;
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()
{
test_db_env();
return 0;
}
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
/* This test ensures that a db->get DB_NOTFOUND does not cause an
exception when exceptions are enabled, which is consistent with
Berkeley DB */
#include <db_cxx.h>
#include <assert.h>
#include <stdlib.h>
#include <memory.h>
#define DIR __FILE__ ".dir"
#define fname "foo.tdb"
void db_put(Db *db, int k, int v) {
Dbt key(&k, sizeof k);
Dbt val(&v, sizeof v);
int r = db->put(0, &key, &val, 0);
assert(r == 0);
}
void db_del(Db *db, int k) {
Dbt key(&k, sizeof k);
int r = db->del(0, &key, 0);
assert(r == 0);
}
void db_get(Db *db, int k, int v, int expectr) {
Dbt key(&k, sizeof k);
Dbt val; val.set_data(&v); val.set_ulen(sizeof v); val.set_flags(DB_DBT_USERMEM);
int r = db->get(0, &key, &val, 0);
assert(r == expectr);
if (r == 0) {
assert(val.get_size() == sizeof v);
int vv;
memcpy(&vv, val.get_data(), val.get_size());
assert(vv == v);
}
}
DbEnv *env = NULL;
void reset_env (void) {
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
if (env) delete env;
env = new DbEnv(DB_CXX_NO_EXCEPTIONS);
{ int r = env->set_redzone(0); assert(r==0); }
int r = env->open(DIR, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777);
assert(r == 0);
}
void test_not_found(void) {
int r;
reset_env();
Db *db = new Db(env, DB_CXX_NO_EXCEPTIONS); assert(db);
r = db->open(0, fname, 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0);
db_put(db, 1, 2);
db_get(db, 1, 2, 0);
db_del(db, 1);
db_get(db, 1, 0, DB_NOTFOUND);
r = db->close(0); assert(r == 0);
delete db;
}
void test_exception_not_found(void) {
int r;
reset_env();
Db *db = new Db(env, 0); assert(db);
r = db->open(0, fname, 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0);
db_put(db, 1, 2);
db_get(db, 1, 2, 0);
db_del(db, 1);
try {
db_get(db, 1, 0, DB_NOTFOUND);
} catch(...) {
assert(0);
}
r = db->close(0); assert(r == 0);
delete db;
}
int main(int argc, char *argv[]) {
test_not_found();
test_exception_not_found();
if (env) delete env;
return 0;
}
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
/* try a reverse compare function to verify that the database always uses the application's
compare function */
#include <arpa/inet.h>
#include <assert.h>
#include <db_cxx.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <memory.h>
#define DIR __FILE__ ".dir"
int verbose;
int keycompare (const void *key1, unsigned int key1len, const void *key2, unsigned int key2len) {
if (key1len==key2len) {
return memcmp(key1,key2,key1len);
} else if (key1len<key2len) {
int r = memcmp(key1,key2,key1len);
if (r<=0) return -1; /* If the keys are the same up to 1's length, then return -1, since key1 is shorter than key2. */
else return 1;
} else {
return -keycompare(key2,key2len,key1,key1len);
}
}
extern "C" int reverse_compare(DB *db __attribute__((__unused__)), const DBT *a, const DBT*b) {
return -keycompare(a->data, a->size, b->data, b->size);
}
void expect(Dbc *cursor, int k, int v) {
Dbt key; key.set_flags(DB_DBT_MALLOC);
Dbt val; val.set_flags(DB_DBT_MALLOC);
int r = cursor->get(&key, &val, DB_NEXT);
assert(r == 0);
assert(key.get_size() == sizeof k);
int kk;
memcpy(&kk, key.get_data(), key.get_size());
assert(val.get_size() == sizeof v);
int vv;
memcpy(&vv, val.get_data(), val.get_size());
if (kk != k || vv != v) printf("expect key %d got %d - %d %d\n", htonl(k), htonl(kk), htonl(v), htonl(vv));
assert(kk == k);
assert(vv == v);
toku_free(key.get_data());
toku_free(val.get_data());
}
void test_reverse_compare(int n) {
if (verbose) printf("test_reverse_compare:%d\n", n);
Db *db;
DbTxn * const null_txn = 0;
const char * const fname = "reverse.compare.db";
int r;
int i;
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
/* create the dup database file */
DbEnv env(DB_CXX_NO_EXCEPTIONS);
r = env.set_redzone(0); assert(r==0);
r = env.set_default_bt_compare(reverse_compare);
assert(r == 0);
r = env.open(DIR, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
db = new Db(&env, DB_CXX_NO_EXCEPTIONS);
assert(db);
r = db->set_pagesize(4096);
assert(r == 0);
r = db->open(null_txn, fname, "main", DB_BTREE, DB_CREATE, 0666);
assert(r == 0);
/* insert n unique keys {0, 1, n-1} */
for (i=0; i<n; i++) {
int k, v;
k = htonl(i);
Dbt key(&k, sizeof k);
v = htonl(i);
Dbt val(&v, sizeof v);
r = db->put(null_txn, &key, &val, 0);
assert(r == 0);
}
/* reopen the database to force nonleaf buffering */
r = db->close(0);
assert(r == 0);
delete db;
db = new Db(&env, 0);
assert(db);
r = db->set_pagesize(4096);
assert(r == 0);
r = db->open(null_txn, fname, "main", DB_BTREE, 0, 0666);
assert(r == 0);
/* insert n unique keys {n, n+1, 2*n-1} */
for (i=n; i<2*n; i++) {
int k, v;
k = htonl(i);
Dbt key(&k, sizeof k);
v = htonl(i);
Dbt val(&v, sizeof v);
r = db->put(null_txn, &key, &val, 0);
assert(r == 0);
}
/* verify the sort order with a cursor */
Dbc *cursor;
r = db->cursor(null_txn, &cursor, 0);
assert(r == 0);
//for (i=0; i<2*n; i++)
for (i=2*n-1; i>=0; i--)
expect(cursor, htonl(i), htonl(i));
r = cursor->close();
assert(r == 0);
r = db->close(0);
assert(r == 0);
delete db;
}
int main(int argc, const char *argv[]) {
int i;
for (i = 1; i <= (1<<16); i *= 2) {
test_reverse_compare(i);
}
return 0;
}
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <db_cxx.h>
DbTxn::DbTxn(DB_TXN *txn)
: the_txn(txn)
{
txn->api_internal = this;
}
DbTxn::~DbTxn()
{
if (the_txn) {
the_txn->abort(0);
}
}
int DbTxn::commit (u_int32_t flags) {
DbEnv *env = (DbEnv*)the_txn->mgrp->api1_internal; // Must grab the env before committing the txn (because that releases the txn memory.)
int ret = the_txn->commit(the_txn, flags);
the_txn=0; // So we don't touch it my mistake.
return env->maybe_throw_error(ret);
}
int DbTxn::abort () {
DbEnv *env = (DbEnv*)the_txn->mgrp->api1_internal; // Must grab the env before committing the txn (because that releases the txn memory.)
int ret = the_txn->abort(the_txn);
the_txn=0; // So we don't touch it my mistake.
return env->maybe_throw_error(ret);
}
# -*- Mode: Makefile -*-
#ident "Copyright (c) 2007 Tokutek Inc. All rights reserved."
# standard build: make
# build with Berkeley DB 4.1: make BDBDIR=/usr/local/BerkeleyDB.4.1
# build with TokuDB: make BDBDIR=~/svn/tokudb
# build with g++: make CC=g++
.DEFAULT_GOAL= build
TOKUROOT=../
INCLUDEDIRS=-I. -I../ -I$(TOKUROOT)include -I$(TOKUROOT)toku_include -I$(TOKUROOT)ft -I../range_tree -I../lock_tree
DEPEND_COMPILE += \
./*.h \
#end
HERE = db-benchmark-test-cxx
include $(TOKUROOT)toku_include/Makefile.include
BENCHDBS = bench.bdb/ bench.tokudb
OPTFLAGS = -O2
CXXFLAGS = $(GCC_VERSION_SPECIFIC) -Wall -Werror -g $(OPTFLAGS) $(GCOV_FLAGS)
ifeq ($(CC),icc)
CXX=icc
endif
# CFLAGS += -pg
ifdef BDBDIR
BDB_CPPFLAGS = -I$(BDBDIR)/include -DHAVE_CXX_STDHEADERS
BDB_LDFLAGS = -L$(BDBDIR)/lib -ldb_cxx -Wl,-rpath,$(BDBDIR)/lib -ldl
else
BDB_CPPFLAGS =
BDB_LDFLAGS = -ldb_cxx
endif
BDB_LDFLAGS += -lpthread -L../lib -Wl,-rpath,$(PWD)/../lib -ltokuportability
TARGET_BDB = db-benchmark-test-bdb
TARGET_TDB = db-benchmark-test-tokudb
TARGETS = $(TARGET_BDB) $(TARGET_TDB)
HERE = db-benchmark-test-cxx
ifeq ($(SUMMARIZE),1)
SUMMARIZE_CMD = ;if test $$? = 0; then printf "%-60sPASS\n" $(HERE)/$@; else printf "%-60sFAIL\n" $(HERE)/$@ ; test 0 = 1; fi
QUIET = -q
else
SUMMARIZE_CMD =
QUIET =
endif
default: build
build: $(TARGETS)
check: check-default
check-default: $(TARGET_TDB)
$(VGRIND) ./$(TARGET_TDB) $(QUIET) $(SUMMARIZE_CMD)
check-x: $(TARGET_TDB)
$(VGRIND) ./$(TARGET_TDB) -x $(QUIET) $(SUMMARIZE_CMD)
clean:
rm -rf $(TARGETS) $(BENCHDBS) *.gcno *.gcda *.gcov
db-benchmark-test-tokudb: ../lib/libtokudb_cxx.a
db-benchmark-test-tokudb: db-benchmark-test.cpp
$(CXX) $(CXXFLAGS) -I../include -I../toku_include -L../lib -Wl,-rpath,$(PWD)/../lib $< -o $@ -ltokudb -ltokudb_cxx -DDIRSUF=tokudb -lz -lpthread -ltokuportability
db-benchmark-test-bdb: db-benchmark-test.cpp
$(CXX) $(CXXFLAGS) $(BDB_CPPFLAGS) $(BDB_LDFLAGS) $< -o $@ -DDIRSUF=bdb
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
/* Insert a bunch of stuff */
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <unistd.h>
#include <db_cxx.h>
enum { SERIAL_SPACING = 1<<6 };
enum { ITEMS_TO_INSERT_PER_ITERATION = 1<<20 };
enum { ITEMS_PER_TRANSACTION = 1<<14 };
//enum { ITEMS_TO_INSERT_PER_ITERATION = 1<<14 };
enum { BOUND_INCREASE_PER_ITERATION = SERIAL_SPACING*ITEMS_TO_INSERT_PER_ITERATION };
#define CKERR(r) if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, db_strerror(r)); assert(r==0);
int verbose = 1;
/* default test parameters */
int keysize = sizeof (long long);
int valsize = sizeof (long long);
int pagesize = 0;
long long cachesize = 128*1024*1024;
#define STRINGIFY2(s) #s
#define STRINGIFY(s) STRINGIFY2(s)
char dbdir[] = "./bench." STRINGIFY(DIRSUF) "/"; /* DIRSUF is passed in as a -D argument to the compiler. */;
char dbfilename[] = "bench.db";
char *dbname;
DbEnv *dbenv;
Db *db;
DbTxn *tid=0;
int do_transactions = 0;
int n_insertions_since_txn_began=0;
void setup (void) {
int r;
{
char unlink_cmd[strlen(dbdir) + strlen("rf -rf ") + 1];
snprintf(unlink_cmd, sizeof(unlink_cmd), "rm -rf %s", dbdir);
//printf("unlink_cmd=%s\n", unlink_cmd);
system(unlink_cmd);
}
if (strcmp(dbdir, ".") != 0)
mkdir(dbdir, 0755);
dbenv = new DbEnv(DB_CXX_NO_EXCEPTIONS); assert(dbenv);
#if DB_VERSION_MAJOR<4 || (DB_VERSION_MAJOR==4 && DB_VERSION_MINOR<=4)
{
r = dbenv->set_lk_max(ITEMS_PER_TRANSACTION*2);
assert(r==0);
}
#endif
r = dbenv->set_lk_max_locks(ITEMS_PER_TRANSACTION*2);
assert(r == 0);
if (cachesize) {
r = dbenv->set_cachesize(cachesize / (1024*1024*1024), cachesize % (1024*1024*1024), 1);
if (r != 0)
printf("WARNING: set_cachesize %d\n", r);
}
{
int flags = DB_CREATE|DB_PRIVATE|DB_INIT_MPOOL | (do_transactions ? (DB_INIT_TXN | DB_INIT_LOG | DB_INIT_LOCK): 0);
r = dbenv->open(dbdir, flags, 0644);
assert(r == 0);
}
db = new Db(dbenv, DB_CXX_NO_EXCEPTIONS); assert(db);
if (do_transactions) {
r=dbenv->txn_begin(0, &tid, 0); assert(r==0);
}
if (pagesize) {
r = db->set_pagesize(pagesize);
assert(r == 0);
}
r = db->open(tid, dbfilename, NULL, DB_BTREE, DB_CREATE, 0644);
assert(r == 0);
if (do_transactions) {
r=tid->commit(0); assert(r==0);
}
}
void shutdown (void) {
int r;
r = db->close(0);
assert(r == 0);
delete db;
r = dbenv->close(0);
assert(r == 0);
delete dbenv;
}
void long_long_to_array (unsigned char *a, unsigned long long l) {
int i;
for (i=0; i<8; i++)
a[i] = (l>>(56-8*i))&0xff;
}
DBT *toku_fill_dbt(DBT *dbt, const void *data, int size) {
memset(dbt, 0, sizeof *dbt);
dbt->size = size;
dbt->data = (void *) data;
return dbt;
}
void insert (long long v) {
unsigned char kc[keysize], vc[valsize];
Dbt kt(kc, keysize), vt(vc, valsize);
memset(kc, 0, sizeof kc);
long_long_to_array(kc, v);
memset(vc, 0, sizeof vc);
long_long_to_array(vc, v);
int r = db->put(tid, &kt, &vt, 0);
CKERR(r);
if (do_transactions) {
if (n_insertions_since_txn_began>=ITEMS_PER_TRANSACTION) {
n_insertions_since_txn_began=0;
r = tid->commit(0); assert(r==0);
r=dbenv->txn_begin(0, &tid, 0); assert(r==0);
n_insertions_since_txn_began=0;
}
n_insertions_since_txn_began++;
}
}
void serial_insert_from (long long from) {
long long i;
if (do_transactions) {
int r = dbenv->txn_begin(0, &tid, 0); assert(r==0);
#if 0
{
DBT k,v;
r=db->put(db, tid, toku_fill_dbt(&k, "a", 1), toku_fill_dbt(&v, "b", 1), 0);
CKERR(r);
}
#endif
}
for (i=0; i<ITEMS_TO_INSERT_PER_ITERATION; i++) {
insert((from+i)*SERIAL_SPACING);
}
if (do_transactions) {
int r= tid->commit(0); assert(r==0);
tid=0;
}
}
long long llrandom (void) {
return (((long long)(random()))<<32) + random();
}
void random_insert_below (long long below) {
long long i;
if (do_transactions) {
int r = dbenv->txn_begin(0, &tid, 0); assert(r==0);
}
for (i=0; i<ITEMS_TO_INSERT_PER_ITERATION; i++) {
insert(llrandom()%below);
}
if (do_transactions) {
int r= tid->commit(0); assert(r==0);
tid=0;
}
}
double tdiff (struct timeval *a, struct timeval *b) {
return (a->tv_sec-b->tv_sec)+1e-6*(a->tv_usec-b->tv_usec);
}
void biginsert (long long n_elements, struct timeval *starttime) {
long long i;
struct timeval t1,t2;
int iteration;
for (i=0, iteration=0; i<n_elements; i+=ITEMS_TO_INSERT_PER_ITERATION, iteration++) {
gettimeofday(&t1,0);
serial_insert_from(i);
gettimeofday(&t2,0);
if (verbose) printf("serial %9.6fs %8.0f/s ", tdiff(&t2, &t1), ITEMS_TO_INSERT_PER_ITERATION/tdiff(&t2, &t1));
fflush(stdout);
gettimeofday(&t1,0);
random_insert_below((i+ITEMS_TO_INSERT_PER_ITERATION)*SERIAL_SPACING);
gettimeofday(&t2,0);
if (verbose) {
printf("random %9.6fs %8.0f/s ", tdiff(&t2, &t1), ITEMS_TO_INSERT_PER_ITERATION/tdiff(&t2, &t1));
printf("cumulative %9.6fs %8.0f/s\n", tdiff(&t2, starttime), (ITEMS_TO_INSERT_PER_ITERATION*2.0/tdiff(&t2, starttime))*(iteration+1));
}
}
}
const long long default_n_items = 1LL<<22;
void print_usage (const char *argv0) {
fprintf(stderr, "Usage:\n");
fprintf(stderr, " %s [-x] [--keysize KEYSIZE] [--valsize VALSIZE] [ n_iterations ]\n", argv0);
fprintf(stderr, " where\n");
fprintf(stderr, " -x do transactions (one transaction per iteration) (default: no transactions at all)\n");
fprintf(stderr, " --keysize KEYSIZE sets the key size (default 8)\n");
fprintf(stderr, " --valsize VALSIZE sets the value size (default 8)\n");
fprintf(stderr, " --cachesize CACHESIZE set the database cache size\n");
fprintf(stderr, " --pagesize PAGESIZE sets the database page size\n");
fprintf(stderr, " n_iterations how many iterations (default %lld iterations of %d items per iteration)\n", default_n_items/ITEMS_TO_INSERT_PER_ITERATION, ITEMS_TO_INSERT_PER_ITERATION);
}
int main (int argc, const char *argv[]) {
struct timeval t1,t2,t3;
long long total_n_items = default_n_items;
int i;
for (i=1; i<argc; i++) {
const char *arg = argv[i];
if (arg[0] != '-')
break;
if (strcmp(arg, "-q") == 0) {
verbose--;
if (verbose<0) verbose=0;
continue;
}
if (strcmp(arg, "-x") == 0) {
do_transactions = 1;
continue;
}
if (strcmp(arg, "--cachesize") == 0) {
if (i+1 < argc) {
i++;
cachesize = strtoll(argv[i], 0, 10);
}
continue;
}
if (strcmp(arg, "--keysize") == 0) {
if (i+1 < argc) {
i++;
keysize = atoi(argv[i]);
}
continue;
}
if (strcmp(arg, "--valsize") == 0) {
if (i+1 < argc) {
i++;
valsize = atoi(argv[i]);
}
continue;
}
if (strcmp(arg, "--pagesize") == 0) {
if (i+1 < argc) {
i++;
pagesize = atoi(argv[i]);
}
continue;
}
print_usage(argv[0]);
return 1;
}
if (i<argc) {
/* if it looks like a number */
char *end;
errno=0;
long n_iterations = strtol(argv[i], &end, 10);
if (errno!=0 || *end!=0 || end==argv[i]) {
print_usage(argv[0]);
return 1;
}
total_n_items = ITEMS_TO_INSERT_PER_ITERATION * (long long)n_iterations;
}
if (verbose) printf("Serial and random insertions of %d per batch%s\n", ITEMS_TO_INSERT_PER_ITERATION, do_transactions ? " (with transactions)" : "");
setup();
gettimeofday(&t1,0);
biginsert(total_n_items, &t1);
gettimeofday(&t2,0);
shutdown();
gettimeofday(&t3,0);
if (verbose) {
printf("Shutdown %9.6fs\n", tdiff(&t3, &t2));
printf("Total time %9.6fs for %lld insertions = %8.0f/s\n", tdiff(&t3, &t1), 2*total_n_items, 2*total_n_items/tdiff(&t3, &t1));
}
return 0;
}
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS _GNU_SOURCE DONT_DEPRECATE_ERRNO)
set(both_bins
db-benchmark-test
scanscan
ptquery
txncommit
)
set(tokudbonly_bins
scanrace
multi-bench
db-verify
)
if(BDB_FOUND)
foreach(bdb_bin ${both_bins})
add_executable(${bdb_bin}-bdb ${bdb_bin})
set_property(TARGET ${bdb_bin}-bdb APPEND PROPERTY
COMPILE_DEFINITIONS "DIRSUF=bdb;TOKU_ALLOW_DEPRECATED;ENVDIR=\"${bdb_bin}.cc.bdb\"")
set_target_properties(${bdb_bin}-bdb PROPERTIES
INCLUDE_DIRECTORIES "${BDB_INCLUDE_DIR};${CMAKE_CURRENT_BINARY_DIR}/../toku_include;${CMAKE_CURRENT_SOURCE_DIR}/../toku_include;${CMAKE_CURRENT_SOURCE_DIR}/../portability;${CMAKE_CURRENT_SOURCE_DIR}/..")
target_link_libraries(${bdb_bin}-bdb ${LIBTOKUPORTABILITY} ${BDB_LIBRARIES})
add_space_separated_property(TARGET ${bdb_bin}-bdb COMPILE_FLAGS -fvisibility=hidden)
endforeach(bdb_bin)
endif()
foreach(tokudb_bin ${both_bins} ${tokudbonly_bins})
add_executable(${tokudb_bin}-tokudb ${tokudb_bin})
set_property(TARGET ${tokudb_bin}-tokudb APPEND PROPERTY
COMPILE_DEFINITIONS "TOKUDB;ENVDIR=\"${tokudb_bin}.cc.tdb\"")
target_link_libraries(${tokudb_bin}-tokudb ${LIBTOKUDB} ${LIBTOKUPORTABILITY})
add_space_separated_property(TARGET ${tokudb_bin}-tokudb COMPILE_FLAGS -fvisibility=hidden)
endforeach(tokudb_bin)
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "$Id$"
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved."
/* Insert a bunch of stuff */
#include <toku_portability.h>
#include "tokudb_common_funcs.h"
#include <toku_time.h>
#include <toku_assert.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#if defined(HAVE_MALLOC_H)
# include <malloc.h>
#elif defined(HAVE_SYS_MALLOC_H)
# include <sys/malloc.h>
#endif
#include <dlfcn.h>
#if !defined(DB_PRELOCKED_WRITE)
#define NO_DB_PRELOCKED
#define DB_PRELOCKED_WRITE 0
#endif
int verbose=1;
int engine_status = 0;
int which;
enum { SERIAL_SPACING = 1<<6 };
enum { DEFAULT_ITEMS_TO_INSERT_PER_ITERATION = 1<<20 };
enum { DEFAULT_ITEMS_PER_TRANSACTION = 1<<14 };
#define DEFAULT_N_ITEMS (1LL<<22)
#define DEFAULT_N_ITERATIONS (DEFAULT_N_ITEMS/DEFAULT_ITEMS_TO_INSERT_PER_ITERATION)
static void insert (long long v);
#define CKERR(r) ({ int __r = r; if (__r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, __r, db_strerror(r)); assert(__r==0); })
#define CKERR2(r,rexpect) do { if (r!=rexpect) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, db_strerror(r)); assert(r==rexpect); } while (0)
/* default test parameters */
int keysize = sizeof (long long);
int valsize = sizeof (long long);
int pagesize = 0;
long long cachesize = 128*1024*1024;
int do_1514_point_query = 0;
int dupflags = 0;
int insert_multiple = 0;
int num_dbs = 1;
int cleaner_period = 0;
int cleaner_iterations = 0;
int noserial = 0; // Don't do the serial stuff
int norandom = 0; // Don't do the random stuff
int prelock = 0;
int prelockflag = 0;
int items_per_transaction = DEFAULT_ITEMS_PER_TRANSACTION;
int items_per_iteration = DEFAULT_ITEMS_TO_INSERT_PER_ITERATION;
int finish_child_first = 0; // Commit or abort child first (before doing so to the parent). No effect if child does not exist.
int singlex_child = 0; // Do a single transaction, but do all work with a child
int singlex = 0; // Do a single transaction
int singlex_create = 0; // Create the db using the single transaction (only valid if singlex)
int insert1first = 0; // insert 1 before doing the rest
int check_small_rollback = 0; // verify that the rollback logs are small (only valid if singlex)
int do_transactions = 0;
int if_transactions_do_logging = DB_INIT_LOG; // set this to zero if we want no logging when transactions are used
int do_abort = 0;
int n_insertions_since_txn_began=0;
int env_open_flags = DB_CREATE|DB_PRIVATE|DB_INIT_MPOOL;
uint32_t put_flags = 0;
double compressibility = -1; // -1 means make it very compressible. 1 means use random bits everywhere. 2 means half the bits are random.
int do_append = 0;
int do_checkpoint_period = 0;
uint32_t checkpoint_period = 0;
static const char *log_dir = NULL;
static int commitflags = 0;
static int redzone = 0;
static int redzone_set = 0;
static int do_optimize = 0;
static int unique_checks = 0;
static long long n_iterations = DEFAULT_N_ITERATIONS;
static int use_random = 0;
enum { MAX_RANDOM_C = 16000057 }; // prime-numbers.org
static unsigned char random_c[MAX_RANDOM_C];
static int next_random_c;
static void init_random_c(void) {
int i;
for (i=0; i<MAX_RANDOM_C; i++)
random_c[i] = (unsigned char) random();
}
static void update_random_c_index(int n) {
next_random_c += n;
if (next_random_c >= MAX_RANDOM_C)
next_random_c = 0;
}
static unsigned char get_random_c(void) {
update_random_c_index(1);
return random_c[next_random_c];
}
static int min_int(int a, int b) {
return a > b ? b : a;
}
static void copy_random_c(unsigned char *p, int n) {
while (n > 0) {
int m = min_int(n, MAX_RANDOM_C-next_random_c);
memcpy(p, &random_c[next_random_c], m);
n -= m;
p += m;
update_random_c_index(m);
}
}
static void do_prelock(DB* db, DB_TXN* txn) {
if (prelock) {
#if !defined(NO_DB_PRELOCKED)
int r = db->pre_acquire_table_lock(db, txn);
assert(r==0);
#else
(void) db; (void) txn;
#endif
}
}
#define STRINGIFY2(s) #s
#define STRINGIFY(s) STRINGIFY2(s)
const char *dbdir = "./bench." STRINGIFY(DIRSUF); /* DIRSUF is passed in as a -D argument to the compiler. */
const char *dbfilename = "bench.db";
char *dbname;
DB_ENV *dbenv;
enum {MAX_DBS=128};
DB *dbs[MAX_DBS];
uint32_t put_flagss[MAX_DBS];
DB_TXN *parenttid=0;
DB_TXN *tid=0;
DBT dest_keys[MAX_DBS];
DBT dest_vals[MAX_DBS];
#if defined(TOKUDB)
static int
put_multiple_generate(DB *dest_db, DB *src_db, DBT *dest_key, DBT *dest_val, const DBT *src_key, const DBT *src_val) {
assert(src_db == NULL);
assert(dest_db != NULL);
dest_key->data = src_key->data;
dest_key->size = src_key->size;
dest_val->data = src_val->data;
dest_val->size = src_val->size;
return 0;
}
#endif
static void benchmark_setup (void) {
int r;
if (!do_append) {
char unlink_cmd[strlen(dbdir) + strlen("rm -rf ") + 1];
snprintf(unlink_cmd, sizeof(unlink_cmd), "rm -rf %s", dbdir);
//printf("unlink_cmd=%s\n", unlink_cmd);
r = system(unlink_cmd);
CKERR(r);
if (strcmp(dbdir, ".") != 0) {
r = toku_os_mkdir(dbdir,S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);
assert(r == 0);
}
}
r = db_env_create(&dbenv, 0);
if (r!=0) fprintf(stderr, "Error on db_env_create: %s\n", db_strerror(r));
assert(r == 0);
#if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR <= 4
if (dbenv->set_lk_max) {
r = dbenv->set_lk_max(dbenv, items_per_transaction*2);
assert(r==0);
}
#endif
#ifndef TOKUDB
if (dbenv->set_lk_max_locks) {
r = dbenv->set_lk_max_locks(dbenv, items_per_transaction*2);
assert(r == 0);
}
#endif
if (dbenv->set_cachesize) {
r = dbenv->set_cachesize(dbenv, cachesize / (1024*1024*1024), cachesize % (1024*1024*1024), 1);
if (r != 0)
printf("WARNING: set_cachesize %d\n", r);
}
if (log_dir) {
r = dbenv->set_lg_dir(dbenv, log_dir);
assert(r == 0);
}
#if defined(TOKUDB)
if (insert_multiple) {
r = dbenv->set_generate_row_callback_for_put(dbenv, put_multiple_generate);
CKERR(r);
}
#endif
#if defined(TOKUDB)
if (redzone_set) {
r = dbenv->set_redzone(dbenv, redzone);
assert(r == 0);
}
#endif
r = dbenv->open(dbenv, dbdir, env_open_flags, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
assert(r == 0);
#if defined(TOKUDB)
if (do_checkpoint_period) {
r = dbenv->checkpointing_set_period(dbenv, checkpoint_period);
assert(r == 0);
uint32_t period;
r = dbenv->checkpointing_get_period(dbenv, &period);
assert(r == 0 && period == checkpoint_period);
}
#endif
#if defined(TOKUDB)
if (cleaner_period) {
r = dbenv->cleaner_set_period(dbenv, cleaner_period);
assert(r == 0);
uint32_t period;
r = dbenv->cleaner_get_period(dbenv, &period);
assert(r == 0 && period == (uint32_t)cleaner_period);
}
if (cleaner_iterations) {
r = dbenv->cleaner_set_iterations(dbenv, cleaner_iterations);
assert(r == 0);
uint32_t iterations;
r = dbenv->cleaner_get_iterations(dbenv, &iterations);
assert(r == 0 && iterations == (uint32_t)cleaner_iterations);
}
#endif
for (which = 0; which < num_dbs; which++) {
r = db_create(&dbs[which], dbenv, 0);
assert(r == 0);
}
if (do_transactions) {
r=dbenv->txn_begin(dbenv, 0, &tid, 0); CKERR(r);
}
for (which = 0; which < num_dbs; which++) {
DB *db = dbs[which];
if (pagesize && db->set_pagesize) {
r = db->set_pagesize(db, pagesize);
assert(r == 0);
}
if (dupflags) {
r = db->set_flags(db, dupflags);
assert(r == 0);
}
char name[strlen(dbfilename)+10];
if (which==0)
sprintf(name, "%s", dbfilename);
else
sprintf(name, "%s_%d", dbfilename, which);
r = db->open(db, tid, name, NULL, DB_BTREE, DB_CREATE, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
if (r!=0) fprintf(stderr, "errno=%d, %s\n", errno, strerror(errno));
assert(r == 0);
}
if (insert1first) {
if (do_transactions) {
r=tid->commit(tid, 0);
assert(r==0);
tid = NULL;
r=dbenv->txn_begin(dbenv, 0, &tid, 0); CKERR(r);
}
insert(-1);
if (singlex) {
r=tid->commit(tid, 0);
assert(r==0);
tid = NULL;
r=dbenv->txn_begin(dbenv, 0, &tid, 0); CKERR(r);
}
}
else if (singlex && !singlex_create) {
r=tid->commit(tid, 0);
assert(r==0);
tid = NULL;
r=dbenv->txn_begin(dbenv, 0, &tid, 0); CKERR(r);
}
if (do_transactions) {
if (singlex) {
for (which = 0; which < num_dbs; which++) {
DB *db = dbs[which];
do_prelock(db, tid);
}
}
else {
r=tid->commit(tid, 0);
assert(r==0);
tid = NULL;
}
}
if (singlex_child) {
parenttid = tid;
tid = NULL;
r=dbenv->txn_begin(dbenv, parenttid, &tid, 0); CKERR(r);
}
}
#if defined(TOKUDB)
static void test1514(void);
#endif
static void benchmark_shutdown (void) {
int r;
#if defined(TOKUDB)
if (do_1514_point_query) test1514();
#endif
if (do_transactions && singlex && !insert1first && (singlex_create || prelock)) {
#if defined(TOKUDB)
//There should be a single 'truncate' in the rollback instead of many 'insert' entries.
struct txn_stat *s;
r = tid->txn_stat(tid, &s);
assert(r==0);
//TODO: #1125 Always do the test after performance testing is done.
if (singlex_child) fprintf(stderr, "SKIPPED 'small rollback' test for child txn\n");
else
assert(s->rollback_raw_count < 100); // gross test, not worth investigating details
toku_free(s);
//system("ls -l bench.tokudb");
#endif
}
if (do_transactions && singlex) {
if (!singlex_child || finish_child_first) {
assert(tid);
r = (do_abort ? tid->abort(tid) : tid->commit(tid, 0)); assert(r==0);
tid = NULL;
}
if (singlex_child) {
tid = NULL;
assert(parenttid);
r = (do_abort ? parenttid->abort(parenttid) : parenttid->commit(parenttid, 0)); assert(r==0);
parenttid = NULL;
}
else
assert(!parenttid);
}
assert(!tid);
assert(!parenttid);
for (which = 0; which < num_dbs; which++) {
DB *db = dbs[which];
if (do_optimize) {
#if defined(TOKUDB)
r = db->optimize(db);
assert(r == 0);
#endif
}
r = db->close(db, 0);
assert(r == 0);
}
if (engine_status) {
print_engine_status(dbenv);
typedef void (*malloc_stats_fun_t)(void);
malloc_stats_fun_t malloc_stats_f = (malloc_stats_fun_t) dlsym(RTLD_DEFAULT, "malloc_stats");
if (malloc_stats_f) {
malloc_stats_f();
}
}
r = dbenv->close(dbenv, 0);
assert(r == 0);
}
static void long_long_to_array (unsigned char *a, int array_size, unsigned long long l) {
int i;
for (i=0; i<8 && i<array_size; i++)
a[i] = (l>>(56-8*i))&0xff;
}
static DBT *fill_dbt(DBT *dbt, const void *data, int size) {
memset(dbt, 0, sizeof *dbt);
dbt->size = size;
dbt->data = (void *) data;
return dbt;
}
// Fill array with 0's if compressibilty==-1, otherwise fill array with data that is likely to compress by a factor of compressibility.
static void fill_array (unsigned char *data, int size) {
memset(data, 0, size);
if (compressibility>0) {
if (use_random) {
int i;
for (i=0; i<size/compressibility; i++) {
data[i] = (unsigned char) random();
}
} else {
copy_random_c(data, size/compressibility);
}
}
}
static void insert (long long v) {
int r;
unsigned char *XMALLOC_N(keysize, kc);
unsigned char *XMALLOC_N(valsize, vc);
DBT kt, vt;
fill_array(kc, keysize);
long_long_to_array(kc, keysize, v); // Fill in the array first, then write the long long in.
fill_array(vc, valsize);
long_long_to_array(vc, valsize, v);
fill_dbt(&kt, kc, keysize);
fill_dbt(&vt, vc, valsize);
if (insert_multiple) {
#if defined(TOKUDB)
r = dbenv->put_multiple(dbenv, NULL, tid, &kt, &vt, num_dbs, dbs, dest_keys, dest_vals, put_flagss);
#else
r = EINVAL;
#endif
if (unique_checks)
assert(r == 0 || r == DB_KEYEXIST);
else
CKERR(r);
}
else {
for (which = 0; which < num_dbs; which++) {
DB *db = dbs[which];
r = db->put(db, tid, &kt, &vt, put_flags);
if (unique_checks)
assert(r == 0 || r == DB_KEYEXIST);
else
CKERR(r);
}
}
if (do_transactions) {
if (n_insertions_since_txn_began>=items_per_transaction && !singlex) {
n_insertions_since_txn_began=0;
r = tid->commit(tid, commitflags); assert(r==0);
tid = NULL;
r=dbenv->txn_begin(dbenv, 0, &tid, 0); assert(r==0);
for (which = 0; which < num_dbs; which++) {
DB *db = dbs[which];
do_prelock(db, tid);
}
n_insertions_since_txn_began=0;
}
n_insertions_since_txn_began++;
}
toku_free(kc);
toku_free(vc);
}
static void serial_insert_from (long long from) {
long long i;
if (do_transactions && !singlex) {
int r = dbenv->txn_begin(dbenv, 0, &tid, 0); assert(r==0);
for (which = 0; which < num_dbs; which++) {
DB *db = dbs[which];
do_prelock(db, tid);
}
}
for (i=0; i<items_per_iteration; i++) {
insert((from+i)*SERIAL_SPACING);
}
if (do_transactions && !singlex) {
int r= tid->commit(tid, 0); assert(r==0);
tid=NULL;
}
}
static long long llrandom (void) {
return (((long long)(random()))<<32) + random();
}
static void random_insert_below (long long below) {
long long i;
if (do_transactions && !singlex) {
int r = dbenv->txn_begin(dbenv, 0, &tid, 0); assert(r==0);
for (which = 0; which < num_dbs; which++) {
DB *db = dbs[which];
do_prelock(db, tid);
}
}
for (i=0; i<items_per_iteration; i++) {
insert(llrandom()%below);
}
if (do_transactions && !singlex) {
int r= tid->commit(tid, 0); assert(r==0);
tid=NULL;
}
}
static void biginsert (long long n_elements, struct timeval *starttime) {
long long i;
struct timeval t1,t2;
int iteration;
for (i=0, iteration=0; i<n_elements; i+=items_per_iteration, iteration++) {
if (verbose) printf("%3d ", iteration);
if (!noserial) {
gettimeofday(&t1,0);
serial_insert_from(i);
gettimeofday(&t2,0);
if (verbose) printf("serial %9.6fs %8.0f/s ", toku_tdiff(&t2, &t1), items_per_iteration/toku_tdiff(&t2, &t1));
fflush(stdout);
}
if (!norandom) {
gettimeofday(&t1,0);
random_insert_below((i+items_per_iteration)*SERIAL_SPACING);
gettimeofday(&t2,0);
if (verbose) printf("random %9.6fs %8.0f/s ", toku_tdiff(&t2, &t1), items_per_iteration/toku_tdiff(&t2, &t1));
}
if (verbose) printf("cumulative %10.6fs %8.0f/s\n", toku_tdiff(&t2, starttime), (((float)items_per_iteration*(!noserial+!norandom))/toku_tdiff(&t2, starttime))*(iteration+1));
}
}
static int print_usage (const char *argv0) {
fprintf(stderr, "Usage:\n");
fprintf(stderr, " %s [-x] [--keysize KEYSIZE] [--valsize VALSIZE] [--noserial] [--norandom] [ n_iterations ]\n", argv0);
fprintf(stderr, " where\n");
fprintf(stderr, " -x do transactions (XCOUNT transactions per iteration) (default: no transactions at all)\n");
fprintf(stderr, " --keysize KEYSIZE sets the key size (default 8)\n");
fprintf(stderr, " --valsize VALSIZE sets the value size (default 8)\n");
fprintf(stderr, " --cachesize CACHESIZE set the database cache size\n");
fprintf(stderr, " --pagesize PAGESIZE sets the database page size\n");
fprintf(stderr, " --noserial causes the serial insertions to be skipped\n");
fprintf(stderr, " --norandom causes the random insertions to be skipped\n");
fprintf(stderr, " --compressibility C creates data that should compress by about a factor C. Default C is large. C is an float.\n");
fprintf(stderr, " --xcount N how many insertions per transaction (default=%d)\n", DEFAULT_ITEMS_PER_TRANSACTION);
fprintf(stderr, " --nosync commit with nosync\n");
fprintf(stderr, " --singlex (implies -x) Run the whole job as a single transaction. (Default don't run as a single transaction.)\n");
fprintf(stderr, " --singlex-child (implies -x) Run the whole job as a single transaction, do all work a child of that transaction.\n");
fprintf(stderr, " --finish-child-first Commit/abort child before doing so to parent (no effect if no child).\n");
fprintf(stderr, " --singlex-create (implies --singlex) Create the file using the single transaction (Default is to use a different transaction to create.)\n");
fprintf(stderr, " --check_small_rollback (Only valid in --singlex mode) Verify that very little data was saved in the rollback logs.\n");
fprintf(stderr, " --prelock Prelock the database.\n");
fprintf(stderr, " --prelockflag Prelock the database and send the DB_PRELOCKED_WRITE flag.\n");
fprintf(stderr, " --abort Abort the singlex after the transaction is over. (Requires --singlex.)\n");
fprintf(stderr, " --nolog If transactions are used, then don't write the recovery log\n");
fprintf(stderr, " --log_dir LOGDIR Put the logs in LOGDIR\n");
fprintf(stderr, " --env DIR\n");
fprintf(stderr, " --periter N how many insertions per iteration (default=%d)\n", DEFAULT_ITEMS_TO_INSERT_PER_ITERATION);
fprintf(stderr, " --1514 do a point query for something not there at end. See #1514. (Requires --norandom)\n");
fprintf(stderr, " --append append to an existing file\n");
fprintf(stderr, " --userandom use random()\n");
fprintf(stderr, " --checkpoint-period %" PRIu32 " checkpoint period\n", checkpoint_period);
fprintf(stderr, " --cleaner-period %" PRIu32 " cleaner period\n", cleaner_period);
fprintf(stderr, " --cleaner-iterations %" PRIu32 " cleaner iterations\n", cleaner_iterations);
fprintf(stderr, " --numdbs N Insert same items into N dbs (1 to %d)\n", MAX_DBS);
fprintf(stderr, " --insertmultiple Use DB_ENV->put_multiple api. Requires transactions.\n");
fprintf(stderr, " --redzone N redzone in percent\n");
fprintf(stderr, " --srandom N srandom(N)\n");
fprintf(stderr, " --engine_status print engine status at end of test \n");
fprintf(stderr, " n_iterations how many iterations (default %lld)\n", DEFAULT_N_ITERATIONS);
return 1;
}
#if defined(TOKUDB)
static int
nothing(DBT const* UU(key), DBT const* UU(val), void* UU(extra)) {
return 0;
}
static void
test1514(void) {
assert(norandom); //Otherwise we can't know the given element is missing.
unsigned char kc[keysize], vc[valsize];
DBT kt;
long long v = SERIAL_SPACING - 1;
fill_array(kc, sizeof kc);
long_long_to_array(kc, keysize, v); // Fill in the array first, then write the long long in.
fill_array(vc, sizeof vc);
long_long_to_array(vc, valsize, v);
int r;
DBC *c;
struct timeval t1,t2;
for (which = 0; which < num_dbs; which++) {
DB *db = dbs[which];
r = db->cursor(db, tid, &c, 0); CKERR(r);
gettimeofday(&t1,0);
r = c->c_getf_set(c, 0, fill_dbt(&kt, kc, keysize), nothing, NULL);
gettimeofday(&t2,0);
CKERR2(r, DB_NOTFOUND);
r = c->c_close(c); CKERR(r);
}
if (verbose) printf("(#1514) Single Point Query %9.6fs\n", toku_tdiff(&t2, &t1));
}
#endif
static int test_main (int argc, char *const argv[]) {
struct timeval t1,t2,t3;
long long total_n_items = DEFAULT_N_ITEMS;
char *endptr;
int i;
for (i=1; i<argc; i++) {
const char *arg = argv[i];
if (arg[0] != '-')
break;
if (strcmp(arg, "-q") == 0) {
verbose--; if (verbose<0) verbose=0;
} else if (strcmp(arg, "-x") == 0) {
do_transactions = 1;
} else if (strcmp(arg, "--noserial") == 0) {
noserial=1;
} else if (strcmp(arg, "--norandom") == 0) {
norandom=1;
} else if (strcmp(arg, "--insertmultiple") == 0) {
insert_multiple=1;
} else if (strcmp(arg, "--numdbs") == 0) {
num_dbs = atoi(argv[++i]);
if (num_dbs <= 0 || num_dbs > MAX_DBS) {
fprintf(stderr, "--numdbs needs between 1 and %d\n", MAX_DBS);
return print_usage(argv[0]);
}
} else if (strcmp(arg, "--cleaner-period") == 0) {
cleaner_period = atoi(argv[++i]);
if (cleaner_period < 0) {
fprintf(stderr, "--cleaner-period needs to be positive\n");
return print_usage(argv[0]);
}
} else if (strcmp(arg, "--cleaner-iterations") == 0) {
cleaner_iterations = atoi(argv[++i]);
if (cleaner_iterations < 0) {
fprintf(stderr, "--cleaner-iterations needs to be positive\n");
return print_usage(argv[0]);
}
} else if (strcmp(arg, "--compressibility") == 0) {
compressibility = atof(argv[++i]);
init_random_c(); (void) get_random_c();
} else if (strcmp(arg, "--nolog") == 0) {
if_transactions_do_logging = 0;
} else if (strcmp(arg, "--singlex-create") == 0) {
do_transactions = 1;
singlex = 1;
singlex_create = 1;
} else if (strcmp(arg, "--finish-child-first") == 0) {
finish_child_first = 1;
} else if (strcmp(arg, "--singlex-child") == 0) {
do_transactions = 1;
singlex = 1;
singlex_child = 1;
} else if (strcmp(arg, "--singlex") == 0) {
do_transactions = 1;
singlex = 1;
} else if (strcmp(arg, "--insert1first") == 0) {
insert1first = 1;
} else if (strcmp(arg, "--check_small_rollback") == 0) {
check_small_rollback = 1;
} else if (strcmp(arg, "--xcount") == 0) {
if (i+1 >= argc) return print_usage(argv[0]);
items_per_transaction = strtoll(argv[++i], &endptr, 10); assert(*endptr == 0);
} else if (strcmp(arg, "--abort") == 0) {
do_abort = 1;
} else if (strcmp(arg, "--periter") == 0) {
if (i+1 >= argc) return print_usage(argv[0]);
items_per_iteration = strtoll(argv[++i], &endptr, 10); assert(*endptr == 0);
} else if (strcmp(arg, "--cachesize") == 0) {
if (i+1 >= argc) return print_usage(argv[0]);
cachesize = strtoll(argv[++i], &endptr, 10); assert(*endptr == 0);
} else if (strcmp(arg, "--keysize") == 0) {
if (i+1 >= argc) return print_usage(argv[0]);
keysize = atoi(argv[++i]);
} else if (strcmp(arg, "--valsize") == 0) {
if (i+1 >= argc) return print_usage(argv[0]);
valsize = atoi(argv[++i]);
} else if (strcmp(arg, "--pagesize") == 0) {
if (i+1 >= argc) return print_usage(argv[0]);
pagesize = atoi(argv[++i]);
} else if (strcmp(arg, "--env") == 0) {
if (i+1 >= argc) return print_usage(argv[0]);
dbdir = argv[++i];
#if defined(TOKUDB)
} else if (strcmp(arg, "--1514") == 0) {
do_1514_point_query=1;
#endif
} else if (strcmp(arg, "--prelock") == 0) {
prelock=1;
} else if (strcmp(arg, "--prelockflag") == 0) {
prelock=1;
prelockflag=1;
} else if (strcmp(arg, "--srandom") == 0) {
if (i+1 >= argc) return print_usage(argv[0]);
srandom(atoi(argv[++i]));
} else if (strcmp(arg, "--append") == 0) {
do_append = 1;
} else if (strcmp(arg, "--checkpoint-period") == 0) {
if (i+1 >= argc) return print_usage(argv[9]);
do_checkpoint_period = 1;
checkpoint_period = (uint32_t) atoi(argv[++i]);
} else if (strcmp(arg, "--nosync") == 0) {
commitflags += DB_TXN_NOSYNC;
} else if (strcmp(arg, "--userandom") == 0) {
use_random = 1;
} else if (strcmp(arg, "--unique_checks") == 0) {
if (i+1 >= argc) return print_usage(argv[0]);
unique_checks = atoi(argv[++i]);
if (unique_checks)
put_flags = DB_NOOVERWRITE;
else
put_flags = 0;
} else if (strcmp(arg, "--log_dir") == 0) {
if (i+1 >= argc) return print_usage(argv[0]);
log_dir = argv[++i];
} else if (strcmp(arg, "--redzone") == 0) {
if (i+1 >= argc) return print_usage(argv[0]);
redzone_set = 1;
redzone = atoi(argv[++i]);
} else if (strcmp(arg, "--optimize") == 0) {
do_optimize = 1;
} else if (strcmp(arg, "--engine_status") == 0) {
engine_status = 1;
} else {
return print_usage(argv[0]);
}
}
if (do_transactions) {
env_open_flags |= DB_INIT_TXN | if_transactions_do_logging | DB_INIT_LOCK;
}
if (do_transactions && prelockflag) {
put_flags |= DB_PRELOCKED_WRITE;
}
if (i<argc) {
/* if it looks like a number */
char *end;
errno=0;
n_iterations = strtol(argv[i], &end, 10);
if (errno!=0 || *end!=0 || end==argv[i]) {
print_usage(argv[0]);
return 1;
}
total_n_items = items_per_iteration * n_iterations;
i++;
}
if (i<argc) {
fprintf(stderr, "Extra arguments?\n");
print_usage(argv[0]);
return 1;
}
if (verbose) {
if (!noserial) printf("serial ");
if (!noserial && !norandom) printf("and ");
if (!norandom) printf("random ");
printf("insertions of %d per batch%s\n", items_per_iteration, do_transactions ? " (with transactions)" : "");
}
#if !defined TOKUDB
if (insert_multiple) {
fprintf(stderr, "--insert_multiple only works on the TokuDB (not BDB)\n");
return print_usage(argv[0]);
}
if (check_small_rollback) {
fprintf(stderr, "--check_small_rollback only works on the TokuDB (not BDB)\n");
return print_usage(argv[0]);
}
#endif
if (insert_multiple) {
memset(dest_keys, 0, sizeof(dest_keys));
memset(dest_vals, 0, sizeof(dest_vals));
for (which = 0; which < num_dbs; which++) {
put_flagss[i] = put_flags;
}
}
if (check_small_rollback && !singlex) {
fprintf(stderr, "--check_small_rollback requires --singlex\n");
return print_usage(argv[0]);
}
if (!do_transactions && insert_multiple) {
fprintf(stderr, "--insert_multiple requires transactions\n");
return print_usage(argv[0]);
}
benchmark_setup();
gettimeofday(&t1,0);
biginsert(total_n_items, &t1);
gettimeofday(&t2,0);
benchmark_shutdown();
gettimeofday(&t3,0);
if (verbose) {
printf("Shutdown %9.6fs\n", toku_tdiff(&t3, &t2));
printf("Total time %9.6fs for %lld insertions = %8.0f/s\n", toku_tdiff(&t3, &t1),
(!noserial+!norandom)*total_n_items, (!noserial+!norandom)*total_n_items/toku_tdiff(&t3, &t1));
}
return 0;
}
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "$Id$"
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <stdio.h>
#include <string.h>
#include <db.h>
#include "tokudb_common_funcs.h"
#include <assert.h>
static int verbose = 0;
static int env_open_flags_yesx = DB_CREATE|DB_PRIVATE|DB_INIT_MPOOL|DB_INIT_TXN|DB_INIT_LOG|DB_INIT_LOCK;
static int env_open_flags_nox = DB_CREATE|DB_PRIVATE|DB_INIT_MPOOL;
int test_main(int argc, char * const argv[]) {
int r;
const char *envdir = "bench.tokudb";
const char *dbfilename = "bench.db";
bool do_txns = false;
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
verbose++;
continue;
}
if (strcmp(argv[i], "-q") == 0) {
if (verbose > 0)
verbose--;
continue;
}
if (strcmp(argv[i], "-x") == 0) {
do_txns = true;
continue;
}
}
DB_ENV *env = NULL;
r = db_env_create(&env, 0);
assert(r == 0);
r = env->open(env, envdir, do_txns ? env_open_flags_yesx : env_open_flags_nox, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
assert(r == 0);
DB *db = NULL;
r = db_create(&db, env, 0);
assert(r == 0);
r = db->open(db, NULL, dbfilename, NULL, DB_BTREE, DB_AUTO_COMMIT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
assert(r == 0);
if (verbose) {
DB_BTREE_STAT64 s;
r = db->stat64(db, NULL, &s); assert(r == 0);
printf("nkeys=%" PRIu64 " dsize=%" PRIu64 "\n", s.bt_nkeys, s.bt_dsize);
}
r = db->verify_with_progress(db, NULL, NULL, verbose > 0, false);
assert(r == 0);
r = db->close(db, 0);
assert(r == 0);
r = env->close(env, 0);
assert(r == 0);
return 0;
}
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "$Id$"
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include "toku_config.h"
#include <stdio.h>
#include <assert.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/stat.h>
#include <db.h>
#include <toku_byteswap.h>
static int verbose = 0;
static int commit_flag = 0;
static int do_verify = 0;
static int nthread = 1;
static int maxk = 1000000;
static int do_multidb = 0;
static int usage(const char *prog) {
fprintf(stderr, "%s: run multi client single row insertions\n", prog);
fprintf(stderr, "[--n %d]\n", maxk);
fprintf(stderr, "[--nthread %d]\n", nthread);
fprintf(stderr, "[--verify] (%d)\n", do_verify);
fprintf(stderr, "[--nosync] (%d)\n", commit_flag);
fprintf(stderr, "[--multidb] (%d)\n", do_multidb);
return 1;
}
struct keygen {
pthread_mutex_t lock;
uint64_t k;
uint64_t maxk;
};
static void keygen_init(struct keygen *key, uint64_t _maxk) {
pthread_mutex_init(&key->lock, NULL);
key->k = 0;
key->maxk = _maxk;
}
static void keygen_destroy(struct keygen *key) {
pthread_mutex_destroy(&key->lock);
}
static int keygen_next(struct keygen *key, uint64_t *k) {
int r;
pthread_mutex_lock(&key->lock);
if (key->k >= key->maxk)
r = 1;
else {
*k = key->k++;
r = 0;
}
pthread_mutex_unlock(&key->lock);
return r;
}
struct inserter_arg {
struct keygen *keygen;
DB_ENV *env;
DB *db;
};
static int inserter(struct keygen *keygen, DB_ENV *env, DB *db) {
if (verbose) printf("%p %p %p\n", keygen, env, db);
while (1) {
uint64_t k;
int r = keygen_next(keygen, &k);
if (r != 0)
break;
if (verbose) printf("%" PRIdPTR ": %" PRIu64 "\n", (intptr_t) pthread_self(), k);
DB_TXN *txn;
r = env->txn_begin(env, NULL, &txn, 0);
assert(r == 0);
uint64_t kk = bswap_64(k);
DBT key = { .data = &kk, .size = sizeof kk };
DBT val = { .data = &k, .size = sizeof k };
r = db->put(db, txn, &key, &val, 0);
assert(r == 0);
r = txn->commit(txn, commit_flag);
assert(r == 0);
}
return 0;
}
static void *inserter_wrap(void *arg) {
if (verbose) printf("%" PRIdPTR "\n", (intptr_t) pthread_self());
struct inserter_arg *inserter_arg = (struct inserter_arg *) arg;
int r = inserter(inserter_arg->keygen, inserter_arg->env, inserter_arg->db);
assert(r == 0);
return arg;
}
static int verify(DB_ENV *env, DB *db, uint64_t _maxk) {
int r;
DB_TXN *txn;
r = env->txn_begin(env, NULL, &txn, 0);
assert(r == 0);
DBC *cursor;
r = db->cursor(db, txn, &cursor, 0);
assert(r == 0);
DBT key; memset(&key, 0, sizeof key);
DBT val; memset(&val, 0, sizeof val);
uint64_t i;
for (i=0; 1; i++) {
r = cursor->c_get(cursor, &key, &val, DB_NEXT);
if (r != 0)
break;
uint64_t k, v;
assert(key.size == sizeof k);
assert(val.size == sizeof v);
memcpy(&k, key.data, key.size);
k = bswap_64(k);
assert(i == k);
memcpy(&v, val.data, val.size);
assert(v == i);
}
assert(i == _maxk);
r = cursor->c_close(cursor);
assert(r == 0);
r = txn->commit(txn, 0);
assert(r == 0);
return 0;
}
static int env_init(DB_ENV **envptr, const char *envdir) {
int r;
DB_ENV *env;
r = db_env_create(&env, 0);
if (r == 0) {
// env setup
// env open
r = env->open(env, envdir, DB_CREATE+DB_PRIVATE+DB_INIT_LOCK+DB_INIT_LOG+DB_INIT_MPOOL+DB_INIT_TXN, 0777);
}
if (r == 0)
*envptr = env;
return r;
}
static int db_init(DB_ENV *env, const char *dbname, DB **dbptr) {
int r;
DB *db;
r = db_create(&db, env, 0);
if (r == 0) {
// db create
r = db->open(db, NULL, dbname, NULL, DB_BTREE, DB_CREATE, 0777);
if (r != 0) {
r = db->close(db, 0);
assert(r == 0);
}
}
if (r == 0)
*dbptr = db;
return r;
}
int main(int argc, char *argv[]) {
int r;
for (int i = 1; i < argc; i++) {
char *arg = argv[i];
if (strcmp(arg, "--nthread") == 0 && i+1 < argc) {
nthread = atoi(argv[++i]);
continue;
}
if (strcmp(arg, "--n") == 0 && i+1 < argc) {
maxk = atoi(argv[++i]);
continue;
}
if (strcmp(arg, "--verbose") == 0) {
verbose++;
continue;
}
if (strcmp(arg, "--nosync") == 0) {
commit_flag = DB_TXN_NOSYNC;
continue;
}
if (strcmp(arg, "--verify") == 0) {
do_verify++;
continue;
}
if (strcmp(arg, "--multidb") == 0) {
do_multidb++;
continue;
}
return usage(argv[0]);
}
int ndb = 1;
int nkeygen = 1;
if (do_multidb) {
ndb = nthread;
nkeygen = nthread;
}
const char *envdir = ENVDIR;
r = system("rm -rf " ENVDIR);
assert(r == 0);
r = mkdir(envdir, 0777);
assert(r == 0);
struct keygen keygen[nkeygen];
for (int i = 0; i < nkeygen; i++)
keygen_init(&keygen[i], maxk);
DB_ENV *env;
r = env_init(&env, envdir);
assert(r == 0);
DB *db[ndb];
for (int i = 0 ; i < ndb; i++) {
char dbname[32]; sprintf(dbname, "db%d", i);
r = db_init(env, dbname, &db[i]);
assert(r == 0);
}
pthread_t tids[nthread];
struct inserter_arg args[nthread];
for (int i = 0; i < nthread; i++) {
struct inserter_arg this_arg = { .keygen = &keygen[i % nkeygen], .env = env, .db = db[i % ndb] };
args[i] = this_arg;
pthread_create(&tids[i], NULL, inserter_wrap, &args[i]);
}
for (int i = 0; i < nthread; i++) {
void *retptr;
pthread_join(tids[i], &retptr);
}
for (int i = 0; i < ndb; i++) {
if (do_verify)
verify(env, db[i], maxk);
r = db[i]->close(db[i], 0);
assert(r == 0);
}
r = env->close(env, 0);
assert(r == 0);
for (int i = 0; i < nkeygen; i++)
keygen_destroy(&keygen[i]);
return 0;
}
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "$Id$"
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <toku_portability.h>
#include "tokudb_common_funcs.h"
#include <toku_pthread.h>
#include <toku_assert.h>
#include <portability/toku_atomic.h>
#include <db.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
static DB_ENV *env = NULL;
static DB *db = NULL;
#define STRINGIFY2(s) #s
#define STRINGIFY(s) STRINGIFY2(s)
static const char *dbdir = "./bench." STRINGIFY(DIRSUF); /* DIRSUF is passed in as a -D argument to the compiler. */
static int env_open_flags_yesx = DB_CREATE|DB_PRIVATE|DB_INIT_MPOOL|DB_INIT_TXN|DB_INIT_LOG|DB_INIT_LOCK|DB_RECOVER|DB_THREAD;
// static int env_open_flags_nox = DB_CREATE|DB_PRIVATE|DB_INIT_MPOOL;
static const char *dbfilename = "bench.db";
static uint64_t cachesize = 127*1024*1024;
static int nqueries = 1000000;
static int nthreads = 1;
static const char *log_dir = NULL;
static long long set_count = 0;
static void pt_query_setup (void) {
int r;
r = db_env_create(&env, 0); assert(r==0);
r = env->set_cachesize(env, cachesize / (1<<30), cachesize % (1<<30), 1); assert(r==0);
if (log_dir) {
r = env->set_lg_dir(env, log_dir); assert(r==0);
}
r = env->open(env, dbdir, env_open_flags_yesx, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); assert(r==0);
r = db_create(&db, env, 0); assert(r==0);
r = db->open(db, NULL, dbfilename, NULL, DB_BTREE, DB_THREAD|DB_AUTO_COMMIT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); assert(r==0);
}
static void pt_query_shutdown (void) {
int r;
r = db->close(db, 0); assert(r==0);
r = env->close(env, 0); assert(r==0);
env = NULL;
}
static unsigned long long maxkey;
enum { SERIAL_SPACING = 1<<6 };
static const int keylen=8;
static double gettime (void) {
struct timeval tv;
int r = gettimeofday(&tv, 0);
assert(r==0);
return tv.tv_sec + 1e-6*tv.tv_usec;
}
/* From db-benchmark-test.c */
static void long_long_to_array (unsigned char *a, int array_size, unsigned long long l) {
for (int i=0; i<8 && i<array_size; i++)
a[i] = (l>>(56-8*i))&0xff;
}
static void array_to_long_long (unsigned long long *l, unsigned char *a, int array_size) {
*l = 0;
for(int i=0; i<8 && i<array_size; i++) {
unsigned long long tmp = a[i] & 0xff;
*l += tmp << (56-8*i);
}
}
#if TOKUDB
static int do_nothing (DBT const* UU(key), DBT const* UU(data), void* UU(extrav)) {
return TOKUDB_CURSOR_CONTINUE;
}
#endif
static void test_begin_commit(int _nqueries) {
int r;
unsigned long long k;
unsigned char kv[keylen];
for (int i = 0; i < _nqueries; i++) {
DB_TXN *txn = NULL;
r = env->txn_begin(env, NULL, &txn, DB_TXN_SNAPSHOT); assert_zero(r);
DBC *c = NULL;
r = db->cursor(db, txn, &c, 0); assert_zero(r);
k = (random() + (random() << 31)) % maxkey;
k = ( k / SERIAL_SPACING ) * SERIAL_SPACING;
long_long_to_array(kv, keylen, k);
DBT key = { .data = kv, .size = 8 };
DBT val = { .data = NULL, .size = 0 };
#if TOKUDB
r = c->c_getf_set(c, 0, &key, do_nothing, &val);
#else
r = c->c_get(c, &key, &val, DB_SET);
#endif
assert_zero(r);
(void) toku_sync_fetch_and_add(&set_count, 1);
r = c->c_close(c); assert_zero(r);
r = txn->commit(txn, 0); assert_zero(r);
}
}
// read in the entire DB, warming up the cache
// - record maxkey
static void warmup(void) {
int r;
DB_TXN *txn=NULL;
DBC *c = NULL;
DBT key = { .data = NULL };
DBT val = { .data = NULL };
double tstart = gettime();
r = env->txn_begin(env, NULL, &txn, 0); assert_zero(r);
r = db->cursor(db, txn, &c, 0); assert_zero(r);
r = c->c_get(c, &key, &val, DB_FIRST); assert_zero(r);
assert(key.size == 8);
while ( r != DB_NOTFOUND ) {
#if TOKUDB
r = c->c_getf_next(c, DB_PRELOCKED, do_nothing, NULL);
#else
r = c->c_get(c, &key, &val, DB_NEXT);
#endif
if ( r != 0 && r != DB_NOTFOUND) assert_zero(r);
}
memset(&key, 0, sizeof key);
memset(&val, 0, sizeof val);
r = c->c_get(c, &key, &val, DB_LAST); assert_zero(r);
array_to_long_long(&maxkey, (unsigned char*)key.data, key.size);
r = c->c_close(c); assert_zero(r);
r = txn->commit(txn, 0); assert_zero(r);
double tdiff = gettime() - tstart;
unsigned long long rows = maxkey / SERIAL_SPACING;
printf("Warmup : read %12llu rows in %6.1fs %8.0f/s\n", rows, tdiff, rows/tdiff); fflush(stdout);
}
struct arg {
// DB_ENV *env;
// DB *db;
int nqueries;
// int nrows;
};
static void *test_thread(void *arg) {
struct arg *myarg = (struct arg *) arg;
test_begin_commit(myarg->nqueries);
return arg;
}
static void usage(void) {
fprintf(stderr, "--nqueries %d\n", nqueries);
fprintf(stderr, "--nthreads %d\n", nthreads);
fprintf(stderr, "--cachesize %" PRId64 "\n", cachesize);
}
int test_main(int argc, char * const argv[]) {
for (int i = 1; i < argc; i++) {
char * const arg = argv[i];
if (strcmp(arg, "--nqueries") == 0 && i+1 < argc) {
nqueries = atoi(argv[++i]);
continue;
}
if (strcmp(arg, "--nthreads") == 0 && i+1 < argc) {
nthreads = atoi(argv[++i]);
continue;
}
if (strcmp(arg, "--cachesize") == 0 && i+1 < argc) {
cachesize = atoll(argv[++i]);
continue;
}
usage();
return 1;
}
int r;
pt_query_setup();
warmup();
assert(nthreads > 0);
struct arg myargs[nthreads-1];
toku_pthread_t mytids[nthreads];
double tstart = gettime();
for (int i = 0; i < nthreads-1; i++) {
myargs[i] = (struct arg) { nqueries };
r = toku_pthread_create(&mytids[i], NULL, test_thread, &myargs[i]); assert_zero(r);
}
test_begin_commit(nqueries);
for (int i = 0; i < nthreads-1; i++) {
void *ret;
r = toku_pthread_join(mytids[i], &ret); assert_zero(r);
}
assert(set_count == nthreads * nqueries);
double tdiff = gettime() - tstart;
printf("Point Queries : read %12llu rows in %6.1fs %8.0f/s with %d threads\n", set_count, tdiff, set_count/tdiff, nthreads); fflush(stdout);
pt_query_shutdown();
return 0;
}
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "$Id$"
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
/* Scan the bench.tokudb/bench.db over and over. */
#include <toku_portability.h>
#include "tokudb_common_funcs.h"
#include <toku_assert.h>
#include <db.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#ifndef TOKUDB
#error requires tokudb
#endif
static const char *pname;
static long limitcount=-1;
static uint32_t cachesize = 16*1024*1024;
#define STRINGIFY2(s) #s
#define STRINGIFY(s) STRINGIFY2(s)
const char *dbdir = "./bench." STRINGIFY(DIRSUF); /* DIRSUF is passed in as a -D argument to the compiler. */
static void parse_args (int argc, char *const argv[]) {
pname=argv[0];
argc--;
argv++;
while (argc>0) {
if (strcmp(*argv, "--count")==0) {
char *end;
argv++; argc--;
errno=0; limitcount=strtol(*argv, &end, 10); assert(errno==0);
printf("Limiting count to %ld\n", limitcount);
} else if (strcmp(*argv, "--cachesize")==0 && argc>0) {
char *end;
argv++; argc--;
cachesize=(uint32_t)strtol(*argv, &end, 10);
} else if (strcmp(*argv, "--env") == 0) {
argv++; argc--;
if (argc <= 0) goto print_usage;
dbdir = *argv;
} else {
print_usage:
fprintf(stderr, "Usage:\n%s\n", pname);
fprintf(stderr, " --count <count> read the first COUNT rows and then stop.\n");
fprintf(stderr, " --cachesize <n> set the env cachesize to <n>\n");
fprintf(stderr, " --env DIR\n");
exit(1);
}
argc--;
argv++;
}
}
DB_ENV *env;
DB *db;
DB_TXN *tid=0;
static int env_open_flags_yesx = DB_CREATE|DB_PRIVATE|DB_INIT_MPOOL|DB_INIT_TXN|DB_INIT_LOG|DB_INIT_LOCK;
const char *dbfilename = "bench.db";
static void scanrace_setup (void) {
int r;
r = db_env_create(&env, 0); assert(r==0);
r = env->set_cachesize(env, 0, cachesize, 1); assert(r==0);
r = env->open(env, dbdir, env_open_flags_yesx, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); assert(r==0);
r = db_create(&db, env, 0); assert(r==0);
r = env->txn_begin(env, 0, &tid, 0); assert(r==0);
r = db->open(db, tid, dbfilename, NULL, DB_BTREE, 0, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); assert(r==0);
assert(r==0);
}
static void scanrace_shutdown (void) {
int r;
r = db->close(db, 0); assert(r==0);
r = tid->commit(tid, 0); assert(r==0);
r = env->close(env, 0); assert(r==0);
}
static double gettime (void) {
struct timeval tv;
int r = gettimeofday(&tv, 0);
assert(r==0);
return tv.tv_sec + 1e-6*tv.tv_usec;
}
struct extra_count {
long long totalbytes;
int rowcounter;
};
static int
counttotalbytes (DBT const *key, DBT const *data, void *extrav) {
struct extra_count *CAST_FROM_VOIDP(e, extrav);
e->totalbytes += key->size + data->size;
e->rowcounter++;
return 0;
}
static void scanrace_lwc (void) {
int r;
struct extra_count e = {0,0};
double prevtime = gettime();
DBC *dbc;
r = db->cursor(db, tid, &dbc, 0); assert(r==0);
r = dbc->c_pre_acquire_range_lock(dbc, db->dbt_neg_infty(), db->dbt_pos_infty());
assert(r==0);
long rowcounter=0;
while (0 == (r = dbc->c_getf_next(dbc, DB_PRELOCKED, counttotalbytes, &e))) {
//if (rowcounter%128==0) { printf("."); fflush(stdout); }
rowcounter++;
if (limitcount>0 && rowcounter>=limitcount) break;
}
r = dbc->c_close(dbc); assert(r==0);
double thistime = gettime();
double tdiff = thistime-prevtime;
printf("LWC Scan %lld bytes (%d rows) in %9.6fs at %9fMB/s\n", e.totalbytes, e.rowcounter, tdiff, 1e-6*e.totalbytes/tdiff);
}
static int test_main (int argc, char * const argv[]) {
parse_args(argc,argv);
scanrace_setup();
scanrace_lwc();
scanrace_shutdown();
#if defined __linux__ && __linux__
char fname[256];
sprintf(fname, "/proc/%d/status", toku_os_getpid());
FILE *f = fopen(fname, "r");
if (f) {
char line[256];
while (fgets(line, sizeof line, f)) {
int n;
if (sscanf(line, "VmPeak: %d", &n) || sscanf(line, "VmHWM: %d", &n) || sscanf(line, "VmRSS: %d", &n))
fputs(line, stdout);
}
fclose(f);
}
#endif
return 0;
}
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "$Id$"
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
/* Scan the bench.tokudb/bench.db over and over. */
#define DONT_DEPRECATE_MALLOC
#include <toku_portability.h>
#include "tokudb_common_funcs.h"
#include <toku_assert.h>
#include <db.h>
#include <errno.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#ifdef TOKUDB
#include <ft/key.h>
#include <ft/cachetable.h>
#endif
static const char *pname;
static enum run_mode { RUN_HWC, RUN_LWC, RUN_VERIFY, RUN_RANGE} run_mode = RUN_HWC;
static int do_txns=1, prelock=0, prelockflag=0;
static int cleaner_period=0, cleaner_iterations=0;
static uint32_t lock_flag = 0;
static long limitcount=-1;
static uint32_t cachesize = 127*1024*1024;
static uint64_t start_range = 0, end_range = 0;
static int n_experiments = 2;
static int bulk_fetch = 1;
static int verbose = 0;
static int engine_status = 0;
static const char *log_dir = NULL;
static int print_usage (const char *argv0) {
fprintf(stderr, "Usage:\n%s [--verify-lwc | --lwc | --nohwc] [--prelock] [--prelockflag] [--prelockwriteflag] [--env DIR] [--verbose]\n", argv0);
fprintf(stderr, " --verify-lwc means to run the light weight cursor and the heavyweight cursor to verify that they get the same answer.\n");
fprintf(stderr, " --lwc run light weight cursors instead of heavy weight cursors\n");
fprintf(stderr, " --prelock acquire a read lock on the entire table before running\n");
fprintf(stderr, " --prelockflag pass DB_PRELOCKED to the the cursor get operation whenever the locks have been acquired\n");
fprintf(stderr, " --prelockwriteflag pass DB_PRELOCKED_WRITE to the cursor get operation\n");
fprintf(stderr, " --nox no transactions (no locking)\n");
fprintf(stderr, " --count <count> read the first COUNT rows and then stop.\n");
fprintf(stderr, " --cachesize <n> set the env cachesize to <n>\n");
fprintf(stderr, " --cleaner-period <n> set the cleaner period to <n>\n");
fprintf(stderr, " --cleaner-iterations <n> set the cleaner iterations to <n>\n");
fprintf(stderr, " --env DIR put db files in DIR instead of default\n");
fprintf(stderr, " --log_dir LOGDIR put the logs in LOGDIR\n");
fprintf(stderr, " --range LOW HIGH set the LOW and HIGH key boundaries in which random range queries are made\n");
fprintf(stderr, " --experiments N run N experiments (default:%d)\n", n_experiments);
fprintf(stderr, " --srandom N srandom(N)\n");
fprintf(stderr, " --recover run recovery\n");
fprintf(stderr, " --verbose print verbose information\n");
fprintf(stderr, " --bulk_fetch 0|1 do bulk fetch on lwc operations (default: 1)\n");
fprintf(stderr, " --engine_status print engine status at end of test \n");
return 1;
}
static DB_ENV *env;
static DB *db;
static DB_TXN *tid = NULL;
#define STRINGIFY2(s) #s
#define STRINGIFY(s) STRINGIFY2(s)
static const char *dbdir = "./bench." STRINGIFY(DIRSUF); /* DIRSUF is passed in as a -D argument to the compiler. */
static int env_open_flags_yesx = DB_CREATE|DB_PRIVATE|DB_INIT_MPOOL|DB_INIT_TXN|DB_INIT_LOG|DB_INIT_LOCK;
static int env_open_flags_nox = DB_CREATE|DB_PRIVATE|DB_INIT_MPOOL;
static const char *dbfilename = "bench.db";
static double gettime (void) {
struct timeval tv;
int r = gettimeofday(&tv, 0);
assert(r==0);
return tv.tv_sec + 1e-6*tv.tv_usec;
}
static void parse_args (int argc, char *const argv[]) {
pname=argv[0];
argc--; argv++;
int specified_run_mode=0;
while (argc>0) {
if (strcmp(*argv,"--verbose")==0) {
verbose++;
} else if (strcmp(*argv,"--verify-lwc")==0) {
if (specified_run_mode && run_mode!=RUN_VERIFY) { two_modes: fprintf(stderr, "You specified two run modes\n"); exit(1); }
run_mode = RUN_VERIFY;
} else if (strcmp(*argv, "--lwc")==0) {
if (specified_run_mode && run_mode!=RUN_LWC) goto two_modes;
run_mode = RUN_LWC;
} else if (strcmp(*argv, "--hwc")==0) {
if (specified_run_mode && run_mode!=RUN_VERIFY) goto two_modes;
run_mode = RUN_HWC;
} else if (strcmp(*argv, "--prelock")==0) prelock=1;
#ifdef TOKUDB
else if (strcmp(*argv, "--prelockflag")==0) { prelockflag=1; lock_flag = DB_PRELOCKED; }
else if (strcmp(*argv, "--prelockwriteflag")==0) { prelockflag=1; lock_flag = DB_PRELOCKED_WRITE; }
#endif
else if (strcmp(*argv, "--nox")==0) { do_txns=0; }
else if (strcmp(*argv, "--count")==0) {
char *end;
argc--; argv++;
errno=0; limitcount=strtol(*argv, &end, 10); assert(errno==0);
printf("Limiting count to %ld\n", limitcount);
} else if (strcmp(*argv, "--cachesize")==0 && argc>0) {
char *end;
argc--; argv++;
cachesize=(uint32_t)strtol(*argv, &end, 10);
} else if (strcmp(*argv, "--cleaner-period")==0 && argc>0) {
char *end;
argc--; argv++;
cleaner_period=(uint32_t)strtol(*argv, &end, 10);
} else if (strcmp(*argv, "--cleaner-iterations")==0 && argc>0) {
char *end;
argc--; argv++;
cleaner_iterations=(uint32_t)strtol(*argv, &end, 10);
} else if (strcmp(*argv, "--env") == 0) {
argc--; argv++;
if (argc==0) exit(print_usage(pname));
dbdir = *argv;
} else if (strcmp(*argv, "--log_dir") == 0) {
argc--; argv++;
if (argc==0) exit(print_usage(pname));
log_dir = *argv;
} else if (strcmp(*argv, "--verbose") == 0) {
verbose = 1;
} else if (strcmp(*argv, "--range") == 0 && argc > 2) {
run_mode = RUN_RANGE;
argc--; argv++;
start_range = strtoll(*argv, NULL, 10);
argc--; argv++;
end_range = strtoll(*argv, NULL, 10);
} else if (strcmp(*argv, "--experiments") == 0 && argc > 1) {
argc--; argv++;
n_experiments = strtol(*argv, NULL, 10);
} else if (strcmp(*argv, "--srandom") == 0 && argc > 1) {
argc--; argv++;
srandom(atoi(*argv));
} else if (strcmp(*argv, "--recover") == 0) {
env_open_flags_yesx |= DB_RECOVER;
env_open_flags_nox |= DB_RECOVER;
} else if (strcmp(*argv, "--bulk_fetch") == 0 && argc > 1) {
argc--; argv++;
bulk_fetch = atoi(*argv);
} else if (strcmp(*argv, "--engine_status") == 0) {
engine_status = 1;
} else {
exit(print_usage(pname));
}
argc--; argv++;
}
//Prelocking is meaningless without transactions
if (do_txns==0) {
//prelockflag=0;
lock_flag=0;
//prelock=0;
}
}
static void scanscan_setup (void) {
int r;
r = db_env_create(&env, 0); assert(r==0);
r = env->set_cachesize(env, 0, cachesize, 1); assert(r==0);
if (log_dir) {
r = env->set_lg_dir(env, log_dir); assert(r==0);
}
double tstart = gettime();
r = env->open(env, dbdir, do_txns? env_open_flags_yesx : env_open_flags_nox, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); assert(r==0);
double tend = gettime();
if (verbose)
printf("env open %f seconds\n", tend-tstart);
#ifdef TOKUDB
if (cleaner_period) {
r = env->cleaner_set_period(env, cleaner_period); assert(r == 0);
}
if (cleaner_iterations) {
r = env->cleaner_set_iterations(env, cleaner_iterations); assert(r == 0);
}
#endif
r = db_create(&db, env, 0); assert(r==0);
if (do_txns) {
r = env->txn_begin(env, 0, &tid, 0); assert(r==0);
}
r = db->open(db, tid, dbfilename, NULL, DB_BTREE, 0, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); assert(r==0);
#ifdef TOKUDB
if (prelock) {
r = db->pre_acquire_table_lock(db,
tid);
assert(r==0);
}
#endif
}
static void scanscan_shutdown (void) {
int r;
r = db->close(db, 0); assert(r==0);
if (do_txns) {
r = tid->commit(tid, 0); assert(r==0);
}
if (verbose || engine_status)
print_engine_status(env);
r = env->close(env, 0); assert(r==0);
env = NULL;
}
static void scanscan_hwc (void) {
int r;
int counter=0;
for (counter=0; counter<n_experiments; counter++) {
long long totalbytes=0;
int rowcounter=0;
double prevtime = gettime();
DBT k,v;
DBC *dbc;
r = db->cursor(db, tid, &dbc, 0); assert(r==0);
memset(&k, 0, sizeof(k));
memset(&v, 0, sizeof(v));
uint32_t c_get_flags = DB_NEXT;
if (prelockflag && (counter || prelock)) {
c_get_flags |= lock_flag;
}
while (0 == (r = dbc->c_get(dbc, &k, &v, c_get_flags))) {
totalbytes += k.size + v.size;
rowcounter++;
if (limitcount>0 && rowcounter>=limitcount) break;
}
assert(r==DB_NOTFOUND); // complain about things like lock-not-found
r = dbc->c_close(dbc); assert(r==0);
double thistime = gettime();
double tdiff = thistime-prevtime;
printf("Scan %lld bytes (%d rows) in %9.6fs at %9fMB/s\n", totalbytes, rowcounter, tdiff, 1e-6*totalbytes/tdiff);
}
}
#ifdef TOKUDB
struct extra_count {
long long totalbytes;
int rowcounter;
};
static int counttotalbytes (DBT const *key, DBT const *data, void *extrav) {
struct extra_count *CAST_FROM_VOIDP(e, extrav);
e->totalbytes += key->size + data->size;
e->rowcounter++;
return bulk_fetch ? TOKUDB_CURSOR_CONTINUE : 0;
}
static void scanscan_lwc (void) {
int r;
int counter=0;
for (counter=0; counter<n_experiments; counter++) {
struct extra_count e = {0,0};
double prevtime = gettime();
DBC *dbc;
r = db->cursor(db, tid, &dbc, 0); assert(r==0);
if(prelock) {
r = dbc->c_pre_acquire_range_lock(dbc, db->dbt_neg_infty(), db->dbt_pos_infty()); assert(r==0);
}
uint32_t f_flags = 0;
if (prelockflag && (counter || prelock)) {
f_flags |= lock_flag;
}
long rowcounter=0;
while (0 == (r = dbc->c_getf_next(dbc, f_flags, counttotalbytes, &e))) {
rowcounter++;
if (limitcount>0 && rowcounter>=limitcount) break;
}
//assert(r==DB_NOTFOUND);
r = dbc->c_close(dbc); assert(r==0);
double thistime = gettime();
double tdiff = thistime-prevtime;
printf("LWC Scan %lld bytes (%d rows) in %9.6fs at %9fMB/s\n", e.totalbytes, e.rowcounter, tdiff, 1e-6*e.totalbytes/tdiff);
}
}
#endif
static void scanscan_range (void) {
int r;
double texperiments[n_experiments];
uint64_t k = 0;
char kv[8];
DBT key, val;
for (int counter = 0; counter < n_experiments; counter++) {
if (1) { //if ((counter&1) == 0) {
makekey:
// generate a random key in the key range
k = (start_range + (random() % (end_range - start_range))) * (1<<6);
for (int i = 0; i < 8; i++)
kv[i] = k >> (56-8*i);
}
memset(&key, 0, sizeof key); key.data = &kv, key.size = sizeof kv;
memset(&val, 0, sizeof val);
double tstart = gettime();
DBC *dbc;
r = db->cursor(db, tid, &dbc, 0); assert(r==0);
// set the cursor to the random key
r = dbc->c_get(dbc, &key, &val, DB_SET_RANGE+lock_flag);
if (r != 0) {
assert(r == DB_NOTFOUND);
//printf("%s:%d %" PRIu64 "\n", __FUNCTION__, __LINE__, k);
goto makekey;
}
#ifdef TOKUDB
// do the range scan
long rowcounter = 0;
struct extra_count e = {0,0};
while (limitcount > 0 && rowcounter < limitcount) {
r = dbc->c_getf_next(dbc, prelockflag ? lock_flag : 0, counttotalbytes, &e);
if (r != 0)
break;
rowcounter++;
}
#endif
r = dbc->c_close(dbc);
assert(r==0);
texperiments[counter] = gettime() - tstart;
printf("%" PRIu64 " %f\n", k, texperiments[counter]); fflush(stdout);
}
// print the times
double tsum = 0.0, tmin = 0.0, tmax = 0.0;
for (int counter = 0; counter < n_experiments; counter++) {
if (counter==0 || texperiments[counter] < tmin)
tmin = texperiments[counter];
if (counter==0 || texperiments[counter] > tmax)
tmax = texperiments[counter];
tsum += texperiments[counter];
}
printf("%f %f %f/%d = %f\n", tmin, tmax, tsum, n_experiments, tsum / n_experiments);
}
#ifdef TOKUDB
struct extra_verify {
long long totalbytes;
int rowcounter;
DBT k,v; // the k and v are gotten using the old cursor
};
static int
checkbytes (DBT const *key, DBT const *data, void *extrav) {
struct extra_verify *CAST_FROM_VOIDP(e, extrav);
e->totalbytes += key->size + data->size;
e->rowcounter++;
assert(e->k.size == key->size);
assert(e->v.size == data->size);
assert(memcmp(e->k.data, key->data, key->size)==0);
assert(memcmp(e->v.data, data->data, data->size)==0);
assert(e->k.data != key->data);
assert(e->v.data != data->data);
return 0;
}
static void scanscan_verify (void) {
int r;
int counter=0;
for (counter=0; counter<n_experiments; counter++) {
struct extra_verify v;
v.totalbytes=0;
v.rowcounter=0;
double prevtime = gettime();
DBC *dbc1, *dbc2;
r = db->cursor(db, tid, &dbc1, 0); assert(r==0);
r = db->cursor(db, tid, &dbc2, 0); assert(r==0);
memset(&v.k, 0, sizeof(v.k));
memset(&v.v, 0, sizeof(v.v));
uint32_t f_flags = 0;
uint32_t c_get_flags = DB_NEXT;
if (prelockflag && (counter || prelock)) {
f_flags |= lock_flag;
c_get_flags |= lock_flag;
}
while (1) {
int r1,r2;
r2 = dbc1->c_get(dbc1, &v.k, &v.v, c_get_flags);
r1 = dbc2->c_getf_next(dbc2, f_flags, checkbytes, &v);
assert(r1==r2);
if (r1) break;
}
r = dbc1->c_close(dbc1); assert(r==0);
r = dbc2->c_close(dbc2); assert(r==0);
double thistime = gettime();
double tdiff = thistime-prevtime;
printf("verify %lld bytes (%d rows) in %9.6fs at %9fMB/s\n", v.totalbytes, v.rowcounter, tdiff, 1e-6*v.totalbytes/tdiff);
}
}
#endif
static int test_main (int argc, char *const argv[]) {
parse_args(argc,argv);
scanscan_setup();
switch (run_mode) {
case RUN_HWC: scanscan_hwc(); break;
#ifdef TOKUDB
case RUN_LWC: scanscan_lwc(); break;
case RUN_VERIFY: scanscan_verify(); break;
#endif
case RUN_RANGE: scanscan_range(); break;
default: assert(0); break;
}
scanscan_shutdown();
return 0;
}
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "$Id$"
#if !defined(TOKUDB_COMMON_FUNCS_H)
#define TOKUDB_COMMON_FUNCS_H
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#include <db.h>
#include <memory.h>
#if defined(TOKUDB) && TOKU_WINDOWS
#include <ydb.h>
#endif
static int test_main (int argc, char *const argv[]);
int
main(int argc, char *const argv[]) {
int r;
#if defined(TOKUDB) && TOKU_WINDOWS
toku_ydb_init();
#endif
#if !defined(TOKUDB) && DB_VERSION_MINOR==4 && DB_VERSION_MINOR == 7
r = db_env_set_func_malloc(toku_malloc); assert(r==0);
r = db_env_set_func_free(toku_free); assert(r==0);
r = db_env_set_func_realloc(toku_realloc); assert(r==0);
#endif
r = test_main(argc, argv);
#if defined(TOKUDB) && TOKU_WINDOWS
toku_ydb_destroy();
#endif
return r;
}
static __attribute__((__unused__)) void
print_engine_status(DB_ENV * UU(env)) {
#if defined(TOKUDB)
int buffsize = 1024 * 128;
char buff[buffsize];
env->get_engine_status_text(env, buff, buffsize);
printf("Engine status:\n");
printf("%s", buff);
#endif
}
#endif /* #if !defined(TOKUDB_COMMON_H) */
import sys
def main():
ts = None
while 1:
b = sys.stdin.readline()
if b == "": break
f = b.split()
if len(f) != 2: continue
newts = int(f[0])
event = f[1]
if ts is None:
ts = int(f[0])
else:
print "%8d %s" % (newts - ts, event)
ts = newts
return 0
sys.exit(main())
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "$Id$"
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
// run txn begin commit on multiple threads and measure the throughput
#include "toku_portability.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/time.h>
#include "db.h"
#include "toku_pthread.h"
static double now(void) {
struct timeval tv;
int r = gettimeofday(&tv, NULL); assert(r == 0);
return tv.tv_sec * 1000000.0 + tv.tv_usec;
}
static void test_txn(DB_ENV *env, uint32_t ntxns, long usleep_time) {
int r;
for (uint32_t i = 0; i < ntxns; i++) {
DB_TXN *txn = NULL;
r = env->txn_begin(env, NULL, &txn, DB_TXN_SNAPSHOT); assert(r == 0);
r = txn->commit(txn, 0); assert(r == 0);
if (usleep_time)
usleep(usleep_time);
else
sched_yield();
}
}
struct arg {
DB_ENV *env;
uint32_t ntxns;
long usleep_time;
};
static void *test_thread(void *arg) {
struct arg *myarg = (struct arg *) arg;
test_txn(myarg->env, myarg->ntxns, myarg->usleep_time);
return arg;
}
int main(int argc, char * const argv[]) {
uint32_t ntxns = 1000000;
uint32_t nthreads = 1;
long usleep_time = 0;
for (int i = 1; i < argc; i++) {
char * const arg = argv[i];
if (strcmp(arg, "--ntxns") == 0 && i+1 < argc) {
ntxns = atoll(argv[++i]);
continue;
}
if (strcmp(arg, "--nthreads") == 0 && i+1 < argc) {
nthreads = atoll(argv[++i]);
continue;
}
if (strcmp(arg, "--usleep") == 0 && i+1 < argc) {
usleep_time = atol(argv[++i]);
continue;
}
return 1;
}
int r;
char cmd[256];
sprintf(cmd, "rm -rf %s", ENVDIR);
r = system(cmd); assert(r == 0);
r = toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO); assert(r == 0);
DB_ENV *env = NULL;
r = db_env_create(&env, 0); assert(r == 0);
r = env->set_cachesize(env, 4, 0, 1); assert(r == 0);
r = env->open(env, ENVDIR, DB_PRIVATE + DB_THREAD + DB_CREATE + DB_INIT_TXN + DB_INIT_LOG + DB_INIT_MPOOL + DB_RECOVER, 0); assert(r == 0);
double tstart = now();
assert(nthreads > 0);
struct arg myargs[nthreads-1];
toku_pthread_t mytids[nthreads];
for (uint32_t i = 0; i < nthreads-1; i++) {
myargs[i] = (struct arg) { env, ntxns, usleep_time};
r = toku_pthread_create(&mytids[i], NULL, test_thread, &myargs[i]); assert(r == 0);
}
test_txn(env, ntxns, usleep_time);
for (uint32_t i = 0; i < nthreads-1; i++) {
void *ret;
r = toku_pthread_join(mytids[i], &ret); assert(r == 0);
}
double tend = now();
double t = tend-tstart;
double n = ntxns * nthreads;
printf("%f %f %f\n", n, t, (n/t)*1000000.0);
r = env->close(env, 0); assert(r == 0);
return 0;
}
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "$Id$"
#ifndef _DB_CXX_H_
#define _DB_CXX_H_
#include <db.h>
#include <iostream>
#include <exception>
#include <string.h>
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved."
class Dbt;
class DbEnv;
class DbTxn;
class Dbc;
class DbException;
class DbException : public std::exception {
friend class DbEnv;
public:
~DbException() throw();
DbException(int err);
int get_errno() const;
const char *what() const throw();
DbEnv *get_env() const;
void set_env(DbEnv *);
DbException(const DbException &);
DbException &operator = (const DbException &);
private:
char *the_what;
int the_err;
DbEnv *the_env;
void FillTheWhat(void);
};
class DbDeadlockException : public DbException {
public:
DbDeadlockException(DbEnv*);
};
class DbLockNotGrantedException {
};
class DbMemoryException {
};
class DbRunRecoveryException {
};
// DBT and Dbt objects are the same pointers. So watch out if you use Dbt to make other classes (e.g., with subclassing).
class Dbt : private DBT {
friend class Dbc;
public:
void * get_data(void) const { return data; }
void set_data(void *p) { data = p; }
uint32_t get_size(void) const { return size; }
void set_size(uint32_t p) { size = p; }
uint32_t get_flags() const { return flags; }
void set_flags(uint32_t f) { flags = f; }
uint32_t get_ulen() const { return ulen; }
void set_ulen(uint32_t p) { ulen = p; }
DBT *get_DBT(void) { return (DBT*)this; }
const DBT *get_const_DBT(void) const { return (const DBT*)this; }
static Dbt* get_Dbt(DBT *dbt) { return (Dbt *)dbt; }
static const Dbt* get_const_Dbt(const DBT *dbt) { return (const Dbt *)dbt; }
Dbt(void */*data*/, uint32_t /*size*/);
Dbt(void);
~Dbt();
private:
// Nothing here.
};
extern "C" {
typedef int (*bt_compare_fcn_type)(DB *db, const DBT *dbt1, const DBT *dbt2);
typedef int (*dup_compare_fcn_type)(DB *db, const DBT *dbt1, const DBT *dbt2);
};
class Db {
public:
/* Functions to make C++ work, defined in the BDB C++ API documents */
Db(DbEnv *dbenv, uint32_t flags);
~Db();
DB *get_DB(void) {
return the_db;
}
const DB *get_const_DB() const {
return the_db;
}
static Db *get_Db(DB *db) {
return (Db*)db->api_internal;
}
static const Db *get_const_Db(const DB *db) {
return (Db*)db->api_internal;
}
/* C++ analogues of the C functions. */
int open(DbTxn */*txn*/, const char */*name*/, const char */*subname*/, DBTYPE, uint32_t/*flags*/, int/*mode*/);
int close(uint32_t /*flags*/);
int cursor(DbTxn */*txn*/, Dbc **/*cursorp*/, uint32_t /*flags*/);
int del(DbTxn */*txn*/, Dbt */*key*/, uint32_t /*flags*/);
int get(DbTxn */*txn*/, Dbt */*key*/, Dbt */*data*/, uint32_t /*flags*/);
int put(DbTxn *, Dbt *, Dbt *, uint32_t);
int get_flags(uint32_t *);
int set_flags(uint32_t);
int set_pagesize(uint32_t);
int remove(const char *file, const char *database, uint32_t flags);
#if 0
int set_bt_compare(bt_compare_fcn_type bt_compare_fcn);
int set_bt_compare(int (*)(Db *, const Dbt *, const Dbt *));
#endif
int set_dup_compare(dup_compare_fcn_type dup_compare_fcn);
int set_dup_compare(int (*)(Db *, const Dbt *, const Dbt *));
int associate(DbTxn *, Db *, int (*)(Db *, const Dbt *, const Dbt *, Dbt *), uint32_t);
int fd(int *);
void set_errpfx(const char *errpfx);
void set_error_stream(std::ostream *);
/* the cxx callbacks must be public so they can be called by the c callback. But it's really private. */
int (*associate_callback_cxx)(Db *, const Dbt *, const Dbt *, Dbt*);
int (*dup_compare_callback_cxx)(Db *, const Dbt *, const Dbt *);
//int (do_bt_compare_callback_cxx)(Db *, const Dbt *, const Dbt *);
private:
DB *the_db;
DbEnv *the_Env;
int is_private_env;
};
class DbEnv {
friend class Db;
friend class Dbc;
friend class DbTxn;
public:
DbEnv(uint32_t flags);
~DbEnv(void);
DB_ENV *get_DB_ENV(void) {
if (this==0) return 0;
return the_env;
}
/* C++ analogues of the C functions. */
int close(uint32_t);
int open(const char *, uint32_t, int);
int set_cachesize(uint32_t, uint32_t, int);
int set_redzone(uint32_t);
int set_flags(uint32_t, int);
int txn_begin(DbTxn *, DbTxn **, uint32_t);
int set_data_dir(const char *dir);
void set_errpfx(const char *errpfx);
void err(int error, const char *fmt, ...)
__attribute__((__format__(__printf__, 3, 4)));
void set_errfile(FILE *errfile);
void set_errcall(void (*)(const DbEnv *, const char *, const char *));
void set_error_stream(std::ostream *);
int get_flags(uint32_t *flagsp);
int set_default_bt_compare(bt_compare_fcn_type bt_compare_fcn);
// Don't support this one for now. It's a little tricky.
// int set_default_bt_compare(int (*)(Db *, const Dbt *, const Dbt *));
// locking
#if DB_VERSION_MAJOR<4 || (DB_VERSION_MAJOR==4 && DB_VERSION_MINOR<=4)
// set_lk_max is only defined for versions up to 4.4
int set_lk_max(uint32_t);
#endif
int set_lk_max_locks(uint32_t);
int get_lk_max_locks(uint32_t *);
// somewhat_private:
int do_no_exceptions; // This should be private!!!
void (*errcall)(const DbEnv *, const char *, const char *);
std::ostream *_error_stream;
//int (*bt_compare_callback_cxx)(Db *, const Dbt *, const Dbt *);
private:
DB_ENV *the_env;
DbEnv(DB_ENV *, uint32_t /*flags*/);
int maybe_throw_error(int /*err*/) throw (DbException);
static int maybe_throw_error(int, DbEnv*, int /*no_exceptions*/) throw (DbException);
};
class DbTxn {
public:
int commit (uint32_t /*flags*/);
int abort ();
virtual ~DbTxn();
DB_TXN *get_DB_TXN()
{
if (this==0) return 0;
return the_txn;
}
DbTxn(DB_TXN*);
private:
DB_TXN *the_txn;
};
class Dbc : protected DBC {
public:
int close(void);
int get(Dbt *, Dbt *, uint32_t);
int count(db_recno_t *, uint32_t);
private:
Dbc(); // User may not call it.
~Dbc(); // User may not delete it.
};
#endif
libtokudb.so
libtokudbtrace.so
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