20 #include <aerospike/as_buffer.h>
26 #include <citrusleaf/cf_byte_order.h>
27 #include <citrusleaf/cf_digest.h>
38 #define AS_FIELD_NAMESPACE 0
39 #define AS_FIELD_SETNAME 1
40 #define AS_FIELD_KEY 2
41 #define AS_FIELD_DIGEST 4
42 #define AS_FIELD_DIGEST_ARRAY 6
43 #define AS_FIELD_TASK_ID 7
44 #define AS_FIELD_SCAN_OPTIONS 8
45 #define AS_FIELD_SCAN_TIMEOUT 9
46 #define AS_FIELD_INDEX_RANGE 22
47 #define AS_FIELD_INDEX_FILTER 23
48 #define AS_FIELD_INDEX_LIMIT 24
49 #define AS_FIELD_INDEX_ORDER 25
50 #define AS_FIELD_INDEX_TYPE 26
51 #define AS_FIELD_UDF_PACKAGE_NAME 30
52 #define AS_FIELD_UDF_FUNCTION 31
53 #define AS_FIELD_UDF_ARGLIST 32
54 #define AS_FIELD_UDF_OP 33
55 #define AS_FIELD_QUERY_BINS 40
56 #define AS_FIELD_BATCH_INDEX 41
57 #define AS_FIELD_BATCH_INDEX_WITH_SET 42
58 #define AS_FIELD_PREDEXP 43
61 #define AS_MSG_INFO1_READ (1 << 0) // contains a read operation
62 #define AS_MSG_INFO1_GET_ALL (1 << 1) // get all bins, period
64 #define AS_MSG_INFO1_BATCH_INDEX (1 << 3) // batch read
65 #define AS_MSG_INFO1_XDR (1 << 4) // operation is being performed by XDR
66 #define AS_MSG_INFO1_GET_NOBINDATA (1 << 5) // do not get information about bins and its data
67 #define AS_MSG_INFO1_CONSISTENCY_ALL (1 << 6) // read consistency level - bit 0
71 #define AS_MSG_INFO2_WRITE (1 << 0) // contains a write semantic
72 #define AS_MSG_INFO2_DELETE (1 << 1) // delete record
73 #define AS_MSG_INFO2_GENERATION (1 << 2) // pay attention to the generation
74 #define AS_MSG_INFO2_GENERATION_GT (1 << 3) // apply write if new generation >= old, good for restore
75 #define AS_MSG_INFO2_DURABLE_DELETE (1 << 4) // transaction resulting in record deletion leaves tombstone (Enterprise only).
76 #define AS_MSG_INFO2_CREATE_ONLY (1 << 5) // write record only if it doesn't exist
78 #define AS_MSG_INFO2_RESPOND_ALL_OPS (1 << 7) // return a result for every operation.
81 #define AS_MSG_INFO3_LAST (1 << 0) // this is the last of a multi-part message
82 #define AS_MSG_INFO3_COMMIT_MASTER (1 << 1) // write commit level - bit 0
84 #define AS_MSG_INFO3_UPDATE_ONLY (1 << 3) // update existing record only, do not create new record
85 #define AS_MSG_INFO3_CREATE_OR_REPLACE (1 << 4) // completely replace existing record, or create new record
86 #define AS_MSG_INFO3_REPLACE_ONLY (1 << 5) // completely replace existing record, do not create new record
87 #define AS_MSG_INFO3_LINEARIZE_READ (1 << 6) // linearize read when in CP mode.
91 #define AS_MESSAGE_VERSION 2L
92 #define AS_MESSAGE_TYPE 3L
93 #define AS_COMPRESSED_MESSAGE_TYPE 4L
96 #define AS_INFO_MESSAGE_VERSION 2L
97 #define AS_INFO_MESSAGE_TYPE 1L
100 #define AS_HEADER_SIZE 30
101 #define AS_FIELD_HEADER_SIZE 5
102 #define AS_OPERATION_HEADER_SIZE 8
104 #define AS_STACK_BUF_SIZE (1024 * 16)
115 return cf_malloc(size);
121 return cf_free(memory);
128 #define as_command_init(_sz) (_sz > AS_STACK_BUF_SIZE) ? (uint8_t*)local_malloc(_sz) : (uint8_t*)alloca(_sz)
134 #define as_command_free(_buf, _sz) if (_sz > AS_STACK_BUF_SIZE) {local_free(_buf);}
144 typedef struct as_command_node_s {
155 typedef struct as_command_parse_result_data_s {
221 size_t s = strlen(name);
248 uint32_t ttl, uint32_t timeout_ms, uint16_t
n_fields, uint16_t n_bins,
bool durable_delete);
254 static inline uint8_t*
256 bool linearize_read, uint32_t timeout_ms, uint16_t
n_fields, uint16_t n_bins)
258 uint8_t info_attr = 0;
260 if (linearize_read) {
272 memset(&cmd[12], 0, 10);
273 *(uint32_t*)&cmd[22] = cf_swap_to_be32(timeout_ms);
274 *(uint16_t*)&cmd[26] = cf_swap_to_be16(n_fields);
275 *(uint16_t*)&cmd[28] = cf_swap_to_be16(n_bins);
283 static inline uint8_t*
286 *(uint32_t*)p = cf_swap_to_be32(size+1);
296 static inline uint8_t*
313 static inline uint8_t*
317 *(uint64_t*)p = cf_swap_to_be64(val);
318 return p +
sizeof(uint64_t);
325 static inline uint8_t*
329 memcpy(p, buffer->data, buffer->size);
330 return p + buffer->size;
337 static inline uint8_t*
373 uint64_t len = end - begin;
375 *(uint64_t*)begin = cf_swap_to_be64(proto);
386 uint64_t len = end - begin;
388 *(uint64_t*)begin = cf_swap_to_be64(proto);
418 uint8_t* command,
size_t command_len,
as_parse_results_fn parse_results_fn,
void* parse_results_data,
as_status(* as_parse_results_fn)(as_error *err, as_socket *sock, as_node *node, uint32_t socket_timeout, uint64_t deadline_ms, void *user_data)
static uint8_t * as_command_write_field_uint64(uint8_t *p, uint8_t id, uint64_t val)
as_policy_consistency_level
static uint8_t * as_command_write_field_header(uint8_t *p, uint8_t id, uint32_t size)
static uint8_t * as_command_write_header_read(uint8_t *cmd, uint8_t read_attr, as_policy_consistency_level consistency, bool linearize_read, uint32_t timeout_ms, uint16_t n_fields, uint16_t n_bins)
static as_status as_command_bin_name_size(as_error *err, const char *name, size_t *size)
as_policy_replica replica
#define AS_BIN_NAME_MAX_LEN
uint8_t * as_command_write_header(uint8_t *cmd, uint8_t read_attr, uint8_t write_attr, as_policy_commit_level commit_level, as_policy_consistency_level consistency, bool linearize_read, as_policy_exists exists, as_policy_gen gen_policy, uint32_t gen, uint32_t ttl, uint32_t timeout_ms, uint16_t n_fields, uint16_t n_bins, bool durable_delete)
#define AS_OPERATION_HEADER_SIZE
static void local_free(void *memory)
static size_t as_command_string_operation_size(const char *value)
#define AS_MESSAGE_VERSION
uint8_t * as_command_write_bin_name(uint8_t *cmd, const char *name)
size_t as_command_value_size(as_val *val, as_buffer *buffer)
static size_t as_command_field_size(size_t size)
static uint8_t * as_command_write_field_digest(uint8_t *p, const as_digest *val)
as_status as_command_execute(as_cluster *cluster, as_error *err, const as_policy_base *policy, as_command_node *cn, uint8_t *command, size_t command_len, as_parse_results_fn parse_results_fn, void *parse_results_data, bool is_read)
as_status as_command_parse_result(as_error *err, as_socket *sock, as_node *node, uint32_t socket_timeout, uint64_t deadline_ms, void *user_data)
#define AS_FIELD_HEADER_SIZE
as_status as_command_parse_bins(uint8_t **pp, as_error *err, as_record *rec, uint32_t n_bins, bool deserialize)
uint8_t * as_command_write_key(uint8_t *p, as_policy_key policy, const as_key *key)
static void * local_malloc(size_t size)
uint8_t * as_command_ignore_bins(uint8_t *p, uint32_t n_bins)
uint8_t * as_command_write_bin(uint8_t *begin, as_operator op_type, const as_bin *bin, as_buffer *buffer)
as_status as_command_parse_udf_failure(uint8_t *p, as_error *err, as_msg *msg, as_status status)
#define AS_DIGEST_VALUE_SIZE
#define AS_MSG_INFO3_LINEARIZE_READ
as_status as_command_parse_success_failure(as_error *err, as_socket *sock, as_node *node, uint32_t socket_timeout, uint64_t deadline_ms, void *user_data)
#define AS_MSG_INFO1_CONSISTENCY_ALL
static uint8_t * as_command_write_field_buffer(uint8_t *p, uint8_t id, as_buffer *buffer)
uint8_t * as_command_ignore_fields(uint8_t *p, uint32_t n_fields)
static uint8_t * as_command_write_field_string(uint8_t *begin, uint8_t id, const char *val)
uint8_t * as_command_parse_key(uint8_t *p, uint32_t n_fields, as_key *key)
static size_t as_command_string_field_size(const char *value)
static size_t as_command_write_end(uint8_t *begin, uint8_t *end)
size_t as_command_compress_max_size(size_t cmd_sz)
static size_t as_command_compress_write_end(uint8_t *begin, uint8_t *end, uint64_t uncompressed_sz)
as_status as_command_parse_success_failure_bins(uint8_t **pp, as_error *err, as_msg *msg, as_val **value)
size_t as_command_key_size(as_policy_key policy, const as_key *key, uint16_t *n_fields)
#define as_error_update(__err, __code, __fmt,...)
#define AS_COMPRESSED_MESSAGE_TYPE
static size_t as_command_bin_size(const as_bin *bin, as_buffer *buffer)
as_status as_command_compress(as_error *err, uint8_t *cmd, size_t cmd_sz, uint8_t *compressed_cmd, size_t *compressed_size)
as_status as_command_parse_header(as_error *err, as_socket *sock, as_node *node, uint32_t socket_timeout, uint64_t deadline_ms, void *user_data)