ConfD User Community

How to configure HA from erlang econfd application?


#1

Hi,

How do I configure HA from my econfd application?

Regards.


#2

Hi @mazhar

Use the Erlang documentation doc/api/econfd/econfd_ha.html, together with the C example examples.confd/ha, and the UG chapters “High Availability” and “High Availability - Cluster Events”.

Regards


#3

Hello,

I have been trying that but I am getting an error and the connection is getting closed and I am unable to figure out that error.
The socket connection is getting closed when I run the function econfd_ha:bemaster/2.

My setup :

I have an HA tag in my confd.conf as follows
< ha>
< enabled>true< /enabled>
< ip>0.0.0.0< /ip>
< port>4569< /port>
< /ha>

Next, I start the econfd application and run the connect function as follows
1> econfd_ha:connect({192,168,21,29}, 4569, <<“utl”>>).
{ok,#Port<0.782>}

Now I am passing the sock reference to the bemaster function with a nodeid as follows

2>econfd_ha:bemaster(#Port<0.783>, “node1”).
{error,closed}

When I run this bemaster function the program hangs for a while and throws the exception as {error, closed}.

Why am I getting this error? What am I doing wrong here?

Regards.


#4

So, this is the port that the master listens on for connections from slaves.

But econfd_ha:connect/3 should (just like confd_ha_connect() in the C API) connect to the IPC port - default 4565, defined as ?CONFD_PORT when using econfd.

Hm, I guess that line is “just for information”, since you can’t actually type “#Port<0.783>” in the Erlang shell. If you are trying things out in the shell (a nice way to test), the way to go is to bind the port/socket by matching on the reply from econfd_ha:connect/2,3.

{ok, S} = econfd_ha:connect(Ip, <<"utl”>>).
econfd_ha:bemaster(S, <<“node1”>>).

As an aside, I may be mistaken here, but it seems to me that you are trying to learn ConfD and Erlang (in general) simultaneously. It might be a better idea to learn ConfD through the C examples, and Erlang through some non-ConfD tutorials, before tackling the combination.


#5

Yes, it is.

Oh I see. But I want to use port 4569 and not the default port 4565. What additional parameters do I have to add in my confd.conf file in order to achieve this? And also the econfd:connect/3 function takes the port number as one of its arguments, what is that for? I was assuming that this additional argument allows me to connect to whichever IPC port I want to connect to. Is it so?

Yes of course it is. And yes I am actually binding the port/socket to the reply from econfd_ha:connect/2,3 but the connection was just getting closed. Now I understand it’s the problem with the port and how econfd connects to default IPC port 4565. However, I want econfd to connect to a different IPC port. What do I do for this?

No, I am not. I have already worked on a few erlang projects. I was just confused by the fact that my connection is getting closed when I run the function econfd:bemaster/2. As in general if I am able to connect to the IPC port I should have been able to run the econfd:bemaster/2 function successfully.


#6

To set the IPC port and HA port respectively, in your confd.conf file see:
/confdConfig/confdIpcAddress/port – default 4565
/confdConfig/ha/port – default 4569


#7

I have followed this and it is working fine now. But still, I am unable to set the slave node from my Erlang application.

From my managed object application (running on different host than confD), I am running the functions as follows

1> {ok, S} = econfd_ha:connect({192,168,21,29}, <<"utl”>>).
2> econfd_ha:beslave( S, <<“node2”>>, #ha_node{addr = {192,168,21,29}, nodeid = <<“node1”>>, 0}).

For this, I am getting a return value as “ok”. But when I check the confD status the slave node is neither configured nor connected to the cluster.

What am I doing wrong here? The edoc for econfd has limited information so I am unable to trace back the error.


#8

Are you using the ConfD developer log with log level “trace” to debug? E.g. in confd.conf something like:

    <developerLog>
      <enabled>true</enabled>
      <file>
        <enabled>true</enabled>
        <name>./devel.log</name>
      </file>
      <syslog>
        <enabled>false</enabled>
      </syslog>
    </developerLog>
    <developerLogLevel>trace</developerLogLevel>

#9

Yes, I am using the ConfD developer log but not with a log level. What exactly does it do?


#10

And I have another question. My confd.conf file in the standby node should be an exact replica of confd.conf file as in the active node, is it?

And also from the standby node, do I have to connect to my local HA subsystem or to my master node HA subsystem?

My HA configuration is as follows in both the systems (Active and Standby, running on different hosts).

< ha>
< enabled>true< /enabled>
< ip>0.0.0.0< /ip>
< port>4569< /port>
< /ha>

do I have to give proper IP here? I am a little confused.


#11

Save time by reading the man page for confd.conf instead of posting questions about what it says. For example:

$ man $CONFD_DIR/man/man5/confd.conf.5

look for “developerLogLevel”


#12

It can be, but doesn’t have to.

0.0.0.0 is the default setting. See ConfD UG under Chapter “High Availability” section “Security aspects” for more.


#13

Yes, I have gone through the manual page and it just says,
Controls which level of developer messages are printed in the developer log. This configuration parameter takes effect for both existing and new sessions. However, I
want to know if there is any specific way to interpret the trace message.

As I can see in my devel.log file, it just says in the last line “confd embedded apps in phase2”. I don’t see any trace related to HA.


#14

Which is exactly why you want to set the developerLogLevel to “trace” instead of using the default “info” level.


#15

That’s what the devel.log file has even after setting the developerLogLevel to trace.

I am performing all the required steps in my econfd application as

1> {ok, S} = econfd_ha:connect({192,168,21,29}, <<"utl”>>).
{ok,#Port<0.765>}
2> econfd_ha:beslave( S, <<“node2”>>, #ha_node{addr = {192,168,21,29}, nodeid = <<“node1”>>, 0}).
ok

Still, the slave node is neither configured nor connected to the cluster when i check the confd status.

And I still have no trace messages related to HA in my devel.log file even after setting the developerLogLevel to “trace”.

What am I doing wrong? Everything seems to be right here as my function executes successfully with expected return value but still, the slave node won’t connect to the cluster.


#16

And what does the developer log say for the master/active node?


#17

The developer log for the master/active node just says confd HA_INFO_IS_MASTER.


#18

1> {ok, S} = econfd_ha:connect({192,168,21,29}, <<"utl”>>).
{ok,#Port<0.765>}
2> econfd_ha:beslave( S, <<“node2”>>, #ha_node{addr = {192,168,21,29}, nodeid = <<“node1”>>, 0}).
ok

From your output from the Erlang shell I read that you connect to “node2” on ip 192.168.21.29 and then make it slave while telling it to connect to the master/“node1” on the same 192.168.21.29 IP address?
Are you trying to start two ConfD instances on the same machine with the same IPC/HA/etc ports configured in confd.conf? Or is the mistake that you use the same IP address for “node1” and “node2”?


#19

Sorry my bad it is a typo. It is supposed to be

1> {ok, S} = econfd_ha:connect({192,168,21,24}, <<"utl”>>).

I am connecting to “node2” on IP 192.168.21.24 and instructing it to be a slave with a master as “node1” on IP 192.168.21.29.


#20

Both the master and slave’s developer log, trace level, will say “New HA socket connected” after you made a successful econfd_ha:connect(). Do they?