Commit 0ecffb3a authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

[t:5011], remove the ydb lock

git-svn-id: file:///svn/toku/tokudb@44206 c7de825b-a66e-492c-adef-691d508d4ae1
parent 59da3e00
......@@ -16,7 +16,6 @@ set(tokudb_srcs
loader.c
indexer.c
indexer-undo-do.c
elocks.c
)
## make the shared library
......
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#ident "Copyright (c) 2007-2009 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 "$Id$"
/**
\file elocks.c
\brief Ephemeral locks
The ydb big lock serializes access to the tokudb
every call (including methods) into the tokudb library gets the lock
no internal function should invoke a method through an object */
#include <toku_portability.h>
#include "ydb-internal.h"
#include <string.h>
#include <toku_assert.h>
#include <toku_pthread.h>
#include <sys/types.h>
struct ydb_big_lock {
toku_mutex_t lock;
tokutime_t starttime; // what time was the lock initialized?
tokutime_t acquired_time; // what time was the lock acquired
};
static struct ydb_big_lock ydb_big_lock;
static inline u_int64_t u64max(u_int64_t a, u_int64_t b) {return a > b ? a : b; }
/* Status is intended for display to humans to help understand system behavior.
* It does not need to be perfectly thread-safe.
*/
static volatile YDB_LOCK_STATUS_S ydb_lock_status;
#define STATUS_INIT(k,t,l) { \
ydb_lock_status.status[k].keyname = #k; \
ydb_lock_status.status[k].type = t; \
ydb_lock_status.status[k].legend = "ydb lock: " l; \
}
static void
status_init(void) {
// Note, this function initializes the keyname, type, and legend fields.
// Value fields are initialized to zero by compiler.
STATUS_INIT(YDB_LOCK_TAKEN, UINT64, "taken");
STATUS_INIT(YDB_LOCK_RELEASED, UINT64, "released");
STATUS_INIT(YDB_NUM_WAITERS_NOW, UINT64, "num waiters now");
STATUS_INIT(YDB_MAX_WAITERS, UINT64, "max waiters");
STATUS_INIT(YDB_TOTAL_SLEEP_TIME, UINT64, "total sleep time (usec)");
STATUS_INIT(YDB_MAX_TIME_YDB_LOCK_HELD, TOKUTIME, "max time held (sec)");
STATUS_INIT(YDB_TOTAL_TIME_YDB_LOCK_HELD, TOKUTIME, "total time held (sec)");
STATUS_INIT(YDB_TOTAL_TIME_SINCE_START, TOKUTIME, "total time since start (sec)");
ydb_lock_status.initialized = true;
}
#undef STATUS_INIT
void
toku_ydb_lock_get_status(YDB_LOCK_STATUS statp) {
if (!ydb_lock_status.initialized)
status_init();
*statp = ydb_lock_status;
}
#define STATUS_VALUE(x) ydb_lock_status.status[x].value.num
/* End of status section.
*/
void
toku_ydb_lock_init(void) {
toku_mutex_init(&ydb_big_lock.lock, NULL);
ydb_big_lock.starttime = get_tokutime();
ydb_big_lock.acquired_time = 0;
}
void
toku_ydb_lock_destroy(void) {
toku_mutex_destroy(&ydb_big_lock.lock);
}
void
toku_ydb_lock(void) {
u_int32_t new_num_waiters = __sync_add_and_fetch(&STATUS_VALUE(YDB_NUM_WAITERS_NOW), 1);
toku_mutex_lock(&ydb_big_lock.lock);
u_int64_t now = get_tokutime();
// Update the lock
ydb_big_lock.acquired_time = now;
// Update status
STATUS_VALUE(YDB_LOCK_TAKEN)++;
if (new_num_waiters > STATUS_VALUE(YDB_MAX_WAITERS))
STATUS_VALUE(YDB_MAX_WAITERS) = new_num_waiters;
STATUS_VALUE(YDB_TOTAL_TIME_SINCE_START) = now - ydb_big_lock.starttime;
}
static void
ydb_unlock_internal(unsigned long useconds) {
STATUS_VALUE(YDB_LOCK_RELEASED)++;
tokutime_t now = get_tokutime();
tokutime_t time_held = now - ydb_big_lock.acquired_time;
STATUS_VALUE(YDB_TOTAL_TIME_YDB_LOCK_HELD) += time_held;
if (time_held > STATUS_VALUE(YDB_MAX_TIME_YDB_LOCK_HELD))
STATUS_VALUE(YDB_MAX_TIME_YDB_LOCK_HELD) = time_held;
STATUS_VALUE(YDB_TOTAL_TIME_SINCE_START) = now - ydb_big_lock.starttime;
toku_mutex_unlock(&ydb_big_lock.lock);
int new_num_waiters = __sync_add_and_fetch(&STATUS_VALUE(YDB_NUM_WAITERS_NOW), -1);
if (new_num_waiters > 0 && useconds > 0) {
__sync_add_and_fetch(&STATUS_VALUE(YDB_TOTAL_SLEEP_TIME), useconds);
usleep(useconds);
}
}
void
toku_ydb_unlock(void) {
ydb_unlock_internal(0);
}
void
toku_ydb_unlock_and_yield(unsigned long useconds) {
ydb_unlock_internal(useconds);
}
#undef STATUS_VALUE
......@@ -118,14 +118,6 @@ typedef struct {
void toku_ydb_lock_init(void);
void toku_ydb_lock_destroy(void);
void toku_ydb_lock(void);
void toku_ydb_unlock(void);
void toku_ydb_unlock_and_yield(unsigned long useconds);
void toku_ydb_lock_get_status(YDB_LOCK_STATUS statp);
int toku_ydb_check_avail_fs_space(DB_ENV *env);
......
......@@ -193,12 +193,7 @@ int
toku_ydb_init(void) {
int r = 0;
//Lower level must be initialized first.
if (r==0) {
r = toku_ft_layer_init();
}
if (r==0) {
toku_ydb_lock_init();
}
return r;
}
......@@ -206,7 +201,6 @@ toku_ydb_init(void) {
void
toku_ydb_destroy(void) {
if (env_is_panicked == 0) {
toku_ydb_lock_destroy();
toku_ft_layer_destroy();
}
}
......@@ -1885,13 +1879,6 @@ env_get_engine_status (DB_ENV * env, TOKU_ENGINE_STATUS_ROW engstat, uint64_t ma
engstat[row++] = ydb_write_stat.status[i];
}
}
{
YDB_LOCK_STATUS_S ydb_lock_status;
toku_ydb_lock_get_status(&ydb_lock_status);
for (int i = 0; i < YDB_LOCK_STATUS_NUM_ROWS && row < maxrows; i++) {
engstat[row++] = ydb_lock_status.status[i];
}
}
{
LE_STATUS_S lestat; // Rice's vampire
toku_le_get_status(&lestat);
......
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