diff options
-rw-r--r-- | nserver/src/protocol.c | 31 | ||||
-rw-r--r-- | nserver/tests/protocol_tests.c | 2 |
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; } |