Heartbeat的可靠消息通信实现分析

http://tech.ddvip.com   2007年05月21日    社区交流

本文详细介绍Heartbeat的可靠消息通信实现分析

static void add2_xmit_hist (struct msg_xmit_hist *hist, struct ha_msg *msg,
seqno_t seq)
{
int slot;
struct ha_msg *slotmsg;
...
/*查找队列里消息存放的位置*/
slot = hist->lastmsg + 1;
if (slot >= MAXMSGHIST) {
/*到达队尾,从头开始。在这里实现循环队列*/
slot = 0;
}
hist->hiseq = seq;
slotmsg = hist->msgq[slot];
/*删除队列中找到的位置上的旧消息*/
if (slotmsg != NULL) {
hist->lowseq = hist->seqnos[slot];
hist->msgq[slot] = NULL;
if (!ha_is_allocated(slotmsg)) {
...
} else {
ha_msg_del(slotmsg);
}
}
hist->msgq[slot] = msg;
hist->seqnos[slot] = seq;
hist->lastrexmit[slot] = 0L;
hist->lastmsg = slot;
if (enable_flow_control && live_node_count > 1
&& (hist->hiseq – hist->lowseq) > ((MAXMSGHIST*3)/4)) {
/*消息队列长度大于告警长度,记录日志*/
...
}
if (enable_flow_control
&& hist->hiseq – hist->ackseq > FLOWCONTROL_LIMIT) {
/*消息队列的长度大于流控限制长度*/
if (live_node_count < 2) {
/*集群里只有本机节点为存活节点,更新历史消息队列,删除旧消息,
以防止历史消息队列满*/
update_ackseq(hist->hiseq – (FLOWCONTROL_LIMIT – 1));
all_clients_resume();
} else {
/*client进程发送消息过快,暂停所有的client进程*/
all_clients_pause();
hist_display(hist);
}
}
}

责编:豆豆技术应用

正在加载评论...