All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
src/main/citrusleaf/internal.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2008-2013 by Aerospike.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20  * IN THE SOFTWARE.
21  *****************************************************************************/
22 
23 #pragma once
24 
25 #include <inttypes.h>
26 #include <stdbool.h>
27 #include <netinet/in.h>
28 
29 #include <citrusleaf/cf_atomic.h>
30 #include <citrusleaf/cf_ll.h>
31 #include <citrusleaf/cf_vector.h>
32 #include <citrusleaf/cf_queue.h>
33 #include <citrusleaf/cf_digest.h>
34 #include <citrusleaf/cf_log_internal.h>
35 #include <citrusleaf/cf_proto.h>
36 
37 #include <aerospike/as_buffer.h>
38 #include <aerospike/as_string.h>
39 
40 #include <citrusleaf/citrusleaf.h>
41 #include <citrusleaf/cl_cluster.h>
42 #include <citrusleaf/cl_udf.h>
43 #include <citrusleaf/cl_scan.h>
44 
45 /******************************************************************************
46  * CONSTANTS
47  ******************************************************************************/
48 
49 #define MAX_PACKAGE_NAME_SIZE 64
50 
51 // 30-39 RESEVED FOR UDF
52 #define CL_MSG_FIELD_TYPE_UDF_FILENAME 30
53 #define CL_MSG_FIELD_TYPE_UDF_FUNCTION 31
54 #define CL_MSG_FIELD_TYPE_UDF_ARGLIST 32
55 
56 #pragma GCC diagnostic warning "-Wformat"
57 
58 #define DO_PRAGMA(x) _Pragma (#x)
59 #define TODO(x) DO_PRAGMA(message ("TODO - " x))
60 
61 /******************************************************************************
62  * TYPES
63  ******************************************************************************/
64 
65 
66 typedef struct cl_async_work cl_async_work;
67 typedef struct cl_batch_work cl_batch_work;
68 typedef struct as_call_s as_call;
69 
70 struct cl_async_work {
71  uint64_t trid; //Transaction-id of the submitted work
72  uint64_t deadline; //Deadline time for this work item
73  uint64_t starttime; //Start time for this work item
74  cl_cluster_node * node; //Node to which the work item was sent
75  int fd; //FD used to send the command asynchronously
76  void * udata;
77 };
78 
79 struct cl_batch_work {
80  // these sections are the same for the same query
81  cl_cluster * asc;
82  int info1;
83  int info2;
84  int info3;
85  char * ns;
86  cf_digest * digests;
87  cl_cluster_node ** nodes;
88  int n_digests;
89  bool get_key;
90  cl_bin * bins; // Bins. If this is used, 'operation' should be null, and 'operator' should be the operation to be used on the bins
91  cl_operator operator; // Operator. The single operator used on all the bins, if bins is non-null
92  cl_operation * operations; // Operations. Set of operations (bins + operators). Should be used if bins is not used.
93  int n_ops; // Number of operations (count of elements in 'bins' or count of elements in 'operations', depending on which is used.
95  void * udata;
96  // struct mr_state_s * mr_state;
97  cf_queue * complete_q;
98  // this is different for every work
99  cl_cluster_node * my_node;
101  int index; // debug only
102  int imatch;
103 
104 };
105 
106 struct as_call_s {
110 };
111 
112 /******************************************************************************
113  * VARIABLES
114  ******************************************************************************/
115 
116 extern shash * g_cl_async_hashtab;
117 
118 // For XDS...
119 extern cf_queue * g_cl_async_q;
120 extern cf_queue * g_cl_workitems_freepool_q;
121 
122 /******************************************************************************
123  * FUNCTIONS
124  ******************************************************************************/
125 
126 int cl_del_node_asyncworkitems(void *key, void *value, void *clnode);
127 
128 
129 // citrusleaf.c used by cl_batch
130 int cl_value_to_op_get_size(cl_bin *v, size_t *sz);
131 
132 uint8_t * cl_write_header(uint8_t *buf, size_t msg_sz, uint info1, uint info2, uint info3, uint32_t generation, uint32_t record_ttl, uint32_t transaction_ttl, uint32_t n_fields, uint32_t n_ops );
133 
134 int cl_value_to_op(cl_bin *v, cl_operator clOperator, cl_operation *operation, cl_msg_op *op);
135 
136 void cl_set_value_particular(cl_msg_op *op, cl_bin *value);
137 
138 int cl_object_get_size(cl_object *obj, size_t *sz);
139 
140 int cl_object_to_buf (cl_object *obj, uint8_t *data);
141 
142 void cl_cluster_batch_init();
144 
145 
146 int cl_do_async_monte(cl_cluster *asc, int info1, int info2, const char *ns, const char *set, const cl_object *key,
147  const cf_digest *digest, cl_bin **values, cl_operator operator, cl_operation **operations,
148  int *n_values, uint32_t *cl_gen, const cl_write_parameters *cl_w_p, uint64_t *trid, void *udata
149  );
150 
151 int do_the_full_monte(cl_cluster *asc, int info1, int info2, int info3, const char *ns, const char *set, const cl_object *key,
152  const cf_digest *digest, cl_bin **values, cl_operator operator, cl_operation **operations, int *n_values,
153  uint32_t *cl_gen, const cl_write_parameters *cl_w_p, uint64_t *trid, char **setname_r, as_call * call, uint32_t* cl_ttl
154  );
155 
156 int citrusleaf_info_host_limit(struct sockaddr_in *sa_in, char *names, char **values, int timeout_ms, bool send_asis, uint64_t max_response_length, bool check_bounds);
157 
158 int cl_compile(uint info1, uint info2, uint info3, const char *ns, const char *set, const cl_object *key, const cf_digest *digest,
159  cl_bin *values, cl_operator operator, cl_operation *operations, int n_values,
160  uint8_t **buf_r, size_t *buf_sz_r, const cl_write_parameters *cl_w_p, cf_digest *d_ret, uint64_t trid,
161  cl_scan_param_field *scan_field, as_call * as_call, uint8_t udf_type
162  );
163 
164 int cl_parse(cl_msg *msg, uint8_t *buf, size_t buf_len, cl_bin **values_r, cl_operation **operations_r,
165  int *n_values_r, uint64_t *trid, char **setname_r
166  );
167 
168 // // Get a map reduce state - the instance - based on the job description
169 // cl_mr_state * cl_mr_state_get(const cl_mr_job *mrj);
170 // void cl_mr_state_put(cl_mr_state *mrs);
171 
172 // // hand a row to the map reduce system
173 // // call with "islast" on the final bit! important!
174 // int cl_mr_state_row(cl_mr_state *mr_state, char *ns, cf_digest *keyd, char *set,
175 // uint32_t generation, uint32_t record_ttl,
176 // cl_bin *bins, int n_bins, bool islast, citrusleaf_get_many_cb cb, void *udata
177 // );
178 
179 // // All data has been done. Do finalize and any necessary callbacks
180 // int cl_mr_state_done(cl_mr_state *mr_state, citrusleaf_get_many_cb cb, void *udata);
181 
182 // int citrusleaf_mr_init(void);
183 // void citrusleaf_mr_shutdown(void);
184 
185 
186 
187 // int citrusleaf_query_init();
188 
189 // void citrusleaf_query_shutdown();
190 
191 
192 // int sproc_compile_arg_field(char * const*argk, cl_object * const*argv, int argc, uint8_t *buf, int *sz_p);
193 
194 
195 // int citrusleaf_sproc_package_get(cl_cluster *asc, const char *package, cl_script_lang_t lang);
196 
197 // int citrusleaf_sproc_package_get_with_gen(cl_cluster *asc, const char *package_name, char **content, int *content_len, char **gen, cl_script_lang_t lang_t);
198 
199 #ifdef DEBUG_VERBOSE
200 void
201 dump_buf(char *info, uint8_t *buf, size_t buf_len);
202 #endif