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 D84B16E200; Fri, 18 Jun 2021 00:12:25 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D84B16E200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1623964345; bh=P+pNyNjkJmihbNjKwpAUlKbEWBwJU7UbhnnTxNCIB/Y=; 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=VSehJH5q/OOI/JD65BNe61BXApkS1UZfO6IDC5zrAATXXYdiOHqQVivOV7dySdY5p gIjnHkVITZaMWAUEP8/15YsaXiJI5lWmAGl5MyhOLHsEoPT1ejZFpNLT+4+c5vMHD+ 2j7JE1uroi0iN++o5ma/fGBewYVsujlBqW2YGL5w= Received: from smtp46.i.mail.ru (smtp46.i.mail.ru [94.100.177.106]) (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 864216E207 for ; Fri, 18 Jun 2021 00:08:49 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 864216E207 Received: by smtp46.i.mail.ru with esmtpa (envelope-from ) id 1ltzFo-00046o-LQ; Fri, 18 Jun 2021 00:08:49 +0300 To: v.shpilevoy@tarantool.org, gorcunov@gmail.com Date: Fri, 18 Jun 2021 00:07:41 +0300 Message-Id: <4bdfaee7ba9cc74c6e59798ddbdf94291eb9a844.1623963649.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: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD91C2C07775F13263A7E15E163E5632B0345CA5730AF53AB3C00894C459B0CD1B970054F8585AF0F2B5559A021207C2A6B7FF79ED123BE076C142D0AB2E9B78576 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7195F30236A8D43B4EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006374F638C8F0F4AA0FB8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D815E9323D8C01B1F63D16A5D6EE65C13A117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC55D5BE2F85BDEC5FA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352026055571C92BF10F6FD1C55BDD38FC3FD2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE7532CA1512B81981A9D86F9317F2E7ACD8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE3E3786DD2C77EBDAABA3038C0950A5D36B5C8C57E37DE458B0BC6067A898B09E46D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE7D151390FFDBF6399731C566533BA786AA5CC5B56E945C8DA X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2368A440D3B0F6089093C9A16E5BC824A2A04A2ABAA09D25379311020FFC8D4AD7067FEF890167A54AF36BE3F388E2360 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8183A4AFAF3EA6BDC44C234C8B12C006B7A1E11FAF78CF6E2FBD5E0EA832E5094444F56BF85ED643FEBB1881A6453793CE9C32612AADDFBE061C61BE10805914D3804EBA3D8E7E5B87ABF8C51168CD8EBDBAB5495298CADBD05DC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34987A0E8D235BB534A5CE23CBB0003316937BA3A931E29B452546419CE54955C76BCC0D132666947C1D7E09C32AA3244C737FC98C52254A44AF8E08E98244B00F3FD9C8CA1B0515E0927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXjymZAW17GbhBpC19xm/6eX X-Mailru-Sender: 583F1D7ACE8F49BD9DF7A8DAE6E2B08A18ACA3F9016771415900E9A3C6F09704AB09C8E55D095759424AE0EB1F3D1D21E2978F233C3FAE6EE63DB1732555E4A8EE80603BA4A5B0BC112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v2 7/8] 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 b5af02479..482e17c8f 100644 --- a/src/box/txn_limbo.c +++ b/src/box/txn_limbo.c @@ -296,6 +296,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)