Code

Remove (now) usued sdb_fe_exec_timeseries().
[sysdb.git] / src / frontend / query.c
index 7fcdbe2c338fb8c43f46d96ac22194c735d4b275..6015d7dd17275f27d01ef1f312321ca22d4975b9 100644 (file)
@@ -59,6 +59,43 @@ lookup_tojson(sdb_store_obj_t *obj, sdb_store_matcher_t *filter,
        return sdb_store_json_emit_full(f, obj, filter);
 } /* lookup_tojson */
 
+static int
+query_exec(sdb_conn_t *conn, sdb_ast_node_t *ast)
+{
+       sdb_store_query_t *q;
+       sdb_strbuf_t *buf;
+       int status;
+
+       q = sdb_store_query_prepare(ast);
+       if (! q) {
+               /* this shouldn't happen */
+               sdb_strbuf_sprintf(conn->errbuf, "failed to compile AST");
+               sdb_log(SDB_LOG_ERR, "frontend: failed to compile AST");
+               return -1;
+       }
+
+       buf = sdb_strbuf_create(1024);
+       if (! buf) {
+               sdb_strbuf_sprintf(conn->errbuf, "Out of memory");
+               sdb_object_deref(SDB_OBJ(q));
+               return -1;
+       }
+       status = sdb_store_query_execute(q, buf, conn->errbuf);
+       if (status < 0) {
+               char query[conn->cmd_len + 1];
+               strncpy(query, sdb_strbuf_string(conn->buf), conn->cmd_len);
+               query[sizeof(query) - 1] = '\0';
+               sdb_log(SDB_LOG_ERR, "frontend: failed to execute query '%s'", query);
+       }
+       else
+               sdb_connection_send(conn, status,
+                               (uint32_t)sdb_strbuf_len(buf), sdb_strbuf_string(buf));
+
+       sdb_strbuf_destroy(buf);
+       sdb_object_deref(SDB_OBJ(q));
+       return status < 0 ? status : 0;
+} /* query_exec */
+
 /*
  * public API
  */
@@ -68,9 +105,6 @@ sdb_fe_query(sdb_conn_t *conn)
 {
        sdb_llist_t *parsetree;
        sdb_ast_node_t *ast = NULL;
-
-       sdb_store_query_t *q;
-       sdb_strbuf_t *buf = NULL;
        int status = 0;
 
        if ((! conn) || (conn->cmd != SDB_CONNECTION_QUERY))
@@ -110,43 +144,12 @@ sdb_fe_query(sdb_conn_t *conn)
                        }
        }
 
-       q = sdb_store_query_prepare(ast);
-       if (! q) {
-               /* this shouldn't happen */
-               sdb_strbuf_sprintf(conn->errbuf, "failed to compile AST");
-               sdb_log(SDB_LOG_ERR, "frontend: failed to compile AST");
-               status = -1;
-       } else {
-               buf = sdb_strbuf_create(1024);
-               if (! buf) {
-                       sdb_strbuf_sprintf(conn->errbuf, "Out of memory");
-                       sdb_object_deref(SDB_OBJ(q));
-                       return -1;
-               }
-               status = sdb_store_query_execute(q, buf, conn->errbuf);
-               if (status < 0) {
-                       char query[conn->cmd_len + 1];
-                       strncpy(query, sdb_strbuf_string(conn->buf), conn->cmd_len);
-                       query[sizeof(query) - 1] = '\0';
-                       sdb_log(SDB_LOG_ERR, "frontend: failed to execute query '%s'", query);
-               }
+       if (ast) {
+               status = query_exec(conn, ast);
+               sdb_object_deref(SDB_OBJ(ast));
        }
-       sdb_object_deref(SDB_OBJ(ast));
        sdb_llist_destroy(parsetree);
-
-       if (status < 0) {
-               sdb_object_deref(SDB_OBJ(q));
-               sdb_strbuf_destroy(buf);
-               return status;
-       }
-
-       assert(buf);
-       sdb_connection_send(conn, status,
-                       (uint32_t)sdb_strbuf_len(buf), sdb_strbuf_string(buf));
-
-       sdb_strbuf_destroy(buf);
-       sdb_object_deref(SDB_OBJ(q));
-       return 0;
+       return status;
 } /* sdb_fe_query */
 
 int
@@ -460,38 +463,5 @@ sdb_fe_exec_lookup(sdb_conn_t *conn, int type,
        return 0;
 } /* sdb_fe_exec_lookup */
 
-int
-sdb_fe_exec_timeseries(sdb_conn_t *conn,
-               const char *hostname, const char *metric,
-               sdb_timeseries_opts_t *opts)
-{
-       sdb_strbuf_t *buf;
-       uint32_t res_type = htonl(SDB_CONNECTION_TIMESERIES);
-
-       buf = sdb_strbuf_create(1024);
-       if (! buf) {
-               char errbuf[1024];
-               sdb_log(SDB_LOG_ERR, "frontend: Failed to create "
-                               "buffer to handle TIMESERIES command: %s",
-                               sdb_strerror(errno, errbuf, sizeof(errbuf)));
-
-               sdb_strbuf_sprintf(conn->errbuf, "Out of memory");
-               return -1;
-       }
-
-       sdb_strbuf_memcpy(buf, &res_type, sizeof(uint32_t));
-       if (sdb_store_fetch_timeseries(hostname, metric, opts, buf)) {
-               sdb_log(SDB_LOG_ERR, "frontend: Failed to fetch time-series");
-               sdb_strbuf_sprintf(conn->errbuf, "Failed to fetch time-series");
-               sdb_strbuf_destroy(buf);
-               return -1;
-       }
-
-       sdb_connection_send(conn, SDB_CONNECTION_DATA,
-                       (uint32_t)sdb_strbuf_len(buf), sdb_strbuf_string(buf));
-       sdb_strbuf_destroy(buf);
-       return 0;
-} /* sdb_fe_exec_timeseries */
-
 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */