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

#141 redo table open and close locking to avoid table opening pileup

parent e56f12d4
This diff is collapsed.
...@@ -126,6 +126,10 @@ typedef struct hot_optimize_context { ...@@ -126,6 +126,10 @@ typedef struct hot_optimize_context {
// and auto increment information. // and auto increment information.
// //
class TOKUDB_SHARE { class TOKUDB_SHARE {
public:
void init(void);
void destroy(void);
public: public:
char *table_name; char *table_name;
uint table_name_length, use_count; uint table_name_length, use_count;
...@@ -184,6 +188,10 @@ public: ...@@ -184,6 +188,10 @@ public:
bool replace_into_fast; bool replace_into_fast;
rw_lock_t num_DBs_lock; rw_lock_t num_DBs_lock;
uint32_t num_DBs; uint32_t num_DBs;
pthread_cond_t m_openclose_cond;
enum { CLOSED, OPENING, OPENED, CLOSING, ERROR } m_state;
int m_error;
}; };
typedef struct st_filter_key_part_info { typedef struct st_filter_key_part_info {
...@@ -443,10 +451,7 @@ private: ...@@ -443,10 +451,7 @@ private:
int write_auto_inc_create(DB* db, ulonglong val, DB_TXN* txn); int write_auto_inc_create(DB* db, ulonglong val, DB_TXN* txn);
void init_auto_increment(); void init_auto_increment();
bool can_replace_into_be_fast(TABLE_SHARE* table_share, KEY_AND_COL_INFO* kc_info, uint pk); bool can_replace_into_be_fast(TABLE_SHARE* table_share, KEY_AND_COL_INFO* kc_info, uint pk);
int initialize_share( int initialize_share(const char* name, int mode);
const char* name,
int mode
);
void set_query_columns(uint keynr); void set_query_columns(uint keynr);
int prelock_range (const key_range *start_key, const key_range *end_key); int prelock_range (const key_range *start_key, const key_range *end_key);
...@@ -599,10 +604,10 @@ public: ...@@ -599,10 +604,10 @@ public:
int get_status(DB_TXN* trans); int get_status(DB_TXN* trans);
void init_hidden_prim_key_info(); void init_hidden_prim_key_info();
inline void get_auto_primary_key(uchar * to) { inline void get_auto_primary_key(uchar * to) {
pthread_mutex_lock(&share->mutex); tokudb_pthread_mutex_lock(&share->mutex);
share->auto_ident++; share->auto_ident++;
hpk_num_to_char(to, share->auto_ident); hpk_num_to_char(to, share->auto_ident);
pthread_mutex_unlock(&share->mutex); tokudb_pthread_mutex_unlock(&share->mutex);
} }
virtual void get_auto_increment(ulonglong offset, ulonglong increment, ulonglong nb_desired_values, ulonglong * first_value, ulonglong * nb_reserved_values); virtual void get_auto_increment(ulonglong offset, ulonglong increment, ulonglong nb_desired_values, ulonglong * first_value, ulonglong * nb_reserved_values);
bool is_optimize_blocking(); bool is_optimize_blocking();
......
...@@ -443,4 +443,44 @@ static inline void* tokudb_my_multi_malloc(myf myFlags, ...) { ...@@ -443,4 +443,44 @@ static inline void* tokudb_my_multi_malloc(myf myFlags, ...) {
return start; return start;
} }
static inline void tokudb_pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) {
int r = pthread_mutex_init(mutex, attr);
assert(r == 0);
}
static inline void tokudb_pthread_mutex_destroy(pthread_mutex_t *mutex) {
int r = pthread_mutex_destroy(mutex);
assert(r == 0);
}
static inline void tokudb_pthread_mutex_lock(pthread_mutex_t *mutex) {
int r = pthread_mutex_lock(mutex);
assert(r == 0);
}
static inline void tokudb_pthread_mutex_unlock(pthread_mutex_t *mutex) {
int r = pthread_mutex_unlock(mutex);
assert(r == 0);
}
static inline void tokudb_pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) {
int r = pthread_cond_init(cond, attr);
assert(r == 0);
}
static inline void tokudb_pthread_cond_destroy(pthread_cond_t *cond) {
int r = pthread_cond_destroy(cond);
assert(r == 0);
}
static inline void tokudb_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) {
int r = pthread_cond_wait(cond, mutex);
assert(r == 0);
}
static inline void tokudb_pthread_cond_broadcast(pthread_cond_t *cond) {
int r = pthread_cond_broadcast(cond);
assert(r == 0);
}
#endif #endif
...@@ -311,7 +311,7 @@ static int tokudb_init_func(void *p) { ...@@ -311,7 +311,7 @@ static int tokudb_init_func(void *p) {
tokudb_hton = (handlerton *) p; tokudb_hton = (handlerton *) p;
pthread_mutex_init(&tokudb_mutex, MY_MUTEX_INIT_FAST); tokudb_pthread_mutex_init(&tokudb_mutex, MY_MUTEX_INIT_FAST);
(void) my_hash_init(&tokudb_open_tables, table_alias_charset, 32, 0, 0, (my_hash_get_key) tokudb_get_key, 0, 0); (void) my_hash_init(&tokudb_open_tables, table_alias_charset, 32, 0, 0, (my_hash_get_key) tokudb_get_key, 0, 0);
tokudb_hton->state = SHOW_OPTION_YES; tokudb_hton->state = SHOW_OPTION_YES;
...@@ -529,7 +529,7 @@ static int tokudb_done_func(void *p) { ...@@ -529,7 +529,7 @@ static int tokudb_done_func(void *p) {
tokudb_my_free(toku_global_status_rows); tokudb_my_free(toku_global_status_rows);
toku_global_status_rows = NULL; toku_global_status_rows = NULL;
my_hash_free(&tokudb_open_tables); my_hash_free(&tokudb_open_tables);
pthread_mutex_destroy(&tokudb_mutex); tokudb_pthread_mutex_destroy(&tokudb_mutex);
#if defined(_WIN64) #if defined(_WIN64)
toku_ydb_destroy(); toku_ydb_destroy();
#endif #endif
......
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