Commit 8c6feda0 authored by Yoni Fogel's avatar Yoni Fogel

Addresses #307 Addresses #293

Modified makefiles to clean up install process
Added tests
Added hash table to store list of db's that a tx has access to.

git-svn-id: file:///svn/tokudb@2130 c7de825b-a66e-492c-adef-691d508d4ae1
parent 5696d79c
......@@ -8,7 +8,6 @@ OPTFLAGS = -O2
CFLAGS = -W -Wall -Werror -g3 -ggdb3 -fPIC $(OPTFLAGS) $(GCOV_FLAGS)
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
CPPFLAGS += -L../lib
ifeq ($(OSX),OSX)
......@@ -26,10 +25,10 @@ install: logformat locktree $(LIBNAME).$(LIBEXT) $(LIBNAME).a
cp $(LIBNAME).a ../lib
logformat:
(cd ../newbrt;make)
(cd ../newbrt && make)
locktree:
cd lock_tree;make OSX=$(OSX) OPT=$(OPT) GCOV=$(GCOV)
cd lock_tree && make
check: $(LIBNAME).$(LIBEXT)
python tokuglobals.py $(LIBNAME).$(LIBEXT)
......@@ -39,19 +38,22 @@ strip: $(LIBNAME).$(LIBEXT)
clean:
rm -rf $(LIBNAME).$(LIBEXT) $(LIBNAME).a *.o *.gcno *.gcda *.gcov
cd tests;make clean
cd lock_tree;make clean
cd tests && make clean
cd lock_tree && make clean
ydb.o: ../include/db.h ../newbrt/cachetable.h ../newbrt/brt.h ../newbrt/log.c
DBBINS = ydb.o ../newbrt/brt.o ../newbrt/brt-serialize.o ../newbrt/brt-verify.o ../newbrt/cachetable.o ../newbrt/fifo.o ../newbrt/key.o ../newbrt/memory.o ../newbrt/mempool.o ../newbrt/pma.o ../newbrt/ybt.o ../newbrt/primes.o ../newbrt/log.o ../newbrt/fingerprint.o ../newbrt/log_code.o ../newbrt/roll.o
RANGETREE_BINS = range_tree/linear.o
LOCKTREE_BINS = lock_tree/locktree.o lock_tree/rth.o lock_tree/lth.o $(RANGETREE_BINS)
$(LIBNAME).$(LIBEXT): $(DBBINS)
cc $(CPPFLAGS) $^ $(SHARED) -o $@ $(CFLAGS) -lz -llocktree_linear
$(LIBNAME).a: $(DBBINS) lock_tree/locktree.o lock_tree/rth.o range_tree/linear.o
$(LIBNAME).$(LIBEXT): $(DBBINS) $(LOCKTREE_BINS)
cc $(CPPFLAGS) $^ $(SHARED) -o $@ $(CFLAGS) -lz
$(LIBNAME).a: $(DBBINS) $(LOCKTREE_BINS)
$(AR) rv $@ $^
libdb.a(ydb.o): ydb.o
......@@ -5,11 +5,7 @@ LIBNAME_LINEAR = liblocktree_linear
LIBNAME_TLOG = liblocktree_tlog
LIBNAME_LOG = liblocktree_log
ifneq ($(OPT),)
OPTFLAGS = -O0 -g3 -ggdb3
else
OPTFLAGS = -O2 -g3 -ggdb3
endif
OPTFLAGS = -O2
ifneq ($(GCOV),)
GCOV_FLAGS = -fprofile-arcs -ftest-coverage
......@@ -17,7 +13,7 @@ else
GCOV_FLAGS =
endif
CFLAGS = -W -Wall -Wextra -Werror -fPIC $(OPTFLAGS) $(GCOV_FLAGS)
CFLAGS = -W -Wall -Wextra -Werror -fPIC $(OPTFLAGS) -g3 -ggdb3 $(GCOV_FLAGS)
CFLAGS += -Wbad-function-cast -Wcast-align -Wconversion -Waggregate-return
CFLAGS += -Wmissing-noreturn -Wmissing-format-attribute
CPPFLAGS = -I. -I.. -I../range_tree -I../../include -I../../newbrt -L../range_tree
......@@ -35,47 +31,45 @@ endif
.PHONY: install logformat range_tree
install: range_tree $(LIBNAME_LINEAR).$(LIBEXT) $(LIBNAME_LINEAR).a #$(LIBNAME_TLOG).$(LIBEXT) $(LIBNAME_TLOG).a $(LIBNAME_LOG).$(LIBEXT) $(LIBNAME_LOG).a
cp $(LIBNAME_LINEAR).$(LIBEXT) ../../lib/
cp $(LIBNAME_LINEAR).a ../../lib
#cp $(LIBNAME_TLOG).$(LIBEXT) ../../lib/
#cp $(LIBNAME_TLOG).a ../../lib
#cp $(LIBNAME_LOG).$(LIBEXT) ../../lib/
#cp $(LIBNAME_LOG).a ../../lib
range_tree:
cd ../range_tree; make
cd ../range_tree && make
clean:
cd ../range_tree; make clean
cd ../range_tree && make clean
rm -rf *.o
rm -rf $(LIBNAME_LINEAR).$(LIBEXT) $(LIBNAME_LINEAR).a
rm -rf $(LIBNAME_TLOG).$(LIBEXT) $(LIBNAME_TLOG).a
rm -rf $(LIBNAME_LOG).$(LIBEXT) $(LIBNAME_LOG).a
rm -rf *.gcno *.gcda *.gcov
cd tests;make clean
cd tests && make clean
BINS = locktree.o rth.o lth.o
locktree.o: locktree.c locktree.h
gcc $(CFLAGS) $(CPPFLAGS) -DTOKU_LT_LINEAR -c $< -o $@
rth.o: rth.c rth.h
gcc $(CFLAGS) $(CPPFLAGS) -DTOKU_RT_LINEAR -c $< -o $@
gcc $(CFLAGS) $(CPPFLAGS) -c $< -o $@
lth.o: lth.c lth.h
gcc $(CFLAGS) $(CPPFLAGS) -c $< -o $@
$(LIBNAME_LINEAR).$(LIBEXT): locktree.o rth.o
$(LIBNAME_LINEAR).$(LIBEXT): $(BINS)
cc $(CPPFLAGS) $^ $(SHARED) -o $@ $(CFLAGS) -lrangetree_linear
$(LIBNAME_LINEAR).a: locktree.o rth.o ../range_tree/linear.o
$(LIBNAME_LINEAR).a: $(BINS) ../range_tree/linear.o
$(AR) rv $@ $^
$(LIBNAME_TLOG).$(LIBEXT): locktree.o rth.o
$(LIBNAME_TLOG).$(LIBEXT): $(BINS)
cc $(CPPFLAGS) $^ $(SHARED) -o $@ $(CFLAGS) -lrangetree_tlog
$(LIBNAME_TLOG).a: locktree.o rth.o ../range_tree/tlog.o
$(LIBNAME_TLOG).a: $(BINS) ../range_tree/tlog.o
$(AR) rv $@ $^
$(LIBNAME_LOG).$(LIBEXT): locktree.o rth.o
$(LIBNAME_LOG).$(LIBEXT): $(BINS)
cc $(CPPFLAGS) $^ $(SHARED) -o $@ $(CFLAGS) -lrangetree_log
$(LIBNAME_LOG).a: locktree.o rth.o ../range_tree/log.o
$(LIBNAME_LOG).a: $(BINS) ../range_tree/log.o
$(AR) rv $@ $^
......@@ -3,6 +3,9 @@
#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."
#if !defined(TOKU_LOCKTREE_H)
#define TOKU_LOCKTREE_H
/**
\file locktree.h
\brief Lock trees: header and comments
......@@ -55,6 +58,7 @@ typedef enum {
char* toku_lt_strerror(TOKU_LT_ERROR r) __attribute__((const,pure));
#define TOKU_LOCK_TREE_DEFINED
/** \brief The lock tree structure */
typedef struct __toku_lock_tree {
/** The database for which this locktree will be handling locks */
......@@ -367,3 +371,5 @@ int toku_lt_acquire_range_write_lock(toku_lock_tree* tree, DB_TXN* txn,
* *** Note that txn == NULL is not supported at this time.
*/
int toku_lt_unlock(toku_lock_tree* tree, DB_TXN* txn);
#endif
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007-8 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
/**
\file hash_table.h
\brief Hash table
*/
#include "lth.h"
#include <assert.h>
#include <errno.h>
#include <string.h>
/* TODO: reallocate the hash table if it grows too big. Perhaps, use toku_get_prime in newbrt/primes.c */
const uint32 __toku_lth_init_size = 521;
static inline uint32 __toku_lth_hash(toku_lth* table, toku_lock_tree* key) {
size_t tmp = (size_t)key;
return tmp % table->array_size;
}
static inline void __toku_invalidate_scan(toku_lth* table) {
table->finger_end = TRUE;
}
int toku_lth_create(toku_lth** ptable,
void* (*user_malloc) (size_t),
void (*user_free) (void*),
void* (*user_realloc)(void*, size_t)) {
assert(ptable && user_malloc && user_free && user_realloc);
int r;
toku_lth* tmp = (toku_lth*)user_malloc(sizeof(*tmp));
if (0) { died1: user_free(tmp); return r; }
if (!tmp) return errno;
memset(tmp, 0, sizeof(*tmp));
tmp->malloc = user_malloc;
tmp->free = user_free;
tmp->realloc = user_realloc;
tmp->array_size = __toku_lth_init_size;
tmp->table = (toku_lth_elt**)
tmp->malloc(tmp->array_size * sizeof(*tmp->table));
if (!tmp->table) { r = errno; goto died1; }
memset(tmp->table, 0, tmp->array_size * sizeof(*tmp->table));
__toku_invalidate_scan(tmp);
*ptable = tmp;
return 0;
}
toku_lock_tree* toku_lth_find(toku_lth* table, toku_lock_tree* key) {
assert(table && key);
uint32 index = __toku_lth_hash(table, key);
toku_lth_elt* element = table->table[index];
while (element && element->key != key) element = element->next;
return element ? element->key : NULL;
}
void toku_lth_start_scan(toku_lth* table) {
assert(table);
table->finger_index = 0;
table->finger_ptr = table->table[table->finger_index];
table->finger_start = TRUE;
table->finger_end = FALSE;
}
static inline toku_lth_elt* __toku_lth_next(toku_lth* table) {
assert(table);
assert(!table->finger_end);
if (table->finger_ptr && !table->finger_start) {
table->finger_ptr = table->finger_ptr->next;
}
while (!table->finger_ptr && ++table->finger_index < table->array_size) {
table->finger_ptr = table->table[table->finger_index];
}
table->finger_start = FALSE;
table->finger_end = !table->finger_ptr;
return table->finger_ptr;
}
toku_lock_tree* toku_lth_next(toku_lth* table) {
assert(table);
toku_lth_elt* next = __toku_lth_next(table);
return next ? next->key : NULL;
}
/* Element MUST exist. */
void toku_lth_delete(toku_lth* table, toku_lock_tree* key) {
assert(table && key);
__toku_invalidate_scan(table);
/* Must have elements. */
assert(table->num_keys);
uint32 index = __toku_lth_hash(table, key);
toku_lth_elt* element = table->table[index];
/* Elements of the right hash must exist. */
assert(element);
/* Case where it is the first element. */
if (element->key == key) {
table->table[index] = element->next;
table->free(element);
table->num_keys--;
return;
}
toku_lth_elt* prev;
/* Case where it is not the first element. */
do {
assert(element);
prev = element;
element = element->next;
} while (element->key != key);
/* Must be found. */
assert(element);
prev->next = element->next;
table->free(element);
table->num_keys--;
return;
}
/* Will allow you to insert it over and over. You need to keep track. */
int toku_lth_insert(toku_lth* table, toku_lock_tree* key) {
assert(table && key);
__toku_invalidate_scan(table);
uint32 index = __toku_lth_hash(table, key);
/* Allocate a new one. */
toku_lth_elt* element = (toku_lth_elt*)table->malloc(sizeof(*element));
if (!element) return errno;
memset(element, 0, sizeof(*element));
element->key = key;
element->next = table->table[index];
table->table[index] = element;
table->num_keys++;
return 0;
}
void toku_lth_close(toku_lth* table) {
assert(table);
toku_lth_elt* element;
toku_lth_elt* next = NULL;
toku_lth_start_scan(table);
next = __toku_lth_next(table);
while (next) {
element = next;
next = __toku_lth_next(table);
table->free(element);
}
table->free(table->table);
table->free(table);
}
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007-8 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
/**
\file hash_table.h
\brief Hash table
*/
//Defines BOOL data type.
#include <db.h>
#include <brttypes.h>
#include <locktree.h>
typedef struct __toku_lth_elt toku_lth_elt;
struct __toku_lth_elt {
toku_lock_tree* key;
toku_lth_elt* next;
};
typedef struct __toku_lth toku_lth;
struct __toku_lth {
toku_lth_elt** table;
uint32 num_keys;
uint32 array_size;
uint32 finger_index;
toku_lth_elt* finger_ptr;
BOOL finger_start;
BOOL finger_end;
/** The user malloc function */
void* (*malloc) (size_t);
/** The user free function */
void (*free) (void*);
/** The user realloc function */
void* (*realloc)(void*, size_t);
};
int toku_lth_create(toku_lth** ptable,
void* (*user_malloc) (size_t),
void (*user_free) (void*),
void* (*user_realloc)(void*, size_t));
toku_lock_tree* toku_lth_find (toku_lth* table, toku_lock_tree* key);
void toku_lth_start_scan(toku_lth* table);
toku_lock_tree* toku_lth_next (toku_lth* table);
void toku_lth_delete (toku_lth* table, toku_lock_tree* key);
void toku_lth_close (toku_lth* table);
int toku_lth_insert (toku_lth* table, toku_lock_tree* key);
......@@ -133,7 +133,7 @@ int toku_rth_insert(toku_rth* table, DB_TXN* key) {
/* Allocate a new one. */
toku_rth_elt* element = (toku_rth_elt*)table->malloc(sizeof(*element));
if (!element) return errno;
memset(&element->value, 0, sizeof(toku_rt_forest));
memset(element, 0, sizeof(*element));
element->key = key;
element->next = table->table[index];
table->table[index] = element;
......
......@@ -3,6 +3,8 @@
#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."
#if !defined(TOKU_RTH_H)
#define TOKU_RTH_H
/**
\file hash_table.h
\brief Hash table
......@@ -62,3 +64,4 @@ void toku_rth_delete (toku_rth* table, DB_TXN* key);
void toku_rth_close (toku_rth* table);
int toku_rth_insert (toku_rth* table, DB_TXN* key);
#endif
......@@ -95,7 +95,7 @@ endif
$(MAYBEATSIGN) $(SETENV) $(VGRIND) ./$< $(VERBVERBOSE)
libs:
cd ..;make
cd .. && make
%.lin: %.c ../locktree.h test.h
$(SETENV) cc -DDIR=\"dir.$<.lin\" -DTOKU_LT_LINEAR $(CPPFLAGS) $(CFLAGS) $< -lrangetree_linear -llocktree_linear -o $@
......@@ -107,7 +107,7 @@ libs:
.PHONY: make_libs
make_libs:
cd ..;make
cd .. && make
clean:
rm -f $(ALL_TESTS) *.o *.gcno *.gcda *.gcov
......
......@@ -8,6 +8,7 @@
#include <assert.h>
#include <errno.h>
int verbose=0;
#include <lth.h>
BOOL want_panic = FALSE;
......
/* We are going to test whether create and close properly check their input. */
#include "test.h"
toku_lth* lth;
int main(int argc, const char *argv[]) {
int r;
parse_args(argc, argv);
lth = NULL;
for (failon = 1; failon <= 2; failon++) {
mallocced = 0;
r = toku_lth_create(&lth, fail_malloc, toku_free, toku_realloc);
CKERR2(r, ENOMEM);
assert(lth==NULL);
}
r = toku_lth_create(&lth, toku_malloc, toku_free, toku_realloc);
CKERR(r);
assert(lth);
toku_lth_close(lth);
lth = NULL;
size_t i;
size_t iterations = 512 << 2;
r = toku_lth_create(&lth, toku_malloc, toku_free, toku_realloc);
CKERR(r);
assert(lth);
for (i = 1; i < iterations; i++) {
r = toku_lth_insert(lth, (toku_lock_tree*)i);
CKERR(r);
}
toku_lock_tree* f;
for (i = 1; i < iterations; i++) {
f = toku_lth_find(lth, (toku_lock_tree*)i);
assert(f == (toku_lock_tree*) i);
}
f = toku_lth_find(lth, (toku_lock_tree*)i);
assert(!f);
toku_lth_start_scan(lth);
for (i = 1; i < iterations; i++) {
f = toku_lth_next(lth);
assert(f);
}
f = toku_lth_next(lth);
assert(!f);
for (i = iterations - 1; i >= 1; i--) {
toku_lth_delete(lth, (toku_lock_tree*)i);
}
toku_lth_close(lth);
lth = NULL;
r = toku_lth_create(&lth, toku_malloc, toku_free, toku_realloc);
CKERR(r);
assert(lth);
for (i = 1; i < iterations; i++) {
r = toku_lth_insert(lth, (toku_lock_tree*)i);
CKERR(r);
}
for (i = 1; i < iterations; i++) {
toku_lth_delete(lth, (toku_lock_tree*)i);
}
toku_lth_close(lth);
lth = NULL;
r = toku_lth_create(&lth, toku_malloc, toku_free, toku_realloc);
CKERR(r);
assert(lth);
for (i = iterations - 1; i >= 1; i--) {
r = toku_lth_insert(lth, (toku_lock_tree*)i);
CKERR(r);
}
toku_lth_close(lth);
lth = NULL;
failon = 3;
mallocced = 0;
r = toku_lth_create(&lth, fail_malloc, toku_free, toku_realloc);
CKERR(r);
assert(lth);
r = toku_lth_insert(lth, (toku_lock_tree*)1);
CKERR2(r, ENOMEM);
toku_lth_close(lth);
lth = NULL;
return 0;
}
......@@ -5,11 +5,7 @@ LIBNAME_LINEAR = librangetree_linear
LIBNAME_TLOG = librangetree_tlog
LIBNAME_LOG = librangetree_log
ifneq ($(OPT),)
OPTFLAGS = -O3
else
OPTFLAGS = -O2 -g3 -ggdb3
endif
OPTFLAGS = -O2
ifneq ($(GCOV),)
GCOV_FLAGS = -fprofile-arcs -ftest-coverage
......@@ -17,7 +13,7 @@ else
GCOV_FLAGS =
endif
CFLAGS = -W -Wall -Wextra -Werror -fPIC $(OPTFLAGS) $(GCOV_FLAGS)
CFLAGS = -W -Wall -Wextra -Werror -fPIC $(OPTFLAGS) -g3 -ggdb3 $(GCOV_FLAGS)
CFLAGS += -Wbad-function-cast -Wcast-align -Wconversion -Waggregate-return
CFLAGS += -Wmissing-noreturn -Wmissing-format-attribute
CPPFLAGS = -I../../include -I../../newbrt
......@@ -36,19 +32,13 @@ endif
.PHONY: install logformat
install: $(LIBNAME_LINEAR).$(LIBEXT) $(LIBNAME_LINEAR).a #$(LIBNAME_TLOG).$(LIBEXT) $(LIBNAME_TLOG).a $(LIBNAME_LOG).$(LIBEXT) $(LIBNAME_LOG).a
#cp $(LIBNAME_LOG).$(LIBEXT) ../../lib/
#cp $(LIBNAME_LOG).a ../../lib
#cp $(LIBNAME_TLOG).$(LIBEXT) ../../lib/
#cp $(LIBNAME_TLOG).a ../../lib
cp $(LIBNAME_LINEAR).$(LIBEXT) ../../lib/
cp $(LIBNAME_LINEAR).a ../../lib
clean:
rm -rf *.o
rm -rf $(LIBNAME_LINEAR).$(LIBEXT) $(LIBNAME_LINEAR).a
rm -rf $(LIBNAME_TLOG).$(LIBEXT) $(LIBNAME_TLOG).a
rm -rf $(LIBNAME_LOG).$(LIBEXT) $(LIBNAME_LOG).a
cd tests;make clean
cd tests && make clean
linear.o: linear.c rangetree.h
......
......@@ -20,6 +20,8 @@ else
VGRIND=valgrind --quiet --error-exitcode=1 --leak-check=yes
endif
OPTFLAGS=-O0
LIBNAME=librt.$(LIBEXT)
# GCOV_FLAGS = -fprofile-arcs -ftest-coverage
CFLAGS = -W -Wall -Wextra -Werror $(OPTFLAGS) -g3 -ggdb3 $(GCOV_FLAGS)
......@@ -87,7 +89,7 @@ endif
$(MAYBEATSIGN) $(SETENV) $(VGRIND) ./$< $(VERBVERBOSE)
libs:
cd ..;make
cd .. && make
%.lin: %.c ../rangetree.h test.h
$(SETENV) cc -DDIR=\"dir.$<.lin\" $(CPPFLAGS) $(CFLAGS) $< -lrangetree_linear -o $@
......@@ -99,7 +101,7 @@ libs:
.PHONY: make_libs
make_libs:
cd ..;make
cd .. && make
clean:
rm -f $(ALL_TESTS) *.o *.gcno *.gcda *.gcov
......
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