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