Commit ec4cd630 authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

merge 1032 into 1032b. addresses #1032

git-svn-id: file:///svn/toku/tokudb.1032b@7804 c7de825b-a66e-492c-adef-691d508d4ae1
parent 0a5a3951
# On OSX do:
# make OSX=OSX
# -*- Mode: Makefile -*-
.DEFAULT_GOAL=build
TOKUROOT=../
INCLUDEDIRS=-I$(TOKUROOT)newbrt -I./lock_tree -I./range_tree
DEPEND_COMPILE += \
ydb-internal.h \
$(TOKUROOT)include/db.h \
$(TOKUROOT)newbrt/cachetable.h \
$(TOKUROOT)newbrt/brt.h \
$(TOKUROOT)newbrt/log.c \
#End of line
ydbtrace.o tdbtrace.o: tdbtrace.h
include $(TOKUROOT)include/Makefile.include
CPPFLAGS += -D_GNU_SOURCE -D_THREAD_SAFE
YDB=ydb.$(AEXT)
TYDB=tydb.$(AEXT)
LIBNAME=libtokudb
TLIBNAME=libtokudbtrace
EXPORTMAP = -Wl,--version-script=export.map
VISIBILITY = -fvisibility=hidden
# PROF_FLAGS=-pg
OPTFLAGS = -O3 -finline-functions
# GCOV_FLAGS = -fprofile-arcs -ftest-coverage
CFLAGS = -fPIC $(OPTFLAGS) $(GCOV_FLAGS)
ifeq ($(CC),icc)
CFLAGS += -Wall -g
CFLAGS += -diag-disable 177
CFLAGS += -diag-disable 589
CFLAGS += -diag-disable 981
CFLAGS += -diag-disable 1418
CFLAGS += -diag-disable 1419
else
CFLAGS += -W -Werror -Wall -Wextra -g3 -ggdb3
CFLAGS += -Wbad-function-cast -Wcast-align
endif
CPPFLAGS = -I../include -I../newbrt -I./lock_tree/ -I./range_tree/
CPPFLAGS += -D_GNU_SOURCE -D_THREAD_SAFE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
CFLAGS+= $(VISIBILITY) $(PROF_FLAGS)
LIBRARY=$(LIBNAME).$(SOEXT)
TLIBRARY=$(TLIBNAME).$(SOEXT)
LIBRARY_S=$(LIBNAME).$(AEXT)
TLIBRARY_S=$(TLIBNAME).$(AEXT)
OBJS_RAW = \
ydb_lib \
ydb \
errors \
elocks \
#\end
#OBJS automatically defined.
LIBRARIES= \
$(LIBRARY) \
$(TLIBRARY) \
$(LIBRARY_S) \
$(TLIBRARY_S) \
#Purposely here for \ at end of prev
ifneq ($(OSX),)
LIBRARY=$(LIBNAME).dylib
TLIBRARY=$(TLIBNAME).dylib
SHARED=-dynamiclib
RPATHNAME=-install_name @rpath/$(LIBRARY)
CFLAGS+=-fno-common
else
LIBRARY=$(LIBNAME).so
TLIBRARY=$(TLIBNAME).so
SHARED=-shared $(EXPORTMAP)
RPATHNAME=
endif
INSTALL_LIBRARIES= $(patsubst %,%.install,$(LIBRARIES))
.PHONY:install_libs install.% build install local build_tests
#Half Build Half Install???
build: local build_tests ;
local: buildlocktrees libs install_libs ;
build_tests: | local
$(MAYBEATSIGN)cd tests && $(MAKE) build
build: buildlocktrees lib
cd tests;$(MAKE) build
if ! diff $(LIBNAME).a ../lib/$(LIBNAME).a >/dev/null 2>&1; then cp $(LIBNAME).a ../lib/; fi
if ! diff $(LIBRARY) ../lib/$(LIBRARY) > /dev/null 2>&1; then cp $(LIBRARY) ../lib/; fi
if ! diff $(TLIBNAME).a ../lib/$(TLIBNAME).a >/dev/null 2>&1; then cp $(TLIBNAME).a ../lib/; fi
if ! diff $(TLIBRARY) ../lib/$(TLIBRARY) > /dev/null 2>&1; then cp $(TLIBRARY) ../lib/; fi
lib: $(LIBRARY) $(LIBNAME).a $(TLIBNAME).a $(TLIBRARY)
TOBJS= tdbtrace.$(OEXT) $(patsubst ydb.$(OEXT),ydbtrace.$(OEXT),$(OBJS))
.PHONY: buildlocktrees
buildlocktrees:
cd range_tree;$(MAKE) build
cd lock_tree;$(MAKE) build
local: $(LIBRARY) $(LIBNAME).a $(TLIBNAME).a $(TLIBRARY)
install_libs: $(INSTALL_LIBRARIES)
%.install: %
$(MAYBEATSIGN)if ! diff $* ../lib/$* > /dev/null 2>&1; then cp $* ../lib/; fi
.PHONY: install
install: $(LIBRARY) $(LIBNAME).a $(TLIBRARY) $(TLIBNAME).a
cp $(LIBRARY) ../lib/
cp $(LIBNAME).a ../lib
cp $(TLIBRARY) ../lib/
cp $(TLIBNAME).a ../lib
install: libs install_libs ;
check_globals: $(LIBRARY)
python tokuglobals.py $(LIBRARY)
.PHONY: local libs buildlocktrees
libs: $(LIBRARIES) ;
check_tests:
cd tests;$(MAKE) check
check: $(LIBRARY) check_globals check_tests
buildlocktrees: $(LOCKTREE) $(RANGETREE) ;
strip: $(LIBRARY)
strip $(LIBRARY)
$(YDB): $(OBJS)
$(TYDB): $(TOBJS)
clean:
rm -rf $(LIBRARY) $(LIBNAME).a $(TLIBRARY) $(TLIBNAME).a *.o *.gcno *.gcda *.gcov
cd tests && $(MAKE) clean
cd lock_tree && $(MAKE) clean
cd range_tree && $(MAKE) clean
ydbtrace.o ydb.o: ../include/db.h ../newbrt/cachetable.h ../newbrt/brt.h ../newbrt/log.c
ydbtrace.o tdbtrace.o: tdbtrace.h
ydbtrace.o: ydb.c
$(CC) $(CFLAGS) $(CPPFLAGS) -DTOKUTRACE -c -o $@ $<
$(LIBRARY): $(YDB) $(LOCKTREE) $(RANGETREE) $(NEWBRT) $(DEPEND_COMPILE) $(DEPEND_LINK)
$(TLIBRARY): $(TYDB) $(LOCKTREE) $(RANGETREE) $(NEWBRT) $(DEPEND_COMPILE) $(DEPEND_LINK)
DBBINS = ydb.o errors.o elocks.o ../newbrt/newbrt.o
$(LIBRARY): LINK_FILES=ydb_lib.$(OEXT) $(YDB) $(LOCKTREE) $(RANGETREE) $(NEWBRT)
$(TLIBRARY): LINK_FILES=$(TYDB) $(LOCKTREE) $(RANGETREE) $(NEWBRT)
TDBBINS = tdbtrace.o $(patsubst ydb.o,ydbtrace.o,$(DBBINS))
#Skip all BDB tests for CYGWIN+ICC
ifeq ($(CYGWIN),)
$(LIBRARY_S): $(YDB) $(LOCKTREE) $(RANGETREE) $(NEWBRT) $(LIBPORTABILITY)
$(TLIBRARY_S): $(TYDB) $(LOCKTREE) $(RANGETREE) $(NEWBRT) $(LIBPORTABILITY)
else ifneq ($(CC),icc)
$(LIBRARY_S): $(YDB) $(LOCKTREE) $(RANGETREE) $(NEWBRT) $(LIBPORTABILITY)
$(TLIBRARY_S): $(TYDB) $(LOCKTREE) $(RANGETREE) $(NEWBRT) $(LIBPORTABILITY)
else
$(LIBRARY_S): $(LIBRARY) ;
$(TLIBRARY_S): $(TLIBRARY) ;
#$(LIBRARY_S): $(YDB) $(LOCKTREE) $(RANGETREE) $(NEWBRT) $(LIBPORTABILITY)
#$(TLIBRARY_S): $(TYDB) $(LOCKTREE) $(RANGETREE) $(NEWBRT) $(LIBPORTABILITY)
endif
RANGETREE_BINS = range_tree/rangetree.o
LOCKTREE_BINS = lock_tree/locktree.o lock_tree/rth.o lock_tree/lth.o lock_tree/idlth.o lock_tree/db_id.o $(RANGETREE_BINS)
static_libtokudb.lib: $(YDB) $(LOCKTREE) $(RANGETREE) $(NEWBRT) $(LIBPORTABILITY)
lib /out:$@ $^
$(LIBRARY): $(DBBINS) | buildlocktrees
$(CC) $(CPPFLAGS) $^ $(LOCKTREE_BINS) $(SHARED) -o $@ $(CFLAGS) $(RPATHNAME)
$(LIBNAME).a: $(DBBINS) | buildlocktrees
$(AR) cr $@ $^ $(LOCKTREE_BINS)
check_globals: $(LIBNAME).$(AEXT)
$(MAYBEATSIGN)python tokuglobals.py $<
$(LIBNAME).a(ydb.o): ydb.o
.PHONY: check_tests
check_tests: build_tests
$(MAYBEATSIGN)cd tests && $(MAKE) check
$(TLIBRARY): $(TDBBINS) | buildlocktrees
$(CC) $(CPPFLAGS) $^ $(LOCKTREE_BINS) $(SHARED) -o $@ $(CFLAGS) $(RPATHNAME)
.PHONY: check
check: local check_globals check_tests
.PHONY: strip
strip: $(LIBRARY)
$(MAYBEATSIGN)strip $<
clean:
$(MAYBEATSIGN)cd tests && $(MAKE) clean
$(MAYBEATSIGN)cd lock_tree && $(MAKE) clean
$(MAYBEATSIGN)cd range_tree && $(MAKE) clean
$(TLIBNAME).a: $(TDBBINS) | buildlocktrees
$(AR) cr $@ $^ $(LOCKTREE_BINS)
ydbtrace.$(OEXT): ydb.c $(DEPEND_COMPILE)
$(MAYBEATSIGN)$(CC) $< $(O_FROM_C_FLAGS) -DTOKUTRACE
$(TLIBNAME).a(ydbtrace.o): ydbtrace.o
......@@ -11,41 +11,19 @@
every call (including methods) into the tokudb library gets the lock
no internal function should invoke a method through an object */
#include "portability.h"
#include "ydb-internal.h"
#include <assert.h>
#include <pthread.h>
#include <toku_pthread.h>
#include <sys/types.h>
#ifdef __CYGWIN__
#include <windows.h>
#include <winbase.h>
CRITICAL_SECTION ydb_big_lock;
static toku_pthread_mutex_t ydb_big_lock = TOKU_PTHREAD_MUTEX_INITIALIZER;
void toku_ydb_lock(void) {
static int initialized = 0;
if (!initialized) {
initialized=1;
InitializeCriticalSection(&ydb_big_lock);
}
EnterCriticalSection(&ydb_big_lock);
int r = toku_pthread_mutex_lock(&ydb_big_lock); assert(r == 0);
}
void toku_ydb_unlock(void) {
LeaveCriticalSection(&ydb_big_lock);
int r = toku_pthread_mutex_unlock(&ydb_big_lock); assert(r == 0);
}
#else //Not Cygwin
#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
static pthread_mutex_t ydb_big_lock = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
#else
static pthread_mutex_t ydb_big_lock = PTHREAD_MUTEX_INITIALIZER;
#endif
void toku_ydb_lock(void) {
int r = pthread_mutex_lock(&ydb_big_lock); assert(r == 0);
}
void toku_ydb_unlock(void) {
int r = pthread_mutex_unlock(&ydb_big_lock); assert(r == 0);
}
#endif
EXPORTS
db_create @1
db_env_create @2
db_strerror @3
db_version @4
log_compare @5
db_env_set_func_fsync @6
toku_get_maxrss @7
toku_ydb_error_all_cases @8
toku_set_trace_file @9
toku_close_trace_file @10
toku_add_trace_mem @11
toku_print_trace_mem @12
# On OSX do:
# make OSX=OSX
# -*- Mode: Makefile -*-
OPTFLAGS = -O3 -finline-functions
.DEFAULT_GOAL= build
TOKUROOT=../../
INCLUDEDIRS=-I. -I$(TOKUROOT)newbrt -I../range_tree -I$(TOKUROOT)src
DEPEND_COMPILE+= \
*.h \
../range_tree/*.h \
#end
ifneq ($(GCOV),)
GCOV_FLAGS = -fprofile-arcs -ftest-coverage
else
GCOV_FLAGS =
endif
SKIP_LOCKTREERULE=1
include $(TOKUROOT)include/Makefile.include
VISIBILITY = -fvisibility=hidden
LOCKTREE = locktree.$(AEXT)
LOCKTREE_LINEAR = locktree_linear.$(AEXT)
LOCKTREE_TLOG = locktree_tlog.$(AEXT)
LOCKTREE_LOG = locktree_log.$(AEXT)
CFLAGS = -Wall -fPIC $(OPTFLAGS) $(GCOV_FLAGS)
ifeq ($(CC),icc)
CFLAGS += -g
CFLAGS += -Werror
CFLAGS += -diag-disable 177
CFLAGS += -diag-disable 589
CFLAGS += -diag-disable 869
CFLAGS += -diag-disable 981
CFLAGS += -diag-disable 1324
else
CFLAGS += -g3 -ggdb3
CFLAGS += -Werror -Wextra -Wbad-function-cast -Wcast-align -Wconversion -Waggregate-return
CFLAGS += -Wmissing-noreturn -Wmissing-format-attribute
endif
CFLAGS += $(VISIBILITY) $(PROF_FLAGS)
CPPFLAGS = -I. -I.. -I../range_tree -I../../include -I../../newbrt -L../range_tree
CPPFLAGS += -D_GNU_SOURCE -D_THREAD_SAFE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
OBJS_RAW = \
db_id \
idlth \
lth \
rth \
#end
LIBRARIES=$(LOCKTREE_LINEAR) $(LOCKTREE_TLOG) $(LOCKTREE) # $(LOCKTREE_LOG)
ifneq ($(OSX),)
CFLAGS+=-fno-common
endif
$(LOCKTREE_TLOG): $(OBJS) locktree_nooverlap.$(OEXT)
$(LOCKTREE_LOG) $(LOCKTREE_LINEAR): $(OBJS) locktree.$(OEXT)
LT_OVERLAP = locktree_global_readset.o
LT_NOOVERLAP = locktree_no_global_readset.o
LT_LINEAR = $(LT_OVERLAP)
LT_TLINEAR = $(LT_NOOVERLAP)
LT_TLOG = $(LT_NOOVERLAP)
LT_LOG = $(LT_OVERLAP)
$(LOCKTREE): $(LOCKTREE_TLOG)
$(MAYBEATSIGN)cp $< $@
LT_BINS=$(LT_OVERLAP) $(LT_NOOVERLAP) locktree.o
BINS=rth.o lth.o idlth.o db_id.o
.PHONY: build check
build: $(LIBRARIES)
.PHONY: install logformat
locktree_nooverlap.$(OEXT): locktree.c $(DEPEND_COMPILE)
$(MAYBEATSIGN)$(CC) $< -DTOKU_RT_NOOVERLAPS $(O_FROM_C_FLAGS)
build: $(LT_BINS) $(BINS)
cd tests; $(MAKE) build
build check clean:
$(MAYBEATSIGN)cd tests;$(MAKE) $@
check:
cd tests; $(MAKE) check
clean:
rm -rf $(BINS) $(LT_BINS)
rm -rf *.gcno *.gcda *.gcov
cd tests && $(MAKE) clean
locktree.o: $(LT_TLOG)
cp $< $@
locktree_global_readset.o: locktree.c locktree.h
$(CC) $(CFLAGS) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
locktree_no_global_readset.o: locktree.c locktree.h
$(CC) $(CFLAGS) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ -DTOKU_RT_NOOVERLAPS
rth.o: rth.c rth.h
lth.o: lth.c lth.h
......@@ -3,6 +3,7 @@
#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 "portability.h"
#include <errno.h>
#include <assert.h>
#include <string.h>
......@@ -15,9 +16,9 @@
BOOL toku_db_id_equals(const toku_db_id* a, const toku_db_id* b) {
assert(a && b);
return (BOOL)
(a == b ||
(a == b ||
(a->saved_hash == b->saved_hash &&
!strcmp(a->absolute_path, b->absolute_path) &&
memcmp(&a->id, &b->id, sizeof(b->id))==0 &&
!strcmp(a->sub_database_name, b->sub_database_name)));
}
......@@ -27,21 +28,23 @@ void toku_db_id_add_ref(toku_db_id* db_id) {
db_id->ref_count++;
}
static void toku_db_id_close(toku_db_id* db_id) {
toku_free(db_id->absolute_path);
static void toku_db_id_close(toku_db_id** pdb_id) {
toku_db_id* db_id = *pdb_id;
toku_free(db_id->sub_database_name);
toku_free(db_id);
*pdb_id = NULL;
}
void toku_db_id_remove_ref(toku_db_id* db_id) {
void toku_db_id_remove_ref(toku_db_id** pdb_id) {
toku_db_id* db_id = *pdb_id;
assert(db_id);
assert(db_id->ref_count > 0);
db_id->ref_count--;
if (db_id->ref_count > 0) { return; }
toku_db_id_close(db_id);
toku_db_id_close(pdb_id);
}
int toku_db_id_create(toku_db_id** pdbid, const char* path,
int toku_db_id_create(toku_db_id** pdbid, int fd,
const char* sub_database_name) {
int r = ENOSYS;
assert(sub_database_name);
......@@ -51,27 +54,14 @@ int toku_db_id_create(toku_db_id** pdbid, const char* path,
if (!db_id) { r = ENOMEM; goto cleanup; }
memset(db_id, 0, sizeof(*db_id));
db_id->absolute_path = (char *)toku_malloc((PATH_MAX + 1) * sizeof(char));
if (!db_id->absolute_path) { r = ENOMEM; goto cleanup; }
r = os_get_unique_file_id(fd, &db_id->id);
if (r!=0) goto cleanup;
/* TODO: BUG! Buffer overflow if the path > PATH_MAX. */
if (realpath(path, db_id->absolute_path) == NULL) {
r = errno;
goto cleanup;
}
char* tmp = (char*)toku_realloc(db_id->absolute_path,
(strlen(db_id->absolute_path) + 1) * sizeof(char));
if (!tmp) { r = ENOMEM; goto cleanup; }
db_id->absolute_path = tmp;
db_id->sub_database_name = toku_strdup(sub_database_name);
if (!db_id->sub_database_name) { r = ENOMEM; goto cleanup; }
db_id->saved_hash = hash_key((unsigned char*)db_id->absolute_path,
strlen(db_id->absolute_path));
db_id->saved_hash = hash_key_extend(db_id->saved_hash,
(unsigned char*)db_id->sub_database_name,
strlen(db_id->sub_database_name));
db_id->saved_hash = hash_key((unsigned char*)db_id->sub_database_name,
strlen(db_id->sub_database_name));
db_id->ref_count = 1;
*pdbid = db_id;
......@@ -79,10 +69,10 @@ int toku_db_id_create(toku_db_id** pdbid, const char* path,
cleanup:
if (r != 0) {
if (db_id != NULL) {
if (db_id->absolute_path) { toku_free(db_id->absolute_path); }
if (db_id->sub_database_name) { toku_free(db_id->sub_database_name); }
toku_free(db_id);
}
}
return r;
}
......@@ -3,26 +3,28 @@
#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 "portability.h"
#include "os.h"
#include <brttypes.h>
#if !defined(TOKU_DB_ID_H)
#define TOKU_DB_ID_H
typedef struct __toku_db_id {
char* absolute_path;
char* sub_database_name;
u_int32_t saved_hash;
u_int32_t ref_count;
struct fileid id;
char* sub_database_name;
u_int32_t saved_hash;
u_int32_t ref_count;
} toku_db_id;
/* db_id methods */
int toku_db_id_create(toku_db_id** pdbid, const char* path,
int toku_db_id_create(toku_db_id** pdbid, int fd,
const char* sub_database_name);
BOOL toku_db_id_equals(const toku_db_id* a, const toku_db_id* b);
void toku_db_id_add_ref(toku_db_id* db_id);
void toku_db_id_remove_ref(toku_db_id* db_id);
void toku_db_id_remove_ref(toku_db_id** pdb_id);
#endif /* #if !defined(TOKU_DB_ID_H) */
......@@ -9,6 +9,7 @@
*/
#include "portability.h"
#include <idlth.h>
#include <assert.h>
#include <errno.h>
......@@ -119,7 +120,7 @@ void toku_idlth_delete(toku_idlth* idlth, toku_db_id* key) {
current->prev_in_iteration->next_in_iteration = current->next_in_iteration;
current->next_in_iteration->prev_in_iteration = current->prev_in_iteration;
prev->next_in_bucket = current->next_in_bucket;
toku_db_id_remove_ref(current->value.db_id);
toku_db_id_remove_ref(&current->value.db_id);
idlth->free(current);
idlth->num_keys--;
return;
......@@ -165,7 +166,7 @@ static inline void toku__idlth_clear(toku_idlth* idlth, BOOL clean) {
while (next != head) {
element = next;
next = toku__idlth_next(idlth);
toku_db_id_remove_ref(element->value.db_id);
toku_db_id_remove_ref(&element->value.db_id);
idlth->free(element);
}
/* If clean is true, then we want to restore it to 'just created' status.
......
......@@ -8,7 +8,7 @@
\brief Lock trees: implementation
*/
#include "portability.h"
#include <locktree.h>
#include <ydb-internal.h>
#include <brt-internal.h>
......@@ -380,7 +380,7 @@ toku_range_tree* toku__lt_ifexist_selfread(toku_lock_tree* tree, TXNID txn) {
/* Provides access to a selfwrite tree for a particular transaction.
Returns NULL if it does not exist yet. */
static toku_range_tree* toku__lt_ifexist_selfwrite(toku_lock_tree* tree, TXNID txn) {
toku_range_tree* toku__lt_ifexist_selfwrite(toku_lock_tree* tree, TXNID txn) {
assert(tree);
rt_forest* forest = toku_rth_find(tree->rth, txn);
return forest ? forest->self_write : NULL;
......@@ -948,7 +948,7 @@ static int free_contents_helper(toku_range* value, void* extra) {
toku__lt_free_point (singular)
*/
static inline int toku__lt_free_contents(toku_lock_tree* tree, toku_range_tree* rt,
toku_range_tree *rtdel, BOOL close) {
toku_range_tree *rtdel, BOOL doclose) {
assert(tree);
if (!rt) return 0;
......@@ -965,7 +965,7 @@ static inline int toku__lt_free_contents(toku_lock_tree* tree, toku_range_tree*
info.store_value = &tree->buf[0];
if ((r=toku_rt_iterate(rt, free_contents_helper, &info))) return r;
if (close) r = toku_rt_close(rt);
if (doclose) r = toku_rt_close(rt);
else {
r = 0;
toku_rt_clear(rt);
......@@ -1362,7 +1362,7 @@ int toku_lt_close(toku_lock_tree* tree) {
toku_rth_close(tree->txns_still_locked);
tree->free(tree->buf);
if (tree->db_id) { toku_db_id_remove_ref(tree->db_id); }
if (tree->db_id) { toku_db_id_remove_ref(&tree->db_id); }
tree->free(tree);
r = first_error;
cleanup:
......
......@@ -517,4 +517,6 @@ int toku__lt_point_cmp(const toku_point* x, const toku_point* y);
toku_range_tree* toku__lt_ifexist_selfread(toku_lock_tree* tree, TXNID txn);
toku_range_tree* toku__lt_ifexist_selfwrite(toku_lock_tree* tree, TXNID txn);
#endif
......@@ -9,6 +9,7 @@
*/
#include "portability.h"
#include "lth.h"
#include <assert.h>
#include <errno.h>
......
......@@ -9,6 +9,7 @@
*/
#include "portability.h"
#include "rth.h"
#include <assert.h>
#include <errno.h>
......
# On OSX do:
# make OSX=OSX
# -*- Mode: Makefile -*-
# For verbose output do
# make VERBOSE=1
# For very verbose output do
# make VERBOSE=2
.DEFAULT_GOAL= build
TOKUROOT=../../../
INCLUDEDIRS=-I. -I../ -I$(TOKUROOT)newbrt -I$(TOKUROOT)src/range_tree
DEPEND_COMPILE += \
../*.h \
test.h \
#end
DEPEND_COMPILE+= $(NEWBRT)
OPTFLAGS = -O0
ifeq ($(OSX),)
VGRIND=valgrind --quiet --error-exitcode=1 --leak-check=yes
endif
LINK_FILES=$(NEWBRT)
include $(TOKUROOT)include/Makefile.include
ifeq ($(GCOV),GCOV)
GCOV_FLAGS = -fprofile-arcs -ftest-coverage
else
GCOV_FLAGS =
endif
ifeq ($(CC),icc)
CFLAGS = -Wall $(OPTFLAGS) $(GCOV_FLAGS)
else
CFLAGS = -W -Wall -Wextra $(OPTFLAGS) -g3 -ggdb3 $(GCOV_FLAGS)
CFLAGS += -Wbad-function-cast -Wcast-align -Waggregate-return
CFLAGS += -Wmissing-noreturn -Wmissing-format-attribute
SKIP_WARNING += $(ICC_NOWARN)1418 #Non static functions do not need prototypes.
endif
CPPFLAGS += -L../ -L../../range_tree
CPPFLAGS += -I. -I../ -I../../range_tree -I../../../newbrt -I../../../include
LDFLAGS = -lpthread -lz
SRCS = $(wildcard *.c)
LOG_TESTS = $(patsubst %.c,%.log,$(SRCS))
TLOG_TESTS = $(patsubst %.c,%.tlog,$(SRCS))
LIN_TESTS = $(patsubst %.c,%.lin,$(SRCS))
TLIN_TESTS = $(patsubst %.c,%.tlin,$(SRCS))
ALL_TESTS = $(LIN_TESTS) $(TLIN_TESTS) $(TLOG_TESTS) #$(LOG_TESTS)
LOG_TESTS = $(patsubst %.c,%.log$(BINSUF),$(SRCS))
TLOG_TESTS = $(patsubst %.c,%.tlog$(BINSUF),$(SRCS))
LIN_TESTS = $(patsubst %.c,%.lin$(BINSUF),$(SRCS))
RUN_LOG_TESTS = $(patsubst %.log,%.logrun,$(LOG_TESTS))
RUN_TLOG_TESTS = $(patsubst %.tlog,%.tlogrun,$(TLOG_TESTS))
RUN_LIN_TESTS = $(patsubst %.lin,%.linrun,$(LIN_TESTS))
RUN_TLIN_TESTS = $(patsubst %.tlin,%.tlinrun,$(TLIN_TESTS))
RUN_ALL_TESTS = $(RUN_LIN_TESTS) $(RUN_TLIN_TESTS) $(RUN_TLOG_TESTS) $(RUN_LOG_TESTS)
ALL_TESTS = $(LIN_TESTS) $(TLOG_TESTS) #$(LOG_TESTS)
.PHONY: check tests default all check.lin check.tlin check.log check.tlog tests.lin tests.tlin tests.tlog tests.log
RUN_LOG_TESTS = $(patsubst %.log$(BINSUF),%.logrun,$(LOG_TESTS))
RUN_TLOG_TESTS = $(patsubst %.tlog$(BINSUF),%.tlogrun,$(TLOG_TESTS))
RUN_LIN_TESTS = $(patsubst %.lin$(BINSUF),%.linrun,$(LIN_TESTS))
RUN_ALL_TESTS = $(RUN_LIN_TESTS) $(RUN_TLOG_TESTS) #$(RUN_LOG_TESTS)
default: build
.PHONY: default all check tests check.lin check.tlog check.log tests.lin tests.log tests.tlog
build all: $(ALL_TESTS)
default all build: $(ALL_TESTS)
check: check.lin check.tlin check.tlog #check.log
@ echo $@ ok
tests: tests.lin tests.tlin tests.tlog #tests.log
@ echo $@ ok
tests.lin: make_libs $(LIN_TESTS)
@ echo $@ ok
check: $(RUN_ALL_TESTS)
tests: $(ALL_TESTS)
tests.lin: $(LIN_TESTS)
check.lin: $(RUN_LIN_TESTS)
@ echo $@ ok
tests.tlin: $(TLIN_TESTS)
@ echo $@ ok
check.tlin: $(RUN_TLIN_TESTS)
@ echo $@ ok
tests.tlog: $(TLOG_TESTS)
@ echo $@ ok
check.tlog: $(RUN_TLOG_TESTS)
@ echo $@ ok
tests.log: $(LOG_TESTS)
@ echo $@ ok
check.log: $(RUN_LOG_TESTS)
@ echo $@ ok
# Need these rule so that Make knows about all the file names
.PHONY: %.linrun %.tlinrun %.tlogrun %.logrun %.run
%.run: %.linrun %.tlinrun %.tlogrun %.logrun
@ echo ok
ifeq ($(VERBOSE),2)
VERBVERBOSE=-v
MAYBEATSIGN=
VERBQUIET=
else
ifeq ($(VERBOSE),1)
VERBVERBOSE=
MAYBEATSIGN=
VERBQUIET=
else
VERBVERBOSE=
MAYBEATSIGN=@
VERBQUIET=--quiet
endif
endif
tests.log: $(LOG_TESTS)
check.log: $(RUN_LOG_TESTS)
.PHONY: %.linrun %.logrun %.run %.tlogrun
# STUFF!!!!
%.run: %.linrun %.tlogrun #%.logrun
# The @ sign makes the make quiet. If there is an error there is enough info to tell what test failed.
%.linrun: %.lin
$(MAYBEATSIGN) $(VGRIND) ./$< $(VERBVERBOSE)
%.tlinrun: %.tlin
$(MAYBEATSIGN) $(VGRIND) ./$< $(VERBVERBOSE)
%.tlinrun: %.tlin
$(MAYBEATSIGN) $(VGRIND) ./$< $(VERBVERBOSE)
%.logrun: %.log
$(MAYBEATSIGN) $(VGRIND) ./$< $(VERBVERBOSE)
%.tlogrun: %.tlog
$(MAYBEATSIGN) $(VGRIND) ./$< $(VERBVERBOSE)
NEWBRT_BINS = ../../../newbrt/newbrt.o
RT_LINEAR_BINS = ../../range_tree/linear.o
RT_TLINEAR_BINS = ../../range_tree/linear.o
RT_TLOG_BINS = ../../range_tree/log_nooverlap.o
RT_LOG_BINS = ../../range_tree/log.o
LT_BINS = ../lth.o ../rth.o ../idlth.o ../db_id.o
LT_OVERLAP = ../locktree_global_readset.o
LT_NOOVERLAP = ../locktree_no_global_readset.o
LT_LINEAR = $(LT_OVERLAP) $(LT_BINS) $(RT_LINEAR_BINS)
LT_TLINEAR = $(LT_NOOVERLAP) $(LT_BINS) $(RT_TLINEAR_BINS)
LT_TLOG = $(LT_NOOVERLAP) $(LT_BINS) $(RT_TLOG_BINS)
LT_LOG = $(LT_OVERLAP) $(LT_BINS) $(RT_LOG_BINS)
foo:
echo ../locktree.h test.h $(LT_LINEAR)
%.lin: %.c ../locktree.h test.h $(LT_LINEAR)
$(CC) -DDIR=\"dir.$<.lin\" $(CPPFLAGS) $(CFLAGS) $< -o $@ $(LT_LINEAR) $(NEWBRT_BINS) $(LDFLAGS)
%.tlin: %.c ../locktree.h test.h $(LT_TLINEAR)
$(CC) -DDIR=\"dir.$<.tlin\" $(CPPFLAGS) $(CFLAGS) $< -o $@ $(LT_TLINEAR) $(NEWBRT_BINS) -DTOKU_RT_NOOVERLAPS $(LDFLAGS)
%.tlog: %.c ../locktree.h test.h $(LT_TLOG)
$(CC) -DDIR=\"dir.$<.tlog\" $(CPPFLAGS) $(CFLAGS) $< -o $@ $(LT_TLOG) $(NEWBRT_BINS) -DTOKU_RT_NOOVERLAPS $(LDFLAGS)
%.log: %.c ../locktree.h test.h $(LT_LOG)
$(CC) -DDIR=\"dir.$<.log\" $(CPPFLAGS) $(CFLAGS) $< -o $@ $(LT_LOG) $(NEWBRT_BINS) $(LDFLAGS)
%.linrun: %.lin$(BINSUF)
$(MAYBEATSIGN) $(VGRIND) ./$< $(VERBVERBOSE) $(SUMMARIZE_CMD)
%.tlogrun: %.tlog$(BINSUF)
$(MAYBEATSIGN) $(VGRIND) ./$< $(VERBVERBOSE) $(SUMMARIZE_CMD)
%.logrun: %.log$(BINSUF)
$(MAYBEATSIGN) $(VGRIND) ./$< $(VERBVERBOSE) $(SUMMARIZE_CMD)
A_LINEAR=$(LOCKTREE_LINEAR) $(RANGETREE_LINEAR)
A_TLOG =$(LOCKTREE_TLOG) $(RANGETREE_TLOG)
A_LOG =$(LOCKTREE_LOG) $(RANGETREE_LOG)
%.lin$(BINSUF): %.c $(DEPEND_COMPILE) $(DEPEND_LINK) $(A_LINEAR)
$(MAYBEATSIGN)$(CC) -DTESTDIR=\"dir.$<.lin\" $< $(A_LINEAR) $(BIN_FROM_C_FLAGS)
%.tlog$(BINSUF): %.c $(DEPEND_COMPILE) $(DEPEND_LINK) $(A_TLOG)
$(MAYBEATSIGN)$(CC) -DTESTDIR=\"dir.$<.tlog\" $< $(A_TLOG) $(BIN_FROM_C_FLAGS) -DTOKU_RT_NOOVERLAPS
%.log$(BINSUF): %.c $(DEPEND_COMPILE) $(DEPEND_LINK) $(A_LOG)
$(MAYBEATSIGN)$(CC) -DTESTDIR=\"dir.$<.log\" $< $(A_LOG) $(BIN_FROM_C_FLAGS)
clean:
rm -f $(ALL_TESTS) *.o *.gcno *.gcda *.gcov
rm -rf dir.*
$(MAYBEATSIGN)rm -f $(ALL_TESTS)
$(MAYBEATSIGN)rm -rf dir.*.lin dir.*.tlog dir.*.log
#include "portability.h"
#include <string.h>
#include <locktree.h>
#include <db.h>
......@@ -18,7 +19,7 @@ int verbose=0;
BOOL want_panic = FALSE;
int intcmp(DB *db __attribute__((__unused__)), const DBT* a, const DBT* b) {
static inline int intcmp(DB *db __attribute__((__unused__)), const DBT* a, const DBT* b) {
int x = *(int*)a->data;
int y = *(int*)b->data;
......@@ -26,24 +27,24 @@ int intcmp(DB *db __attribute__((__unused__)), const DBT* a, const DBT* b) {
}
int dbcmp (DB *db __attribute__((__unused__)), const DBT *a, const DBT*b) {
static inline int dbcmp (DB *db __attribute__((__unused__)), const DBT *a, const DBT*b) {
return toku_keycompare(a->data, a->size, b->data, b->size);
}
toku_dbt_cmp compare_fun = dbcmp;
toku_dbt_cmp dup_compare = dbcmp;
toku_dbt_cmp get_compare_fun_from_db(__attribute__((unused)) DB* db) {
static inline toku_dbt_cmp get_compare_fun_from_db(__attribute__((unused)) DB* db) {
return compare_fun;
}
toku_dbt_cmp get_dup_compare_from_db(__attribute__((unused)) DB* db) {
static inline toku_dbt_cmp get_dup_compare_from_db(__attribute__((unused)) DB* db) {
return dup_compare;
}
BOOL panicked = FALSE;
int dbpanic(DB* db, int r) {
static inline int dbpanic(DB* db, int r) {
if (verbose) printf("AHH!!!! %d is rampaging! Run away %p!!!\n", r, db);
panicked = TRUE;
assert(want_panic);
......@@ -51,18 +52,20 @@ int dbpanic(DB* db, int r) {
}
#define CKERR(r) ({ if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, strerror(r)); assert(r==0); })
#define CKERR2(r,r2) ({ if (r!=r2) fprintf(stderr, "%s:%d error %d %s, expected %d\n", __FILE__, __LINE__, r, strerror(r), r2); assert(r==r2); })
#define CKERR(r) { if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, strerror(r)); assert(r==0); }
#define CKERR2(r,r2) { if (r!=r2) fprintf(stderr, "%s:%d error %d %s, expected %d\n", __FILE__, __LINE__, r, strerror(r), r2); assert(r==r2); }
void parse_args (int argc, const char *argv[]) {
static inline void parse_args (int argc, const char *argv[]) {
const char *argv0=argv[0];
while (argc>1) {
int resultcode=0;
if (strcmp(argv[1], "-v")==0) {
verbose++;
} else if (strcmp(argv[1], "-q")==0) {
verbose=0;
} else if (strcmp(argv[1], "-h")==0) {
do_usage:
fprintf(stderr, "Usage:\n%s [-v|-h]\n", argv0);
fprintf(stderr, "Usage:\n%s [-v|-h-q]\n", argv0);
exit(resultcode);
} else {
resultcode=1;
......@@ -84,7 +87,7 @@ static inline u_int32_t myrandom (void) {
}
DBT *dbt_init(DBT *dbt, void *data, u_int32_t size) {
static inline DBT *dbt_init(DBT *dbt, void *data, u_int32_t size) {
memset(dbt, 0, sizeof *dbt);
dbt->data = data;
dbt->size = size;
......@@ -101,7 +104,7 @@ DBT *dbt_init(DBT *dbt, void *data, u_int32_t size) {
*/
// extern int toku__lt_point_cmp(void* a, void* b);
void init_point(toku_point* point, toku_lock_tree* tree) {
static inline void init_point(toku_point* point, toku_lock_tree* tree) {
assert(point && tree);
memset(point, 0, sizeof(toku_point));
point->lt = tree;
......@@ -110,7 +113,7 @@ void init_point(toku_point* point, toku_lock_tree* tree) {
int mallocced = 0;
int failon = -1;
void* fail_malloc(size_t size) {
static inline void* fail_malloc(size_t size) {
if (++mallocced == failon) {
errno = ENOMEM;
return NULL;
......
......@@ -291,5 +291,6 @@ int main(int argc, const char *argv[]) {
do_range_test(toku_lt_acquire_range_read_lock);
do_range_test(toku_lt_acquire_range_write_lock);
toku_ltm_close(ltm);
return 0;
}
......@@ -2,9 +2,6 @@
#include "test.h"
toku_range_tree* toku__lt_ifexist_selfwrite(toku_lock_tree* tree, TXNID txn);
toku_range_tree* toku__lt_ifexist_selfread(toku_lock_tree* tree, TXNID txn);
int r;
toku_lock_tree* lt = NULL;
toku_ltm* ltm = NULL;
......@@ -14,14 +11,14 @@ u_int32_t max_locks = 1000;
BOOL duplicates = FALSE;
int nums[100];
DBT _key_left[2];
DBT _key_right[2];
DBT _data_left[2];
DBT _data_right[2];
DBT* key_left[2] ;
DBT* key_right[2] ;
DBT* data_left [2] ;
DBT* data_right[2] ;
DBT _keys_left[2];
DBT _keys_right[2];
DBT _datas_left[2];
DBT _datas_right[2];
DBT* keys_left[2] ;
DBT* keys_right[2] ;
DBT* datas_left[2] ;
DBT* datas_right[2] ;
toku_point qleft, qright;
toku_interval query;
......@@ -29,7 +26,7 @@ toku_range* buf;
unsigned buflen;
unsigned numfound;
void init_query(BOOL dups) {
static void init_query(BOOL dups) {
init_point(&qleft, lt);
init_point(&qright, lt);
......@@ -46,7 +43,7 @@ void init_query(BOOL dups) {
query.right = &qright;
}
void setup_tree(BOOL dups) {
static void setup_tree(BOOL dups) {
assert(!lt && !ltm);
r = toku_ltm_create(&ltm, max_locks, dbpanic,
get_compare_fun_from_db, get_dup_compare_from_db,
......@@ -61,7 +58,7 @@ void setup_tree(BOOL dups) {
init_query(dups);
}
void close_tree(void) {
static void close_tree(void) {
assert(lt && ltm);
r = toku_lt_close(lt);
CKERR(r);
......@@ -73,7 +70,7 @@ void close_tree(void) {
typedef enum { null = -1, infinite = -2, neg_infinite = -3 } lt_infty;
DBT* set_to_infty(DBT *dbt, lt_infty value) {
static DBT* set_to_infty(DBT *dbt, int value) {
if (value == infinite) return (DBT*)toku_lt_infinity;
if (value == neg_infinite) return (DBT*)toku_lt_neg_infinity;
if (value == null) return dbt_init(dbt, NULL, 0);
......@@ -82,7 +79,7 @@ DBT* set_to_infty(DBT *dbt, lt_infty value) {
}
void lt_insert(BOOL dups, int key_l, int data_l, int key_r, int data_r) {
static void lt_insert(BOOL dups, int key_l, int data_l, int key_r, int data_r) {
DBT _key_left;
DBT _key_right;
DBT _data_left;
......@@ -112,7 +109,7 @@ void lt_insert(BOOL dups, int key_l, int data_l, int key_r, int data_r) {
CKERR(r);
}
void setup_payload_len(void** payload, u_int32_t* len, int val) {
static void setup_payload_len(void** payload, u_int32_t* len, int val) {
assert(payload && len);
DBT temp;
......@@ -128,21 +125,21 @@ void setup_payload_len(void** payload, u_int32_t* len, int val) {
}
}
void temporarily_fake_comparison_functions(void) {
static void temporarily_fake_comparison_functions(void) {
assert(!lt->db && !lt->compare_fun && !lt->dup_compare);
lt->db = db;
lt->compare_fun = get_compare_fun_from_db(db);
lt->dup_compare = get_dup_compare_from_db(db);
}
void stop_fake_comparison_functions(void) {
static void stop_fake_comparison_functions(void) {
assert(lt->db && lt->compare_fun && lt->dup_compare);
lt->db = NULL;
lt->compare_fun = NULL;
lt->dup_compare = NULL;
}
void lt_find(BOOL dups, toku_range_tree* rt,
static void lt_find(BOOL dups, toku_range_tree* rt,
unsigned k, int key_l, int data_l,
int key_r, int data_r,
TXNID find_txn) {
......@@ -176,7 +173,7 @@ temporarily_fake_comparison_functions();
}
void insert_1(BOOL dups, int key_l, int key_r, int data_l, int data_r,
static void insert_1(BOOL dups, int key_l, int key_r, int data_l, int data_r,
const void* kl, const void* dl, const void* kr, const void* dr) {
DBT _key_left;
DBT _key_right;
......@@ -211,45 +208,7 @@ void insert_1(BOOL dups, int key_l, int key_r, int data_l, int data_r,
close_tree();
}
void insert_2_noclose(BOOL dups, int key_l[2], int key_r[2],
int data_l[2], int data_r[2],
const void* kl[2], const void* dl[2],
const void* kr[2], const void* dr[2]) {
int i;
setup_tree(dups);
for (i = 0; i < 2; i++) {
key_left[i] = &_key_left[i];
key_right[i] = &_key_right[i];
data_left [i] = dups ? &_data_left[i] : NULL;
data_right[i] = dups ? &_data_right[i] : NULL;
dbt_init (key_left[i], &nums[key_l[i]], sizeof(nums[key_l[i]]));
dbt_init (key_right[i], &nums[key_r[i]], sizeof(nums[key_r[i]]));
if (dups) {
dbt_init(data_left[i], &nums[data_l[i]],
sizeof(nums[data_l[i]]));
dbt_init(data_right[i], &nums[data_r[i]],
sizeof(nums[data_r[i]]));
if (dl[i]) data_left[i] = (DBT*)dl[i];
if (dr[i]) data_right[i] = (DBT*)dr[i];
}
if (kl[i]) key_left[i] = (DBT*)kl[i];
if (kr[i]) key_right[i] = (DBT*)kr[i];
r = toku_lt_acquire_range_read_lock(lt, db, txn, key_left[i], data_left[i],
key_right[i], data_right[i]);
CKERR(r);
}
}
void runtest(BOOL dups) {
static void runtest(BOOL dups) {
int i;
const DBT* choices[3];
......@@ -467,14 +426,18 @@ void runtest(BOOL dups) {
}
void init_test(void) {
static void init_test(void) {
unsigned i;
for (i = 0; i < sizeof(nums)/sizeof(nums[0]); i++) nums[i] = i;
buflen = 64;
buf = (toku_range*) toku_malloc(buflen*sizeof(toku_range));
assert(buf);
}
static void close_test(void) {
toku_free(buf);
}
......@@ -487,5 +450,6 @@ int main(int argc, const char *argv[]) {
runtest(FALSE);
runtest(TRUE);
close_test();
return 0;
}
......@@ -2,9 +2,6 @@
#include "test.h"
toku_range_tree* toku__lt_ifexist_selfwrite(toku_lock_tree* tree, TXNID txn);
toku_range_tree* toku__lt_ifexist_selfread(toku_lock_tree* tree, TXNID txn);
int r;
toku_lock_tree* lt = NULL;
toku_ltm* ltm = NULL;
......@@ -13,14 +10,14 @@ u_int32_t max_locks = 1000;
BOOL duplicates = FALSE;
int nums[100];
DBT _key_left[2];
DBT _key_right[2];
DBT _data_left[2];
DBT _data_right[2];
DBT* key_left[2];
DBT* key_right[2];
DBT* data_left [2];
DBT* data_right[2];
DBT _keys_left[2];
DBT _keys_right[2];
DBT _datas_left[2];
DBT _datas_right[2];
DBT* keys_left[2];
DBT* keys_right[2];
DBT* datas_left [2];
DBT* datas_right[2];
toku_point qleft, qright;
toku_interval query;
......@@ -28,7 +25,7 @@ toku_range* buf;
unsigned buflen;
unsigned numfound;
void init_query(BOOL dups) {
static void init_query(BOOL dups) {
init_point(&qleft, lt);
init_point(&qright, lt);
......@@ -45,7 +42,7 @@ void init_query(BOOL dups) {
query.right = &qright;
}
void setup_tree(BOOL dups) {
static void setup_tree(BOOL dups) {
assert(!lt && !ltm);
r = toku_ltm_create(&ltm, max_locks, dbpanic,
get_compare_fun_from_db, get_dup_compare_from_db,
......@@ -60,7 +57,7 @@ void setup_tree(BOOL dups) {
init_query(dups);
}
void close_tree(void) {
static void close_tree(void) {
assert(lt && ltm);
r = toku_lt_close(lt);
CKERR(r);
......@@ -72,7 +69,7 @@ void close_tree(void) {
typedef enum { null = -1, infinite = -2, neg_infinite = -3 } lt_infty;
DBT* set_to_infty(DBT *dbt, lt_infty value) {
static DBT* set_to_infty(DBT *dbt, int value) {
if (value == infinite) return (DBT*)toku_lt_infinity;
if (value == neg_infinite) return (DBT*)toku_lt_neg_infinity;
if (value == null) return dbt_init(dbt, NULL, 0);
......@@ -81,7 +78,7 @@ DBT* set_to_infty(DBT *dbt, lt_infty value) {
}
void lt_insert(BOOL dups, int r_expect, char txn, int key_l, int data_l,
static void lt_insert(BOOL dups, int r_expect, char txn, int key_l, int data_l,
int key_r, int data_r, BOOL read_flag) {
DBT _key_left;
DBT _key_right;
......@@ -118,72 +115,23 @@ void lt_insert(BOOL dups, int r_expect, char txn, int key_l, int data_l,
CKERR2(r, r_expect);
}
void lt_insert_read(BOOL dups, int r_expect, char txn, int key_l, int data_l,
static void lt_insert_read(BOOL dups, int r_expect, char txn, int key_l, int data_l,
int key_r, int data_r) {
lt_insert(dups, r_expect, txn, key_l, data_l, key_r, data_r, TRUE);
}
void lt_insert_write(BOOL dups, int r_expect, char txn, int key_l, int data_l) {
static void lt_insert_write(BOOL dups, int r_expect, char txn, int key_l, int data_l) {
lt_insert(dups, r_expect, txn, key_l, data_l, 0, 0, FALSE);
}
void setup_payload_len(void** payload, u_int32_t* len, int val) {
assert(payload && len);
DBT temp;
*payload = set_to_infty(&temp, val);
if (val < 0) {
*len = 0;
}
else {
*len = sizeof(nums[0]);
*payload = temp.data;
}
}
void lt_find(BOOL dups, toku_range_tree* rt,
unsigned k, int key_l, int data_l,
int key_r, int data_r,
char char_txn) {
r = toku_rt_find(rt, &query, 0, &buf, &buflen, &numfound);
CKERR(r);
assert(numfound==k);
TXNID find_txn = (TXNID) (size_t) char_txn;
toku_point left, right;
init_point(&left, lt);
setup_payload_len(&left.key_payload, &left.key_len, key_l);
if (dups) {
if (key_l < null) left.data_payload = left.key_payload;
else setup_payload_len(&left.data_payload, &left.data_len, data_l);
}
init_point(&right, lt);
setup_payload_len(&right.key_payload, &right.key_len, key_r);
if (dups) {
if (key_r < null) right.data_payload = right.key_payload;
else setup_payload_len(&right.data_payload, &right.data_len, data_r);
}
unsigned i;
for (i = 0; i < numfound; i++) {
if (toku__lt_point_cmp(buf[i].ends.left, &left ) == 0 &&
toku__lt_point_cmp(buf[i].ends.right, &right) == 0 &&
buf[i].data == find_txn) return;
}
assert(FALSE); //Crash since we didn't find it.
}
void lt_unlock(char ctxn) {
int r;
r = toku_lt_unlock(lt, (TXNID) (size_t) ctxn);
CKERR(r);
static void lt_unlock(char ctxn) {
int retval;
retval = toku_lt_unlock(lt, (TXNID) (size_t) ctxn);
CKERR(retval);
}
void runtest(BOOL dups) {
static void runtest(BOOL dups) {
/* ********************* */
setup_tree(dups);
......@@ -331,7 +279,7 @@ void runtest(BOOL dups) {
}
void init_test(void) {
static void init_test(void) {
unsigned i;
for (i = 0; i < sizeof(nums)/sizeof(nums[0]); i++) nums[i] = i;
......@@ -339,9 +287,9 @@ void init_test(void) {
buf = (toku_range*) toku_malloc(buflen*sizeof(toku_range));
}
static void close_test(void) {
toku_free(buf);
}
int main(int argc, const char *argv[]) {
parse_args(argc, argv);
......@@ -351,5 +299,7 @@ int main(int argc, const char *argv[]) {
runtest(FALSE);
runtest(TRUE);
close_test();
return 0;
}
......@@ -2,9 +2,6 @@
#include "test.h"
toku_range_tree* toku__lt_ifexist_selfwrite(toku_lock_tree* tree, TXNID txn);
toku_range_tree* toku__lt_ifexist_selfread(toku_lock_tree* tree, TXNID txn);
int r;
toku_lock_tree* lt = NULL;
toku_ltm* ltm = NULL;
......@@ -13,14 +10,14 @@ u_int32_t max_locks = 10;
BOOL duplicates = FALSE;
int nums[10000];
DBT _key_left[2];
DBT _key_right[2];
DBT _data_left[2];
DBT _data_right[2];
DBT* key_left[2] ;
DBT* key_right[2] ;
DBT* data_left [2] ;
DBT* data_right[2] ;
DBT _keys_left[2];
DBT _keys_right[2];
DBT _datas_left[2];
DBT _datas_right[2];
DBT* keys_left[2] ;
DBT* keys_right[2] ;
DBT* datas_left [2] ;
DBT* datas_right[2] ;
toku_point qleft, qright;
toku_interval query;
......@@ -28,7 +25,7 @@ toku_range* buf;
unsigned buflen;
unsigned numfound;
void init_query(BOOL dups) {
static void init_query(BOOL dups) {
init_point(&qleft, lt);
init_point(&qright, lt);
......@@ -45,7 +42,7 @@ void init_query(BOOL dups) {
query.right = &qright;
}
void setup_tree(BOOL dups) {
static void setup_tree(BOOL dups) {
assert(!lt && !ltm);
r = toku_ltm_create(&ltm, max_locks, dbpanic,
get_compare_fun_from_db, get_dup_compare_from_db,
......@@ -60,7 +57,7 @@ void setup_tree(BOOL dups) {
init_query(dups);
}
void close_tree(void) {
static void close_tree(void) {
assert(lt && ltm);
r = toku_lt_close(lt);
CKERR(r);
......@@ -72,7 +69,7 @@ void close_tree(void) {
typedef enum { null = -1, infinite = -2, neg_infinite = -3 } lt_infty;
DBT* set_to_infty(DBT *dbt, lt_infty value) {
static DBT* set_to_infty(DBT *dbt, int value) {
if (value == infinite) return (DBT*)toku_lt_infinity;
if (value == neg_infinite) return (DBT*)toku_lt_neg_infinity;
if (value == null) return dbt_init(dbt, NULL, 0);
......@@ -81,8 +78,8 @@ DBT* set_to_infty(DBT *dbt, lt_infty value) {
}
void lt_insert(BOOL dups, int r_expect, char txn, int key_l, int data_l,
int key_r, int data_r, BOOL read_flag) {
static void lt_insert(BOOL dups, int r_expect, char txn, int key_l, int data_l,
int key_r, int data_r, BOOL read_flag) {
DBT _key_left;
DBT _key_right;
DBT _data_left;
......@@ -118,88 +115,22 @@ void lt_insert(BOOL dups, int r_expect, char txn, int key_l, int data_l,
CKERR2(r, r_expect);
}
void lt_insert_read(BOOL dups, int r_expect, char txn, int key_l, int data_l,
int key_r, int data_r) {
static void lt_insert_read(BOOL dups, int r_expect, char txn, int key_l, int data_l,
int key_r, int data_r) {
lt_insert(dups, r_expect, txn, key_l, data_l, key_r, data_r, TRUE);
}
void lt_insert_write(BOOL dups, int r_expect, char txn, int key_l, int data_l) {
static void lt_insert_write(BOOL dups, int r_expect, char txn, int key_l, int data_l) {
lt_insert(dups, r_expect, txn, key_l, data_l, 0, 0, FALSE);
}
void setup_payload_len(void** payload, u_int32_t* len, int val) {
assert(payload && len);
DBT temp;
*payload = set_to_infty(&temp, val);
if (val < 0) {
*len = 0;
}
else {
*len = sizeof(nums[0]);
*payload = temp.data;
}
}
void temporarily_fake_comparison_functions(void) {
assert(!lt->db && !lt->compare_fun && !lt->dup_compare);
lt->db = db;
lt->compare_fun = get_compare_fun_from_db(db);
lt->dup_compare = get_dup_compare_from_db(db);
}
void stop_fake_comparison_functions(void) {
assert(lt->db && lt->compare_fun && lt->dup_compare);
lt->db = NULL;
lt->compare_fun = NULL;
lt->dup_compare = NULL;
}
void lt_find(BOOL dups, toku_range_tree* rt,
unsigned k, int key_l, int data_l,
int key_r, int data_r,
char char_txn) {
temporarily_fake_comparison_functions();
r = toku_rt_find(rt, &query, 0, &buf, &buflen, &numfound);
CKERR(r);
assert(numfound==k);
TXNID find_txn = (TXNID) (size_t) char_txn;
toku_point left, right;
init_point(&left, lt);
setup_payload_len(&left.key_payload, &left.key_len, key_l);
if (dups) {
if (key_l < null) left.data_payload = left.key_payload;
else setup_payload_len(&left.data_payload, &left.data_len, data_l);
}
init_point(&right, lt);
setup_payload_len(&right.key_payload, &right.key_len, key_r);
if (dups) {
if (key_r < null) right.data_payload = right.key_payload;
else setup_payload_len(&right.data_payload, &right.data_len, data_r);
}
unsigned i;
for (i = 0; i < numfound; i++) {
if (toku__lt_point_cmp(buf[i].ends.left, &left ) == 0 &&
toku__lt_point_cmp(buf[i].ends.right, &right) == 0 &&
buf[i].data == find_txn) { goto cleanup; }
}
assert(FALSE); //Crash since we didn't find it.
cleanup:
stop_fake_comparison_functions();
}
void lt_unlock(char ctxn) {
int r;
r = toku_lt_unlock(lt, (TXNID) (size_t) ctxn);
CKERR(r);
static void lt_unlock(char ctxn) {
int retval;
retval = toku_lt_unlock(lt, (TXNID) (size_t) ctxn);
CKERR(retval);
}
void run_escalation_test(BOOL dups) {
static void run_escalation_test(BOOL dups) {
int i = 0;
/* ******************** */
/* 1 transaction request 1000 write locks, make sure it succeeds*/
......@@ -439,7 +370,7 @@ void run_escalation_test(BOOL dups) {
/* ******************** */
}
void init_test(void) {
static void init_test(void) {
unsigned i;
for (i = 0; i < sizeof(nums)/sizeof(nums[0]); i++) nums[i] = i;
......@@ -449,9 +380,9 @@ void init_test(void) {
dup_compare = intcmp;
}
static void close_test(void) {
toku_free(buf);
}
int main(int argc, const char *argv[]) {
parse_args(argc, argv);
......@@ -461,5 +392,7 @@ int main(int argc, const char *argv[]) {
run_escalation_test(FALSE);
run_escalation_test(TRUE);
close_test();
return 0;
}
/* Test for a memory leak from just closing the lock tree manager (should close
all lock trees. */
#include "portability.h"
#include <fcntl.h>
#include "test.h"
toku_range_tree* toku__lt_ifexist_selfwrite(toku_lock_tree* tree, DB_TXN* txn);
#include <unistd.h>
int r;
toku_lock_tree* lt [10] = {0};
......@@ -13,7 +14,7 @@ u_int32_t max_locks = 10;
BOOL duplicates = FALSE;
int nums[10000];
void setup_ltm(void) {
static void setup_ltm(void) {
assert(!ltm);
r = toku_ltm_create(&ltm, max_locks, dbpanic,
get_compare_fun_from_db, get_dup_compare_from_db,
......@@ -22,7 +23,7 @@ void setup_ltm(void) {
assert(ltm);
}
void setup_tree(BOOL dups, size_t index, toku_db_id* db_id) {
static void setup_tree(BOOL dups, size_t index, toku_db_id* db_id) {
assert(!lt[index] && ltm);
r = toku_ltm_get_lt(ltm, &lt[index], dups, db_id);
CKERR(r);
......@@ -30,7 +31,7 @@ void setup_tree(BOOL dups, size_t index, toku_db_id* db_id) {
}
void close_ltm(void) {
static void close_ltm(void) {
assert(ltm);
r = toku_ltm_close(ltm);
CKERR(r);
......@@ -39,19 +40,22 @@ void close_ltm(void) {
ltm = NULL;
}
void run_test(BOOL dups) {
static void run_test(BOOL dups) {
int fd = open(TESTDIR "/file.db", O_CREAT|O_RDWR, S_IRWXU);
assert(fd>=0);
toku_db_id* db_id = NULL;
r = toku_db_id_create(&db_id, DIR, "subdb");
r = toku_db_id_create(&db_id, fd, "subdb");
CKERR(r);
assert(db_id);
toku_db_id* db_id2 = NULL;
r = toku_db_id_create(&db_id2, DIR, "subdb2");
r = toku_db_id_create(&db_id2, fd, "subdb2");
CKERR(r);
assert(db_id);
toku_db_id* db_id3 = NULL;
r = toku_db_id_create(&db_id3, DIR, "subdb");
r = toku_db_id_create(&db_id3, fd, "subdb");
CKERR(r);
assert(db_id);
......@@ -74,9 +78,10 @@ void run_test(BOOL dups) {
assert(lt[4] == lt[5]);
close_ltm();
toku_db_id_remove_ref(db_id);
toku_db_id_remove_ref(db_id2);
toku_db_id_remove_ref(db_id3);
toku_db_id_remove_ref(&db_id);
toku_db_id_remove_ref(&db_id2);
toku_db_id_remove_ref(&db_id3);
close(fd);
}
int main(int argc, const char *argv[]) {
......@@ -84,8 +89,8 @@ int main(int argc, const char *argv[]) {
compare_fun = intcmp;
dup_compare = intcmp;
system("rm -rf " DIR);
mkdir(DIR, 0777);
system("rm -rf " TESTDIR);
os_mkdir(TESTDIR, S_IRWXU|S_IRWXG|S_IRWXO);
run_test(FALSE);
run_test(TRUE);
......
/* Test for a memory leak from just closing the lock tree manager (should close
all lock trees. */
#include "portability.h"
#include <fcntl.h>
#include "test.h"
#include <unistd.h>
static void initial_setup(void);
......@@ -13,6 +16,7 @@ static toku_db_id* db_ids[100];
static char subdb [100][5];
static u_int32_t max_locks = 10;
int nums[10000];
int fd;
static void setup_ltm(void) {
assert(!ltm);
......@@ -111,6 +115,7 @@ static void run_test(BOOL dups) {
static void initial_setup(void) {
u_int32_t i;
fd = open(TESTDIR "/file.db", O_CREAT|O_RDWR, S_IRWXU);
ltm = NULL;
assert(sizeof(db_ids) / sizeof(db_ids[0]) == sizeof(lts) / sizeof(lts[0]));
......@@ -118,19 +123,29 @@ static void initial_setup(void) {
for (i = 0; i < sizeof(lts) / sizeof(lts[0]); i++) {
lts[i] = NULL;
sprintf(subdb[i], "%05x", i);
if (!db_ids[i]) toku_db_id_create(&db_ids[i], DIR, subdb[i]);
if (!db_ids[i]) toku_db_id_create(&db_ids[i], fd, subdb[i]);
assert(db_ids[i]);
lt_refs[i] = 0;
}
}
static void close_test(void) {
u_int32_t i;
for (i = 0; i < sizeof(lts) / sizeof(lts[0]); i++) {
assert(lt_refs[i]==0); //The internal reference isn't counted.
assert(db_ids[i]);
toku_db_id_remove_ref(&db_ids[i]);
assert(!db_ids[i]);
}
}
int main(int argc, const char *argv[]) {
parse_args(argc, argv);
compare_fun = intcmp;
dup_compare = intcmp;
system("rm -rf " DIR);
mkdir(DIR, 0777);
system("rm -rf " TESTDIR);
os_mkdir(TESTDIR, S_IRWXU|S_IRWXG|S_IRWXO);
initial_setup();
......@@ -138,5 +153,7 @@ int main(int argc, const char *argv[]) {
run_test(TRUE);
close(fd);
close_test();
return 0;
}
# On OSX do:
# make OSX=OSX
# -*- Mode: Makefile -*-
OPTFLAGS = -O3 -finline-functions
.DEFAULT_GOAL= build
TOKUROOT=../../
INCLUDEDIRS=-I. -I$(TOKUROOT)newbrt
DEPEND_COMPILE+= \
*.h \
#end
LIBNAME=libtokurange
SKIP_RANGETREERULE=1
VISIBILITY = #-fvisibility=hidden
include $(TOKUROOT)include/Makefile.include
ifneq ($(GCOV),)
GCOV_FLAGS = -fprofile-arcs -ftest-coverage
else
GCOV_FLAGS =
endif
RANGETREE = rangetree.$(AEXT)
RANGETREE_LINEAR = rangetree_linear.$(AEXT)
RANGETREE_TLOG = rangetree_tlog.$(AEXT)
RANGETREE_LOG = rangetree_log.$(AEXT)
CFLAGS = -Werror -Wall -fPIC $(OPTFLAGS) $(GCOV_FLAGS)
ifneq ($(CC),icc)
CFLAGS += -W -Wextra -g3 -ggdb3
CFLAGS += -Wbad-function-cast -Wcast-align -Wconversion -Waggregate-return
CFLAGS += -Wmissing-noreturn -Wmissing-format-attribute
else
CFLAGS += -g
CFLAGS += -diag-disable 589 # Don't complain about goto into a block that skips initializing variables. GCC catches the actual uninitialized variables.
endif
CPPFLAGS = -I. -I../../include -I../../newbrt
CPPFLAGS += -D_GNU_SOURCE -D_THREAD_SAFE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
CFLAGS += $(VISIBILITY) $(PROF_FLAGS)
LDFLAGS += -lpthread
ifneq ($(OSX),)
CFLAGS+=-fno-common
endif
#This line is so we can have a \ at the end of the previous.
BINS = linear.o log_nooverlap.o rangetree.o #log.o
RANGETREE =rangetree.$(AEXT)
build: $(BINS)
cd tests;$(MAKE) build
LIBRARIES=$(RANGETREE_LINEAR) $(RANGETREE_TLOG) $(RANGETREE) # $(RANGETREE_LOG)
check:
cd tests;$(MAKE) check
$(RANGETREE_TLOG): log_nooverlap.$(OEXT)
$(RANGETREE_LINEAR): linear.$(OEXT)
$(RANGETREE_LOG): log.$(OEXT)
.PHONY: install
install: $(BINS)
$(RANGETREE): $(RANGETREE_TLOG)
$(MAYBEATSIGN)cp $< $@
clean:
rm -rf *.o *.gcno *.gcda *.gcov
cd tests && $(MAKE) clean
.PHONY: build check
build: $(LIBRARIES)
rangetree.o: log_nooverlap.o
cp $< $@
HEADERS=rangetree.h rangetree-internal.h
linear.o: linear.c $(HEADERS)
log.o: log.c $(HEADERS)
log_nooverlap.o: log_nooverlap.c $(HEADERS)
build check clean:
$(MAYBEATSIGN)cd tests;$(MAKE) $@
......@@ -19,6 +19,7 @@
*/
//Defines BOOL data type.
#include "portability.h"
#include <brttypes.h>
#include <db.h>
......
# On OSX do:
# make OSX=OSX
# -*- Mode: Makefile -*-
# For verbose output do
# make VERBOSE=1
# For very verbose output do
# make VERBOSE=2
.DEFAULT_GOAL= build
TOKUROOT=../../../
INCLUDEDIRS=-I. -I../ -I$(TOKUROOT)newbrt
DEPEND_COMPILE+=../rangetree.h ../rangetree-internal.h test.h
NEWBRT=$(TOKUROOT)newbrt/newbrt.$(AEXT)
DEPEND_COMPILE+=$(NEWBRT)
ifeq ($(OSX),)
VGRIND=valgrind --quiet --error-exitcode=1 --leak-check=yes
endif
LINK_FILES=$(NEWBRT)
include $(TOKUROOT)include/Makefile.include
OPTFLAGS=-O0
# GCOV_FLAGS = -fprofile-arcs -ftest-coverage
CFLAGS = -Werror -Wall $(OPTFLAGS) $(GCOV_FLAGS)
ifneq ($(CC),icc)
CFLAGS += -W -Wextra -g3 -ggdb3
CFLAGS += -Wbad-function-cast -Wcast-align -Wconversion -Waggregate-return
CFLAGS += -Wmissing-noreturn -Wmissing-format-attribute
else
CFLAGS += -g
CFLAGS += -diag-disable 981 # Don't complain about "operands are evaluated in unspecified order". This seems to be generated whenever more than one argument to a function or operand is computed by function call.
ifeq ($(CC),icc)
SKIP_WARNING += $(ICC_NOWARN)1418 #Non static functions do not need prototypes.
endif
CPPFLAGS += -I../ -I../../../newbrt -I../../../include
LDFLAGS = -lpthread
SRCS = $(wildcard *.c)
LOG_TESTS = $(patsubst %.c,%.log,$(SRCS))
TLOG_TESTS = $(patsubst %.c,%.tlog,$(SRCS))
LIN_TESTS = $(patsubst %.c,%.lin,$(SRCS))
LOG_TESTS = $(patsubst %.c,%.log$(BINSUF),$(SRCS))
TLOG_TESTS = $(patsubst %.c,%.tlog$(BINSUF),$(SRCS))
LIN_TESTS = $(patsubst %.c,%.lin$(BINSUF),$(SRCS))
ALL_TESTS = $(LIN_TESTS) $(LOG_TESTS) $(TLOG_TESTS)
ALL_TESTS = $(LIN_TESTS) $(TLOG_TESTS) #$(LOG_TESTS)
RUN_LOG_TESTS = $(patsubst %.log,%.logrun,$(LOG_TESTS))
RUN_TLOG_TESTS = $(patsubst %.tlog,%.tlogrun,$(TLOG_TESTS))
RUN_LIN_TESTS = $(patsubst %.lin,%.linrun,$(LIN_TESTS))
RUN_ALL_TESTS = $(RUN_LIN_TESTS) $(RUN_TLOG_TESTS) $(RUN_LOG_TESTS)
RUN_LOG_TESTS = $(patsubst %.log$(BINSUF),%.logrun,$(LOG_TESTS))
RUN_TLOG_TESTS = $(patsubst %.tlog$(BINSUF),%.tlogrun,$(TLOG_TESTS))
RUN_LIN_TESTS = $(patsubst %.lin$(BINSUF),%.linrun,$(LIN_TESTS))
RUN_ALL_TESTS = $(RUN_LIN_TESTS) $(RUN_TLOG_TESTS) #$(RUN_LOG_TESTS)
.PHONY: default all check tests check.lin check.tlog check.log tests.lin tests.log tests.tlog
default: build
all build: $(ALL_TESTS)
default all build: $(ALL_TESTS)
check: check.lin check.tlog #check.log
@ echo $@ ok
tests: tests.lin tests.tlog #tests.log
@ echo $@ ok
tests.lin: $(LIN_TESTS)
@ echo $@ ok
check: $(RUN_ALL_TESTS)
tests: $(ALL_TESTS)
tests.lin: $(LIN_TESTS)
check.lin: $(RUN_LIN_TESTS)
@ echo $@ ok
tests.tlog: $(TLOG_TESTS)
@ echo $@ ok
check.tlog: $(RUN_TLOG_TESTS)
@ echo $@ ok
tests.log: $(LOG_TESTS)
@ echo $@ ok
check.log: $(RUN_LOG_TESTS)
@ echo $@ ok
# Need these rule so that Make knows about all the file names
.PHONY: %.linrun %.logrun %.run %.tlogrun
$(RUN_ALL_TESTS):
$(ALL_TESTS):
%.run: %.linrun %.tlogrun %.logrun
@ echo ok
ifeq ($(VERBOSE),2)
VERBVERBOSE=-v
MAYBEATSIGN=
VERBQUIET=
else
ifeq ($(VERBOSE),1)
VERBVERBOSE=
MAYBEATSIGN=
VERBQUIET=
else
VERBVERBOSE=
MAYBEATSIGN=@
VERBQUIET=--quiet
endif
endif
# STUFF!!!!
# The @ sign makes the make quiet. If there is an error there is enough info to tell what test failed.
%.linrun: %.lin
$(MAYBEATSIGN) $(VGRIND) ./$< $(VERBVERBOSE)
%.logrun: %.log
$(MAYBEATSIGN) $(VGRIND) ./$< $(VERBVERBOSE)
%.tlogrun: %.tlog
$(MAYBEATSIGN) $(VGRIND) ./$< $(VERBVERBOSE)
%.run: %.linrun %.tlogrun #%.logrun
LINEAR_BINS = ../linear.o ../../../newbrt/newbrt.o
TLOG_BINS = ../log_nooverlap.o ../../../newbrt/newbrt.o
LOG_BINS = ../log.o ../../../newbrt/newbrt.o
HEADERS=../rangetree.h ../rangetree-internal.h test.h
%.linrun: %.lin$(BINSUF)
$(MAYBEATSIGN) $(VGRIND) ./$< $(VERBVERBOSE) $(SUMMARIZE_CMD)
%.tlogrun: %.tlog$(BINSUF)
$(MAYBEATSIGN) $(VGRIND) ./$< $(VERBVERBOSE) $(SUMMARIZE_CMD)
%.logrun: %.log$(BINSUF)
$(MAYBEATSIGN) $(VGRIND) ./$< $(VERBVERBOSE) $(SUMMARIZE_CMD)
../../../newbrt/newbrt.o:
cd ../../../newbrt && $(MAKE)
A_LINEAR=$(RANGETREE_LINEAR)
A_TLOG =$(RANGETREE_TLOG)
A_LOG =$(RANGETREE_LOG)
LDFLAGS = -lz -lpthread
%.lin$(BINSUF): %.c $(DEPEND_COMPILE) $(DEPEND_LINK) $(A_LINEAR)
$(MAYBEATSIGN)$(CC) -DTESTDIR=\"dir.$<.lin\" $< $(A_LINEAR) $(BIN_FROM_C_FLAGS)
%.lin: %.c $(HEADERS) $(LINEAR_BINS)
$(CC) -DDIR=\"dir.$<.lin\" $(CFLAGS) $(CPPFLAGS) $< -o $@ $(LINEAR_BINS) $(LDFLAGS)
%.tlog: %.c $(HEADERS) $(TLOG_BINS)
$(CC) -DDIR=\"dir.$<.log\" $(CFLAGS) $(CPPFLAGS) $< -o $@ $(TLOG_BINS) -DTOKU_RT_NOOVERLAPS $(LDFLAGS)
%.log: %.c $(HEADERS) $(LOG_BINS)
$(CC) -DDIR=\"dir.$<.log\" $(CFLAGS) $(CPPFLAGS) $< -o $@ $(LOG_BINS) $(LDFLAGS)
%.tlog$(BINSUF): %.c $(DEPEND_COMPILE) $(DEPEND_LINK) $(A_TLOG)
$(MAYBEATSIGN)$(CC) -DTESTDIR=\"dir.$<.tlog\" $< $(A_TLOG) $(BIN_FROM_C_FLAGS) -DTOKU_RT_NOOVERLAPS
%.log$(BINSUF): %.c $(DEPEND_COMPILE) $(DEPEND_LINK) $(A_LOG)
$(MAYBEATSIGN)$(CC) -DTESTDIR=\"dir.$<.log\" $< $(A_LOG) $(BIN_FROM_C_FLAGS)
clean:
rm -f $(ALL_TESTS) *.o *.gcno *.gcda *.gcov
rm -rf dir.*.log dir.*.LIN
$(MAYBEATSIGN)rm -f $(ALL_TESTS)
$(MAYBEATSIGN)rm -rf dir.*.lin dir.*.tlog dir.*.log
......@@ -8,8 +8,8 @@
#include "../../../newbrt/memory.h"
int verbose=0;
#define CKERR(r) ({ if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, strerror(r)); assert(r==0); })
#define CKERR2(r,r2) ({ if (r!=r2) fprintf(stderr, "%s:%d error %d %s, expected %d\n", __FILE__, __LINE__, r, strerror(r), r2); assert(r==r2); })
#define CKERR(r) do { if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, strerror(r)); assert(r==0); } while (0)
#define CKERR2(r,r2) do { if (r!=r2) fprintf(stderr, "%s:%d error %d %s, expected %d\n", __FILE__, __LINE__, r, strerror(r), r2); assert(r==r2); } while (0)
static inline void
parse_args (int argc, const char *argv[]) {
......@@ -18,9 +18,11 @@ parse_args (int argc, const char *argv[]) {
int resultcode=0;
if (strcmp(argv[1], "-v")==0) {
verbose++;
} else if (strcmp(argv[1], "-q")==0) {
verbose=0;
} else if (strcmp(argv[1], "-h")==0) {
do_usage:
fprintf(stderr, "Usage:\n%s [-v|-h]\n", argv0);
fprintf(stderr, "Usage:\n%s [-v|-h|-q]\n", argv0);
exit(resultcode);
} else {
resultcode=1;
......
......@@ -7,6 +7,7 @@
* The trace file ends up in the cwd.
*/
#include "portability.h"
#include "../include/db.h"
#include "toku_assert.h"
#include "memory.h"
......@@ -14,23 +15,19 @@
#include "ydb-internal.h"
#include <errno.h>
#include <pthread.h>
#include <toku_pthread.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
static pthread_mutex_t tdb_big_lock = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
#else
static pthread_mutex_t tdb_big_lock = PTHREAD_MUTEX_INITIALIZER;
#endif
static toku_pthread_mutex_t tdb_big_lock = TOKU_PTHREAD_MUTEX_INITIALIZER;
static void tlock(void) {
int r = pthread_mutex_lock(&tdb_big_lock); assert(r == 0);
int r = toku_pthread_mutex_lock(&tdb_big_lock); assert(r == 0);
}
static void tunlock(void) {
int r = pthread_mutex_unlock(&tdb_big_lock); assert(r == 0);
int r = toku_pthread_mutex_unlock(&tdb_big_lock); assert(r == 0);
}
static FILE *tracefile = 0;
......@@ -127,7 +124,7 @@ static int tokutrace_env_close (DB_ENV *env, u_int32_t flags) {
if (*ptr) {
assert((*ptr)->tt==TT_ENV);
if (tracefile) {
fprintf(tracefile, "env_close %d %d %d\n", r, (*ptr)->itemnum, flags);
fprintf(tracefile, "env_close %d %d %u\n", r, (*ptr)->itemnum, flags);
}
struct tracepair *hold=*ptr;
*ptr=(*ptr)->next;
......@@ -138,6 +135,7 @@ static int tokutrace_env_close (DB_ENV *env, u_int32_t flags) {
tunlock();
return r;
}
static void tokutrace_env_err(const DB_ENV * env, int error, const char *fmt, ...) __attribute__((format (printf, 3, 0)));
static void tokutrace_env_err(const DB_ENV * env, int error, const char *fmt, ...) {
// Don't need to trace the err call.
tlock();
......@@ -157,7 +155,7 @@ static int tokutrace_env_get_cachesize (DB_ENV *env, u_int32_t *gbytes, u_int32_
struct tracepair *ep = find_envpair(env, &itemnum);
if (env==0 || ep) {
if (r==0) {
fprintf(tracefile, "env_get_cachesize %d %d %d %d %d\n", r, itemnum, *gbytes, *bytes, *ncache);
fprintf(tracefile, "env_get_cachesize %d %d %u %u %d\n", r, itemnum, *gbytes, *bytes, *ncache);
} else {
fprintf(tracefile, "env_get_cachesize %d %d %d %d %d\n", r, itemnum, -1, -1, -1);
}
......@@ -182,7 +180,7 @@ static int tokutrace_env_open (DB_ENV *env, const char *home, u_int32_t flags, i
if (tracefile) {
int itemnum;
find_envpair(env, &itemnum);
fprintf(tracefile, "env_open %d %d %s %d %d\n", r, itemnum, home, flags, mode);
fprintf(tracefile, "env_open %d %d %s %u %d\n", r, itemnum, home, flags, mode);
}
tunlock();
return r;
......@@ -203,7 +201,7 @@ int db_env_create(DB_ENV ** envp, u_int32_t flags) {
#define SE(name) result->name = tokutrace_env_ ## name;
SE(close);
SE(err);
result->err = (void (*)(const DB_ENV *, int, const char *, ...)) tokutrace_env_err;
SE(get_cachesize);
//SE(get_flags);
//SE(get_lk_max_locks);
......@@ -232,7 +230,7 @@ int db_env_create(DB_ENV ** envp, u_int32_t flags) {
if (tracefile) {
struct tracepair *pair = create_tracepair(result, TT_ENV);
fprintf(tracefile, "db_env_create %d %d %d\n", 0, pair->itemnum, flags);
fprintf(tracefile, "db_env_create %d %d %u\n", 0, pair->itemnum, flags);
}
......@@ -245,7 +243,7 @@ static int tokutrace_db_set_flags(DB *db, u_int32_t flags) {
DB *d = (DB*)db->i;
int r = d->set_flags(d, flags);
if (tracefile) {
fprintf(tracefile, "db_set_flags %d %d %d\n", r, dbpairnum(db), flags);
fprintf(tracefile, "db_set_flags %d %d %u\n", r, dbpairnum(db), flags);
}
tunlock();
return r;
......@@ -256,7 +254,7 @@ static int tokutrace_db_set_pagesize(DB *db, u_int32_t pagesize) {
DB *d = (DB*)db->i;
int r = d->set_pagesize(d, pagesize);
if (tracefile) {
fprintf(tracefile, "db_set_pagesize %d %d %d\n", r, dbpairnum(db), pagesize);
fprintf(tracefile, "db_set_pagesize %d %d %u\n", r, dbpairnum(db), pagesize);
}
tunlock();
return r;
......@@ -267,7 +265,7 @@ static int tokutrace_db_open(DB * db, DB_TXN * txn, const char *fname, const cha
DB *d = (DB*)db->i;
int r = d->open(d, txn ? (DB_TXN*)txn->i : 0, fname, dbname, dbtype, flags, mode);
if (tracefile) {
fprintf(tracefile, "db_open %d %d %d %s %s %d %d %d\n",
fprintf(tracefile, "db_open %d %d %d %s %s %d %u %d\n",
r,
dbpairnum(db), txnpairnum(txn), fname, dbname, dbtype, flags, mode);
}
......@@ -279,7 +277,7 @@ static int tokutrace_db_close (DB *db, u_int32_t flags) {
tlock();
DB *d = (DB*)db->i;
int r = d->close(d, flags);
if (tracefile) fprintf(tracefile, "db_close %d %d %d\n", r, dbpairnum(db), flags);
if (tracefile) fprintf(tracefile, "db_close %d %d %u\n", r, dbpairnum(db), flags);
tunlock();
return r;
}
......@@ -292,7 +290,7 @@ static void trace_char (unsigned char ch) {
}
static void trace_dbt (DBT *v) {
fprintf(tracefile,"{%d ", v->size);
fprintf(tracefile,"{%u ", v->size);
unsigned int i;
for (i=0; i<v->size; i++) trace_char(((unsigned char*)v->data)[i]);
fprintf(tracefile," }");
......@@ -313,7 +311,7 @@ static int tokutrace_db_put(DB * db, DB_TXN * txn, DBT * key, DBT * data, u_int3
trace_dbt(key);
fprintf(tracefile, " ");
trace_dbt(data);
fprintf(tracefile, " %d\n", flags);
fprintf(tracefile, " %u\n", flags);
}
tunlock();
return r;
......@@ -331,7 +329,7 @@ static int tokutrace_db_get (DB * db, DB_TXN * txn, DBT * key, DBT * data, u_int
trace_dbt(key);
fprintf(tracefile, " ");
trace_dbt(data);
fprintf(tracefile, " %d\n", flags);
fprintf(tracefile, " %u\n", flags);
}
tunlock();
return r;
......@@ -350,7 +348,7 @@ static int tokutrace_dbc_c_get(DBC * c, DBT * key, DBT * data, u_int32_t flag) {
trace_dbt(key);
fprintf(tracefile, " ");
trace_dbt(data);
fprintf(tracefile, " %d\n", flag);
fprintf(tracefile, " %u\n", flag);
}
break;
default:
......@@ -380,7 +378,7 @@ static int tokutrace_db_cursor(DB *db, DB_TXN *txn, DBC **c, u_int32_t flags) {
int r = native_db->cursor(native_db, native_txn, &native_cursor, flags);
if (tracefile) {
struct tracepair *pair = create_tracepair(result, TT_DBC);
fprintf(tracefile, "db_cursor %d %d %d %d %d\n",
fprintf(tracefile, "db_cursor %d %d %d %d %u\n",
r, dbpairnum(db), txnpairnum(txn), pair->itemnum, flags);
}
tunlock();
......@@ -416,7 +414,7 @@ int db_create(DB **dbp, DB_ENV *env, u_int32_t flags) {
struct tracepair *pair = create_tracepair(result, TT_DB);
int envitemnum;
find_envpair(env, &envitemnum);
fprintf(tracefile, "db_create %d %d %d %d\n", 0, pair->itemnum, envitemnum, flags);
fprintf(tracefile, "db_create %d %d %d %u\n", 0, pair->itemnum, envitemnum, flags);
}
tunlock();
return r;
......
#ifndef TDB_TRACE_H
#define TDB_TRACE_H
int db_env_create_toku10(DB_ENV ** envp, u_int32_t flags);
int db_create_toku10 (DB **, DB_ENV *, u_int32_t flags);
#endif
This diff is collapsed.
// This file defines the public interface to the ydb library
#if !defined(TOKU_YDB_INTERFACE_H)
#define TOKU_YDB_INTERFACE_H
// Initialize the ydb library globals.
// Called when the ydb library is loaded.
void toku_ydb_init(void);
// Called when the ydb library is unloaded.
void toku_ydb_destroy(void);
#endif
#include <stdio.h>
#include "ydb.h"
#if defined(__GNUC__)
static void __attribute__((constructor)) libtokudb_init(void) {
// printf("%s:%s:%d\n", __FILE__, __FUNCTION__, __LINE__);
toku_ydb_init();
}
static void __attribute__((destructor)) libtokudb_destroy(void) {
// printf("%s:%s:%d\n", __FILE__, __FUNCTION__, __LINE__);
toku_ydb_destroy();
}
#endif
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#define UNUSED(x) x=x
BOOL WINAPI DllMain(HINSTANCE h, DWORD reason, LPVOID reserved) {
UNUSED(h); UNUSED(reserved);
// printf("%s:%lu\n", __FUNCTION__, reason);
if (reason == DLL_PROCESS_ATTACH)
toku_ydb_init();
if (reason == DLL_PROCESS_DETACH)
toku_ydb_destroy();
return TRUE;
}
#endif
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