From ba94f3f1b22c0144401dd76b5c84457ba5886d5a Mon Sep 17 00:00:00 2001 From: nallg00d Date: Mon, 16 Apr 2018 23:35:27 -0400 Subject: [PATCH 1/9] Trying to figure out put --- PROJ1/main.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/PROJ1/main.go b/PROJ1/main.go index c6ede67..eefd9b6 100644 --- a/PROJ1/main.go +++ b/PROJ1/main.go @@ -425,7 +425,7 @@ func InitRingFingers(node_obj *node.Node, respond_to int64) { func Put(data *msg.Data, respond_to int64, node_obj *node.Node) { // FindPReceedingNode - var closest_node = FindClosestPreceedingNode(&node_obj.FingerTable, data.Key) + var closest_node = FindClosestPreceedingNode(node_obj, respond_to) // Get ID from bucket var closest_id = ExtractIdFromBucketData(data.Key) @@ -434,7 +434,7 @@ func Put(data *msg.Data, respond_to int64, node_obj *node.Node) { var closest_data = GetDataFromBucket(closest_id) // Put data in node - closest_node.DataTable[data.Key] := closest_data + closest_node.DataTable[closest_data] = closest_data } /* @@ -704,8 +704,7 @@ func net_node(channel_id int64){ SendDataToNetwork(random_ring_node, "{\"do\": \"stabilize-ring\"}") } } - } - /*else if message.Do == "put" { + } else if message.Do == "put" { respond_to_node_id = struct_message.RespondTo data = struct_message.Data Put(data, respond_to_node_id, node_obj) @@ -713,13 +712,11 @@ func net_node(channel_id int64){ respond_to_node_id = struct_message.RespondTo data = struct_message.Data Get(data, respond_to_node_id, node_obj) - }else if message.Do == "remove"{ respond_to_node_id = struct_message.RespondTo data = struct_message.Data Remove(data, respond_to_node_id, node_obj) } - */ print_ring_nodes() default: From 67e9eb474c9ba5078472a008e539bd01bf5444f6 Mon Sep 17 00:00:00 2001 From: nallg00d Date: Sun, 22 Apr 2018 20:53:06 -0400 Subject: [PATCH 2/9] Toying around with PutData --- PROJ1/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PROJ1/main.go b/PROJ1/main.go index dcc9a5e..c79703c 100644 --- a/PROJ1/main.go +++ b/PROJ1/main.go @@ -465,7 +465,7 @@ func PutData(node_obj *node.Node, data msg.Data, respond_to int64) { if closest > key_id { //Then just say we are at the right node to store log.Printf("\nStored Data\n") - + node_obj.DataTable[data.Key] = data.Value } return } From 1f9c596632b42441c447ed0a5cf7122bbf97792b Mon Sep 17 00:00:00 2001 From: nallg00d Date: Sun, 29 Apr 2018 00:15:49 -0400 Subject: [PATCH 3/9] Moved Data struct to be inside Message struct for correct JSON parsing --- PROJ1/main.go | 37 +++++++++++++++++++----- PROJ1/utils/message_defs/message_defs.go | 8 ++++- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/PROJ1/main.go b/PROJ1/main.go index a1f7567..f0c1e12 100644 --- a/PROJ1/main.go +++ b/PROJ1/main.go @@ -494,20 +494,37 @@ func RemoveData(node_obj *node.Node, respond_to int64, key string){ return } -func PutData(node_obj *node.Node, data msg.Data, respond_to int64) { +func PutData(node_obj *node.Node, respond_to int64, key string, value string) { - log.Printf("\nPutting data with key %s by asking Node %d\n", data.Key, node_obj.ChannelId) - key_id := map_string_to_id(data.Key) - log.Printf("\nKey: %s mapped to hash of %d\n", data.Key, key_id) + // When this is sent to the node, it's that node that will be processing/being used to store the data + // respond_to is the channel_id that sent the message + log.Printf("\nPutting data with key %s by asking Node %d\n", key, node_obj.ChannelId) + + // Get Key ID to string + key_id := map_string_to_id(key) + + log.Printf("\nKey: %s mapped to hash of %d\n", key, key_id) + + // Get closest node FindClosestPreceedingNode(node_obj, key_id) + + // The node that sent this message shoudl have data in the bucket, so scooop the bucket bucket_data := GetDataFromBucket(node_obj.ChannelId) + + // Now we can get the closest node from the bucket closest := ExtractIdFromBucketData(bucket_data) + log.Printf("\nPUT: Found %d as the closest to %d\n", closest, key_id) + + log.Printf("\nPUT: Putting value: %s into Node: %d\n", value, closest) + + /* if closest > key_id { //Then just say we are at the right node to store log.Printf("\nStored Data\n") - - } + } + */ + return } @@ -887,7 +904,7 @@ func net_node(channel_id int64){ test_channel <- "Done" } }else if message.Do == "put" { - PutData(&node_obj, message.Data, node_obj.ChannelId) + PutData(&node_obj, node_obj.ChannelId, message.Data.Key, message.Data.Value) if test_mode == true { test_channel <- "Done" } @@ -1054,6 +1071,9 @@ func coordinator(prog_args []string){ //get a list of string json instructions to send to random nodes var instructions []string = create_message_list(file_name) + + +// log.Printf("\nCoordiantor is getting the following instruction: %s\n", instructions) var channel_id int64 for i := 0; i < len(instructions); i++ { //pick a random node in the ring to send the message to. @@ -1061,6 +1081,9 @@ func coordinator(prog_args []string){ random_ring_id = get_random_ring_node() random_network_id := get_random_network_node() byte_msg := []byte(instructions[i]) + + //log.Printf("\nCoordiantor is getting the following instruction: %s\n", string(byte_msg)) + var message msg.Message err := json.Unmarshal(byte_msg, &message) if err != nil { diff --git a/PROJ1/utils/message_defs/message_defs.go b/PROJ1/utils/message_defs/message_defs.go index 399fab1..592a480 100644 --- a/PROJ1/utils/message_defs/message_defs.go +++ b/PROJ1/utils/message_defs/message_defs.go @@ -19,14 +19,20 @@ type Message struct { Mode string `json:"mode"` RespondTo int64 `json:"respond-to"` TargetId int64 `json:target-id` - Data Data `json:"data"` + //Data Data `json:"data"` + Data struct { + Key string `json:"key"` + Value string `json:"value"` + } TestSendTo int64 `json:"test-send-to"` } +/* type Data struct { Key string `json:"key"` Value string `json:"value"` } + */ /* The tag is a field that nodes use to ensure that the order From 48682423b3af4f15da9518adb8236659fea04435 Mon Sep 17 00:00:00 2001 From: nallg00d Date: Sun, 29 Apr 2018 10:28:08 -0400 Subject: [PATCH 4/9] Fixed message parsing issue by removing respond-to from my own test instructions nad utilizing check_error(err). Right now doesn't seem to find the closest node correct --- PROJ1/main.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/PROJ1/main.go b/PROJ1/main.go index 4e9c030..cf87a11 100644 --- a/PROJ1/main.go +++ b/PROJ1/main.go @@ -501,17 +501,14 @@ func PutData(node_obj *node.Node, respond_to int64, key string, value string) { bucket_data := GetDataFromBucket(node_obj.ChannelId) closest := ExtractIdFromBucketData(bucket_data) - log.Printf("\nChannel ID that is the closest: %d\n", closest) - - /* log.Printf("\nPUT: 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") + log.Printf("\n@@@@@----- Stored Data at node %d -----@@@@@@@\n", closest) } - */ return } @@ -836,8 +833,11 @@ func net_node(channel_id int64){ log.Printf("\nNode: %d received the following message:%s\n", channel_id, msg_recv) byte_msg := []byte(msg_recv) + var message msg.Message err := json.Unmarshal(byte_msg, &message) + + //log.Printf("\n---- UnMarshal Data Struct: %+v -----\n", message) if err != nil { log.Printf("Node: %d failed to unmarshal the json string", channel_id) break @@ -848,7 +848,7 @@ func net_node(channel_id int64){ //Perform join-ring action if message.Do == "join-ring" { - log.Printf("\n***** JOIN-RING INSIDE NET_NODE *****\n") + //log.Printf("\n***** JOIN-RING INSIDE NET_NODE *****\n") if val, ok := ring_nodes.Load(channel_id); ok != true { _ = val @@ -886,8 +886,6 @@ func net_node(channel_id int64){ }else{ log.Printf("\nRespondTo node: %d is not responding...not in ring?\n", message.RespondTo) } - - } else if message.Do == "find-ring-predecessor" { //Tell node_obj to find the predecessor of target id and report back to respond-to FindRingPredecessor(&node_obj, message.TargetId, message.RespondTo) @@ -1082,7 +1080,7 @@ func coordinator(prog_args []string){ var instructions []string = create_message_list(file_name) - log.Printf("\nRaw instructions: %s\n", instructions) + //log.Printf("\nRaw instructions: %s\n", instructions) var channel_id int64 for i := 0; i < len(instructions); i++ { //pick a random node in the ring to send the message to. @@ -1091,13 +1089,21 @@ func coordinator(prog_args []string){ random_network_id := get_random_network_node() byte_msg := []byte(instructions[i]) - log.Printf("\n****Byte msg Instruction: %s\n", instructions[i]) + //log.Printf("\n****Byte msg Instruction: %s\n", instructions[i]) var message msg.Message + err := json.Unmarshal(byte_msg, &message) + //check_error(err) + + //log.Printf("\n@@@@@@------ UnMarshal Struct Message: %+v -------@@@@@@@\n", message) + if err != nil { log.Println("Reached the end of the json instructions") break } + + //log.Printf("\n@@@@@@@---- Message.Do: %s @@@@@@-----\n", message.Do) + //format join ring instruction with random sponsoring node if message.Do == "join-ring" { random_ring_id = -1 From 0dee2b5cd6c46f75b6f47221ef14fb619e2873eb Mon Sep 17 00:00:00 2001 From: nallg00d Date: Sun, 29 Apr 2018 10:57:59 -0400 Subject: [PATCH 5/9] added a bit more code to Put for node storage and some notes --- PROJ1/main.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/PROJ1/main.go b/PROJ1/main.go index cf87a11..1b9e39f 100644 --- a/PROJ1/main.go +++ b/PROJ1/main.go @@ -484,6 +484,7 @@ func RemoveData(node_obj *node.Node, respond_to int64, key string){ bucket_data := GetDataFromBucket(node_obj.ChannelId) closest := ExtractIdFromBucketData(bucket_data) log.Printf("\nREMOVE: 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") @@ -503,11 +504,15 @@ func PutData(node_obj *node.Node, respond_to int64, key string, value string) { log.Printf("\nPUT: Found %d as the closest to %d\n", closest, key_id) + // while closest < key_id { } if closest > key_id { //Then just say we are at the right node to store log.Printf("\n@@@@@----- Stored Data at node %d -----@@@@@@@\n", closest) + //node.DataTable[key] := value - } + } else { + log.Printf("\n@@@@@----- Closest Node not found, looking again...-----@@@@@\n") + } return } From 8630bc2a7f0a2b6b422626406e91cbe01ed9a629 Mon Sep 17 00:00:00 2001 From: nallg00d Date: Sun, 29 Apr 2018 22:28:33 -0400 Subject: [PATCH 6/9] PutData sometimes works and updates a node's data table but sometimes it doesn't do anything. For some reason even when it works I'm not seeing any of the log messages on the console --- PROJ1/main.go | 15 +++++++++++---- PROJ1/test_instructions.txt | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/PROJ1/main.go b/PROJ1/main.go index 1b9e39f..029121e 100644 --- a/PROJ1/main.go +++ b/PROJ1/main.go @@ -504,14 +504,21 @@ func PutData(node_obj *node.Node, respond_to int64, key string, value string) { log.Printf("\nPUT: Found %d as the closest to %d\n", closest, key_id) - // while closest < key_id { } if closest > key_id { //Then just say we are at the right node to store - log.Printf("\n@@@@@----- Stored Data at node %d -----@@@@@@@\n", closest) - //node.DataTable[key] := value + log.Printf("\nPUT: Putting Key: %s with value: %s at Node: %d\n", key, value, node_obj.ChannelId) + node_obj.DataTable[key] = value } else { - log.Printf("\n@@@@@----- Closest Node not found, looking again...-----@@@@@\n") + // This is the wrong node to store the data + // Need to send this message to the successor + // Get Successor Channel ID + // Send Message to Successor + //node_obj.DataTable[key] := value + + log.Printf("\nPUT: Sending key: %s and value: %s to bucket for Node: %d\n", key, value, node_obj.Successor) + SendDataToBucket(node_obj.Successor, key) + SendDataToBucket(node_obj.Successor, value) } return diff --git a/PROJ1/test_instructions.txt b/PROJ1/test_instructions.txt index 24d7ad9..b5559fc 100644 --- a/PROJ1/test_instructions.txt +++ b/PROJ1/test_instructions.txt @@ -1,4 +1,7 @@ {"do":"join-ring", "sponsoring-node": 2, "test-send-to": 1} +{"do":"join-ring", "sponsoring-node": 2, "test-send-to": 2} +{"do":"put","data":{"key":"fff","value":"DFDF"}, "test-send-to":1} +{"do":"put","data":{"key":"xxx","value":"XXXX"}, "test-send-to":2} {"do":"stabilize-ring", "test-send-to": 1} {"do":"stabilize-ring", "test-send-to": 2} {"do":"stabilize-ring", "test-send-to": 1} From 868ddde4ac4c423cffe95a83883f0da2b47d9d82 Mon Sep 17 00:00:00 2001 From: nallg00d Date: Mon, 30 Apr 2018 23:26:05 -0400 Subject: [PATCH 7/9] added conditions to send to successor in the event closest node isn't found. Also a check to avoid looping if the current node is it's own successor --- PROJ1/main.go | 19 +++++++++++++------ PROJ1/test_instructions.txt | 12 +----------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/PROJ1/main.go b/PROJ1/main.go index 029121e..91889c1 100644 --- a/PROJ1/main.go +++ b/PROJ1/main.go @@ -512,13 +512,20 @@ func PutData(node_obj *node.Node, respond_to int64, key string, value string) { } else { // This is the wrong node to store the data // Need to send this message to the successor - // Get Successor Channel ID - // Send Message to Successor - //node_obj.DataTable[key] := value - log.Printf("\nPUT: Sending key: %s and value: %s to bucket for Node: %d\n", key, value, node_obj.Successor) - SendDataToBucket(node_obj.Successor, key) - SendDataToBucket(node_obj.Successor, value) + // Check to see current node isn't succcessor + // This is to avoid looping + if node_obj.ChannelID == node_obj.Successor { + log.Printf("\nPUT: Putting Key: %s with value: %s at Node: %d\n", key, value, node_obj.ChannelId) + node_obj.DataTable[key] = value + + } else { + // Send to successor + log.Printf("\nPUT: Sending key: %s and value: %s to node: %d\n", key, value, node_obj.Successor) + SendDataToNetwork(node_obj.Successor, key) + SendDataToNetwork(node_obj.Successor, value) + + } } return diff --git a/PROJ1/test_instructions.txt b/PROJ1/test_instructions.txt index b5559fc..8bf87ed 100644 --- a/PROJ1/test_instructions.txt +++ b/PROJ1/test_instructions.txt @@ -1,12 +1,2 @@ -{"do":"join-ring", "sponsoring-node": 2, "test-send-to": 1} -{"do":"join-ring", "sponsoring-node": 2, "test-send-to": 2} +{"do":"join-ring", "sponsoring-node": 1, "test-send-to": 2} {"do":"put","data":{"key":"fff","value":"DFDF"}, "test-send-to":1} -{"do":"put","data":{"key":"xxx","value":"XXXX"}, "test-send-to":2} -{"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} From ed021da5ca9afce19542753bc45fea7a76a5ace5 Mon Sep 17 00:00:00 2001 From: nallg00d Date: Mon, 30 Apr 2018 23:26:50 -0400 Subject: [PATCH 8/9] Fixed typo in ChannelId --- PROJ1/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PROJ1/main.go b/PROJ1/main.go index 91889c1..a76c8b9 100644 --- a/PROJ1/main.go +++ b/PROJ1/main.go @@ -515,7 +515,7 @@ func PutData(node_obj *node.Node, respond_to int64, key string, value string) { // Check to see current node isn't succcessor // This is to avoid looping - if node_obj.ChannelID == node_obj.Successor { + if node_obj.ChannelId == node_obj.Successor { log.Printf("\nPUT: Putting Key: %s with value: %s at Node: %d\n", key, value, node_obj.ChannelId) node_obj.DataTable[key] = value From a5ff7e4cdf8e0454dddea386ae00d938eba443a7 Mon Sep 17 00:00:00 2001 From: nallg00d Date: Mon, 30 Apr 2018 23:46:48 -0400 Subject: [PATCH 9/9] Fixed Put, seems to work --- PROJ1/main.go | 6 +++--- PROJ1/test_instructions.txt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/PROJ1/main.go b/PROJ1/main.go index a76c8b9..f0c523e 100644 --- a/PROJ1/main.go +++ b/PROJ1/main.go @@ -495,14 +495,14 @@ func RemoveData(node_obj *node.Node, respond_to int64, key string){ func PutData(node_obj *node.Node, respond_to int64, key string, value string) { - log.Printf("\nPutting data with key %s by asking Node %d\n", key, node_obj.ChannelId) + log.Printf("\nPUT: Putting 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("\nPUT: Found %d as the closest to %d\n", closest, key_id) + //log.Printf("\nPUT: 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 @@ -516,7 +516,7 @@ func PutData(node_obj *node.Node, respond_to int64, key string, value string) { // Check to see current node isn't succcessor // This is to avoid looping if node_obj.ChannelId == node_obj.Successor { - log.Printf("\nPUT: Putting Key: %s with value: %s at Node: %d\n", key, value, node_obj.ChannelId) + log.Printf("\nPUT: Current node is it's own successor. Putting Key: %s with value: %s at Node: %d\n", key, value, node_obj.ChannelId) node_obj.DataTable[key] = value } else { diff --git a/PROJ1/test_instructions.txt b/PROJ1/test_instructions.txt index 8bf87ed..8c6ba39 100644 --- a/PROJ1/test_instructions.txt +++ b/PROJ1/test_instructions.txt @@ -1,2 +1,2 @@ {"do":"join-ring", "sponsoring-node": 1, "test-send-to": 2} -{"do":"put","data":{"key":"fff","value":"DFDF"}, "test-send-to":1} +{"do":"put","data":{"key":"fff","value":"DFDF"}, "test-send-to":2}