From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 99AB36BD0D; Sun, 11 Apr 2021 20:56:39 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 99AB36BD0D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618163799; bh=QPM6DXqt0tnlF2m/R6oLf0i7iZnxbAsTSdxGx3mWDEU=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=vcWZCgdD09XGhMOjEps05CaoQwgYr7zzqN/z7EbQcT93LxAITAVXC0ozfszzj7Fdd mXogzLb6uLziFeBNU1c5AvwpUtSmYKoD3rXgreZ42k3BknWg6rP+lWkUC9k9dyvYL9 t4L5cEbx4LqbWbDXWQQ8O424e3vlSHrUhtPVeyZc= Received: from smtp42.i.mail.ru (smtp42.i.mail.ru [94.100.177.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 76AF16BD0D for ; Sun, 11 Apr 2021 20:56:09 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 76AF16BD0D Received: by smtp42.i.mail.ru with esmtpa (envelope-from ) id 1lVeJc-0001Ua-Op; Sun, 11 Apr 2021 20:56:09 +0300 To: v.shpilevoy@tarantool.org, gorcunov@gmail.com Date: Sun, 11 Apr 2021 20:55:56 +0300 Message-Id: <69fd9b54dcaf92116e08d3319a66c080ad578cea.1618163409.git.sergepetrenko@tarantool.org> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E7480BE79914FF86F9151AC38CC435EA4A654182A05F538085040DF495FDE9DD5C9645DC240D5687DCA44B5E28922082931CAD3F053FA666A52D9 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE74B5FAD37B56A37BDC2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE7BC21C294753CF0FAEA1F7E6F0F101C67CDEEF6D7F21E0D1D9295C2E9FA3191EE1B59CA4C82EFA658029CC55D78B50782BB6059DC0F64B999F6B57BC7E64490618DEB871D839B73339E8FC8737B5C2249BAA8CD687FCDB2EBCC7F00164DA146DAFE8445B8C89999729449624AB7ADAF37F6B57BC7E64490611E7FA7ABCAF51C92176DF2183F8FC7C0E95A866B274017E58941B15DA834481F9449624AB7ADAF37BA3038C0950A5D3613377AFFFEAFD2691661749BA6B977358EED4D61EBB61A6E7B076A6E789B0E97A8DF7F3B2552694A1E7802607F20496D49FD398EE364050FB28585415E75ADA9452896749CDDA0A6B3661434B16C20AC78D18283394535A9E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B67BEEC15D15C45022089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A24209795067102C07E8F7B195E1C9783191471F51605917AD437CCAE968C07DD4 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8183A4AFAF3EA6BDC44C234C8B12C006B7AFD80A448CD634CA5E15C29638EE99F76481C33C154686168B1881A6453793CE9C32612AADDFBE061C61BE10805914D3804EBA3D8E7E5B87ABF8C51168CD8EBDB63AF70AF8205D7DCDC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D340DAE5B306C240CF56195EDFFC1B15CE1075DBE83ABA9ED18179CCE6098BC8A2E05C5BF1AA52417AA1D7E09C32AA3244C2ED0FBD32ACAC3ED2BB3E27C88760E6C8894E9C85370243E927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXjz3uqod8pbhY90JjMNGvbB X-Mailru-Sender: 583F1D7ACE8F49BDD2846D59FC20E9F8A3D5B6EFD69438693BBA83AFDEFAFB98A40AD7AC6ECEA9DF424AE0EB1F3D1D21E2978F233C3FAE6EE63DB1732555E4A8EE80603BA4A5B0BC112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH 1/9] wal: enrich row's meta information with sync replication flags X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Serge Petrenko via Tarantool-patches Reply-To: Serge Petrenko Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Introduce two new flags to xrow_header: `wait_ack` and `wait_sync`. These flags are set for rows belonging to synchronous transactions in addition to `is_commit`. The new flags help to define whether the rows belong to a synchronous transaction or not without parsing them all and checking whether any of the rows touches a synchronous space. This will be used in applier once it is taught to filter synchronous transactions based on whether they are coming from a raft leader or not. P.S. These flags will also be useful once we allow to turn any transaction synchronous. Once this is done, the flags in row header will be the only source of information on whether the transaction is synchronous or not. Prerequisite #5445 @TarantoolBot document Title: new values for IPROTO_FLAGS field IPROTO_FLAGS bitfield is enriched with two new constant: IPROTO_FLAG_WAIT_SYNC = 0x02 IPROTO_FLAG_WAIT_ACK = 0x04 IPROTO_FLAG_WAIT_SYNC is set for the last synchronous transaction row. IPROTO_FLAG_WAIT_ACK is set for the last row of a transaction which is not applied because other synchronous transactions are in fly. --- src/box/iproto_constants.h | 5 +++++ src/box/journal.h | 2 ++ src/box/txn.c | 5 +++++ src/box/wal.c | 26 +++++++++++++++----------- src/box/xrow.c | 13 ++++++++----- src/box/xrow.h | 30 ++++++++++++++++++++++-------- 6 files changed, 57 insertions(+), 24 deletions(-) diff --git a/src/box/iproto_constants.h b/src/box/iproto_constants.h index d3738c705..f7f46088f 100644 --- a/src/box/iproto_constants.h +++ b/src/box/iproto_constants.h @@ -49,9 +49,14 @@ enum { XLOG_FIXHEADER_SIZE = 19 }; +/** IPROTO_FLAGS bitfield constants. */ enum { /** Set for the last xrow in a transaction. */ IPROTO_FLAG_COMMIT = 0x01, + /** Set for the last row of a tx residing in limbo. */ + IPROTO_FLAG_WAIT_SYNC = 0x02, + /** Set for the last row of a synchronous tx. */ + IPROTO_FLAG_WAIT_ACK = 0x04, }; enum iproto_key { diff --git a/src/box/journal.h b/src/box/journal.h index 76c70c19f..9ab8af2c1 100644 --- a/src/box/journal.h +++ b/src/box/journal.h @@ -63,6 +63,7 @@ struct journal_entry { * A journal entry completion callback argument. */ void *complete_data; + uint8_t opt_flags; /** * Asynchronous write completion function. */ @@ -97,6 +98,7 @@ journal_entry_create(struct journal_entry *entry, size_t n_rows, entry->approx_len = approx_len; entry->n_rows = n_rows; entry->res = -1; + entry->opt_flags = 0; } /** diff --git a/src/box/txn.c b/src/box/txn.c index 40061ff09..d65315f58 100644 --- a/src/box/txn.c +++ b/src/box/txn.c @@ -76,6 +76,7 @@ txn_add_redo(struct txn *txn, struct txn_stmt *stmt, struct request *request) row->lsn = 0; row->sync = 0; row->tm = 0; + row->opt_flags = 0; } /* * Group ID should be set both for requests not having a @@ -681,6 +682,10 @@ txn_journal_entry_new(struct txn *txn) --req->n_rows; } + req->opt_flags |= + (txn_has_flag(txn, TXN_WAIT_SYNC) ? IPROTO_FLAG_WAIT_SYNC : 0) | + (txn_has_flag(txn, TXN_WAIT_ACK) ? IPROTO_FLAG_WAIT_ACK : 0); + return req; } diff --git a/src/box/wal.c b/src/box/wal.c index 34af0bda6..00fcb21b4 100644 --- a/src/box/wal.c +++ b/src/box/wal.c @@ -962,14 +962,14 @@ out: */ static void wal_assign_lsn(struct vclock *vclock_diff, struct vclock *base, - struct xrow_header **row, - struct xrow_header **end) + struct journal_entry *entry) { int64_t tsn = 0; - struct xrow_header **start = row; - struct xrow_header **first_glob_row = row; + struct xrow_header **start = entry->rows; + struct xrow_header **end = entry->rows + entry->n_rows; + struct xrow_header **first_glob_row = start; /** Assign LSN to all local rows. */ - for ( ; row < end; row++) { + for (struct xrow_header **row = start; row < end; row++) { if ((*row)->replica_id == 0) { /* * All rows representing local space data @@ -996,7 +996,13 @@ wal_assign_lsn(struct vclock *vclock_diff, struct vclock *base, first_glob_row = row; } (*row)->tsn = tsn == 0 ? (*start)->lsn : tsn; - (*row)->is_commit = row == end - 1; + if (row < end - 1) + continue; + /* Tx meta is stored in the last tx row. */ + if (row == end - 1) { + (*row)->opt_flags = entry->opt_flags; + (*row)->is_commit = true; + } } else { int64_t diff = (*row)->lsn - vclock_get(base, (*row)->replica_id); if (diff <= vclock_get(vclock_diff, @@ -1020,7 +1026,7 @@ wal_assign_lsn(struct vclock *vclock_diff, struct vclock *base, * the first global row. tsn was yet unknown when those * rows were processed. */ - for (row = start; row < first_glob_row; row++) + for (struct xrow_header **row = start; row < first_glob_row; row++) (*row)->tsn = tsn; } @@ -1098,8 +1104,7 @@ wal_write_to_disk(struct cmsg *msg) struct journal_entry *entry; struct stailq_entry *last_committed = NULL; stailq_foreach_entry(entry, &wal_msg->commit, fifo) { - wal_assign_lsn(&vclock_diff, &writer->vclock, - entry->rows, entry->rows + entry->n_rows); + wal_assign_lsn(&vclock_diff, &writer->vclock, entry); entry->res = vclock_sum(&vclock_diff) + vclock_sum(&writer->vclock); rc = xlog_write_entry(l, entry); @@ -1319,8 +1324,7 @@ wal_write_none_async(struct journal *journal, struct vclock vclock_diff; vclock_create(&vclock_diff); - wal_assign_lsn(&vclock_diff, &writer->vclock, entry->rows, - entry->rows + entry->n_rows); + wal_assign_lsn(&vclock_diff, &writer->vclock, entry); vclock_merge(&writer->vclock, &vclock_diff); vclock_copy(&replicaset.vclock, &writer->vclock); entry->res = vclock_sum(&writer->vclock); diff --git a/src/box/xrow.c b/src/box/xrow.c index bc06738ad..cc8e43ed4 100644 --- a/src/box/xrow.c +++ b/src/box/xrow.c @@ -183,7 +183,7 @@ error: break; case IPROTO_FLAGS: flags = mp_decode_uint(pos); - header->is_commit = flags & IPROTO_FLAG_COMMIT; + header->opt_flags = flags; break; default: /* unknown header */ @@ -299,6 +299,7 @@ xrow_header_encode(const struct xrow_header *header, uint64_t sync, * flag to find transaction boundary (last row in the * transaction stream). */ + uint8_t flags_to_encode = header->opt_flags & ~IPROTO_FLAG_COMMIT; if (header->tsn != 0) { if (header->tsn != header->lsn || !header->is_commit) { /* @@ -314,12 +315,14 @@ xrow_header_encode(const struct xrow_header *header, uint64_t sync, map_size++; } if (header->is_commit && header->tsn != header->lsn) { - /* Setup last row for multi row transaction. */ - d = mp_encode_uint(d, IPROTO_FLAGS); - d = mp_encode_uint(d, IPROTO_FLAG_COMMIT); - map_size++; + flags_to_encode |= IPROTO_FLAG_COMMIT; } } + if (flags_to_encode != 0) { + d = mp_encode_uint(d, IPROTO_FLAGS); + d = mp_encode_uint(d, flags_to_encode); + map_size++; + } assert(d <= data + XROW_HEADER_LEN_MAX); mp_encode_map(data, map_size); out->iov_len = d - (char *) out->iov_base; diff --git a/src/box/xrow.h b/src/box/xrow.h index fde8f9474..2a18733c0 100644 --- a/src/box/xrow.h +++ b/src/box/xrow.h @@ -80,14 +80,28 @@ struct xrow_header { * transaction. */ int64_t tsn; - /** - * True for the last row in a multi-statement transaction, - * or single-statement transaction. Is only encoded in the - * write ahead log for multi-statement transactions. - * Single-statement transactions do not encode - * tsn and is_commit flag to save space. - */ - bool is_commit; + /** Transaction meta flags set only in the last transaction row. */ + union { + uint8_t opt_flags; + struct { + /** + * Is only encoded in the write ahead log for + * multi-statement transactions. Single-statement + * transactions do not encode tsn and is_commit flag to + * save space. + */ + bool is_commit : 1; + /** + * True for a synchronous transaction. + */ + bool wait_sync : 1; + /** + * True for any transaction that would enter the limbo + * (not necessarily a synchronous one). + */ + bool wait_ack : 1; + }; + }; int bodycnt; uint32_t schema_version; -- 2.24.3 (Apple Git-128)