Commit 93938e76 authored by Mayank Manoj's avatar Mayank Manoj

Merge branch 'mayank' into 'master'

code running properly

See merge request !5
parents e140c269 0dc1284e
...@@ -26,7 +26,7 @@ public: ...@@ -26,7 +26,7 @@ public:
{ {
return; return;
} }
virtual string getKeyValuePairs(int id) virtual string getKeyValuePairs(int new_id,int id)
{ {
return "This will never run"; return "This will never run";
} }
...@@ -75,9 +75,9 @@ public: ...@@ -75,9 +75,9 @@ public:
mycache.pushAll(); mycache.pushAll();
} }
string getKeyValuePairs(int id) string getKeyValuePairs(int new_id,int id)
{ {
return mycache.getKeyValuePairs(id); return mycache.getKeyValuePairs(new_id,id);
} }
}; };
...@@ -124,8 +124,8 @@ public: ...@@ -124,8 +124,8 @@ public:
} }
// key1;key2;key3;;value1;value2;value3; // key1;key2;key3;;value1;value2;value3;
string getKeyValuePairs(int id) string getKeyValuePairs(int new_id,int id)
{ {
return mycache.getKeyValuePairs(id); return mycache.getKeyValuePairs(new_id,id);
} }
}; };
\ No newline at end of file
...@@ -160,7 +160,7 @@ void RunClient() { ...@@ -160,7 +160,7 @@ void RunClient() {
Info info; Info info;
ClientContext context; ClientContext context;
Status status=stub->GETADDRESS(&context,null,&info); Status status=stub->GETADDRESS(&context,null,&info);
std::cout<<"Server: "<<info.address()<<std::endl; std::cout<<"Connected to Server: "<<info.address()<<std::endl;
std::string target_address(info.address()); std::string target_address(info.address());
// Instantiates the client // Instantiates the client
KeyValueServicesClient client( KeyValueServicesClient client(
......
...@@ -105,12 +105,10 @@ public: ...@@ -105,12 +105,10 @@ public:
new ServerData(service, cq, reqType); new ServerData(service, cq, reqType);
if (reqType == NEW) { if (reqType == NEW) {
cout<<"New Server to join:"<<info.address()<<endl; cout<<"New Server to join:"<<info.address()<<endl;
//calculate id of node, return it's successor and predecessor
string address=info.address(); string address=info.address();
int id=stoi(address.substr(address.find(':')+1)); int id=stoi(address.substr(address.find(':')+1));
int fingers[16]; int fingers[16];
ifstream fin; ifstream fin;
cout<<"Getting my finger table"<<endl;
fin.open(FINGER_TABLE); fin.open(FINGER_TABLE);
int nums=0; int nums=0;
do { do {
...@@ -162,7 +160,6 @@ public: ...@@ -162,7 +160,6 @@ public:
Id x; Id x;
x.set_id(next); x.set_id(next);
Id y; Id y;
cout<<"asking the possible successor whether its predecessor is less than the new node id"<<endl;
int mypred,nextpred; int mypred,nextpred;
fin.open(NEIGHBOURS); fin.open(NEIGHBOURS);
string temp; string temp;
...@@ -175,21 +172,20 @@ public: ...@@ -175,21 +172,20 @@ public:
nextpred=y.id(); nextpred=y.id();
} }
if(fl==false&&next!=my_id&&nextpred==node) { if(fl==false&&next!=my_id&&nextpred==node) {
cout<<"Yes it is. So we found the successor and the predecessor"<<endl; cout<<"We found the successor and predecessor for the new node:-"<<endl;
cout<<"Successor: "<<x.id()<<endl; cout<<"Successor: "<<x.id()<<endl;
cout<<"Predecessor: "<<nextpred<<endl; cout<<"Predecessor: "<<nextpred<<endl;
successorInfo.set_succaddress("0.0.0.0:"+to_string(x.id())); successorInfo.set_succaddress("0.0.0.0:"+to_string(x.id()));
successorInfo.set_predaddress("0.0.0.0:"+to_string(nextpred)); successorInfo.set_predaddress("0.0.0.0:"+to_string(nextpred));
} }
else if(fl==false&&next==my_id&&mypred==node) { else if(fl==false&&next==my_id&&mypred==node) {
cout<<"Yes it is. So we found the successor and the predecessor"<<endl; cout<<"We found the successor and predecessor for the new node:-"<<endl;
cout<<"Successor: "<<x.id()<<endl; cout<<"Successor: "<<x.id()<<endl;
cout<<"Predecessor: "<<mypred<<endl; cout<<"Predecessor: "<<mypred<<endl;
successorInfo.set_succaddress("0.0.0.0:"+to_string(x.id())); successorInfo.set_succaddress("0.0.0.0:"+to_string(x.id()));
successorInfo.set_predaddress("0.0.0.0:"+to_string(mypred)); successorInfo.set_predaddress("0.0.0.0:"+to_string(mypred));
} }
else if(fl==false){ else if(fl==false){
cout<<"No it is not. We will ask the possible predecessor to find the successor of new node"<<endl;
if(node==my_id) { if(node==my_id) {
int mysucc; int mysucc;
fin.open(NEIGHBOURS); fin.open(NEIGHBOURS);
...@@ -199,6 +195,9 @@ public: ...@@ -199,6 +195,9 @@ public:
fin.close(); fin.close();
mysucc=stoi(temp.substr(temp.find(':')+1)); mysucc=stoi(temp.substr(temp.find(':')+1));
if(mysucc>=id) { if(mysucc>=id) {
cout<<"We found the successor and predecessor for the new node:-"<<endl;
cout<<"Successor: "<<mysucc<<endl;
cout<<"Predecessor: "<<my_id<<endl;
successorInfo.set_succaddress("0.0.0.0:"+to_string(mysucc)); successorInfo.set_succaddress("0.0.0.0:"+to_string(mysucc));
successorInfo.set_predaddress("0.0.0.0:"+to_string(my_id)); successorInfo.set_predaddress("0.0.0.0:"+to_string(my_id));
} }
...@@ -208,15 +207,15 @@ public: ...@@ -208,15 +207,15 @@ public:
stub=KeyValueServices::NewStub(channel); stub=KeyValueServices::NewStub(channel);
ClientContext context1; ClientContext context1;
x.set_id(id); x.set_id(id);
cout<<"Asking node "<<mysucc<<" for the successor of new node"<<endl;
stub->GETSUCCESSOR(&context1,x,&y); stub->GETSUCCESSOR(&context1,x,&y);
cout<<"Yes. We got the successor"<<endl;
Id z; Id z;
string t_address("0.0.0.0:"+to_string(y.id())); string t_address("0.0.0.0:"+to_string(y.id()));
channel=grpc::CreateChannel(t_address, grpc::InsecureChannelCredentials()); channel=grpc::CreateChannel(t_address, grpc::InsecureChannelCredentials());
stub=KeyValueServices::NewStub(channel); stub=KeyValueServices::NewStub(channel);
ClientContext context2; ClientContext context2;
stub->GETPREDECESSOR(&context2,y,&z); stub->GETPREDECESSOR(&context2,y,&z);
cout<<"Yes. We got the predecessor"<<endl; cout<<"We found the successor and predecessor for the new node:-"<<endl;
cout<<"Successor: "<<y.id()<<endl; cout<<"Successor: "<<y.id()<<endl;
cout<<"Predecessor: "<<z.id()<<endl; cout<<"Predecessor: "<<z.id()<<endl;
successorInfo.set_succaddress("0.0.0.0:"+to_string(y.id())); successorInfo.set_succaddress("0.0.0.0:"+to_string(y.id()));
...@@ -229,15 +228,15 @@ public: ...@@ -229,15 +228,15 @@ public:
stub=KeyValueServices::NewStub(channel); stub=KeyValueServices::NewStub(channel);
ClientContext context1; ClientContext context1;
x.set_id(id); x.set_id(id);
cout<<"Asking node "<<node<<" for the successor of the new node"<<endl;
stub->GETSUCCESSOR(&context1,x,&y); stub->GETSUCCESSOR(&context1,x,&y);
cout<<"Yes. We got the successor"<<endl;
Id z; Id z;
string t_address("0.0.0.0:"+to_string(y.id())); string t_address("0.0.0.0:"+to_string(y.id()));
channel=grpc::CreateChannel(t_address, grpc::InsecureChannelCredentials()); channel=grpc::CreateChannel(t_address, grpc::InsecureChannelCredentials());
stub=KeyValueServices::NewStub(channel); stub=KeyValueServices::NewStub(channel);
ClientContext context2; ClientContext context2;
stub->GETPREDECESSOR(&context2,y,&z); stub->GETPREDECESSOR(&context2,y,&z);
cout<<"Yes. We got the predecessor"<<endl; cout<<"We found the successor and predecessor for the new node:-"<<endl;
cout<<"Successor: "<<y.id()<<endl; cout<<"Successor: "<<y.id()<<endl;
cout<<"Predecessor: "<<z.id()<<endl; cout<<"Predecessor: "<<z.id()<<endl;
successorInfo.set_succaddress("0.0.0.0:"+to_string(y.id())); successorInfo.set_succaddress("0.0.0.0:"+to_string(y.id()));
...@@ -253,6 +252,9 @@ public: ...@@ -253,6 +252,9 @@ public:
fin.close(); fin.close();
int xi=stoi(xyz.substr(xyz.find(':')+1)); int xi=stoi(xyz.substr(xyz.find(':')+1));
if(xi==node) { if(xi==node) {
cout<<"We found the successor and predecessor for the new node:-"<<endl;
cout<<"Successor: "<<next<<endl;
cout<<"Predecessor: "<<node<<endl;
successorInfo.set_succaddress("0.0.0.0:"+to_string(next)); successorInfo.set_succaddress("0.0.0.0:"+to_string(next));
successorInfo.set_predaddress("0.0.0.0:"+to_string(node)); successorInfo.set_predaddress("0.0.0.0:"+to_string(node));
} }
...@@ -262,8 +264,8 @@ public: ...@@ -262,8 +264,8 @@ public:
stub=KeyValueServices::NewStub(channel); stub=KeyValueServices::NewStub(channel);
ClientContext context1; ClientContext context1;
x.set_id(id); x.set_id(id);
cout<<"Asking node "<<node<<" for the successor of new node"<<endl;
stub->GETSUCCESSOR(&context1,x,&y); stub->GETSUCCESSOR(&context1,x,&y);
cout<<"Yes. We got the successor"<<endl;
if(y.id()!=my_id) { if(y.id()!=my_id) {
Id z; Id z;
string t_address("0.0.0.0:"+to_string(y.id())); string t_address("0.0.0.0:"+to_string(y.id()));
...@@ -271,13 +273,16 @@ public: ...@@ -271,13 +273,16 @@ public:
stub=KeyValueServices::NewStub(channel); stub=KeyValueServices::NewStub(channel);
ClientContext context2; ClientContext context2;
stub->GETPREDECESSOR(&context2,y,&z); stub->GETPREDECESSOR(&context2,y,&z);
cout<<"Yes. We got the predecessor"<<endl; cout<<"We found the successor and predecessor for the new node:-"<<endl;
cout<<"Successor: "<<y.id()<<endl; cout<<"Successor: "<<y.id()<<endl;
cout<<"Predecessor: "<<z.id()<<endl; cout<<"Predecessor: "<<z.id()<<endl;
successorInfo.set_succaddress("0.0.0.0:"+to_string(y.id())); successorInfo.set_succaddress("0.0.0.0:"+to_string(y.id()));
successorInfo.set_predaddress("0.0.0.0:"+to_string(z.id())); successorInfo.set_predaddress("0.0.0.0:"+to_string(z.id()));
} }
else { else {
cout<<"We found the successor and predecessor for the new node:-"<<endl;
cout<<"Successor: "<<next<<endl;
cout<<"Predecessor: "<<node<<endl;
successorInfo.set_succaddress("0.0.0.0:"+to_string(next)); successorInfo.set_succaddress("0.0.0.0:"+to_string(next));
successorInfo.set_predaddress("0.0.0.0:"+to_string(node)); successorInfo.set_predaddress("0.0.0.0:"+to_string(node));
} }
...@@ -292,6 +297,9 @@ public: ...@@ -292,6 +297,9 @@ public:
fin1.close(); fin1.close();
int t1i=stoi(t1.substr(t1.find(':')+1)); int t1i=stoi(t1.substr(t1.find(':')+1));
if(t1==t2||t1i==node) { if(t1==t2||t1i==node) {
cout<<"We found the successor and predecessor for the new node:-"<<endl;
cout<<"Successor: "<<node<<endl;
cout<<"Predecessor: "<<next<<endl;
successorInfo.set_succaddress("0.0.0.0:"+to_string(node)); successorInfo.set_succaddress("0.0.0.0:"+to_string(node));
successorInfo.set_predaddress("0.0.0.0:"+to_string(next)); successorInfo.set_predaddress("0.0.0.0:"+to_string(next));
} }
...@@ -301,8 +309,8 @@ public: ...@@ -301,8 +309,8 @@ public:
stub=KeyValueServices::NewStub(channel); stub=KeyValueServices::NewStub(channel);
ClientContext context1; ClientContext context1;
x.set_id(id); x.set_id(id);
cout<<"Asking node "<<node<<" for the successor of new node"<<endl;
stub->GETSUCCESSOR(&context1,x,&y); stub->GETSUCCESSOR(&context1,x,&y);
cout<<"Yes. We got the successor"<<endl;
if(y.id()!=my_id) { if(y.id()!=my_id) {
Id z; Id z;
string t_address("0.0.0.0:"+to_string(y.id())); string t_address("0.0.0.0:"+to_string(y.id()));
...@@ -310,13 +318,16 @@ public: ...@@ -310,13 +318,16 @@ public:
stub=KeyValueServices::NewStub(channel); stub=KeyValueServices::NewStub(channel);
ClientContext context2; ClientContext context2;
stub->GETPREDECESSOR(&context2,y,&z); stub->GETPREDECESSOR(&context2,y,&z);
cout<<"Yes. We got the predecessor"<<endl; cout<<"We found the successor and predecessor for the new node:-"<<endl;
cout<<"Successor: "<<y.id()<<endl; cout<<"Successor: "<<y.id()<<endl;
cout<<"Predecessor: "<<z.id()<<endl; cout<<"Predecessor: "<<z.id()<<endl;
successorInfo.set_succaddress("0.0.0.0:"+to_string(y.id())); successorInfo.set_succaddress("0.0.0.0:"+to_string(y.id()));
successorInfo.set_predaddress("0.0.0.0:"+to_string(z.id())); successorInfo.set_predaddress("0.0.0.0:"+to_string(z.id()));
} }
else { else {
cout<<"We found the successor and predecessor for the new node:-"<<endl;
cout<<"Successor: "<<next<<endl;
cout<<"Predecessor: "<<node<<endl;
successorInfo.set_succaddress("0.0.0.0:"+to_string(next)); successorInfo.set_succaddress("0.0.0.0:"+to_string(next));
successorInfo.set_predaddress("0.0.0.0:"+to_string(node)); successorInfo.set_predaddress("0.0.0.0:"+to_string(node));
} }
...@@ -325,12 +336,12 @@ public: ...@@ -325,12 +336,12 @@ public:
} }
} }
else { else {
cout<<"We got no node with id greater than new node"<<endl; cout<<"We found the successor and predecessor for the new node:-"<<endl;
cout<<"Only one node present right now, that is me"<<endl; cout<<"Successor: "<<my_id<<endl;
cout<<"Predecessor: "<<my_id<<endl;
successorInfo.set_succaddress("0.0.0.0:"+to_string(my_id)); successorInfo.set_succaddress("0.0.0.0:"+to_string(my_id));
successorInfo.set_predaddress("0.0.0.0:"+to_string(my_id)); successorInfo.set_predaddress("0.0.0.0:"+to_string(my_id));
} }
cout<<"Sending the successor and predecessor back to the new server"<<endl;
newResponder.Finish(successorInfo,Status::OK,this); newResponder.Finish(successorInfo,Status::OK,this);
} }
else if(reqType==INFORMSUCCESSOR){ else if(reqType==INFORMSUCCESSOR){
...@@ -340,7 +351,6 @@ public: ...@@ -340,7 +351,6 @@ public:
string keyvalues=memManager->getKeyValuePairs(id,stoi(params["LISTENING_PORT"])); string keyvalues=memManager->getKeyValuePairs(id,stoi(params["LISTENING_PORT"]));
string keys=keyvalues.substr(0,keyvalues.find(";;")+1); string keys=keyvalues.substr(0,keyvalues.find(";;")+1);
string values=keyvalues.substr(keyvalues.find(";;")+2); string values=keyvalues.substr(keyvalues.find(";;")+2);
cout<<"Okay, my new predecessor is: "<<info.address()<<endl;
ifstream fin; ifstream fin;
fin.open(NEIGHBOURS); fin.open(NEIGHBOURS);
string successor,predecessor; string successor,predecessor;
...@@ -355,15 +365,15 @@ public: ...@@ -355,15 +365,15 @@ public:
fout.close(); fout.close();
keyValues.set_keys(keys); keyValues.set_keys(keys);
keyValues.set_values(values); keyValues.set_values(values);
cout<<"Done making changes accordingly"<<endl; cout<<"My new Predecessor: "<<id<<endl;
cout<<"Keys given to "<<id<<endl;
informSuccessorResponder.Finish(keyValues,Status::OK,this); informSuccessorResponder.Finish(keyValues,Status::OK,this);
} }
else if(reqType==GETSUCCESSOR) { else if(reqType==GETSUCCESSOR) {
cout<<"Some server asked me to find the successor of "<<idvar1.id()<<endl; cout<<"Request to find successor of "<<idvar1.id()<<endl;
int id=idvar1.id(); int id=idvar1.id();
int fingers[16]; int fingers[16];
ifstream fin; ifstream fin;
cout<<"Getting the finger table"<<endl;
fin.open(FINGER_TABLE); fin.open(FINGER_TABLE);
int nums=0; int nums=0;
for(int i=0;i<16;i++) { for(int i=0;i<16;i++) {
...@@ -372,6 +382,7 @@ public: ...@@ -372,6 +382,7 @@ public:
if(temp=="null"||temp.size()==0) if(temp=="null"||temp.size()==0)
break; break;
fingers[i]=stoi(temp); fingers[i]=stoi(temp);
nums++;
} }
fin.close(); fin.close();
int node=-1; int node=-1;
...@@ -415,7 +426,6 @@ public: ...@@ -415,7 +426,6 @@ public:
Id x; Id x;
x.set_id(next); x.set_id(next);
Id y; Id y;
cout<<"asking the possible successor whether its predecessor is less than the new node id"<<endl;
int mypred,nextpred; int mypred,nextpred;
fin.open(NEIGHBOURS); fin.open(NEIGHBOURS);
string temp; string temp;
...@@ -427,10 +437,14 @@ public: ...@@ -427,10 +437,14 @@ public:
stub->GETPREDECESSOR(&context,x,&y); stub->GETPREDECESSOR(&context,x,&y);
nextpred=y.id(); nextpred=y.id();
} }
if(fl==false&&next!=my_id&&nextpred==node) if(fl==false&&next!=my_id&&nextpred==node) {
cout<<"Successor found: "<<x.id()<<endl;
idvar2.set_id(x.id()); idvar2.set_id(x.id());
else if(fl==false&&next==my_id&&mypred==node) }
else if(fl==false&&next==my_id&&mypred==node) {
cout<<"Successor found: "<<x.id()<<endl;
idvar2.set_id(x.id()); idvar2.set_id(x.id());
}
else if(fl==false){ else if(fl==false){
if(node==my_id) { if(node==my_id) {
int mysucc; int mysucc;
...@@ -440,15 +454,19 @@ public: ...@@ -440,15 +454,19 @@ public:
getline(fin,temp); getline(fin,temp);
fin.close(); fin.close();
mysucc=stoi(temp.substr(temp.find(':')+1)); mysucc=stoi(temp.substr(temp.find(':')+1));
if(mysucc>=id) if(mysucc>=id) {
cout<<"Successor found: "<<mysucc<<endl;
idvar2.set_id(mysucc); idvar2.set_id(mysucc);
}
else { else {
string tar_address("0.0.0.0:"+to_string(mysucc)); string tar_address("0.0.0.0:"+to_string(mysucc));
channel=grpc::CreateChannel(tar_address, grpc::InsecureChannelCredentials()); channel=grpc::CreateChannel(tar_address, grpc::InsecureChannelCredentials());
stub=KeyValueServices::NewStub(channel); stub=KeyValueServices::NewStub(channel);
ClientContext context1; ClientContext context1;
x.set_id(id); x.set_id(id);
cout<<"Asking node "<<mysucc<<" to find successor of given node"<<endl;
stub->GETSUCCESSOR(&context1,x,&y); stub->GETSUCCESSOR(&context1,x,&y);
cout<<"Successor found: "<<y.id()<<endl;
idvar2.set_id(y.id()); idvar2.set_id(y.id());
} }
} }
...@@ -458,7 +476,9 @@ public: ...@@ -458,7 +476,9 @@ public:
stub=KeyValueServices::NewStub(channel); stub=KeyValueServices::NewStub(channel);
ClientContext context1; ClientContext context1;
x.set_id(id); x.set_id(id);
cout<<"Asking node "<<node<<" to find successor of given node"<<endl;
stub->GETSUCCESSOR(&context1,x,&y); stub->GETSUCCESSOR(&context1,x,&y);
cout<<"Successor found: "<<y.id()<<endl;
idvar2.set_id(y.id()); idvar2.set_id(y.id());
} }
} }
...@@ -471,6 +491,7 @@ public: ...@@ -471,6 +491,7 @@ public:
fin.close(); fin.close();
int xi=stoi(xyz.substr(xyz.find(':')+1));; int xi=stoi(xyz.substr(xyz.find(':')+1));;
if(xi==node) { if(xi==node) {
cout<<"Successor found: "<<next<<endl;
idvar2.set_id(next); idvar2.set_id(next);
} }
else { else {
...@@ -479,12 +500,14 @@ public: ...@@ -479,12 +500,14 @@ public:
stub=KeyValueServices::NewStub(channel); stub=KeyValueServices::NewStub(channel);
ClientContext context1; ClientContext context1;
x.set_id(id); x.set_id(id);
cout<<"Asking node "<<node<<" to find the successor of given node"<<endl;
stub->GETSUCCESSOR(&context1,x,&y); stub->GETSUCCESSOR(&context1,x,&y);
cout<<"Yes. We got the successor"<<endl;
if(y.id()!=my_id) { if(y.id()!=my_id) {
cout<<"Successor found: "<<y.id()<<endl;
idvar2.set_id(y.id()); idvar2.set_id(y.id());
} }
else { else {
cout<<"Successor found: "<<next<<endl;
idvar2.set_id(next); idvar2.set_id(next);
} }
} }
...@@ -498,7 +521,7 @@ public: ...@@ -498,7 +521,7 @@ public:
fin1.close(); fin1.close();
int t1i=stoi(t1.substr(t1.find(':')+1)); int t1i=stoi(t1.substr(t1.find(':')+1));
if(t1==t2||t1i==node) { if(t1==t2||t1i==node) {
cout<<"Here"<<endl; cout<<"Successor found: "<<node<<endl;
idvar2.set_id(node); idvar2.set_id(node);
} }
else { else {
...@@ -507,12 +530,14 @@ public: ...@@ -507,12 +530,14 @@ public:
stub=KeyValueServices::NewStub(channel); stub=KeyValueServices::NewStub(channel);
ClientContext context1; ClientContext context1;
x.set_id(id); x.set_id(id);
cout<<"Asking node "<<node<<" to find the successor of given node"<<endl;
stub->GETSUCCESSOR(&context1,x,&y); stub->GETSUCCESSOR(&context1,x,&y);
cout<<"Yes. We got the successor"<<endl;
if(y.id()!=my_id) { if(y.id()!=my_id) {
cout<<"Successor found: "<<y.id()<<endl;
idvar2.set_id(y.id()); idvar2.set_id(y.id());
} }
else { else {
cout<<"Successor found: "<<next<<endl;
idvar2.set_id(next); idvar2.set_id(next);
} }
} }
...@@ -522,7 +547,7 @@ public: ...@@ -522,7 +547,7 @@ public:
getSuccessorResponder.Finish(idvar2,Status::OK,this); getSuccessorResponder.Finish(idvar2,Status::OK,this);
} }
else if(reqType==GETPREDECESSOR) { else if(reqType==GETPREDECESSOR) {
cout<<"Someone asked me for my predecessor. Sending them"<<endl; cout<<"Request for my Predecessor"<<endl;
ifstream fin; ifstream fin;
fin.open(NEIGHBOURS); fin.open(NEIGHBOURS);
string successor,predecessor; string successor,predecessor;
...@@ -530,12 +555,11 @@ public: ...@@ -530,12 +555,11 @@ public:
getline(fin,predecessor); getline(fin,predecessor);
fin.close(); fin.close();
idvar2.set_id(stoi(predecessor.substr(predecessor.find(':')+1))); idvar2.set_id(stoi(predecessor.substr(predecessor.find(':')+1)));
cout<<"Sent my predecessor"<<endl; cout<<"Sent my predecessor: "<<idvar2.id()<<endl;
getPredecessorResponder.Finish(idvar2,Status::OK,this); getPredecessorResponder.Finish(idvar2,Status::OK,this);
} }
else if(reqType==INFORMPREDECESSOR) { else if(reqType==INFORMPREDECESSOR) {
cout<<"Okay, i got the information that my successor has changed"<<endl; cout<<"My new Successor: "<<info.address()<<endl;
cout<<"My new successor: "<<info.address()<<endl;
ifstream fin; ifstream fin;
fin.open(NEIGHBOURS); fin.open(NEIGHBOURS);
string successor,predecessor; string successor,predecessor;
...@@ -549,10 +573,10 @@ public: ...@@ -549,10 +573,10 @@ public:
fout<<predecessor<<endl; fout<<predecessor<<endl;
fout.close(); fout.close();
null.set_nothing(0); null.set_nothing(0);
cout<<"Okay, i made the necessary changes"<<endl;
informPredecessorResponder.Finish(null,Status::OK,this); informPredecessorResponder.Finish(null,Status::OK,this);
} }
else { else {
cout<<"Updating finger table"<<endl;
string addresses=addressarr.addresses(); string addresses=addressarr.addresses();
int num=addressarr.servers(); int num=addressarr.servers();
int ids[num]; int ids[num];
...@@ -602,6 +626,7 @@ public: ...@@ -602,6 +626,7 @@ public:
fout.close(); fout.close();
Null n; Null n;
n.set_nothing(0); n.set_nothing(0);
cout<<"Finger table updated"<<endl;
updateTableResponder.Finish(n,Status::OK,this); updateTableResponder.Finish(n,Status::OK,this);
} }
status = FINISH; status = FINISH;
...@@ -671,10 +696,10 @@ public: ...@@ -671,10 +696,10 @@ public:
else else
pred_id=stoi(pred.substr(pred.find(':')+1)); pred_id=stoi(pred.substr(pred.find(':')+1));
if(my_id<key_id&&!(pred_id<key_id&&pred_id>my_id)) { if(my_id<key_id&&!(pred_id<key_id&&pred_id>my_id)) {
cout<<"I don't have the key"<<endl;
//transfer request //transfer request
int fingers[16]; int fingers[16];
ifstream fin; ifstream fin;
cout<<"Getting my finger table"<<endl;
fin.open(FINGER_TABLE); fin.open(FINGER_TABLE);
int nums=0; int nums=0;
do { do {
...@@ -726,7 +751,6 @@ public: ...@@ -726,7 +751,6 @@ public:
Id x; Id x;
x.set_id(next); x.set_id(next);
Id y; Id y;
cout<<"asking the possible successor whether its predecessor is less than the new node id"<<endl;
int mypred,nextpred; int mypred,nextpred;
fin.open(NEIGHBOURS); fin.open(NEIGHBOURS);
string temp; string temp;
...@@ -791,7 +815,6 @@ public: ...@@ -791,7 +815,6 @@ public:
ClientContext context1; ClientContext context1;
x.set_id(key_id); x.set_id(key_id);
stub->GETSUCCESSOR(&context1,x,&y); stub->GETSUCCESSOR(&context1,x,&y);
cout<<"Yes. We got the successor"<<endl;
if(y.id()!=my_id) { if(y.id()!=my_id) {
succ=y.id(); succ=y.id();
} }
...@@ -818,7 +841,6 @@ public: ...@@ -818,7 +841,6 @@ public:
ClientContext context1; ClientContext context1;
x.set_id(key_id); x.set_id(key_id);
stub->GETSUCCESSOR(&context1,x,&y); stub->GETSUCCESSOR(&context1,x,&y);
cout<<"Yes. We got the successor"<<endl;
if(y.id()!=my_id) { if(y.id()!=my_id) {
succ=y.id(); succ=y.id();
} }
...@@ -833,6 +855,7 @@ public: ...@@ -833,6 +855,7 @@ public:
shared_ptr<Channel> channel=grpc::CreateChannel(t_address, grpc::InsecureChannelCredentials()); shared_ptr<Channel> channel=grpc::CreateChannel(t_address, grpc::InsecureChannelCredentials());
unique_ptr<KeyValueServices::Stub> stub=KeyValueServices::NewStub(channel); unique_ptr<KeyValueServices::Stub> stub=KeyValueServices::NewStub(channel);
ClientContext cont1; ClientContext cont1;
cout<<"Forwarding request to node "<<succ<<endl;
stub->GET(&cont1,key,&value); stub->GET(&cont1,key,&value);
} }
else if(my_id==key_id||(my_id<key_id&&pred_id<key_id&&pred_id>my_id)) { else if(my_id==key_id||(my_id<key_id&&pred_id<key_id&&pred_id>my_id)) {
...@@ -850,6 +873,7 @@ public: ...@@ -850,6 +873,7 @@ public:
value.set_error(v); value.set_error(v);
} }
cout << " RETURN VALUE : " << value.value() << endl; cout << " RETURN VALUE : " << value.value() << endl;
memManager->traverse();
} }
else { else {
if(pred_id==-1||pred_id<key_id) { if(pred_id==-1||pred_id<key_id) {
...@@ -867,12 +891,13 @@ public: ...@@ -867,12 +891,13 @@ public:
value.set_error(v); value.set_error(v);
} }
cout << " RETURN VALUE : " << value.value() << endl; cout << " RETURN VALUE : " << value.value() << endl;
memManager->traverse();
} }
else { else {
cout<<"I don't have the key"<<endl;
//transfer the request //transfer the request
int fingers[16]; int fingers[16];
ifstream fin; ifstream fin;
cout<<"Getting my finger table"<<endl;
fin.open(FINGER_TABLE); fin.open(FINGER_TABLE);
int nums=0; int nums=0;
do { do {
...@@ -924,7 +949,6 @@ public: ...@@ -924,7 +949,6 @@ public:
Id x; Id x;
x.set_id(next); x.set_id(next);
Id y; Id y;
cout<<"asking the possible successor whether its predecessor is less than the new node id"<<endl;
int mypred,nextpred; int mypred,nextpred;
fin.open(NEIGHBOURS); fin.open(NEIGHBOURS);
string temp; string temp;
...@@ -989,7 +1013,6 @@ public: ...@@ -989,7 +1013,6 @@ public:
ClientContext context1; ClientContext context1;
x.set_id(key_id); x.set_id(key_id);
stub->GETSUCCESSOR(&context1,x,&y); stub->GETSUCCESSOR(&context1,x,&y);
cout<<"Yes. We got the successor"<<endl;
if(y.id()!=my_id) { if(y.id()!=my_id) {
succ=y.id(); succ=y.id();
} }
...@@ -1016,7 +1039,6 @@ public: ...@@ -1016,7 +1039,6 @@ public:
ClientContext context1; ClientContext context1;
x.set_id(key_id); x.set_id(key_id);
stub->GETSUCCESSOR(&context1,x,&y); stub->GETSUCCESSOR(&context1,x,&y);
cout<<"Yes. We got the successor"<<endl;
if(y.id()!=my_id) { if(y.id()!=my_id) {
succ=y.id(); succ=y.id();
} }
...@@ -1031,6 +1053,7 @@ public: ...@@ -1031,6 +1053,7 @@ public:
shared_ptr<Channel> channel=grpc::CreateChannel(t_address, grpc::InsecureChannelCredentials()); shared_ptr<Channel> channel=grpc::CreateChannel(t_address, grpc::InsecureChannelCredentials());
unique_ptr<KeyValueServices::Stub> stub=KeyValueServices::NewStub(channel); unique_ptr<KeyValueServices::Stub> stub=KeyValueServices::NewStub(channel);
ClientContext cont1; ClientContext cont1;
cout<<"Forwarding request to node "<<succ<<endl;
stub->GET(&cont1,key,&value); stub->GET(&cont1,key,&value);
} }
} }
...@@ -1055,10 +1078,10 @@ public: ...@@ -1055,10 +1078,10 @@ public:
else else
succ_id=stoi(scc.substr(scc.find(':')+1)); succ_id=stoi(scc.substr(scc.find(':')+1));
if(my_id<key_id&&!(pred_id<key_id&&pred_id>my_id)) { if(my_id<key_id&&!(pred_id<key_id&&pred_id>my_id)) {
cout<<"I don't have the key"<<endl;
//transfer request //transfer request
int fingers[16]; int fingers[16];
ifstream fin; ifstream fin;
cout<<"Getting my finger table"<<endl;
fin.open(FINGER_TABLE); fin.open(FINGER_TABLE);
int nums=0; int nums=0;
do { do {
...@@ -1110,7 +1133,6 @@ public: ...@@ -1110,7 +1133,6 @@ public:
Id x; Id x;
x.set_id(next); x.set_id(next);
Id y; Id y;
cout<<"asking the possible successor whether its predecessor is less than the new node id"<<endl;
int mypred,nextpred; int mypred,nextpred;
fin.open(NEIGHBOURS); fin.open(NEIGHBOURS);
string temp; string temp;
...@@ -1175,7 +1197,6 @@ public: ...@@ -1175,7 +1197,6 @@ public:
ClientContext context1; ClientContext context1;
x.set_id(key_id); x.set_id(key_id);
stub->GETSUCCESSOR(&context1,x,&y); stub->GETSUCCESSOR(&context1,x,&y);
cout<<"Yes. We got the successor"<<endl;
if(y.id()!=my_id) { if(y.id()!=my_id) {
succ=y.id(); succ=y.id();
} }
...@@ -1202,7 +1223,6 @@ public: ...@@ -1202,7 +1223,6 @@ public:
ClientContext context1; ClientContext context1;
x.set_id(key_id); x.set_id(key_id);
stub->GETSUCCESSOR(&context1,x,&y); stub->GETSUCCESSOR(&context1,x,&y);
cout<<"Yes. We got the successor"<<endl;
if(y.id()!=my_id) { if(y.id()!=my_id) {
succ=y.id(); succ=y.id();
} }
...@@ -1217,6 +1237,7 @@ public: ...@@ -1217,6 +1237,7 @@ public:
shared_ptr<Channel> channel=grpc::CreateChannel(t_address, grpc::InsecureChannelCredentials()); shared_ptr<Channel> channel=grpc::CreateChannel(t_address, grpc::InsecureChannelCredentials());
unique_ptr<KeyValueServices::Stub> stub=KeyValueServices::NewStub(channel); unique_ptr<KeyValueServices::Stub> stub=KeyValueServices::NewStub(channel);
ClientContext cont1; ClientContext cont1;
cout<<"Forwarding request to node "<<succ<<endl;
stub->PUT(&cont1,keyvalue,&stat); stub->PUT(&cont1,keyvalue,&stat);
} }
else if(my_id==key_id||(my_id<key_id&&pred_id<key_id&&pred_id>my_id)) { else if(my_id==key_id||(my_id<key_id&&pred_id<key_id&&pred_id>my_id)) {
...@@ -1228,6 +1249,7 @@ public: ...@@ -1228,6 +1249,7 @@ public:
pthread_mutex_unlock(&_masterLock); pthread_mutex_unlock(&_masterLock);
stat.set_status(200); stat.set_status(200);
memManager->traverse();
} }
else { else {
if(pred_id==-1||(pred_id<key_id&&my_id>=key_id)||(pred_id>my_id&&my_id>=key_id)) { if(pred_id==-1||(pred_id<key_id&&my_id>=key_id)||(pred_id>my_id&&my_id>=key_id)) {
...@@ -1239,12 +1261,13 @@ public: ...@@ -1239,12 +1261,13 @@ public:
pthread_mutex_unlock(&_masterLock); pthread_mutex_unlock(&_masterLock);
stat.set_status(200); stat.set_status(200);
memManager->traverse();
} }
else { else {
cout<<"I don't have the key"<<endl;
//transfer the request //transfer the request
int fingers[16]; int fingers[16];
ifstream fin; ifstream fin;
cout<<"Getting my finger table"<<endl;
fin.open(FINGER_TABLE); fin.open(FINGER_TABLE);
int nums=0; int nums=0;
do { do {
...@@ -1296,7 +1319,6 @@ public: ...@@ -1296,7 +1319,6 @@ public:
Id x; Id x;
x.set_id(next); x.set_id(next);
Id y; Id y;
cout<<"asking the possible successor whether its predecessor is less than the new node id"<<endl;
int mypred,nextpred; int mypred,nextpred;
fin.open(NEIGHBOURS); fin.open(NEIGHBOURS);
string temp; string temp;
...@@ -1361,7 +1383,6 @@ public: ...@@ -1361,7 +1383,6 @@ public:
ClientContext context1; ClientContext context1;
x.set_id(key_id); x.set_id(key_id);
stub->GETSUCCESSOR(&context1,x,&y); stub->GETSUCCESSOR(&context1,x,&y);
cout<<"Yes. We got the successor"<<endl;
if(y.id()!=my_id) { if(y.id()!=my_id) {
succ=y.id(); succ=y.id();
} }
...@@ -1388,7 +1409,6 @@ public: ...@@ -1388,7 +1409,6 @@ public:
ClientContext context1; ClientContext context1;
x.set_id(key_id); x.set_id(key_id);
stub->GETSUCCESSOR(&context1,x,&y); stub->GETSUCCESSOR(&context1,x,&y);
cout<<"Yes. We got the successor"<<endl;
if(y.id()!=my_id) { if(y.id()!=my_id) {
succ=y.id(); succ=y.id();
} }
...@@ -1403,6 +1423,7 @@ public: ...@@ -1403,6 +1423,7 @@ public:
shared_ptr<Channel> channel=grpc::CreateChannel(t_address, grpc::InsecureChannelCredentials()); shared_ptr<Channel> channel=grpc::CreateChannel(t_address, grpc::InsecureChannelCredentials());
unique_ptr<KeyValueServices::Stub> stub=KeyValueServices::NewStub(channel); unique_ptr<KeyValueServices::Stub> stub=KeyValueServices::NewStub(channel);
ClientContext cont1; ClientContext cont1;
cout<<"Forwarding request to node "<<succ<<endl;
stub->PUT(&cont1,keyvalue,&stat); stub->PUT(&cont1,keyvalue,&stat);
} }
} }
...@@ -1423,10 +1444,10 @@ public: ...@@ -1423,10 +1444,10 @@ public:
else else
pred_id=stoi(pred.substr(pred.find(':')+1)); pred_id=stoi(pred.substr(pred.find(':')+1));
if(my_id<key_id&&!(pred_id<key_id&&pred_id>my_id)) { if(my_id<key_id&&!(pred_id<key_id&&pred_id>my_id)) {
cout<<"I don't have the key"<<endl;
//transfer request //transfer request
int fingers[16]; int fingers[16];
ifstream fin; ifstream fin;
cout<<"Getting my finger table"<<endl;
fin.open(FINGER_TABLE); fin.open(FINGER_TABLE);
int nums=0; int nums=0;
do { do {
...@@ -1478,7 +1499,6 @@ public: ...@@ -1478,7 +1499,6 @@ public:
Id x; Id x;
x.set_id(next); x.set_id(next);
Id y; Id y;
cout<<"asking the possible successor whether its predecessor is less than the new node id"<<endl;
int mypred,nextpred; int mypred,nextpred;
fin.open(NEIGHBOURS); fin.open(NEIGHBOURS);
string temp; string temp;
...@@ -1543,7 +1563,6 @@ public: ...@@ -1543,7 +1563,6 @@ public:
ClientContext context1; ClientContext context1;
x.set_id(key_id); x.set_id(key_id);
stub->GETSUCCESSOR(&context1,x,&y); stub->GETSUCCESSOR(&context1,x,&y);
cout<<"Yes. We got the successor"<<endl;
if(y.id()!=my_id) { if(y.id()!=my_id) {
succ=y.id(); succ=y.id();
} }
...@@ -1570,7 +1589,6 @@ public: ...@@ -1570,7 +1589,6 @@ public:
ClientContext context1; ClientContext context1;
x.set_id(key_id); x.set_id(key_id);
stub->GETSUCCESSOR(&context1,x,&y); stub->GETSUCCESSOR(&context1,x,&y);
cout<<"Yes. We got the successor"<<endl;
if(y.id()!=my_id) { if(y.id()!=my_id) {
succ=y.id(); succ=y.id();
} }
...@@ -1585,6 +1603,7 @@ public: ...@@ -1585,6 +1603,7 @@ public:
shared_ptr<Channel> channel=grpc::CreateChannel(t_address, grpc::InsecureChannelCredentials()); shared_ptr<Channel> channel=grpc::CreateChannel(t_address, grpc::InsecureChannelCredentials());
unique_ptr<KeyValueServices::Stub> stub=KeyValueServices::NewStub(channel); unique_ptr<KeyValueServices::Stub> stub=KeyValueServices::NewStub(channel);
ClientContext cont1; ClientContext cont1;
cout<<"Forwarding request to node "<<succ<<endl;
stub->DEL(&cont1,key,&stat); stub->DEL(&cont1,key,&stat);
} }
else if(my_id==key_id||(my_id<key_id&&pred_id<key_id&&pred_id>my_id)) { else if(my_id==key_id||(my_id<key_id&&pred_id<key_id&&pred_id>my_id)) {
...@@ -1602,6 +1621,7 @@ public: ...@@ -1602,6 +1621,7 @@ public:
stat.set_status(400); stat.set_status(400);
stat.set_error("KEY NOT EXIST"); stat.set_error("KEY NOT EXIST");
} }
memManager->traverse();
} }
else { else {
if(pred_id==-1||pred_id<key_id) { if(pred_id==-1||pred_id<key_id) {
...@@ -1619,11 +1639,12 @@ public: ...@@ -1619,11 +1639,12 @@ public:
stat.set_status(400); stat.set_status(400);
stat.set_error("KEY NOT EXIST"); stat.set_error("KEY NOT EXIST");
} }
memManager->traverse();
} }
else { else {
cout<<"I don't have the key"<<endl;
int fingers[16]; int fingers[16];
ifstream fin; ifstream fin;
cout<<"Getting my finger table"<<endl;
fin.open(FINGER_TABLE); fin.open(FINGER_TABLE);
int nums=0; int nums=0;
do { do {
...@@ -1675,7 +1696,6 @@ public: ...@@ -1675,7 +1696,6 @@ public:
Id x; Id x;
x.set_id(next); x.set_id(next);
Id y; Id y;
cout<<"asking the possible successor whether its predecessor is less than the new node id"<<endl;
int mypred,nextpred; int mypred,nextpred;
fin.open(NEIGHBOURS); fin.open(NEIGHBOURS);
string temp; string temp;
...@@ -1740,7 +1760,6 @@ public: ...@@ -1740,7 +1760,6 @@ public:
ClientContext context1; ClientContext context1;
x.set_id(key_id); x.set_id(key_id);
stub->GETSUCCESSOR(&context1,x,&y); stub->GETSUCCESSOR(&context1,x,&y);
cout<<"Yes. We got the successor"<<endl;
if(y.id()!=my_id) { if(y.id()!=my_id) {
succ=y.id(); succ=y.id();
} }
...@@ -1767,7 +1786,6 @@ public: ...@@ -1767,7 +1786,6 @@ public:
ClientContext context1; ClientContext context1;
x.set_id(key_id); x.set_id(key_id);
stub->GETSUCCESSOR(&context1,x,&y); stub->GETSUCCESSOR(&context1,x,&y);
cout<<"Yes. We got the successor"<<endl;
if(y.id()!=my_id) { if(y.id()!=my_id) {
succ=y.id(); succ=y.id();
} }
...@@ -1782,13 +1800,13 @@ public: ...@@ -1782,13 +1800,13 @@ public:
shared_ptr<Channel> channel=grpc::CreateChannel(t_address, grpc::InsecureChannelCredentials()); shared_ptr<Channel> channel=grpc::CreateChannel(t_address, grpc::InsecureChannelCredentials());
unique_ptr<KeyValueServices::Stub> stub=KeyValueServices::NewStub(channel); unique_ptr<KeyValueServices::Stub> stub=KeyValueServices::NewStub(channel);
ClientContext cont1; ClientContext cont1;
cout<<"Forwarding request to node "<<succ<<endl;
stub->DEL(&cont1,key,&stat); stub->DEL(&cont1,key,&stat);
} }
} }
delResponder.Finish(stat, Status::OK, this); delResponder.Finish(stat, Status::OK, this);
} }
/* --------------------------------CONTENT OF CACHE ONLY KEY-------------------------------- */ /* --------------------------------CONTENT OF CACHE ONLY KEY-------------------------------- */
memManager->traverse();
status = FINISH; status = FINISH;
} else { } else {
GPR_ASSERT(status == FINISH); GPR_ASSERT(status == FINISH);
...@@ -1947,7 +1965,6 @@ void updateAllFingerTables() { ...@@ -1947,7 +1965,6 @@ void updateAllFingerTables() {
} }
void register_server_DNS(string my_address) { void register_server_DNS(string my_address) {
cout<<"Registering to DNS"<<endl;
string target_address(DNS_SERVER); string target_address(DNS_SERVER);
shared_ptr<Channel> channel=grpc::CreateChannel(target_address, grpc::InsecureChannelCredentials()); shared_ptr<Channel> channel=grpc::CreateChannel(target_address, grpc::InsecureChannelCredentials());
unique_ptr<KeyValueServices::Stub> stub; unique_ptr<KeyValueServices::Stub> stub;
...@@ -1957,29 +1974,22 @@ void register_server_DNS(string my_address) { ...@@ -1957,29 +1974,22 @@ void register_server_DNS(string my_address) {
Info info; Info info;
ClientContext context; ClientContext context;
Status status=stub->GETADDRESS(&context,null,&info); Status status=stub->GETADDRESS(&context,null,&info);
cout<<"Address received:"<<info.address()<<endl;
string old_server; string old_server;
if(status.ok()) { if(status.ok()) {
old_server=info.address(); old_server=info.address();
info.set_address(my_address); info.set_address(my_address);
ClientContext new_context; ClientContext new_context;
cout<<"Adding address to DNS"<<endl;
stub->ADDADDRESS(&new_context,info,&null); stub->ADDADDRESS(&new_context,info,&null);
cout<<"Address added to DNS"<<endl;
ofstream fout; ofstream fout;
cout<<"Generating initial finger table"<<endl;
fout.open(FINGER_TABLE); fout.open(FINGER_TABLE);
for(int i=0;i<16;i++) for(int i=0;i<16;i++)
fout<<"null"<<endl; fout<<"null"<<endl;
fout.close(); fout.close();
cout<<"Initial finger table generated"<<endl;
if(old_server=="null") { if(old_server=="null") {
cout<<"Initializing initial neighbours"<<endl;
fout.open(NEIGHBOURS); fout.open(NEIGHBOURS);
fout<<"-1"<<endl; fout<<"-1"<<endl;
fout<<"-1"<<endl; fout<<"-1"<<endl;
fout.close(); fout.close();
cout<<"Initialized initial neighbours"<<endl;
return; return;
} }
channel=grpc::CreateChannel(old_server,grpc::InsecureChannelCredentials()); channel=grpc::CreateChannel(old_server,grpc::InsecureChannelCredentials());
...@@ -1989,25 +1999,21 @@ void register_server_DNS(string my_address) { ...@@ -1989,25 +1999,21 @@ void register_server_DNS(string my_address) {
ClientContext context1; ClientContext context1;
cout<<"Sending request to server: "<<old_server<<endl; cout<<"Sending request to server: "<<old_server<<endl;
status=stub->NEW(&context1,info,&successorInfo); status=stub->NEW(&context1,info,&successorInfo);
cout<<"Request sent. Successor and predecessor info received"<<endl;
if(status.ok()) { if(status.ok()) {
string successor=successorInfo.succaddress(); string successor=successorInfo.succaddress();
string predecessor=successorInfo.predaddress(); string predecessor=successorInfo.predaddress();
ofstream fout; ofstream fout;
cout<<"Storing neighbours info"<<endl;
fout.open(NEIGHBOURS); fout.open(NEIGHBOURS);
fout<<successor<<endl; fout<<successor<<endl;
fout<<predecessor<<endl; fout<<predecessor<<endl;
fout.close(); fout.close();
cout<<"Successor: "<<successor<<endl; cout<<"Successor: "<<successor<<endl;
cout<<"Predecessor: "<<predecessor<<endl; cout<<"Predecessor: "<<predecessor<<endl;
cout<<"Stored neighbours info"<<endl;
channel=grpc::CreateChannel(successor,grpc::InsecureChannelCredentials()); channel=grpc::CreateChannel(successor,grpc::InsecureChannelCredentials());
stub=KeyValueServices::NewStub(channel); stub=KeyValueServices::NewStub(channel);
info.set_address(my_address); info.set_address(my_address);
KeyValues keyValues; KeyValues keyValues;
ClientContext context2; ClientContext context2;
cout<<"Informing successor about my presence"<<endl;
status=stub->INFORMSUCCESSOR(&context2,info,&keyValues); status=stub->INFORMSUCCESSOR(&context2,info,&keyValues);
string keys=keyValues.keys(); string keys=keyValues.keys();
string values=keyValues.values(); string values=keyValues.values();
...@@ -2022,14 +2028,11 @@ void register_server_DNS(string my_address) { ...@@ -2022,14 +2028,11 @@ void register_server_DNS(string my_address) {
values=values.substr(values.find(';')+1); values=values.substr(values.find(';')+1);
memManager->put(key,value); memManager->put(key,value);
} }
cout<<"Informed succesor"<<endl;
channel=grpc::CreateChannel(predecessor,grpc::InsecureChannelCredentials()); channel=grpc::CreateChannel(predecessor,grpc::InsecureChannelCredentials());
stub=KeyValueServices::NewStub(channel); stub=KeyValueServices::NewStub(channel);
info.set_address(my_address); info.set_address(my_address);
ClientContext context3; ClientContext context3;
cout<<"Informing predecessor about my presence"<<endl;
status=stub->INFORMPREDECESSOR(&context3,info,&null); status=stub->INFORMPREDECESSOR(&context3,info,&null);
cout<<"Informed predecessor"<<endl;
updateAllFingerTables(); updateAllFingerTables();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment