Commit 0834a3d7 authored by ajinkyatanksale's avatar ajinkyatanksale

Initial Commit of PA4 code

parent 7d269e06
# Copyright 2018 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# cmake build file for C++ helloworld example.
# Assumes protobuf and gRPC have been installed using cmake.
# See cmake_externalproject/CMakeLists.txt for all-in-one cmake build
# that automatically builds all the dependencies before building helloworld.
cmake_minimum_required(VERSION 3.5.1)
project(keyvaluestore C CXX)
include(../cmake/common.cmake)
# Proto file
get_filename_component(hw_proto "keyvaluestore.proto" ABSOLUTE)
get_filename_component(hw_proto_path "${hw_proto}" PATH)
# Generated sources
set(hw_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/keyvaluestore.pb.cc")
set(hw_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/keyvaluestore.pb.h")
set(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/keyvaluestore.grpc.pb.cc")
set(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/keyvaluestore.grpc.pb.h")
add_custom_command(
OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}"
COMMAND ${_PROTOBUF_PROTOC}
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
-I "${hw_proto_path}"
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
"${hw_proto}"
DEPENDS "${hw_proto}")
# Include generated *.pb.h files
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
# hw_grpc_proto
add_library(hw_grpc_proto
${hw_grpc_srcs}
${hw_grpc_hdrs}
${hw_proto_srcs}
${hw_proto_hdrs})
target_link_libraries(hw_grpc_proto
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF})
# route_guide_helper
add_library(MyCache_
"MyCache.h"
"MyCache.cpp")
add_library(configReader_
"configReader.h"
"configReader.cc")
add_library(storage_
"storage.h"
"storage.cc")
# route_guide_helper
# add_library(LFUCache
# "LFUCache.h"
# "LFUCache.cpp")
# Targets greeter_[async_](client|server)
foreach(_target
server client)
add_executable(${_target} "${_target}.cc")
target_link_libraries(${_target}
hw_grpc_proto
MyCache_
storage_
configReader_
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF})
endforeach()
This diff is collapsed.
#include <iostream>
#include <string>
#include "configReader.h"
#include "storage.h"
#define Cache_LFU 1
#define Cache_LRU 2
class MyCache {
std::string key;
std::string value;
int freq;
int isUpdated;
public:
MyCache(std::string, std::string, int, int);
MyCache(std::string, std::string, int);
std::string get_key();
std::string get_value();
int get_freq();
int get_isUpdated();
void set_value(std::string);
void set_freq(int);
void set_isUpdated(int);
};
void setCacheSize(int size);
std::string getCache(std::string key,int cacheType,Persistant * obj);
void putCache(std::string key, std::string value,int cacheType,Persistant *obj);
std::string delCache(std::string key,int cacheType,Persistant*obj);
void init_cache();
void cacheFill();
\ No newline at end of file
PUT k1 v1
PUT k2 v2
PUT k3 v3
PUT k4 v4
PUT k34 v1
PUT k12 v1
PUT k23 v2
PUT k31 v3
PUT k43 v4
PUT k34 v1
PUT k13 v1
PUT k24 v2
PUT k35 v3
PUT k46 v4
PUT k34 v1
This diff is collapsed.
LISTENING_PORT=50051
CACHE_REPLACEMENT_TYPE=LRU
CACHE_SIZE=10
THREAD_POOL_SIZE=10
\ No newline at end of file
#include <iostream>
#include <memory>
#include <fstream>
#include <sstream>
#include <string>
#include <thread>
#include <vector>
#include "MyCache.h"
std::vector<std::string> parser_1(std::string request) {
std::vector<std::string> tokens{};
std::stringstream stream1(request);
std::string intermediate;
while(getline(stream1, intermediate, '=')) {
tokens.push_back(intermediate);
}
return tokens;
}
configReader::configReader(){
LISTENING_PORT = 50051;
CACHE_REPLACEMENT_TYPE ="LRU";
CACHE_SIZE=10;
THREAD_POOL_SIZE=10;
}
int configReader::readConfigFile(std::string filename){
std::string myText;
std::ifstream MyReadFile;
MyReadFile.open(filename);
if(MyReadFile.is_open())
{
while (getline(MyReadFile, myText)) {
std::vector<std::string> tokens = parser_1(myText);
if(tokens[0]=="LISTENING_PORT")
LISTENING_PORT=atoi(tokens[1].c_str());
else if(tokens[0]=="CACHE_REPLACEMENT_TYPE")
CACHE_REPLACEMENT_TYPE=tokens[1];
else if (tokens[0]=="CACHE_SIZE"){
CACHE_SIZE = atoi(tokens[1].c_str());
// if(CACHE_SIZE > 100)
// CACHE_SIZE = 100;
}
else if(tokens[0]=="THREAD_POOL_SIZE"){
THREAD_POOL_SIZE= atoi(tokens[1].c_str());
// if(THREAD_POOL_SIZE > 50){
// THREAD_POOL_SIZE = 50;
// }
}
}
}
else{
return -1;
}
return 0;
}
int configReader::getListeningPort(){
return this->LISTENING_PORT;
}
int configReader::getCacheReplacementType(){
if(CACHE_REPLACEMENT_TYPE.compare("LFU")==0)
return Cache_LFU;
if(CACHE_REPLACEMENT_TYPE.compare("LRU")==0)
return Cache_LRU;
return -1;
}
int configReader::getCacheSize(){
return this->CACHE_SIZE;
}
size_t configReader::getThreadPoolSize(){
return this->THREAD_POOL_SIZE;
}
\ No newline at end of file
#include <iostream>
#include <string>
class configReader{
private:
int LISTENING_PORT;
std::string CACHE_REPLACEMENT_TYPE;
int CACHE_SIZE;
size_t THREAD_POOL_SIZE;
public:
configReader();
int readConfigFile(std::string filename);
int getListeningPort();
int getCacheReplacementType();
int getCacheSize();
size_t getThreadPoolSize();
};
\ No newline at end of file
syntax = "proto3";
package keyvaluestore;
// A simple key-value storage service
service storeManager {
// Provides a value for each key request
rpc GET ( requestKey) returns ( responseValue) {}
rpc DEL ( requestKey) returns ( responseValue) {}
rpc PUT ( requestKeyValue) returns ( responseStatus) {}
}
enum statusValue{
DEAULT = 0;
UPDATED = 100;
SUCCESS = 200;
FAILURE = 400;
}
// The request message containing the key
message requestKey {
string key = 1;
}
// The response message containing the value associated with the key
message responseValue {
statusValue status = 1;
string value = 2;
}
message requestKeyValue {
string key = 1;
string value = 2;
}
message responseStatus{
statusValue status = 1;
}
\ No newline at end of file
Team Information:
Arnav Mishra : 213059002
Ajinkya Tanksale : 213050034
Vedant Singh : 213050038
Steps to build and run the server and client
1) Put the folder in grpc/examples/cpp
2) cd KeyValueStore
3) mkdir -p cmake/build
4) pushd cmake/build
5) cmake -DCMAKE_PREFIX_PATH=$MY_INSTALL_DIR ../..
6) make
7) Open two terminals and write commands
./server in first and ./client in second
8) For exiting server press (clt+c) 2 time.
This diff is collapsed.
This diff is collapsed.
#include <iostream>
#include <string>
#include <vector>
#define NUM_CHAR 8
#define MAX_SIZE 256
#define NUM_FILES MAX_SIZE / NUM_CHAR
static std::string SuccessMessage = "KEY DELETED";
static std::string ErrorMessage = "KEY NOT EXIST";
static std::string PutMessage = "KEY INSERTED";
static std::string UpdateMessage = "KEY UPDATED";
class Persistant {
private:
std::fstream desc[NUM_FILES];
public:
Persistant();
~Persistant();
std::string get_padded_value(int init_size , std::string value);
std::vector<std::string> parser(std::string line);
std::string get_value(std::string key);
std::string put_value(std::string key, std::string value);
std::string delete_value(std::string key);
};
void init_storage();
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