Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
key-value-store
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
Samarth Joshi
key-value-store
Commits
5f4708dd
Commit
5f4708dd
authored
Nov 10, 2020
by
Samarth Joshi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bugfix Makefile
parent
5b79a48a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
27 deletions
+22
-27
File0.txt
File0.txt
+11
-24
KVServer.c
KVServer.c
+1
-0
Server
Server
+0
-0
StorageHandler.c
StorageHandler.c
+10
-3
No files found.
File0.txt
View file @
5f4708dd
test:tessdfs
2:asdsad
3:ssadasd
4:ssdasd
5:asdasd
6:asdasdasd
7:asdasdas
8:asdasdasd
9:asdasd
10:asdasd
11:sdsadas
12:sdasd
13:sadasd
asdasd:sadasd
3:sadasd
4:asdas
5:asda
6:sadas
7:sadasd
8:asdasd
9:sadsd
10:asdsa
11:sadds
12:dssad
1:test
2:test
3:test
4:test
5:test
6:test
7:test
8:test
9:test
10:tet
11:test
KVServer.c
View file @
5f4708dd
...
...
@@ -103,6 +103,7 @@ void *worker(void *args) {
requestMessage
->
status
=
200
;
}
else
{
status
=
file_get
(
requestMessage
->
key
,
requestMessage
->
value
);
cache_put
(
requestMessage
->
key
,
requestMessage
->
value
);
if
(
status
)
{
requestMessage
->
status
=
200
;
}
else
{
...
...
Server
View file @
5f4708dd
No preview for this file type
StorageHandler.c
View file @
5f4708dd
...
...
@@ -37,6 +37,9 @@ void file_del( char *key)
int
length
=
0
;
sem_wait
(
&
mutex
[
index
]);
char
blankspace
[
512
];
char
ch
;
int
k
=-
1
;
lseek
(
fds
[
index
],
0
,
SEEK_SET
);
memset
(
blankspace
,
0
,
512
);
char
*
line
;
char
temp
[
514
];
...
...
@@ -52,12 +55,13 @@ void file_del( char *key)
if
(
strcmp
(
key
,
fkey
)
==
0
){
lseek
(
fds
[
index
],
position
,
SEEK_SET
);
write
(
fds
[
index
],
blankspace
,
strlen
(
temp
));
puts
(
temp
);
break
;
}
position
=
ftell
(
fp
);
}
printf
(
"length %d"
,
length
);
sem_post
(
&
mutex
[
index
]);
}
...
...
@@ -66,7 +70,9 @@ int file_get(char *key, char *value)
/* Gets the value stored at offset */
/* Does not depend on key argument */
int
found
=
0
;
int
index
=
modulus
(
key
,
256
,
setSize
);
lseek
(
fds
[
index
],
0
,
SEEK_SET
);
sem_wait
(
&
readerLocks
[
index
]);
readCounters
[
index
]
+=
1
;
if
(
readCounters
[
index
]
==
1
)
...
...
@@ -103,6 +109,7 @@ off_t file_put(char *key,char *value)
if not present then search for empty line and insert there!
*/
unsigned
int
index
=
modulus
(
key
,
256
,
setSize
);
lseek
(
fds
[
index
],
0
,
SEEK_SET
);
off_t
position
;
//sem_wait(&mutex[index]);
printf
(
"[Write to File: %d]
\n
"
,
index
);
...
...
@@ -128,7 +135,7 @@ off_t file_put(char *key,char *value)
printf
(
"value:(%s)(%s)
\n
"
,
fvalue
,
value
);
fflush
(
stdout
);
fseek
(
fp
,
position
,
SEEK_SET
);
snprintf
(
lin
,
s
izeof
(
lin
)
,
"%s:%s
\n
"
,
key
,
value
);
snprintf
(
lin
,
s
trlen
(
key
)
+
strlen
(
value
)
+
2
,
"%s:%s
\n
"
,
key
,
value
);
if
(
fputs
(
lin
,
fp
)
<
0
)
printf
(
"
\n
[unable to perform file_put]
\n
"
);
return
0
;
...
...
@@ -172,5 +179,5 @@ int storage_init()
sem_init
(
&
mutex
[
i
],
0
,
1
);
readCounters
[
i
]
=
0
;
}
return
0
;
}
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