Creating a cluster of nodes in C++ REST

Creating a cluster of nodes…

I have a server appz that can be forked either to start nodes or the main server controller node.

When a node starts, its register with the node controller (master) giving its ip, its port and a name.

The node controller keeps that information in a std::vector<T>.

There is also an admin tool to send commands and see what’s in the master node.

start myserver

start myserver 192.168.1.33 7002 node node_1

start myserver 192.168.1.33 7003 node node_2

start myserver 192.168.1.33 7004 node node_3

start myclient 192.168.1.33 7001

The first myserver instance is the controller node (master). All others instances are worker nodes on a dedicated ip/port.

They all register with master. Master node will allow a node to be active when a client request for a node…

An admin tool allow to known when it happened:

F:DevGitHubLMDBLMDBWindowsx64Debug>admin 192.168.1.33 7001

Client http://192.168.1.33:7001/MyServer/LMDB/

Enter a command:?request=show-nodes

HTTP/1.1 200 OK

Content-Length: 0

Date: Sat, 19 May 2018 15:25:52 GMT

Server: Microsoft-HTTPAPI/2.0

Message GET /MyServer/LMDB/?request=show-nodes HTTP/1.1

Connection: Keep-Alive

Host: 192.168.1.33:7001

User-Agent: cpprestsdk/2.10.2

Relative URI /?request=show-nodes

Query request show-nodes

Request show-nodes

show-nodes…

Active:0 Server:192.168.1.33 Port:7002 Name:node_1

Active:0 Server:192.168.1.33 Port:7003 Name:node_2

Active:0 Server:192.168.1.33 Port:7004 Name:node_3

As we can see, there are registered nodes but no active one yet.

If I start a client asking for a worker node: myclient 192.168.1.33 7001

The server reacts:

Relative URI /?request=get-node&name=cache_v1

Query name cache_v1

Query request get-node

Request get-node

name cache_v1

get-node…

{"ip":"192.168.1.33","name":"cache_v1","port":"7002"}

If I ask my admin tool to show nodes:

Relative URI /?request=show-nodes

Query request show-nodes

Request show-nodes

show-nodes…

Active:1 Server:192.168.1.33 Port:7002 Name:cache_v1

Active:0 Server:192.168.1.33 Port:7003 Name:node_2

Active:0 Server:192.168.1.33 Port:7004 Name:node_3

There is one active node. The name is submitted by the client for an LMDB database names cache_v1.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: