Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CS744 DECS-PA4-KEYVALUE-SERVER
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kamal Khodabhai
CS744 DECS-PA4-KEYVALUE-SERVER
Commits
e94cec16
Commit
e94cec16
authored
Nov 20, 2021
by
Mayank Manoj
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'mayank' into 'master'
Mayank See merge request
!2
parents
40295e4f
b69e736e
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
1483 additions
and
29 deletions
+1483
-29
Backend.h
Backend.h
+11
-0
CMakeLists.txt
CMakeLists.txt
+1
-1
client.cpp
client.cpp
+11
-1
dns.cpp
dns.cpp
+208
-0
keyvaluestore.proto
keyvaluestore.proto
+37
-1
server.cpp
server.cpp
+1215
-26
No files found.
Backend.h
View file @
e94cec16
...
@@ -20,6 +20,9 @@ public:
...
@@ -20,6 +20,9 @@ public:
virtual
void
pushAll
()
{
virtual
void
pushAll
()
{
return
;
return
;
}
}
virtual
string
getKeyValuePairs
(
int
id
)
{
return
"This will never run"
;
}
};
};
class
storageLRU
:
public
memoryManagement
{
class
storageLRU
:
public
memoryManagement
{
...
@@ -57,6 +60,10 @@ public:
...
@@ -57,6 +60,10 @@ public:
void
pushAll
()
{
void
pushAll
()
{
mycache
.
pushAll
();
mycache
.
pushAll
();
}
}
string
getKeyValuePairs
(
int
id
)
{
return
"keyvaluepairs"
;
}
};
};
class
storageLFU
:
public
memoryManagement
{
class
storageLFU
:
public
memoryManagement
{
...
@@ -93,4 +100,8 @@ public:
...
@@ -93,4 +100,8 @@ public:
void
pushAll
()
{
void
pushAll
()
{
mycache
.
pushAll
();
mycache
.
pushAll
();
}
}
string
getKeyValuePairs
(
int
id
)
{
return
"keyvaluepairs"
;
}
};
};
\ No newline at end of file
CMakeLists.txt
View file @
e94cec16
...
@@ -42,7 +42,7 @@ include_directories("${CMAKE_CURRENT_BINARY_DIR}")
...
@@ -42,7 +42,7 @@ include_directories("${CMAKE_CURRENT_BINARY_DIR}")
# Targets (client|server)
# Targets (client|server)
foreach
(
_target
foreach
(
_target
client client_test server
)
client client_test server
dns
)
add_executable
(
${
_target
}
"
${
_target
}
.cpp"
add_executable
(
${
_target
}
"
${
_target
}
.cpp"
${
hw_proto_srcs
}
${
hw_proto_srcs
}
${
hw_grpc_srcs
}
)
${
hw_grpc_srcs
}
)
...
...
client.cpp
View file @
e94cec16
...
@@ -13,6 +13,8 @@ using keyvaluestore::Value;
...
@@ -13,6 +13,8 @@ using keyvaluestore::Value;
using
keyvaluestore
::
KeyValue
;
using
keyvaluestore
::
KeyValue
;
using
keyvaluestore
::
ReqStatus
;
using
keyvaluestore
::
ReqStatus
;
using
keyvaluestore
::
KeyValueServices
;
using
keyvaluestore
::
KeyValueServices
;
using
keyvaluestore
::
Info
;
using
keyvaluestore
::
Null
;
std
::
map
<
std
::
string
,
std
::
string
>
params
;
std
::
map
<
std
::
string
,
std
::
string
>
params
;
std
::
string
config_filename
=
"../config"
;
std
::
string
config_filename
=
"../config"
;
...
@@ -150,7 +152,15 @@ void parse(std::string& str, std::string& cmd, std::string& key, std::string& va
...
@@ -150,7 +152,15 @@ void parse(std::string& str, std::string& cmd, std::string& key, std::string& va
}
}
void
RunClient
()
{
void
RunClient
()
{
std
::
string
target_address
(
"0.0.0.0:"
+
params
.
find
(
"LISTENING_PORT"
)
->
second
);
std
::
string
dns_address
(
"0.0.0.0:1234"
);
std
::
shared_ptr
<
Channel
>
channel
=
grpc
::
CreateChannel
(
dns_address
,
grpc
::
InsecureChannelCredentials
());
std
::
unique_ptr
<
KeyValueServices
::
Stub
>
stub
=
KeyValueServices
::
NewStub
(
channel
);
Null
null
;
null
.
set_nothing
(
0
);
Info
info
;
ClientContext
context
;
Status
status
=
stub
->
GETADDRESS
(
&
context
,
null
,
&
info
);
std
::
string
target_address
(
info
.
address
());
// Instantiates the client
// Instantiates the client
KeyValueServicesClient
client
(
KeyValueServicesClient
client
(
// Channel from which RPCs are made - endpoint is the target_address
// Channel from which RPCs are made - endpoint is the target_address
...
...
dns.cpp
0 → 100644
View file @
e94cec16
#include <bits/stdc++.h>
#include <grpcpp/grpcpp.h>
#include<fstream>
#include "keyvaluestore.grpc.pb.h"
#define SERVERS "serverlist.txt"
using
namespace
std
;
using
grpc
::
Server
;
using
grpc
::
ServerAsyncResponseWriter
;
using
grpc
::
ServerBuilder
;
using
grpc
::
ServerCompletionQueue
;
using
grpc
::
ServerContext
;
using
grpc
::
Status
;
using
grpc
::
Channel
;
using
grpc
::
ClientContext
;
using
keyvaluestore
::
KeyValueServices
;
using
keyvaluestore
::
Info
;
using
keyvaluestore
::
Null
;
using
keyvaluestore
::
Addresses
;
ServerBuilder
builder
;
KeyValueServices
::
AsyncService
service
;
std
::
unique_ptr
<
Server
>
server
;
enum
RequestType
{
GETADDRESS
,
ADDADDRESS
,
UPDATEFINGERTABLES
,
GETSERVERS
};
class
DNSData
{
public:
DNSData
(
KeyValueServices
::
AsyncService
*
service
,
ServerCompletionQueue
*
cq
,
RequestType
reqType
)
:
service
(
service
),
cq
(
cq
),
getAddressResponder
(
&
context
),
addAddressResponder
(
&
context
),
updateFingerTablesResponder
(
&
context
),
getServersResponder
(
&
context
),
status
(
CREATE
),
reqType
(
reqType
)
{
Proceed
();
}
void
Proceed
()
{
if
(
status
==
CREATE
)
{
status
=
PROCESS
;
if
(
reqType
==
GETADDRESS
)
service
->
RequestGETADDRESS
(
&
context
,
&
null
,
&
getAddressResponder
,
cq
,
cq
,
this
);
else
if
(
reqType
==
ADDADDRESS
)
service
->
RequestADDADDRESS
(
&
context
,
&
info
,
&
addAddressResponder
,
cq
,
cq
,
this
);
else
if
(
reqType
==
UPDATEFINGERTABLES
)
service
->
RequestUPDATEFINGERTABLES
(
&
context
,
&
null
,
&
updateFingerTablesResponder
,
cq
,
cq
,
this
);
else
service
->
RequestGETSERVERS
(
&
context
,
&
null
,
&
getServersResponder
,
cq
,
cq
,
this
);
}
else
if
(
status
==
PROCESS
)
{
new
DNSData
(
service
,
cq
,
reqType
);
if
(
reqType
==
GETADDRESS
)
{
ifstream
fin
;
int
size
=
0
;
map
<
int
,
string
>
servers
;
fin
.
open
(
SERVERS
);
do
{
string
temp
;
getline
(
fin
,
temp
);
if
(
temp
.
size
()
==
0
)
break
;
servers
[
size
++
]
=
temp
;
}
while
(
fin
);
fin
.
close
();
if
(
size
==
0
)
info
.
set_address
(
"null"
);
else
{
int
x
=
rand
()
%
size
;
info
.
set_address
(
servers
.
find
(
x
)
->
second
);
}
getAddressResponder
.
Finish
(
info
,
Status
::
OK
,
this
);
}
else
if
(
reqType
==
ADDADDRESS
){
ifstream
fin
;
fin
.
open
(
SERVERS
);
int
size
=
0
;
map
<
int
,
string
>
svs
;
do
{
string
temp
;
getline
(
fin
,
temp
);
if
(
temp
.
size
()
==
0
)
break
;
svs
[
size
++
]
=
temp
;
}
while
(
fin
);
fin
.
close
();
string
addresses
[
size
+
1
];
int
count
=
0
;
string
addtoadd
=
info
.
address
();
int
porttoadd
=
stoi
(
addtoadd
.
substr
(
addtoadd
.
find
(
':'
)
+
1
));
bool
flag
=
false
;
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
int
curr_port
=
stoi
(
svs
[
i
].
substr
(
svs
[
i
].
find
(
':'
)
+
1
));
if
(
porttoadd
<
curr_port
&&
flag
==
false
)
{
addresses
[
count
++
]
=
addtoadd
;
flag
=
true
;
}
addresses
[
count
++
]
=
svs
[
i
];
}
if
(
flag
==
false
)
addresses
[
count
++
]
=
addtoadd
;
ofstream
fout
;
fout
.
open
(
SERVERS
);
for
(
int
i
=
0
;
i
<
count
;
i
++
)
fout
<<
addresses
[
i
]
<<
endl
;
fout
.
close
();
null
.
set_nothing
(
0
);
cout
<<
info
.
address
()
<<
endl
;
addAddressResponder
.
Finish
(
null
,
Status
::
OK
,
this
);
}
else
if
(
reqType
==
UPDATEFINGERTABLES
){
ifstream
fin
;
int
index
=
0
;
map
<
int
,
string
>
servers
;
fin
.
open
(
SERVERS
);
do
{
string
temp
;
getline
(
fin
,
temp
);
if
(
temp
.
size
()
==
0
)
break
;
servers
[
index
++
]
=
temp
;
}
while
(
fin
);
fin
.
close
();
string
addressarr
=
""
;
for
(
int
i
=
0
;
i
<
index
;
i
++
)
addressarr
+=
servers
[
i
]
+
";"
;
for
(
int
i
=
0
;
i
<
index
;
i
++
)
{
string
target_address
(
servers
[
i
]);
shared_ptr
<
Channel
>
channel
=
grpc
::
CreateChannel
(
target_address
,
grpc
::
InsecureChannelCredentials
());
unique_ptr
<
KeyValueServices
::
Stub
>
stub
;
stub
=
KeyValueServices
::
NewStub
(
channel
);
Null
null
;
ClientContext
cont
;
Addresses
addr
;
addr
.
set_addresses
(
addressarr
);
addr
.
set_servers
(
index
);
stub
->
UPDATETABLE
(
&
cont
,
addr
,
&
null
);
}
updateFingerTablesResponder
.
Finish
(
null
,
Status
::
OK
,
this
);
}
else
{
ifstream
fin
;
int
index
=
0
;
map
<
int
,
string
>
servers
;
fin
.
open
(
SERVERS
);
do
{
string
temp
;
getline
(
fin
,
temp
);
if
(
temp
.
size
()
==
0
)
break
;
servers
[
index
++
]
=
temp
;
}
while
(
fin
);
fin
.
close
();
string
addressarr
=
""
;
for
(
int
i
=
0
;
i
<
index
;
i
++
)
addressarr
+=
servers
[
i
]
+
";"
;
addr1
.
set_addresses
(
addressarr
);
addr1
.
set_servers
(
index
);
getServersResponder
.
Finish
(
addr1
,
Status
::
OK
,
this
);
}
status
=
FINISH
;
}
else
{
GPR_ASSERT
(
status
==
FINISH
);
delete
this
;
}
}
private:
KeyValueServices
::
AsyncService
*
service
;
ServerCompletionQueue
*
cq
;
ServerContext
context
;
Null
null
;
Info
info
;
Addresses
addr1
;
ServerAsyncResponseWriter
<
Info
>
getAddressResponder
;
ServerAsyncResponseWriter
<
Null
>
addAddressResponder
;
ServerAsyncResponseWriter
<
Null
>
updateFingerTablesResponder
;
ServerAsyncResponseWriter
<
Addresses
>
getServersResponder
;
enum
CallStatus
{
CREATE
,
PROCESS
,
FINISH
};
CallStatus
status
;
RequestType
reqType
;
};
int
main
(
int
argc
,
char
**
argv
)
{
srand
(
time
(
0
));
string
server_address
(
"0.0.0.0:1234"
);
builder
.
AddListeningPort
(
server_address
,
grpc
::
InsecureServerCredentials
());
builder
.
RegisterService
(
&
service
);
unique_ptr
<
ServerCompletionQueue
>
comp_queue
=
builder
.
AddCompletionQueue
();
server
=
builder
.
BuildAndStart
();
cout
<<
"DNS SERVER COMES UP SUCCESSFULLY"
<<
endl
;
new
DNSData
(
&
service
,
comp_queue
.
get
(),
GETADDRESS
);
new
DNSData
(
&
service
,
comp_queue
.
get
(),
ADDADDRESS
);
new
DNSData
(
&
service
,
comp_queue
.
get
(),
UPDATEFINGERTABLES
);
new
DNSData
(
&
service
,
comp_queue
.
get
(),
GETSERVERS
);
void
*
tag
;
bool
ok
;
while
(
true
)
{
GPR_ASSERT
(
comp_queue
->
Next
(
&
tag
,
&
ok
));
GPR_ASSERT
(
ok
);
static_cast
<
DNSData
*>
(
tag
)
->
Proceed
();
}
}
\ No newline at end of file
keyvaluestore.proto
View file @
e94cec16
...
@@ -8,9 +8,18 @@ service KeyValueServices {
...
@@ -8,9 +8,18 @@ service KeyValueServices {
rpc
GET
(
Key
)
returns
(
Value
)
{}
rpc
GET
(
Key
)
returns
(
Value
)
{}
rpc
PUT
(
KeyValue
)
returns
(
ReqStatus
)
{}
rpc
PUT
(
KeyValue
)
returns
(
ReqStatus
)
{}
rpc
DEL
(
Key
)
returns
(
ReqStatus
)
{}
rpc
DEL
(
Key
)
returns
(
ReqStatus
)
{}
rpc
NEW
(
Info
)
returns
(
SuccessorInfo
)
{}
rpc
INFORMSUCCESSOR
(
Info
)
returns
(
KeyValues
)
{}
rpc
INFORMPREDECESSOR
(
Info
)
returns
(
Null
)
{}
rpc
GETADDRESS
(
Null
)
returns
(
Info
)
{}
rpc
ADDADDRESS
(
Info
)
returns
(
Null
)
{}
rpc
UPDATEFINGERTABLES
(
Null
)
returns
(
Null
)
{}
rpc
GETSUCCESSOR
(
Id
)
returns
(
Id
)
{}
rpc
GETPREDECESSOR
(
Id
)
returns
(
Id
)
{}
rpc
UPDATETABLE
(
Addresses
)
returns
(
Null
)
{}
rpc
GETSERVERS
(
Null
)
returns
(
Addresses
)
{}
}
}
message
Key
{
message
Key
{
string
key
=
1
;
string
key
=
1
;
}
}
...
@@ -30,3 +39,30 @@ message ReqStatus {
...
@@ -30,3 +39,30 @@ message ReqStatus {
int32
status
=
1
;
int32
status
=
1
;
string
error
=
2
;
string
error
=
2
;
}
}
message
Info
{
string
address
=
1
;
}
message
SuccessorInfo
{
string
succaddress
=
1
;
string
predaddress
=
2
;
}
message
KeyValues
{
string
keys
=
1
;
string
values
=
2
;
}
message
Null
{
int32
nothing
=
1
;
}
message
Id
{
int64
id
=
1
;
}
message
Addresses
{
string
addresses
=
1
;
int64
servers
=
2
;
}
\ No newline at end of file
server.cpp
View file @
e94cec16
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment