Skip to content

Recipe: Niovakv Leader Election

Paul Nowoczynski edited this page Sep 29, 2021 · 1 revision

Niovakv Leader Election

Parent Recipe: “Basic Recipe For Niovakv”

Objective

Ensure that the writes happening before killing the leader , the writes should be reflected after electing a new leader as well.

Parameters:

  • Pmdb Server Count: Start servers such that quorum is formed. (Number of servers /2 + 1)
  • Niovakv Server Count : 1 or more servers need to be started.
  • Niovakv Client-Count: 1 or more clients need to be started.

1 - Check if app_type is niovakv

2 - Export path

export CGO_LDFLAGS="-L/usr/local/niova/niova-core/lib/"
export CGO_CFLAGS="-I/usr/local/niova/niova-core/include/niova"
export LD_LIBRARY_PATH=/usr/local/niova/niova-core/lib/
export PATH=$PATH:/usr/local/go/bin
export PYTHONPATH= <holon-directory-path>
export NIOVA_BIN_PATH= /home/user-name/dir-name/niova-core/libexec/niova

3 - Write a key-value pair by starting a niovakv_client

Here to start niovakv client we need to pass various parameters for write operation

Operation : "write"
Key : <key-prefix>
Value : <value-prefix>
OutfileName :  <abc>
NumRequest : <how many request to process / by default it is 5 no of request>
MultiKey : <since we here are passing single key and value this value will be False>
Sequential : <since we here are passing single key and value this value will be False>

Here’s some output from the write operation json file:

{
 "write": [
  {
   "Request": {
    "Operation": "write",
    "Key": "Country0",
    "Value": "India0",
    "Request_timestamp": "2021-09-22T07:23:12.087609427Z"
   },
   "Response": {
    "Status": 0,
    "Response": "",
    "Validate": true,
    "Response_timestamp": "2021-09-22T07:23:12.121613006Z"
   },
   "Req_resolved_time": 34003603
  }
 ]
}

4 - Verify if the operation is successful.

  1. Add checks for Status for write operation it should be 0.
"Response": {
    "Status": 0,
    "Response": "",
    "Validate": true,
    "Response_timestamp": "2021-09-22T07:23:12.121613006Z"
   },
   "Req_resolved_time": 34003603
  }

5 - Get the leader uuid

Here to get the leader uuid we need to pass various parameters to the niovakv_client

Operation : "leader"
Key : ""
Value : ""
OutfileName : <abc>
NumRequest : 0
MultiKey : <since we here are passing single key and value this value will be False>
Sequential : <since we here are passing single key and value this value will be False>

Here’s some output from the leader operation json file:

{
 "Leader-UUID": "ead05b74-1b75-11ec-a153-43e6ab21c54a
}

6 - Kill the leader for new leader election

Kill the current leader-uuid and verify that a new leader election should happen and a new uuid elected as leader-uuid.

7 - Get the new leader uuid

Here to get the leader uuid we need to pass various parameters to the niovakv_client

Operation : "leader"
Key : ""
Value : ""
OutfileName :  <abc>
NumRequest : 0
MultiKey : <since we here are passing single key and value this value will be False>
Sequential : <since we here are passing single key and value this value will be False>

Here’s output from the leader operation json file:

{
 "Leader-UUID": "eacf937e-1b75-11ec-b88d-c36a6fdc1fb1"
}
  1. Add checks to verify new leader is elected <"OldLeaderUUID"> != <"NewLeaderUUID">

8 - Read a key-value pair by starting a niovakv_client

Here to start niovakv client we need to pass various parameters for read operation.

Operation : "read"
Key : <key-prefix same as what is mentioned in write key-prefix>
Value : ""
OutfileName :  <abc>
NumRequest : <how many request to process / by default it is 5 no of request>
MultiKey : <since we here are passing single key and value this value will be False>
Sequential : <since we here are passing single key and value this value will be False>

Here’s some output from the write operation json file:

{
 "read": [
  {
   "Request": {
    "Operation": "read",
    "Key": "Country0",
    "Value": "",
    "Request_timestamp": "2021-09-22T07:23:15.038529797Z"
   },
   "Response": {
    "Status": 0,
    "Response": "India0",
    "Validate": false,
    "Response_timestamp": "2021-09-22T07:23:15.041801536Z"
   },
   "Req_resolved_time": 3271736
  }
 ]
}

9 - Compare values of read and write

  1. Added some checks to verify read value and write value are same
    1. Status of read should be equal to zero
    2. Read of Response should be equal to write of Value
Clone this wiki locally