Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
ef79535c
提交
ef79535c
authored
9月 14, 2010
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add nitrus boost to sql thread
上级
8ea90fb1
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
116 行增加
和
58 行删除
+116
-58
switch_core_pvt.h
src/include/private/switch_core_pvt.h
+2
-0
sofia.c
src/mod/endpoints/mod_sofia/sofia.c
+30
-20
switch_core.c
src/switch_core.c
+33
-1
switch_core_sqldb.c
src/switch_core_sqldb.c
+51
-37
没有找到文件。
src/include/private/switch_core_pvt.h
浏览文件 @
ef79535c
...
@@ -233,6 +233,8 @@ struct switch_runtime {
...
@@ -233,6 +233,8 @@ struct switch_runtime {
switch_profile_timer_t
*
profile_timer
;
switch_profile_timer_t
*
profile_timer
;
double
profile_time
;
double
profile_time
;
double
min_idle_time
;
double
min_idle_time
;
int
sql_buffer_len
;
int
max_sql_buffer_len
;
};
};
extern
struct
switch_runtime
runtime
;
extern
struct
switch_runtime
runtime
;
...
...
src/mod/endpoints/mod_sofia/sofia.c
浏览文件 @
ef79535c
...
@@ -1225,7 +1225,7 @@ static void sofia_perform_profile_start_failure(sofia_profile_t *profile, char *
...
@@ -1225,7 +1225,7 @@ static void sofia_perform_profile_start_failure(sofia_profile_t *profile, char *
#define sofia_profile_start_failure(p, xp) sofia_perform_profile_start_failure(p, xp, __FILE__, __LINE__)
#define sofia_profile_start_failure(p, xp) sofia_perform_profile_start_failure(p, xp, __FILE__, __LINE__)
#define SQLLEN 1024 *
32
#define SQLLEN 1024 *
1024
void
*
SWITCH_THREAD_FUNC
sofia_profile_worker_thread_run
(
switch_thread_t
*
thread
,
void
*
obj
)
void
*
SWITCH_THREAD_FUNC
sofia_profile_worker_thread_run
(
switch_thread_t
*
thread
,
void
*
obj
)
{
{
sofia_profile_t
*
profile
=
(
sofia_profile_t
*
)
obj
;
sofia_profile_t
*
profile
=
(
sofia_profile_t
*
)
obj
;
...
@@ -1235,8 +1235,8 @@ void *SWITCH_THREAD_FUNC sofia_profile_worker_thread_run(switch_thread_t *thread
...
@@ -1235,8 +1235,8 @@ void *SWITCH_THREAD_FUNC sofia_profile_worker_thread_run(switch_thread_t *thread
uint32_t
qsize
;
uint32_t
qsize
;
void
*
pop
;
void
*
pop
;
int
loop_count
=
0
;
int
loop_count
=
0
;
switch_size_t
sql_len
=
SQLLEN
;
switch_size_t
sql_len
=
1024
*
32
;
char
*
sqlbuf
=
NULL
;
char
*
tmp
,
*
sqlbuf
=
NULL
;
char
*
sql
=
NULL
;
char
*
sql
=
NULL
;
if
(
sofia_test_pflag
(
profile
,
PFLAG_SQL_IN_TRANS
))
{
if
(
sofia_test_pflag
(
profile
,
PFLAG_SQL_IN_TRANS
))
{
...
@@ -1254,33 +1254,43 @@ void *SWITCH_THREAD_FUNC sofia_profile_worker_thread_run(switch_thread_t *thread
...
@@ -1254,33 +1254,43 @@ void *SWITCH_THREAD_FUNC sofia_profile_worker_thread_run(switch_thread_t *thread
while
((
mod_sofia_globals
.
running
==
1
&&
sofia_test_pflag
(
profile
,
PFLAG_RUNNING
))
||
qsize
)
{
while
((
mod_sofia_globals
.
running
==
1
&&
sofia_test_pflag
(
profile
,
PFLAG_RUNNING
))
||
qsize
)
{
if
(
sofia_test_pflag
(
profile
,
PFLAG_SQL_IN_TRANS
))
{
if
(
sofia_test_pflag
(
profile
,
PFLAG_SQL_IN_TRANS
))
{
if
(
(
qsize
>
0
&&
(
qsize
>=
1024
||
++
loop_count
>=
profile
->
trans_timeout
))
||
sql
)
{
if
(
qsize
>
0
&&
(
qsize
>=
1024
||
++
loop_count
>=
profile
->
trans_timeout
)
)
{
switch_size_t
newlen
;
switch_size_t
newlen
;
uint32_t
itterations
=
0
;
uint32_t
itterations
=
0
;
switch_size_t
len
=
0
;
switch_size_t
len
=
0
;
switch_mutex_lock
(
profile
->
ireg_mutex
);
switch_mutex_lock
(
profile
->
ireg_mutex
);
//sofia_glue_actually_execute_sql(profile, "begin;\n", NULL);
while
(
sql
||
(
switch_queue_trypop
(
profile
->
sql_queue
,
&
pop
)
==
SWITCH_STATUS_SUCCESS
&&
pop
))
{
while
(
sql
||
(
switch_queue_trypop
(
profile
->
sql_queue
,
&
pop
)
==
SWITCH_STATUS_SUCCESS
&&
pop
))
{
if
(
!
sql
)
sql
=
(
char
*
)
pop
;
if
(
!
sql
)
{
sql
=
(
char
*
)
pop
;
}
newlen
=
strlen
(
sql
)
+
2
;
newlen
=
strlen
(
sql
)
+
2
;
itterations
++
;
itterations
++
;
if
(
len
+
newlen
+
10
<
sql_len
)
{
if
(
len
+
newlen
+
10
>
sql_len
)
{
sprintf
(
sqlbuf
+
len
,
"%s;
\n
"
,
sql
);
int
new_mlen
=
len
+
newlen
+
10
+
10240
;
len
+=
newlen
;
switch_safe_free
(
sql
);
if
(
new_mlen
<
SQLLEN
)
{
}
else
{
sql_len
=
new_mlen
;
if
(
!
(
tmp
=
realloc
(
sqlbuf
,
sql_len
)))
{
abort
();
break
;
break
;
}
}
sqlbuf
=
tmp
;
}
else
{
goto
skip
;
}
}
sprintf
(
sqlbuf
+
len
,
"%s;
\n
"
,
sql
);
len
+=
newlen
;
free
(
sql
);
sql
=
NULL
;
}
}
skip:
//printf("TRANS:\n%s\n", sqlbuf);
//printf("TRANS:\n%s\n", sqlbuf);
sofia_glue_actually_execute_sql_trans
(
profile
,
sqlbuf
,
NULL
);
sofia_glue_actually_execute_sql_trans
(
profile
,
sqlbuf
,
NULL
);
//sofia_glue_actually_execute_sql(profile, "commit;\n", NULL);
//sofia_glue_actually_execute_sql(profile, "commit;\n", NULL);
...
...
src/switch_core.c
浏览文件 @
ef79535c
...
@@ -1222,7 +1222,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
...
@@ -1222,7 +1222,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
}
}
runtime
.
runlevel
++
;
runtime
.
runlevel
++
;
runtime
.
sql_buffer_len
=
1024
*
32
;
runtime
.
max_sql_buffer_len
=
1024
*
1024
;
runtime
.
dummy_cng_frame
.
data
=
runtime
.
dummy_data
;
runtime
.
dummy_cng_frame
.
data
=
runtime
.
dummy_data
;
runtime
.
dummy_cng_frame
.
datalen
=
sizeof
(
runtime
.
dummy_data
);
runtime
.
dummy_cng_frame
.
datalen
=
sizeof
(
runtime
.
dummy_data
);
runtime
.
dummy_cng_frame
.
buflen
=
sizeof
(
runtime
.
dummy_data
);
runtime
.
dummy_cng_frame
.
buflen
=
sizeof
(
runtime
.
dummy_data
);
...
@@ -1440,6 +1441,37 @@ static void switch_load_core_config(const char *file)
...
@@ -1440,6 +1441,37 @@ static void switch_load_core_config(const char *file)
if
(
tmp
>
-
1
&&
tmp
<
11
)
{
if
(
tmp
>
-
1
&&
tmp
<
11
)
{
switch_core_session_ctl
(
SCSC_DEBUG_LEVEL
,
&
tmp
);
switch_core_session_ctl
(
SCSC_DEBUG_LEVEL
,
&
tmp
);
}
}
}
else
if
(
!
strcasecmp
(
var
,
"sql-buffer-len"
))
{
int
tmp
=
atoi
(
val
);
if
(
end_of
(
val
)
==
'k'
)
{
tmp
*=
1024
;
}
else
if
(
end_of
(
val
)
==
'm'
)
{
tmp
*=
(
1024
*
1024
);
}
if
(
tmp
>=
32000
&&
tmp
<
10500000
)
{
runtime
.
sql_buffer_len
=
tmp
;
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"sql-buffer-len: Value is not within rage 32k to 10m
\n
"
);
}
}
else
if
(
!
strcasecmp
(
var
,
"max-sql-buffer-len"
))
{
int
tmp
=
atoi
(
val
);
if
(
end_of
(
val
)
==
'k'
)
{
tmp
*=
1024
;
}
else
if
(
end_of
(
val
)
==
'm'
)
{
tmp
*=
(
1024
*
1024
);
}
if
(
tmp
<
runtime
.
sql_buffer_len
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Value is not larger than sql-buffer-len
\n
"
);
}
else
if
(
tmp
>=
32000
&&
tmp
<
10500000
)
{
runtime
.
sql_buffer_len
=
tmp
;
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"max-sql-buffer-len: Value is not within rage 32k to 10m
\n
"
);
}
}
else
if
(
!
strcasecmp
(
var
,
"auto-create-schemas"
))
{
}
else
if
(
!
strcasecmp
(
var
,
"auto-create-schemas"
))
{
if
(
switch_true
(
val
))
{
if
(
switch_true
(
val
))
{
switch_set_flag
((
&
runtime
),
SCF_AUTO_SCHEMAS
);
switch_set_flag
((
&
runtime
),
SCF_AUTO_SCHEMAS
);
...
...
src/switch_core_sqldb.c
浏览文件 @
ef79535c
...
@@ -35,8 +35,6 @@
...
@@ -35,8 +35,6 @@
#include <switch.h>
#include <switch.h>
#include "private/switch_core_pvt.h"
#include "private/switch_core_pvt.h"
#define SQLLEN 32768
static
struct
{
static
struct
{
switch_cache_db_handle_t
*
event_db
;
switch_cache_db_handle_t
*
event_db
;
switch_queue_t
*
sql_queue
[
2
];
switch_queue_t
*
sql_queue
[
2
];
...
@@ -48,6 +46,8 @@ static struct {
...
@@ -48,6 +46,8 @@ static struct {
switch_mutex_t
*
io_mutex
;
switch_mutex_t
*
io_mutex
;
switch_mutex_t
*
dbh_mutex
;
switch_mutex_t
*
dbh_mutex
;
switch_hash_t
*
dbh_hash
;
switch_hash_t
*
dbh_hash
;
switch_thread_cond_t
*
cond
;
switch_mutex_t
*
cond_mutex
;
}
sql_manager
;
}
sql_manager
;
...
@@ -539,7 +539,7 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql(switch_cache_db_hand
...
@@ -539,7 +539,7 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql(switch_cache_db_hand
switch
(
dbh
->
type
)
{
switch
(
dbh
->
type
)
{
default
:
default
:
{
{
status
=
switch_cache_db_execute_sql_chunked
(
dbh
,
(
char
*
)
sql
,
SQLLEN
,
err
);
status
=
switch_cache_db_execute_sql_chunked
(
dbh
,
(
char
*
)
sql
,
32768
,
err
);
}
}
break
;
break
;
}
}
...
@@ -850,19 +850,18 @@ SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive(switch_cache_db_hand
...
@@ -850,19 +850,18 @@ SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive(switch_cache_db_hand
static
void
*
SWITCH_THREAD_FUNC
switch_core_sql_thread
(
switch_thread_t
*
thread
,
void
*
obj
)
static
void
*
SWITCH_THREAD_FUNC
switch_core_sql_thread
(
switch_thread_t
*
thread
,
void
*
obj
)
{
{
void
*
pop
=
NULL
;
void
*
pop
;
uint32_t
itterations
=
0
;
uint32_t
itterations
=
0
;
uint8_t
trans
=
0
,
nothing_in_queue
=
0
;
uint8_t
trans
=
0
;
uint32_t
target
=
10
0000
;
uint32_t
target
=
2
0000
;
switch_size_t
len
=
0
,
sql_len
=
SQLLEN
;
switch_size_t
len
=
0
,
sql_len
=
runtime
.
sql_buffer_len
;
char
*
sqlbuf
=
(
char
*
)
malloc
(
sql_len
);
char
*
tmp
,
*
sqlbuf
=
(
char
*
)
malloc
(
sql_len
);
char
*
sql
=
NULL
;
char
*
sql
=
NULL
;
switch_size_t
newlen
;
switch_size_t
newlen
;
int
lc
=
0
;
int
lc
=
0
;
uint32_t
loops
=
0
,
sec
=
0
;
uint32_t
loops
=
0
,
sec
=
0
;
uint32_t
l1
=
1000
;
uint32_t
l1
=
1000
;
uint32_t
sanity
=
120
;
uint32_t
sanity
=
120
;
int
item_remained
=
0
;
switch_assert
(
sqlbuf
);
switch_assert
(
sqlbuf
);
...
@@ -887,6 +886,9 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
...
@@ -887,6 +886,9 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
sql_manager
.
thread_running
=
1
;
sql_manager
.
thread_running
=
1
;
while
(
sql_manager
.
thread_running
==
1
)
{
while
(
sql_manager
.
thread_running
==
1
)
{
switch_mutex_lock
(
sql_manager
.
cond_mutex
);
if
(
++
loops
==
l1
)
{
if
(
++
loops
==
l1
)
{
if
(
++
sec
==
SQL_CACHE_TIMEOUT
)
{
if
(
++
sec
==
SQL_CACHE_TIMEOUT
)
{
sql_close
(
switch_epoch_time_now
(
NULL
));
sql_close
(
switch_epoch_time_now
(
NULL
));
...
@@ -900,16 +902,10 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
...
@@ -900,16 +902,10 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
continue
;
continue
;
}
}
//printf("SIZE %d %d\n", switch_queue_size(sql_manager.sql_queue[0]), switch_queue_size(sql_manager.sql_queue[1]));
if
(
sql
||
switch_queue_trypop
(
sql_manager
.
sql_queue
[
0
],
&
pop
)
==
SWITCH_STATUS_SUCCESS
||
if
(
item_remained
||
switch_queue_trypop
(
sql_manager
.
sql_queue
[
0
],
&
pop
)
==
SWITCH_STATUS_SUCCESS
||
switch_queue_trypop
(
sql_manager
.
sql_queue
[
1
],
&
pop
)
==
SWITCH_STATUS_SUCCESS
)
{
switch_queue_trypop
(
sql_manager
.
sql_queue
[
1
],
&
pop
)
==
SWITCH_STATUS_SUCCESS
)
{
if
(
item_remained
)
{
if
(
!
sql
)
sql
=
(
char
*
)
pop
;
item_remained
=
0
;
}
else
{
sql
=
(
char
*
)
pop
;
}
if
(
sql
)
{
if
(
sql
)
{
newlen
=
strlen
(
sql
)
+
2
;
newlen
=
strlen
(
sql
)
+
2
;
...
@@ -918,45 +914,59 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
...
@@ -918,45 +914,59 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
trans
=
1
;
trans
=
1
;
}
}
/* ignore abnormally large strings sql strings as potential buffer overflow */
if
(
len
+
newlen
>
sql_len
)
{
if
(
newlen
<
SQLLEN
)
{
int
new_mlen
=
len
+
newlen
+
10240
;
itterations
++
;
if
(
len
+
newlen
<
sql_len
)
{
if
(
new_mlen
<
runtime
.
max_sql_buffer_len
)
{
sprintf
(
sqlbuf
+
len
,
"%s;
\n
"
,
sql
);
sql_len
=
new_mlen
;
len
+=
newlen
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG10
,
"REALLOC %ld %d %d
\n
"
,
sql_len
,
switch_queue_size
(
sql_manager
.
sql_queue
[
0
]),
switch_queue_size
(
sql_manager
.
sql_queue
[
1
]));
if
(
!
(
tmp
=
realloc
(
sqlbuf
,
sql_len
)))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CRIT
,
"SQL thread ending on mem err
\n
"
);
abort
();
break
;
}
sqlbuf
=
tmp
;
}
else
{
}
else
{
item_remained
=
1
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG10
,
"SAVE %d %d
\n
"
,
switch_queue_size
(
sql_manager
.
sql_queue
[
0
]),
switch_queue_size
(
sql_manager
.
sql_queue
[
1
]));
goto
skip
;
}
}
}
}
if
(
!
item_remained
)
{
itterations
++
;
sprintf
(
sqlbuf
+
len
,
"%s;
\n
"
,
sql
);
len
+=
newlen
;
free
(
sql
);
free
(
sql
);
}
sql
=
NULL
;
}
else
{
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_NOTICE
,
"SQL thread ending
\n
"
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_NOTICE
,
"SQL thread ending
\n
"
);
break
;
break
;
}
}
}
else
{
nothing_in_queue
=
1
;
}
}
skip
:
lc
=
sql
?
1
:
0
+
switch_queue_size
(
sql_manager
.
sql_queue
[
0
])
+
switch_queue_size
(
sql_manager
.
sql_queue
[
1
]);
if
((
item_remained
||
(
trans
&&
((
itterations
==
target
)
||
(
nothing_in_queue
&&
++
lc
>=
500
))))
&&
if
(
trans
&&
itterations
&&
(
itterations
>
target
||
!
lc
))
{
(
sql_manager
.
event_db
->
native_handle
.
core_db_dbh
))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG10
,
"RUN %d %d %d
\n
"
,
switch_queue_size
(
sql_manager
.
sql_queue
[
0
]),
switch_queue_size
(
sql_manager
.
sql_queue
[
1
]),
itterations
);
if
(
switch_cache_db_persistant_execute_trans
(
sql_manager
.
event_db
,
sqlbuf
,
1
)
!=
SWITCH_STATUS_SUCCESS
)
{
if
(
switch_cache_db_persistant_execute_trans
(
sql_manager
.
event_db
,
sqlbuf
,
1
)
!=
SWITCH_STATUS_SUCCESS
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CRIT
,
"SQL thread unable to commit transaction, records lost!
\n
"
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CRIT
,
"SQL thread unable to commit transaction, records lost!
\n
"
);
}
}
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG10
,
"DONE
\n
"
);
itterations
=
0
;
itterations
=
0
;
trans
=
0
;
trans
=
0
;
nothing_in_queue
=
0
;
len
=
0
;
len
=
0
;
*
sqlbuf
=
'\0'
;
*
sqlbuf
=
'\0'
;
lc
=
0
;
lc
=
0
;
switch_yield
(
400000
);
}
}
if
(
nothing_in_queue
)
{
if
(
!
lc
)
{
switch_
cond_next
(
);
switch_
thread_cond_wait
(
sql_manager
.
cond
,
sql_manager
.
cond_mutex
);
}
}
}
}
...
@@ -1389,6 +1399,7 @@ static void core_event_handler(switch_event_t *event)
...
@@ -1389,6 +1399,7 @@ static void core_event_handler(switch_event_t *event)
switch_queue_push
(
sql_manager
.
sql_queue
[
0
],
sql
[
i
]);
switch_queue_push
(
sql_manager
.
sql_queue
[
0
],
sql
[
i
]);
}
}
sql
[
i
]
=
NULL
;
sql
[
i
]
=
NULL
;
switch_thread_cond_broadcast
(
sql_manager
.
cond
);
}
}
}
}
}
}
...
@@ -1511,6 +1522,9 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
...
@@ -1511,6 +1522,9 @@ 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_thread_cond_create
(
&
sql_manager
.
cond
,
sql_manager
.
memory_pool
);
switch_core_hash_init
(
&
sql_manager
.
dbh_hash
,
sql_manager
.
memory_pool
);
switch_core_hash_init
(
&
sql_manager
.
dbh_hash
,
sql_manager
.
memory_pool
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论