Commit f5f8b956 authored by Shivaji's avatar Shivaji

Merge branch 'master' of https://git.cse.iitb.ac.in/samarthjoshi/key-value-store into lru-sample

parents ab71c925 e7b03d37
No preview for this file type
File added
File added
...@@ -148,7 +148,7 @@ int main(int argc, char const *argv[]) ...@@ -148,7 +148,7 @@ int main(int argc, char const *argv[])
int seconds = 1; int seconds = 1;
int i; int i;
if(1) { if(0) {
sock = client_init(); sock = client_init();
interactive(sock); interactive(sock);
return 0; return 0;
...@@ -167,8 +167,8 @@ int main(int argc, char const *argv[]) ...@@ -167,8 +167,8 @@ int main(int argc, char const *argv[])
} }
if(seconds%5==0) { if(seconds%5==0) {
printf("%d, %f\n", i, ((float)sum/seconds)); printf("%d, %f\n", i, ((float)sum/seconds));
//pthread_create( &seige_threads[i], NULL, seige, requestcompleted+i ); pthread_create( &seige_threads[i], NULL, seige, requestcompleted+i );
//i++; i++;
} }
if(i==max_concurrent) { if(i==max_concurrent) {
break; break;
......
...@@ -92,9 +92,9 @@ void *worker(void *args) { ...@@ -92,9 +92,9 @@ void *worker(void *args) {
if (flag & EPOLLIN) { if (flag & EPOLLIN) {
/* Parse the actual message from client */ /* Parse the actual message from client */
struct message *requestMessage= malloc(sizeof(struct message)); struct message *requestMessage= malloc(sizeof(struct message));
int readlength=read(events[i].data.fd , requestMessage, sizeof(struct message));
memset(requestMessage->key, 0, 256); memset(requestMessage->key, 0, 256);
memset(requestMessage->value, 0, 256); memset(requestMessage->value, 0, 256);
int readlength=read(events[i].data.fd , requestMessage, sizeof(struct message));
if DEBUG printf("[%s][EVENT][EPOLLIN] \n", name); if DEBUG printf("[%s][EVENT][EPOLLIN] \n", name);
switch(requestMessage->status) { switch(requestMessage->status) {
case STATUS_GET: case STATUS_GET:
...@@ -104,8 +104,8 @@ void *worker(void *args) { ...@@ -104,8 +104,8 @@ void *worker(void *args) {
requestMessage->status = 200; requestMessage->status = 200;
} else { } else {
status = file_get(requestMessage->key, requestMessage->value); status = file_get(requestMessage->key, requestMessage->value);
cache_put(requestMessage->key, requestMessage->value);
if(status) { if(status) {
cache_put(requestMessage->key, requestMessage->value);
requestMessage->status = 200; requestMessage->status = 200;
} else { } else {
requestMessage->status = 240; requestMessage->status = 240;
...@@ -150,12 +150,12 @@ int main (int argc, int argv) { ...@@ -150,12 +150,12 @@ int main (int argc, int argv) {
int i; int i;
int next_thread_to_assign = 0; int next_thread_to_assign = 0;
pthread_t *worker_threads; pthread_t *worker_threads;
int pool_thread_size = 1; // TODO: get pool thread size from config file int pool_thread_size = 50; // TODO: get pool thread size from config file
int sockfd, newsockfd, portno, clilen, n; int sockfd, newsockfd, portno, clilen, n;
struct sockaddr_in serv_addr, cli_addr; struct sockaddr_in serv_addr, cli_addr;
//int *pipes = (int*) malloc(pool_thread_size * 2 * sizeof(pipes)); //int *pipes = (int*) malloc(pool_thread_size * 2 * sizeof(pipes));
int pipes[1][2]; // TODO: initialize pipes dynamically int pipes[50][2]; // TODO: initialize pipes dynamically
worker_threads = malloc(pool_thread_size * sizeof(pthread_t)); worker_threads = malloc(pool_thread_size * sizeof(pthread_t));
for( i=0; i < pool_thread_size; i++ ) { for( i=0; i < pool_thread_size; i++ ) {
......
No preview for this file type
...@@ -24,9 +24,11 @@ int readercount = 0; ...@@ -24,9 +24,11 @@ int readercount = 0;
unsigned modulus( unsigned char *num, size_t size, unsigned divisor) { unsigned modulus( unsigned char *num, size_t size, unsigned divisor) {
unsigned rem = 0; unsigned rem = 0;
while(size>0) int i=0;
while(i<divisor)
{ {
rem+=num[size--]%divisor; rem+=num[i]%divisor;
i++;
} }
return rem%divisor; return rem%divisor;
} }
...@@ -59,13 +61,17 @@ void file_del( char *key) ...@@ -59,13 +61,17 @@ void file_del( char *key)
{ {
int offset; int offset;
int index=modulus(key,256,setSize); int index=modulus(key,256,setSize);
char fkey[256];
char fval[256];
sem_wait(&mutex[index]); sem_wait(&mutex[index]);
offset = file_search(key, NULL, index); offset = file_search(key, NULL, index);
if(offset >= 0) { if(offset >= 0) {
lseek(fds[index], offset, SEEK_SET); lseek(fds[index], offset, SEEK_SET);
write(fds[index], 0, 256); memset(fkey, 0, 256);
write(fds[index], 0, 256); memset(fval, 0, 256);
write(fds[index], fkey, 256);
write(fds[index], fval, 256);
} }
sem_post(&mutex[index]); sem_post(&mutex[index]);
......
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