27 #include <citrusleaf/cf_byte_order.h>
38 #define AS_COMMAND_FLAGS_READ 1
39 #define AS_COMMAND_FLAGS_BATCH 2
40 #define AS_COMMAND_FLAGS_LINEARIZE 4
41 #define AS_COMMAND_FLAGS_SPLIT_RETRY 8
44 #define AS_FIELD_NAMESPACE 0
45 #define AS_FIELD_SETNAME 1
46 #define AS_FIELD_KEY 2
47 #define AS_FIELD_DIGEST 4
48 #define AS_FIELD_TASK_ID 7
49 #define AS_FIELD_SOCKET_TIMEOUT 9
50 #define AS_FIELD_RPS 10
51 #define AS_FIELD_PID_ARRAY 11
52 #define AS_FIELD_DIGEST_ARRAY 12
53 #define AS_FIELD_MAX_RECORDS 13
54 #define AS_FIELD_BVAL_ARRAY 15
55 #define AS_FIELD_INDEX_RANGE 22
56 #define AS_FIELD_INDEX_CONTEXT 23
57 #define AS_FIELD_INDEX_TYPE 26
58 #define AS_FIELD_UDF_PACKAGE_NAME 30
59 #define AS_FIELD_UDF_FUNCTION 31
60 #define AS_FIELD_UDF_ARGLIST 32
61 #define AS_FIELD_UDF_OP 33
62 #define AS_FIELD_QUERY_BINS 40
63 #define AS_FIELD_BATCH_INDEX 41
64 #define AS_FIELD_FILTER 43
67 #define AS_MSG_INFO1_READ (1 << 0) // contains a read operation
68 #define AS_MSG_INFO1_GET_ALL (1 << 1) // get all bins, period
69 #define AS_MSG_INFO1_SHORT_QUERY (1 << 2) // short query
70 #define AS_MSG_INFO1_BATCH_INDEX (1 << 3) // batch
71 #define AS_MSG_INFO1_XDR (1 << 4) // operation is being performed by XDR
72 #define AS_MSG_INFO1_GET_NOBINDATA (1 << 5) // do not get information about bins and its data
73 #define AS_MSG_INFO1_READ_MODE_AP_ALL (1 << 6) // read mode all for AP namespaces.
74 #define AS_MSG_INFO1_COMPRESS_RESPONSE (1 << 7) // tell server to compress it's response.
77 #define AS_MSG_INFO2_WRITE (1 << 0) // contains a write semantic
78 #define AS_MSG_INFO2_DELETE (1 << 1) // delete record
79 #define AS_MSG_INFO2_GENERATION (1 << 2) // pay attention to the generation
80 #define AS_MSG_INFO2_GENERATION_GT (1 << 3) // apply write if new generation >= old, good for restore
81 #define AS_MSG_INFO2_DURABLE_DELETE (1 << 4) // transaction resulting in record deletion leaves tombstone (Enterprise only).
82 #define AS_MSG_INFO2_CREATE_ONLY (1 << 5) // write record only if it doesn't exist
84 #define AS_MSG_INFO2_RESPOND_ALL_OPS (1 << 7) // return a result for every operation.
87 #define AS_MSG_INFO3_LAST (1 << 0) // this is the last of a multi-part message
88 #define AS_MSG_INFO3_COMMIT_MASTER (1 << 1) // write commit level - bit 0
91 #define AS_MSG_INFO3_PARTITION_DONE (1 << 2)
92 #define AS_MSG_INFO3_UPDATE_ONLY (1 << 3) // update existing record only, do not create new record
93 #define AS_MSG_INFO3_CREATE_OR_REPLACE (1 << 4) // completely replace existing record, or create new record
94 #define AS_MSG_INFO3_REPLACE_ONLY (1 << 5) // completely replace existing record, do not create new record
95 #define AS_MSG_INFO3_SC_READ_TYPE (1 << 6) // see below
96 #define AS_MSG_INFO3_SC_READ_RELAX (1 << 7) // see below
111 #define AS_HEADER_SIZE 30
112 #define AS_FIELD_HEADER_SIZE 5
113 #define AS_OPERATION_HEADER_SIZE 8
115 #define AS_STACK_BUF_SIZE (1024 * 16)
116 #define AS_COMPRESS_THRESHOLD 128
126 return cf_malloc(size);
139 #define as_command_buffer_init(_sz) (_sz > AS_STACK_BUF_SIZE) ? (uint8_t*)local_malloc(_sz) : (uint8_t*)alloca(_sz)
145 #define as_command_buffer_free(_buf, _sz) if (_sz > AS_STACK_BUF_SIZE) {local_free(_buf);}
164 as_error* err,
struct as_command_s* cmd,
as_node* node, uint8_t* buf,
size_t size
171 typedef struct as_command_s {
199 typedef struct as_command_parse_result_data_s {
271 size_t s = strlen(name);
297 uint8_t* read_attr, uint8_t* info_attr
300 switch (read_mode_sc) {
342 uint8_t* read_attr, uint8_t* info_attr
357 uint16_t
n_fields, uint16_t n_bins,
bool durable_delete, uint8_t read_attr, uint8_t write_attr,
369 uint8_t read_attr, uint8_t info_attr
386 static inline uint8_t*
389 *(uint32_t*)p = cf_swap_to_be32(size+1);
399 static inline uint8_t*
416 static inline uint8_t*
420 *(uint32_t*)p = cf_swap_to_be32(val);
421 return p +
sizeof(uint32_t);
428 static inline uint8_t*
432 *(uint64_t*)p = cf_swap_to_be64(val);
433 return p +
sizeof(uint64_t);
440 static inline uint8_t*
444 memcpy(p, buffer->
data, buffer->
size);
445 return p + buffer->
size;
452 static inline uint8_t*
497 uint64_t len = end - begin;
499 *(uint64_t*)begin = cf_swap_to_be64(proto);
510 uint64_t len = end - begin;
512 *(uint64_t*)begin = cf_swap_to_be64(proto);
513 ((as_compressed_proto *)begin)->uncompressed_sz = cf_swap_to_be64(uncompressed_sz);
535 static inline uint32_t
653 static inline uint64_t
660 if (*task_id_ptr == 0) {
677 static inline uint8_t
size_t(* as_write_fn)(void *udata, uint8_t *buf)
static void as_buffers_destroy(as_queue *buffers)
as_status as_command_execute(as_command *cmd, as_error *err)
uint8_t * as_command_write_user_key(uint8_t *begin, const as_key *key)
#define AS_MSG_INFO3_SC_READ_RELAX
static uint8_t * as_command_write_field_uint64(uint8_t *p, uint8_t id, uint64_t val)
as_status as_command_send(as_command *cmd, as_error *err, uint32_t comp_threshold, as_write_fn write_fn, void *udata)
static uint8_t * as_command_write_field_header(uint8_t *p, uint8_t id, uint32_t size)
uint8_t * as_command_write_bin(uint8_t *begin, as_operator operation_type, const as_bin *bin, as_queue *buffers)
static as_status as_command_bin_name_size(as_error *err, const char *name, size_t *size)
#define AS_BIN_NAME_MAX_LEN
#define AS_OPERATION_HEADER_SIZE
static void local_free(void *memory)
static size_t as_command_string_operation_size(const char *value)
#define AS_MSG_INFO3_SC_READ_TYPE
static void as_command_set_attr_compress(bool compress, uint8_t *read_attr)
uint8_t * as_command_write_bin_name(uint8_t *cmd, const char *name)
uint8_t * as_command_write_header_read_header(uint8_t *cmd, const as_policy_base *policy, as_policy_read_mode_ap read_mode_ap, as_policy_read_mode_sc read_mode_sc, uint16_t n_fields, uint16_t n_bins, uint8_t read_attr)
static size_t as_command_field_size(size_t size)
uint8_t * as_command_write_header_read(uint8_t *cmd, const as_policy_base *policy, as_policy_read_mode_ap read_mode_ap, as_policy_read_mode_sc read_mode_sc, uint32_t timeout, uint16_t n_fields, uint16_t n_bins, uint8_t read_attr, uint8_t info_attr)
const as_policy_base * policy
static uint8_t * as_command_write_field_digest(uint8_t *p, const as_digest *val)
static as_policy_replica as_command_write_replica(as_policy_replica replica)
#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)
#define AS_MSG_INFO1_COMPRESS_RESPONSE
uint8_t * as_command_write_header_write(uint8_t *cmd, const as_policy_base *policy, as_policy_commit_level commit_level, as_policy_exists exists, as_policy_gen gen_policy, uint32_t gen, uint32_t ttl, uint16_t n_fields, uint16_t n_bins, bool durable_delete, uint8_t read_attr, uint8_t write_attr, uint8_t info_attr)
uint8_t * as_command_write_key(uint8_t *p, as_policy_key policy, const as_key *key)
as_status as_command_parse_result(as_error *err, as_command *cmd, as_node *node, uint8_t *buf, size_t size)
static bool as_queue_pop(as_queue *queue, void *ptr)
size_t as_command_user_key_size(const as_key *key)
static uint32_t as_command_server_timeout(const as_policy_base *policy)
static void as_command_set_attr_read_header(as_policy_read_mode_ap read_mode_ap, as_policy_read_mode_sc read_mode_sc, uint8_t *read_attr, uint8_t *info_attr)
static void * local_malloc(size_t size)
uint8_t * as_command_ignore_bins(uint8_t *p, uint32_t n_bins)
as_status as_command_parse_udf_failure(uint8_t *p, as_error *err, as_msg *msg, as_status status)
#define AS_DIGEST_VALUE_SIZE
as_parse_results_fn parse_results_fn
as_policy_replica replica
static uint8_t as_replica_index_init_read(as_policy_replica replica)
as_status as_command_parse_success_failure(as_error *err, as_command *cmd, as_node *node, uint8_t *buf, size_t size)
static uint8_t * as_command_write_field_uint32(uint8_t *p, uint8_t id, uint32_t val)
static uint8_t * as_command_write_field_buffer(uint8_t *p, uint8_t id, as_buffer *buffer)
#define AS_COMPRESSED_MESSAGE_TYPE
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)
static size_t as_command_string_field_size(const char *value)
#define AS_MSG_INFO1_READ_MODE_AP_ALL
static void as_command_set_attr_read(as_policy_read_mode_ap read_mode_ap, as_policy_read_mode_sc read_mode_sc, bool compress, uint8_t *read_attr, uint8_t *info_attr)
static size_t as_command_write_end(uint8_t *begin, uint8_t *end)
static uint64_t as_random_get_uint64()
static uint64_t as_task_id_resolve(uint64_t *task_id_ptr)
static void as_command_start_timer(as_command *cmd)
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)
uint8_t as_replica_index_any(void)
as_status as_command_parse_success_failure_bins(uint8_t **pp, as_error *err, as_msg *msg, as_val **value)
as_status as_command_parse_header(as_error *err, as_command *cmd, as_node *node, uint8_t *buf, size_t size)
uint8_t * as_command_parse_key(uint8_t *p, uint32_t n_fields, as_key *key, uint64_t *bval)
size_t as_command_key_size(as_policy_key policy, const as_key *key, uint16_t *n_fields)
AS_EXTERN void as_queue_destroy(as_queue *queue)
#define as_error_update(__err, __code, __fmt,...)
as_status(* as_parse_results_fn)(as_error *err, struct as_command_s *cmd, as_node *node, uint8_t *buf, size_t size)
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_bin_size(const as_bin *bin, as_queue *buffers, size_t *size, as_error *err)