diff --git a/src/box/xrow_update.c b/src/box/xrow_update.c index 1b9aa528b7cb34ca9672e4527f29314765b3d352..4e8695e0c3e2929982c8c517c042206f6088aa95 100644 --- a/src/box/xrow_update.c +++ b/src/box/xrow_update.c @@ -169,13 +169,8 @@ xrow_update_read_ops(struct xrow_update *update, const char *expr, int size = update->op_count * sizeof(update->ops[0]); update->ops = (struct xrow_update_op *) - region_aligned_alloc(&fiber()->gc, size, - alignof(struct xrow_update_op)); - if (update->ops == NULL) { - diag_set(OutOfMemory, size, "region_aligned_alloc", - "update->ops"); - return -1; - } + xregion_aligned_alloc(&fiber()->gc, size, + alignof(struct xrow_update_op)); struct xrow_update_op *op = update->ops; struct xrow_update_op *ops_end = op + update->op_count; for (int i = 1; op < ops_end; op++, i++) { @@ -296,9 +291,8 @@ xrow_update_do_ops(struct xrow_update *update, const char *header, const char *old_data, const char *old_data_end, uint32_t part_count) { - if (xrow_update_array_create(&update->root, header, old_data, - old_data_end, part_count) != 0) - return -1; + xrow_update_array_create(&update->root, header, old_data, + old_data_end, part_count); struct xrow_update_op *op = update->ops; struct xrow_update_op *ops_end = op + update->op_count; for (; op < ops_end; op++) { @@ -318,9 +312,8 @@ xrow_upsert_do_ops(struct xrow_update *update, const char *header, const char *old_data, const char *old_data_end, uint32_t part_count, bool suppress_error) { - if (xrow_update_array_create(&update->root, header, old_data, - old_data_end, part_count) != 0) - return -1; + xrow_update_array_create(&update->root, header, old_data, + old_data_end, part_count); struct xrow_update_op *op = update->ops; struct xrow_update_op *ops_end = op + update->op_count; for (; op < ops_end; op++) { @@ -349,11 +342,7 @@ xrow_update_finish(struct xrow_update *update, struct tuple_format *format, uint32_t *p_tuple_len) { uint32_t tuple_len = xrow_update_array_sizeof(&update->root); - char *buffer = (char *) region_alloc(&fiber()->gc, tuple_len); - if (buffer == NULL) { - diag_set(OutOfMemory, tuple_len, "region_alloc", "buffer"); - return NULL; - } + char *buffer = (char *)xregion_alloc(&fiber()->gc, tuple_len); *p_tuple_len = xrow_update_array_store(&update->root, &format->fields, &format->fields.root, buffer, buffer + tuple_len); @@ -395,11 +384,7 @@ xrow_update_execute(const char *expr,const char *expr_end, if (column_mask) *column_mask = update.column_mask; - const char *ret = xrow_update_finish(&update, format, p_tuple_len); - if (ret == NULL) - goto error; - - return ret; + return xrow_update_finish(&update, format, p_tuple_len); error: region_truncate(&fiber()->gc, region_svp); diff --git a/src/box/xrow_update_array.c b/src/box/xrow_update_array.c index b3cbd7a3b13d3fdcce18f41fcddb9dcae099372b..f15a4851b4d8da4ae92fffcbd2aac228abb99a38 100644 --- a/src/box/xrow_update_array.c +++ b/src/box/xrow_update_array.c @@ -104,12 +104,7 @@ xrow_update_array_item_create(struct xrow_update_array_item *item, static inline void * xrow_update_alloc(struct region *region, size_t size) { - void *ptr = region_aligned_alloc(region, size, alignof(uint64_t)); - if (ptr == NULL) { - diag_set(OutOfMemory, size, "region_aligned_alloc", - "xrow update internals"); - } - return ptr; + return xregion_aligned_alloc(region, size, alignof(uint64_t)); } /** Split a range of fields in two. */ @@ -121,8 +116,6 @@ xrow_update_array_item_split(struct region *region, (void) size; struct xrow_update_array_item *next = (struct xrow_update_array_item *) xrow_update_alloc(region, sizeof(*next)); - if (next == NULL) - return NULL; assert(offset > 0 && prev->tail_size > 0); const char *tail = prev->field.data + prev->field.size; @@ -164,7 +157,7 @@ xrow_update_array_extract_item(struct xrow_update_field *field, return NULL; } -int +void xrow_update_array_create(struct xrow_update_field *field, const char *header, const char *data, const char *data_end, uint32_t field_count) @@ -174,14 +167,11 @@ xrow_update_array_create(struct xrow_update_field *field, const char *header, field->size = data_end - header; struct region *region = &fiber()->gc; field->array.rope = xrow_update_rope_new(region); - if (field->array.rope == NULL) - return -1; + assert(field->array.rope != NULL); struct xrow_update_array_item *item = (struct xrow_update_array_item *) xrow_update_alloc(region, sizeof(*item)); - if (item == NULL) - return -1; if (data == data_end) - return 0; + return; /* * Initial item consists of one range - the whole array. */ @@ -189,10 +179,12 @@ xrow_update_array_create(struct xrow_update_field *field, const char *header, mp_next(&data); xrow_update_array_item_create(item, XUPDATE_NOP, begin, data - begin, data_end - data); - return xrow_update_rope_append(field->array.rope, item, field_count); + int rc = xrow_update_rope_append(field->array.rope, item, field_count); + assert(rc == 0); + (void)rc; } -int +void xrow_update_array_create_with_child(struct xrow_update_field *field, const char *header, const struct xrow_update_field *child, @@ -205,12 +197,9 @@ xrow_update_array_create_with_child(struct xrow_update_field *field, mp_next(&first_field_end); struct region *region = &fiber()->gc; struct xrow_update_rope *rope = xrow_update_rope_new(region); - if (rope == NULL) - return -1; + assert(rope != NULL); struct xrow_update_array_item *item = (struct xrow_update_array_item *) xrow_update_alloc(region, sizeof(*item)); - if (item == NULL) - return -1; const char *end = first_field_end; if (field_no > 0) { for (int32_t i = 1; i < field_no; ++i) @@ -218,12 +207,11 @@ xrow_update_array_create_with_child(struct xrow_update_field *field, xrow_update_array_item_create(item, XUPDATE_NOP, first_field, first_field_end - first_field, end - first_field_end); - if (xrow_update_rope_append(rope, item, field_no) != 0) - return -1; + int rc = xrow_update_rope_append(rope, item, field_no); + assert(rc == 0); + (void)rc; item = (struct xrow_update_array_item *) xrow_update_alloc(region, sizeof(*item)); - if (item == NULL) - return -1; first_field = end; first_field_end = first_field; mp_next(&first_field_end); @@ -239,7 +227,9 @@ xrow_update_array_create_with_child(struct xrow_update_field *field, field->data = header; field->size = end - header; field->array.rope = rope; - return xrow_update_rope_append(rope, item, field_count - field_no); + int rc = xrow_update_rope_append(rope, item, field_count - field_no); + assert(rc == 0); + (void)rc; } uint32_t @@ -315,37 +305,33 @@ xrow_update_array_store(struct xrow_update_field *field, * Helper function that appends nils in the end so that op will insert * without gaps */ -static int +static void xrow_update_array_append_nils(struct xrow_update_field *field, struct xrow_update_op *op) { struct xrow_update_rope *rope = field->array.rope; uint32_t size = xrow_update_rope_size(rope); if (op->field_no < 0 || (uint32_t)op->field_no <= size) - return 0; + return; /* * Do not allow autofill of nested arrays with nulls. It is not * supported only because there is no an easy way how to apply that to * bar updates which can also affect arrays. */ if (!op->is_for_root) - return 0; + return; uint32_t nil_count = op->field_no - size; struct xrow_update_array_item *item = (struct xrow_update_array_item *) xrow_update_alloc(rope->ctx, sizeof(*item)); - if (item == NULL) - return -1; assert(mp_sizeof_nil() == 1); - char *item_data = (char *)region_alloc(rope->ctx, nil_count); - if (item_data == NULL) { - diag_set(OutOfMemory, nil_count, "region", "item_data"); - return -1; - } + char *item_data = (char *)xregion_alloc(rope->ctx, nil_count); memset(item_data, 0xc0, nil_count); xrow_update_array_item_create(item, XUPDATE_NOP, item_data, 1, nil_count - 1); - return xrow_update_rope_insert(rope, op->field_no, item, nil_count); + int rc = xrow_update_rope_insert(rope, op->field_no, item, nil_count); + assert(rc == 0); + (void)rc; } int @@ -365,8 +351,7 @@ xrow_update_op_do_array_insert(struct xrow_update_op *op, return xrow_update_op_do_field_insert(op, &item->field); } - if (xrow_update_array_append_nils(field, op) != 0) - return -1; + xrow_update_array_append_nils(field, op); struct xrow_update_rope *rope = field->array.rope; uint32_t size = xrow_update_rope_size(rope); @@ -386,11 +371,12 @@ xrow_update_op_do_array_insert(struct xrow_update_op *op, item = (struct xrow_update_array_item *) xrow_update_alloc(rope->ctx, sizeof(*item)); - if (item == NULL) - return -1; xrow_update_array_item_create(item, XUPDATE_NOP, op->arg.set.value, op->arg.set.length, 0); - return xrow_update_rope_insert(rope, op->field_no, item, 1); + int rc = xrow_update_rope_insert(rope, op->field_no, item, 1); + assert(rc == 0); + (void)rc; + return 0; } int diff --git a/src/box/xrow_update_field.h b/src/box/xrow_update_field.h index 3a2ab5b001798d22cad58b90c97412e6810d557e..d355efe39d01c4934cd265ee964bcaad9c1b238a 100644 --- a/src/box/xrow_update_field.h +++ b/src/box/xrow_update_field.h @@ -578,11 +578,8 @@ xrow_update_##type##_store(struct xrow_update_field *field, \ * @param data MessagePack data of the array to update. * @param data_end End of @a data. * @param field_count Field count in @data. - * - * @retval 0 Success. - * @retval -1 Error. */ -int +void xrow_update_array_create(struct xrow_update_field *field, const char *header, const char *data, const char *data_end, uint32_t field_count); @@ -604,11 +601,8 @@ xrow_update_array_create(struct xrow_update_field *field, const char *header, * @param child A child subtree. The child is copied by value into * the created array. * @param field_no Field number of @a child. - * - * @retval 0 Success. - * @retval -1 Error. */ -int +void xrow_update_array_create_with_child(struct xrow_update_field *field, const char *header, const struct xrow_update_field *child, @@ -627,11 +621,8 @@ OP_DECL_GENERIC(array) * @param data MessagePack data of the map to update. * @param data_end End of @a data. * @param field_count Key-value pair count in @data. - * - * @retval 0 Success. - * @retval -1 Error. */ -int +void xrow_update_map_create(struct xrow_update_field *field, const char *header, const char *data, const char *data_end, int field_count); @@ -640,7 +631,7 @@ xrow_update_map_create(struct xrow_update_field *field, const char *header, * exactly the same as with a similar array constructor. It allows * to avoid unnecessary MessagePack decoding. */ -int +void xrow_update_map_create_with_child(struct xrow_update_field *field, const char *header, const struct xrow_update_field *child, diff --git a/src/box/xrow_update_map.c b/src/box/xrow_update_map.c index 57fb27f183df25860d200ce61d99880b3378a3e0..a280036c7330f243dd8cb79c48d9c4908243f69d 100644 --- a/src/box/xrow_update_map.c +++ b/src/box/xrow_update_map.c @@ -63,12 +63,7 @@ struct xrow_update_map_item { static inline struct xrow_update_map_item * xrow_update_map_item_alloc(void) { - size_t size; - struct xrow_update_map_item *item = - region_alloc_object(&fiber()->gc, typeof(*item), &size); - if (item == NULL) - diag_set(OutOfMemory, size, "region_alloc_object", "item"); - return item; + return xregion_alloc_object(&fiber()->gc, struct xrow_update_map_item); } static void @@ -102,10 +97,8 @@ xrow_update_map_new_item(struct xrow_update_field *field, uint32_t tail_size) { struct xrow_update_map_item *item = xrow_update_map_item_alloc(); - if (item != NULL) { - xrow_update_map_create_item(field, item, type, key, key_len, - data, data_size, tail_size); - } + xrow_update_map_create_item(field, item, type, key, key_len, + data, data_size, tail_size); return item; } @@ -191,8 +184,6 @@ xrow_update_map_extract_opt_item(struct xrow_update_field *field, new_item = xrow_update_map_new_item(field, XUPDATE_NOP, op->key, op->key_len, pos, tmp - pos, end - tmp); - if (new_item == NULL) - return -1; i->tail_size = i_tail_size; } *res = new_item; @@ -237,7 +228,7 @@ xrow_update_op_do_map_insert(struct xrow_update_op *op, item = xrow_update_map_new_item(field, XUPDATE_NOP, op->key, op->key_len, op->arg.set.value, op->arg.set.length, 0); - return item != NULL ? 0 : -1; + return 0; } int @@ -265,7 +256,7 @@ xrow_update_op_do_map_set(struct xrow_update_op *op, item = xrow_update_map_new_item(field, XUPDATE_NOP, op->key, op->key_len, op->arg.set.value, op->arg.set.length, 0); - return item != NULL ? 0 : -1; + return 0; } int @@ -338,7 +329,7 @@ DO_SCALAR_OP_GENERIC(bit) DO_SCALAR_OP_GENERIC(splice) -int +void xrow_update_map_create(struct xrow_update_field *field, const char *header, const char *data, const char *data_end, int field_count) { @@ -348,14 +339,12 @@ xrow_update_map_create(struct xrow_update_field *field, const char *header, field->map.size = field_count; stailq_create(&field->map.items); if (field_count == 0) - return 0; - struct xrow_update_map_item *first = - xrow_update_map_new_item(field, XUPDATE_NOP, NULL, 0, data, 0, - data_end - data); - return first != NULL ? 0 : -1; + return; + xrow_update_map_new_item(field, XUPDATE_NOP, NULL, 0, data, 0, + data_end - data); } -int +void xrow_update_map_create_with_child(struct xrow_update_field *field, const char *header, const struct xrow_update_field *child, @@ -381,8 +370,6 @@ xrow_update_map_create_with_child(struct xrow_update_field *field, item = xrow_update_map_new_item(field, XUPDATE_NOP, NULL, 0, begin, 0, before_key - begin); - if (item == NULL) - return -1; ++i; break; } @@ -402,14 +389,11 @@ xrow_update_map_create_with_child(struct xrow_update_field *field, mp_next(&pos); } item = xrow_update_map_item_alloc(); - if (item == NULL) - return -1; item->field = *child; xrow_update_map_create_item(field, item, child->type, key, key_len, data, data_size, pos - data - data_size); field->map.size = field_count; field->size = pos - header; - return 0; } uint32_t diff --git a/src/box/xrow_update_route.c b/src/box/xrow_update_route.c index 640d32f594dba7187c2c7791c5717df4070b28ce..23a56fa05e2b9ece4591a0c5d46b5c54297c164a 100644 --- a/src/box/xrow_update_route.c +++ b/src/box/xrow_update_route.c @@ -45,7 +45,7 @@ * @param child Current field from which the branch happens. It * already contains an update subtree. */ -static int +static void xrow_update_route_branch_array(struct xrow_update_field *next_hop, const char *parent, const struct xrow_update_field *child, @@ -118,17 +118,18 @@ xrow_update_route_branch_array(struct xrow_update_field *next_hop, const char *end = data; for (uint32_t i = 0; i < field_count; ++i) mp_next(&end); - if (xrow_update_array_create(next_hop, parent, data, end, - field_count) != 0) - return -1; - return op->meta->do_op(op, next_hop); + xrow_update_array_create(next_hop, parent, data, end, field_count); + int rc = op->meta->do_op(op, next_hop); + /* Should not fail as we already applied it before successfully. */ + assert(rc == 0); + (void)rc; } /** * Do the actual branch, but by a map and a key in that map. Works * exactly the same as the array-counterpart. */ -static int +static void xrow_update_route_branch_map(struct xrow_update_field *next_hop, const char *parent, const struct xrow_update_field *child, @@ -151,10 +152,11 @@ xrow_update_route_branch_map(struct xrow_update_field *next_hop, mp_next(&end); mp_next(&end); } - if (xrow_update_map_create(next_hop, parent, data, end, - field_count) != 0) - return -1; - return op->meta->do_op(op, next_hop); + xrow_update_map_create(next_hop, parent, data, end, field_count); + int rc = op->meta->do_op(op, next_hop); + /* Should not fail as we already applied it before successfully. */ + assert(rc == 0); + (void)rc; } struct xrow_update_field * @@ -254,18 +256,11 @@ xrow_update_route_branch(struct xrow_update_field *field, */ bool transform_root = (saved_old_offset == 0); struct xrow_update_field *next_hop; - if (!transform_root) { - size_t size; - next_hop = region_alloc_object(&fiber()->gc, typeof(*next_hop), - &size); - if (next_hop == NULL) { - diag_set(OutOfMemory, size, "region_alloc_object", - "next_hop"); - return NULL; - } - } else { + if (!transform_root) + next_hop = xregion_alloc_object(&fiber()->gc, + typeof(*next_hop)); + else next_hop = field; - } int path_offset = old_path_lexer.offset; struct xrow_update_field child = *field; @@ -299,9 +294,8 @@ xrow_update_route_branch(struct xrow_update_field *field, new_op->is_token_consumed = false; new_op->token_type = JSON_TOKEN_NUM; new_op->field_no = new_token.num; - if (xrow_update_route_branch_array(next_hop, parent, &child, - old_token.num) != 0) - return NULL; + xrow_update_route_branch_array(next_hop, parent, &child, + old_token.num); } else if (type == MP_MAP) { if (new_token.type != JSON_TOKEN_STR) { xrow_update_err(new_op, "can not update map by "\ @@ -312,10 +306,8 @@ xrow_update_route_branch(struct xrow_update_field *field, new_op->token_type = JSON_TOKEN_STR; new_op->key = new_token.str; new_op->key_len = new_token.len; - if (xrow_update_route_branch_map(next_hop, parent, &child, - old_token.str, - old_token.len) != 0) - return NULL; + xrow_update_route_branch_map(next_hop, parent, &child, + old_token.str, old_token.len); } else { xrow_update_err_no_such_field(new_op); return NULL;