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
7f1f4d66
Commit
7f1f4d66
authored
Nov 25, 2019
by
AXEL JAMES
Committed by
Bhavesh Yadav
Nov 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleaned code
parent
748bdb91
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 @
7f1f4d66
...
...
@@ -5,7 +5,6 @@
#include<unistd.h>
#include<stdbool.h>
/////////////////add/////////////////
#define NUMFILES 10
typedef
struct
Store
{
...
...
@@ -22,6 +21,7 @@ int getFileId(char * key){
}
return
s
%
(
NUMFILES
);
}
void
initStore
()
{
//creating locks
store
.
locks
=
(
pthread_mutex_t
*
)
malloc
(
NUMFILES
*
sizeof
(
pthread_mutex_t
));
...
...
@@ -41,14 +41,11 @@ void initStore() {
return
;
}
/////////////////add end/////////////////
bool
dumpToFile
(
char
*
key
,
char
*
val
){
/////////////////add/////////////////
int
setNo
=
getFileId
(
key
);
printf
(
"ch1 %d"
,
setNo
);
/////////////////add end/////////////////
char
fileName
[
10
];
char
tempfileName
[
10
];
...
...
@@ -57,34 +54,16 @@ bool dumpToFile(char* key, char* val){
sprintf
(
fileName
,
"%d"
,
setNo
);
strcat
(
fileName
,
".csv"
);
strcat
(
tempfileName
,
fileName
);
/////////////////add/////////////////
pthread_mutex_lock
(
&
(
store
.
locks
[
setNo
]));
/////////////////add end/////////////////
FILE
*
fp
=
fopen
(
fileName
,
"r"
);
FILE
*
newFp
=
fopen
(
tempfileName
,
"w"
);
char
*
storedKey
=
malloc
(
sizeof
(
char
)
*
257
);
char
*
storedVal
=
malloc
(
sizeof
(
char
)
*
256
*
1024
+
1
);
// char* storedVal;
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
)
{
/* code */
...
...
@@ -111,9 +90,7 @@ bool dumpToFile(char* key, char* val){
// free(fp);
rename
(
tempfileName
,
fileName
);
/////////////////add/////////////////
pthread_mutex_unlock
(
&
(
store
.
locks
[
setNo
]));
/////////////////add end/////////////////
fclose
(
newFp
);
free
(
storedKey
);
...
...
@@ -125,9 +102,7 @@ bool dumpToFile(char* key, char* val){
//TODO:: re-use code of add-key instead of copy-paste
bool
deleteStore
(
char
*
key
)
{
/////////////////add/////////////////
int
setNo
=
getFileId
(
key
);
/////////////////add end/////////////////
char
fileName
[
10
];
char
tempfileName
[
10
];
...
...
@@ -137,9 +112,7 @@ bool deleteStore(char* key) {
strcat
(
fileName
,
".csv"
);
strcat
(
tempfileName
,
fileName
);
/////////////////add/////////////////
pthread_mutex_lock
(
&
(
store
.
locks
[
setNo
]));
/////////////////add end/////////////////
FILE
*
fp
=
fopen
(
fileName
,
"r"
);
FILE
*
newFp
=
fopen
(
tempfileName
,
"w"
);
...
...
@@ -162,9 +135,7 @@ bool deleteStore(char* key) {
// free(fp);
rename
(
tempfileName
,
fileName
);
/////////////////add/////////////////
pthread_mutex_unlock
(
&
(
store
.
locks
[
setNo
]));
/////////////////add end/////////////////
fclose
(
newFp
);
free
(
storedKey
);
...
...
@@ -257,12 +228,3 @@ int iniit() {
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