Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch-contrib
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch-contrib
Commits
bfe17f31
提交
bfe17f31
authored
3月 26, 2011
作者:
Eliot Gable
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More additions, bug fixes, and change to atomic operations to replace many rwlocks.
上级
8255607b
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
388 行增加
和
183 行删除
+388
-183
ha_cluster_config.c
mod/applications/mod_ha_cluster/ha_cluster_config.c
+10
-37
ha_cluster_interfaces.c
mod/applications/mod_ha_cluster/ha_cluster_interfaces.c
+144
-94
mod_ha_cluster.c
mod/applications/mod_ha_cluster/mod_ha_cluster.c
+199
-26
mod_ha_cluster.h
mod/applications/mod_ha_cluster/mod_ha_cluster.h
+35
-26
没有找到文件。
mod/applications/mod_ha_cluster/ha_cluster_config.c
浏览文件 @
bfe17f31
...
@@ -537,6 +537,8 @@ switch_status_t config_hb(hac_hb_t** hb, switch_xml_t root)
...
@@ -537,6 +537,8 @@ switch_status_t config_hb(hac_hb_t** hb, switch_xml_t root)
cur
->
lport
=
atoi
(
port
);
cur
->
lport
=
atoi
(
port
);
cur
->
ttl
=
ttl
;
cur
->
ttl
=
ttl
;
cur
->
next
=
NULL
;
cur
->
next
=
NULL
;
switch_thread_rwlock_create
(
&
cur
->
recv_lock
,
config
.
pool
);
switch_thread_rwlock_create
(
&
cur
->
send_lock
,
config
.
pool
);
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
fail:
fail:
return
SWITCH_STATUS_FALSE
;
return
SWITCH_STATUS_FALSE
;
...
@@ -611,9 +613,7 @@ switch_status_t config_general(switch_xml_t root)
...
@@ -611,9 +613,7 @@ switch_status_t config_general(switch_xml_t root)
value
=
switch_xml_attr
(
x_list
,
"value"
);
value
=
switch_xml_attr
(
x_list
,
"value"
);
if
(
!
switch_strlen_zero
(
value
))
{
if
(
!
switch_strlen_zero
(
value
))
{
config
.
general
.
nodeid
=
value
;
config
.
general
.
nodeid
=
value
;
switch_thread_rwlock_wrlock
(
hac_globals
.
lock
);
switch_atomic_set
(
&
hac_globals
.
nodeid
,
(
switch_strlen_zero
(
value
)
?
-
1
:
atoi
(
value
)));
hac_globals
.
nodeid
=
(
switch_strlen_zero
(
value
)
?
-
1
:
atoi
(
value
));
switch_thread_rwlock_unlock
(
hac_globals
.
lock
);
}
else
{
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CRIT
,
"HAC: Missing nodeid value in general section.
\n
"
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CRIT
,
"HAC: Missing nodeid value in general section.
\n
"
);
goto
fail
;
goto
fail
;
...
@@ -623,31 +623,12 @@ switch_status_t config_general(switch_xml_t root)
...
@@ -623,31 +623,12 @@ switch_status_t config_general(switch_xml_t root)
goto
fail
;
goto
fail
;
}
}
if
((
x_list
=
switch_xml_child
(
root
,
"master-slave-ratio"
)))
{
const
char
*
value
=
NULL
;
value
=
switch_xml_attr
(
x_list
,
"value"
);
if
(
!
switch_strlen_zero
(
value
))
{
config
.
general
.
msr
=
value
;
switch_thread_rwlock_wrlock
(
hac_globals
.
lock
);
hac_globals
.
msr
=
(
switch_strlen_zero
(
value
)
?
"4:1"
:
value
);
switch_thread_rwlock_unlock
(
hac_globals
.
lock
);
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CRIT
,
"HAC: Missing master-slave-ratio value in general section.
\n
"
);
goto
fail
;
}
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CRIT
,
"HAC: Missing master-slave-ratio element in general section.
\n
"
);
goto
fail
;
}
if
((
x_list
=
switch_xml_child
(
root
,
"timer-a"
)))
{
if
((
x_list
=
switch_xml_child
(
root
,
"timer-a"
)))
{
const
char
*
value
=
NULL
;
const
char
*
value
=
NULL
;
value
=
switch_xml_attr
(
x_list
,
"value"
);
value
=
switch_xml_attr
(
x_list
,
"value"
);
if
(
!
switch_strlen_zero
(
value
))
{
if
(
!
switch_strlen_zero
(
value
))
{
config
.
general
.
timer_a
=
value
;
config
.
general
.
timer_a
=
value
;
switch_thread_rwlock_wrlock
(
hac_globals
.
lock
);
switch_atomic_set
(
&
hac_globals
.
timer_a_dur
,
(
switch_strlen_zero
(
value
)
?
60
:
atoi
(
value
)));
hac_globals
.
timer_a_dur
=
(
switch_strlen_zero
(
value
)
?
60
:
atoi
(
value
));
switch_thread_rwlock_unlock
(
hac_globals
.
lock
);
}
else
{
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CRIT
,
"HAC: Missing timer-a value in general section.
\n
"
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CRIT
,
"HAC: Missing timer-a value in general section.
\n
"
);
goto
fail
;
goto
fail
;
...
@@ -662,9 +643,7 @@ switch_status_t config_general(switch_xml_t root)
...
@@ -662,9 +643,7 @@ switch_status_t config_general(switch_xml_t root)
value
=
switch_xml_attr
(
x_list
,
"value"
);
value
=
switch_xml_attr
(
x_list
,
"value"
);
if
(
!
switch_strlen_zero
(
value
))
{
if
(
!
switch_strlen_zero
(
value
))
{
config
.
general
.
timer_b
=
value
;
config
.
general
.
timer_b
=
value
;
switch_thread_rwlock_wrlock
(
hac_globals
.
lock
);
switch_atomic_set
(
&
hac_globals
.
timer_b_dur
,
(
switch_strlen_zero
(
value
)
?
60
:
atoi
(
value
)));
hac_globals
.
timer_b_dur
=
(
switch_strlen_zero
(
value
)
?
60
:
atoi
(
value
));
switch_thread_rwlock_unlock
(
hac_globals
.
lock
);
}
}
}
}
...
@@ -673,17 +652,13 @@ switch_status_t config_general(switch_xml_t root)
...
@@ -673,17 +652,13 @@ switch_status_t config_general(switch_xml_t root)
value
=
switch_xml_attr
(
x_list
,
"value"
);
value
=
switch_xml_attr
(
x_list
,
"value"
);
if
(
!
switch_strlen_zero
(
value
))
{
if
(
!
switch_strlen_zero
(
value
))
{
config
.
general
.
failure_threshold
=
value
;
config
.
general
.
failure_threshold
=
value
;
switch_thread_rwlock_wrlock
(
hac_globals
.
lock
);
switch_atomic_set
(
&
hac_globals
.
failure_threshold
,
(
switch_strlen_zero
(
value
)
?
5000
:
atoi
(
value
)));
hac_globals
.
failure_threshold
=
(
switch_strlen_zero
(
value
)
?
5000
:
atoi
(
value
));
switch_thread_rwlock_unlock
(
hac_globals
.
lock
);
}
else
{
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_WARNING
,
"HAC: Missing failure-threshold value in general section; defaulted to 5000ms.
\n
"
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_WARNING
,
"HAC: Missing failure-threshold value in general section; defaulted to 5000ms.
\n
"
);
}
}
}
else
{
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_WARNING
,
"HAC: Missing failure-threshold element in general section; defaulting to 5000ms.
\n
"
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_WARNING
,
"HAC: Missing failure-threshold element in general section; defaulting to 5000ms.
\n
"
);
switch_thread_rwlock_wrlock
(
hac_globals
.
lock
);
switch_atomic_set
(
&
hac_globals
.
failure_threshold
,
5000
);
hac_globals
.
failure_threshold
=
5000
;
switch_thread_rwlock_unlock
(
hac_globals
.
lock
);
}
}
config
.
general
.
heartbeat
=
switch_core_alloc
(
config
.
pool
,
sizeof
(
hac_hb_t
));
config
.
general
.
heartbeat
=
switch_core_alloc
(
config
.
pool
,
sizeof
(
hac_hb_t
));
...
@@ -692,9 +667,9 @@ switch_status_t config_general(switch_xml_t root)
...
@@ -692,9 +667,9 @@ switch_status_t config_general(switch_xml_t root)
if
(
config_hb
(
&
cur
,
x_list
)
!=
SWITCH_STATUS_SUCCESS
)
{
if
(
config_hb
(
&
cur
,
x_list
)
!=
SWITCH_STATUS_SUCCESS
)
{
goto
fail
;
goto
fail
;
}
}
switch_thread_rwlock_wrlock
(
hac_globals
.
lock
);
switch_thread_rwlock_wrlock
(
hac_globals
.
hb_
lock
);
hac_globals
.
hb
=
config
.
general
.
heartbeat
;
hac_globals
.
hb
=
config
.
general
.
heartbeat
;
switch_thread_rwlock_unlock
(
hac_globals
.
lock
);
switch_thread_rwlock_unlock
(
hac_globals
.
hb_
lock
);
}
}
if
(
switch_strlen_zero
(
config
.
general
.
heartbeat
->
address
))
{
if
(
switch_strlen_zero
(
config
.
general
.
heartbeat
->
address
))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CRIT
,
"HAC: Missing heartbeat element in general section.
\n
"
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CRIT
,
"HAC: Missing heartbeat element in general section.
\n
"
);
...
@@ -743,9 +718,7 @@ switch_status_t do_config(switch_bool_t reload)
...
@@ -743,9 +718,7 @@ switch_status_t do_config(switch_bool_t reload)
}
}
switch_xml_free
(
xml
);
switch_xml_free
(
xml
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CONSOLE
,
"HAC: Configuration loaded.
\n
"
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CONSOLE
,
"HAC: Configuration loaded.
\n
"
);
switch_thread_rwlock_wrlock
(
hac_globals
.
lock
);
switch_atomic_set
(
&
hac_globals
.
state
,
HAC_PEER_STARTING
);
hac_globals
.
state
=
HAC_PEER_STARTING
;
switch_thread_rwlock_unlock
(
hac_globals
.
lock
);
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
failconfig:
failconfig:
...
...
mod/applications/mod_ha_cluster/ha_cluster_interfaces.c
浏览文件 @
bfe17f31
差异被折叠。
点击展开。
mod/applications/mod_ha_cluster/mod_ha_cluster.c
浏览文件 @
bfe17f31
差异被折叠。
点击展开。
mod/applications/mod_ha_cluster/mod_ha_cluster.h
浏览文件 @
bfe17f31
...
@@ -23,16 +23,22 @@
...
@@ -23,16 +23,22 @@
extern
unsigned
char
MAGIC
[];
extern
unsigned
char
MAGIC
[];
/*static char *MARKER = "1"; */
/*static char *MARKER = "1"; */
typedef
enum
{
/* Atomic state type so we don't need rwlocks */
HAC_PEER_UNKNOWN
=
0
,
#define HAC_PEER_UNKNOWN 0
HAC_PEER_STARTING
=
1
,
#define HAC_PEER_STARTING 1
HAC_PEER_MASTER
=
2
,
#define HAC_PEER_MASTER 2
HAC_PEER_SLAVE
=
3
,
#define HAC_PEER_SLAVE 3
HAC_PEER_FAILED_MASTER
=
4
,
#define HAC_PEER_FAILED_MASTER 4
HAC_PEER_FAILED_SLAVE
=
5
,
#define HAC_PEER_FAILED_SLAVE 5
HAC_PEER_STOPPING_MASTER
=
6
,
#define HAC_PEER_STOPPING_MASTER 6
HAC_PEER_STOPPING_SLAVE
=
7
#define HAC_PEER_STOPPING_SLAVE 7
}
hac_peer_state_t
;
typedef
switch_atomic_t
hac_peer_state_t
;
/* Atomic state type so we don't need rwlocks */
#define HAC_LOOPING 0
#define HAC_SHUTDOWN_RUNTIME 1
#define HAC_UNLOAD 2
typedef
switch_atomic_t
hac_state_t
;
struct
s_hac_rule
{
struct
s_hac_rule
{
const
char
*
name
;
const
char
*
name
;
...
@@ -157,6 +163,8 @@ struct s_hac_hb {
...
@@ -157,6 +163,8 @@ struct s_hac_hb {
switch_socket_t
*
udp_sock
;
switch_socket_t
*
udp_sock
;
struct
timeval
last_hb
;
struct
timeval
last_hb
;
struct
s_hac_hb
*
next
;
struct
s_hac_hb
*
next
;
switch_thread_rwlock_t
*
recv_lock
;
switch_thread_rwlock_t
*
send_lock
;
};
};
typedef
struct
s_hac_hb
hac_hb_t
;
typedef
struct
s_hac_hb
hac_hb_t
;
...
@@ -193,18 +201,14 @@ struct s_hac_config {
...
@@ -193,18 +201,14 @@ struct s_hac_config {
};
};
typedef
struct
s_hac_config
hac_config_t
;
typedef
struct
s_hac_config
hac_config_t
;
typedef
enum
{
HAC_LOOPING
=
0
,
HAC_SHUTDOWN_RUNTIME
=
1
,
HAC_UNLOAD
=
2
}
hac_state_t
;
extern
hac_config_t
config
;
extern
hac_config_t
config
;
struct
s_hac_event
{
struct
s_hac_event
{
switch_event_t
*
event
;
switch_event_t
*
event
;
switch_bool_t
processed
;
switch_bool_t
processed
;
switch_atomic_t
refcount
;
const
char
*
uuid
;
struct
timeval
arrived
;
struct
timeval
arrived
;
};
};
typedef
struct
s_hac_event
hac_event_t
;
typedef
struct
s_hac_event
hac_event_t
;
...
@@ -227,31 +231,36 @@ struct s_hac_peer {
...
@@ -227,31 +231,36 @@ struct s_hac_peer {
struct
timeval
last_seen
;
struct
timeval
last_seen
;
hac_peer_state_t
state
;
hac_peer_state_t
state
;
uint64_t
missed_beats
;
uint64_t
missed_beats
;
switch_atomic_t
refcount
;
switch_thread_rwlock_t
*
lock
;
};
};
typedef
struct
s_hac_peer
hac_peer_t
;
typedef
struct
s_hac_peer
hac_peer_t
;
struct
s_global
{
struct
s_global
{
switch_memory_pool_t
*
pool
;
switch_memory_pool_t
*
pool
;
char
hostname
[
256
];
char
hostname
[
256
];
uint64
_t
host_hash
;
switch_atomic
_t
host_hash
;
switch_memory_pool_t
*
event_pool
;
switch_memory_pool_t
*
event_pool
;
switch_hash_t
*
event_hash
;
switch_hash_t
*
event_hash
;
switch_hash_t
*
peer_hash
;
switch_hash_t
*
peer_hash
;
hac_peer_state_t
state
;
hac_peer_state_t
state
;
hac_state_t
mod_state
;
hac_state_t
mod_state
;
hac_hb_t
*
hb
;
hac_hb_t
*
hb
;
int
nodeid
;
switch_atomic_t
nodeid
;
uint64_t
rand_val
;
switch_atomic_t
rand_val
;
const
char
*
msr
;
switch_atomic_t
req_masters
;
int
req_masters
;
switch_atomic_t
masters
;
int
masters
;
switch_atomic_t
slaves
;
int
slaves
;
switch_atomic_t
timer_a_dur
;
int
timer_a_dur
;
switch_atomic_t
timer_b_dur
;
int
timer_b_dur
;
struct
timeval
timer_a
;
struct
timeval
timer_a
;
struct
timeval
timer_b
;
struct
timeval
timer_b
;
int
failure_threshold
;
switch_atomic_t
failure_threshold
;
switch_atomic_t
max_latency
;
switch_thread_rwlock_t
*
lock
;
switch_thread_rwlock_t
*
lock
;
switch_thread_rwlock_t
*
hb_lock
;
switch_thread_rwlock_t
*
event_hash_lock
;
switch_thread_rwlock_t
*
peer_hash_lock
;
};
};
extern
struct
s_global
hac_globals
;
extern
struct
s_global
hac_globals
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论