nserver

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit 51a3127d1de8903cfed7837029af223f7b58db07
parent 49edbb003a0aef0fd864e5f2a12228807618a175
Author: rsiddharth <s@ricketyspace.net>
Date:   Sat, 11 Apr 2020 12:53:53 -0400

nserver: Add ssstore.

* nserver/src/protocol.c (ssstore): New function definition.
* nserver/src/protocol.h (ssstore): New function declaration.
* nserver/tests/protocol_tests.c (test_ssstore): New test.

Diffstat:
nserver/src/protocol.c | 24++++++++++++++++++++++++
nserver/src/protocol.h | 2++
nserver/tests/protocol_tests.c | 13+++++++++++++
3 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/nserver/src/protocol.c b/nserver/src/protocol.c @@ -207,3 +207,27 @@ char *sslist() return NULL; } +int ssstore(char *key) +{ + check(key != NULL && strlen(key) > 0, "key invalid"); + check(tst != NULL, "tstree not initialized"); + + // 1. create bstring from 'key'. + Record *rec = (Record *) TSTree_search(tst, key, strlen(key)); + + check(rec != NULL, "record not found"); + check(rec->st != NULL, "stats not found for key"); + check(rec->deleted != 1, "record was deleted"); + + // 2. stringify the stats. + char *st_str = Stats_stringify(rec->st); + check(st_str != NULL, "stats stringify failed"); + + // 3. store stats in db. + int rc = db_store(key, st_str); + check(rc == 0, "db store failed"); + + return 0; + error: + return -1; +} diff --git a/nserver/src/protocol.h b/nserver/src/protocol.h @@ -4,6 +4,7 @@ #include <bstrlib.h> #include <darray.h> +#include <db.h> #include <hashmap.h> #include <stats.h> #include <tstree.h> @@ -21,6 +22,7 @@ double sssample(char *key, double s); double ssmean(char *key); char *ssdump(char *key); char *sslist(); +int ssstore(char *key); #endif diff --git a/nserver/tests/protocol_tests.c b/nserver/tests/protocol_tests.c @@ -139,6 +139,18 @@ char *test_sslist() return NULL; } +char *test_ssstore() +{ + + int rc = ssstore("/crimson"); + mu_assert(rc == 0, "store /crimson failed"); + + rc = ssstore("/nonexistent"); + mu_assert(rc == -1, "store /nonexistent failed"); + + return NULL; +} + char *test_ssdelete() { int rc = 0; @@ -164,6 +176,7 @@ char *all_tests() mu_run_test(test_ssmean); mu_run_test(test_ssdump); mu_run_test(test_sslist); + mu_run_test(test_ssstore); mu_run_test(test_ssdelete); return NULL;