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 607EF6EC56; Wed, 14 Jul 2021 21:27:20 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 607EF6EC56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1626287240; bh=SgGGaOeAgJe30J1cxMVSGf48AaLh+cQP0Dxin20dHmw=; 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=NywXx2PK7LiDxKuZvxNlVrQ3/NgM4RNtj8Rv484sjAnaa+ipyuZYswfga4ZASaGYN 7g3LQHWnU779UTQ6/UejCJdYAoH5g4K+714vW2aMiN9s/ltZK3/SAEed3RWvIHn3zE tu4uY8LkgSuO1BBJRtjLNAhlwyYW2mgQA7U5WotY= Received: from smtp58.i.mail.ru (smtp58.i.mail.ru [217.69.128.38]) (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 D83F66EC5A for ; Wed, 14 Jul 2021 21:25:59 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D83F66EC5A Received: by smtp58.i.mail.ru with esmtpa (envelope-from ) id 1m3ja3-0007Q7-5h; Wed, 14 Jul 2021 21:25:59 +0300 To: v.shpilevoy@tarantool.org, gorcunov@gmail.com Date: Wed, 14 Jul 2021 21:25:31 +0300 Message-Id: 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: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD97BB0EF39AD2B33D5A52DC40C1D324F80A71B59DA57F828EE182A05F538085040C7DCF4898E1B6C8362EFB15CF8ECC34C774A0ECEF389E5A3D852E5EED5BEFEA1 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7E27C7C60963D4ED9EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063750AD27396E031BA88638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8063E4C71243BFD651F1416C52258E553117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC55D5BE2F85BDEC5FA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352026055571C92BF10FCB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6D635BA3ABDB36C18089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8183A4AFAF3EA6BDC44C234C8B12C006B7A3EB0C8D5FD3BD3A08A84B5EB51D6A878C977BC7BD438B66CB1881A6453793CE9C32612AADDFBE061C61BE10805914D3804EBA3D8E7E5B87ABF8C51168CD8EBDB30B6221521ACED37DC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34524B2D44961BF9C6FF0D0040D56A1BCC42BA0769E67EB4D798E2154073524404990DC51072C13DDC1D7E09C32AA3244C8591B6D7B29529D0BD4EC72B6FB1C6BDC86C126E7119A0FE927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojDdSFIg49M1RCOdk6LP6lAA== X-Mailru-Sender: 3B9A0136629DC9125D61937A2360A446DCF67A6ACA5D040D157B51FC0CFB707802589D0B7D3E543D424AE0EB1F3D1D21E2978F233C3FAE6EE63DB1732555E4A8EE80603BA4A5B0BC112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v4 03/16] 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. Prerequisite #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 c85dc6af3..0b06e5e63 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; @@ -546,6 +565,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. @@ -571,6 +591,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; } @@ -659,6 +680,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) { @@ -696,6 +726,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 6e5d6d04e..991c47698 100644 --- a/src/box/txn_limbo.c +++ b/src/box/txn_limbo.c @@ -306,6 +306,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 7debbc0b9..7151843f4 100644 --- a/src/box/txn_limbo.h +++ b/src/box/txn_limbo.h @@ -315,6 +315,13 @@ txn_limbo_wait_confirm(struct txn_limbo *limbo); int txn_limbo_wait_empty(struct txn_limbo *limbo, double timeout); +/** + * 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)