Commit a411d843 authored by Yoni Fogel's avatar Yoni Fogel

closes #549

git-svn-id: file:///svn/tokudb@2903 c7de825b-a66e-492c-adef-691d508d4ae1
parent 82a1bd8c
......@@ -124,8 +124,8 @@ int toku__lt_point_cmp(const toku_point* x, const toku_point* y) {
static inline BOOL toku__lt_percent_ranges_free(toku_lock_tree* tree,
u_int32_t percent) {
assert(tree && tree->num_ranges && (percent <= 100));
u_int64_t max_ranges64= tree->max_ranges;
assert(tree && tree->max_ranges && tree->num_ranges && (percent <= 100));
u_int64_t max_ranges64 = *tree->max_ranges;
return *tree->num_ranges <= max_ranges64 * (100 - percent) / 100;
}
......@@ -135,7 +135,7 @@ static inline BOOL toku__lt_range_test_incr(toku_lock_tree* tree, u_int32_t repl
assert(tree);
assert(tree->num_ranges);
assert(replace <= *tree->num_ranges);
return *tree->num_ranges - replace < tree->max_ranges;
return *tree->num_ranges - replace < *tree->max_ranges;
}
static inline void toku__lt_range_incr(toku_lock_tree* tree, u_int32_t replace) {
......@@ -924,7 +924,7 @@ static inline int toku__lt_borderwrite_insert(toku_lock_tree* tree,
}
int toku_lt_create(toku_lock_tree** ptree, DB* db, BOOL duplicates,
int (*panic)(DB*, int), u_int32_t max_ranges,
int (*panic)(DB*, int), u_int32_t* max_ranges,
u_int32_t* num_ranges,
int (*compare_fun)(DB*,const DBT*,const DBT*),
int (*dup_compare)(DB*,const DBT*,const DBT*),
......@@ -933,7 +933,7 @@ int toku_lt_create(toku_lock_tree** ptree, DB* db, BOOL duplicates,
void* (*user_realloc)(void*, size_t)) {
if (!ptree || !db || !compare_fun || !dup_compare || !panic ||
!max_ranges || !num_ranges || !user_malloc || !user_free ||
!user_realloc) { return EINVAL; }
!user_realloc || !*max_ranges) { return EINVAL; }
int r;
toku_lock_tree* tmp_tree = (toku_lock_tree*)user_malloc(sizeof(*tmp_tree));
......
......@@ -68,7 +68,7 @@ struct __toku_lock_tree {
toku_range* buf;
u_int32_t buflen; /**< The length of buf */
/** The maximum number of ranges allowed. */
u_int32_t max_ranges;
u_int32_t* max_ranges;
/** The current number of ranges. */
u_int32_t* num_ranges;
/** Whether lock escalation is allowed. */
......@@ -149,7 +149,7 @@ typedef struct __toku_point toku_point;
instead.
*/
int toku_lt_create(toku_lock_tree** ptree, DB* db, BOOL duplicates,
int (*panic)(DB*, int), u_int32_t max_locks,
int (*panic)(DB*, int), u_int32_t* max_locks,
u_int32_t* num_locks,
int (*compare_fun)(DB*,const DBT*,const DBT*),
int (*dup_compare)(DB*,const DBT*,const DBT*),
......
......@@ -9,7 +9,7 @@ int main() {
BOOL duplicates;
for (duplicates = 0; duplicates < 2; duplicates++) {
r = toku_lt_create(&lt, db, duplicates, dbpanic, max_locks, &memcnt,
r = toku_lt_create(&lt, db, duplicates, dbpanic, &max_locks, &memcnt,
dbcmp, dbcmp, toku_malloc, toku_free, toku_realloc);
CKERR(r);
assert(lt);
......
......@@ -6,7 +6,7 @@ static DBT _key;
static DBT _data;
DBT* key;
DBT* data;
u_int32_t mem = 4096 * 1000;
u_int32_t mem = 1000;
u_int32_t memcnt = 0;
static void do_range_test(int (*acquire)(toku_lock_tree*, DB_TXN*,
......@@ -41,7 +41,7 @@ static void do_range_test(int (*acquire)(toku_lock_tree*, DB_TXN*,
reverse_data_r = &_data_r;
}
memcnt = 0;
r = toku_lt_create(&lt, db, duplicates, dbpanic, mem, &memcnt,
r = toku_lt_create(&lt, db, duplicates, dbpanic, &mem, &memcnt,
dbcmp, dbcmp, toku_malloc, toku_free, toku_realloc);
CKERR(r);
assert(lt);
......@@ -146,7 +146,7 @@ static void do_point_test(int (*acquire)(toku_lock_tree*, DB_TXN*,
data = NULL;
}
memcnt = 0;
r = toku_lt_create(&lt, db, duplicates, dbpanic, mem, &memcnt,
r = toku_lt_create(&lt, db, duplicates, dbpanic, &mem, &memcnt,
dbcmp, dbcmp, toku_malloc, toku_free, toku_realloc);
CKERR(r);
assert(lt);
......@@ -202,52 +202,52 @@ int main(int argc, const char *argv[]) {
/* create tests. */
for (duplicates = 0; duplicates < 2; duplicates++) {
memcnt = 0;
r = toku_lt_create(NULL, db, duplicates, dbpanic, mem, &memcnt,
r = toku_lt_create(NULL, db, duplicates, dbpanic, &mem, &memcnt,
dbcmp, dbcmp, toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL);
memcnt = 0;
r = toku_lt_create(&lt, NULL, duplicates, dbpanic, mem, &memcnt,
r = toku_lt_create(&lt, NULL, duplicates, dbpanic, &mem, &memcnt,
dbcmp, dbcmp, toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL);
memcnt = 0;
r = toku_lt_create(&lt, db, duplicates, NULL, mem, &memcnt,
r = toku_lt_create(&lt, db, duplicates, NULL, &mem, &memcnt,
dbcmp, dbcmp, toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL);
u_int32_t old_mem = mem;
mem = 0;
memcnt = 0;
r = toku_lt_create(&lt, db, duplicates, dbpanic, mem, &memcnt,
r = toku_lt_create(&lt, db, duplicates, dbpanic, &mem, &memcnt,
dbcmp, dbcmp, toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL);
mem = old_mem;
memcnt = 0;
r = toku_lt_create(&lt, db, duplicates, dbpanic, mem, NULL,
r = toku_lt_create(&lt, db, duplicates, dbpanic, &mem, NULL,
NULL, dbcmp, toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL);
memcnt = 0;
r = toku_lt_create(&lt, db, duplicates, dbpanic, mem, &memcnt,
r = toku_lt_create(&lt, db, duplicates, dbpanic, &mem, &memcnt,
NULL, dbcmp, toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL);
memcnt = 0;
r = toku_lt_create(&lt, db, duplicates, dbpanic, mem, &memcnt,
r = toku_lt_create(&lt, db, duplicates, dbpanic, &mem, &memcnt,
dbcmp, NULL,
toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL);
memcnt = 0;
r = toku_lt_create(&lt, db, duplicates, dbpanic, mem, &memcnt,
r = toku_lt_create(&lt, db, duplicates, dbpanic, &mem, &memcnt,
dbcmp, dbcmp,
NULL, toku_free, toku_realloc);
CKERR2(r, EINVAL);
memcnt = 0;
r = toku_lt_create(&lt, db, duplicates, dbpanic, mem, &memcnt,
r = toku_lt_create(&lt, db, duplicates, dbpanic, &mem, &memcnt,
dbcmp, dbcmp, toku_malloc, NULL, toku_realloc);
CKERR2(r, EINVAL);
memcnt = 0;
r = toku_lt_create(&lt, db, duplicates, dbpanic, mem, &memcnt,
r = toku_lt_create(&lt, db, duplicates, dbpanic, &mem, &memcnt,
dbcmp, dbcmp, toku_malloc, toku_free, NULL);
CKERR2(r, EINVAL);
}
......
......@@ -48,7 +48,7 @@ void init_query(BOOL dups) {
void setup_tree(BOOL dups) {
memcnt = 0;
r = toku_lt_create(&lt, db, dups, dbpanic, mem, &memcnt, dbcmp, dbcmp,
r = toku_lt_create(&lt, db, dups, dbpanic, &mem, &memcnt, dbcmp, dbcmp,
toku_malloc, toku_free, toku_realloc);
CKERR(r);
assert(lt);
......
......@@ -47,7 +47,7 @@ void init_query(BOOL dups) {
void setup_tree(BOOL dups) {
memcnt = 0;
r = toku_lt_create(&lt, db, dups, dbpanic, mem, &memcnt, dbcmp, dbcmp,
r = toku_lt_create(&lt, db, dups, dbpanic, &mem, &memcnt, dbcmp, dbcmp,
toku_malloc, toku_free, toku_realloc);
CKERR(r);
assert(lt);
......
......@@ -47,7 +47,7 @@ void init_query(BOOL dups) {
void setup_tree(BOOL dups) {
num_locks = 0;
r = toku_lt_create(&lt, db, dups, dbpanic, max_locks, &num_locks, intcmp, charcmp,
r = toku_lt_create(&lt, db, dups, dbpanic, &max_locks, &num_locks, intcmp, charcmp,
toku_malloc, toku_free, toku_realloc);
CKERR(r);
assert(lt);
......
......@@ -540,8 +540,9 @@ static int toku_env_set_lk_detect(DB_ENV * env, u_int32_t detect) {
static int toku_env_set_lk_max_locks(DB_ENV *dbenv, u_int32_t max) {
HANDLE_PANICKED_ENV(dbenv);
if (env_opened(dbenv)) return EINVAL;
if (!max) return EINVAL;
if (env_opened(dbenv)) { return EINVAL; }
if (!max) { return EINVAL; }
if (max < dbenv->i->num_locks) { return EDOM; }
dbenv->i->max_locks = max;
return 0;
}
......@@ -2029,7 +2030,7 @@ static int toku_db_open(DB * db, DB_TXN * txn, const char *fname, const char *db
if (need_locktree) {
r = toku_lt_create(&db->i->lt, db, FALSE,
toku_db_lt_panic, db->dbenv->i->max_locks,
toku_db_lt_panic, &db->dbenv->i->max_locks,
&db->dbenv->i->num_locks,
db->i->brt->compare_fun, db->i->brt->dup_compare,
toku_malloc, toku_free, toku_realloc);
......
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