From patchwork Mon May 13 08:47:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13663209 Received: from wfout2-smtp.messagingengine.com (wfout2-smtp.messagingengine.com [64.147.123.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22E471474C8 for ; Mon, 13 May 2024 08:47:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590027; cv=none; b=anpXtSovIfVYestvyFxJaoAfZpplgdqCuypG6siRlR4BfmxStR1RzG+FJdGBDHhTGngPOORMHCmzcMQfn3FBKDSLj+PL1g2V8wYK9oi/s8HiGQnKrRXFnYjM3kDUdj8tTfKYKa6iWwCw5LW84vqsAbGKdojg8BVEYD9bv/4L9xo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590027; c=relaxed/simple; bh=rb2NdnGlKfCsCakwgWs2RkSoUgQ8P2ViELBsToXG+Z8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fE2YsUPKH5rw87M8/Da3JjT1oJGfnCc/6x8w0QqukVh9pNOPptHQGCBfwaqMjpamR++H1oqe5cqbjUEzNKqZT8u5j6Rt1OP2SdXkF5+D00Gh7Wmv2Myc6d50ofVdclV5bXGGCMU/DSM2ic1p3cY1c8fbYLIlLytMeysTGyzM6bg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=jjF9ysCK; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=a2NEG8QT; arc=none smtp.client-ip=64.147.123.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="jjF9ysCK"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="a2NEG8QT" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.west.internal (Postfix) with ESMTP id 4A0FA1C00065; Mon, 13 May 2024 04:47:05 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 13 May 2024 04:47:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715590024; x=1715676424; bh=JGVujBWaB5 2M7VINiLy8vXOKVcJdNvgjWgx43qn9l3Y=; b=jjF9ysCKRVsjPvILGM6BkB7G7W HupdXvegyLHdGK7R0AKk9fXRnVJXw1Sk9NwP5i+VxZtR1jat1CTZ+dNlBfpAlSmX bFuryb25zKVH/XfkTSH41O7u7gilmAG6KB9VaZ+Ef3S1XhZ1pg5M6RbPaVBj5+xJ 78sXGlsnDlm02SZUhW2YT0vCEwdc+1jx5v2rIuEXjf0w8diLmM1CbVa2kEGHLvIE ojkla/ffdofWRdzPHrAHc7UW6SRS2bkYlNkpPDfSmXS2c6egZ+/UrBf7XLuGiFji 8p6WNAzHa/VRD0fMkxYLiHVrMnmVP41j7iOsEfBoPxB3Y9AYbLa94mxEd/Lg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715590024; x=1715676424; bh=JGVujBWaB52M7VINiLy8vXOKVcJd NvgjWgx43qn9l3Y=; b=a2NEG8QTuPOwD1FX5Ucada99qEaCSgHSUOAhWYO1ganR Q5y7t+HOuAwULupIBljDZh3Kiryo3Ki12NOD+Df0T2Wu1NqcRveCwDAnkksZiqOy Cv9Z5jpB4WW8h2QJU3/zCUCdHnJtjc2GACeoaiMW+/wkpYHxdJbfMkoob/QAVUqr YroTLNIvYI2YUGjkUMGtR8OameYrUSNbrylXwP63nDtQlTpBS+pMyhNrVwB7PfnC XqHDUKGJcyTMn6vtSDxEH04rk9YGdj7KrPeZFquk2TYVUb3uSk6NCu/xqFurIVpa wVLVKNZKmd3pIDxhlFrEfAC+bj6UemkUH7dNwD+Rrg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeggedgtdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 May 2024 04:47:03 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 7d82619f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 13 May 2024 08:46:44 +0000 (UTC) Date: Mon, 13 May 2024 10:47:01 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Justin Tobler Subject: [PATCH v2 01/13] reftable/block: use `size_t` to track restart point index Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The function `block_reader_restart_offset()` gets the offset of the `i`th restart point. `i` is a signed integer though, which is certainly not the correct type to track indices like this. Furthermore, both callers end up passing a `size_t`. Refactor the code to use a `size_t` instead. Signed-off-by: Patrick Steinhardt --- reftable/block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reftable/block.c b/reftable/block.c index 5942cb4053..00030eee06 100644 --- a/reftable/block.c +++ b/reftable/block.c @@ -326,9 +326,9 @@ int block_reader_first_key(const struct block_reader *br, struct strbuf *key) return 0; } -static uint32_t block_reader_restart_offset(const struct block_reader *br, int i) +static uint32_t block_reader_restart_offset(const struct block_reader *br, size_t idx) { - return get_be24(br->restart_bytes + 3 * i); + return get_be24(br->restart_bytes + 3 * idx); } void block_iter_seek_start(struct block_iter *it, const struct block_reader *br) From patchwork Mon May 13 08:47:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13663210 Received: from wfout2-smtp.messagingengine.com (wfout2-smtp.messagingengine.com [64.147.123.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2208147C90 for ; Mon, 13 May 2024 08:47:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590032; cv=none; b=jjHFOz/Eatnd4G4mpXIoX2fIqijcLCpV19RKTVz1a2Sck92Sy+OotchZeYXh4OjCCL/Qwn7KIFKFFPdaa70wOdgT8O0XpAlwvzofmjijGMVGjWXVMHEWRUYPtobmm42seN5nD2hXTfmkiNXyPsDPPAdLcz/2Z7l7KBRN+9bJIAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590032; c=relaxed/simple; bh=2l7pvMDNRTEdXVtuOXwNH+EVkqdoHZmL2btydQLH7B0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TFTS1/xtHxYOdVLCYl+Wu9VZpwmUUQ6AOdXOqYfdFOtUKGP4QaiP0a5gXYVM6KXjhYcE97SLun1hhDA7SZ52blzHa/EFxpHfpUtsddzir8gf9Lh+ZteooHRZ1VggZq/lI+ayt7tF2i2eTQ9J18txvSTRabr7FDUjU+6K6qKaX7k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=KTN8AMVv; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=KK+7GBQp; arc=none smtp.client-ip=64.147.123.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="KTN8AMVv"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="KK+7GBQp" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.west.internal (Postfix) with ESMTP id 1B21C1C00065; Mon, 13 May 2024 04:47:10 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 13 May 2024 04:47:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715590029; x=1715676429; bh=N0+vRGR+ww 7zn1Oyq8eSjpiWvSjEmsRPvOH18PkQMYw=; b=KTN8AMVvATtFf+sZPVVm7g4tav PRWoFKD0Ma3D7IA4DUNDImloBNqFSpFwcQg1h+jCMq/8y6hm7LItqi26oufJ5+ov TDNZHlsg4hM8IM9q82KWwhn8Uih66hkJ88M4LbrX1R+nVUYEP8BiRqlQ+cyOcPPl Qu8mR0qjzYH7Gr8l8Ky+BNeWmLYiXgReoms3OvN/0Nht2vk24RK2gyzDN2CZwA8W 2vjDOkUKValI6KaE2oUU3zW6to3lcPtyltVj7n+T60I0jp6f7t0r0aTqqFZ/36v3 1WQEud93U+vB+5FVSE9MUnb003AuNNNlo3Z5QTwB6A+UsMW43roqLZK+8ceA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715590029; x=1715676429; bh=N0+vRGR+ww7zn1Oyq8eSjpiWvSjE msRPvOH18PkQMYw=; b=KK+7GBQpWK+qnJCPCx1bZ78VIITgF0ozZhDCr/cEM8Rq ChsEfNrsNGHI/x7IKl/7u1H72UbuUtfZ9fcOnTb/AI0yL9ZE+SsHMh6A5pgSz9Ef Ovcv2brzWRpjLuTPw6F9Tt1Uy+kbEeRbBvmtIb0I/6/1WT8ArTkfZbK9YFo7NCF5 Nj2yYr0O4v+KgOgj+WQn4hp/a3rZd5D9a+4V7vbQElLWxyCoMkRUpcISudNHYOAY yvYUxDUyY/14lii8taUcLSh2rIH8QMe7xmbthk1cCxnUqBSV0Sw0JcSvsssULV6x jlxtiPygwkYq9rga4MatoUrQyxWUrQa0cg/jgGmytA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeggedgtdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 May 2024 04:47:08 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id b3477757 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 13 May 2024 08:46:50 +0000 (UTC) Date: Mon, 13 May 2024 10:47:06 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Justin Tobler Subject: [PATCH v2 02/13] reftable/reader: avoid copying index iterator Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: When doing an indexed seek we need to walk down the multi-level index until we finally hit a record of the desired indexed type. This loop performs a copy of the index iterator on every iteration, which is both hard to understand and completely unnecessary. Refactor the code so that we use a single iterator to walk down the indices, only. Note that while this should improve performance, the improvement is negligible in all but the most unreasonable repositories. This is because the effect is only really noticeable when we have to walk down many levels of indices, which is not something that a repository would typically have. So the motivation for this change is really only about readability. Signed-off-by: Patrick Steinhardt --- reftable/reader.c | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/reftable/reader.c b/reftable/reader.c index 481dff10d4..6bfadcad71 100644 --- a/reftable/reader.c +++ b/reftable/reader.c @@ -510,13 +510,11 @@ static int reader_seek_indexed(struct reftable_reader *r, .type = BLOCK_TYPE_INDEX, .u.idx = { .last_key = STRBUF_INIT }, }; - struct table_iter index_iter = TABLE_ITER_INIT; - struct table_iter empty = TABLE_ITER_INIT; - struct table_iter next = TABLE_ITER_INIT; + struct table_iter ti = TABLE_ITER_INIT, *malloced; int err = 0; reftable_record_key(rec, &want_index.u.idx.last_key); - err = reader_start(r, &index_iter, reftable_record_type(rec), 1); + err = reader_start(r, &ti, reftable_record_type(rec), 1); if (err < 0) goto done; @@ -526,7 +524,7 @@ static int reader_seek_indexed(struct reftable_reader *r, * highest layer that identifies the relevant index block as well as * the record inside that block that corresponds to our wanted key. */ - err = reader_seek_linear(&index_iter, &want_index); + err = reader_seek_linear(&ti, &want_index); if (err < 0) goto done; @@ -552,44 +550,36 @@ static int reader_seek_indexed(struct reftable_reader *r, * all levels of the index only to find out that the key does * not exist. */ - err = table_iter_next(&index_iter, &index_result); + err = table_iter_next(&ti, &index_result); if (err != 0) goto done; - err = reader_table_iter_at(r, &next, index_result.u.idx.offset, - 0); + err = reader_table_iter_at(r, &ti, index_result.u.idx.offset, 0); if (err != 0) goto done; - err = block_iter_seek_key(&next.bi, &next.br, &want_index.u.idx.last_key); + err = block_iter_seek_key(&ti.bi, &ti.br, &want_index.u.idx.last_key); if (err < 0) goto done; - if (next.typ == reftable_record_type(rec)) { + if (ti.typ == reftable_record_type(rec)) { err = 0; break; } - if (next.typ != BLOCK_TYPE_INDEX) { + if (ti.typ != BLOCK_TYPE_INDEX) { err = REFTABLE_FORMAT_ERROR; - break; + goto done; } - - table_iter_close(&index_iter); - index_iter = next; - next = empty; } - if (err == 0) { - struct table_iter *malloced = reftable_calloc(1, sizeof(*malloced)); - *malloced = next; - next = empty; - iterator_from_table_iter(it, malloced); - } + REFTABLE_ALLOC_ARRAY(malloced, 1); + *malloced = ti; + iterator_from_table_iter(it, malloced); done: - table_iter_close(&next); - table_iter_close(&index_iter); + if (err) + table_iter_close(&ti); reftable_record_release(&want_index); reftable_record_release(&index_result); return err; From patchwork Mon May 13 08:47:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13663211 Received: from wfhigh5-smtp.messagingengine.com (wfhigh5-smtp.messagingengine.com [64.147.123.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE65B147C88 for ; Mon, 13 May 2024 08:47:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590038; cv=none; b=mHH5ZhPP6toMB5S3U8Nnlc98mlFgG5pyIlCOKwaVT26tSQ0jlCapH8/i7EIMoEnyE63ZlipEDqQTJcImTdrahxbOnJjNada22nI/2lDs6PezQCWuRbP9ngpKrahEZ31Hf0fO689s11F8Sr1aG4+fUz/FGNMdiCU47vCC5LupwlQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590038; c=relaxed/simple; bh=RkT5upg2N3jlXzXX1utzuF3wWYpP21nbkZZFBAdhQ6c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Ibl/Q9gHjw4xWESloBGFnakJCLXOuJ3yx7c0qV6glagzWBxtAC6nUlaPkV45DF+h6393uIa8Gdw6VpbMrPZgJRmbB+8nWmbYNOa1qOpV1h1j62xLA5TcGhqy74aE1uVnLv2qKzC6RMYhc1EpysxEribCaq5VGk/nO8r00ETyXZE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=J8YRXz0B; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=VSds1IU0; arc=none smtp.client-ip=64.147.123.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="J8YRXz0B"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="VSds1IU0" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfhigh.west.internal (Postfix) with ESMTP id EA5B0180013C; Mon, 13 May 2024 04:47:15 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Mon, 13 May 2024 04:47:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715590035; x=1715676435; bh=kL+ieS8zjx 1w8se1Ln+W441riKCQleRbZAJG/7Uhnn0=; b=J8YRXz0BGNWx7ErHfAt1auQn1Z /KcNhpar5Skdb5vbpeC2LYQ5Flle3fM6pf9AbZ8wtWzcAJUj1IrJRFp0OrbfvQlU z+eQPI/ayOLUrVwN2LxDQ5euoq5janRgshnEOVMHMnm1Qbp/nx593LPoQnNDcdlt ft8+MKi6u+ANTfogOyw7I/MLayOFY8VeVn+KGM/1YVx8jJi1sHEZ8Au6jiVmvbiY /3Y4MUl5vNM0oK2pvCrEmMQUpt+m6IiWOwJegPCb59FGLgAfK39wzCORt9XyszIv 30ImRi6mgMj/S5NlGxDH07i/HK9oHGjEQ0yJ1CDdefiJXZU8VDy8Fdhd6Wcg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715590035; x=1715676435; bh=kL+ieS8zjx1w8se1Ln+W441riKCQ leRbZAJG/7Uhnn0=; b=VSds1IU0jQdNj0znodBcWrW/BgcjQz73Mr7dwHmAkBFF DNA9Kr2Vak9Gm95LBvQQFpjY1BffI6K8I0b2NnH8Uj8wdASyomiL/s9tZ0aaQBrV Dt/G9JQ8kBSOkzYmvWyCZEV0K0o/6kSXKQJm2/z08f/XzFd8uqrQpcQRCB+20E+g XWo6ZvjefFsllPFZEcQXoUMwxhvE9bHCpWga5ofWjFj+hMLNKyncyyxfj0JM8dVM N/fniiocfzFLMqJ/USpFsxmtpJznL3SbylfmLsj3kioCg5aqmKLSAyyibcGCOubl me5fAEGt6GTez6p3uPT8qYvN4taz4IOQX9y6gJH+FQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeggedgtdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 May 2024 04:47:14 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 78277313 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 13 May 2024 08:46:55 +0000 (UTC) Date: Mon, 13 May 2024 10:47:11 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Justin Tobler Subject: [PATCH v2 03/13] reftable/reader: unify indexed and linear seeking Message-ID: <716863a580f9e1ef8ea796c25c97e50c63585a7b.1715589670.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: In `reader_seek_internal()` we either end up doing an indexed seek when there is one or a linear seek otherwise. These two code paths are disjunct without a good reason, where the indexed seek will cause us to exit early. Refactor the two code paths such that it becomes possible to share a bit more code between them. Signed-off-by: Patrick Steinhardt --- reftable/reader.c | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/reftable/reader.c b/reftable/reader.c index 6bfadcad71..cf7f126d8d 100644 --- a/reftable/reader.c +++ b/reftable/reader.c @@ -425,7 +425,7 @@ static int reader_seek_linear(struct table_iter *ti, struct strbuf want_key = STRBUF_INIT; struct strbuf got_key = STRBUF_INIT; struct reftable_record rec; - int err = -1; + int err; reftable_record_init(&rec, reftable_record_type(want)); reftable_record_key(want, &want_key); @@ -499,8 +499,8 @@ static int reader_seek_linear(struct table_iter *ti, return err; } -static int reader_seek_indexed(struct reftable_reader *r, - struct reftable_iterator *it, +static int reader_seek_indexed(struct table_iter *ti, + struct reftable_reader *r, struct reftable_record *rec) { struct reftable_record want_index = { @@ -510,13 +510,9 @@ static int reader_seek_indexed(struct reftable_reader *r, .type = BLOCK_TYPE_INDEX, .u.idx = { .last_key = STRBUF_INIT }, }; - struct table_iter ti = TABLE_ITER_INIT, *malloced; - int err = 0; + int err; reftable_record_key(rec, &want_index.u.idx.last_key); - err = reader_start(r, &ti, reftable_record_type(rec), 1); - if (err < 0) - goto done; /* * The index may consist of multiple levels, where each level may have @@ -524,7 +520,7 @@ static int reader_seek_indexed(struct reftable_reader *r, * highest layer that identifies the relevant index block as well as * the record inside that block that corresponds to our wanted key. */ - err = reader_seek_linear(&ti, &want_index); + err = reader_seek_linear(ti, &want_index); if (err < 0) goto done; @@ -550,36 +546,30 @@ static int reader_seek_indexed(struct reftable_reader *r, * all levels of the index only to find out that the key does * not exist. */ - err = table_iter_next(&ti, &index_result); + err = table_iter_next(ti, &index_result); if (err != 0) goto done; - err = reader_table_iter_at(r, &ti, index_result.u.idx.offset, 0); + err = reader_table_iter_at(r, ti, index_result.u.idx.offset, 0); if (err != 0) goto done; - err = block_iter_seek_key(&ti.bi, &ti.br, &want_index.u.idx.last_key); + err = block_iter_seek_key(&ti->bi, &ti->br, &want_index.u.idx.last_key); if (err < 0) goto done; - if (ti.typ == reftable_record_type(rec)) { + if (ti->typ == reftable_record_type(rec)) { err = 0; break; } - if (ti.typ != BLOCK_TYPE_INDEX) { + if (ti->typ != BLOCK_TYPE_INDEX) { err = REFTABLE_FORMAT_ERROR; goto done; } } - REFTABLE_ALLOC_ARRAY(malloced, 1); - *malloced = ti; - iterator_from_table_iter(it, malloced); - done: - if (err) - table_iter_close(&ti); reftable_record_release(&want_index); reftable_record_release(&index_result); return err; @@ -595,15 +585,15 @@ static int reader_seek_internal(struct reftable_reader *r, struct table_iter ti = TABLE_ITER_INIT, *p; int err; - if (idx > 0) - return reader_seek_indexed(r, it, rec); - - err = reader_start(r, &ti, reftable_record_type(rec), 0); + err = reader_start(r, &ti, reftable_record_type(rec), !!idx); if (err < 0) goto out; - err = reader_seek_linear(&ti, rec); - if (err < 0) + if (idx) + err = reader_seek_indexed(&ti, r, rec); + else + err = reader_seek_linear(&ti, rec); + if (err) goto out; REFTABLE_ALLOC_ARRAY(p, 1); From patchwork Mon May 13 08:47:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13663212 Received: from wfhigh5-smtp.messagingengine.com (wfhigh5-smtp.messagingengine.com [64.147.123.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA92114830A for ; Mon, 13 May 2024 08:47:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590042; cv=none; b=ds4xS8Yo6n8RM+8aby4wMeXVKEKemNJUndcYVUzuoP4JcwVeSziRaVQ4OOPu5hZMhuanMFExosH5JcD6W4pUSnC+58wGiBNRhBimWnmCMy51S5y9EXlmmroec3w72fo691j61ImxIihiqdLH4q/mRioZm1fjRb/5I0VtJJyNAK0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590042; c=relaxed/simple; bh=hLnkd0nTh24UmyITmW2LECpNMFe2VTLm4cxnAO5TAmU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FbMnizck95z3uOj3dQoQ84cr5oRMDtK1PODGyUdZ9EnBnQuuluedD53KIAXW+UqwnVD3QyNYCoLykNVsYlXqjpeLiJQldQpuZO46W+LXRPM3a5HeiXX1njK+5Gvbam6Hk8BTJWqYljSBIDqLf4ikvkh5JxEu2jSYebaG0BxZHSg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=E01LaFkW; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=RNi8+u8g; arc=none smtp.client-ip=64.147.123.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="E01LaFkW"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="RNi8+u8g" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.west.internal (Postfix) with ESMTP id B732318000CC; Mon, 13 May 2024 04:47:19 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 13 May 2024 04:47:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715590039; x=1715676439; bh=94L/0XEgrN 1oBxW8oHCPQmBan05P7btQXrzyrH3u7Nk=; b=E01LaFkW6ZA+edS63vKcz7vtY2 Sf0+dt5PZiL24gYp5f6lKqIUVPcEHe6at/wcn4hzODT2tGO+0hw6Suzchy6eXyt4 lm9As8RrZKqHz2otoB2+kTACMMD+UpdmpbIqcdWDuuUeRzfwXct4I+rkOcH9sGLY +Jb0324AXdc2/Uqaas1LWncDctwh7gsCp9f9tYxKTNDqtVI9PmGmUs+5k4gHq34Y 33VBNzmbSrMrNh2D4h8Lg6dwL3469dNHJH2bJdvtaio/Zcgo+MuTniWuhPtuBBdE JWUSpS2KP8ngzsuJ05yhiUynV6vsUMHAggunfEb7WoWNPcoESgAvGmTHYWhQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715590039; x=1715676439; bh=94L/0XEgrN1oBxW8oHCPQmBan05P 7btQXrzyrH3u7Nk=; b=RNi8+u8gGEobWG0Kdb7Sp8/HGsWotD5d6M4mjkNmmNLu ei73s/Mfd3PaFmz8W2CpQSesKeODJYAeg6QCtXFwMDeMOzDyDdWJrojjUizdhKQ5 /mcKH6QpiizIOpdOw6T3zxD24JKUWBR0hNMF2ldmRx9jAWMv8FYseLuA9PDwXMzF wCxOZErFxfriZWOCxyzSKgrsytzyhk1B/Y+2tIyRcnuVrsk3hHJX8v9vH1t3y3j0 xoK+VDbJmvCGTdX6M2mf80mIYbHzXdREwf5KfIdUtjmj5lphTqowmo7Ag+qh5Gms ecr4dgJdY8IsG23xHoXpl20UDJ6qCV2OOeq6fQ9vjg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeggedgtdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 May 2024 04:47:18 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id eb810813 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 13 May 2024 08:47:00 +0000 (UTC) Date: Mon, 13 May 2024 10:47:16 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Justin Tobler Subject: [PATCH v2 04/13] reftable/reader: separate concerns of table iter and reftable reader Message-ID: <91db2f18c105611bc85fa07fa6eb33ba600e742a.1715589670.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: In "reftable/reader.c" we implement two different interfaces: - The reftable reader contains the logic to read reftables. - The table iterator is used to iterate through a single reftable read by the reader. The way those two types are used in the code is somewhat confusing though because seeking inside a table is implemented as if it was part of the reftable reader, even though it is ultimately more of a detail implemented by the table iterator. Make the boundary between those two types clearer by renaming functions that seek records in a table such that they clearly belong to the table iterator's logic. Signed-off-by: Patrick Steinhardt --- reftable/reader.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/reftable/reader.c b/reftable/reader.c index cf7f126d8d..b210753441 100644 --- a/reftable/reader.c +++ b/reftable/reader.c @@ -386,9 +386,8 @@ static void iterator_from_table_iter(struct reftable_iterator *it, it->ops = &table_iter_vtable; } -static int reader_table_iter_at(struct reftable_reader *r, - struct table_iter *ti, uint64_t off, - uint8_t typ) +static int table_iter_seek_to(struct table_iter *ti, struct reftable_reader *r, + uint64_t off, uint8_t typ) { int err; @@ -403,8 +402,8 @@ static int reader_table_iter_at(struct reftable_reader *r, return 0; } -static int reader_start(struct reftable_reader *r, struct table_iter *ti, - uint8_t typ, int index) +static int table_iter_seek_start(struct table_iter *ti, struct reftable_reader *r, + uint8_t typ, int index) { struct reftable_reader_offsets *offs = reader_offsets_for(r, typ); uint64_t off = offs->offset; @@ -416,11 +415,11 @@ static int reader_start(struct reftable_reader *r, struct table_iter *ti, typ = BLOCK_TYPE_INDEX; } - return reader_table_iter_at(r, ti, off, typ); + return table_iter_seek_to(ti, r, off, typ); } -static int reader_seek_linear(struct table_iter *ti, - struct reftable_record *want) +static int table_iter_seek_linear(struct table_iter *ti, + struct reftable_record *want) { struct strbuf want_key = STRBUF_INIT; struct strbuf got_key = STRBUF_INIT; @@ -499,9 +498,8 @@ static int reader_seek_linear(struct table_iter *ti, return err; } -static int reader_seek_indexed(struct table_iter *ti, - struct reftable_reader *r, - struct reftable_record *rec) +static int table_iter_seek_indexed(struct table_iter *ti, + struct reftable_record *rec) { struct reftable_record want_index = { .type = BLOCK_TYPE_INDEX, .u.idx = { .last_key = STRBUF_INIT } @@ -520,7 +518,7 @@ static int reader_seek_indexed(struct table_iter *ti, * highest layer that identifies the relevant index block as well as * the record inside that block that corresponds to our wanted key. */ - err = reader_seek_linear(ti, &want_index); + err = table_iter_seek_linear(ti, &want_index); if (err < 0) goto done; @@ -550,7 +548,7 @@ static int reader_seek_indexed(struct table_iter *ti, if (err != 0) goto done; - err = reader_table_iter_at(r, ti, index_result.u.idx.offset, 0); + err = table_iter_seek_to(ti, ti->r, index_result.u.idx.offset, 0); if (err != 0) goto done; @@ -585,14 +583,14 @@ static int reader_seek_internal(struct reftable_reader *r, struct table_iter ti = TABLE_ITER_INIT, *p; int err; - err = reader_start(r, &ti, reftable_record_type(rec), !!idx); + err = table_iter_seek_start(&ti, r, reftable_record_type(rec), !!idx); if (err < 0) goto out; if (idx) - err = reader_seek_indexed(&ti, r, rec); + err = table_iter_seek_indexed(&ti, rec); else - err = reader_seek_linear(&ti, rec); + err = table_iter_seek_linear(&ti, rec); if (err) goto out; @@ -742,7 +740,7 @@ static int reftable_reader_refs_for_unindexed(struct reftable_reader *r, int err; *ti = ti_empty; - err = reader_start(r, ti, BLOCK_TYPE_REF, 0); + err = table_iter_seek_start(ti, r, BLOCK_TYPE_REF, 0); if (err < 0) { reftable_free(ti); return err; From patchwork Mon May 13 08:47:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13663213 Received: from wfout2-smtp.messagingengine.com (wfout2-smtp.messagingengine.com [64.147.123.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A5CB1482E6 for ; Mon, 13 May 2024 08:47:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590047; cv=none; b=EY5ugYDgsJropnl36d9I7dCavGYGL4cPsRskrj8jJoF5C1QoK0VToqccuMmDbMjRShLMn9ITI+Zr0YVS07jJ3DTvA9Hpn2JAhOTN1UhaHQ0Dnw8X74YGF2OHTJyt9Y3wH5w3zxO7wy2FzOqf2cZSq5ysnCv7USMUqAGLTvOkSdE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590047; c=relaxed/simple; bh=rj6dzg4uRBPAaVs4Wp1op0P7ZJ7bNZZvMDVYJp6YLSw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qGzLem6phyVV+6F+OmCbcUNRnueTM+FPJJb7fA4ZQc0zKnEBM0Eai2Oz7qg3UCtFpBDOVdvvGQ1vuMMTnMoi/+FxdQxg2NyaQYs3kLf9ME5YNPfK0jOTYimiO5nrP6NvovdMaTAbEM08fBq4zUWScchGwx1Iu6s8NZ8U2KkNnc0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=nHt1dNNc; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=dxYlDRZ5; arc=none smtp.client-ip=64.147.123.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="nHt1dNNc"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="dxYlDRZ5" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.west.internal (Postfix) with ESMTP id B3B281C00077; Mon, 13 May 2024 04:47:25 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 13 May 2024 04:47:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715590045; x=1715676445; bh=cB4a/qLH55 OAHnnBYi6RmwJT0pUx5JfEMHrKR4svJLE=; b=nHt1dNNcWFaU70enRdD2WLPyoC j/uXe1QxxyFZ6z40lSCWuHMeMvmf30LVRv4WtEAEMd0GkcHsUhpHdCV6UY5tZrQz aOEINBytOy0104Z0koospDpSq6uf32oS5Sw4GP8vp+DE/JvWLdYL4r3J25lSjo9w kZOIzEnh7m9WtmwP5BIX84rR1qKI6Wcjgb4LMBMfMOxunXCEZjUv1E+jwcnc9QvF IMYnKyB7rRjDZuPvM/x13zsRibvG/kyD5MeNzqxhMaayg1sPWt1RQMl0MRMpEw8d YkVXrwn7yYh6aRL/LxkRz3J0K8228RFn2sWMZptv4BKXMRHeD0VZlt+Rnryg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715590045; x=1715676445; bh=cB4a/qLH55OAHnnBYi6RmwJT0pUx 5JfEMHrKR4svJLE=; b=dxYlDRZ5BcN2HULd87MZOdg8bP2iZAeqyyW7m0MdzfSR 44GK69ySotqKfYoibwugkmNmKfv/58dMnLlkVCDsAgjvyEePY/2CZJYKOR2R67UT vMYsoVvHEaHhCV/5oK9tua2nYkP4j+aQfj/7NLWaqLypaQTC2reYGe0sZQ20cTb0 JS+NjudL2KJOc2Ucw4GF+E5jmMPR25SphVz04WvRO35hFh2YD4zQjdi3uu5W5n20 REcaRahkmWTL7FnjKNHzw+wrdIZ5iD7UL5Sbmfdozo0SAHPb9SlflgDC3oO/WCgE bKlgSaLBzS07CBAeylsKBCc59yoJts3469n8ImEssw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeggedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 May 2024 04:47:24 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 64c3abdd (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 13 May 2024 08:47:05 +0000 (UTC) Date: Mon, 13 May 2024 10:47:21 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Justin Tobler Subject: [PATCH v2 05/13] reftable/reader: inline `reader_seek_internal()` Message-ID: <4d498ef3426877c703bababaa743dd5613ba5839.1715589670.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We have both `reader_seek()` and `reader_seek_internal()`, where the former function only exists so that we can exit early in case the given table has no records of the sought-after type. Merge these two functions into one. Signed-off-by: Patrick Steinhardt --- reftable/reader.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/reftable/reader.c b/reftable/reader.c index b210753441..c3541e2c43 100644 --- a/reftable/reader.c +++ b/reftable/reader.c @@ -573,21 +573,25 @@ static int table_iter_seek_indexed(struct table_iter *ti, return err; } -static int reader_seek_internal(struct reftable_reader *r, - struct reftable_iterator *it, - struct reftable_record *rec) +static int reader_seek(struct reftable_reader *r, struct reftable_iterator *it, + struct reftable_record *rec) { - struct reftable_reader_offsets *offs = - reader_offsets_for(r, reftable_record_type(rec)); - uint64_t idx = offs->index_offset; + uint8_t typ = reftable_record_type(rec); + struct reftable_reader_offsets *offs = reader_offsets_for(r, typ); struct table_iter ti = TABLE_ITER_INIT, *p; int err; - err = table_iter_seek_start(&ti, r, reftable_record_type(rec), !!idx); + if (!offs->is_present) { + iterator_set_empty(it); + return 0; + } + + err = table_iter_seek_start(&ti, r, reftable_record_type(rec), + !!offs->index_offset); if (err < 0) goto out; - if (idx) + if (offs->index_offset) err = table_iter_seek_indexed(&ti, rec); else err = table_iter_seek_linear(&ti, rec); @@ -604,20 +608,6 @@ static int reader_seek_internal(struct reftable_reader *r, return err; } -static int reader_seek(struct reftable_reader *r, struct reftable_iterator *it, - struct reftable_record *rec) -{ - uint8_t typ = reftable_record_type(rec); - - struct reftable_reader_offsets *offs = reader_offsets_for(r, typ); - if (!offs->is_present) { - iterator_set_empty(it); - return 0; - } - - return reader_seek_internal(r, it, rec); -} - int reftable_reader_seek_ref(struct reftable_reader *r, struct reftable_iterator *it, const char *name) { From patchwork Mon May 13 08:47:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13663214 Received: from wfout2-smtp.messagingengine.com (wfout2-smtp.messagingengine.com [64.147.123.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4918A1482E6 for ; Mon, 13 May 2024 08:47:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590053; cv=none; b=lz8hsq+qc6iZf4Ri7fca8KD1InUjEEdXNVQ6msiNgg8EMOHITuTcHBBe7jFakqszNM+khI0+VBRwotehglzDLkrEPI+rkQl58l4CJ9S04jWF5Giwk+W0SrYu9sGKujwsTrsoy+N9fl4katdCcULh1oCyv51d5wsAAk/N0kc2hxI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590053; c=relaxed/simple; bh=gY7j83ePQZL58jfWTR/XSPVNq2YXY6qOsxgGXP1AF4Q=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=k4zSBMjULxI8K0jrZV8I61CxIbFkliosw6FE1qr8WAIWx0V8a9JW6lGUNAimN+CnbmsdzmMEcSCZ78le8ZAdcyAeVCUxKmC376E9UpyaiWWR4SrL+wBd66giEOoXjONU6AwwpUYHuzttOE/aN05jLlTfMt6cmDjSLwxvpvT5qSo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=amWzfYKm; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=I64xuKKv; arc=none smtp.client-ip=64.147.123.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="amWzfYKm"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="I64xuKKv" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.west.internal (Postfix) with ESMTP id 826851C000BF; Mon, 13 May 2024 04:47:30 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 13 May 2024 04:47:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715590050; x=1715676450; bh=+D9UioQqm0 +0Gf9xCYcI+jufPJVzjCMA0cd1YYXbZqA=; b=amWzfYKmVVSeU18wqhINfYjzV+ ayKrCVoSn900lAwL4B47HDxVX9BMz6HjywRkcpFXOR3IYIE61dgY2ZWlgnPyZKvg mW0AyySrVRryLGHF5bzbiuFhYZg/PVsd2jqoP5oHJlHFhjOAZza3jM7nUXfakRZC XY3eGFXoI+EVrcvp27vb0q8l0d6FIRoZsY4jlde9C5fuOLcKuV6pwoB1+scSyiSo c/UYPv5GjmcTG1XcKPezQyLJFz89ZKHa4Xb6Vhgrhe0nXoQzeJZZc4RF1nfIQyYj lRSoRO2r5djIzEw4eqwuHkKOJTScvsXvE9SESmljKUQpFcPiG6R4jTuHPrag== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715590050; x=1715676450; bh=+D9UioQqm0+0Gf9xCYcI+jufPJVz jCMA0cd1YYXbZqA=; b=I64xuKKvro4WmSWZqIDa2wzdNtW+IYVuHId912YFQnVP aFH69kw69fn9bYedyB+PmI8y3iu+7iIxpmZ7LMwyG/to8AFdfW6muRSBeB6DKMco Jw0D2MmIq7BHG9iEcOlWhHemYBF5vPexxwj0KsxZJb0OQ3I0GBsp9VCpfXH9UaHg qP5qCGWwsWJs8va0n7vVf/bE73d2PHpFvfSTsq8Rn+vmQoUQy9wxtMK7AHjRBeNP ktFZyRvGjjR154EjjlneP2XYTtvmyFZzxvl5lP94qmZngZY58bSqxj6mxhMYg0ZM K7tTBZN70UYyyrt2i4UBA7R+CJgLzgzfIbYz5VDVPQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeggedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 May 2024 04:47:29 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 36548134 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 13 May 2024 08:47:10 +0000 (UTC) Date: Mon, 13 May 2024 10:47:26 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Justin Tobler Subject: [PATCH v2 06/13] reftable/reader: set up the reader when initializing table iterator Message-ID: <5a10a115841512a46e4d3a3d3713e5532facdb39.1715589670.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: All the seeking functions accept a `struct reftable_reader` as input such that they can use the reader to look up the respective blocks. Refactor the code to instead set up the reader as a member of `struct table_iter` during initialization such that we don't have to pass the reader on every single call. This step is required to move seeking of records into the generic `struct reftable_iterator` infrastructure. Signed-off-by: Patrick Steinhardt --- reftable/reader.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/reftable/reader.c b/reftable/reader.c index c3541e2c43..021608f638 100644 --- a/reftable/reader.c +++ b/reftable/reader.c @@ -224,8 +224,14 @@ struct table_iter { struct block_iter bi; int is_finished; }; -#define TABLE_ITER_INIT { \ - .bi = BLOCK_ITER_INIT \ + +static int table_iter_init(struct table_iter *ti, struct reftable_reader *r) +{ + struct block_iter bi = BLOCK_ITER_INIT; + memset(ti, 0, sizeof(*ti)); + ti->r = r; + ti->bi = bi; + return 0; } static int table_iter_next_in_block(struct table_iter *ti, @@ -386,26 +392,23 @@ static void iterator_from_table_iter(struct reftable_iterator *it, it->ops = &table_iter_vtable; } -static int table_iter_seek_to(struct table_iter *ti, struct reftable_reader *r, - uint64_t off, uint8_t typ) +static int table_iter_seek_to(struct table_iter *ti, uint64_t off, uint8_t typ) { int err; - err = reader_init_block_reader(r, &ti->br, off, typ); + err = reader_init_block_reader(ti->r, &ti->br, off, typ); if (err != 0) return err; - ti->r = r; ti->typ = block_reader_type(&ti->br); ti->block_off = off; block_iter_seek_start(&ti->bi, &ti->br); return 0; } -static int table_iter_seek_start(struct table_iter *ti, struct reftable_reader *r, - uint8_t typ, int index) +static int table_iter_seek_start(struct table_iter *ti, uint8_t typ, int index) { - struct reftable_reader_offsets *offs = reader_offsets_for(r, typ); + struct reftable_reader_offsets *offs = reader_offsets_for(ti->r, typ); uint64_t off = offs->offset; if (index) { off = offs->index_offset; @@ -415,7 +418,7 @@ static int table_iter_seek_start(struct table_iter *ti, struct reftable_reader * typ = BLOCK_TYPE_INDEX; } - return table_iter_seek_to(ti, r, off, typ); + return table_iter_seek_to(ti, off, typ); } static int table_iter_seek_linear(struct table_iter *ti, @@ -548,7 +551,7 @@ static int table_iter_seek_indexed(struct table_iter *ti, if (err != 0) goto done; - err = table_iter_seek_to(ti, ti->r, index_result.u.idx.offset, 0); + err = table_iter_seek_to(ti, index_result.u.idx.offset, 0); if (err != 0) goto done; @@ -578,7 +581,7 @@ static int reader_seek(struct reftable_reader *r, struct reftable_iterator *it, { uint8_t typ = reftable_record_type(rec); struct reftable_reader_offsets *offs = reader_offsets_for(r, typ); - struct table_iter ti = TABLE_ITER_INIT, *p; + struct table_iter ti, *p; int err; if (!offs->is_present) { @@ -586,7 +589,9 @@ static int reader_seek(struct reftable_reader *r, struct reftable_iterator *it, return 0; } - err = table_iter_seek_start(&ti, r, reftable_record_type(rec), + table_iter_init(&ti, r); + + err = table_iter_seek_start(&ti, reftable_record_type(rec), !!offs->index_offset); if (err < 0) goto out; @@ -722,15 +727,15 @@ static int reftable_reader_refs_for_unindexed(struct reftable_reader *r, struct reftable_iterator *it, uint8_t *oid) { - struct table_iter ti_empty = TABLE_ITER_INIT; - struct table_iter *ti = reftable_calloc(1, sizeof(*ti)); + struct table_iter *ti; struct filtering_ref_iterator *filter = NULL; struct filtering_ref_iterator empty = FILTERING_REF_ITERATOR_INIT; int oid_len = hash_size(r->hash_id); int err; - *ti = ti_empty; - err = table_iter_seek_start(ti, r, BLOCK_TYPE_REF, 0); + REFTABLE_ALLOC_ARRAY(ti, 1); + table_iter_init(ti, r); + err = table_iter_seek_start(ti, BLOCK_TYPE_REF, 0); if (err < 0) { reftable_free(ti); return err; From patchwork Mon May 13 08:47:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13663215 Received: from wfhigh5-smtp.messagingengine.com (wfhigh5-smtp.messagingengine.com [64.147.123.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF4EB147C90 for ; Mon, 13 May 2024 08:47:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590057; cv=none; b=DDnOoNhGxTTl13pdswxCQEr8XwTZsOt0EVwg4lbkC3MurIykiHEYc+O++nIS030rJB0xoQbm98TMn6dkBDXhFfuBfgVKjp2RuGuXad5CDzc89yrMVQVndI8VZW9swSQi7Ih6GwA++Et5tdzsV2Majnrbh3ooVLiPgLhdGZkJikQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590057; c=relaxed/simple; bh=W6wWELl+G0JcNH1+JM3SyhieiNYYlJOLHUSQ6akIVqQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=b2vsHJyicCoV62bosieQmthECFkIhTyFV3bsfMk6oaxHHxLKgAuYDOVClNp9Uy2YBXeSclpGNRAfndYswu+NswIow4EzRaCygNsD57cgRFlPIjYvWzVGFQ32XGQMDU/d/llXPYaH7iRmB5C1w7wTu8w52kIiTF3aooG0u1ok8Cw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=Q4NYDCjc; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=CKnj8LJ6; arc=none smtp.client-ip=64.147.123.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="Q4NYDCjc"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="CKnj8LJ6" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.west.internal (Postfix) with ESMTP id 3D3651800120; Mon, 13 May 2024 04:47:35 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 13 May 2024 04:47:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715590054; x=1715676454; bh=4PCKekwZIs og9BptFHJ2scRgWmaSUOu756PFhah0cQQ=; b=Q4NYDCjc+xz6xjj8UfhokU7xtK 1s1vgKwTrDunrErMd+xCHOnfzPGCWTA0RLeB0m2qbnESoWxFCQmdiRnT4T6fMLNy OfxaQWYsTPCkfM3LUsiNn67d4YFHCGYOOiCbf/TMeQVWX74jEfZa795oK3QXzmdo K4QqVb/3ZYTf8LeY/Ew25vpOslnweKMT6noMF/h/06/nyuf52a7YU8X4nd6hrK62 h0OO4NoS1hJyvTzVU+UY10hyGqbpVB3ax1xG6bPXL8Gm6tsEzcSFe5y99Oxs5k7B E+R6Qep3IBshwYZCbX7GoN9oPZ3+PTJ7ZxHxUpM3WdGY9ZLshyhz9O76A8EA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715590054; x=1715676454; bh=4PCKekwZIsog9BptFHJ2scRgWmaS UOu756PFhah0cQQ=; b=CKnj8LJ6R/eVeIvfkYCRmQWdDJPHUu5Lv8BfCGUuZVL9 Bb2JRjKEOD4pfSOF/wd11NJrqBi0yHvW3zmXO5Bj1ez/pqXzegG5L7pRCblLDZLJ YyQi2j4351yUGBBMGAJObaxDTF0+swXp+lpJOxRd1AjvkHV3OI4KE2QyAbi/XpTV 8ni9dRJqo4e+Ej0h4+6aaov9GqMREf20B/rYJinz5BqPr2zJU2qIRvRn2uKNRim3 6dMaY1CuYhjikKEBUhAVfXikLKjCT+SXFwo75tk4bVKfyPBd1Y86x5B8ncRlh0Tz cD1fDWpqYbmstz3OdQZLUUlHIHwcEem3oyj8d5RXtQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeggedgtdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 May 2024 04:47:34 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 1292fd8a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 13 May 2024 08:47:15 +0000 (UTC) Date: Mon, 13 May 2024 10:47:31 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Justin Tobler Subject: [PATCH v2 07/13] reftable/merged: split up initialization and seeking of records Message-ID: <12c10fd366c30a9e615d0928c2874a6099e04e21.1715589670.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: To initialize a `struct merged_iter`, we need to seek all subiterators to the wanted record and then add their results to the priority queue used to sort the records. This logic is split up across two functions, `merged_table_seek_record()` and `merged_iter_init()`. The scope of these functions is somewhat weird though, where `merged_iter_init()` is only responsible for adding the records of the subiterators to the priority queue. Clarify the scope of those functions such that `merged_iter_init()` is only responsible for initializing the iterator's structure. Performing the subiterator seeks are now part of `merged_table_seek_record()`. This step is required to move seeking of records into the generic `struct reftable_iterator` infrastructure. Signed-off-by: Patrick Steinhardt --- reftable/merged.c | 59 ++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/reftable/merged.c b/reftable/merged.c index f85a24c678..4e1b78e93f 100644 --- a/reftable/merged.c +++ b/reftable/merged.c @@ -25,34 +25,18 @@ struct merged_subiter { struct merged_iter { struct merged_subiter *subiters; struct merged_iter_pqueue pq; - uint32_t hash_id; size_t stack_len; - uint8_t typ; int suppress_deletions; ssize_t advance_index; }; -static int merged_iter_init(struct merged_iter *mi) +static void merged_iter_init(struct merged_iter *mi, + struct reftable_merged_table *mt) { - for (size_t i = 0; i < mi->stack_len; i++) { - struct pq_entry e = { - .index = i, - .rec = &mi->subiters[i].rec, - }; - int err; - - reftable_record_init(&mi->subiters[i].rec, mi->typ); - err = iterator_next(&mi->subiters[i].iter, - &mi->subiters[i].rec); - if (err < 0) - return err; - if (err > 0) - continue; - - merged_iter_pqueue_add(&mi->pq, &e); - } - - return 0; + memset(mi, 0, sizeof(*mi)); + mi->advance_index = -1; + mi->suppress_deletions = mt->suppress_deletions; + REFTABLE_CALLOC_ARRAY(mi->subiters, mt->stack_len); } static void merged_iter_close(void *p) @@ -246,32 +230,33 @@ static int merged_table_seek_record(struct reftable_merged_table *mt, struct reftable_iterator *it, struct reftable_record *rec) { - struct merged_iter merged = { - .typ = reftable_record_type(rec), - .hash_id = mt->hash_id, - .suppress_deletions = mt->suppress_deletions, - .advance_index = -1, - }; - struct merged_iter *p; + struct merged_iter merged, *p; int err; - REFTABLE_CALLOC_ARRAY(merged.subiters, mt->stack_len); + merged_iter_init(&merged, mt); + for (size_t i = 0; i < mt->stack_len; i++) { + reftable_record_init(&merged.subiters[merged.stack_len].rec, + reftable_record_type(rec)); + err = reftable_table_seek_record(&mt->stack[i], &merged.subiters[merged.stack_len].iter, rec); if (err < 0) goto out; - if (!err) - merged.stack_len++; - } + if (err > 0) + continue; - err = merged_iter_init(&merged); - if (err < 0) - goto out; + err = merged_iter_advance_subiter(&merged, merged.stack_len); + if (err < 0) + goto out; + + merged.stack_len++; + } - p = reftable_malloc(sizeof(struct merged_iter)); + p = reftable_malloc(sizeof(*p)); *p = merged; iterator_from_merged_iter(it, p); + err = 0; out: if (err < 0) From patchwork Mon May 13 08:47:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13663216 Received: from wfout2-smtp.messagingengine.com (wfout2-smtp.messagingengine.com [64.147.123.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2F19147C90 for ; Mon, 13 May 2024 08:47:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590062; cv=none; b=UXQEUE3HGInVxYe1njWixtLzN6zPrgIVUJP8ib3yevDB5eUdNxNWJUDl1Cg4aE0FsmQYf/e0a/u7MFCg1WFH1n2nrVcxwAIuknCWPjfb0YbXv+UdSzVRmgw3bAhEw6qj2FFbeJuFX191tOtgtxq0bHRwvjz/fd15E1Nm/K+9Azg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590062; c=relaxed/simple; bh=f5g//odyxIPPYJFGH6Yr+dyJ7Fl7NlPYBcsbQW1QHQg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SIlnesqi4vqNc9nPo5CmTE1C45bvC2SYOIjKNfElIXXS2f1id8GrhDZNSgUfUxhQIbk6PRWjyr1/fv00kFxhmVxBZWOuMk4modxTGw1Nf6+PZ0CgrHxLAJ7BJHFDaVY2SfeBBoWg4DiKCWb0drcfI1IgT4dbItUeYEIj5gp+GPQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=qeGIM0uG; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=QzoRQ7KF; arc=none smtp.client-ip=64.147.123.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="qeGIM0uG"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="QzoRQ7KF" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.west.internal (Postfix) with ESMTP id 08C071C00065; Mon, 13 May 2024 04:47:39 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Mon, 13 May 2024 04:47:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715590059; x=1715676459; bh=3J1xpdU/yx LirvvE9eG0ePjiXeKADZYaJnvQ3BHX0Iw=; b=qeGIM0uGYVqrvBZSJYKntMSF/E gHG836jLOVvZAfz2OzAJXdUfO6m343JVlU22sXtY1vSkKiQs6hiZSFqv6XEUG2hF 4NjvpwCJczh9UPSD2VeRe8L4JOkhr6lIeHOMftfj9BO0ETvp7Am0zXYYSuENU1pm /iTnwRGfDKsmiQok8mwIePyYDGhj2UN1p09yqQ3e0E/5qBDXaDxxWAFV+krjYV1l xyr1PFNtf0ZUOkoZFwR2tTZFu1P9XbxWEgHkLdESpDjeiVQx1OJEiRN8o4SB+AjG kX68pGvXT8uHN0LJijj5+nHaXDPlpvkuyxO7MP4luIRQdfqHaSSmK2/qD9HA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715590059; x=1715676459; bh=3J1xpdU/yxLirvvE9eG0ePjiXeKA DZYaJnvQ3BHX0Iw=; b=QzoRQ7KFIW4FpTiIy1w47POuLNlvuauF94u41tBRFMWc LMyk5Rvs8vMGjfDYT/0vLdEN/LXx02ryqX06AdOy0or6qL0PyGjlCyDy4pFzmqff hzsVi1IdwTil7nmVja7n5+tKGCTnPkAUR2We6178qoTTP7W66vMwPnKUei5eYJRG dmTx53C0VOVsYIUAoqLgMjnHSgonp/O80a5osRKiLvtz58PO+2NWWSnyWhdlr+FM Hq+WMIY21BtL90XiZWO0n3C8vjNdRcwk1eyH5wdP7aIOWhiEFuryVTYWaocUVPKV V3VHSxgGzd4RCYcnG+qIO/gJ+ZryP0DBFMlvMQ69NQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeggedgtdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 May 2024 04:47:38 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 3c40a12f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 13 May 2024 08:47:20 +0000 (UTC) Date: Mon, 13 May 2024 10:47:36 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Justin Tobler Subject: [PATCH v2 08/13] reftable/merged: simplify indices for subiterators Message-ID: <31bdfc1e34079dd79ba3bfd39a03eacaa2929762.1715589670.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: When seeking on a merged table, we perform the seek for each of the subiterators. If the subiterator has the desired record we add it to the priority queue, otherwise we skip it and don't add it to the stack of subiterators hosted by the merged table. The consequence of this is that the index of the subiterator in the merged table does not necessarily correspond to the index of it in the merged iterator. Next to being potentially confusing, it also means that we won't easily be able to re-seek the merged iterator because we have no clear connection between both of the data structures. Refactor the code so that the index stays the same in both structures. Signed-off-by: Patrick Steinhardt --- reftable/merged.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/reftable/merged.c b/reftable/merged.c index 4e1b78e93f..18a2a6f09b 100644 --- a/reftable/merged.c +++ b/reftable/merged.c @@ -37,6 +37,7 @@ static void merged_iter_init(struct merged_iter *mi, mi->advance_index = -1; mi->suppress_deletions = mt->suppress_deletions; REFTABLE_CALLOC_ARRAY(mi->subiters, mt->stack_len); + mi->stack_len = mt->stack_len; } static void merged_iter_close(void *p) @@ -236,21 +237,19 @@ static int merged_table_seek_record(struct reftable_merged_table *mt, merged_iter_init(&merged, mt); for (size_t i = 0; i < mt->stack_len; i++) { - reftable_record_init(&merged.subiters[merged.stack_len].rec, + reftable_record_init(&merged.subiters[i].rec, reftable_record_type(rec)); err = reftable_table_seek_record(&mt->stack[i], - &merged.subiters[merged.stack_len].iter, rec); + &merged.subiters[i].iter, rec); if (err < 0) goto out; if (err > 0) continue; - err = merged_iter_advance_subiter(&merged, merged.stack_len); + err = merged_iter_advance_subiter(&merged, i); if (err < 0) goto out; - - merged.stack_len++; } p = reftable_malloc(sizeof(*p)); From patchwork Mon May 13 08:47:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13663217 Received: from wfout2-smtp.messagingengine.com (wfout2-smtp.messagingengine.com [64.147.123.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CC39146A98 for ; Mon, 13 May 2024 08:47:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590067; cv=none; b=C3TD3QwmHTyxP+DmUP6ldEe9C9dfnotdD3zw4gf/DnrIOmK7mnKcj+kYh+Tm/rn0ZW/TL8038rKkahskE8DM2dvg9Itt+EucK70lBgWFR7UJB/i9iFutA5pOYI0bRcERRz+ocATSNN62sLP+mnzo/UmZXWZMm3Riry/67CPAGTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590067; c=relaxed/simple; bh=zSropp4IjPY9tzbfmrg3BmWAX2eG6lEw3lZ1bYlX07s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eM27GB4JMAsrwzLN4iJF9cVTr+MarrkueWZIC9mScqD3Jag6ibTlsLWnTPuXakV4SxXZlsa7OnVggQp2fXKmSRg5tSTRPdOc5mGx5CYycO+jEobz1frAWsXfxEW/j1g/2wyhBednfOOFEgbjmznv9GAY8Meyv9rW/XMFMI7fv4g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=lFMeWs2u; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ZNJVo4U7; arc=none smtp.client-ip=64.147.123.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="lFMeWs2u"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ZNJVo4U7" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.west.internal (Postfix) with ESMTP id D7C9F1C000DC; Mon, 13 May 2024 04:47:44 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 13 May 2024 04:47:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715590064; x=1715676464; bh=xLxvr5ZRTr GR1CciAxuR/D+LtOYbWihlBguxsdSoP2o=; b=lFMeWs2uU2aTA675wgZKTyOvry gO1E3Hc7Twjl/Qw9g0C5AKAB+d/UyeaGo8pPN0XifR1Xv8Q135AI8yc7L5hKauaR HLCsVd8dFIMhfxnOEm/41+P7kMxaZZffEAW5djEGM/gEgOS/SGdOsfWja1K36qgC dOjYuLeujrDPWaBYlNZW9/2s8fc2uUAga/y1zSQ02nJdV+PuvHmwHroViYz4KQLT gWd4ZZVdM/pccgbcl4rS8pJ8KiMauSo1WKDSystJiE1TPH0NJOXDgkICl0AXct5S TH5Iy+zOqBJF2U0eNyds3Vov6eVge6f+bXEiw4QuK5ks+mVgvuXG7qYkW09w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715590064; x=1715676464; bh=xLxvr5ZRTrGR1CciAxuR/D+LtOYb WihlBguxsdSoP2o=; b=ZNJVo4U7MgBLcFti3W25WEcv0dkSHnfwVJYusG1FZW1H Mgi1HTBvue7QzJL+GcCcGmKRPDmcPwLUV0PcaAEg58Xdjd+cikD7lJE53hQzuCdr 4PKXhnLbZCk6H1Mhrz7VHcIZYTlN0R7Qqb6qaKYEXqWlr13gS+PnhYZvJKX1YvKh V0qLGv6TFU45TVUqKRbnGQU8KBDtixRHPmBcj+d2a0LwAmUW7GGBqH07BtnWg1Pr 2Ig7O8Q9bDtuxS7cqZx1L8reAr4gXcfB+NJQ8GIn40+Z0UvuiDG/2aihBmIYzSZx 35KG5kxey5ci6oLkj4rSfYeXOsxi9+IJiTN8NFBMXA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeggedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 May 2024 04:47:43 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 6ae0dc12 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 13 May 2024 08:47:25 +0000 (UTC) Date: Mon, 13 May 2024 10:47:41 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Justin Tobler Subject: [PATCH v2 09/13] reftable/generic: move seeking of records into the iterator Message-ID: <3e91c3830e42063a74dac983152b7b8f0053bafa.1715589670.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Reftable iterators are created by seeking on the parent structure of a corresponding record. For example, to create an iterator for the merged table you would call `reftable_merged_table_seek_ref()`. Most notably, it is not posible to create an iterator and then seek it afterwards. While this may be a bit easier to reason about, it comes with two significant downsides. The first downside is that the logic to find records is split up between the parent data structure and the iterator itself. Conceptually, it is more straight forward if all that logic was contained in a single place, which should be the iterator. The second and more significant downside is that it is impossible to reuse iterators for multiple seeks. Whenever you want to look up a record, you need to re-create the whole infrastructure again, which is quite a waste of time. Furthermore, it is impossible to optimize seeks, such as when seeking the same record multiple times. To address this, we essentially split up the concerns properly such that the parent data structure is responsible for setting up the iterator via a new `init_iter()` callback, whereas the iterator handles seeks via a new `seek()` callback. This will eventually allow us to call `seek()` on the iterator multiple times, where every iterator can potentially optimize for certain cases. Note that at this point in time we are not yet ready to reuse the iterators. This will be left for a future patch series. Signed-off-by: Patrick Steinhardt --- reftable/generic.c | 47 +++++++++++++---- reftable/generic.h | 9 +++- reftable/iter.c | 15 ++++++ reftable/merged.c | 97 +++++++++++++++++----------------- reftable/reader.c | 126 +++++++++++++++++++++++++-------------------- 5 files changed, 177 insertions(+), 117 deletions(-) diff --git a/reftable/generic.c b/reftable/generic.c index b9f1c7c18a..1cf68fe124 100644 --- a/reftable/generic.c +++ b/reftable/generic.c @@ -12,25 +12,39 @@ license that can be found in the LICENSE file or at #include "reftable-iterator.h" #include "reftable-generic.h" +void table_init_iter(struct reftable_table *tab, + struct reftable_iterator *it, + uint8_t typ) +{ + + tab->ops->init_iter(tab->table_arg, it, typ); +} + int reftable_table_seek_ref(struct reftable_table *tab, struct reftable_iterator *it, const char *name) { - struct reftable_record rec = { .type = BLOCK_TYPE_REF, - .u.ref = { - .refname = (char *)name, - } }; - return tab->ops->seek_record(tab->table_arg, it, &rec); + struct reftable_record want = { + .type = BLOCK_TYPE_REF, + .u.ref = { + .refname = (char *)name, + }, + }; + table_init_iter(tab, it, BLOCK_TYPE_REF); + return it->ops->seek(it->iter_arg, &want); } int reftable_table_seek_log(struct reftable_table *tab, struct reftable_iterator *it, const char *name) { - struct reftable_record rec = { .type = BLOCK_TYPE_LOG, - .u.log = { - .refname = (char *)name, - .update_index = ~((uint64_t)0), - } }; - return tab->ops->seek_record(tab->table_arg, it, &rec); + struct reftable_record want = { + .type = BLOCK_TYPE_LOG, + .u.log = { + .refname = (char *)name, + .update_index = ~((uint64_t)0), + }, + }; + table_init_iter(tab, it, BLOCK_TYPE_LOG); + return it->ops->seek(it->iter_arg, &want); } int reftable_table_read_ref(struct reftable_table *tab, const char *name, @@ -152,11 +166,21 @@ int reftable_iterator_next_log(struct reftable_iterator *it, return err; } +int iterator_seek(struct reftable_iterator *it, struct reftable_record *want) +{ + return it->ops->seek(it->iter_arg, want); +} + int iterator_next(struct reftable_iterator *it, struct reftable_record *rec) { return it->ops->next(it->iter_arg, rec); } +static int empty_iterator_seek(void *arg, struct reftable_record *want) +{ + return 0; +} + static int empty_iterator_next(void *arg, struct reftable_record *rec) { return 1; @@ -167,6 +191,7 @@ static void empty_iterator_close(void *arg) } static struct reftable_iterator_vtable empty_vtable = { + .seek = &empty_iterator_seek, .next = &empty_iterator_next, .close = &empty_iterator_close, }; diff --git a/reftable/generic.h b/reftable/generic.h index 98886a0640..8341fa570e 100644 --- a/reftable/generic.h +++ b/reftable/generic.h @@ -14,19 +14,24 @@ license that can be found in the LICENSE file or at /* generic interface to reftables */ struct reftable_table_vtable { - int (*seek_record)(void *tab, struct reftable_iterator *it, - struct reftable_record *); + void (*init_iter)(void *tab, struct reftable_iterator *it, uint8_t typ); uint32_t (*hash_id)(void *tab); uint64_t (*min_update_index)(void *tab); uint64_t (*max_update_index)(void *tab); }; +void table_init_iter(struct reftable_table *tab, + struct reftable_iterator *it, + uint8_t typ); + struct reftable_iterator_vtable { + int (*seek)(void *iter_arg, struct reftable_record *want); int (*next)(void *iter_arg, struct reftable_record *rec); void (*close)(void *iter_arg); }; void iterator_set_empty(struct reftable_iterator *it); +int iterator_seek(struct reftable_iterator *it, struct reftable_record *want); int iterator_next(struct reftable_iterator *it, struct reftable_record *rec); #endif diff --git a/reftable/iter.c b/reftable/iter.c index aa9ac199b1..b4528fab47 100644 --- a/reftable/iter.c +++ b/reftable/iter.c @@ -23,6 +23,13 @@ static void filtering_ref_iterator_close(void *iter_arg) reftable_iterator_destroy(&fri->it); } +static int filtering_ref_iterator_seek(void *iter_arg, + struct reftable_record *want) +{ + struct filtering_ref_iterator *fri = iter_arg; + return iterator_seek(&fri->it, want); +} + static int filtering_ref_iterator_next(void *iter_arg, struct reftable_record *rec) { @@ -73,6 +80,7 @@ static int filtering_ref_iterator_next(void *iter_arg, } static struct reftable_iterator_vtable filtering_ref_iterator_vtable = { + .seek = &filtering_ref_iterator_seek, .next = &filtering_ref_iterator_next, .close = &filtering_ref_iterator_close, }; @@ -119,6 +127,12 @@ static int indexed_table_ref_iter_next_block(struct indexed_table_ref_iter *it) return 0; } +static int indexed_table_ref_iter_seek(void *p, struct reftable_record *want) +{ + BUG("seeking indexed table is not supported"); + return -1; +} + static int indexed_table_ref_iter_next(void *p, struct reftable_record *rec) { struct indexed_table_ref_iter *it = p; @@ -175,6 +189,7 @@ int new_indexed_table_ref_iter(struct indexed_table_ref_iter **dest, } static struct reftable_iterator_vtable indexed_table_ref_iter_vtable = { + .seek = &indexed_table_ref_iter_seek, .next = &indexed_table_ref_iter_next, .close = &indexed_table_ref_iter_close, }; diff --git a/reftable/merged.c b/reftable/merged.c index 18a2a6f09b..fc7946d90d 100644 --- a/reftable/merged.c +++ b/reftable/merged.c @@ -31,12 +31,18 @@ struct merged_iter { }; static void merged_iter_init(struct merged_iter *mi, - struct reftable_merged_table *mt) + struct reftable_merged_table *mt, + uint8_t typ) { memset(mi, 0, sizeof(*mi)); mi->advance_index = -1; mi->suppress_deletions = mt->suppress_deletions; + REFTABLE_CALLOC_ARRAY(mi->subiters, mt->stack_len); + for (size_t i = 0; i < mt->stack_len; i++) { + reftable_record_init(&mi->subiters[i].rec, typ); + table_init_iter(&mt->stack[i], &mi->subiters[i].iter, typ); + } mi->stack_len = mt->stack_len; } @@ -68,6 +74,27 @@ static int merged_iter_advance_subiter(struct merged_iter *mi, size_t idx) return 0; } +static int merged_iter_seek(struct merged_iter *mi, struct reftable_record *want) +{ + int err; + + mi->advance_index = -1; + + for (size_t i = 0; i < mi->stack_len; i++) { + err = iterator_seek(&mi->subiters[i].iter, want); + if (err < 0) + return err; + if (err > 0) + continue; + + err = merged_iter_advance_subiter(mi, i); + if (err < 0) + return err; + } + + return 0; +} + static int merged_iter_next_entry(struct merged_iter *mi, struct reftable_record *rec) { @@ -133,6 +160,11 @@ static int merged_iter_next_entry(struct merged_iter *mi, return 0; } +static int merged_iter_seek_void(void *it, struct reftable_record *want) +{ + return merged_iter_seek(it, want); +} + static int merged_iter_next_void(void *p, struct reftable_record *rec) { struct merged_iter *mi = p; @@ -147,6 +179,7 @@ static int merged_iter_next_void(void *p, struct reftable_record *rec) } static struct reftable_iterator_vtable merged_iter_vtable = { + .seek = merged_iter_seek_void, .next = &merged_iter_next_void, .close = &merged_iter_close, }; @@ -220,47 +253,13 @@ reftable_merged_table_min_update_index(struct reftable_merged_table *mt) return mt->min; } -static int reftable_table_seek_record(struct reftable_table *tab, - struct reftable_iterator *it, - struct reftable_record *rec) -{ - return tab->ops->seek_record(tab->table_arg, it, rec); -} - -static int merged_table_seek_record(struct reftable_merged_table *mt, - struct reftable_iterator *it, - struct reftable_record *rec) +static void merged_table_init_iter(struct reftable_merged_table *mt, + struct reftable_iterator *it, + uint8_t typ) { - struct merged_iter merged, *p; - int err; - - merged_iter_init(&merged, mt); - - for (size_t i = 0; i < mt->stack_len; i++) { - reftable_record_init(&merged.subiters[i].rec, - reftable_record_type(rec)); - - err = reftable_table_seek_record(&mt->stack[i], - &merged.subiters[i].iter, rec); - if (err < 0) - goto out; - if (err > 0) - continue; - - err = merged_iter_advance_subiter(&merged, i); - if (err < 0) - goto out; - } - - p = reftable_malloc(sizeof(*p)); - *p = merged; - iterator_from_merged_iter(it, p); - err = 0; - -out: - if (err < 0) - merged_iter_close(&merged); - return err; + struct merged_iter *mi = reftable_malloc(sizeof(*mi)); + merged_iter_init(mi, mt, typ); + iterator_from_merged_iter(it, mi); } int reftable_merged_table_seek_ref(struct reftable_merged_table *mt, @@ -273,7 +272,8 @@ int reftable_merged_table_seek_ref(struct reftable_merged_table *mt, .refname = (char *)name, }, }; - return merged_table_seek_record(mt, it, &rec); + merged_table_init_iter(mt, it, BLOCK_TYPE_REF); + return iterator_seek(it, &rec); } int reftable_merged_table_seek_log_at(struct reftable_merged_table *mt, @@ -285,7 +285,8 @@ int reftable_merged_table_seek_log_at(struct reftable_merged_table *mt, .refname = (char *)name, .update_index = update_index, } }; - return merged_table_seek_record(mt, it, &rec); + merged_table_init_iter(mt, it, BLOCK_TYPE_LOG); + return iterator_seek(it, &rec); } int reftable_merged_table_seek_log(struct reftable_merged_table *mt, @@ -301,11 +302,11 @@ uint32_t reftable_merged_table_hash_id(struct reftable_merged_table *mt) return mt->hash_id; } -static int reftable_merged_table_seek_void(void *tab, - struct reftable_iterator *it, - struct reftable_record *rec) +static void reftable_merged_table_init_iter_void(void *tab, + struct reftable_iterator *it, + uint8_t typ) { - return merged_table_seek_record(tab, it, rec); + merged_table_init_iter(tab, it, typ); } static uint32_t reftable_merged_table_hash_id_void(void *tab) @@ -324,7 +325,7 @@ static uint64_t reftable_merged_table_max_update_index_void(void *tab) } static struct reftable_table_vtable merged_table_vtable = { - .seek_record = reftable_merged_table_seek_void, + .init_iter = reftable_merged_table_init_iter_void, .hash_id = reftable_merged_table_hash_id_void, .min_update_index = reftable_merged_table_min_update_index_void, .max_update_index = reftable_merged_table_max_update_index_void, diff --git a/reftable/reader.c b/reftable/reader.c index 021608f638..a5a13cb0b9 100644 --- a/reftable/reader.c +++ b/reftable/reader.c @@ -369,29 +369,6 @@ static int table_iter_next(struct table_iter *ti, struct reftable_record *rec) } } -static int table_iter_next_void(void *ti, struct reftable_record *rec) -{ - return table_iter_next(ti, rec); -} - -static void table_iter_close_void(void *ti) -{ - table_iter_close(ti); -} - -static struct reftable_iterator_vtable table_iter_vtable = { - .next = &table_iter_next_void, - .close = &table_iter_close_void, -}; - -static void iterator_from_table_iter(struct reftable_iterator *it, - struct table_iter *ti) -{ - assert(!it->ops); - it->iter_arg = ti; - it->ops = &table_iter_vtable; -} - static int table_iter_seek_to(struct table_iter *ti, uint64_t off, uint8_t typ) { int err; @@ -576,43 +553,74 @@ static int table_iter_seek_indexed(struct table_iter *ti, return err; } -static int reader_seek(struct reftable_reader *r, struct reftable_iterator *it, - struct reftable_record *rec) +static int table_iter_seek(struct table_iter *ti, + struct reftable_record *want) { - uint8_t typ = reftable_record_type(rec); - struct reftable_reader_offsets *offs = reader_offsets_for(r, typ); - struct table_iter ti, *p; + uint8_t typ = reftable_record_type(want); + struct reftable_reader_offsets *offs = reader_offsets_for(ti->r, typ); int err; - if (!offs->is_present) { - iterator_set_empty(it); - return 0; - } - - table_iter_init(&ti, r); - - err = table_iter_seek_start(&ti, reftable_record_type(rec), + err = table_iter_seek_start(ti, reftable_record_type(want), !!offs->index_offset); if (err < 0) goto out; if (offs->index_offset) - err = table_iter_seek_indexed(&ti, rec); + err = table_iter_seek_indexed(ti, want); else - err = table_iter_seek_linear(&ti, rec); + err = table_iter_seek_linear(ti, want); if (err) goto out; - REFTABLE_ALLOC_ARRAY(p, 1); - *p = ti; - iterator_from_table_iter(it, p); - out: - if (err) - table_iter_close(&ti); return err; } +static int table_iter_seek_void(void *ti, struct reftable_record *want) +{ + return table_iter_seek(ti, want); +} + +static int table_iter_next_void(void *ti, struct reftable_record *rec) +{ + return table_iter_next(ti, rec); +} + +static void table_iter_close_void(void *ti) +{ + table_iter_close(ti); +} + +static struct reftable_iterator_vtable table_iter_vtable = { + .seek = &table_iter_seek_void, + .next = &table_iter_next_void, + .close = &table_iter_close_void, +}; + +static void iterator_from_table_iter(struct reftable_iterator *it, + struct table_iter *ti) +{ + assert(!it->ops); + it->iter_arg = ti; + it->ops = &table_iter_vtable; +} + +static void reader_init_iter(struct reftable_reader *r, + struct reftable_iterator *it, + uint8_t typ) +{ + struct reftable_reader_offsets *offs = reader_offsets_for(r, typ); + + if (offs->is_present) { + struct table_iter *ti; + REFTABLE_ALLOC_ARRAY(ti, 1); + table_iter_init(ti, r); + iterator_from_table_iter(it, ti); + } else { + iterator_set_empty(it); + } +} + int reftable_reader_seek_ref(struct reftable_reader *r, struct reftable_iterator *it, const char *name) { @@ -622,19 +630,23 @@ int reftable_reader_seek_ref(struct reftable_reader *r, .refname = (char *)name, }, }; - return reader_seek(r, it, &rec); + reader_init_iter(r, it, BLOCK_TYPE_REF); + return iterator_seek(it, &rec); } int reftable_reader_seek_log_at(struct reftable_reader *r, struct reftable_iterator *it, const char *name, uint64_t update_index) { - struct reftable_record rec = { .type = BLOCK_TYPE_LOG, - .u.log = { - .refname = (char *)name, - .update_index = update_index, - } }; - return reader_seek(r, it, &rec); + struct reftable_record rec = { + .type = BLOCK_TYPE_LOG, + .u.log = { + .refname = (char *)name, + .update_index = update_index, + }, + }; + reader_init_iter(r, it, BLOCK_TYPE_LOG); + return iterator_seek(it, &rec); } int reftable_reader_seek_log(struct reftable_reader *r, @@ -692,7 +704,8 @@ static int reftable_reader_refs_for_indexed(struct reftable_reader *r, struct indexed_table_ref_iter *itr = NULL; /* Look through the reverse index. */ - err = reader_seek(r, &oit, &want); + reader_init_iter(r, &oit, BLOCK_TYPE_OBJ); + err = iterator_seek(&oit, &want); if (err != 0) goto done; @@ -773,10 +786,11 @@ uint64_t reftable_reader_min_update_index(struct reftable_reader *r) /* generic table interface. */ -static int reftable_reader_seek_void(void *tab, struct reftable_iterator *it, - struct reftable_record *rec) +static void reftable_reader_init_iter_void(void *tab, + struct reftable_iterator *it, + uint8_t typ) { - return reader_seek(tab, it, rec); + reader_init_iter(tab, it, typ); } static uint32_t reftable_reader_hash_id_void(void *tab) @@ -795,7 +809,7 @@ static uint64_t reftable_reader_max_update_index_void(void *tab) } static struct reftable_table_vtable reader_vtable = { - .seek_record = reftable_reader_seek_void, + .init_iter = reftable_reader_init_iter_void, .hash_id = reftable_reader_hash_id_void, .min_update_index = reftable_reader_min_update_index_void, .max_update_index = reftable_reader_max_update_index_void, From patchwork Mon May 13 08:47:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13663218 Received: from wfhigh5-smtp.messagingengine.com (wfhigh5-smtp.messagingengine.com [64.147.123.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8225B146A98 for ; Mon, 13 May 2024 08:47:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590073; cv=none; b=nNjZedDaeWSup7MrauZvlIRCuaushW3rS1bBJSlHIQ8dcmLq+3sw5LvDayHN3bXzlkWnGnYUGrEpEm//F6QykzyrJ0on7V4QVDCLGx43o9O8omB2rK3wjGPJIOvHduIZbA33VZoVk1Y4A+8wthO7Srf1WoXoGHlsPqxSB+Wf630= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590073; c=relaxed/simple; bh=hNbE9p/UXxIlz5fmQLRO1mdV1tgFuzv5ozpKsulLWq4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TF4ABw/ZM2rf13Vg7HNmKiNTSK8OC0dpFEg/t2/TtnzAx+RwByeoVJAX9iraGcDhLzeFpF78jvQxWTde4MIv3MUY2AdpEyRDpjQb8e0/j6zAhmyhQUm/XLWVPPpN0LxUEboN1PxE9oJRz98MzQfz7tj+6oCE2L2ldjy/gmqbRS0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=QYCq+0UE; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Z5zmVr3T; arc=none smtp.client-ip=64.147.123.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="QYCq+0UE"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Z5zmVr3T" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.west.internal (Postfix) with ESMTP id A4D8C1800120; Mon, 13 May 2024 04:47:50 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 13 May 2024 04:47:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715590070; x=1715676470; bh=nNHMuFn9+J EDTuhRcXdwa88SeXOp5OllBWrQHCcPxHA=; b=QYCq+0UEMkeHBQ/iLwxbaFB+M5 TM5qMySF0/567aL+1+3gZalH+O2Xfckosb2HWGCgbtKPgxDH11LSwBAaj0M2A0ZN JOmJubezlTsHBjAhi+1ty/LUY1weBYxchwYetc6MhrlNLJALZT7a7WdDiJsEUY/m sh5LLPrmFwTZtrK/aAd9jBYalmTcj4CJbuUaf9DYi4k4jIP9xX2XezR7s1Xg+bPH /5EDc/YSJyPwTPgJ8NlLtes8dLSALeeFO0xOeIq/bHtEmapuPhAR0MVZ2E1Ovxdl Mes5UtQIXHRd8xF6xpX4RtlpbTIkTq5GpEfBb00/WVjFSdJRQlFcNhACwBRQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715590070; x=1715676470; bh=nNHMuFn9+JEDTuhRcXdwa88SeXOp 5OllBWrQHCcPxHA=; b=Z5zmVr3TguSraGViVTK7SwCZafA2QI+N9MOSJ0UeTW7K qhaF4V31PMHAQE3KXIG8BKsao+iyF5mqQQWRzF1mFAOfhGGJOufGslJcDyp3RoXn Sqb6ApAXAy9tXdt/dVHVuQ2SLWfkTvnesq/9luZRzW12pq/Mgf82UPiNQOHyjQuY 7b2Ook3hsjgAeW+bjr627uo5B0GAjx5XQzgVfqCDWQV/170KmKwoh8SOXPz9zYj3 ZFqWmmsTxXQ1Jk6/ibgrlltaPkFoNCd54Sdqjm+1TBF/8atl5VXjX/kupBmfOj35 esTPQrItYOmoNTufp+OgS2VN2GT+5CeebkcbkwL6LA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeggedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 May 2024 04:47:49 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 8a8ce537 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 13 May 2024 08:47:31 +0000 (UTC) Date: Mon, 13 May 2024 10:47:47 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Justin Tobler Subject: [PATCH v2 10/13] reftable/generic: adapt interface to allow reuse of iterators Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Refactor the interfaces exposed by `struct reftable_table` and `struct reftable_iterator` such that they support iterator reuse. This is done by separating initialization of the iterator and seeking on it. Signed-off-by: Patrick Steinhardt --- reftable/generic.c | 53 ++++++++++++++++++++++++++---------- reftable/iter.c | 8 +++--- reftable/reftable-generic.h | 8 +++--- reftable/reftable-iterator.h | 21 ++++++++++++++ 4 files changed, 68 insertions(+), 22 deletions(-) diff --git a/reftable/generic.c b/reftable/generic.c index 1cf68fe124..28ae26145e 100644 --- a/reftable/generic.c +++ b/reftable/generic.c @@ -20,8 +20,20 @@ void table_init_iter(struct reftable_table *tab, tab->ops->init_iter(tab->table_arg, it, typ); } -int reftable_table_seek_ref(struct reftable_table *tab, - struct reftable_iterator *it, const char *name) +void reftable_table_init_ref_iter(struct reftable_table *tab, + struct reftable_iterator *it) +{ + table_init_iter(tab, it, BLOCK_TYPE_REF); +} + +void reftable_table_init_log_iter(struct reftable_table *tab, + struct reftable_iterator *it) +{ + table_init_iter(tab, it, BLOCK_TYPE_LOG); +} + +int reftable_iterator_seek_ref(struct reftable_iterator *it, + const char *name) { struct reftable_record want = { .type = BLOCK_TYPE_REF, @@ -29,29 +41,37 @@ int reftable_table_seek_ref(struct reftable_table *tab, .refname = (char *)name, }, }; - table_init_iter(tab, it, BLOCK_TYPE_REF); return it->ops->seek(it->iter_arg, &want); } -int reftable_table_seek_log(struct reftable_table *tab, - struct reftable_iterator *it, const char *name) +int reftable_iterator_seek_log_at(struct reftable_iterator *it, + const char *name, uint64_t update_index) { struct reftable_record want = { .type = BLOCK_TYPE_LOG, .u.log = { .refname = (char *)name, - .update_index = ~((uint64_t)0), + .update_index = update_index, }, }; - table_init_iter(tab, it, BLOCK_TYPE_LOG); return it->ops->seek(it->iter_arg, &want); } +int reftable_iterator_seek_log(struct reftable_iterator *it, + const char *name) +{ + return reftable_iterator_seek_log_at(it, name, ~((uint64_t) 0)); +} + int reftable_table_read_ref(struct reftable_table *tab, const char *name, struct reftable_ref_record *ref) { struct reftable_iterator it = { NULL }; - int err = reftable_table_seek_ref(tab, &it, name); + int err; + + reftable_table_init_ref_iter(tab, &it); + + err = reftable_iterator_seek_ref(&it, name); if (err) goto done; @@ -76,10 +96,13 @@ int reftable_table_print(struct reftable_table *tab) { struct reftable_ref_record ref = { NULL }; struct reftable_log_record log = { NULL }; uint32_t hash_id = reftable_table_hash_id(tab); - int err = reftable_table_seek_ref(tab, &it, ""); - if (err < 0) { + int err; + + reftable_table_init_ref_iter(tab, &it); + + err = reftable_iterator_seek_ref(&it, ""); + if (err < 0) return err; - } while (1) { err = reftable_iterator_next_ref(&it, &ref); @@ -94,10 +117,12 @@ int reftable_table_print(struct reftable_table *tab) { reftable_iterator_destroy(&it); reftable_ref_record_release(&ref); - err = reftable_table_seek_log(tab, &it, ""); - if (err < 0) { + reftable_table_init_log_iter(tab, &it); + + err = reftable_iterator_seek_log(&it, ""); + if (err < 0) return err; - } + while (1) { err = reftable_iterator_next_log(&it, &log); if (err > 0) { diff --git a/reftable/iter.c b/reftable/iter.c index b4528fab47..fddea31e51 100644 --- a/reftable/iter.c +++ b/reftable/iter.c @@ -45,11 +45,11 @@ static int filtering_ref_iterator_next(void *iter_arg, if (fri->double_check) { struct reftable_iterator it = { NULL }; - err = reftable_table_seek_ref(&fri->tab, &it, - ref->refname); - if (err == 0) { + reftable_table_init_ref_iter(&fri->tab, &it); + + err = reftable_iterator_seek_ref(&it, ref->refname); + if (err == 0) err = reftable_iterator_next_ref(&it, ref); - } reftable_iterator_destroy(&it); diff --git a/reftable/reftable-generic.h b/reftable/reftable-generic.h index d239751a77..65670ea093 100644 --- a/reftable/reftable-generic.h +++ b/reftable/reftable-generic.h @@ -21,11 +21,11 @@ struct reftable_table { void *table_arg; }; -int reftable_table_seek_log(struct reftable_table *tab, - struct reftable_iterator *it, const char *name); +void reftable_table_init_ref_iter(struct reftable_table *tab, + struct reftable_iterator *it); -int reftable_table_seek_ref(struct reftable_table *tab, - struct reftable_iterator *it, const char *name); +void reftable_table_init_log_iter(struct reftable_table *tab, + struct reftable_iterator *it); /* returns the hash ID from a generic reftable_table */ uint32_t reftable_table_hash_id(struct reftable_table *tab); diff --git a/reftable/reftable-iterator.h b/reftable/reftable-iterator.h index d3eee7af35..e3bf688d53 100644 --- a/reftable/reftable-iterator.h +++ b/reftable/reftable-iterator.h @@ -21,12 +21,33 @@ struct reftable_iterator { void *iter_arg; }; +/* + * Position the iterator at the ref record with given name such that the next + * call to `next_ref()` would yield the record. + */ +int reftable_iterator_seek_ref(struct reftable_iterator *it, + const char *name); + /* reads the next reftable_ref_record. Returns < 0 for error, 0 for OK and > 0: * end of iteration. */ int reftable_iterator_next_ref(struct reftable_iterator *it, struct reftable_ref_record *ref); +/* + * Position the iterator at the log record with given name and update index + * such that the next call to `next_log()` would yield the record. + */ +int reftable_iterator_seek_log_at(struct reftable_iterator *it, + const char *name, uint64_t update_index); + +/* + * Position the iterator at the newest log record with given name such that the + * next call to `next_log()` would yield the record. + */ +int reftable_iterator_seek_log(struct reftable_iterator *it, + const char *name); + /* reads the next reftable_log_record. Returns < 0 for error, 0 for OK and > 0: * end of iteration. */ From patchwork Mon May 13 08:47:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13663219 Received: from wfout2-smtp.messagingengine.com (wfout2-smtp.messagingengine.com [64.147.123.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 55BF2146A98 for ; Mon, 13 May 2024 08:47:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590077; cv=none; b=arNWwpsUGdONWzuC8PHqHPR3ErMN/p/2q9ChERMUYvwv87VPT3COEUAZW7bvVGahmgdB5Som2OjICKFftW8UKUb5WRp6ycO7siPljg3tKiENwD/6MrftD228gUTbTkrVUoyi4uXFfmpYJPybjGaUHnoMLQZSBc+Qti2kJO5gCk8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590077; c=relaxed/simple; bh=kF4Pnx5zR/vtKIi7nIFh1h3dOXH22SN+24bh68IazCY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dn51JU50t8mIVdPXlcgy3FSNcYU1zU9RJKbdS0m83B8ppMaCZTgsywSbWfZts2o+5+asp+bxGqevAGjEuWZJgqeRpp6PyyEwRITPssg9z9q7D3Qr3yCi0B1T0iDidrGkjue63hQGN2l23zT3PT7Uvnf3eJef04ETRrOIIwPqMVE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=tJPl5tid; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=jzgYwkzP; arc=none smtp.client-ip=64.147.123.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="tJPl5tid"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="jzgYwkzP" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.west.internal (Postfix) with ESMTP id 6AC871C000E3; Mon, 13 May 2024 04:47:55 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 13 May 2024 04:47:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715590075; x=1715676475; bh=oDSx4O1DdP DnXTNU+VrbiULKCzP5hm9rw/H9XPM8sN0=; b=tJPl5tidVqiBKyESSdas/F0dif 8zb1ZTYzAFLU6zhF3ySjKpxykDkMZxnN6Xh9GP7yhjRQMwsEL7Vyzqqz+puv0zYu cGgKZBrVZxUWU7CS3TGPURcIRmsPD8TQbHqQkEQfbPNeO94l+OManKTpcqUciFpV PdxsaYn3xb3blXe0Cipk4vm5DYyWBD9s13lV7MtSLSWyr1P37KBJ1DoKomTsIuQm 0ajbB7qbvWN4tjM4dqehkpthKwTP9SESAfPcTX3zkCQ7/mOINdQlThwBCa48P8+U ZqFwAngDb75Tkr3DcTCUaRoECnphf8E4fcofkFoNzLv8wuULvOUm5zIEIG2A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715590075; x=1715676475; bh=oDSx4O1DdPDnXTNU+VrbiULKCzP5 hm9rw/H9XPM8sN0=; b=jzgYwkzPXNTM4KYtW6WQ0BtPWQ5ChoLwfaPkBuYtMlvr JqC4t3FDbXTAHz6UmJbsowJnBAP1rQOv8mRf27vkdpPMsWO55teFyzYRKdAs04Ac qdUaqQFiO1R9v17t+4c4hiV/qUDu2F5e8Wwx4i6RFNoygChR1t3bZ1JuiMZSrjJy PeNElIiKo03geiJfzZQhFVlWajvsBkoI4bVTiDf0hvAgZtd3bkOWb7u1c+XNotXH 6Hst0yajRDcWZRWNQHrVHkscch5ox+peaJ2+Md3UHYsyFWY0zbNuQicObkpCvtvv 2C4hYerbxDwskBJrybaku/bNiCRy8gTkDJjRhbJkkA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeggedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepvefhuefhudetfeeltedvheeufeejuddtueeiieeitdeffffhieevuedukeevteeg necuffhomhgrihhnpehosghjpghofhhfshgvthhsrdhishenucevlhhushhtvghrufhiii gvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 May 2024 04:47:54 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 239f03fb (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 13 May 2024 08:47:35 +0000 (UTC) Date: Mon, 13 May 2024 10:47:52 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Justin Tobler Subject: [PATCH v2 11/13] reftable/reader: adapt interface to allow reuse of iterators Message-ID: <07459516508c6982ad185c5f9409be523878bc50.1715589670.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Refactor the interfaces exposed by `struct reftable_reader` and `struct table_iterator` such that they support iterator reuse. This is done by separating initialization of the iterator and seeking on it. Signed-off-by: Patrick Steinhardt --- reftable/reader.c | 31 ++++---------------------- reftable/readwrite_test.c | 35 +++++++++++++++++++---------- reftable/reftable-reader.h | 45 ++++++-------------------------------- 3 files changed, 35 insertions(+), 76 deletions(-) diff --git a/reftable/reader.c b/reftable/reader.c index a5a13cb0b9..bbdb4bdafa 100644 --- a/reftable/reader.c +++ b/reftable/reader.c @@ -621,39 +621,16 @@ static void reader_init_iter(struct reftable_reader *r, } } -int reftable_reader_seek_ref(struct reftable_reader *r, - struct reftable_iterator *it, const char *name) +void reftable_reader_init_ref_iterator(struct reftable_reader *r, + struct reftable_iterator *it) { - struct reftable_record rec = { - .type = BLOCK_TYPE_REF, - .u.ref = { - .refname = (char *)name, - }, - }; reader_init_iter(r, it, BLOCK_TYPE_REF); - return iterator_seek(it, &rec); } -int reftable_reader_seek_log_at(struct reftable_reader *r, - struct reftable_iterator *it, const char *name, - uint64_t update_index) +void reftable_reader_init_log_iterator(struct reftable_reader *r, + struct reftable_iterator *it) { - struct reftable_record rec = { - .type = BLOCK_TYPE_LOG, - .u.log = { - .refname = (char *)name, - .update_index = update_index, - }, - }; reader_init_iter(r, it, BLOCK_TYPE_LOG); - return iterator_seek(it, &rec); -} - -int reftable_reader_seek_log(struct reftable_reader *r, - struct reftable_iterator *it, const char *name) -{ - uint64_t max = ~((uint64_t)0); - return reftable_reader_seek_log_at(r, it, name, max); } void reader_close(struct reftable_reader *r) diff --git a/reftable/readwrite_test.c b/reftable/readwrite_test.c index a6dbd214c5..d99543bbd6 100644 --- a/reftable/readwrite_test.c +++ b/reftable/readwrite_test.c @@ -239,7 +239,9 @@ static void test_log_write_read(void) err = init_reader(&rd, &source, "file.log"); EXPECT_ERR(err); - err = reftable_reader_seek_ref(&rd, &it, names[N - 1]); + reftable_reader_init_ref_iterator(&rd, &it); + + err = reftable_iterator_seek_ref(&it, names[N - 1]); EXPECT_ERR(err); err = reftable_iterator_next_ref(&it, &ref); @@ -252,7 +254,9 @@ static void test_log_write_read(void) reftable_iterator_destroy(&it); reftable_ref_record_release(&ref); - err = reftable_reader_seek_log(&rd, &it, ""); + reftable_reader_init_log_iterator(&rd, &it); + + err = reftable_iterator_seek_log(&it, ""); EXPECT_ERR(err); i = 0; @@ -330,7 +334,8 @@ static void test_log_zlib_corruption(void) err = init_reader(&rd, &source, "file.log"); EXPECT_ERR(err); - err = reftable_reader_seek_log(&rd, &it, "refname"); + reftable_reader_init_log_iterator(&rd, &it); + err = reftable_iterator_seek_log(&it, "refname"); EXPECT(err == REFTABLE_ZLIB_ERROR); reftable_iterator_destroy(&it); @@ -358,7 +363,8 @@ static void test_table_read_write_sequential(void) err = init_reader(&rd, &source, "file.ref"); EXPECT_ERR(err); - err = reftable_reader_seek_ref(&rd, &it, ""); + reftable_reader_init_ref_iterator(&rd, &it); + err = reftable_iterator_seek_ref(&it, ""); EXPECT_ERR(err); while (1) { @@ -412,7 +418,8 @@ static void test_table_read_api(void) err = init_reader(&rd, &source, "file.ref"); EXPECT_ERR(err); - err = reftable_reader_seek_ref(&rd, &it, names[0]); + reftable_reader_init_ref_iterator(&rd, &it); + err = reftable_iterator_seek_ref(&it, names[0]); EXPECT_ERR(err); err = reftable_iterator_next_log(&it, &log); @@ -457,7 +464,8 @@ static void test_table_read_write_seek(int index, int hash_id) } for (i = 1; i < N; i++) { - int err = reftable_reader_seek_ref(&rd, &it, names[i]); + reftable_reader_init_ref_iterator(&rd, &it); + err = reftable_iterator_seek_ref(&it, names[i]); EXPECT_ERR(err); err = reftable_iterator_next_ref(&it, &ref); EXPECT_ERR(err); @@ -472,7 +480,8 @@ static void test_table_read_write_seek(int index, int hash_id) strbuf_addstr(&pastLast, names[N - 1]); strbuf_addstr(&pastLast, "/"); - err = reftable_reader_seek_ref(&rd, &it, pastLast.buf); + reftable_reader_init_ref_iterator(&rd, &it); + err = reftable_iterator_seek_ref(&it, pastLast.buf); if (err == 0) { struct reftable_ref_record ref = { NULL }; int err = reftable_iterator_next_ref(&it, &ref); @@ -576,7 +585,8 @@ static void test_table_refs_for(int indexed) rd.obj_offsets.is_present = 0; } - err = reftable_reader_seek_ref(&rd, &it, ""); + reftable_reader_init_ref_iterator(&rd, &it); + err = reftable_iterator_seek_ref(&it, ""); EXPECT_ERR(err); reftable_iterator_destroy(&it); @@ -639,7 +649,8 @@ static void test_write_empty_table(void) err = reftable_new_reader(&rd, &source, "filename"); EXPECT_ERR(err); - err = reftable_reader_seek_ref(rd, &it, ""); + reftable_reader_init_ref_iterator(rd, &it); + err = reftable_iterator_seek_ref(&it, ""); EXPECT_ERR(err); err = reftable_iterator_next_ref(&it, &rec); @@ -846,7 +857,8 @@ static void test_write_multiple_indices(void) * Seeking the log uses the log index now. In case there is any * confusion regarding indices we would notice here. */ - err = reftable_reader_seek_log(reader, &it, ""); + reftable_reader_init_log_iterator(reader, &it); + err = reftable_iterator_seek_log(&it, ""); EXPECT_ERR(err); reftable_iterator_destroy(&it); @@ -901,7 +913,8 @@ static void test_write_multi_level_index(void) /* * Seeking the last ref should work as expected. */ - err = reftable_reader_seek_ref(reader, &it, "refs/heads/199"); + reftable_reader_init_ref_iterator(reader, &it); + err = reftable_iterator_seek_ref(&it, "refs/heads/199"); EXPECT_ERR(err); reftable_iterator_destroy(&it); diff --git a/reftable/reftable-reader.h b/reftable/reftable-reader.h index 4a4bc2fdf8..52e4942b7b 100644 --- a/reftable/reftable-reader.h +++ b/reftable/reftable-reader.h @@ -36,48 +36,17 @@ struct reftable_table; int reftable_new_reader(struct reftable_reader **pp, struct reftable_block_source *src, const char *name); -/* reftable_reader_seek_ref returns an iterator where 'name' would be inserted - in the table. To seek to the start of the table, use name = "". - - example: - - struct reftable_reader *r = NULL; - int err = reftable_new_reader(&r, &src, "filename"); - if (err < 0) { ... } - struct reftable_iterator it = {0}; - err = reftable_reader_seek_ref(r, &it, "refs/heads/master"); - if (err < 0) { ... } - struct reftable_ref_record ref = {0}; - while (1) { - err = reftable_iterator_next_ref(&it, &ref); - if (err > 0) { - break; - } - if (err < 0) { - ..error handling.. - } - ..found.. - } - reftable_iterator_destroy(&it); - reftable_ref_record_release(&ref); -*/ -int reftable_reader_seek_ref(struct reftable_reader *r, - struct reftable_iterator *it, const char *name); +/* Initialize a reftable iterator for reading refs. */ +void reftable_reader_init_ref_iterator(struct reftable_reader *r, + struct reftable_iterator *it); + +/* Initialize a reftable iterator for reading logs. */ +void reftable_reader_init_log_iterator(struct reftable_reader *r, + struct reftable_iterator *it); /* returns the hash ID used in this table. */ uint32_t reftable_reader_hash_id(struct reftable_reader *r); -/* seek to logs for the given name, older than update_index. To seek to the - start of the table, use name = "". -*/ -int reftable_reader_seek_log_at(struct reftable_reader *r, - struct reftable_iterator *it, const char *name, - uint64_t update_index); - -/* seek to newest log entry for given name. */ -int reftable_reader_seek_log(struct reftable_reader *r, - struct reftable_iterator *it, const char *name); - /* closes and deallocates a reader. */ void reftable_reader_free(struct reftable_reader *); From patchwork Mon May 13 08:47:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13663220 Received: from wfhigh5-smtp.messagingengine.com (wfhigh5-smtp.messagingengine.com [64.147.123.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F24D6146A98 for ; Mon, 13 May 2024 08:48:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590082; cv=none; b=ZLDI632Cf+LKZWbwYlWNJAVGlUOvHAGQ7GlAhilvPCthI48lcII3v6pG9Zs4XdoIVt78ZdBPBl07YZMcUlwVcKQYAHb6hBfWBepTWlfTDoxCXMxuY7reRtFJm2L8H0akH87h52buSrEFD98HEaxctae2kr7YYp9O0swn/Op9TwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590082; c=relaxed/simple; bh=qbbNgnBPf8oJ4xbMLZ5l1OdXbo0p1RripaMdjgM+WAM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nUB+hCoo3oB+ytxzF9XGkwlTrp/h9csi2A60j1SxRggvOw/1aFrgmYn2mU9pA5Zx3B3CUpDwmjRAekbF+CSC6qtN0+Ohe0YGQrgYAfZaVqC4abYWwNzRHGu/vCtYKSYrG2ptw5pqfN8EKVqNJT4Y2MkKsclpJxhiKXPib4T+xhI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=GZznd0TB; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=WM7ANPvR; arc=none smtp.client-ip=64.147.123.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="GZznd0TB"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="WM7ANPvR" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.west.internal (Postfix) with ESMTP id 3B17A180013A; Mon, 13 May 2024 04:48:00 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 13 May 2024 04:48:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715590079; x=1715676479; bh=KAVOa4X+aA HRMB4NJ/2vr/1D3jRVHa4GmHXoAKuL7jk=; b=GZznd0TB+pKOBaM1ppim8+0QHi e3eNj3PHrHKJ5lPMQ/7TgupnkSFlE5EtGwB1dCPWK5Via+eRU8yV29VC5tmVmsu2 bn93cxXvzd42JNZRRd8QvkT32FwNyzQWApVgTOuaVzbf7VEqOUZhonXaZJoizGwk TgtPys5VdUx5qymseCz9ngTQnFooxEF413APlw4jymbRcKm3trxMpVWz72ka0dkL opMwGHRWJGhthb3Un6EpBxr+eBWoYhsFytesUP37WHW0CVO/l05qi6qnpyiImfJP kGKYXw0hdKWfAbTbF9cUBH7iGjf/FVlJGPH+ExSKsoTJOpyUoEcp7qRqorBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715590079; x=1715676479; bh=KAVOa4X+aAHRMB4NJ/2vr/1D3jRV Ha4GmHXoAKuL7jk=; b=WM7ANPvRzP5kw+PsGMIXjOkE5PbPcGeyNfnc1lCaRrfr hVuWJ7Vf7fQPkRBZIc1yOktnCzzg6JDZ2ANFOJL2wIokOj55IzqsTLSKKWpYqqK6 03huvT6hILXkV/s3wkNLcSPdhKDLUtU7TzAtDreC6mRJPS1KNjjzsOvJzLbUc+Cj 5EcCqj96lI/bHhG7Nkv7Q/5dne0mK7BOt78gD7RwpYRbJTHcwo/uHQ+gaC75G3St 8RiUiwWRD1UhH3EbqtXcfwq8HtxKRx/6b2pUXLCPpDF3DrCV6fSkiYJZKzEeI+Kj G6/f0l6k84QLtq+M9cDkxaS7ZbH9+oPFvt7GqnwzFA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeggedgtdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 May 2024 04:47:58 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 0d6f608d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 13 May 2024 08:47:40 +0000 (UTC) Date: Mon, 13 May 2024 10:47:56 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Justin Tobler Subject: [PATCH v2 12/13] reftable/stack: provide convenience functions to create iterators Message-ID: <51480c43287ee3164d108859725ca819b3466df5.1715589670.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: There exist a bunch of call sites in the reftable backend that want to create iterators for a reftable stack. This is rather convoluted right now, where you always have to go via the merged table. And it is about to become even more convoluted when we split up iterator initialization and seeking in the next commit. Introduce convenience functions that allow the caller to create an iterator from a reftable stack directly without going through the merged table. Adapt callers accordingly. Signed-off-by: Patrick Steinhardt --- refs/reftable-backend.c | 48 +++++++++++++++++---------------------- reftable/merged.c | 6 ++--- reftable/merged.h | 6 +++++ reftable/reftable-stack.h | 18 +++++++++++++++ reftable/stack.c | 15 ++++++++++++ 5 files changed, 63 insertions(+), 30 deletions(-) diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index 010ef811b6..7ac2772bcb 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -15,7 +15,6 @@ #include "../reftable/reftable-record.h" #include "../reftable/reftable-error.h" #include "../reftable/reftable-iterator.h" -#include "../reftable/reftable-merged.h" #include "../setup.h" #include "../strmap.h" #include "parse.h" @@ -462,7 +461,6 @@ static struct reftable_ref_iterator *ref_iterator_for_stack(struct reftable_ref_ const char *prefix, int flags) { - struct reftable_merged_table *merged_table; struct reftable_ref_iterator *iter; int ret; @@ -482,9 +480,8 @@ static struct reftable_ref_iterator *ref_iterator_for_stack(struct reftable_ref_ if (ret) goto done; - merged_table = reftable_stack_merged_table(stack); - - ret = reftable_merged_table_seek_ref(merged_table, &iter->iter, prefix); + reftable_stack_init_ref_iterator(stack, &iter->iter); + ret = reftable_iterator_seek_ref(&iter->iter, prefix); if (ret) goto done; @@ -1015,8 +1012,6 @@ static int transaction_update_cmp(const void *a, const void *b) static int write_transaction_table(struct reftable_writer *writer, void *cb_data) { struct write_transaction_table_arg *arg = cb_data; - struct reftable_merged_table *mt = - reftable_stack_merged_table(arg->stack); uint64_t ts = reftable_stack_next_update_index(arg->stack); struct reftable_log_record *logs = NULL; struct ident_split committer_ident = {0}; @@ -1051,6 +1046,8 @@ static int write_transaction_table(struct reftable_writer *writer, void *cb_data struct reftable_log_record log = {0}; struct reftable_iterator it = {0}; + reftable_stack_init_log_iterator(arg->stack, &it); + /* * When deleting refs we also delete all reflog entries * with them. While it is not strictly required to @@ -1060,7 +1057,7 @@ static int write_transaction_table(struct reftable_writer *writer, void *cb_data * Unfortunately, we have no better way than to delete * all reflog entries one by one. */ - ret = reftable_merged_table_seek_log(mt, &it, u->refname); + ret = reftable_iterator_seek_log(&it, u->refname); while (ret == 0) { struct reftable_log_record *tombstone; @@ -1354,7 +1351,6 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data) { struct write_copy_arg *arg = cb_data; uint64_t deletion_ts, creation_ts; - struct reftable_merged_table *mt = reftable_stack_merged_table(arg->stack); struct reftable_ref_record old_ref = {0}, refs[2] = {0}; struct reftable_log_record old_log = {0}, *logs = NULL; struct reftable_iterator it = {0}; @@ -1488,7 +1484,8 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data) * copy over all log entries from the old reflog. Last but not least, * when renaming we also have to delete all the old reflog entries. */ - ret = reftable_merged_table_seek_log(mt, &it, arg->oldname); + reftable_stack_init_log_iterator(arg->stack, &it); + ret = reftable_iterator_seek_log(&it, arg->oldname); if (ret < 0) goto done; @@ -1694,7 +1691,6 @@ static struct ref_iterator_vtable reftable_reflog_iterator_vtable = { static struct reftable_reflog_iterator *reflog_iterator_for_stack(struct reftable_ref_store *refs, struct reftable_stack *stack) { - struct reftable_merged_table *merged_table; struct reftable_reflog_iterator *iter; int ret; @@ -1711,9 +1707,8 @@ static struct reftable_reflog_iterator *reflog_iterator_for_stack(struct reftabl if (ret < 0) goto done; - merged_table = reftable_stack_merged_table(stack); - - ret = reftable_merged_table_seek_log(merged_table, &iter->iter, ""); + reftable_stack_init_log_iterator(stack, &iter->iter); + ret = reftable_iterator_seek_log(&iter->iter, ""); if (ret < 0) goto done; @@ -1771,7 +1766,6 @@ static int reftable_be_for_each_reflog_ent_reverse(struct ref_store *ref_store, struct reftable_ref_store *refs = reftable_be_downcast(ref_store, REF_STORE_READ, "for_each_reflog_ent_reverse"); struct reftable_stack *stack = stack_for(refs, refname, &refname); - struct reftable_merged_table *mt = NULL; struct reftable_log_record log = {0}; struct reftable_iterator it = {0}; int ret; @@ -1779,8 +1773,8 @@ static int reftable_be_for_each_reflog_ent_reverse(struct ref_store *ref_store, if (refs->err < 0) return refs->err; - mt = reftable_stack_merged_table(stack); - ret = reftable_merged_table_seek_log(mt, &it, refname); + reftable_stack_init_log_iterator(stack, &it); + ret = reftable_iterator_seek_log(&it, refname); while (!ret) { ret = reftable_iterator_next_log(&it, &log); if (ret < 0) @@ -1808,7 +1802,6 @@ static int reftable_be_for_each_reflog_ent(struct ref_store *ref_store, struct reftable_ref_store *refs = reftable_be_downcast(ref_store, REF_STORE_READ, "for_each_reflog_ent"); struct reftable_stack *stack = stack_for(refs, refname, &refname); - struct reftable_merged_table *mt = NULL; struct reftable_log_record *logs = NULL; struct reftable_iterator it = {0}; size_t logs_alloc = 0, logs_nr = 0, i; @@ -1817,8 +1810,8 @@ static int reftable_be_for_each_reflog_ent(struct ref_store *ref_store, if (refs->err < 0) return refs->err; - mt = reftable_stack_merged_table(stack); - ret = reftable_merged_table_seek_log(mt, &it, refname); + reftable_stack_init_log_iterator(stack, &it); + ret = reftable_iterator_seek_log(&it, refname); while (!ret) { struct reftable_log_record log = {0}; @@ -1855,7 +1848,6 @@ static int reftable_be_reflog_exists(struct ref_store *ref_store, struct reftable_ref_store *refs = reftable_be_downcast(ref_store, REF_STORE_READ, "reflog_exists"); struct reftable_stack *stack = stack_for(refs, refname, &refname); - struct reftable_merged_table *mt = reftable_stack_merged_table(stack); struct reftable_log_record log = {0}; struct reftable_iterator it = {0}; int ret; @@ -1868,7 +1860,8 @@ static int reftable_be_reflog_exists(struct ref_store *ref_store, if (ret < 0) goto done; - ret = reftable_merged_table_seek_log(mt, &it, refname); + reftable_stack_init_log_iterator(stack, &it); + ret = reftable_iterator_seek_log(&it, refname); if (ret < 0) goto done; @@ -1966,8 +1959,6 @@ struct write_reflog_delete_arg { static int write_reflog_delete_table(struct reftable_writer *writer, void *cb_data) { struct write_reflog_delete_arg *arg = cb_data; - struct reftable_merged_table *mt = - reftable_stack_merged_table(arg->stack); struct reftable_log_record log = {0}, tombstone = {0}; struct reftable_iterator it = {0}; uint64_t ts = reftable_stack_next_update_index(arg->stack); @@ -1975,12 +1966,14 @@ static int write_reflog_delete_table(struct reftable_writer *writer, void *cb_da reftable_writer_set_limits(writer, ts, ts); + reftable_stack_init_log_iterator(arg->stack, &it); + /* * In order to delete a table we need to delete all reflog entries one * by one. This is inefficient, but the reftable format does not have a * better marker right now. */ - ret = reftable_merged_table_seek_log(mt, &it, arg->refname); + ret = reftable_iterator_seek_log(&it, arg->refname); while (ret == 0) { ret = reftable_iterator_next_log(&it, &log); if (ret < 0) @@ -2116,7 +2109,6 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store, struct reftable_ref_store *refs = reftable_be_downcast(ref_store, REF_STORE_WRITE, "reflog_expire"); struct reftable_stack *stack = stack_for(refs, refname, &refname); - struct reftable_merged_table *mt = reftable_stack_merged_table(stack); struct reftable_log_record *logs = NULL; struct reftable_log_record *rewritten = NULL; struct reftable_ref_record ref_record = {0}; @@ -2135,7 +2127,9 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store, if (ret < 0) goto done; - ret = reftable_merged_table_seek_log(mt, &it, refname); + reftable_stack_init_log_iterator(stack, &it); + + ret = reftable_iterator_seek_log(&it, refname); if (ret < 0) goto done; diff --git a/reftable/merged.c b/reftable/merged.c index fc7946d90d..d127f99360 100644 --- a/reftable/merged.c +++ b/reftable/merged.c @@ -253,9 +253,9 @@ reftable_merged_table_min_update_index(struct reftable_merged_table *mt) return mt->min; } -static void merged_table_init_iter(struct reftable_merged_table *mt, - struct reftable_iterator *it, - uint8_t typ) +void merged_table_init_iter(struct reftable_merged_table *mt, + struct reftable_iterator *it, + uint8_t typ) { struct merged_iter *mi = reftable_malloc(sizeof(*mi)); merged_iter_init(mi, mt, typ); diff --git a/reftable/merged.h b/reftable/merged.h index a2571dbc99..a10469f58e 100644 --- a/reftable/merged.h +++ b/reftable/merged.h @@ -26,4 +26,10 @@ struct reftable_merged_table { void merged_table_release(struct reftable_merged_table *mt); +struct reftable_iterator; + +void merged_table_init_iter(struct reftable_merged_table *mt, + struct reftable_iterator *it, + uint8_t typ); + #endif diff --git a/reftable/reftable-stack.h b/reftable/reftable-stack.h index 1b602dda58..26740e6073 100644 --- a/reftable/reftable-stack.h +++ b/reftable/reftable-stack.h @@ -66,6 +66,24 @@ int reftable_stack_add(struct reftable_stack *st, void *write_arg), void *write_arg); +struct reftable_iterator; + +/* + * Initialize an iterator for the merged tables contained in the stack that can + * be used to iterate through refs. The iterator is valid until the next reload + * or write. + */ +void reftable_stack_init_ref_iterator(struct reftable_stack *st, + struct reftable_iterator *it); + +/* + * Initialize an iterator for the merged tables contained in the stack that can + * be used to iterate through logs. The iterator is valid until the next reload + * or write. + */ +void reftable_stack_init_log_iterator(struct reftable_stack *st, + struct reftable_iterator *it); + /* returns the merged_table for seeking. This table is valid until the * next write or reload, and should not be closed or deleted. */ diff --git a/reftable/stack.c b/reftable/stack.c index a59ebe038d..03f95935e1 100644 --- a/reftable/stack.c +++ b/reftable/stack.c @@ -10,6 +10,7 @@ license that can be found in the LICENSE file or at #include "../write-or-die.h" #include "system.h" +#include "constants.h" #include "merged.h" #include "reader.h" #include "reftable-error.h" @@ -130,6 +131,20 @@ int read_lines(const char *filename, char ***namesp) return err; } +void reftable_stack_init_ref_iterator(struct reftable_stack *st, + struct reftable_iterator *it) +{ + merged_table_init_iter(reftable_stack_merged_table(st), + it, BLOCK_TYPE_REF); +} + +void reftable_stack_init_log_iterator(struct reftable_stack *st, + struct reftable_iterator *it) +{ + merged_table_init_iter(reftable_stack_merged_table(st), + it, BLOCK_TYPE_LOG); +} + struct reftable_merged_table * reftable_stack_merged_table(struct reftable_stack *st) { From patchwork Mon May 13 08:48:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13663221 Received: from wfhigh5-smtp.messagingengine.com (wfhigh5-smtp.messagingengine.com [64.147.123.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5861146A98 for ; Mon, 13 May 2024 08:48:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590088; cv=none; b=af2/daydwUF044wtZbGmCslXDrblrOqxZsbI8P+YlaIG+trq4bCZfbIh2svxBYiN7yWo9zMZwMq7K2IcSfH6+FK6ag9RF0moVK+eAcGntuzKoOwTnv8ci+p9CY0X3IsH2Nk1+HEbHFrVB7U8QLIafd/SWMqh+0B2fqSKZMpHIh0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590088; c=relaxed/simple; bh=QtjfV7V6NdXsRv6YoAtrU4ClCr6LLIowABt20MWHtow=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nFoPZWFX6AZMo9viaDux28ienH/qiZcJYyHB/wN+oO0RLRaPf7AVA/cAplJ1jfG/vh0zXiWGuNBA32MnrVknWqB8Lq7cVhLHVD5K/9X8g3slCppwHnWALR+dfq+SAzYxCNanZvuWKEwjgepLC7AmBwBGsNnI4gzWN/9iYq2MI7s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=lsjQeSBk; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=T565MZBe; arc=none smtp.client-ip=64.147.123.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="lsjQeSBk"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="T565MZBe" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.west.internal (Postfix) with ESMTP id 0E6F71800080; Mon, 13 May 2024 04:48:05 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Mon, 13 May 2024 04:48:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715590085; x=1715676485; bh=rVWkdb9tcW iNoEPv0KKrWd5SlqWtdfPc10uR6zVEQdM=; b=lsjQeSBk/IW135B+4231k+0QzH fdtOwFLRs+8zOPDFbhspraTxaqGxWIioKghiiV0qtMNLbi05xN0N0YAy18kWSLUR EfyG/oonYGR/AOKtO6BLQBdm+oksQPDzR3GxirJGy8DeMgyvQ0Cvsphvodwpq7WW F/7nCzX3G8UesuEErRbYyxUdsjjSvgRXVjMnjDqMlywmcA7Ku6IogWuKix/wPp44 ZoPs/jPTEB/7HmVPSCI5CTFV0D5OAvK+vSh4Sun60XfMRL+/o+dz2nSu6KtDd0Ah RdLX+cjrHfNXgZ5EfrwtN4hhcd0goj2kZQadzRh2iRUVtjee06/9qmWAG4tw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715590085; x=1715676485; bh=rVWkdb9tcWiNoEPv0KKrWd5SlqWt dfPc10uR6zVEQdM=; b=T565MZBe06fkLIjKA66ZHSa9DANUBa4OxbL3qHosCRAP CHabEBaDgJrTdfLKqURkz/L8VBodgTH8PmAbVDSm4oMCaymkT3TYfPTq87HjzXZS mpcqpvmEtocp9UWaWKleVL4N2EidEBN11CnCASLU8k1hqqxEuW4A24TTS1endqTu h0thT2i1TJjotQc0X7d+6cor93Sld5krhtlUBny+B/o8sq2eHjcLtI+Puj3sZuG8 gyfDuRh27cexvOuq03eAOnvXu8aWriCAVuJ4SXPA7UscKSfImVUMY1K7vfAkDzY7 TDUGq/TRDiboWx0zTd4VesdYUBybXxNxXiaz9LGwzw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeggedgtdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 May 2024 04:48:04 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 38b09d1a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 13 May 2024 08:47:45 +0000 (UTC) Date: Mon, 13 May 2024 10:48:01 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Justin Tobler Subject: [PATCH v2 13/13] reftable/merged: adapt interface to allow reuse of iterators Message-ID: <2586e93c448e5df2fab51ba231e413c12e522f0e.1715589670.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Refactor the interfaces exposed by `struct reftable_merged_table` and `struct merged_iter` such that they support iterator reuse. This is done by separating initialization of the iterator and seeking on it. Signed-off-by: Patrick Steinhardt --- reftable/merged.c | 35 ----------------------------------- reftable/merged_test.c | 19 +++++++++++++------ reftable/reftable-merged.h | 15 --------------- reftable/stack.c | 14 +++++++++----- 4 files changed, 22 insertions(+), 61 deletions(-) diff --git a/reftable/merged.c b/reftable/merged.c index d127f99360..0da9dba265 100644 --- a/reftable/merged.c +++ b/reftable/merged.c @@ -262,41 +262,6 @@ void merged_table_init_iter(struct reftable_merged_table *mt, iterator_from_merged_iter(it, mi); } -int reftable_merged_table_seek_ref(struct reftable_merged_table *mt, - struct reftable_iterator *it, - const char *name) -{ - struct reftable_record rec = { - .type = BLOCK_TYPE_REF, - .u.ref = { - .refname = (char *)name, - }, - }; - merged_table_init_iter(mt, it, BLOCK_TYPE_REF); - return iterator_seek(it, &rec); -} - -int reftable_merged_table_seek_log_at(struct reftable_merged_table *mt, - struct reftable_iterator *it, - const char *name, uint64_t update_index) -{ - struct reftable_record rec = { .type = BLOCK_TYPE_LOG, - .u.log = { - .refname = (char *)name, - .update_index = update_index, - } }; - merged_table_init_iter(mt, it, BLOCK_TYPE_LOG); - return iterator_seek(it, &rec); -} - -int reftable_merged_table_seek_log(struct reftable_merged_table *mt, - struct reftable_iterator *it, - const char *name) -{ - uint64_t max = ~((uint64_t)0); - return reftable_merged_table_seek_log_at(mt, it, name, max); -} - uint32_t reftable_merged_table_hash_id(struct reftable_merged_table *mt) { return mt->hash_id; diff --git a/reftable/merged_test.c b/reftable/merged_test.c index 530fc82d1c..33a17efcde 100644 --- a/reftable/merged_test.c +++ b/reftable/merged_test.c @@ -12,6 +12,7 @@ license that can be found in the LICENSE file or at #include "basics.h" #include "blocksource.h" +#include "constants.h" #include "reader.h" #include "record.h" #include "test_framework.h" @@ -145,7 +146,10 @@ static void test_merged_between(void) int i; struct reftable_ref_record ref = { NULL }; struct reftable_iterator it = { NULL }; - int err = reftable_merged_table_seek_ref(mt, &it, "a"); + int err; + + merged_table_init_iter(mt, &it, BLOCK_TYPE_REF); + err = reftable_iterator_seek_ref(&it, "a"); EXPECT_ERR(err); err = reftable_iterator_next_ref(&it, &ref); @@ -217,14 +221,15 @@ static void test_merged(void) struct reftable_reader **readers = NULL; struct reftable_merged_table *mt = merged_table_from_records(refs, &bs, &readers, sizes, bufs, 3); - struct reftable_iterator it = { NULL }; - int err = reftable_merged_table_seek_ref(mt, &it, "a"); + int err; struct reftable_ref_record *out = NULL; size_t len = 0; size_t cap = 0; int i = 0; + merged_table_init_iter(mt, &it, BLOCK_TYPE_REF); + err = reftable_iterator_seek_ref(&it, "a"); EXPECT_ERR(err); EXPECT(reftable_merged_table_hash_id(mt) == GIT_SHA1_FORMAT_ID); EXPECT(reftable_merged_table_min_update_index(mt) == 1); @@ -348,14 +353,15 @@ static void test_merged_logs(void) struct reftable_reader **readers = NULL; struct reftable_merged_table *mt = merged_table_from_log_records( logs, &bs, &readers, sizes, bufs, 3); - struct reftable_iterator it = { NULL }; - int err = reftable_merged_table_seek_log(mt, &it, "a"); + int err; struct reftable_log_record *out = NULL; size_t len = 0; size_t cap = 0; int i = 0; + merged_table_init_iter(mt, &it, BLOCK_TYPE_LOG); + err = reftable_iterator_seek_log(&it, "a"); EXPECT_ERR(err); EXPECT(reftable_merged_table_hash_id(mt) == GIT_SHA1_FORMAT_ID); EXPECT(reftable_merged_table_min_update_index(mt) == 1); @@ -377,7 +383,8 @@ static void test_merged_logs(void) GIT_SHA1_RAWSZ)); } - err = reftable_merged_table_seek_log_at(mt, &it, "a", 2); + merged_table_init_iter(mt, &it, BLOCK_TYPE_LOG); + err = reftable_iterator_seek_log_at(&it, "a", 2); EXPECT_ERR(err); reftable_log_record_release(&out[0]); err = reftable_iterator_next_log(&it, &out[0]); diff --git a/reftable/reftable-merged.h b/reftable/reftable-merged.h index c91a2d83a2..14d5fc9f05 100644 --- a/reftable/reftable-merged.h +++ b/reftable/reftable-merged.h @@ -36,21 +36,6 @@ int reftable_new_merged_table(struct reftable_merged_table **dest, struct reftable_table *stack, size_t n, uint32_t hash_id); -/* returns an iterator positioned just before 'name' */ -int reftable_merged_table_seek_ref(struct reftable_merged_table *mt, - struct reftable_iterator *it, - const char *name); - -/* returns an iterator for log entry, at given update_index */ -int reftable_merged_table_seek_log_at(struct reftable_merged_table *mt, - struct reftable_iterator *it, - const char *name, uint64_t update_index); - -/* like reftable_merged_table_seek_log_at but look for the newest entry. */ -int reftable_merged_table_seek_log(struct reftable_merged_table *mt, - struct reftable_iterator *it, - const char *name); - /* returns the max update_index covered by this merged table. */ uint64_t reftable_merged_table_max_update_index(struct reftable_merged_table *mt); diff --git a/reftable/stack.c b/reftable/stack.c index 03f95935e1..7af4c3fd66 100644 --- a/reftable/stack.c +++ b/reftable/stack.c @@ -925,7 +925,8 @@ static int stack_write_compact(struct reftable_stack *st, goto done; } - err = reftable_merged_table_seek_ref(mt, &it, ""); + merged_table_init_iter(mt, &it, BLOCK_TYPE_REF); + err = reftable_iterator_seek_ref(&it, ""); if (err < 0) goto done; @@ -949,7 +950,8 @@ static int stack_write_compact(struct reftable_stack *st, } reftable_iterator_destroy(&it); - err = reftable_merged_table_seek_log(mt, &it, ""); + merged_table_init_iter(mt, &it, BLOCK_TYPE_LOG); + err = reftable_iterator_seek_log(&it, ""); if (err < 0) goto done; @@ -1340,9 +1342,11 @@ int reftable_stack_read_ref(struct reftable_stack *st, const char *refname, int reftable_stack_read_log(struct reftable_stack *st, const char *refname, struct reftable_log_record *log) { - struct reftable_iterator it = { NULL }; - struct reftable_merged_table *mt = reftable_stack_merged_table(st); - int err = reftable_merged_table_seek_log(mt, &it, refname); + struct reftable_iterator it = {0}; + int err; + + reftable_stack_init_log_iterator(st, &it); + err = reftable_iterator_seek_log(&it, refname); if (err) goto done;