Commit 85594f4e authored by John Esmet's avatar John Esmet Committed by Yoni Fogel

refs #5351 fix various drd and helgrind related issues. tree rotations should...

refs #5351 fix various drd and helgrind related issues. tree rotations should no longer be problematic with race tools.


git-svn-id: file:///svn/toku/tokudb@49920 c7de825b-a66e-492c-adef-691d508d4ae1
parent d6156686
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#ident "Copyright (c) 2007-2012 Tokutek Inc. All rights reserved." #ident "Copyright (c) 2007-2012 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." #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 <toku_race_tools.h>
#include <ft/ybt.h> #include <ft/ybt.h>
#include "locktree.h" #include "locktree.h"
...@@ -33,6 +35,7 @@ void lock_request::create(uint64_t wait_time) { ...@@ -33,6 +35,7 @@ void lock_request::create(uint64_t wait_time) {
void lock_request::destroy(void) { void lock_request::destroy(void) {
toku_destroy_dbt(&m_left_key_copy); toku_destroy_dbt(&m_left_key_copy);
toku_destroy_dbt(&m_right_key_copy); toku_destroy_dbt(&m_right_key_copy);
toku_cond_destroy(&m_wait_cond);
} }
// set the lock request parameters. this API allows a lock request to be reused. // set the lock request parameters. this API allows a lock request to be reused.
......
...@@ -46,6 +46,15 @@ void locktree::create(manager::memory_tracker *mem_tracker, DICTIONARY_ID dict_i ...@@ -46,6 +46,15 @@ void locktree::create(manager::memory_tracker *mem_tracker, DICTIONARY_ID dict_i
m_lock_request_info.pending_lock_requests.create(); m_lock_request_info.pending_lock_requests.create();
m_lock_request_info.mutex = TOKU_MUTEX_INITIALIZER; m_lock_request_info.mutex = TOKU_MUTEX_INITIALIZER;
m_lock_request_info.should_retry_lock_requests = false; m_lock_request_info.should_retry_lock_requests = false;
// Threads read the should retry bit without a lock
// for performance. It's ok to read the wrong value.
// - If you think you should but you shouldn't, you waste a little time.
// - If you think you shouldn't but you should, then some other thread
// will come around to do the work of retrying requests instead of you.
TOKU_VALGRIND_HG_DISABLE_CHECKING(
&m_lock_request_info.should_retry_lock_requests,
sizeof(m_lock_request_info.should_retry_lock_requests));
} }
void locktree::destroy(void) { void locktree::destroy(void) {
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#ident "Copyright (c) 2007-2012 Tokutek Inc. All rights reserved." #ident "Copyright (c) 2007-2012 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." #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 <toku_race_tools.h>
void treenode::mutex_lock(void) { void treenode::mutex_lock(void) {
toku_mutex_lock(&m_mutex); toku_mutex_lock(&m_mutex);
} }
...@@ -345,6 +347,28 @@ bool treenode::right_imbalanced(int threshold) const { ...@@ -345,6 +347,28 @@ bool treenode::right_imbalanced(int threshold) const {
return m_right_child.ptr != nullptr && right_depth > threshold + left_depth; return m_right_child.ptr != nullptr && right_depth > threshold + left_depth;
} }
/*
* How to make helgrind happy about tree rotations and new mutex orderings:
*
* // Tell helgrind that we unlocked it so that the next call doesn't get a "destroyed a locked mutex" error.
* // Tell helgrind that we destroyed the mutex.
* VALGRIND_HG_MUTEX_UNLOCK_PRE(&locka);
* VALGRIND_HG_MUTEX_DESTROY_PRE(&locka);
*
* // And recreate it. It would be better to simply be able to say that the order on these two can now be reversed, because this code forgets all the ordering information for this mutex.
* // Then tell helgrind that we have locked it again.
* VALGRIND_HG_MUTEX_INIT_POST(&locka, 0);
* VALGRIND_HG_MUTEX_LOCK_POST(&locka);
*
* When the ordering of two locks changes, we don't need tell Helgrind about do both locks. Just one is good enough.
*/
#define RESET_LOCKED_MUTEX_ORDERING_INFO(mutex) \
VALGRIND_HG_MUTEX_UNLOCK_PRE(mutex); \
VALGRIND_HG_MUTEX_DESTROY_PRE(mutex); \
VALGRIND_HG_MUTEX_INIT_POST(mutex, 0); \
VALGRIND_HG_MUTEX_LOCK_POST(mutex);
// effect: rebalances the subtree rooted at this node // effect: rebalances the subtree rooted at this node
// using AVL style O(1) rotations. unlocks this // using AVL style O(1) rotations. unlocks this
// node if it is not the new root of the subtree. // node if it is not the new root of the subtree.
...@@ -398,11 +422,14 @@ treenode *treenode::maybe_rebalance(void) { ...@@ -398,11 +422,14 @@ treenode *treenode::maybe_rebalance(void) {
// //
// one of them is the new root. we unlock everything except the new root. // one of them is the new root. we unlock everything except the new root.
if (child && child != new_root) { if (child && child != new_root) {
RESET_LOCKED_MUTEX_ORDERING_INFO(&child->m_mutex);
child->mutex_unlock(); child->mutex_unlock();
} }
if (this != new_root) { if (this != new_root) {
RESET_LOCKED_MUTEX_ORDERING_INFO(&m_mutex);
mutex_unlock(); mutex_unlock();
} }
RESET_LOCKED_MUTEX_ORDERING_INFO(&new_root->m_mutex);
return new_root; return new_root;
} }
......
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