paper4—Multi-MPE_Trigger_Algorithm—temp
2016-02-01 00:00
531 查看
点击(此处)折叠或打开
Description: when SMD start, this algorithm will run as a deamon, two roles: Master,
Slave. When the SMD is elected as a Master role, then, the MPE will be the master MPE accessed by other SMD, and related process data will backup to other
SMD (Slave MPE).
ctrl: Master or Slave, this value is set by batman-adv;
ctrl=0, SMD is Slave role;
ctrl=1, SMD is elected as a Master role;
changed: Master or Slave, this value is set by batman-adv;
changed=0, Master SMD is not changed, so, do not need to create thread in MAIN again for data synchronization;
changed=1, Master SMD is changed, so, need to create thread in MAIN again for data synchronization;
changed=0;
is_me=-1;
prev_state=-1; //0:Slave; 1:Master;
//READ_CTRL, set URL of application system. Access master_ip in browser.
PROCEDURE: READ_CTRL
prev_ip=0.0.0.0;
while true do
read the value of ctrl set by batman-adv;
read master_ip of Master SMD;
if master_ip==me_ip and is_me!=-1 then
prev_state=is_me;
is_me=1;
else if master_ip!=me_ip and is_me!=-1 then
prev_state=is_me;
is_me=0;
end if
if master_ip!=prev_ip then
changed=1;
prev_ip=master_ip;
add (or update) "master_ip mpe.localhost" in /etc/hosts;
end if
sleep 1s;
done
END PROCEDURE READ_CTRL
//******************************
MAIN Thread
PROCEDURE: MAIN
pthread_create(READ_CTRL);
sleep 1s; //waiting for READ_CTRL to read the value of ctrl and master_ip of Master SMD
start=1; //set initial state
while true do
if start==1 and ctrl==1 then
start=0;
is_me=1;
pthread_create(Master);
pthread_join(Master);
else if start==1 and ctrl==0 then
start=0;
is_me=0;
pthread_create(Slave);
pthread_join(Slave);
else if start==0 and changed==1 and ctrl==1 then
pthread_create(Master);
pthread_join(Master);
else if start==0 and changed==1 and ctrl==0 then
sleep(2); //waiting master initialize
pthread_create(Master);
pthread_join(Master);
else //start==0 and changed==0
continue;
end if
done
END PROCEDURE MAIN
//******************************
Master Thread
PROCEDURE: Master
socket();
bind();
listen();
while true do
accept(); //waiting for connect from Slave
pthread_create(M_THREAD);
done
END PROCEDURE Master
//******************************
M_THREAD Thread
PROCEDURE: M_THREAD
while true do //communication between Master & Slave
if database updating then
send synchronous data to Slave;
end if
done
END PROCEDURE M_THREAD
//******************************
Slave Thread
PROCEDURE: Slave
socket();
connect();
while true do
if receive synchronous data from Master then
update database;
end if
done
END PROCEDURE Slave
Description: when SMD start, this algorithm will run as a deamon, two roles: Master,
Slave. When the SMD is elected as a Master role, then, the MPE will be the master MPE accessed by other SMD, and related process data will backup to other
SMD (Slave MPE).
ctrl: Master or Slave, this value is set by batman-adv;
ctrl=0, SMD is Slave role;
ctrl=1, SMD is elected as a Master role;
changed: Master or Slave, this value is set by batman-adv;
changed=0, Master SMD is not changed, so, do not need to create thread in MAIN again for data synchronization;
changed=1, Master SMD is changed, so, need to create thread in MAIN again for data synchronization;
changed=0;
is_me=-1;
prev_state=-1; //0:Slave; 1:Master;
//READ_CTRL, set URL of application system. Access master_ip in browser.
PROCEDURE: READ_CTRL
prev_ip=0.0.0.0;
while true do
read the value of ctrl set by batman-adv;
read master_ip of Master SMD;
if master_ip==me_ip and is_me!=-1 then
prev_state=is_me;
is_me=1;
else if master_ip!=me_ip and is_me!=-1 then
prev_state=is_me;
is_me=0;
end if
if master_ip!=prev_ip then
changed=1;
prev_ip=master_ip;
add (or update) "master_ip mpe.localhost" in /etc/hosts;
end if
sleep 1s;
done
END PROCEDURE READ_CTRL
//******************************
MAIN Thread
PROCEDURE: MAIN
pthread_create(READ_CTRL);
sleep 1s; //waiting for READ_CTRL to read the value of ctrl and master_ip of Master SMD
start=1; //set initial state
while true do
if start==1 and ctrl==1 then
start=0;
is_me=1;
pthread_create(Master);
pthread_join(Master);
else if start==1 and ctrl==0 then
start=0;
is_me=0;
pthread_create(Slave);
pthread_join(Slave);
else if start==0 and changed==1 and ctrl==1 then
pthread_create(Master);
pthread_join(Master);
else if start==0 and changed==1 and ctrl==0 then
sleep(2); //waiting master initialize
pthread_create(Master);
pthread_join(Master);
else //start==0 and changed==0
continue;
end if
done
END PROCEDURE MAIN
//******************************
Master Thread
PROCEDURE: Master
socket();
bind();
listen();
while true do
accept(); //waiting for connect from Slave
pthread_create(M_THREAD);
done
END PROCEDURE Master
//******************************
M_THREAD Thread
PROCEDURE: M_THREAD
while true do //communication between Master & Slave
if database updating then
send synchronous data to Slave;
end if
done
END PROCEDURE M_THREAD
//******************************
Slave Thread
PROCEDURE: Slave
socket();
connect();
while true do
if receive synchronous data from Master then
update database;
end if
done
END PROCEDURE Slave
相关文章推荐
- AlphaGo:黑色方碑?
- paper4—Multi-MPE_Trigger_Algorithm—testing
- paper3—Algorithm1-Engine-Trigger-on-FCD—temp
- paper3—Algorithm2-Engine-Trigger-on-SMD—temp
- Google Guava 类库简介
- 114DNS Public DNS+ 阿里DNS 百度DNS 360 DNS派 Google DNS
- pymongo简单用法
- Google大中华区总裁石博盟用中文拜年
- ZOJ-2855-Google Map【4th浙江省赛】
- LeetCode Algorithms #169 <Majority Element>
- LeetCode Algorithms #171 <Excel Sheet Column Number>
- lightoj1030 - Discovering Gold【概率dp求期望】
- LeetCode Algorithms #242 <Valid Anagram>
- POJ 3259/USACO 2006 December Gold:Wormholes
- LeetCode Algorithms #292 <Nim Game>
- 《Learn You Some Erlang for Great Good!》的学习笔记(四)
- projecteuler---->problem=9----Special Pythagorean triplet
- 【HDOJ】4775 Infinite Go
- Tango学习笔记(一)
- Google Chrome v48.0.2564.