<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EstiloCorreo17
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 3.0cm 70.85pt 3.0cm;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=ES link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Hi,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I think you should have the state of the server updated in all nodes, so when a node goes down it will be restarted with the current state.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>If entire application in all nodes goes down I think there is no sense in having the last state you can start over from the initial state (0 in this case) since the application will start entirely over. But if it does have any sense for other purposes, then when the fail over process start you should store the last state in a distribute storage manager like dets or mnesia and then you can restart the entire application having the lasted state stored in one of the distributed nodes (you don’t need to know which node because the distributed storage manager will give you the most updated information).<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Best Regards,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Ivan.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>De:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> erlang-questions-bounces@erlang.org [mailto:erlang-questions-bounces@erlang.org] <b>En nombre de </b>reaperman123456789@gmail.com<br><b>Enviado el:</b> miércoles, 14 de agosto de 2013 7:21<br><b>Para:</b> erlang-programming@googlegroups.com<br><b>Asunto:</b> [erlang-questions] Maintaining state between application failover<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><div><p class=MsoNormal><span lang=EN-US>Assuming a distributed application, how could state between application starts due to failover be maintained?<br><br>For illustration purposes, consider the following problem:<br>We want a kind of server that delivers unique numbers. Starting at 0, on each request this number is delivered and incremented.<br>For implementation, we use a gen_server process that keeps the current number in it's state. We put that process under a one-for-one supervisor, which serves as the top supervisor of the application.<br><br>Now, even in a non-distributed setup, the gen_server could not maintain the state between restarts managed by it's supervisor. We could store the current number in the environment of the application itself (which doesn't feel right, but for illustration purposes let's keep it in mind), where it would survive restarts of the gen_server process.<br>In a distributed setup, even the state stored in the application environment would not survive in case of an application failover. When the node on which the application is running dies and is restarted on another node, it starts at 0 again.<br><br>Performance considerations aside, the current number could be constantly kept and updated permanently in a state file which could then be read at startup. But since the nodes would usually be running on different machines, on failover the application would be restartet on another machine than the one where the file resided, and since the reason for the death of the erlang node is presumable the death of the hardware node, would not be accessible from the application started in failover mode. For keeping the state file accessible everywhere, we would need to put it on a NFS mount or something, but the NFS server would become a critical component in our setup, not to mention the overkill of running an extra machine for the single purpose of sharing a single file which would not exceed a few bytes in size. Using a database of whatever flavor is essentially the same.<br><br>So, how could state be efficiently maintained in the erlang way of doing things?<br><br>To clarify, I am <u>not</u> asking for a solution to the problem of generating unique numbers, there a probably a thousand ways to do this in a better way, UUID and whatnot. I am asking for ways to maintain state between restarts of a distributed application in a failover scenario. The example problem above is a special case of the general problem I am asking about, made up purely for the purpose of having a simple illustration. A solution of the general problem would automatically solve the special case, anyway ;)<o:p></o:p></span></p></div></div></body></html>