1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/*
* query.h - Responsible for parsing queries.
*/
#ifndef SIRIDB_QUERY_H_
#define SIRIDB_QUERY_H_
#define SIRIDB_QUERY_FLAG_MASTER 1
#define SIRIDB_QUERY_FLAG_REBUILD 2
#define SIRIDB_QUERY_FLAG_UPDATE_REPLICA 4
#define SIRIDB_QUERY_FLAG_ERR 8
/*
* Note(*) : servers must be 'accessible' unless FLAG_ONLY_CHECK_ONLINE is used
*/
typedef enum
{
SIRIDB_QUERY_FWD_SERVERS, /* Forward to all 'online' servers */
SIRIDB_QUERY_FWD_POOLS, /* Forward to all pools(*) */
SIRIDB_QUERY_FWD_SOME_POOLS, /* Forward to some pools(*) */
SIRIDB_QUERY_FWD_UPDATE /* Forward to all pools, upd repl(*) */
} siridb_query_fwd_t;
typedef enum siridb_err_tp
{
SIRIDB_SUCCESS,
/* Server Errors 100 - 199 */
SIRIDB_ERR_SHUTTINGDOWN=100,
/* Query Errors 200 - 999 */
SIRIDB_ERR_INVALID_QUERY=200
} siridb_err_t;
typedef struct siridb_query_s siridb_query_t;
#include <uv.h>
#include <inttypes.h>
#include <sys/time.h>
#include <cleri/cleri.h>
#include <qpack/qpack.h>
#include <siri/db/time.h>
#include <siri/db/nodes.h>
#include <siri/db/series.h>
#include <siri/db/db.h>
#include <siri/net/protocol.h>
#include <siri/inc.h>
#if SIRIDB_EXPR_ALLOC
#include <llist/llist.h>
#endif
void siridb_query_run(
uint16_t pid,
sirinet_stream_t * client,
const char * q,
size_t q_len,
float factor,
int flags);
void siridb_query_free(uv_handle_t * handle);
void siridb_send_query_result(uv_async_t * handle);
void siridb_query_send_error(
uv_async_t * handle,
cproto_server_t err);
void siridb_query_forward(
uv_async_t * handle,
siridb_query_fwd_t fwd,
sirinet_promises_cb cb,
int flags);
void siridb_query_timeit_from_unpacker(
siridb_query_t * query,
qp_unpacker_t * unpacker);
int siridb_query_err_from_pkg(siridb_query_t * query, sirinet_pkg_t * pkg);
struct siridb_query_s
{
uv_close_cb free_cb; /* must be on top */
uint8_t ref;
uint8_t flags;
uint16_t pid;
float factor;
void * data;
sirinet_stream_t * client;
siridb_t * siridb;
char * q;
char err_msg[SIRIDB_MAX_SIZE_ERR_MSG];
qp_packer_t * packer;
qp_packer_t * timeit;
cleri_parse_t * pr;
siridb_nodes_t * nodes;
struct timespec start;
#if SIRIDB_EXPR_ALLOC
llist_t * expr_cache;
#endif
};
#endif /* SIRIDB_QUERY_H_ */
|