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 6A9766EC40; Tue, 29 Jun 2021 01:17:33 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6A9766EC40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1624918653; bh=FVrCAUwcrymiduCbB4h362E88I93KdJm6lzRLNGVGGE=; 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=wXYSCyd3jKIZv0kGgnQI7gKJTBh+UzWPVTbZPEbPmamOO1133FhJiYgALqqIcR7rE VjATt6UckACQO5+m8LH/VNgepzhvJXYeynbuTxBlfstKg9ekaMg51G03QJlYzdC5+r udgdLfBVssVZ6PXfXTX6Os88/S4qJdWx8GkESB5w= Received: from smtp61.i.mail.ru (smtp61.i.mail.ru [217.69.128.41]) (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 6E0E06EC60 for ; Tue, 29 Jun 2021 01:13:20 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6E0E06EC60 Received: by smtp61.i.mail.ru with esmtpa (envelope-from ) id 1lxzVH-0007oC-Ip; Tue, 29 Jun 2021 01:13:19 +0300 To: v.shpilevoy@tarantool.org, gorcunov@gmail.com Date: Tue, 29 Jun 2021 01:12:54 +0300 Message-Id: <53229056b72ce6b779bfe0fb7f0a161804b7f854.1624918078.git.sergepetrenko@tarantool.org> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD954DFF1DC42D673FB8EEAA58EF109ED2DCA3B880632F394B8182A05F538085040D61FFF9452E4626D253B11BAFB191AC9EA09EDE051D72475F497B416377F097C X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE79EDB57D1FB735487EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063714A07403F1CB524B8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D84711C69C29483DDB0C8E1CC0C75DA4EF117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC292D688DDAD4E7BC389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8FA486DC37A503D0BF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8B569F1129A2C6445075ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2AD77751E876CB595E8F7B195E1C97831A91E565E6410D4C486445F3BB20A73D6 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8183A4AFAF3EA6BDC44C234C8B12C006B7A8F199441D0F32EB57BB36B1535E4D0756550EBBEB1A89F82B1881A6453793CE9C32612AADDFBE061C61BE10805914D3804EBA3D8E7E5B87ABF8C51168CD8EBDB1A9C11735BBA05FBDC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3429538671E6527D32AA0927D244BA240BE57E042BFEB0CB331446259CFEA7050CBB039E6C7B053F441D7E09C32AA3244C663B92E71DBFC339AD6DFD384BFA76B88894E9C85370243E927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojNjLyMoNI2JYOkSL7RDZhYA== X-Mailru-Sender: 3B9A0136629DC9125D61937A2360A446C3FEE19542AA4C0EB973197304449DF24AAA9FFB96F90F32424AE0EB1F3D1D21E2978F233C3FAE6EE63DB1732555E4A8EE80603BA4A5B0BC112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v3 08/12] txn_limbo: persist the latest effective promote in snapshot 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" Previously PROMOTE entries, just like CONFIRM and ROLLBACK were only stored in WALs. This is because snapshots consist solely of confirmed transactions, so there's nothing to CONFIRM or ROLLBACK. PROMOTE has gained additional meaning recently: it pins limbo ownership to a specific instance, rendering everyone else read-only. So now PROMOTE information must be stored in snapshots as well. Save the latest limbo state (owner id and latest confirmed lsn) to the snapshot as a PROMOTE request. Follow-up #6034 --- src/box/memtx_engine.c | 32 ++++++++++++++++++++++++++++++++ src/box/txn_limbo.c | 10 ++++++++++ src/box/txn_limbo.h | 7 +++++++ 3 files changed, 49 insertions(+) diff --git a/src/box/memtx_engine.c b/src/box/memtx_engine.c index c662a3c8c..a2cfb2615 100644 --- a/src/box/memtx_engine.c +++ b/src/box/memtx_engine.c @@ -50,6 +50,7 @@ #include "schema.h" #include "gc.h" #include "raft.h" +#include "txn_limbo.h" /* sync snapshot every 16MB */ #define SNAP_SYNC_INTERVAL (1 << 24) @@ -225,6 +226,22 @@ memtx_engine_recover_raft(const struct xrow_header *row) return 0; } +static int +memtx_engine_recover_synchro(const struct xrow_header *row) +{ + assert(row->type == IPROTO_PROMOTE); + struct synchro_request req; + if (xrow_decode_synchro(row, &req) != 0) + return -1; + /* + * Origin id cannot be deduced from row.replica_id in a checkpoint, + * because all its rows have a zero replica_id. + */ + req.origin_id = req.replica_id; + txn_limbo_process(&txn_limbo, &req); + return 0; +} + static int memtx_engine_recover_snapshot_row(struct memtx_engine *memtx, struct xrow_header *row, int *is_space_system) @@ -233,6 +250,8 @@ memtx_engine_recover_snapshot_row(struct memtx_engine *memtx, if (row->type != IPROTO_INSERT) { if (row->type == IPROTO_RAFT) return memtx_engine_recover_raft(row); + if (row->type == IPROTO_PROMOTE) + return memtx_engine_recover_synchro(row); diag_set(ClientError, ER_UNKNOWN_REQUEST_TYPE, (uint32_t) row->type); return -1; @@ -542,6 +561,7 @@ struct checkpoint { struct vclock vclock; struct xdir dir; struct raft_request raft; + struct synchro_request synchro_state; /** * Do nothing, just touch the snapshot file - the * checkpoint already exists. @@ -567,6 +587,7 @@ checkpoint_new(const char *snap_dirname, uint64_t snap_io_rate_limit) xdir_create(&ckpt->dir, snap_dirname, SNAP, &INSTANCE_UUID, &opts); vclock_create(&ckpt->vclock); box_raft_checkpoint_local(&ckpt->raft); + txn_limbo_checkpoint(&txn_limbo, &ckpt->synchro_state); ckpt->touch = false; return ckpt; } @@ -655,6 +676,15 @@ finish: return rc; } +static int +checkpoint_write_synchro(struct xlog *l, const struct synchro_request *req) +{ + struct xrow_header row; + char body[XROW_SYNCHRO_BODY_LEN_MAX]; + xrow_encode_synchro(&row, body, req); + return checkpoint_write_row(l, &row); +} + static int checkpoint_f(va_list ap) { @@ -692,6 +722,8 @@ checkpoint_f(va_list ap) } if (checkpoint_write_raft(&snap, &ckpt->raft) != 0) goto fail; + if (checkpoint_write_synchro(&snap, &ckpt->synchro_state) != 0) + goto fail; if (xlog_flush(&snap) < 0) goto fail; diff --git a/src/box/txn_limbo.c b/src/box/txn_limbo.c index d21f05557..239b6da76 100644 --- a/src/box/txn_limbo.c +++ b/src/box/txn_limbo.c @@ -301,6 +301,16 @@ complete: return 0; } +void +txn_limbo_checkpoint(const struct txn_limbo *limbo, + struct synchro_request *req) +{ + req->type = IPROTO_PROMOTE; + req->replica_id = limbo->owner_id; + req->lsn = limbo->confirmed_lsn; + req->term = limbo->promote_greatest_term; +} + static void txn_limbo_write_synchro(struct txn_limbo *limbo, uint16_t type, int64_t lsn, uint64_t term) diff --git a/src/box/txn_limbo.h b/src/box/txn_limbo.h index 801a1a0ee..442f2483e 100644 --- a/src/box/txn_limbo.h +++ b/src/box/txn_limbo.h @@ -311,6 +311,13 @@ txn_limbo_process(struct txn_limbo *limbo, const struct synchro_request *req); int txn_limbo_wait_confirm(struct txn_limbo *limbo); +/** + * Persist limbo state to a given synchro request. + */ +void +txn_limbo_checkpoint(const struct txn_limbo *limbo, + struct synchro_request *req); + /** * Write a PROMOTE request, which has the same effect as CONFIRM(@a lsn) and * ROLLBACK(@a lsn + 1) combined. -- 2.30.1 (Apple Git-130)