Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
46fee25d
提交
46fee25d
authored
7月 12, 2012
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add fsctl sql start/stop for standby controls
上级
cc480157
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
171 行增加
和
78 行删除
+171
-78
switch_core.h
src/include/switch_core.h
+2
-0
switch_types.h
src/include/switch_types.h
+1
-0
mod_commands.c
src/mod/applications/mod_commands/mod_commands.c
+10
-0
switch_core.c
src/switch_core.c
+7
-0
switch_core_sqldb.c
src/switch_core_sqldb.c
+151
-78
没有找到文件。
src/include/switch_core.h
浏览文件 @
46fee25d
...
@@ -2149,6 +2149,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_chat_send(const char *dest_proto, sw
...
@@ -2149,6 +2149,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_chat_send(const char *dest_proto, sw
SWITCH_DECLARE
(
switch_status_t
)
switch_core_chat_deliver
(
const
char
*
dest_proto
,
switch_event_t
**
message_event
);
SWITCH_DECLARE
(
switch_status_t
)
switch_core_chat_deliver
(
const
char
*
dest_proto
,
switch_event_t
**
message_event
);
SWITCH_DECLARE
(
switch_status_t
)
switch_ivr_preprocess_session
(
switch_core_session_t
*
session
,
const
char
*
cmds
);
SWITCH_DECLARE
(
switch_status_t
)
switch_ivr_preprocess_session
(
switch_core_session_t
*
session
,
const
char
*
cmds
);
SWITCH_DECLARE
(
void
)
switch_core_sqldb_stop_thread
(
void
);
SWITCH_DECLARE
(
void
)
switch_core_sqldb_start_thread
(
void
);
///\}
///\}
...
...
src/include/switch_types.h
浏览文件 @
46fee25d
...
@@ -1775,6 +1775,7 @@ typedef enum {
...
@@ -1775,6 +1775,7 @@ typedef enum {
SCSC_THREADED_SYSTEM_EXEC
,
SCSC_THREADED_SYSTEM_EXEC
,
SCSC_SYNC_CLOCK_WHEN_IDLE
,
SCSC_SYNC_CLOCK_WHEN_IDLE
,
SCSC_DEBUG_SQL
,
SCSC_DEBUG_SQL
,
SCSC_SQL
,
}
switch_session_ctl_t
;
}
switch_session_ctl_t
;
typedef
enum
{
typedef
enum
{
...
...
src/mod/applications/mod_commands/mod_commands.c
浏览文件 @
46fee25d
...
@@ -1915,6 +1915,16 @@ SWITCH_STANDARD_API(ctl_function)
...
@@ -1915,6 +1915,16 @@ SWITCH_STANDARD_API(ctl_function)
switch_core_session_ctl
(
SCSC_DEBUG_SQL
,
&
x
);
switch_core_session_ctl
(
SCSC_DEBUG_SQL
,
&
x
);
stream
->
write_function
(
stream
,
"+OK SQL DEBUG [%s]
\n
"
,
x
?
"on"
:
"off"
);
stream
->
write_function
(
stream
,
"+OK SQL DEBUG [%s]
\n
"
,
x
?
"on"
:
"off"
);
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"sql"
))
{
if
(
argv
[
1
])
{
int
x
=
0
;
if
(
!
strcasecmp
(
argv
[
1
],
"start"
))
{
x
=
1
;
}
switch_core_session_ctl
(
SCSC_SQL
,
&
x
);
stream
->
write_function
(
stream
,
"+OK
\n
"
);
}
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"reclaim_mem"
))
{
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"reclaim_mem"
))
{
switch_core_session_ctl
(
SCSC_RECLAIM
,
&
arg
);
switch_core_session_ctl
(
SCSC_RECLAIM
,
&
arg
);
stream
->
write_function
(
stream
,
"+OK
\n
"
);
stream
->
write_function
(
stream
,
"+OK
\n
"
);
...
...
src/switch_core.c
浏览文件 @
46fee25d
...
@@ -2125,6 +2125,13 @@ SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, void *
...
@@ -2125,6 +2125,13 @@ SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, void *
case
SCSC_SYNC_CLOCK_WHEN_IDLE
:
case
SCSC_SYNC_CLOCK_WHEN_IDLE
:
newintval
=
switch_core_session_sync_clock
();
newintval
=
switch_core_session_sync_clock
();
break
;
break
;
case
SCSC_SQL
:
if
(
oldintval
)
{
switch_core_sqldb_start_thread
();
}
else
{
switch_core_sqldb_stop_thread
();
}
break
;
case
SCSC_PAUSE_ALL
:
case
SCSC_PAUSE_ALL
:
if
(
oldintval
)
{
if
(
oldintval
)
{
switch_set_flag
((
&
runtime
),
SCF_NO_NEW_SESSIONS
);
switch_set_flag
((
&
runtime
),
SCF_NO_NEW_SESSIONS
);
...
...
src/switch_core_sqldb.c
浏览文件 @
46fee25d
...
@@ -66,11 +66,13 @@ static struct {
...
@@ -66,11 +66,13 @@ static struct {
switch_bool_t
manage
;
switch_bool_t
manage
;
switch_mutex_t
*
io_mutex
;
switch_mutex_t
*
io_mutex
;
switch_mutex_t
*
dbh_mutex
;
switch_mutex_t
*
dbh_mutex
;
switch_mutex_t
*
ctl_mutex
;
switch_cache_db_handle_t
*
handle_pool
;
switch_cache_db_handle_t
*
handle_pool
;
switch_thread_cond_t
*
cond
;
switch_thread_cond_t
*
cond
;
switch_mutex_t
*
cond_mutex
;
switch_mutex_t
*
cond_mutex
;
uint32_t
total_handles
;
uint32_t
total_handles
;
uint32_t
total_used_handles
;
uint32_t
total_used_handles
;
switch_cache_db_handle_t
*
dbh
;
}
sql_manager
;
}
sql_manager
;
...
@@ -1957,7 +1959,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_expire_registration(int force)
...
@@ -1957,7 +1959,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_expire_registration(int force)
switch_status_t
switch_core_sqldb_start
(
switch_memory_pool_t
*
pool
,
switch_bool_t
manage
)
switch_status_t
switch_core_sqldb_start
(
switch_memory_pool_t
*
pool
,
switch_bool_t
manage
)
{
{
switch_threadattr_t
*
thd_attr
;
switch_threadattr_t
*
thd_attr
;
switch_cache_db_handle_t
*
dbh
;
uint32_t
sanity
=
400
;
uint32_t
sanity
=
400
;
sql_manager
.
memory_pool
=
pool
;
sql_manager
.
memory_pool
=
pool
;
...
@@ -1966,15 +1967,18 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
...
@@ -1966,15 +1967,18 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
switch_mutex_init
(
&
sql_manager
.
dbh_mutex
,
SWITCH_MUTEX_NESTED
,
sql_manager
.
memory_pool
);
switch_mutex_init
(
&
sql_manager
.
dbh_mutex
,
SWITCH_MUTEX_NESTED
,
sql_manager
.
memory_pool
);
switch_mutex_init
(
&
sql_manager
.
io_mutex
,
SWITCH_MUTEX_NESTED
,
sql_manager
.
memory_pool
);
switch_mutex_init
(
&
sql_manager
.
io_mutex
,
SWITCH_MUTEX_NESTED
,
sql_manager
.
memory_pool
);
switch_mutex_init
(
&
sql_manager
.
cond_mutex
,
SWITCH_MUTEX_NESTED
,
sql_manager
.
memory_pool
);
switch_mutex_init
(
&
sql_manager
.
cond_mutex
,
SWITCH_MUTEX_NESTED
,
sql_manager
.
memory_pool
);
switch_mutex_init
(
&
sql_manager
.
ctl_mutex
,
SWITCH_MUTEX_NESTED
,
sql_manager
.
memory_pool
);
switch_thread_cond_create
(
&
sql_manager
.
cond
,
sql_manager
.
memory_pool
);
switch_thread_cond_create
(
&
sql_manager
.
cond
,
sql_manager
.
memory_pool
);
top
:
if
(
!
sql_manager
.
manage
)
goto
skip
;
if
(
!
sql_manager
.
manage
)
goto
skip
;
top
:
/* Activate SQL database */
/* Activate SQL database */
if
(
switch_core_db_handle
(
&
dbh
)
!=
SWITCH_STATUS_SUCCESS
)
{
if
(
switch_core_db_handle
(
&
sql_manager
.
dbh
)
!=
SWITCH_STATUS_SUCCESS
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Error Opening DB!
\n
"
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Error Opening DB!
\n
"
);
if
(
switch_test_flag
((
&
runtime
),
SCF_CORE_ODBC_REQ
))
{
if
(
switch_test_flag
((
&
runtime
),
SCF_CORE_ODBC_REQ
))
{
...
@@ -1999,7 +2003,7 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
...
@@ -1999,7 +2003,7 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"Opening DB
\n
"
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"Opening DB
\n
"
);
switch
(
dbh
->
type
)
{
switch
(
sql_manager
.
dbh
->
type
)
{
case
SCDB_TYPE_ODBC
:
case
SCDB_TYPE_ODBC
:
if
(
switch_test_flag
((
&
runtime
),
SCF_CLEAR_SQL
))
{
if
(
switch_test_flag
((
&
runtime
),
SCF_CLEAR_SQL
))
{
char
sql
[
512
]
=
""
;
char
sql
[
512
]
=
""
;
...
@@ -2009,61 +2013,61 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
...
@@ -2009,61 +2013,61 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
for
(
i
=
0
;
tables
[
i
];
i
++
)
{
for
(
i
=
0
;
tables
[
i
];
i
++
)
{
switch_snprintfv
(
sql
,
sizeof
(
sql
),
"delete from %q where hostname='%q'"
,
tables
[
i
],
hostname
);
switch_snprintfv
(
sql
,
sizeof
(
sql
),
"delete from %q where hostname='%q'"
,
tables
[
i
],
hostname
);
switch_cache_db_execute_sql
(
dbh
,
sql
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
sql
,
NULL
);
}
}
}
}
break
;
break
;
case
SCDB_TYPE_CORE_DB
:
case
SCDB_TYPE_CORE_DB
:
{
{
switch_cache_db_execute_sql
(
dbh
,
"drop table channels"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"drop table channels"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"drop table calls"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"drop table calls"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"drop view detailed_calls"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"drop view detailed_calls"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"drop view basic_calls"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"drop view basic_calls"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"drop table interfaces"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"drop table interfaces"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"drop table tasks"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"drop table tasks"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"PRAGMA synchronous=OFF;"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"PRAGMA synchronous=OFF;"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"PRAGMA count_changes=OFF;"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"PRAGMA count_changes=OFF;"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"PRAGMA default_cache_size=8000"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"PRAGMA default_cache_size=8000"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"PRAGMA temp_store=MEMORY;"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"PRAGMA temp_store=MEMORY;"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"PRAGMA journal_mode=OFF;"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"PRAGMA journal_mode=OFF;"
,
NULL
);
}
}
break
;
break
;
}
}
switch_cache_db_test_reactive
(
dbh
,
"select hostname from complete"
,
"DROP TABLE complete"
,
create_complete_sql
);
switch_cache_db_test_reactive
(
sql_manager
.
dbh
,
"select hostname from complete"
,
"DROP TABLE complete"
,
create_complete_sql
);
switch_cache_db_test_reactive
(
dbh
,
"select hostname from aliases"
,
"DROP TABLE aliases"
,
create_alias_sql
);
switch_cache_db_test_reactive
(
sql_manager
.
dbh
,
"select hostname from aliases"
,
"DROP TABLE aliases"
,
create_alias_sql
);
switch_cache_db_test_reactive
(
dbh
,
"select hostname from nat"
,
"DROP TABLE nat"
,
create_nat_sql
);
switch_cache_db_test_reactive
(
sql_manager
.
dbh
,
"select hostname from nat"
,
"DROP TABLE nat"
,
create_nat_sql
);
switch_cache_db_test_reactive
(
dbh
,
"delete from registrations where reg_user='' or network_proto='tcp' or network_proto='tls'"
,
switch_cache_db_test_reactive
(
sql_manager
.
dbh
,
"delete from registrations where reg_user='' or network_proto='tcp' or network_proto='tls'"
,
"DROP TABLE registrations"
,
create_registrations_sql
);
"DROP TABLE registrations"
,
create_registrations_sql
);
switch_cache_db_test_reactive
(
dbh
,
"select metadata from registrations"
,
NULL
,
"ALTER TABLE registrations ADD COLUMN metadata VARCHAR(256)"
);
switch_cache_db_test_reactive
(
sql_manager
.
dbh
,
"select metadata from registrations"
,
NULL
,
"ALTER TABLE registrations ADD COLUMN metadata VARCHAR(256)"
);
switch
(
dbh
->
type
)
{
switch
(
sql_manager
.
dbh
->
type
)
{
case
SCDB_TYPE_ODBC
:
case
SCDB_TYPE_ODBC
:
{
{
char
*
err
;
char
*
err
;
switch_cache_db_test_reactive
(
dbh
,
"select call_uuid, read_bit_rate, sent_callee_name from channels"
,
"DROP TABLE channels"
,
create_channels_sql
);
switch_cache_db_test_reactive
(
sql_manager
.
dbh
,
"select call_uuid, read_bit_rate, sent_callee_name from channels"
,
"DROP TABLE channels"
,
create_channels_sql
);
switch_cache_db_test_reactive
(
dbh
,
"select * from detailed_calls where sent_callee_name=''"
,
"DROP VIEW detailed_calls"
,
detailed_calls_sql
);
switch_cache_db_test_reactive
(
sql_manager
.
dbh
,
"select * from detailed_calls where sent_callee_name=''"
,
"DROP VIEW detailed_calls"
,
detailed_calls_sql
);
switch_cache_db_test_reactive
(
dbh
,
"select * from basic_calls where sent_callee_name=''"
,
"DROP VIEW basic_calls"
,
basic_calls_sql
);
switch_cache_db_test_reactive
(
sql_manager
.
dbh
,
"select * from basic_calls where sent_callee_name=''"
,
"DROP VIEW basic_calls"
,
basic_calls_sql
);
switch_cache_db_test_reactive
(
dbh
,
"select call_uuid from calls"
,
"DROP TABLE calls"
,
create_calls_sql
);
switch_cache_db_test_reactive
(
sql_manager
.
dbh
,
"select call_uuid from calls"
,
"DROP TABLE calls"
,
create_calls_sql
);
if
(
runtime
.
odbc_dbtype
==
DBTYPE_DEFAULT
)
{
if
(
runtime
.
odbc_dbtype
==
DBTYPE_DEFAULT
)
{
switch_cache_db_test_reactive
(
dbh
,
"delete from registrations where reg_user='' or network_proto='tcp' or network_proto='tls'"
,
switch_cache_db_test_reactive
(
sql_manager
.
dbh
,
"delete from registrations where reg_user='' or network_proto='tcp' or network_proto='tls'"
,
"DROP TABLE registrations"
,
create_registrations_sql
);
"DROP TABLE registrations"
,
create_registrations_sql
);
}
else
{
}
else
{
char
*
tmp
=
switch_string_replace
(
create_registrations_sql
,
"url TEXT"
,
"url VARCHAR(max)"
);
char
*
tmp
=
switch_string_replace
(
create_registrations_sql
,
"url TEXT"
,
"url VARCHAR(max)"
);
switch_cache_db_test_reactive
(
dbh
,
"delete from registrations where reg_user='' or network_proto='tcp' or network_proto='tls'"
,
switch_cache_db_test_reactive
(
sql_manager
.
dbh
,
"delete from registrations where reg_user='' or network_proto='tcp' or network_proto='tls'"
,
"DROP TABLE registrations"
,
tmp
);
"DROP TABLE registrations"
,
tmp
);
free
(
tmp
);
free
(
tmp
);
}
}
switch_cache_db_test_reactive
(
dbh
,
"select ikey from interfaces"
,
"DROP TABLE interfaces"
,
create_interfaces_sql
);
switch_cache_db_test_reactive
(
sql_manager
.
dbh
,
"select ikey from interfaces"
,
"DROP TABLE interfaces"
,
create_interfaces_sql
);
switch_cache_db_test_reactive
(
dbh
,
"select hostname from tasks"
,
"DROP TABLE tasks"
,
create_tasks_sql
);
switch_cache_db_test_reactive
(
sql_manager
.
dbh
,
"select hostname from tasks"
,
"DROP TABLE tasks"
,
create_tasks_sql
);
if
(
runtime
.
odbc_dbtype
==
DBTYPE_DEFAULT
)
{
if
(
runtime
.
odbc_dbtype
==
DBTYPE_DEFAULT
)
{
switch_cache_db_execute_sql
(
dbh
,
"begin;delete from channels where hostname='';delete from channels where hostname='';commit;"
,
&
err
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"begin;delete from channels where hostname='';delete from channels where hostname='';commit;"
,
&
err
);
}
else
{
}
else
{
switch_cache_db_execute_sql
(
dbh
,
"delete from channels where hostname='';delete from channels where hostname='';"
,
&
err
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"delete from channels where hostname='';delete from channels where hostname='';"
,
&
err
);
}
}
if
(
err
)
{
if
(
err
)
{
...
@@ -2071,7 +2075,7 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
...
@@ -2071,7 +2075,7 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
runtime
.
odbc_user
=
NULL
;
runtime
.
odbc_user
=
NULL
;
runtime
.
odbc_pass
=
NULL
;
runtime
.
odbc_pass
=
NULL
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Transactions not supported on your DB, disabling ODBC
\n
"
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Transactions not supported on your DB, disabling ODBC
\n
"
);
switch_cache_db_release_db_handle
(
&
dbh
);
switch_cache_db_release_db_handle
(
&
sql_manager
.
dbh
);
free
(
err
);
free
(
err
);
goto
top
;
goto
top
;
}
}
...
@@ -2079,44 +2083,44 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
...
@@ -2079,44 +2083,44 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
break
;
break
;
case
SCDB_TYPE_CORE_DB
:
case
SCDB_TYPE_CORE_DB
:
{
{
switch_cache_db_execute_sql
(
dbh
,
create_channels_sql
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
create_channels_sql
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
create_calls_sql
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
create_calls_sql
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
create_interfaces_sql
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
create_interfaces_sql
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
create_tasks_sql
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
create_tasks_sql
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
detailed_calls_sql
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
detailed_calls_sql
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
basic_calls_sql
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
basic_calls_sql
,
NULL
);
}
}
break
;
break
;
}
}
switch_cache_db_execute_sql
(
dbh
,
"delete from complete where sticky=0"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"delete from complete where sticky=0"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"delete from aliases where sticky=0"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"delete from aliases where sticky=0"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"delete from nat where sticky=0"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"delete from nat where sticky=0"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index alias1 on aliases (alias)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index alias1 on aliases (alias)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index tasks1 on tasks (hostname,task_id)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index tasks1 on tasks (hostname,task_id)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index complete1 on complete (a1,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index complete1 on complete (a1,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index complete2 on complete (a2,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index complete2 on complete (a2,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index complete3 on complete (a3,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index complete3 on complete (a3,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index complete4 on complete (a4,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index complete4 on complete (a4,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index complete5 on complete (a5,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index complete5 on complete (a5,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index complete6 on complete (a6,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index complete6 on complete (a6,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index complete7 on complete (a7,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index complete7 on complete (a7,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index complete8 on complete (a8,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index complete8 on complete (a8,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index complete9 on complete (a9,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index complete9 on complete (a9,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index complete10 on complete (a10,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index complete10 on complete (a10,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index complete11 on complete (a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index complete11 on complete (a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index nat_map_port_proto on nat (port,proto,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index nat_map_port_proto on nat (port,proto,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index channels1 on channels(hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index channels1 on channels(hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index calls1 on calls(hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index calls1 on calls(hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index chidx1 on channels (hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index chidx1 on channels (hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index uuindex on channels (uuid)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index uuindex on channels (uuid)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index uuindex2 on channels (call_uuid)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index uuindex2 on channels (call_uuid)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index callsidx1 on calls (hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index callsidx1 on calls (hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index eruuindex on calls (caller_uuid)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index eruuindex on calls (caller_uuid)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index eeuuindex on calls (callee_uuid)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index eeuuindex on calls (callee_uuid)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index eeuuindex2 on calls (call_uuid)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index eeuuindex2 on calls (call_uuid)"
,
NULL
);
switch_cache_db_execute_sql
(
dbh
,
"create index regindex1 on registrations (reg_user,realm,hostname)"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"create index regindex1 on registrations (reg_user,realm,hostname)"
,
NULL
);
skip
:
skip
:
...
@@ -2156,39 +2160,108 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
...
@@ -2156,39 +2160,108 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
switch_threadattr_create
(
&
thd_attr
,
sql_manager
.
memory_pool
);
switch_threadattr_create
(
&
thd_attr
,
sql_manager
.
memory_pool
);
switch_threadattr_stacksize_set
(
thd_attr
,
SWITCH_THREAD_STACKSIZE
);
switch_threadattr_stacksize_set
(
thd_attr
,
SWITCH_THREAD_STACKSIZE
);
if
(
sql_manager
.
manage
)
{
switch_thread_create
(
&
sql_manager
.
thread
,
thd_attr
,
switch_core_sql_thread
,
NULL
,
sql_manager
.
memory_pool
);
switch_core_sqldb_start_thread
();
}
switch_thread_create
(
&
sql_manager
.
db_thread
,
thd_attr
,
switch_core_sql_db_thread
,
NULL
,
sql_manager
.
memory_pool
);
switch_thread_create
(
&
sql_manager
.
db_thread
,
thd_attr
,
switch_core_sql_db_thread
,
NULL
,
sql_manager
.
memory_pool
);
while
(
sql_manager
.
manage
&&
!
sql_manager
.
thread_running
&&
--
sanity
)
{
while
(
sql_manager
.
manage
&&
!
sql_manager
.
thread_running
&&
--
sanity
)
{
switch_yield
(
10000
);
switch_yield
(
10000
);
}
}
if
(
sql_manager
.
manage
)
switch_cache_db_release_db_handle
(
&
dbh
);
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
}
}
void
switch_core_sqldb_stop
(
void
)
{
switch_status_t
st
;
switch_event_unbind_callback
(
core_event_handler
);
SWITCH_DECLARE
(
void
)
switch_core_sqldb_stop_thread
(
void
)
{
switch_mutex_lock
(
sql_manager
.
ctl_mutex
);
if
(
sql_manager
.
thread
&&
sql_manager
.
thread_running
)
{
if
(
sql_manager
.
thread
&&
sql_manager
.
thread_running
)
{
switch_status_t
st
;
if
(
sql_manager
.
manage
)
{
if
(
sql_manager
.
manage
)
{
switch_queue_push
(
sql_manager
.
sql_queue
[
0
],
NULL
);
switch_queue_push
(
sql_manager
.
sql_queue
[
0
],
NULL
);
switch_queue_push
(
sql_manager
.
sql_queue
[
1
],
NULL
);
switch_queue_push
(
sql_manager
.
sql_queue
[
1
],
NULL
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_
DEBUG10
,
"Waiting for unfinished SQL transactions
\n
"
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_
CONSOLE
,
"Waiting for unfinished SQL transactions
\n
"
);
wake_thread
(
0
);
wake_thread
(
0
);
sql_manager
.
thread_running
=
-
1
;
switch_thread_join
(
&
st
,
sql_manager
.
thread
);
sql_manager
.
thread
=
NULL
;
switch_cache_db_release_db_handle
(
&
sql_manager
.
dbh
);
sql_manager
.
dbh
=
NULL
;
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"SQL is not enabled
\n
"
);
}
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"SQL thread is not running
\n
"
);
}
switch_mutex_unlock
(
sql_manager
.
ctl_mutex
);
}
SWITCH_DECLARE
(
void
)
switch_core_sqldb_start_thread
(
void
)
{
switch_mutex_lock
(
sql_manager
.
ctl_mutex
);
if
(
sql_manager
.
manage
)
{
top
:
if
(
!
sql_manager
.
dbh
)
{
/* Activate SQL database */
if
(
switch_core_db_handle
(
&
sql_manager
.
dbh
)
!=
SWITCH_STATUS_SUCCESS
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Error Opening DB!
\n
"
);
if
(
switch_test_flag
((
&
runtime
),
SCF_CORE_ODBC_REQ
))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CRIT
,
"Failure! ODBC IS REQUIRED!
\n
"
);
goto
end
;
}
if
(
runtime
.
odbc_dsn
)
{
runtime
.
odbc_dsn
=
NULL
;
runtime
.
odbc_user
=
NULL
;
runtime
.
odbc_pass
=
NULL
;
runtime
.
odbc_dbtype
=
DBTYPE_DEFAULT
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_WARNING
,
"Falling back to core_db.
\n
"
);
sql_manager
.
dbh
=
NULL
;
goto
top
;
}
switch_clear_flag
((
&
runtime
),
SCF_USE_SQL
);
goto
end
;
}
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"delete from channels"
,
NULL
);
switch_cache_db_execute_sql
(
sql_manager
.
dbh
,
"delete from calls"
,
NULL
);
}
}
sql_manager
.
thread_running
=
-
1
;
switch_thread_join
(
&
st
,
sql_manager
.
thread
);
if
(
!
sql_manager
.
thread
)
{
switch_threadattr_t
*
thd_attr
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CONSOLE
,
"Starting SQL thread.
\n
"
);
switch_threadattr_create
(
&
thd_attr
,
sql_manager
.
memory_pool
);
switch_threadattr_stacksize_set
(
thd_attr
,
SWITCH_THREAD_STACKSIZE
);
switch_thread_create
(
&
sql_manager
.
thread
,
thd_attr
,
switch_core_sql_thread
,
NULL
,
sql_manager
.
memory_pool
);
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"SQL thread is already running
\n
"
);
}
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"SQL is not enabled
\n
"
);
}
}
end
:
switch_mutex_unlock
(
sql_manager
.
ctl_mutex
);
}
void
switch_core_sqldb_stop
(
void
)
{
switch_status_t
st
;
switch_event_unbind_callback
(
core_event_handler
);
switch_core_sqldb_stop_thread
();
if
(
sql_manager
.
thread
&&
sql_manager
.
db_thread_running
)
{
if
(
sql_manager
.
thread
&&
sql_manager
.
db_thread_running
)
{
sql_manager
.
db_thread_running
=
-
1
;
sql_manager
.
db_thread_running
=
-
1
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论