From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH 19/25] vinyl: prepare write iterator heap comparator for deferred DELETEs Date: Fri, 27 Jul 2018 14:29:59 +0300 Message-Id: <42559d41fef6382a080e3a178fd70f6c18c34612.1532689066.git.vdavydov.dev@gmail.com> In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: In the scope of #2129, we won't delete the overwritten tuple from secondary indexes immediately on REPLACE. Instead we will defer generation of the DELETE statement until the primary index compaction. However, it may happen that the overwritten tuple and the tuple that overwrote it have the same secondary key parts, in which case the deferred DELETE is not needed and should be discarded on secondary index compaction. This patch makes the write iterator heap comparator function discard such useless deferred DELETEs. Note, this patch also removes the code that prioritises terminal statements over UPSERTs in the write iterator, which, according to the comment, may happen only during forced recovery. I don't see why we should do that, even during forced recovery, neither have I managed to find the reason in the commit history, so I dropped this code in order not to overburden the write iterator logic with some esoteric cases. Needed for #2129 --- src/box/vy_write_iterator.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/box/vy_write_iterator.c b/src/box/vy_write_iterator.c index b76c2ccb..7a3537f6 100644 --- a/src/box/vy_write_iterator.c +++ b/src/box/vy_write_iterator.c @@ -244,12 +244,15 @@ heap_less(heap_t *heap, struct heap_node *node1, struct heap_node *node2) if (lsn1 != lsn2) return lsn1 > lsn2; - /** - * LSNs are equal. This may happen only during forced recovery. - * Prioritize terminal (non-UPSERT) statements + /* + * LSNs are equal. This may only happen if one of the statements + * is a deferred DELETE and the overwritten tuple which it is + * supposed to purge has the same key parts as the REPLACE that + * overwrote it. Discard the deferred DELETE as the overwritten + * tuple will be (or has already been) purged by the REPLACE. */ - return (vy_stmt_type(src1->tuple) == IPROTO_UPSERT ? 1 : 0) < - (vy_stmt_type(src2->tuple) == IPROTO_UPSERT ? 1 : 0); + return (vy_stmt_type(src1->tuple) == IPROTO_DELETE ? 1 : 0) < + (vy_stmt_type(src2->tuple) == IPROTO_DELETE ? 1 : 0); } -- 2.11.0