summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2020-02-17 20:26:38 -0500
committerrsiddharth <s@ricketyspace.net>2020-04-17 20:56:36 -0400
commit3132ac2798d17de720a653068c968b5b4ed148e8 (patch)
treea177499c8e97b8ef69c86e56e6c69277b5432529
parent09339f341bd467f3f44458bd130c301fe7ccce4a (diff)
nserver/src/protocol.c: Updat ssdelete.
* nserver/src/protocol.c (ssdelete): Refactor to use TSTree. (hash): Remove static variable. No longer used. * nserver/tests/protocol_tests.c (all_tests): Uncomment test_ssdelete.
-rw-r--r--nserver/src/protocol.c31
-rw-r--r--nserver/tests/protocol_tests.c2
2 files changed, 12 insertions, 21 deletions
diff --git a/nserver/src/protocol.c b/nserver/src/protocol.c
index 5d72b16..648e7b7 100644
--- a/nserver/src/protocol.c
+++ b/nserver/src/protocol.c
@@ -1,6 +1,5 @@
#include <protocol.h>
-static Hashmap *hash;
static TSTree *tst;
int sscreate(char *key)
@@ -49,29 +48,21 @@ int sscreate(char *key)
int ssdelete(char *key)
{
- check(hash != NULL, "hash not initialized");
+ check(key != NULL || strlen(key) < 1, "key invalid");
+ check(tst != NULL, "tstree not initialized");
- // 1. create bstring from 'key'.
- bstring k = bfromcstr(key);
- check(k != NULL, "key creation failed");
+ Record *rec = (Record *) TSTree_search_prefix(tst, key, strlen(key));
+ if (rec == NULL) {
+ // key does not exists.
+ return 0;
+ }
- // 2. check if key exists.
- Stats *st = (Stats *) Hashmap_get(hash, k);
- if (st == NULL) {
- // key does not exists.
- return 0;
- }
+ // Mark as deleted.
+ rec->deleted = 1;
- // 3. delete key.
- st = (Stats *) Hashmap_delete(hash, k);
- check(st != NULL, "hash key delete failed");
-
- // 4. clean up the stats for this key.
- free(st);
-
- return 0;
+ return 0;
error:
- return -1;
+ return -1;
}
int sssample_parent(char *key, double s)
diff --git a/nserver/tests/protocol_tests.c b/nserver/tests/protocol_tests.c
index dbf3625..fcad96d 100644
--- a/nserver/tests/protocol_tests.c
+++ b/nserver/tests/protocol_tests.c
@@ -134,7 +134,7 @@ char *all_tests()
mu_run_test(test_ssmean);
mu_run_test(test_ssdump);
mu_run_test(test_sslist);
- /*mu_run_test(test_ssdelete);*/
+ mu_run_test(test_ssdelete);
return NULL;
}