From b44e4625a5f22ac06da2083823f8b3220a7f8bef Mon Sep 17 00:00:00 2001
From: afederici <ajf5@illinois.edu>
Date: Sun, 29 Nov 2020 03:21:47 -0600
Subject: [PATCH] new replication -> pt2

---
 Wc           | Bin 189120 -> 189120 bytes
 Wr           | Bin 184720 -> 184720 bytes
 src/Node.cpp |   8 +++++---
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/Wc b/Wc
index 7a48f640692644ffdf69ab771730c20c533e5b04..99667e09f487c4575b8ecff3da7bae6fb206eeae 100755
GIT binary patch
delta 68
zcmV-K0K5Od#S6g23xKo%@OT0XXt(ls0nRo83~0B)uK~KU4rO9BG%#c?ZvbCyVQFrc
a5orQ4x4dEkEj$KdH)CO8F}LrY0?|XoDH^K)

delta 68
zcmV-K0K5Od#S6g23xKo%@OT2iWViBo0nRo8!DP3>uK~KU4mV<AGd3_TZvbCyVQFrc
a5orQ4x4dEkEj$J?Ibt|8IJfVf0?|VO5F1|r

diff --git a/Wr b/Wr
index 87fe453185225e8a06c5e0b95729d6cb6cd80140..85320a8b25aae4005a2fb2d8e1076eda70482da6 100755
GIT binary patch
delta 67
zcmV-J0KET@qYIFu3xKo%NO%GaXtzpu0ZuUj4QRKTsR5;}4q{|BFgP|YZvbCyVQFrc
Z?)(8Vw|`dxJvIe5Ibt+sx5149&qF6e7%l(+

delta 67
zcmV-J0KET@qYIFu3xKo%NO%IlWVcFq0ZuUj!eqCasR5;}4mC9}V`DfjZvbCyVQFrc
Z?)(8Vw|`dxJvIepF=H_~x5149&qHh?8HE4<

diff --git a/src/Node.cpp b/src/Node.cpp
index 5be4cba..0493f14 100644
--- a/src/Node.cpp
+++ b/src/Node.cpp
@@ -65,6 +65,7 @@ void Node::debugOutputRep(){
 	set<string> membersIP;
 	string debug = "[DEBUGREP] ---------------------------\n";
 	vector<tuple<string,string,int>> toDel;
+	bool added = false;
 	for (auto pos : hashRing->nodePositions) { members.insert(pos); membersIP.insert(hashRing->getValue(pos)); }
 	for (auto &mapping : outputReplication){
 		for (auto &reps: mapping.second){
@@ -75,6 +76,7 @@ void Node::debugOutputRep(){
 				debug += ("FILE: " + mapping.first + " | (" + get<0>(reps.first) + "->");
 				debug += (to_string(get<1>(reps.first)) + ")" + " REPFACTOR: " + to_string(reps.second));
 				debug += "\n";
+				added = true;
 			}
 		}
 	}
@@ -83,7 +85,7 @@ void Node::debugOutputRep(){
 		if (outputReplication[get<0>(item)].size() == 0) outputReplication.erase(get<0>(item));
 	}
 	debug += "[DEBUGREP] ---------------------------\n";
-	cout << debug << endl;
+	if (added) cout << debug << endl;
 }
 
 string Node::populateMembershipMessage()
@@ -301,7 +303,7 @@ int Node::failureDetection(){
 							if (deletedNodePostion == get<1>(pairings.first)){
 								//failed as receiver
 								int repTarget = hashRing->getRandomNode(tuple<int, int, int>(hashRingPosition, hashRingPosition, hashRingPosition));
-								while (locations.count(repTarget) != 0) {
+								while (locations.count(repTarget) != 0 || (hashRing->getValue(repTarget).compare(leaderIP) == 0)) {
 									repTarget = hashRing->getRandomNode(tuple<int, int, int>(hashRingPosition, hashRingPosition, hashRingPosition));
 								}
 								outputReplication[mapping.first][make_tuple(get<0>(pairings.first),repTarget)] = pairings.second;
@@ -1477,7 +1479,7 @@ void Node::handleTcpMessage()
 						set<int> locations;
 						for (auto &e: fileList[inMsg[1]]) locations.insert(e);
 						repTarget = hashRing->getRandomNode(tuple<int, int, int>(hashRingPosition, hashRingPosition, hashRingPosition));
-						while (locations.count(repTarget)!=0) {
+						while (locations.count(repTarget)!=0 || (hashRing->getValue(repTarget).compare(leaderIP) == 0)) {
 							repTarget = hashRing->getRandomNode(tuple<int, int, int>(hashRingPosition, hashRingPosition, hashRingPosition));
 						}
 					}
-- 
GitLab