From: Sebastian Harl Date: Fri, 9 Oct 2015 16:56:12 +0000 (+0200) Subject: FETCH: Add parameter for fetching the main object without children. X-Git-Tag: sysdb-0.8.0~10^2~4 X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=commitdiff_plain;h=0012c03f12422094042bc1458000ac94a38e9efe FETCH: Add parameter for fetching the main object without children. That is, exclude any attributes or child objects. Use this to simplify the TIMESERIES fetcher which no longer requires an attribute callback. --- diff --git a/src/core/memstore_exec.c b/src/core/memstore_exec.c index 802e70c..ce8f825 100644 --- a/src/core/memstore_exec.c +++ b/src/core/memstore_exec.c @@ -86,7 +86,7 @@ lookup_tojson(sdb_memstore_obj_t *obj, sdb_memstore_matcher_t *filter, static int exec_fetch(sdb_memstore_t *store, sdb_store_writer_t *w, sdb_object_t *wd, sdb_strbuf_t *errbuf, - int type, const char *hostname, const char *name, + int type, const char *hostname, const char *name, bool full, sdb_memstore_matcher_t *filter) { sdb_memstore_obj_t *host; @@ -135,7 +135,13 @@ exec_fetch(sdb_memstore_t *store, if (type != SDB_HOST) status = sdb_memstore_emit(obj->parent, w, wd); - if (status || sdb_memstore_emit_full(obj, filter, w, wd)) { + if (! status) { + if (full) + status = sdb_memstore_emit_full(obj, filter, w, wd); + else + status = sdb_memstore_emit(obj, w, wd); + } + if (status) { sdb_log(SDB_LOG_ERR, "memstore: Failed to serialize " "%s %s.%s to JSON", SDB_STORE_TYPE_TO_NAME(type), hostname, name); @@ -205,7 +211,7 @@ sdb_memstore_query_execute(sdb_memstore_t *store, sdb_memstore_query_t *q, case SDB_AST_TYPE_FETCH: return exec_fetch(store, w, wd, errbuf, SDB_AST_FETCH(ast)->obj_type, SDB_AST_FETCH(ast)->hostname, SDB_AST_FETCH(ast)->name, - q->filter); + SDB_AST_FETCH(ast)->full, q->filter); case SDB_AST_TYPE_LIST: return exec_list(store, w, wd, errbuf, SDB_AST_LIST(ast)->obj_type, diff --git a/src/frontend/query.c b/src/frontend/query.c index 9a157fb..28e1e31 100644 --- a/src/frontend/query.c +++ b/src/frontend/query.c @@ -46,8 +46,6 @@ /* * metric fetcher: * Implements the callbacks necessary to read a metric object. - * TODO: FETCH should allow to ignore child elements (attributes); then, we'd - * only need store_host/store_metric. */ typedef struct { @@ -77,15 +75,8 @@ metric_fetcher_metric(sdb_store_metric_t *metric, sdb_object_t *user_data) return 0; } /* metric_fetcher_metric */ -static int -metric_fetcher_attr(sdb_store_attribute_t __attribute__((unused)) *attr, - sdb_object_t __attribute__((unused)) *user_data) -{ - return 0; -} /* metric_fetcher_attr */ - static sdb_store_writer_t metric_fetcher = { - metric_fetcher_host, NULL, metric_fetcher_metric, metric_fetcher_attr, + metric_fetcher_host, NULL, metric_fetcher_metric, NULL, }; /* @@ -404,7 +395,7 @@ sdb_conn_fetch(sdb_conn_t *conn) ast = sdb_ast_fetch_create((int)type, hostname[0] ? strdup(hostname) : NULL, name[0] ? strdup(name) : NULL, - /* filter = */ NULL); + /* full */ 1, /* filter = */ NULL); status = exec_cmd(conn, ast); sdb_object_deref(SDB_OBJ(ast)); return status; diff --git a/src/include/parser/ast.h b/src/include/parser/ast.h index 8533fc7..0736876 100644 --- a/src/include/parser/ast.h +++ b/src/include/parser/ast.h @@ -258,11 +258,14 @@ typedef struct { int obj_type; char *hostname; /* optional */ char *name; + /* whether to include the full object, that is, + * including all attributes and all children */ + bool full; sdb_ast_node_t *filter; /* optional */ } sdb_ast_fetch_t; #define SDB_AST_FETCH(obj) ((sdb_ast_fetch_t *)(obj)) #define SDB_AST_FETCH_INIT \ - { { SDB_OBJECT_INIT, SDB_AST_TYPE_FETCH, -1 }, -1, NULL, NULL, NULL } + { { SDB_OBJECT_INIT, SDB_AST_TYPE_FETCH, -1 }, -1, NULL, NULL, 0, NULL } /* * sdb_ast_list_t represents a LIST command. @@ -384,7 +387,7 @@ sdb_ast_value_create(int type, char *name); * takes ownership of the strings and the filter node. */ sdb_ast_node_t * -sdb_ast_fetch_create(int obj_type, char *hostname, char *name, +sdb_ast_fetch_create(int obj_type, char *hostname, char *name, bool full, sdb_ast_node_t *filter); /* diff --git a/src/parser/ast.c b/src/parser/ast.c index 81a4c34..43fcd41 100644 --- a/src/parser/ast.c +++ b/src/parser/ast.c @@ -289,7 +289,7 @@ sdb_ast_value_create(int type, char *name) } /* sdb_ast_value_create */ sdb_ast_node_t * -sdb_ast_fetch_create(int obj_type, char *hostname, char *name, +sdb_ast_fetch_create(int obj_type, char *hostname, char *name, bool full, sdb_ast_node_t *filter) { sdb_ast_fetch_t *fetch; @@ -302,6 +302,7 @@ sdb_ast_fetch_create(int obj_type, char *hostname, char *name, fetch->obj_type = obj_type; fetch->hostname = hostname; fetch->name = name; + fetch->full = full; fetch->filter = filter; return SDB_AST_NODE(fetch); } /* sdb_ast_fetch_create */ diff --git a/src/parser/grammar.y b/src/parser/grammar.y index 1b6d208..b94300a 100644 --- a/src/parser/grammar.y +++ b/src/parser/grammar.y @@ -281,13 +281,13 @@ statement: fetch_statement: FETCH object_type STRING filter_clause { - $$ = sdb_ast_fetch_create($2, NULL, $3, $4); + $$ = sdb_ast_fetch_create($2, NULL, $3, 1, $4); CK_OOM($$); } | FETCH object_type STRING '.' STRING filter_clause { - $$ = sdb_ast_fetch_create($2, $3, $5, $6); + $$ = sdb_ast_fetch_create($2, $3, $5, 1, $6); CK_OOM($$); } ;