From: Georgy Kirichenko <georgy@tarantool.org> To: tarantool-patches@freelists.org Cc: Georgy Kirichenko <georgy@tarantool.org> Subject: [tarantool-patches] [PATCH v2 1/8] Encode a dml statement to a transaction memory region Date: Thu, 23 May 2019 11:19:33 +0300 [thread overview] Message-ID: <b0c8953687dfce6c5c4ac12ded74fd8c31c5f367.1558598679.git.georgy@tarantool.org> (raw) In-Reply-To: <cover.1558598679.git.georgy@tarantool.org> Encode all statements to be written out to wal onto a transaction memory region. This relaxes a relation between transaction and fiber state and required for an autonomous transaction feature. Prerequisites: #1254 --- src/box/request.c | 2 +- src/box/txn.c | 27 ++++++++++++++------------- src/box/vy_log.c | 2 +- src/box/vy_stmt.c | 4 ++-- src/box/xrow.c | 14 ++++++++------ src/box/xrow.h | 12 +++++++++--- 6 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/box/request.c b/src/box/request.c index 041a8d548..e2a98fdf9 100644 --- a/src/box/request.c +++ b/src/box/request.c @@ -61,7 +61,7 @@ request_update_header(struct request *request, struct xrow_header *row) if (row == NULL) return 0; row->type = request->type; - row->bodycnt = xrow_encode_dml(request, row->body); + row->bodycnt = xrow_encode_dml(request, &fiber()->gc, row->body); if (row->bodycnt < 0) return -1; request->header = row; diff --git a/src/box/txn.c b/src/box/txn.c index 4182d5791..da749d7cc 100644 --- a/src/box/txn.c +++ b/src/box/txn.c @@ -49,11 +49,7 @@ fiber_set_txn(struct fiber *fiber, struct txn *txn) static int txn_add_redo(struct txn *txn, struct txn_stmt *stmt, struct request *request) { - stmt->row = request->header; - if (request->header != NULL) - return 0; - - /* Create a redo log row for Lua requests */ + /* Create a redo log row. */ struct xrow_header *row; row = region_alloc_object(&txn->region, struct xrow_header); if (row == NULL) { @@ -61,14 +57,19 @@ txn_add_redo(struct txn *txn, struct txn_stmt *stmt, struct request *request) "region", "struct xrow_header"); return -1; } - /* Initialize members explicitly to save time on memset() */ - row->type = request->type; - row->replica_id = 0; - row->group_id = stmt->space != NULL ? space_group_id(stmt->space) : 0; - row->lsn = 0; - row->sync = 0; - row->tm = 0; - row->bodycnt = xrow_encode_dml(request, row->body); + if (request->header != NULL) { + *row = *request->header; + } else { + /* Initialize members explicitly to save time on memset() */ + row->type = request->type; + row->replica_id = 0; + row->group_id = stmt->space != NULL ? + space_group_id(stmt->space) : 0; + row->lsn = 0; + row->sync = 0; + row->tm = 0; + } + row->bodycnt = xrow_encode_dml(request, &txn->region, row->body); if (row->bodycnt < 0) return -1; stmt->row = row; diff --git a/src/box/vy_log.c b/src/box/vy_log.c index edd61b33a..bdc1cfa31 100644 --- a/src/box/vy_log.c +++ b/src/box/vy_log.c @@ -520,7 +520,7 @@ vy_log_record_encode(const struct vy_log_record *record, req.tuple_end = pos; memset(row, 0, sizeof(*row)); row->type = req.type; - row->bodycnt = xrow_encode_dml(&req, row->body); + row->bodycnt = xrow_encode_dml(&req, &fiber()->gc, row->body); return 0; } diff --git a/src/box/vy_stmt.c b/src/box/vy_stmt.c index 9e20b6bfb..f936cd61f 100644 --- a/src/box/vy_stmt.c +++ b/src/box/vy_stmt.c @@ -653,7 +653,7 @@ vy_stmt_encode_primary(struct tuple *value, struct key_def *key_def, } if (vy_stmt_meta_encode(value, &request, true) != 0) return -1; - xrow->bodycnt = xrow_encode_dml(&request, xrow->body); + xrow->bodycnt = xrow_encode_dml(&request, &fiber()->gc, xrow->body); if (xrow->bodycnt < 0) return -1; return 0; @@ -688,7 +688,7 @@ vy_stmt_encode_secondary(struct tuple *value, struct key_def *cmp_def, } if (vy_stmt_meta_encode(value, &request, false) != 0) return -1; - xrow->bodycnt = xrow_encode_dml(&request, xrow->body); + xrow->bodycnt = xrow_encode_dml(&request, &fiber()->gc, xrow->body); if (xrow->bodycnt < 0) return -1; else diff --git a/src/box/xrow.c b/src/box/xrow.c index 886fb57fe..0ae5271c1 100644 --- a/src/box/xrow.c +++ b/src/box/xrow.c @@ -752,15 +752,18 @@ request_str(const struct request *request) } int -xrow_encode_dml(const struct request *request, struct iovec *iov) +xrow_encode_dml(const struct request *request, struct region *region, + struct iovec *iov) { int iovcnt = 1; const int MAP_LEN_MAX = 40; uint32_t key_len = request->key_end - request->key; uint32_t ops_len = request->ops_end - request->ops; uint32_t tuple_meta_len = request->tuple_meta_end - request->tuple_meta; - uint32_t len = MAP_LEN_MAX + key_len + ops_len + tuple_meta_len; - char *begin = (char *) region_alloc(&fiber()->gc, len); + uint32_t tuple_len = request->tuple_end - request->tuple; + uint32_t len = MAP_LEN_MAX + key_len + ops_len + tuple_meta_len + + tuple_len; + char *begin = (char *) region_alloc(region, len); if (begin == NULL) { diag_set(OutOfMemory, len, "region_alloc", "begin"); return -1; @@ -802,9 +805,8 @@ xrow_encode_dml(const struct request *request, struct iovec *iov) } if (request->tuple) { pos = mp_encode_uint(pos, IPROTO_TUPLE); - iov[iovcnt].iov_base = (void *) request->tuple; - iov[iovcnt].iov_len = (request->tuple_end - request->tuple); - iovcnt++; + memcpy(pos, request->tuple, tuple_len); + pos += tuple_len; map_size++; } diff --git a/src/box/xrow.h b/src/box/xrow.h index 3a8cba191..35ec06dc0 100644 --- a/src/box/xrow.h +++ b/src/box/xrow.h @@ -54,6 +54,8 @@ enum { IPROTO_SELECT_HEADER_LEN = IPROTO_HEADER_LEN + 7, }; +struct region; + struct xrow_header { /* (!) Please update txn_add_redo() after changing members */ @@ -195,12 +197,15 @@ xrow_decode_dml(struct xrow_header *xrow, struct request *request, /** * Encode the request fields to iovec using region_alloc(). * @param request request to encode + * @param region region to encode + * @param copy_tuple if true then tuple is going to be copied to the region * @param iov[out] iovec to fill * @retval -1 on error, see diag * @retval > 0 the number of iovecs used */ int -xrow_encode_dml(const struct request *request, struct iovec *iov); +xrow_encode_dml(const struct request *request, struct region *region, + struct iovec *iov); /** * CALL/EVAL request. @@ -713,9 +718,10 @@ xrow_decode_dml_xc(struct xrow_header *row, struct request *request, /** @copydoc xrow_encode_dml. */ static inline int -xrow_encode_dml_xc(const struct request *request, struct iovec *iov) +xrow_encode_dml_xc(const struct request *request, struct region *region, + struct iovec *iov) { - int iovcnt = xrow_encode_dml(request, iov); + int iovcnt = xrow_encode_dml(request, region, iov); if (iovcnt < 0) diag_raise(); return iovcnt; -- 2.21.0
next prev parent reply other threads:[~2019-05-23 8:21 UTC|newest] Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-05-23 8:19 [tarantool-patches] [PATCH v2 0/8] Make transaction autonomous from a fiber internals Georgy Kirichenko 2019-05-23 8:19 ` Georgy Kirichenko [this message] 2019-05-28 1:21 ` [tarantool-patches] Re: [PATCH v2 1/8] Encode a dml statement to a transaction memory region Kirill Yukhin 2019-05-23 8:19 ` [tarantool-patches] [PATCH v2 2/8] Get rid of autocommit from a txn structure Georgy Kirichenko 2019-05-27 20:51 ` [tarantool-patches] " Konstantin Osipov 2019-05-31 19:21 ` Konstantin Osipov 2019-05-23 8:19 ` [tarantool-patches] [PATCH v2 3/8] Get rid of fiber_gc from txn_rollback Georgy Kirichenko 2019-05-31 19:27 ` [tarantool-patches] " Konstantin Osipov 2019-05-23 8:19 ` [tarantool-patches] [PATCH v2 4/8] Remove fiber from a journal_entry structure Georgy Kirichenko 2019-05-31 19:29 ` [tarantool-patches] " Konstantin Osipov 2019-05-23 8:19 ` [tarantool-patches] [PATCH v2 5/8] Commit engine before all triggers Georgy Kirichenko 2019-05-31 19:32 ` [tarantool-patches] " Konstantin Osipov 2019-06-03 8:07 ` Георгий Кириченко 2019-05-23 8:19 ` [tarantool-patches] [PATCH v2 6/8] Offload tx_prio processing to a fiber Georgy Kirichenko 2019-05-31 19:36 ` [tarantool-patches] " Konstantin Osipov 2019-06-03 8:04 ` Георгий Кириченко 2019-05-23 8:19 ` [tarantool-patches] [PATCH v2 7/8] Enable asyncronous wal writes Georgy Kirichenko 2019-05-31 19:41 ` [tarantool-patches] " Konstantin Osipov 2019-06-03 8:09 ` Георгий Кириченко 2019-05-23 8:19 ` [tarantool-patches] [PATCH v2 8/8] Introduce asynchronous txn commit Georgy Kirichenko 2019-05-31 19:43 ` [tarantool-patches] " Konstantin Osipov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=b0c8953687dfce6c5c4ac12ded74fd8c31c5f367.1558598679.git.georgy@tarantool.org \ --to=georgy@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH v2 1/8] Encode a dml statement to a transaction memory region' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox