19 #define CL_PROTO_RESULT_OK 0
20 #define CL_PROTO_RESULT_FAIL_UNKNOWN 1 // unknown failure
21 #define CL_PROTO_RESULT_FAIL_NOTFOUND 2
22 #define CL_PROTO_RESULT_FAIL_GENERATION 3
23 #define CL_PROTO_RESULT_FAIL_PARAMETER 4
24 #define CL_PROTO_RESULT_FAIL_KEY_EXISTS 5 // if 'WRITE_ADD', could fail because already exists
25 #define CL_PROTO_RESULT_FAIL_BIN_EXISTS 6
26 #define CL_PROTO_RESULT_FAIL_CLUSTER_KEY_MISMATCH 7
27 #define CL_PROTO_RESULT_FAIL_PARTITION_OUT_OF_SPACE 8
28 #define CL_PROTO_RESULT_FAIL_TIMEOUT 9
29 #define CL_PROTO_RESULT_FAIL_NOXDS 10
30 #define CL_PROTO_RESULT_FAIL_UNAVAILABLE 11 // error returned during node down and partition isn't available
31 #define CL_PROTO_RESULT_FAIL_INCOMPATIBLE_TYPE 12 // op and bin type incompatibilty
32 #define CL_PROTO_RESULT_FAIL_RECORD_TOO_BIG 13
33 #define CL_PROTO_RESULT_FAIL_KEY_BUSY 14
88 #define CL_PROTO_VERSION 2
89 #define CL_PROTO_TYPE_INFO 1 // ascii-format message for determining server info
90 #define CL_PROTO_TYPE_CL_MSG 3
91 #define CL_PROTO_TYPE_CL_MSG_COMPRESSED 4
93 #define CL_RESULT_OK 0
94 #define CL_RESULT_FAIL 1
95 #define CL_RESULT_NOTFOUND 2
99 #pragma pack(push, 1) // packing is now 1
105 #pragma pack(pop) // packing is back to what it was
107 #pragma pack(push, 1) // packing is now 1
119 #pragma pack(pop) // packing is back to what it was
125 #pragma pack(push, 1)
127 #define CL_MSG_FIELD_TYPE_NAMESPACE 0 // UTF8 string
128 #define CL_MSG_FIELD_TYPE_SET 1
129 #define CL_MSG_FIELD_TYPE_KEY 2 // contains a key type
130 #define CL_MSG_FIELD_TYPE_BIN 3 // used for secondary key access - contains a bin, thus a name and value
131 #define CL_MSG_FIELD_TYPE_DIGEST_RIPE 4 // used to send the digest just computed to the server so it doesn't have to
132 #define CL_MSG_FIELD_TYPE_GU_TID 5
133 #define CL_MSG_FIELD_TYPE_DIGEST_RIPE_ARRAY 6
134 #define CL_MSG_FIELD_TYPE_TRID 7
135 #define CL_MSG_FIELD_TYPE_SCAN_OPTIONS 8
142 #pragma pack(push, 1) // packing is now 1
152 #pragma pack(pop) // packing is back to what it was
169 #pragma pack(push, 1) // packing is now 1
174 #pragma pack(pop) // packing is back to what it was
181 #pragma pack(push, 1) // packing is now 1
196 #pragma pack(pop) // packing is back to what it was
203 #pragma pack(push, 1) // packing is now 1
208 #pragma pack(pop) // packing is back to what it was
235 #define CL_MSG_FIELD_TYPE_NAMESPACE 0 // UTF8 string
236 #define CL_MSG_FIELD_TYPE_SET 1
237 #define CL_MSG_FIELD_TYPE_KEY 2 // contains a key type
238 #define CL_MSG_FIELD_TYPE_BIN 3 // used for secondary key access - contains a bin, thus a name and value
239 #define CL_MSG_FIELD_TYPE_DIGEST_RIPE 4 // used to send the digest just computed to the server so it doesn't have to
240 #define CL_MSG_FIELD_TYPE_GU_TID 5
241 #define CL_MSG_FIELD_TYPE_DIGEST_RIPE_ARRAY 6
242 #define CL_MSG_FIELD_TYPE_TRID 7
243 #define CL_MSG_FIELD_TYPE_SCAN_OPTIONS 8
304 #define CL_MSG_OP_READ 1 // read the value in question
305 #define CL_MSG_OP_WRITE 2 // write the value in question
306 #define CL_MSG_OP_WRITE_UNIQUE 3 // write a namespace-wide unique value
307 #define CL_MSG_OP_WRITE_NOW 4 // write the server-current time
308 #define CL_MSG_OP_INCR 5
309 #define CL_MSG_OP_APPEND_SEGMENT 6 // Append segment to a particle
310 #define CL_MSG_OP_APPEND_SEGMENT_EXT 7 // Extended append - with parameters
311 #define CL_MSG_OP_APPEND_SEGMENT_QUERY 8 // Query to return subset of segments
312 #define CL_MSG_OP_APPEND 9 // Add to an existing particle
313 #define CL_MSG_OP_PREPEND 10 // Add to the beginning of an existing particle
314 #define CL_MSG_OP_TOUCH 11 // Touch
316 #define CL_MSG_OP_MC_INCR 129 // Memcache-compatible version of the increment command
317 #define CL_MSG_OP_MC_APPEND 130 // Memcache compatible append. Allow appending to ints.
318 #define CL_MSG_OP_MC_PREPEND 131 // Memcache compatile prepend. Allow prepending to ints.
319 #define CL_MSG_OP_MC_TOUCH 132 // Memcache compatible touch - does not change generation count
321 #define CL_MSG_INFO1_READ (1 << 0) // contains a read operation
322 #define CL_MSG_INFO1_GET_ALL (1 << 1) // get all bins, period
323 #define CL_MSG_INFO1_GET_ALL_NODATA (1 << 2) // get all bins WITHOUT data (currently unimplemented)
324 #define CL_MSG_INFO1_VERIFY (1 << 3) // verify is a GET transaction that includes data, and assert if the data aint right
325 #define CL_MSG_INFO1_XDS (1 << 4) // operation is being performed by XDS
326 #define CL_MSG_INFO1_NOBINDATA (1 << 5) // dOBo not read the bin information
328 #define CL_MSG_INFO2_WRITE (1 << 0) // contains a write semantic
329 #define CL_MSG_INFO2_DELETE (1 << 1) // fling a record into the belly of Moloch
330 #define CL_MSG_INFO2_GENERATION (1 << 2) // pay attention to the generation
331 #define CL_MSG_INFO2_GENERATION_GT (1 << 3) // apply write if new generation >= old, good for restore
332 #define CL_MSG_INFO2_GENERATION_DUP (1 << 4) // if a generation collision, create a duplicate
333 #define CL_MSG_INFO2_WRITE_UNIQUE (1 << 5) // write only if it doesn't exist
334 #define CL_MSG_INFO2_WRITE_BINUNIQUE (1 << 6)
335 #define CL_MSG_INFO2_WRITE_MERGE (1 << 7) // merge this with current
337 #define CL_MSG_INFO3_LAST (1 << 0) // this is the last of a multi-part message
338 #define CL_MSG_INFO3_TRACE (1 << 1) // apply server trace logging for this transaction
339 #define CL_MSG_INFO3_TOMBSTONE (1 << 2) // if set on response, a version was a delete tombstone
340 #define CL_MSG_INFO3_REPLACE (1 << 3) // properly a write option, but there are no more bits. Overwrite existing record only; do not create new record
343 static inline uint8_t * cl_msg_op_get_value_p(cl_msg_op *
op)
345 return ( ((uint8_t *)op) +
sizeof(cl_msg_op) + op->name_sz);
348 static inline uint32_t cl_msg_op_get_value_sz(cl_msg_op *
op)
350 return( op->op_sz - (4 + op->name_sz) );
353 static inline uint32_t cl_msg_field_get_value_sz(cl_msg_field *
f)
355 return( f->field_sz - 1 );
358 static inline cl_msg_field *
359 cl_msg_field_get_next(cl_msg_field *mf)
361 return ( (cl_msg_field *) (((uint8_t *)mf) +
sizeof(mf->field_sz) + mf->field_sz) );
367 static inline cl_msg_field *
368 cl_msg_field_get(cl_msg *msg, uint8_t
type)
371 cl_msg_field *fp = NULL;
373 fp = (cl_msg_field *)msg->data;
374 for (n = 0; n < msg->n_fields; n++) {
376 if (fp->type == type)
379 fp = cl_msg_field_get_next(fp);
381 if (n == msg->n_fields)
393 static inline cl_msg_op *
394 cl_msg_op_get_next(cl_msg_op *op)
396 return ( (cl_msg_op *) (((uint8_t *) op) +
sizeof(op->op_sz) + op->op_sz ) );
400 static inline cl_msg_op *
401 cl_msg_op_iterate(cl_msg *msg, cl_msg_op *current,
int *n)
405 if (msg->n_ops == 0)
return(0);
406 cl_msg_field *mf = (cl_msg_field *) msg->data;
407 for (uint32_t i = 0; i < msg->n_fields; i++)
408 mf = cl_msg_field_get_next(mf);
409 current = (cl_msg_op *) mf;
414 if (*n >= msg->n_ops)
return(0);
415 return ( cl_msg_op_get_next( current ) );
423 cl_proto_size_get(cl_proto *
proto)
425 return(
sizeof(cl_proto) + proto->sz);