So guys, now let us discuss the problem statement of this project.
So we will take an example in which there are total of six nodes in the ring topology, right?
So on each node, a user can actually perform two operations.
The first operation is put operation which takes two argument.
The K and X, both are integers, K represents a key and X represent a value corresponding to that key.
Right.
The second operation is a get key operation where K is an integer and this operation must return x that
is value corresponding to the key K.
Right.
Originator is a node on which user has issued either put or get request.
Right?
So this is how our user will going to interact with our project.
The user can issue, put request or get request on any node of the ring topology.
Now let us try to understand what is the functionality of put request.
So put request is basically used by the user whenever the user wants to save key value pair on some
node of the ring topology.
Right.
So let us try to understand the functionality of put request with the help of an example.
Suppose a user issued a put request with k is equal to five and X is equal to five on node number two
in this ring topology.
So on this node that is node number two, the user has issued this put request.
Now the next thing is that that the Node two immediately performs the hash operation on the key supplied
by the user.
The hash function, which is used to perform this hash operation on a key is k mod n, right.
Here, capital N denotes the total number of nodes in this ring topology and K is the key value which
is specified in the put request.
Here Mode operator is actually a remainder operator.
That is when K is divided by this capital N, then this k mode.
N will going to return a remainder.
So applying the hash operation on a key, we're going to return us an integer value.
So if we apply a hash operation on key K is equal to five, then hash function we're going to return
us the value six.
It simply means that X is equal to five.
That is, value needs to be saved on node six.
Hash table against key K is equal to five.
Now note that every node in this ring topology maintains a table called hash table.
The first column of this hash table is a key, and the second column of this hash table is a value,
right?
So when Node two on which put request is issued, the Node two performs has operation on the key value.
Right.
The return value as per our example will be six.
It means that key value pair five five needs to be saved on node number six.
So now at this point of time, user has issued the put request on node number two.
And after applying the hash operation, Node number two now knows that key value pair needs to be saved
on node number six.
So it simply means that now Node two knows that it do not have to save this key value pair in its own
local hash table.
Hence it forwards the key value to successor node, which is node number three.
Using UDP communication, we will call this message as put forward message.
So you can see that in this diagram.
Node number two is forwarding put forward message to its successor node.
Now the question arises that what should be the content of this put forward message?
The content of this put forward message should be that this message should encode IP address of node
two and TCP port number of node two.
Right.
So input forward message.
We need to encode these three values.
Y we encode these three values, you will going to understand it shortly.
Now, when this put forward message is received by Node three.
Node three Inspect the value of K and applies the hash function on it.
Since we already know that hash function returns six, it simply means that node three do not have to
save.
These key value pair in its local hash table and therefore it forwards the put forward message to its
successor node.
Now note that when node three forwards put forward message to its successor node, the content of the
put forward message is not changed.
The put forward message was prepared by that particular node on which put request was issued by the
user that is node number to prepare the put forward message.
The rest of the node in the ring topology simply forward this put forward message without any modification
to its successor node.
The node decides to forward the put forward message after applying the hash function on the key value
which is specified in this put forward message.
So node three to forwards the put forward message to node four using UDP connection without changing
any content of the put forward message that is put forward message still contains these three values
and this process continues until the put forward message is received by node number six in the topology.
Now, when Node six receives this put forward message, it applies the hash function on the key value
which is specified in put forward message.
And we already know that the hash function returns six for K is equal to five.
It means that the value returned by the hash function matches with the node number.
It simply means that now Node six knows that it has to save key value pair in its local hash table.
Right.
But remember, in the put forward message, which is circulating around the topology, we do not have
the value of X encoded in this put forward message.
So the question is how Node six will know the value of X so that it can save key value pair in its local
hash table.
Now you will understand that why in put forward message we encoded the IP address of the originator
machine and the TCP port number of the originator machine.
Note six established TCP connection with the original originator of put request that is node two and
ask for the value of x.
Right.
So you can see that Node six is establishing TCP connection with the originator of this put request.
So how Node six will come to know who was the originator of the put request?
The originator node is that node on which user originally issued put request.
Since Node six has received this put forward message from Node five from put forward message, Node
six can read the IP address and TCP port number.
These IP address and TCP port number are the credentials of the originator node.
So it means node number six knows everything it needs in order to establish TCP connection with the
originator.
So once the Node six established the TCP connection, the Node six asks the originator that Hey, for
the key K, what is the value of X?
Let us call this question asked by Node six to node two as what X message When Node two receives this?
What X message from Node six.
Node two sends the value of five over TCP connection to Node six directly.
Let us call this message as put reply x.
So Node six sends what?
X message to the originator and the originator replies back with the put reply X message.
Now when the node six receives put reply X message, the Node six would know the value of K is equal
to five and X is equal to five.
And finally, it saves these two key value pairs in its local hash table and closes the TCP connection
with the originator.
So this is the functionality of the put request in the resource section.
I have attached the flow chart of put request and get request which will help you in order to develop
and implement your logic in order to do this project.
Now, next we will going to discuss the algorithm or the functionality of get request.