Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/get #60

Open
wants to merge 22 commits into
base: project1-master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions PROJ1/get/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package get

import msg "./utils/message_defs"
import node "./utils/node_defs"

func Get(data *msg.Data, respond-to int64, node_obj *node.Node)(value string) {

// Get Node Data
var node_id = map_to_string_id(key)

// It's not in our finger table so we need to find the next highest node
var closest_node = FindClosestPreceedingNode(&node_obj.FingerTable, data.Key)
value = closest_node.DataTable[data.Key]

return
}
36 changes: 29 additions & 7 deletions PROJ1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,20 +477,42 @@ func Stabilize(node_obj *node.Node){
Gets the data...The node_obj is the node that will start the lookup for the data
The data that is obtained will be sent through the bucket
*/
func GetData(node_obj *node.Node, respond_to int64, key string){
func GetData(node_obj *node.Node, respond_to int64, key string)(value string){
log.Printf("\nGetting data with key %s by asking Node %d\n", key, node_obj.ChannelId)
key_id := map_string_to_id(key)
log.Printf("\nKey: %s mapped to hash of %d\n", key, key_id)
FindClosestPreceedingNode(node_obj, key_id)
bucket_data := GetDataFromBucket(node_obj.ChannelId)
closest := ExtractIdFromBucketData(bucket_data)
log.Printf("\nGET: Found %d as the closest to %d\n", closest, key_id)
if closest > key_id {
//Then just say we are at the right node to store
log.Printf("\nStored Data\n")

}
return

if Between(closest, key_id, node_obj.Successor) || node_obj.ChannelId == node_obj.Successor {

// Correct Node
log.Printf("\nGET: Retrieving value: %s at key: %s from node %d\n", node_obj.DataTable[key], key, node_obj.ChannelId)
return node_obj.DataTable[key]

} else {

// Could be the right node...
if node_obj.ChannelId == node_obj.Successor {
log.Printf("\nGET: Retrieving value: %s at key: %s from node %d\n", node_obj.DataTable[key], key, node_obj.ChannelId)
return node_obj.DataTable[key]

} else {

// Wrong node
log.Printf("\nGET: Sending key: %s to node: %d\n", key, node_obj.Successor)
var message = msg.Message {Do :"get", Data: msg.Data{Key: key}}
string_message, err := json.Marshal(message)
check_error(err)
SendDataToNetwork(node_obj.Successor, string(string_message))
log.Printf("\nGET: Sending key: %s to node: %d\n", key, node_obj.Successor)
log.Printf("\nGET: Sent: %s \n", string(string_message))

}
}
return
}

/*
Expand Down
20 changes: 5 additions & 15 deletions PROJ1/test_instructions.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
{"do":"join-ring", "sponsoring-node": 2, "test-send-to": 1}
{"do":"stabilize-ring", "test-send-to": 1}
{"do":"stabilize-ring", "test-send-to": 2}
{"do":"stabilize-ring", "test-send-to": 1}
{"do":"stabilize-ring", "test-send-to": 2}
{"do":"fix-ring-fingers", "test-send-to": 2}
{"do":"fix-ring-fingers", "test-send-to": 1}
{"do":"fix-ring-fingers", "test-send-to": 2}
{"do":"fix-ring-fingers", "test-send-to": 1}
{"do":"join-ring", "sponsoring-node": 1, "test-send-to": 2}
{"do":"join-ring", "sponsoring-node": 1, "test-send-to": 3}
{"do":"stabilize-ring", "test-send-to": 3}
{"do":"stabilize-ring", "test-send-to": 2}
{"do":"fix-ring-fingers", "test-send-to": 2}
{"do":"fix-ring-fingers", "test-send-to": 3}
{"do":"leave-ring", "mode":"orderly", "test-send-to": 2}

{"do":"put","data":{"key":"fff","value":"DFDF"}, "test-send-to":1}
{"do":"put","data":{"key":"xxx","value":"YYYY"}, "test-send-to":2}
{"do":"get","data":{"key":"fff"}, "test-send-to":1}
{"do":"get","data":{"key":"xxx"}, "test-send-to":2}
289 changes: 289 additions & 0 deletions SAMPLES/get-test-2-nodes-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,289 @@
2018/05/03 19:37:55
Starting program with the following:
Instruction File: test_instructions.txt
Number of network nodes: 4
Mean wait time: 5.000000
2018/05/03 19:37:55 This is the coordinator.
2018/05/03 19:37:55 Node 2 was used to create the ring.
2018/05/03 19:37:55
Adding Node 0 to network
2018/05/03 19:37:55
Adding Node 1 to network
2018/05/03 19:37:55
Adding Node 3 to network
2018/05/03 19:37:55 INIT_TOPOLOGY:Failed to generate any more network nodes
2018/05/03 19:37:55
Waiting 2 seconds before processing message for Node: 2
2018/05/03 19:37:56
Node: 2 received the following message:{"do":"join-ring","sponsoring-node":1,"mode":"","respond-to":0,"TargetId":0,"data":{"key":"","value":""},"test-send-to":2}
2018/05/03 19:37:56
Node 2 is already in the ring; cannot join-ring
2018/05/03 19:37:56 +++LIST OF NODES CURRENTLY IN THE RING+++
2018/05/03 19:37:56
Node 2 is in the ring
2018/05/03 19:37:56
+++Contents of Node 2+++
2018/05/03 19:37:56 Channel Id/Node Id: 2
2018/05/03 19:37:56 +FingerTable+:
2018/05/03 19:37:56 Finger Table at 0 is 2
2018/05/03 19:37:56 Finger Table at 1 is 2
2018/05/03 19:37:56 +DataTable+:
2018/05/03 19:37:56 Successor Id: 2
2018/05/03 19:37:56 Predecessor Id: 2
2018/05/03 19:37:56
+++END of Contents of Node 2+++
2018/05/03 19:37:56 +++END OF LIST OF NODES CURRENTLY IN THE RING+++
2018/05/03 19:37:56
Waiting 5 seconds before processing message for Node: 3
2018/05/03 19:38:06
Node: 3 received the following message:{"do":"join-ring","sponsoring-node":1,"mode":"","respond-to":0,"TargetId":0,"data":{"key":"","value":""},"test-send-to":3}
2018/05/03 19:38:06
JOIN_RING:Node 3 is joining the ring now
2018/05/03 19:38:06
BUCKET:Node: 1's data is waiting for data to be read ....
2018/05/03 19:38:06
Waiting 5 seconds before processing message for Node: 1
2018/05/03 19:38:06
Node: 1 received the following message:{"do":"find-ring-successor","sponsoring-node":0,"mode":"","respond-to":1,"TargetId":3,"data":{"key":"","value":""},"test-send-to":0}
2018/05/03 19:38:06
RespondTo node: 1 is not responding...not in ring?
2018/05/03 19:38:06 +++LIST OF NODES CURRENTLY IN THE RING+++
2018/05/03 19:38:06
Node 2 is in the ring
2018/05/03 19:38:06
+++Contents of Node 2+++
2018/05/03 19:38:06 Channel Id/Node Id: 2
2018/05/03 19:38:06 +FingerTable+:
2018/05/03 19:38:06 Finger Table at 0 is 2
2018/05/03 19:38:06 Finger Table at 1 is 2
2018/05/03 19:38:06 +DataTable+:
2018/05/03 19:38:06 Successor Id: 2
2018/05/03 19:38:06 Predecessor Id: 2
2018/05/03 19:38:06
+++END of Contents of Node 2+++
2018/05/03 19:38:06 +++END OF LIST OF NODES CURRENTLY IN THE RING+++
2018/05/03 19:38:26
WARNING:Timeout when listening for response data for Node 1
2018/05/03 19:38:26 Failed to extract the following bucket data:
2018/05/03 19:38:26
JOIN_RING:SENT find successor message with sponsoring node: 1 and target node: 3. Successor of target is -1
2018/05/03 19:38:26 +++LIST OF NODES CURRENTLY IN THE RING+++
2018/05/03 19:38:26
Node 3 is in the ring
2018/05/03 19:38:26
+++Contents of Node 3+++
2018/05/03 19:38:26 Channel Id/Node Id: 3
2018/05/03 19:38:26 +FingerTable+:
2018/05/03 19:38:26 +DataTable+:
2018/05/03 19:38:26 Successor Id: 3
2018/05/03 19:38:26 Predecessor Id: nil
2018/05/03 19:38:26
+++END of Contents of Node 3+++
2018/05/03 19:38:26
Node 2 is in the ring
2018/05/03 19:38:26
+++Contents of Node 2+++
2018/05/03 19:38:26 Channel Id/Node Id: 2
2018/05/03 19:38:26 +FingerTable+:
2018/05/03 19:38:26 Finger Table at 0 is 2
2018/05/03 19:38:26 Finger Table at 1 is 2
2018/05/03 19:38:26 +DataTable+:
2018/05/03 19:38:26 Successor Id: 2
2018/05/03 19:38:26 Predecessor Id: 2
2018/05/03 19:38:26
+++END of Contents of Node 2+++
2018/05/03 19:38:26 +++END OF LIST OF NODES CURRENTLY IN THE RING+++
2018/05/03 19:38:26
Waiting 0 seconds before processing message for Node: 1
2018/05/03 19:38:27
Node: 1 received the following message:{"do":"put","sponsoring-node":0,"mode":"","respond-to":0,"TargetId":0,"data":{"key":"fff","value":"DFDF"},"test-send-to":1}
2018/05/03 19:38:27
PUT: Putting data with key fff by asking Node 1
2018/05/03 19:38:27
Key: fff mapped to hash of 2
2018/05/03 19:38:27 CLOSEST_PRECEEDING:Searching for closest preceeding node.....
2018/05/03 19:38:27
BUCKET:Node: 1 was written bucket data
2018/05/03 19:38:27
BUCKET:Node: 1's data is waiting for data to be read ....
2018/05/03 19:38:27
BETWEEN: Checking if 1 is in between 2 and 1
2018/05/03 19:38:27 BEETWEEN: 1 target and 2 first
2018/05/03 19:38:27
PUT: Putting Key: fff with value: DFDF at Node: 1
2018/05/03 19:38:27 +++LIST OF NODES CURRENTLY IN THE RING+++
2018/05/03 19:38:27
Node 2 is in the ring
2018/05/03 19:38:27
+++Contents of Node 2+++
2018/05/03 19:38:27 Channel Id/Node Id: 2
2018/05/03 19:38:27 +FingerTable+:
2018/05/03 19:38:27 Finger Table at 0 is 2
2018/05/03 19:38:27 Finger Table at 1 is 2
2018/05/03 19:38:27 +DataTable+:
2018/05/03 19:38:27 Successor Id: 2
2018/05/03 19:38:27 Predecessor Id: 2
2018/05/03 19:38:27
+++END of Contents of Node 2+++
2018/05/03 19:38:27
Node 3 is in the ring
2018/05/03 19:38:27
+++Contents of Node 3+++
2018/05/03 19:38:27 Channel Id/Node Id: 3
2018/05/03 19:38:27 +FingerTable+:
2018/05/03 19:38:27 +DataTable+:
2018/05/03 19:38:27 Successor Id: 3
2018/05/03 19:38:27 Predecessor Id: nil
2018/05/03 19:38:27
+++END of Contents of Node 3+++
2018/05/03 19:38:27 +++END OF LIST OF NODES CURRENTLY IN THE RING+++
2018/05/03 19:38:27
Waiting 1 seconds before processing message for Node: 2
2018/05/03 19:38:27
Node: 2 received the following message:{"do":"put","sponsoring-node":0,"mode":"","respond-to":0,"TargetId":0,"data":{"key":"xxx","value":"YYYY"},"test-send-to":2}
2018/05/03 19:38:27
PUT: Putting data with key xxx by asking Node 2
2018/05/03 19:38:27
Key: xxx mapped to hash of 0
2018/05/03 19:38:27 CLOSEST_PRECEEDING:Searching for closest preceeding node.....
2018/05/03 19:38:27
BETWEEN: Checking if 2 is in between 2 and 0
2018/05/03 19:38:27 BEETWEEN: 2 target and 2 first
2018/05/03 19:38:27
BETWEEN: Checking if 2 is in between 2 and 0
2018/05/03 19:38:27 BEETWEEN: 2 target and 2 first
2018/05/03 19:38:27
BUCKET:Node: 2 was written bucket data
2018/05/03 19:38:27
BUCKET:Node: 2's data is waiting for data to be read ....
2018/05/03 19:38:27
BETWEEN: Checking if 2 is in between 0 and 2
2018/05/03 19:38:27
PUT: Putting Key: xxx with value: YYYY at Node: 2
2018/05/03 19:38:27 +++LIST OF NODES CURRENTLY IN THE RING+++
2018/05/03 19:38:27
Node 2 is in the ring
2018/05/03 19:38:27
+++Contents of Node 2+++
2018/05/03 19:38:27 Channel Id/Node Id: 2
2018/05/03 19:38:27 +FingerTable+:
2018/05/03 19:38:27 Finger Table at 0 is 2
2018/05/03 19:38:27 Finger Table at 1 is 2
2018/05/03 19:38:27 +DataTable+:
2018/05/03 19:38:27
Waiting 1 seconds before processing message for Node: 1
2018/05/03 19:38:27 Data Table at xxx is YYYY
2018/05/03 19:38:27 Successor Id: 2
2018/05/03 19:38:27 Predecessor Id: 2
2018/05/03 19:38:27
+++END of Contents of Node 2+++
2018/05/03 19:38:27
Node 3 is in the ring
2018/05/03 19:38:27
+++Contents of Node 3+++
2018/05/03 19:38:27 Channel Id/Node Id: 3
2018/05/03 19:38:27 +FingerTable+:
2018/05/03 19:38:27 +DataTable+:
2018/05/03 19:38:27 Successor Id: 3
2018/05/03 19:38:27 Predecessor Id: nil
2018/05/03 19:38:27
+++END of Contents of Node 3+++
2018/05/03 19:38:27 +++END OF LIST OF NODES CURRENTLY IN THE RING+++
2018/05/03 19:38:31
Node: 1 received the following message:{"do":"get","sponsoring-node":0,"mode":"","respond-to":0,"TargetId":0,"data":{"key":"fff","value":""},"test-send-to":1}
2018/05/03 19:38:31
Getting data with key fff by asking Node 1
2018/05/03 19:38:31
Key: fff mapped to hash of 2
2018/05/03 19:38:31 CLOSEST_PRECEEDING:Searching for closest preceeding node.....
2018/05/03 19:38:31
BUCKET:Node: 1 was written bucket data
2018/05/03 19:38:31
BUCKET:Node: 1's data is waiting for data to be read ....
2018/05/03 19:38:31
GET: Found 1 as the closest to 2
2018/05/03 19:38:31
BETWEEN: Checking if 1 is in between 2 and 1
2018/05/03 19:38:31 BEETWEEN: 1 target and 2 first
2018/05/03 19:38:31
GET: Retrieving value: DFDF at key: fff from node 1
2018/05/03 19:38:31 +++LIST OF NODES CURRENTLY IN THE RING+++
2018/05/03 19:38:31
Node 2 is in the ring
2018/05/03 19:38:31
+++Contents of Node 2+++
2018/05/03 19:38:31 Channel Id/Node Id: 2
2018/05/03 19:38:31
Waiting 0 seconds before processing message for Node: 2
2018/05/03 19:38:31 +FingerTable+:
2018/05/03 19:38:31
Node: 2 received the following message:{"do":"get","sponsoring-node":0,"mode":"","respond-to":0,"TargetId":0,"data":{"key":"xxx","value":""},"test-send-to":2}
2018/05/03 19:38:31 Finger Table at 1 is 2
2018/05/03 19:38:31 Finger Table at 0 is 2
2018/05/03 19:38:31 +DataTable+:
2018/05/03 19:38:31 Data Table at xxx is YYYY
2018/05/03 19:38:31 Successor Id: 2
2018/05/03 19:38:31 Predecessor Id: 2
2018/05/03 19:38:31
+++END of Contents of Node 2+++
2018/05/03 19:38:31
Getting data with key xxx by asking Node 2
2018/05/03 19:38:31
Key: xxx mapped to hash of 0
2018/05/03 19:38:31 CLOSEST_PRECEEDING:Searching for closest preceeding node.....
2018/05/03 19:38:31
BETWEEN: Checking if 2 is in between 2 and 0
2018/05/03 19:38:31 BEETWEEN: 2 target and 2 first
2018/05/03 19:38:31
BETWEEN: Checking if 2 is in between 2 and 0
2018/05/03 19:38:31 BEETWEEN: 2 target and 2 first
2018/05/03 19:38:31
BUCKET:Node: 2 was written bucket data
2018/05/03 19:38:31
Node 3 is in the ring
2018/05/03 19:38:31
+++Contents of Node 3+++
2018/05/03 19:38:31 Channel Id/Node Id: 3
2018/05/03 19:38:31 +FingerTable+:
2018/05/03 19:38:31 +DataTable+:
2018/05/03 19:38:31 Successor Id: 3
2018/05/03 19:38:31 Predecessor Id: nil
2018/05/03 19:38:31
+++END of Contents of Node 3+++
2018/05/03 19:38:31 +++END OF LIST OF NODES CURRENTLY IN THE RING+++
2018/05/03 19:38:31
BUCKET:Node: 2's data is waiting for data to be read ....
2018/05/03 19:38:31
GET: Found 2 as the closest to 0
2018/05/03 19:38:31
BETWEEN: Checking if 2 is in between 0 and 2
2018/05/03 19:38:31
GET: Retrieving value: YYYY at key: xxx from node 2
2018/05/03 19:38:31 +++LIST OF NODES CURRENTLY IN THE RING+++
2018/05/03 19:38:31
Node 2 is in the ring
2018/05/03 19:38:31
+++Contents of Node 2+++
2018/05/03 19:38:31 Channel Id/Node Id: 2
2018/05/03 19:38:31 +FingerTable+:
2018/05/03 19:38:31 Finger Table at 0 is 2
2018/05/03 19:38:31 Finger Table at 1 is 2
2018/05/03 19:38:31 +DataTable+:
2018/05/03 19:38:31 Data Table at xxx is YYYY
2018/05/03 19:38:31 Successor Id: 2
2018/05/03 19:38:31 Predecessor Id: 2
2018/05/03 19:38:31
+++END of Contents of Node 2+++
2018/05/03 19:38:31
Node 3 is in the ring
2018/05/03 19:38:31
+++Contents of Node 3+++
2018/05/03 19:38:31 Channel Id/Node Id: 3
2018/05/03 19:38:31 +FingerTable+:
2018/05/03 19:38:31 +DataTable+:
2018/05/03 19:38:31 Successor Id: 3
2018/05/03 19:38:31 Predecessor Id: nil
2018/05/03 19:38:31
+++END of Contents of Node 3+++
2018/05/03 19:38:31 +++END OF LIST OF NODES CURRENTLY IN THE RING+++
signal: killed