Commit b69e736e authored by mayankkakad's avatar mayankkakad

splitting keyvalues template made

parent ce5b49e6
......@@ -20,6 +20,9 @@ public:
virtual void pushAll() {
return;
}
virtual string getKeyValuePairs(int id) {
return "This will never run";
}
};
class storageLRU : public memoryManagement {
......@@ -57,6 +60,10 @@ public:
void pushAll() {
mycache.pushAll();
}
string getKeyValuePairs(int id) {
return "keyvaluepairs";
}
};
class storageLFU : public memoryManagement {
......@@ -93,4 +100,8 @@ public:
void pushAll() {
mycache.pushAll();
}
string getKeyValuePairs(int id) {
return "keyvaluepairs";
}
};
\ No newline at end of file
......@@ -50,8 +50,8 @@ message SuccessorInfo {
}
message KeyValues {
repeated string keys = 1;
repeated string values = 2;
string keys = 1;
string values = 2;
}
message Null {
......
......@@ -214,9 +214,12 @@ public:
}
else if(reqType==INFORMSUCCESSOR){
//return half of the keyvalue pairs to the requesting node
//cout<<"Okay, my new predecessor is: "<<info.address()<<endl;
string address=info.address();
int id=stoi(address.substr(address.find(':')+1));
string keyvalues=memManager->getKeyValuePairs(id);
string keys=keyvalues.substr(0,keyvalues.find(";;")+1);
string values=keyvalues.substr(keyvalues.find(";;")+2);
//cout<<"Okay, my new predecessor is: "<<info.address()<<endl;
ifstream fin;
fin.open(NEIGHBOURS);
string successor,predecessor;
......@@ -229,7 +232,8 @@ public:
fout<<successor<<endl;
fout<<predecessor<<endl;
fout.close();
null.set_nothing(0);
keyValues.set_keys(keys);
keyValues.set_values(values);
//cout<<"Done making changes accordingly"<<endl;
informSuccessorResponder.Finish(keyValues,Status::OK,this);
}
......@@ -1340,6 +1344,19 @@ void register_server_DNS(string my_address) {
ClientContext context2;
//cout<<"Informing successor about my presence"<<endl;
status=stub->INFORMSUCCESSOR(&context2,info,&keyValues);
string keys=keyValues.keys();
string values=keyValues.values();
while(true) {
string key=keys.substr(0,keys.find(';'));
string value=values.substr(0,values.find(';'));
if(key.size()==0)
break;
if(keys.find(';')+1==keys.size())
break;
keys=keys.substr(keys.find(';')+1);
values=values.substr(values.find(';')+1);
memManager->put(key,value);
}
//cout<<"Informed succesor"<<endl;
channel=grpc::CreateChannel(predecessor,grpc::InsecureChannelCredentials());
stub=KeyValueServices::NewStub(channel);
......
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