Commit 385b625f authored by Kamal Khodabhai's avatar Kamal Khodabhai

Hash function added

parent 89e24fe8
......@@ -38,6 +38,7 @@ int *worker_id;
pthread_cond_t startRpcs;
pthread_mutex_t myLock;
bool start;
int mod;
memoryManagement *memManager;
......@@ -55,6 +56,14 @@ void getConfig() {
config.close();
}
int getHash(string key) {
int hash = 0;
for(auto c : key) {
  • We can hash using SHA 1 algorithms as mentioned in chord paper Because it will inherently help with load balancing

Please register or sign in to reply
hash = (hash + c) % mod;
}
return hash;
}
class CallData {
public:
CallData(KeyValueServices::AsyncService *service, ServerCompletionQueue *cq, RequestType reqType) : service(service), cq(cq), getResponder(&context), putResponder(&context), delResponder(&context), status(CREATE), reqType(reqType) {
......@@ -79,6 +88,9 @@ public:
string v = memManager->get(&status, key.key());
pthread_mutex_unlock(&_masterLock);
//Calculate hash
// cout<<getHash(key.key())<<endl;
value.set_value(v);
if (status == 200)
value.set_status(200);
......@@ -188,6 +200,8 @@ int main(int agrc, char **argv) {
start = false;
getConfig();
mod = stoi(params.find("NUMBER_OF_KEY")->second);
int num_threads = stoi(params.find("NUM_SERVER_THREADS")->second);
int port = stoi(params.find("LISTENING_PORT")->second);
string server_address("0.0.0.0:" + to_string(port));
......
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