提交 f542449c authored 作者: Anthony Minessale's avatar Anthony Minessale

FS-3106 --comment-only Try this newer refactored version which completely…

FS-3106 --comment-only Try this newer refactored version which completely removes the thread affinity and uses a linked-list to manage the pool, I can run my same 100cps test and only use like 4 db handles
上级 9feab652
......@@ -2077,8 +2077,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_preprocess_session(switch_core_sessio
#define CACHE_DB_LEN 256
typedef enum {
CDF_INUSE = (1 << 0),
CDF_PRUNE = (1 << 1),
CDF_RELEASED = (1 << 2)
CDF_PRUNE = (1 << 1)
} cache_db_flag_t;
typedef enum {
......@@ -2106,20 +2105,8 @@ typedef union {
switch_cache_db_odbc_options_t odbc_options;
} switch_cache_db_connection_options_t;
typedef struct {
char name[CACHE_DB_LEN];
switch_cache_db_handle_type_t type;
switch_cache_db_native_handle_t native_handle;
time_t last_used;
switch_mutex_t *mutex;
switch_mutex_t *io_mutex;
switch_memory_pool_t *pool;
int32_t flags;
unsigned long hash;
char creator[CACHE_DB_LEN];
char last_user[CACHE_DB_LEN];
} switch_cache_db_handle_t;
struct switch_cache_db_handle;
typedef struct switch_cache_db_handle switch_cache_db_handle_t;
static inline const char *switch_cache_db_type_name(switch_cache_db_handle_type_t type)
{
......@@ -2141,6 +2128,8 @@ static inline const char *switch_cache_db_type_name(switch_cache_db_handle_type_
return type_str;
}
SWITCH_DECLARE(switch_cache_db_handle_type_t) switch_cache_db_get_type(switch_cache_db_handle_t *dbh);
/*!
\brief Returns the handle to the pool, immediately available for other
threads to use.
......@@ -2153,11 +2142,6 @@ SWITCH_DECLARE(void) switch_cache_db_dismiss_db_handle(switch_cache_db_handle_t
\param [in] The handle
*/
SWITCH_DECLARE(void) switch_cache_db_release_db_handle(switch_cache_db_handle_t ** dbh);
/*!
\brief Removes the handle from the pool and frees up the handle resources.
\param [in] The handle
*/
SWITCH_DECLARE(void) switch_cache_db_destroy_db_handle(switch_cache_db_handle_t ** dbh);
/*!
\brief Gets a new cached handle from the pool, potentially creating a new connection.
The connection is bound to the thread until it (the thread) terminates unless
......@@ -2218,10 +2202,7 @@ SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive(switch_cache_db_hand
const char *test_sql, const char *drop_sql, const char *reactive_sql);
SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute(switch_cache_db_handle_t *dbh, const char *sql, uint32_t retries);
SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute_trans(switch_cache_db_handle_t *dbh, char *sql, uint32_t retries);
/*!
\brief Tries to detach all free connections from current thread.
*/
SWITCH_DECLARE(void) switch_cache_db_detach(void);
SWITCH_DECLARE(uint32_t) switch_core_debug_level(void);
SWITCH_DECLARE(void) switch_cache_db_flush_handles(void);
SWITCH_DECLARE(const char *) switch_core_banner(void);
......
......@@ -252,7 +252,7 @@ SWITCH_DECLARE(char *) switch_console_expand_alias(char *cmd, char *arg)
}
if (db->type == SCDB_TYPE_CORE_DB) {
if (switch_cache_db_get_type(db) == SCDB_TYPE_CORE_DB) {
sql = switch_mprintf("select command from aliases where alias='%q'", cmd);
} else {
sql = switch_mprintf("select command from aliases where alias='%w'", cmd);
......@@ -268,7 +268,7 @@ SWITCH_DECLARE(char *) switch_console_expand_alias(char *cmd, char *arg)
switch_safe_free(sql);
if (!r) {
if (db->type == SCDB_TYPE_CORE_DB) {
if (switch_cache_db_get_type(db) == SCDB_TYPE_CORE_DB) {
sql = switch_mprintf("select command from aliases where alias='%q %q'", cmd, arg);
} else {
sql = switch_mprintf("select command from aliases where alias='%w %w'", cmd, arg);
......@@ -794,7 +794,7 @@ SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const ch
stream.write_function(&stream, "select distinct a1 from complete where " "a1 not in (select name from interfaces where hostname='%s') %s ",
switch_core_get_hostname(), argc ? "and" : "");
} else {
if (db->type == SCDB_TYPE_CORE_DB) {
if (switch_cache_db_get_type(db) == SCDB_TYPE_CORE_DB) {
stream.write_function(&stream, "select distinct a%d,'%q','%q' from complete where ", h.words + 1, switch_str_nil(dup), switch_str_nil(lp));
} else {
stream.write_function(&stream, "select distinct a%d,'%q','%w' from complete where ", h.words + 1, switch_str_nil(dup), switch_str_nil(lp));
......@@ -803,7 +803,7 @@ SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const ch
for (x = 0; x < argc && x < 11; x++) {
if (h.words + 1 > argc) {
if (db->type == SCDB_TYPE_CORE_DB) {
if (switch_cache_db_get_type(db) == SCDB_TYPE_CORE_DB) {
stream.write_function(&stream, "(a%d like '::%%' or a%d = '' or a%d = '%q')%q",
x + 1, x + 1, x + 1, switch_str_nil(argv[x]), x == argc - 1 ? "" : " and ");
} else {
......@@ -811,7 +811,7 @@ SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const ch
x + 1, x + 1, x + 1, switch_str_nil(argv[x]), x == argc - 1 ? "" : " and ");
}
} else {
if (db->type == SCDB_TYPE_CORE_DB) {
if (switch_cache_db_get_type(db) == SCDB_TYPE_CORE_DB) {
stream.write_function(&stream, "(a%d like '::%%' or a%d = '' or a%d like '%q%%')%q",
x + 1, x + 1, x + 1, switch_str_nil(argv[x]), x == argc - 1 ? "" : " and ");
} else {
......@@ -1792,7 +1792,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string)
if (argv[x + 1] && !strcasecmp(argv[x + 1], "_any_")) {
mystream.write_function(&mystream, "%s", "'', ");
} else {
if (db->type == SCDB_TYPE_CORE_DB) {
if (switch_cache_db_get_type(db) == SCDB_TYPE_CORE_DB) {
mystream.write_function(&mystream, "'%q', ", switch_str_nil(argv[x + 1]));
} else {
mystream.write_function(&mystream, "'%w', ", switch_str_nil(argv[x + 1]));
......@@ -1808,7 +1808,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string)
if (argv[x + 1] && !strcasecmp(argv[x + 1], "_any_")) {
mystream.write_function(&mystream, "%s", "'', ");
} else {
if (db->type == SCDB_TYPE_CORE_DB) {
if (switch_cache_db_get_type(db) == SCDB_TYPE_CORE_DB) {
mystream.write_function(&mystream, "'%q', ", switch_str_nil(argv[x + 1]));
} else {
mystream.write_function(&mystream, "'%w', ", switch_str_nil(argv[x + 1]));
......@@ -1826,7 +1826,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string)
} else {
mystream.write_function(&mystream, "delete from complete where ");
for (x = 0; x < argc - 1; x++) {
if (db->type == SCDB_TYPE_CORE_DB) {
if (switch_cache_db_get_type(db) == SCDB_TYPE_CORE_DB) {
mystream.write_function(&mystream, "a%d = '%q'%q", x + 1, switch_str_nil(argv[x + 1]), x == argc - 2 ? "" : " and ");
} else {
mystream.write_function(&mystream, "a%d = '%w'%w", x + 1, switch_str_nil(argv[x + 1]), x == argc - 2 ? "" : " and ");
......@@ -1871,7 +1871,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_alias(const char *string)
sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_hostname());
switch_cache_db_persistant_execute(db, sql, 5);
switch_safe_free(sql);
if (db->type == SCDB_TYPE_CORE_DB) {
if (switch_cache_db_get_type(db) == SCDB_TYPE_CORE_DB) {
sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (1, '%q','%q','%q')",
argv[1], argv[2], switch_core_get_hostname());
} else {
......@@ -1884,7 +1884,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_alias(const char *string)
sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_hostname());
switch_cache_db_persistant_execute(db, sql, 5);
switch_safe_free(sql);
if (db->type == SCDB_TYPE_CORE_DB) {
if (switch_cache_db_get_type(db) == SCDB_TYPE_CORE_DB) {
sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (0, '%q','%q','%q')",
argv[1], argv[2], switch_core_get_hostname());
} else {
......
......@@ -409,9 +409,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_new_memory_pool(switch_memor
SWITCH_DECLARE(switch_status_t) switch_core_perform_destroy_memory_pool(switch_memory_pool_t **pool, const char *file, const char *func, int line)
{
switch_assert(pool != NULL);
if (switch_core_memory_pool_get_data(*pool, "_in_thread")) {
switch_cache_db_detach();
}
#ifdef DEBUG_ALLOC2
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Free Pool\n");
#endif
......
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论