提交 11451c10 authored 作者: Anthony Minessale's avatar Anthony Minessale

FS-3106 --comment-only Try this out, its got a few elements from your patch but…

FS-3106 --comment-only Try this out, its got a few elements from your patch but there was a much bigger problem deeper in the code preventing the sqlite handles from being recycled properly
上级 01073a79
...@@ -2075,52 +2075,53 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_preprocess_session(switch_core_sessio ...@@ -2075,52 +2075,53 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_preprocess_session(switch_core_sessio
*/ */
#define CACHE_DB_LEN 256 #define CACHE_DB_LEN 256
typedef enum { typedef enum {
CDF_INUSE = (1 << 0), CDF_INUSE = (1 << 0),
CDF_PRUNE = (1 << 1) CDF_PRUNE = (1 << 1),
} cache_db_flag_t; CDF_RELEASED = (1 << 2)
} cache_db_flag_t;
typedef enum {
SCDB_TYPE_CORE_DB, typedef enum {
SCDB_TYPE_ODBC SCDB_TYPE_CORE_DB,
} switch_cache_db_handle_type_t; SCDB_TYPE_ODBC
} switch_cache_db_handle_type_t;
typedef union {
switch_core_db_t *core_db_dbh; typedef union {
switch_odbc_handle_t *odbc_dbh; switch_core_db_t *core_db_dbh;
} switch_cache_db_native_handle_t; switch_odbc_handle_t *odbc_dbh;
} switch_cache_db_native_handle_t;
typedef struct {
char *db_path; typedef struct {
} switch_cache_db_core_db_options_t; char *db_path;
} switch_cache_db_core_db_options_t;
typedef struct {
char *dsn; typedef struct {
char *user; char *dsn;
char *pass; char *user;
} switch_cache_db_odbc_options_t; char *pass;
} switch_cache_db_odbc_options_t;
typedef union {
switch_cache_db_core_db_options_t core_db_options; typedef union {
switch_cache_db_odbc_options_t odbc_options; switch_cache_db_core_db_options_t core_db_options;
} switch_cache_db_connection_options_t; switch_cache_db_odbc_options_t odbc_options;
} switch_cache_db_connection_options_t;
typedef struct {
char name[CACHE_DB_LEN]; typedef struct {
switch_cache_db_handle_type_t type; char name[CACHE_DB_LEN];
switch_cache_db_native_handle_t native_handle; switch_cache_db_handle_type_t type;
time_t last_used; switch_cache_db_native_handle_t native_handle;
switch_mutex_t *mutex; time_t last_used;
switch_mutex_t *io_mutex; switch_mutex_t *mutex;
switch_memory_pool_t *pool; switch_mutex_t *io_mutex;
int32_t flags; switch_memory_pool_t *pool;
unsigned long hash; int32_t flags;
char creator[CACHE_DB_LEN]; unsigned long hash;
char last_user[CACHE_DB_LEN]; char creator[CACHE_DB_LEN];
} switch_cache_db_handle_t; char last_user[CACHE_DB_LEN];
} switch_cache_db_handle_t;
static inline const char *switch_cache_db_type_name(switch_cache_db_handle_type_t type)
static inline const char *switch_cache_db_type_name(switch_cache_db_handle_type_t type)
{ {
const char *type_str = "INVALID"; const char *type_str = "INVALID";
......
...@@ -94,7 +94,7 @@ SWITCH_DECLARE(int) switch_core_db_exec(switch_core_db_t *db, const char *sql, s ...@@ -94,7 +94,7 @@ SWITCH_DECLARE(int) switch_core_db_exec(switch_core_db_t *db, const char *sql, s
if (ret == SQLITE_BUSY || ret == SQLITE_LOCKED) { if (ret == SQLITE_BUSY || ret == SQLITE_LOCKED) {
if (sane > 1) { if (sane > 1) {
switch_core_db_free(err); switch_core_db_free(err);
switch_yield(100000); switch_yield(1000); /* Was 100000. I think it's too much */
continue; continue;
} }
} else { } else {
...@@ -182,9 +182,27 @@ SWITCH_DECLARE(switch_core_db_t *) switch_core_db_open_file(const char *filename ...@@ -182,9 +182,27 @@ SWITCH_DECLARE(switch_core_db_t *) switch_core_db_open_file(const char *filename
{ {
switch_core_db_t *db; switch_core_db_t *db;
char path[1024]; char path[1024];
int db_ret;
db_pick_path(filename, path, sizeof(path)); db_pick_path(filename, path, sizeof(path));
if (switch_core_db_open(path, &db)) { if ((db_ret = switch_core_db_open(path, &db)) != SQLITE_OK) {
goto end;
}
if ((db_ret = switch_core_db_exec(db, "PRAGMA synchronous=OFF;", NULL, NULL, NULL) != SQLITE_OK)) {
goto end;
}
if ((db_ret = switch_core_db_exec(db, "PRAGMA count_changes=OFF;", NULL, NULL, NULL) != SQLITE_OK)) {
goto end;
}
if ((db_ret = switch_core_db_exec(db, "PRAGMA cache_size=8000;", NULL, NULL, NULL) != SQLITE_OK)) {
goto end;
}
if ((db_ret = switch_core_db_exec(db, "PRAGMA temp_store=MEMORY;", NULL, NULL, NULL) != SQLITE_OK)) {
goto end;
}
end:
if (db_ret != SQLITE_OK) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", switch_core_db_errmsg(db)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", switch_core_db_errmsg(db));
switch_core_db_close(db); switch_core_db_close(db);
db = NULL; db = NULL;
......
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论