Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kv-distributed
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
BHAVESHKUMAR SHYAMSUNDAR YADAV
kv-distributed
Commits
13bf066c
Commit
13bf066c
authored
Nov 25, 2019
by
AXEL JAMES
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleaned code
parent
293f6818
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
43 deletions
+5
-43
server/kvstore.c
server/kvstore.c
+5
-43
No files found.
server/kvstore.c
View file @
13bf066c
...
@@ -5,7 +5,6 @@
...
@@ -5,7 +5,6 @@
#include<unistd.h>
#include<unistd.h>
#include<stdbool.h>
#include<stdbool.h>
/////////////////add/////////////////
#define NUMFILES 10
#define NUMFILES 10
typedef
struct
Store
typedef
struct
Store
{
{
...
@@ -22,6 +21,7 @@ int getFileId(char * key){
...
@@ -22,6 +21,7 @@ int getFileId(char * key){
}
}
return
s
%
(
NUMFILES
);
return
s
%
(
NUMFILES
);
}
}
void
initStore
()
{
void
initStore
()
{
//creating locks
//creating locks
store
.
locks
=
(
pthread_mutex_t
*
)
malloc
(
NUMFILES
*
sizeof
(
pthread_mutex_t
));
store
.
locks
=
(
pthread_mutex_t
*
)
malloc
(
NUMFILES
*
sizeof
(
pthread_mutex_t
));
...
@@ -41,14 +41,11 @@ void initStore() {
...
@@ -41,14 +41,11 @@ void initStore() {
return
;
return
;
}
}
/////////////////add end/////////////////
bool
dumpToFile
(
char
*
key
,
char
*
val
){
bool
dumpToFile
(
char
*
key
,
char
*
val
){
/////////////////add/////////////////
int
setNo
=
getFileId
(
key
);
int
setNo
=
getFileId
(
key
);
printf
(
"ch1 %d"
,
setNo
);
/////////////////add end/////////////////
char
fileName
[
10
];
char
fileName
[
10
];
char
tempfileName
[
10
];
char
tempfileName
[
10
];
...
@@ -57,34 +54,16 @@ bool dumpToFile(char* key, char* val){
...
@@ -57,34 +54,16 @@ bool dumpToFile(char* key, char* val){
sprintf
(
fileName
,
"%d"
,
setNo
);
sprintf
(
fileName
,
"%d"
,
setNo
);
strcat
(
fileName
,
".csv"
);
strcat
(
fileName
,
".csv"
);
strcat
(
tempfileName
,
fileName
);
strcat
(
tempfileName
,
fileName
);
/////////////////add/////////////////
pthread_mutex_lock
(
&
(
store
.
locks
[
setNo
]));
pthread_mutex_lock
(
&
(
store
.
locks
[
setNo
]));
/////////////////add end/////////////////
FILE
*
fp
=
fopen
(
fileName
,
"r"
);
FILE
*
fp
=
fopen
(
fileName
,
"r"
);
FILE
*
newFp
=
fopen
(
tempfileName
,
"w"
);
FILE
*
newFp
=
fopen
(
tempfileName
,
"w"
);
char
*
storedKey
=
malloc
(
sizeof
(
char
)
*
257
);
char
*
storedKey
=
malloc
(
sizeof
(
char
)
*
257
);
char
*
storedVal
=
malloc
(
sizeof
(
char
)
*
256
*
1024
+
1
);
char
*
storedVal
=
malloc
(
sizeof
(
char
)
*
256
*
1024
+
1
);
// char* storedVal;
int
count
=
0
;
int
count
=
0
;
// while((getc(fp))!=EOF)
// {
// // char buff[1024];
// fgets(stored, 256*1024+1, (FILE*)fp);
// puts(stored);
// storedKey = strtok(storedVal,",");
// if(!strcmp(key,storedKey)) {
// keyExists = true;
// fprintf(newFp,"%s,%s\n",key,val);
// }
// storedVal = strtok(NULL,",");
// // count++;
// // if(count != 1)
// // {
// // // getData(buff);
// // }
// getch();
// }
if
(
fp
!=
NULL
)
if
(
fp
!=
NULL
)
{
{
/* code */
/* code */
...
@@ -111,9 +90,7 @@ bool dumpToFile(char* key, char* val){
...
@@ -111,9 +90,7 @@ bool dumpToFile(char* key, char* val){
// free(fp);
// free(fp);
rename
(
tempfileName
,
fileName
);
rename
(
tempfileName
,
fileName
);
/////////////////add/////////////////
pthread_mutex_unlock
(
&
(
store
.
locks
[
setNo
]));
pthread_mutex_unlock
(
&
(
store
.
locks
[
setNo
]));
/////////////////add end/////////////////
fclose
(
newFp
);
fclose
(
newFp
);
free
(
storedKey
);
free
(
storedKey
);
...
@@ -125,9 +102,7 @@ bool dumpToFile(char* key, char* val){
...
@@ -125,9 +102,7 @@ bool dumpToFile(char* key, char* val){
//TODO:: re-use code of add-key instead of copy-paste
//TODO:: re-use code of add-key instead of copy-paste
bool
deleteStore
(
char
*
key
)
{
bool
deleteStore
(
char
*
key
)
{
/////////////////add/////////////////
int
setNo
=
getFileId
(
key
);
int
setNo
=
getFileId
(
key
);
/////////////////add end/////////////////
char
fileName
[
10
];
char
fileName
[
10
];
char
tempfileName
[
10
];
char
tempfileName
[
10
];
...
@@ -137,9 +112,7 @@ bool deleteStore(char* key) {
...
@@ -137,9 +112,7 @@ bool deleteStore(char* key) {
strcat
(
fileName
,
".csv"
);
strcat
(
fileName
,
".csv"
);
strcat
(
tempfileName
,
fileName
);
strcat
(
tempfileName
,
fileName
);
/////////////////add/////////////////
pthread_mutex_lock
(
&
(
store
.
locks
[
setNo
]));
pthread_mutex_lock
(
&
(
store
.
locks
[
setNo
]));
/////////////////add end/////////////////
FILE
*
fp
=
fopen
(
fileName
,
"r"
);
FILE
*
fp
=
fopen
(
fileName
,
"r"
);
FILE
*
newFp
=
fopen
(
tempfileName
,
"w"
);
FILE
*
newFp
=
fopen
(
tempfileName
,
"w"
);
...
@@ -162,9 +135,7 @@ bool deleteStore(char* key) {
...
@@ -162,9 +135,7 @@ bool deleteStore(char* key) {
// free(fp);
// free(fp);
rename
(
tempfileName
,
fileName
);
rename
(
tempfileName
,
fileName
);
/////////////////add/////////////////
pthread_mutex_unlock
(
&
(
store
.
locks
[
setNo
]));
pthread_mutex_unlock
(
&
(
store
.
locks
[
setNo
]));
/////////////////add end/////////////////
fclose
(
newFp
);
fclose
(
newFp
);
free
(
storedKey
);
free
(
storedKey
);
...
@@ -257,12 +228,3 @@ int iniit() {
...
@@ -257,12 +228,3 @@ int iniit() {
return
0
;
return
0
;
}
}
// int main(){
// initStore();
// dumpToFile("sundaram111","shivam4");
// dumpToFile("sundaram112","shivam4");
// dumpToFile("key1","val");
// printf("%s\n",restoreFromFile("sundaram111"));
// deleteStore("key1");
// }
\ No newline at end of file
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