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 8BA046EC55; Thu, 10 Jun 2021 16:35:03 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8BA046EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1623332103; bh=nwqz1mys5mXJqctmZFPt45pfBX82fXilR4JyFWReMPs=; 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=cVAD+ya3nFjHC1o55o328af8ase1gUCyXUH357vgUGDy2KxQn5bcJKh2qtQqGs25l OBKQGKG4k9YwHz5d7qOEql9lyT5wf7TuffK60ifU7kiw52iMquO6CDWVJlqw2AD7Ut B4z/Q6hpCBDjZCjxSBvr0Q42qNQx9kqVR9S5E7jE= Received: from smtp63.i.mail.ru (smtp63.i.mail.ru [217.69.128.43]) (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 178296EC57 for ; Thu, 10 Jun 2021 16:33:06 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 178296EC57 Received: by smtp63.i.mail.ru with esmtpa (envelope-from ) id 1lrKnx-0007EB-3K; Thu, 10 Jun 2021 16:33:05 +0300 To: v.shpilevoy@tarantool.org, gorcunov@gmail.com Date: Thu, 10 Jun 2021 16:32:54 +0300 Message-Id: <2e1ee8330e3ce53517bcb489280bfa5191bb66fb.1623331925.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-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9D5B0DA836B685C546075B3437CB362FF47FF2EE3FBA69D6F182A05F5380850404C284D44CB927D9F1BFF1AFB99DF51191F3D6597DC024F66829FD0E5DB44858D X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE772FD67E8B75B52AFEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637DA223B75F41C64628638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8A445BF6BB5F2E6015FC7AC3A6CD7C860117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC55B19328CBC4F849A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352026055571C92BF10FE5D25F19253116ADD2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EEC24E1E72F37C03A00CB8D3112395442FD8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE365B78C30F681404D9735652A29929C6CC4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F79006371F24DFF1B2961425731C566533BA786AA5CC5B56E945C8DA X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A24209795067102C07E8F7B195E1C97831B61BC0640769A5B17E6ED54993E2D80B X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8183A4AFAF3EA6BDC44C234C8B12C006B7AFC014AD2D9E6C96FAFC1A16B2F5C4C56DEBDBA84E268C5CFB1881A6453793CE9C32612AADDFBE061C61BE10805914D3804EBA3D8E7E5B87ABF8C51168CD8EBDBAB5495298CADBD05DC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D344EF254DC71474AA3C65DD0369810F59F17C8EED11D21CE93182D630DF514113360B641EC1A61A3251D7E09C32AA3244CD91FFD4852DBDBD8551E5C6A47F2FA7555E75C8D0ED9F6EE927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXiiA81jxGMgNqGNPlVLJtki X-Mailru-Sender: 583F1D7ACE8F49BD9DF7A8DAE6E2B08A7C268FF7D9159348882E0DB464E5A634362FCE0672430466424AE0EB1F3D1D21E2978F233C3FAE6EE63DB1732555E4A8EE80603BA4A5B0BC112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH 4/7] 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. Part-of #6034 --- src/box/memtx_engine.c | 34 ++++++++++++++++++++++++++++++++++ src/box/txn_limbo.c | 9 +++++++++ src/box/txn_limbo.h | 6 ++++++ 3 files changed, 49 insertions(+) diff --git a/src/box/memtx_engine.c b/src/box/memtx_engine.c index 6c4982b9f..3713d39d0 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_promote(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 it's 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_promote(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 promote; /** * 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->promote); ckpt->touch = false; return ckpt; } @@ -655,6 +676,17 @@ finish: return rc; } +static int +checkpoint_write_promote(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); + if (checkpoint_write_row(l, &row) != 0) + return -1; + return 0; +} + static int checkpoint_f(va_list ap) { @@ -692,6 +724,8 @@ checkpoint_f(va_list ap) } if (checkpoint_write_raft(&snap, &ckpt->raft) != 0) goto fail; + if (checkpoint_write_promote(&snap, &ckpt->promote) != 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 33a6e5548..40c4a41bb 100644 --- a/src/box/txn_limbo.c +++ b/src/box/txn_limbo.c @@ -295,6 +295,15 @@ complete: return 0; } +void +txn_limbo_checkpoint(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 e409ac657..84a19bb40 100644 --- a/src/box/txn_limbo.h +++ b/src/box/txn_limbo.h @@ -311,6 +311,12 @@ 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(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)