From aacbbb88ab9adade60b3b2c18be191add9a1c065 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Mon, 3 Feb 2020 23:23:37 -0500 Subject: nserver/src/protocol.c: Add ssample_parent. * nserver/src/protocol.c (ssample_parent): New function. --- nserver/src/protocol.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/nserver/src/protocol.c b/nserver/src/protocol.c index 0872bdb..213179a 100644 --- a/nserver/src/protocol.c +++ b/nserver/src/protocol.c @@ -74,6 +74,28 @@ int ssdelete(char *key) return -1; } +int ssample_parent(char *key, double s) +{ + check(key != NULL || strlen(key) < 1, "key invalid"); + check(tst != NULL, "tstree not initialized"); + + // 1. Try to get Record with key prefix. + Record *rec = (Record *) TSTree_search_prefix(tst, key, strlen(key)); + + if (rec == NULL) { + // No record with key prefix. + return 0; + } + check(rec->st != NULL, "record's st invalid"); + + // 2. Sample! + Stats_sample(rec->st, s); + + return 1; + error: + return -1; +} + double sssample(char *key, double s) { check(key != NULL || strlen(key) < 1, "key invalid"); -- cgit v1.2.3