Commit 7c455cbf authored by Rich Prohaska's avatar Rich Prohaska

#81 export an API to set a get wait time callback

parent e44c72cf
......@@ -449,7 +449,7 @@ static void print_db_env_struct (void) {
"int (*set_lk_max_memory) (DB_ENV *env, uint64_t max)",
"int (*get_lk_max_memory) (DB_ENV *env, uint64_t *max)",
"void (*set_update) (DB_ENV *env, int (*update_function)(DB *, const DBT *key, const DBT *old_val, const DBT *extra, void (*set_val)(const DBT *new_val, void *set_extra), void *set_extra))",
"int (*set_lock_timeout) (DB_ENV *env, uint64_t lock_wait_time_msec)",
"int (*set_lock_timeout) (DB_ENV *env, uint64_t lock_wait_time_msec, uint64_t (*get_lock_wait_time_cb)(uint64_t default_lock_wait_time))",
"int (*get_lock_timeout) (DB_ENV *env, uint64_t *lock_wait_time_msec)",
"int (*set_lock_timeout_callback) (DB_ENV *env, lock_timeout_callback callback)",
"int (*txn_xa_recover) (DB_ENV*, TOKU_XA_XID list[/*count*/], long count, /*out*/ long *retp, uint32_t flags)",
......
......@@ -238,7 +238,7 @@ public:
uint64_t get_lock_wait_time(void);
void set_lock_wait_time(uint64_t lock_wait_time);
void set_lock_wait_time(uint64_t lock_wait_time, uint64_t (*get_lock_wait_time_cb)(uint64_t default_lock_wait_time));
// effect: Get a locktree from the manager. If a locktree exists with the given
// dict_id, it is referenced and then returned. If one did not exist, it
......@@ -324,6 +324,7 @@ public:
// lock wait time for blocking row locks, in ms
uint64_t m_lock_wait_time_ms;
uint64_t (*m_get_lock_wait_time_cb)(uint64_t);
// the create and destroy callbacks for the locktrees
lt_create_cb m_lt_create_callback;
......
......@@ -153,11 +153,16 @@ int locktree::manager::set_max_lock_memory(size_t max_lock_memory) {
}
uint64_t locktree::manager::get_lock_wait_time(void) {
return m_lock_wait_time_ms;
uint64_t wait_time = m_lock_wait_time_ms;
if (m_get_lock_wait_time_cb) {
wait_time = m_get_lock_wait_time_cb(wait_time);
}
return wait_time;
}
void locktree::manager::set_lock_wait_time(uint64_t lock_wait_time_ms) {
void locktree::manager::set_lock_wait_time(uint64_t lock_wait_time_ms, uint64_t (*get_lock_wait_time_cb)(uint64_t)) {
m_lock_wait_time_ms = lock_wait_time_ms;
m_get_lock_wait_time_cb = get_lock_wait_time_cb;
}
int locktree::manager::find_by_dict_id(locktree *const &lt, const DICTIONARY_ID &dict_id) {
......
......@@ -116,6 +116,9 @@ public:
// make sure deadlocks are detected when a lock request starts
void test_start_deadlock(void);
// test that the get_wait_time callback works
void test_wait_time_callback(void);
private:
// releases a single range lock and retries all lock requests.
// this is kind of like what the ydb layer does, except that
......
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "$Id$"
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
This software is covered by US Patent No. 8,489,638.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include "lock_request_unit_test.h"
namespace toku {
static int my_calls = 0;
static uint64_t my_lock_wait_time_callback(uint64_t default_lock_wait_time UU()) {
my_calls++;
return 1000;
}
// make sure deadlocks are detected when a lock request starts
void lock_request_unit_test::test_wait_time_callback(void) {
int r;
locktree::manager mgr;
locktree *lt;
mgr.create(nullptr, nullptr, nullptr, nullptr);
mgr.set_lock_wait_time(10*1000, my_lock_wait_time_callback);
DICTIONARY_ID dict_id = { 1 };
lt = mgr.get_lt(dict_id, nullptr, compare_dbts, nullptr);
TXNID txnid_a = 1001;
lock_request request_a;
request_a.create();
TXNID txnid_b = 2001;
lock_request request_b;
request_b.create();
const DBT *one = get_dbt(1);
const DBT *two = get_dbt(2);
// a locks 'one'
request_a.set(lt, txnid_a, one, one, lock_request::type::WRITE);
r = request_a.start();
assert_zero(r);
// b tries to lock 'one'
request_b.set(lt, txnid_b, one, two, lock_request::type::WRITE);
r = request_b.start();
assert(r == DB_LOCK_NOTGRANTED);
assert(my_calls == 0);
uint64_t t_start = toku_current_time_microsec();
r = request_b.wait(mgr.get_lock_wait_time());
uint64_t t_end = toku_current_time_microsec();
assert(r == DB_LOCK_NOTGRANTED);
assert(my_calls == 1);
assert(t_end > t_start);
uint64_t t_delta = t_end - t_start;
assert(1000000 <= t_delta && t_delta < 10000000);
request_b.destroy();
release_lock_and_retry_requests(lt, txnid_a, one, one);
request_a.destroy();
mgr.release_lt(lt);
mgr.destroy();
}
} /* namespace toku */
int main(void) {
toku::lock_request_unit_test test;
test.test_wait_time_callback();
return 0;
}
......@@ -104,7 +104,7 @@ void manager_unit_test::test_params(void) {
invariant(mgr.get_max_lock_memory() == new_max_lock_memory);
uint64_t new_lock_wait_time = 62345234;
mgr.set_lock_wait_time(new_lock_wait_time);
mgr.set_lock_wait_time(new_lock_wait_time, nullptr);
invariant(mgr.get_lock_wait_time() == new_lock_wait_time);
mgr.m_current_lock_memory = 100000;
......
......@@ -220,7 +220,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000, nullptr); assert(r == 0);
#endif
// create the db
......
......@@ -237,7 +237,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000, nullptr); assert(r == 0);
#endif
// create the db
......
......@@ -237,7 +237,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000, nullptr); assert(r == 0);
#endif
// create the db
......
......@@ -306,7 +306,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000, nullptr); assert(r == 0);
#else
r = db_env->set_lk_detect(db_env, DB_LOCK_YOUNGEST); assert(r == 0);
#endif
......
......@@ -182,7 +182,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000, nullptr); assert(r == 0);
#endif
// create the db
......
......@@ -233,7 +233,7 @@ int test_main(int argc, char * const argv[]) {
uint64_t lock_timeout_msec;
r = db_env->get_lock_timeout(db_env, &lock_timeout_msec); assert(r == 0);
if (verbose) printf("lock timeout: %" PRIu64 "\n", lock_timeout_msec);
r = db_env->set_lock_timeout(db_env, 5000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 5000, nullptr); assert(r == 0);
r = db_env->get_lock_timeout(db_env, &lock_timeout_msec); assert(r == 0);
if (verbose) printf("lock timeout: %" PRIu64 "\n", lock_timeout_msec);
#endif
......
......@@ -209,7 +209,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000, nullptr); assert(r == 0);
#endif
// create the db
......
......@@ -181,7 +181,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000, nullptr); assert(r == 0);
#endif
// create the db
......
......@@ -247,7 +247,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000, nullptr); assert(r == 0);
#endif
// create the db
......
......@@ -242,7 +242,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000, nullptr); assert(r == 0);
#endif
// create the db
......
......@@ -245,7 +245,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000, nullptr); assert(r == 0);
#endif
// create the db
......
......@@ -227,7 +227,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000, nullptr); assert(r == 0);
#endif
// create the db
......
......@@ -175,7 +175,7 @@ int test_main(int argc, char * const argv[]) {
}
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000, nullptr); assert(r == 0);
#endif
// create the db
......
......@@ -273,7 +273,7 @@ int test_main(int argc, char * const argv[]) {
#endif
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if defined(USE_TDB)
r = db_env->set_lock_timeout(db_env, 0); assert(r == 0); // no wait
r = db_env->set_lock_timeout(db_env, 0, nullptr); assert(r == 0); // no wait
#elif defined(USE_BDB)
r = db_env->set_lk_detect(db_env, DB_LOCK_YOUNGEST); assert(r == 0);
r = db_env->set_timeout(db_env, 10000, DB_SET_LOCK_TIMEOUT); assert(r == 0);
......
......@@ -214,7 +214,7 @@ int test_main(int argc, char * const argv[]) {
db_env_open_flags &= ~(DB_INIT_TXN | DB_INIT_LOG);
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if TOKUDB
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000, nullptr); assert(r == 0);
#else
r = db_env->set_lk_detect(db_env, DB_LOCK_YOUNGEST); assert(r == 0);
#endif
......
......@@ -275,7 +275,7 @@ int test_main(int argc, char * const argv[]) {
db_env_open_flags &= ~(DB_INIT_TXN | DB_INIT_LOG);
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
#if defined(TOKUDB)
r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
r = db_env->set_lock_timeout(db_env, 30 * 1000, nullptr); assert(r == 0);
#endif
#if defined(USE_BDB)
if (!poll_deadlock) {
......
......@@ -148,7 +148,7 @@ int test_main(int UU(argc), char *const UU(argv[])) {
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, TOKU_TEST_FILENAME, env_flags, 0755); CKERR(r);
r = env->set_lock_timeout(env, 4000);
r = env->set_lock_timeout(env, 4000, nullptr);
r = db_create(&db, env, 0); CKERR(r);
r = db->open(db, NULL, dname, NULL, DB_BTREE, DB_CREATE, 0777); CKERR(r);
......
......@@ -149,7 +149,7 @@ int test_main(int UU(argc), char *const UU(argv[])) {
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, TOKU_TEST_FILENAME, env_flags, 0755); CKERR(r);
r = env->set_lock_timeout(env, 1000);
r = env->set_lock_timeout(env, 1000, nullptr);
r = env->set_lock_timeout_callback(env, lock_not_granted);
r = db_create(&db, env, 0); CKERR(r);
......
......@@ -1715,8 +1715,8 @@ env_get_lock_timeout(DB_ENV *env, uint64_t *lock_timeout_msec) {
}
static int
env_set_lock_timeout(DB_ENV *env, uint64_t lock_timeout_msec) {
env->i->ltm.set_lock_wait_time(lock_timeout_msec);
env_set_lock_timeout(DB_ENV *env, uint64_t lock_timeout_msec, uint64_t (*get_lock_timeout_callback)(uint64_t default_lock_timeout_msec)) {
env->i->ltm.set_lock_wait_time(lock_timeout_msec, get_lock_timeout_callback);
return 0;
}
......
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