Commit 1c762e5e authored by Barry Perlman's avatar Barry Perlman Committed by Yoni Fogel

Addresses #1792 refs[t:1792] Started adding show engine status

git-svn-id: file:///svn/toku/tokudb@14695 c7de825b-a66e-492c-adef-691d508d4ae1
parent ed56f1a3
......@@ -42,6 +42,13 @@ typedef struct __toku_db_btree_stat64 {
u_int64_t bt_dsize; /* how big are the keys+values (not counting the lengths) (an estimate, unless flattened) */
u_int64_t bt_fsize; /* how big is the underlying file */
} DB_BTREE_STAT64;
typedef struct __toku_engine_status {
int ydb_lock_held; /* is some thread holding the ydb lock? */
u_int32_t checkpoint_period; /* delay between automatic checkpoints */
u_int64_t checkpoint_footprint; /* state of checkpoint procedure */
struct timeval tbegin; /* time of last checkpoint begin */
struct timeval tend; /* time of last checkpoint end */
} ENGINE_STATUS;
typedef enum {
DB_BTREE=1,
DB_UNKNOWN=5
......@@ -145,6 +152,7 @@ struct __toku_db_env {
int (*checkpointing_end_atomic_operation) (DB_ENV*) /* End a set of operations (that must be atomic as far as checkpoints are concerned). */;
int (*set_default_bt_compare) (DB_ENV*,int (*bt_compare) (DB *, const DBT *, const DBT *)) /* Set default (key) comparison function for all DBs in this environment. Required for RECOVERY since you cannot open the DBs manually. */;
int (*set_default_dup_compare) (DB_ENV*,int (*bt_compare) (DB *, const DBT *, const DBT *)) /* Set default (val) comparison function for all DBs in this environment. Required for RECOVERY since you cannot open the DBs manually. */;
int (*get_engine_status) (DB_ENV*, ENGINE_STATUS*) /* Fill in status struct */;
void *app_private;
void *api1_internal;
int (*close) (DB_ENV *, u_int32_t);
......
......@@ -54,15 +54,20 @@
#include "logger.h"
#include "checkpoint.h"
// footprint for debugging only
// footprint for debugging and status reporting only
static u_int64_t checkpoint_footprint = 0;
static toku_pthread_rwlock_t checkpoint_safe_lock;
static toku_pthread_rwlock_t multi_operation_lock;
// Call through function pointers because this layer has no access to ydb lock functions.
static void (*ydb_lock)(void) = NULL;
static void (*ydb_unlock)(void) = NULL;
static BOOL initialized = FALSE; // sanity check
// Note following static functions are called from checkpoint internal logic only,
// and use the "writer" calls for locking and unlocking.
......@@ -149,7 +154,13 @@ toku_checkpoint_safe_client_unlock(void) {
}
static BOOL initialized = FALSE;
u_int64_t
toku_checkpoint_get_footprint(void) {
return checkpoint_footprint;
}
// Initialize the checkpoint mechanism, must be called before any client operations.
int
......@@ -185,22 +196,22 @@ toku_checkpoint(CACHETABLE ct, TOKULOGGER logger, char **error_string,
void (*callback2_f)(void*), void * extra2) {
int r;
checkpoint_footprint = 1;
checkpoint_footprint = 10;
assert(initialized);
multi_operation_checkpoint_lock();
checkpoint_footprint = 2;
checkpoint_footprint = 20;
checkpoint_safe_checkpoint_lock();
checkpoint_footprint = 3;
checkpoint_footprint = 30;
ydb_lock();
checkpoint_footprint = 4;
checkpoint_footprint = 40;
r = toku_cachetable_begin_checkpoint(ct, logger);
LSN oldest_live_lsn = toku_logger_get_oldest_living_lsn(logger);
multi_operation_checkpoint_unlock();
ydb_unlock();
checkpoint_footprint = 5;
checkpoint_footprint = 50;
if (r==0) {
if (callback_f)
callback_f(extra); // callback is called with checkpoint_safe_lock still held
......@@ -211,7 +222,7 @@ toku_checkpoint(CACHETABLE ct, TOKULOGGER logger, char **error_string,
r = toku_logger_maybe_trim_log(logger, trim_lsn);
}
checkpoint_footprint = 6;
checkpoint_footprint = 60;
checkpoint_safe_checkpoint_unlock();
checkpoint_footprint = 0;
......
......@@ -57,3 +57,15 @@ int toku_checkpoint_destroy(void);
int toku_checkpoint(CACHETABLE ct, TOKULOGGER logger, char **error_string,
void (*callback_f)(void*), void * extra,
void (*callback2_f)(void*), void * extra2);
/******
* These functions are called from the ydb level.
* They return status information and have no side effects.
* Some status information may be incorrect because no locks are taken to collect status.
* (If checkpoint is in progress, it may overwrite status info while it is being read.)
*****/
u_int64_t toku_checkpoint_get_footprint(void);
......@@ -18,9 +18,16 @@
#include <sys/types.h>
static toku_pthread_mutex_t ydb_big_lock = TOKU_PTHREAD_MUTEX_INITIALIZER;
static int ydb_lock_held = 0; // useful for debug at a live installation (int easier to pass to handlerton than BOOL)
int
toku_ydb_lock_held(void) {
return ydb_lock_held;
}
int
toku_ydb_lock_init(void) {
ydb_lock_held = 0;
int r = toku_pthread_mutex_init(&ydb_big_lock, NULL); assert(r == 0);
return r;
}
......@@ -33,9 +40,11 @@ toku_ydb_lock_destroy(void) {
void toku_ydb_lock(void) {
int r = toku_pthread_mutex_lock(&ydb_big_lock); assert(r == 0);
ydb_lock_held = 1;
}
void toku_ydb_unlock(void) {
int r = toku_pthread_mutex_unlock(&ydb_big_lock); assert(r == 0);
ydb_lock_held = 0;
}
......@@ -69,6 +69,7 @@ int toku_ydb_lock_init(void);
int toku_ydb_lock_destroy(void);
void toku_ydb_lock(void);
void toku_ydb_unlock(void);
int toku_ydb_lock_held(void);
/* *********************************************************
......
......@@ -927,6 +927,26 @@ locked_env_set_default_bt_compare(DB_ENV * env, int (*bt_compare) (DB *, const D
return r;
}
// Do not take ydb lock around or in this function.
// If the engine is blocked because some thread is holding the ydb lock, this function
// can help diagnose the problem.
// This function only collects information, and it does not matter if something gets garbled
// because of a race condition.
static int
env_get_engine_status(DB_ENV * env, ENGINE_STATUS * engstat) {
HANDLE_PANICKED_ENV(env);
int r = 0;
if (!env_opened(env)) r = EINVAL;
else {
engstat->ydb_lock_held = toku_ydb_lock_held(); // is ydb lock held?
env_checkpointing_get_period(env, &(engstat->checkpoint_period)); // do not take ydb lock
engstat->checkpoint_footprint = toku_checkpoint_get_footprint();
}
return r;
}
static int locked_txn_begin(DB_ENV * env, DB_TXN * stxn, DB_TXN ** txn, u_int32_t flags);
static int toku_db_lt_panic(DB* db, int r);
......@@ -952,6 +972,7 @@ static int toku_env_create(DB_ENV ** envp, u_int32_t flags) {
result->checkpointing_resume = env_checkpointing_resume;
result->checkpointing_begin_atomic_operation = env_checkpointing_begin_atomic_operation;
result->checkpointing_end_atomic_operation = env_checkpointing_end_atomic_operation;
result->get_engine_status = env_get_engine_status;
result->open = locked_env_open;
result->close = locked_env_close;
result->txn_checkpoint = toku_env_txn_checkpoint;
......
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