From patchwork Wed May 8 11:03:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13658534 Received: from fout8-smtp.messagingengine.com (fout8-smtp.messagingengine.com [103.168.172.151]) (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 A70597A15D for ; Wed, 8 May 2024 11:03:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166231; cv=none; b=Rupym5ZD0/l97BeU2fw1x2iUJEG5zgz6upbZupuuPL4Mps9tyr29kis8iTiN/4y4Y0uaSEt2vjpGOsztL4l0t/AxKErnw7ASl17zH7fMyGcvvmST8S+MBlqVNFniY/xmaX/SNQsdCkNoVF9TL5FgP+4S/knY1IUEoW6Da0oFT1Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166231; c=relaxed/simple; bh=wAncPLGt3t4OOdRAIlz+DITqp8Sar0AO59jbtqwGq5k=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=c+8B7I9dXzixQzygL/CTNkdxvbmcGbvFuixF2x6MCvRUgfYCJQh6r6vflnTVQdA8taQm/mJyPWQwE4cj3qk6MU6v7TURUKdUEan6FtZFWkjzOLuhRzGPXEhuSyM2SAf7Gki9WtLqjxoMh6/mEhig74EsmwROx9ZEZRJ6Qt4vkbA= 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=ti84UTIH; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=TA72747t; arc=none smtp.client-ip=103.168.172.151 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="ti84UTIH"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="TA72747t" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id C31EB1380FDD for ; Wed, 8 May 2024 07:03:48 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 08 May 2024 07:03:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=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=1715166228; x=1715252628; bh=FAtcAZs2Vr kqjmodc9Yl/RYAGdYG+Otb0P45Zpi803M=; b=ti84UTIHJcnC3RpP3erdnzwN8A cAdTxINXz4LOUEh8rwEPnY3uzcV2K4t+i1+zKoJpOYPA3fap3KvbBW0G5zXPIfLy 8iSf+zn30IX4BunnWV7cor08UUEdUec/S/jKycAwzwA8Pr08SVuiJar9m7VbSXPt 9C+qbNuFaWzEpeBeIoebVbgNYR4wXVp4HcoLfZQE/Ep3o63BV7EHP7fHtgoLcDOJ PW2MghlVH1M7cN8ELqDhZa5QJ/r/70zzAHiZlbVE5YoOlVOycKOrtJ365iNf5wtn LitT+p/cxe6GQbrJ/krC+fFP6Urmdof3lmF5qyGP/zxayNEAwJ272kAjXw1A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=1715166228; x=1715252628; bh=FAtcAZs2Vrkqjmodc9Yl/RYAGdYG +Otb0P45Zpi803M=; b=TA72747tj4KMOEq1mioL45KmZn/NAAKK2ZFG4LMm2c9/ yAVn/8fpZdQRjk48zxuEJ2gVmGcD5ov/c+ROIomTqDhu+Gcin3PaAg1SOy88Xlg0 mkUAU1LnMf3RRqX6p45rXY/ucTEtNM9FfCz3cuS7D2A5QZGexxQWzBSkqcTTWCyG YxWGhTbBPNyRdyrvT42oyE6pHI3Yl7UpaMQRYvhS3NevyCCKtNbOfCY0Cj+RHuiY S6S/RImCc2LBdHMBHpKAerkUPt6LJ6CKWsJMpgvZe75EZHUdqMcYcy6Y3eQFk1XB XRHL3M2ZLU4hBFkmBZuj6KasA3OYJanPqUKocHUypQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeftddgfeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 8 May 2024 07:03:47 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id a0f50e60 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 8 May 2024 11:03:30 +0000 (UTC) Date: Wed, 8 May 2024 13:03:38 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 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 Wed May 8 11:03:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13658535 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 8A4307D3E4 for ; Wed, 8 May 2024 11:03:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166232; cv=none; b=hXDl4vwAIt9YTFGV4e3qko4P+WPxhXw0m6idgiZOpKQ2kHjZn5Ma+aRs4rdk7fJqIv1IwMQlQb6SqeqTCeyGiwLKeyTXGNgc7b8QFFfxVTY7Bb4YX5KJTxWCC4nV0OHSezHaA+NmJ628uuQ+wJuaBVk8dwSnexTgPT4wWwOMO98= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166232; c=relaxed/simple; bh=jehmZ4oZkBNEiFe/b2fK7VWez5e0ZNq2jglYqKDBKlc=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=C44bLAaMZ+PEYsbsso+2cRidfSjoyUp/eAJv0fcwUX2d/3fFUKaeKk43unI24PXZTKWBPKDpGoVQY03HYwu1R8Hy3D2+MZ2xJtbHpe0TWynIKETinShgpnWZB2lc1axAnIoznOuiTqV/RW2nJxvceM/zC69U/Codp1Yi/OlZ+Uo= 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=CFVcfHzA; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=k5sfs/VL; arc=none smtp.client-ip=103.168.172.155 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="CFVcfHzA"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="k5sfs/VL" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id AC07A1140071 for ; Wed, 8 May 2024 07:03:49 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 08 May 2024 07:03:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=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=1715166229; x=1715252629; bh=lhK4RYLwoL UGoHaO3YxHGJPg7J7FGKEBZ4FQJV2PAeQ=; b=CFVcfHzACuDewz7CrUEv8BN+dz NuV3zKc8LVhSJL96oewDINtA+UOwVGvXWlJp9dsZ7kTTjvrySCbJLM20Xrmp0zru rcI9RUy3bhPXSBHBtZFW5kltE1FBvBYh1O37ky7uKqFbLlOPC3TePWxaTbpqAlVD u+oqM9fZvSGuccdHRQoQeYhtWnXMOIx46jirs6H0NXpkJyEU7NNckERn2MNK5eVg gU1bfG9CQxSPDarJ86T2q1Pk84EUfAnCaB17ZkerjmrhpEIx4X88wDc3ZgyehZKd km35FMl+Z6m+fAuOyNJyk/3s7XYc/Hh13MPTHBKwg6ByKVNjjpw3mMyvX6UQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=1715166229; x=1715252629; bh=lhK4RYLwoLUGoHaO3YxHGJPg7J7F GKEBZ4FQJV2PAeQ=; b=k5sfs/VLaGb4o9rbsBvaY+GWj/NbfiHyICNgNwQIZf0/ W92FqMu6bDNGeZ1iNVQDoYx4MJFmWjeYdau1oPqE6g8rpLqpT0QS7OGIHGC2EioU xACsAlYmi3xQvZQ0CzFgDvoSuMHMNJMAAYdwUPULyRnKFwaCWYGGqkGnP1Y/bgr3 0M6SBJR2dooLn3wlEFq5bDSVpB0/mr68E4aA1l/sh5t2D8Aydrrh97/4L4JafFmA eMqCbYdhjCr1Yy11CRb81oOnlRT3TsowYUDqyZYhE/crjhBRljL3BkQHePeTFj8o d/okB5e+Qk8SDpnCYOvtFTy/nL25Ob8T1TSd5j9Zpg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeftddgfeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 8 May 2024 07:03:48 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id db50a0f6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 8 May 2024 11:03:35 +0000 (UTC) Date: Wed, 8 May 2024 13:03:42 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 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 Wed May 8 11:03: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: 13658536 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 7A5AD47F6C for ; Wed, 8 May 2024 11:03:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166232; cv=none; b=Brl2oyVQMs1UzRlGSr+VtgW8hQWOcg/VE7/vHKVb5NuTNSJRXB5FVDM4eRl8PwTPka6tAuLJP0uU+bp/1kAAORAwtuj9KlFiHrvV7PJ/7RxcsRqa3bgN0dJjO6kVGDCOzqpOSy9ODopAmL2Cn1JAKOX4PRQEIjSdGVrDpiNN47k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166232; c=relaxed/simple; bh=8GUU6uTvsZaQ6tzOQXJbHUX6sqOHS86dTy8ciPIx054=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VV8KserZkvLu5w0MXn2OAVVDGZX7iczCs8M4nTm4rdezgXpHr8T95794IgcCzfY6bU1dJ+pcPawkm4opyTlPsi8NyF98/gv0/cw13bKXiZFYQy7Y/v1Qns7Bhzr1m9St9jieH/RnPi0Vf7VWXahu+n1qo2YKA+EOVRyGh8K9r4w= 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=BTBiPcKd; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=eg0hS+Pl; arc=none smtp.client-ip=103.168.172.155 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="BTBiPcKd"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="eg0hS+Pl" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 99D2D1140244 for ; Wed, 8 May 2024 07:03:50 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 08 May 2024 07:03:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=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=1715166230; x=1715252630; bh=p0J6ziEBN8 gkGGGdN/msA/lX0AfjB26dbv9YQzNFq5g=; b=BTBiPcKdPq8uEB72kGkhKycQyj wvR5D6KXAHmT76HcHyKd8EaJB7GHq0qvb1aJNfhcI/yVIqpJmqIZKPtJCOD/cXPN 8b0kd0zVkF9fQvSf+3NCHkGt50Ndpclpq5dZ0qPHVBXusRm8g7Z1wduziIDEFR0M LG+2wezrMWKu1kP3YQyXYng3bsyTdgyOdmaRsKNdl4xiclEu6L+i0p/TB38MPO56 WseeuXxbgC4+5kvTZhz4jQzDhLgs9Pi3K2PWfeTh3FDxlKvZYNQgfcWY5nMPbWwK z4CEVdAPi6DGgjgqFuSNQj/e9LKTtO40KO+fxSW8Vnd6iI1EFUO4YKktaQHg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=1715166230; x=1715252630; bh=p0J6ziEBN8gkGGGdN/msA/lX0Afj B26dbv9YQzNFq5g=; b=eg0hS+PlLdgY/Ahepw5E5/PESJ9hwiuLuwUjRqUE5/cj YNAI3KRXC7nlmoR0zsy5XHQvAY9jKhFNESjX1ptp+58AFerOafb4wYh6TDIiqEWz 9nc59v4oHigS1la7Yb2oLLcSvf2yTBshYzI+W3SO4fFDh3L4ptSTFtG7rfHi6E8w sy8UDecOQVSuwEhQzbzEpWSnb0O3hg7yWV/02fBCrUW4jLWuIBq9e8b/Y9JBXjuc SntgI0mbccLEINWwSfZmnHoCzLsc41OmVCiPKVoRIYWbkNmiq7SSDjqk3RRwPJmC SokgnGPXS9OU1Zu5Vl1dqBxpfVzhvf4xMNzoUdO0nA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeftddgfeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 8 May 2024 07:03:49 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 94bffe37 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 8 May 2024 11:03:39 +0000 (UTC) Date: Wed, 8 May 2024 13:03:47 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 03/13] reftable/reader: unify indexed and linear seeking Message-ID: <716863a580f9e1ef8ea796c25c97e50c63585a7b.1715166175.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 Wed May 8 11:03:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13658537 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 7488E81729 for ; Wed, 8 May 2024 11:03:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166237; cv=none; b=OID0QHt5c/ugwHLy6L4YLH+FEByYdvqySADU+MacYVY9KwG3FUCJMB6jqMasSPIg9THBp4r3Z8n8wa+JO/MFb8GMeBXmmvhpa/UJY8P8UrmZOvcHnRLTzKXZTPiwVfEykX6t5DV/MQypj/8c0zEg6Nh3jXl+KtCj5gJl+7xqa4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166237; c=relaxed/simple; bh=Yvr7g5uFV6Crs9TpGgA9y1KhmIXzuhsjfgcVyrrqxzE=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=twp3fFmzaT8SSSWPZp77sGcxYCN3LFx565tESEcmYbMOFUcgV7Z9SKNWJogOXSo5RmQ3CUHkNGmLyqV8PfRG27mHnfISf01zjRw2F6xF4BQg0yrbknbTNSJTCMsmztOA+YlQLWuKVGr0yCugPVqfX3IPsB5CbnCN/oZEkCVaFAk= 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=nG8PYbMM; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=AbIdGsVg; arc=none smtp.client-ip=103.168.172.155 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="nG8PYbMM"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="AbIdGsVg" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 9DDA5114025A for ; Wed, 8 May 2024 07:03:55 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 08 May 2024 07:03:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=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=1715166235; x=1715252635; bh=uWv1iAH4Oe jG5M7xt2bxYGTjSLsIGqMem0z30x9Mfko=; b=nG8PYbMM0Z9qHoWuYYjxt/KeVO cBRVVxcJVvo13LYY/tpUBpEMkm+aFvoDB8HAtXzxVR3TBisumJxV8RXSRtjiqm06 3pZYaskaZ+yBd1dEwBPA4prN2c3nyBZnKjip4hWMUgod0XTSn6qp3eS+22Wvmp+y 1H2yJon8gS0r8Lgmw8J384icof5T3Gf37bxcQ1nf7ZUWjRrRtleSlbxmw3q7Tu96 mrDRj3fRgUyLxaNFBlePMG2CTVVSEsIsWMUjyOebU0106b05vNbE+K9I7iPrpR4w r0VI0QQ/2bbKgQY7N/iT0NxQjC6ZhQ6SeYafsUTfAejDhpD+Rx5WkDNCIOGg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=1715166235; x=1715252635; bh=uWv1iAH4OejG5M7xt2bxYGTjSLsI GqMem0z30x9Mfko=; b=AbIdGsVgQDIWyvyvwzgFkmUOvd9Ea6+++XagIhJTlZCw glHh1yeO2wQlSZtTOVaeRNFYL82vnKOLLBcBwlDc9fKHANgsYpyQCx9lPKaf4M4q lRimtMJH4vyBq2D5bffo/p9+aYKdfJuTs+sh3sQt9vo3UrEqGSrWMiQD2Xxz1HPY KlLdcLPy+QKD4FSXScwITs79uM34CFkF2/f7awCt7yu8CaylsqJRwzmIuudBuO+I ZlsCj+OUCowGgoMLz9zV8WNr5jZjHcdquUq/bmHAaN+cI8CceN1jhBnBts5AlWgE Jywtn2nW5EUX5puzuuFrbtUFKYSgcgRZ7N933IZD9w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeftddgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 8 May 2024 07:03:54 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 3b011c7f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 8 May 2024 11:03:44 +0000 (UTC) Date: Wed, 8 May 2024 13:03:51 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 04/13] reftable/reader: separate concerns of table iter and reftable reader Message-ID: <91db2f18c105611bc85fa07fa6eb33ba600e742a.1715166175.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 Wed May 8 11:03: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: 13658538 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 874F681729 for ; Wed, 8 May 2024 11:04:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166241; cv=none; b=TuHBKTthioU2mUdcpaVWYOTfNBPpYXLpj2XSpMeOreJijQpfv4QV7Dg8CP+uO7bYf+CJCD85yIDY4Sl8YC63hEv6tc5yQJR/z9/Eo57rKcPWy0PhqE30Zkr+QS0r5EnY1FIBOJis6fsgWQsuFejGmrzKa/vadD6VMMrGW3M/rU4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166241; c=relaxed/simple; bh=WxsyxLJT4GjlPUF7cWZDFSWZovva1g1AiRXvQf7PUKU=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QpGGCXUGICeAGT0/uE2eVsMIW5+d7DfkNmtvao/Gs17SeV1H7370HQ5TsTOVfIJJZ1ZB2ppwGGJjl7OHBWD+sg/J6zHRQpWLTLJfLiS7eUB6+RiYJd6Xn+dNdg3I+prn84dQ9yC1Fp3uD2YJQce3CP7a6XFb4A9B+e4fri2+LFg= 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=rxQWkLr1; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=MGifNl1o; arc=none smtp.client-ip=103.168.172.155 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="rxQWkLr1"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="MGifNl1o" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 9C56F1140256 for ; Wed, 8 May 2024 07:03:59 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 08 May 2024 07:03:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=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=1715166239; x=1715252639; bh=ruFr1iLrS4 icLvadiQnjCqpNgC2DZ/vN8VpjAapcKAE=; b=rxQWkLr1YWIr1kJfSSaJVBJLk9 YSHv1D+ZD5OrylItfyozhASHbQs6atH9YjqvKsafDI84Zixea9yNEg3CHWEs/LT1 4ojECLxoawB0Gbla4v3hKDi2g0RRlzYP49y44m/o53ZmRnimE5QHraVGvazMv2AK CyklkudYPDhpkyKz4xPXfar8Ef86L3Ir8ORcQ8gb6N0U6fUwlBMeFtyW3zb/cEJ/ V0+HC543GDXyYIniEOFpDDOsebzJPZmrSG9VMQzQVRcxDAeupWoSV0AS2Gpd1pAb TdcT6Ol2u0jN0bINUfFfLz4Z3LQMah/jyGvTw12RWuzuA+yccHXB74+HdCaQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=1715166239; x=1715252639; bh=ruFr1iLrS4icLvadiQnjCqpNgC2D Z/vN8VpjAapcKAE=; b=MGifNl1ouuA/JuwMfxajDkRDa6s442qkqJczIER8y48F ZucycGjRVWjpO7qRrtT0PzIshTg3/COUTAQR5ygTPYRGZ50NCQOaUIdV3x0hAvdp wjL3jR1g2n9pWMjhJ2wSLxVOrFM2jV3W9lzV8/cdNzOUO6SOoTsklUVrzeCRJU+z +HGM//1AzX4AMYlMOYWfblydFPQTfzXjXp3qnehh0jnumBBLSgmnE+2M1sOJGqAg J+Z3pEmm9X4M9ecPXXyywInFdp0UfWpdQpSswe6kYEbMw//jozLl3wWOjkrM/98Y k13mcVCkfyo47yw7+Na0GB0gssMGpQfMIgZTBcB1Wg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeftddgfeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 8 May 2024 07:03:58 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 18ef1880 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 8 May 2024 11:03:49 +0000 (UTC) Date: Wed, 8 May 2024 13:03:56 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 05/13] reftable/reader: inline `reader_seek_internal()` Message-ID: <4d498ef3426877c703bababaa743dd5613ba5839.1715166175.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 Wed May 8 11:04: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: 13658539 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 BF1E681729 for ; Wed, 8 May 2024 11:04:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166247; cv=none; b=S13OC0Os9rv5VO8WY+455+0g9egGZVRoT2VvvaJfSoJFw/r0LF5QhFDKggrluvUONkH4H9ZbZJHpGPTvn1OISwyaT5OVEl1G9hSCWIGv55kEmnnyh1h6mAA7nA9dhgCAMI+wwRU0fsZqDagFyoI+BrxeBD+SE5XRXgnFHIT5Ekg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166247; c=relaxed/simple; bh=SjQmixg0I5BolOZDDQZTKLfLIYeGvgGglmWn8wHuBPs=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TK4YCud53Hw/DtLZBCcBCiBhBcvfWx/TaGLpkm+XpgdRN1cCNXI2OuyVYdrIO+/0II58Nk0AV0kfBql9PUcI+/71oKWD+riRmF5AI8p1TMDWVoEJpi5D/g/6eKoPvxzPIVwcjEmKxHSSXom+ZFQ4KjA28pxYU3n8lq66gQOL2Zg= 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=VGeM0OyE; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Trc0EOVv; arc=none smtp.client-ip=103.168.172.155 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="VGeM0OyE"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Trc0EOVv" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 917CD1140226 for ; Wed, 8 May 2024 07:04:04 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 08 May 2024 07:04:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=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=1715166244; x=1715252644; bh=O1dnZy4VQ5 p78DneuAJe9CzVH9xMYTUrJOwkbGgNcx8=; b=VGeM0OyEsfO2dXH/TSmLb+tu9z LHQGeECcnx5t21475BXQa/lXz3j5Usd96ux/GEuBpH0o/PsXTmLXniNCYvcV+/y1 nf+D7mncvG/AW7URheiiUpMBpPmCYG0wpVJ85M1wAnKsQtenWcnIEHiHoPs71wnU mjDFcRGA+vS0D8qbnfA8mrfbk/u2XoClfZkeUY+3Lw9IVaU5KCnQxj7s9pcfh2/c xVhjmtwp484tkdDndCqWAA8JSysiIsbFTVdrxHbNUD8RCGfbSp9oXWtOW9n4qrpz bMJMh54feRi/hwaTCEFgFo36iLRA+XUTkQt4/Rupf7w3ZoC7xLKuzjqamjBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=1715166244; x=1715252644; bh=O1dnZy4VQ5p78DneuAJe9CzVH9xM YTUrJOwkbGgNcx8=; b=Trc0EOVvGDy4LTqXXeMXWDgFqTLP+dKKYkyzWOaUfBzY YbhjXorrXQ4C05zrdTLLWdekBqNgwKU0A3vjGKOjocpNaIUkub/aKwaB/Tjoal7d t6Gmmru30fZu++xH3u+bYY5j7Xq/yylRnyniRa3LRUgDge1quvAXt88skbtYOdcZ ZsoKoEIN1Q2nzfv8wq63wLIOsWA2rBKXrZAPuHD8H39a48lmWIeeQfBlbU24MIi2 jI3D20w5iTDYBK77359ayl5usZIuJXWh3s6kMudQE+MJqqLxaU2eBfag6KOLY4nP mO1cwnAqu3UFECTzWTRagJtF1KlKrRlkyIEpQWyfLA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeftddgfeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgepudenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 8 May 2024 07:04:03 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id c7777124 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 8 May 2024 11:03:54 +0000 (UTC) Date: Wed, 8 May 2024 13:04:01 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 06/13] reftable/reader: set up the reader when initializing table iterator Message-ID: <5a10a115841512a46e4d3a3d3713e5532facdb39.1715166175.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 Wed May 8 11:04: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: 13658540 Received: from fout8-smtp.messagingengine.com (fout8-smtp.messagingengine.com [103.168.172.151]) (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 97E807D3E4 for ; Wed, 8 May 2024 11:04:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166252; cv=none; b=qa+AE1604CLFtJkC/e+EPfch1PPItqJGI4eZmQIF4qEC8xgiPW/ww8PTDASCXKkPFu4NuUaXOjdl4SknXVR7sqxnRIwK8Kde2TQNGm/V+GPRrffdBPrt4KauhCm6bs/jVRlsM1CE9Kpq8WbSbP48slSU5/+fjES/kQ45XzYYomA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166252; c=relaxed/simple; bh=ymd+W+XhHeze7Y302xsI20R6tW37iTs97UpHiK5ZFPk=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GyrU3mqGkyPCsplHydckJPlBPfpNZ/RE1sg/b36t3uKg9MjGCwxcYMoBmxR/HbOWteS6v6Zs1Jplm92Du+RSEdKGK689G0l7MQ4jsDhGpEHMw+BXZyYGuPp+aD47fCEtXOwU8Ix4Fn9gJIsuG4gNAX224t9GgLI0bbkz+d/l9pE= 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=rVb4k8HK; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=IuigPLfP; arc=none smtp.client-ip=103.168.172.151 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="rVb4k8HK"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="IuigPLfP" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id A10DF1380FDE for ; Wed, 8 May 2024 07:04:09 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 08 May 2024 07:04:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=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=1715166249; x=1715252649; bh=zVBGUGV/eg XtFwbV2pCtgbleW9ndFrATnQwSlh6ghyU=; b=rVb4k8HKLYZXlNKo9S6r/dHbbg UTm4R4EAOXlDR91TY04DtC5ctOpDqgJrhinf4aLmVKmMu5oXjl/OvVfpudKNhQCM wIxkUaMmlUzs3ZI73iRQs6SHICpZk0r1A2ZbXpfInyeirJ2RQSTkT27O806tD0YD ODsCCeSE8di7U2lpb/F09B9PZwzDXtoPerumuzUB+TrrX1EyzXr5JzhSZh5WbbV7 oR3Km4wIBTJ+FsAmHhWkDQz/qa42HHOFK1pqDAKAoxXJSKLdxlQtJOJsFVlrYX6E SqtbqovTWWefffz8ZwG9/SGlch3YSsS38/Wmn5TmwNSBp7U5VV1nMEiS67qg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=1715166249; x=1715252649; bh=zVBGUGV/egXtFwbV2pCtgbleW9nd FrATnQwSlh6ghyU=; b=IuigPLfP3DjGnvUMZae3YDKnbS0oi7egxr5teP1Svkon 4wk6qCvojFcMpX1mcNC0ao63Aee7FKbp+UdSL5T614frRHj1s4nIF3/gBgdW1Fy1 FNDU947OcgivkHhfSj/FyikYkAWgszouCiDWccdVsFz+AD7J7p5UnJAV04037EwU FYvesVULaTUfYFLoEHT/1aA4AhcT5MiU/fJSLzOnm8PYyV+xb7j31Q/E8ZnJQYrj BXb3DLMWQ7V/79uwHdFHO5apaiBrPVXZ192CAnOMUacF2lAeONMhi+ZIgJUJ6Eo1 PXMnk0Mze7i/cED2W1YrIFiydAIR1gTJpKkEB+1iRg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeftddgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 8 May 2024 07:04:08 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 84345899 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 8 May 2024 11:03:58 +0000 (UTC) Date: Wed, 8 May 2024 13:04:06 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 07/13] reftable/merged: split up initialization and seeking of records Message-ID: <21b3e3ab5f04e66fdd352187b1da699d1ab67cee.1715166175.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_table_iter()`. The scope of these functions is somewhat weird though, where `merged_table_iter()` is only responsible for adding the records of the subiterators to the priority queue. Clarify the scope of those functions such that `merged_table_iter()` 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 Wed May 8 11:04: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: 13658541 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 5910F81AA2 for ; Wed, 8 May 2024 11:04:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166256; cv=none; b=GEG3VTWQJKyCacESEJhzps/xLoyg8aw8NRoD6Vnj6ZzUmxcZSfGMER/7yswrOL0TF86QtN519FUUouYQFWTnett6g2yeJSHI6s7G7R/03WfEndmC6WfGgPsYjpqwAGGvGEEMbXZ0fmzdYsXL4LyBPbp8Btr6akdlZQd9b7Lksbo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166256; c=relaxed/simple; bh=Hj/FvAQEjG22vrfkhkPL7UWVT0GmZl/Y7aWOVXdUVpg=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=b+vusPyXuOb/BtiS6s4FhCn/mqA4MHOzvcQt3GdFG843NAVKAzkrir8SzzRm2sdvsosMTip9lvmIpzF5DFCpEf+st7mgtLgEpisrBGusxSQt5dw2zbnSp4mgn6VW64E5M+K14iBlY3oUFz+9qsVaCdQTRL70ObDpWR/0eopXInk= 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=VCQ4FDjt; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=SD0C9c5+; arc=none smtp.client-ip=103.168.172.155 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="VCQ4FDjt"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="SD0C9c5+" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 8DE8C1140224 for ; Wed, 8 May 2024 07:04:14 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 08 May 2024 07:04:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=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=1715166254; x=1715252654; bh=4zn2XNPS2x uTM/GvMgF+g18tLHkUJuVGA1XZwAFvQ0o=; b=VCQ4FDjt3YyE4HoKsZG8W6Bwd2 8+8t1fO9WNpOWXpvEfdAnC0PIgQOkoKisogbme3Cm2Q0VhKncxPrpTbsCRIF+/qy wY8oonTXMf8F14mMUk6Z6hG5gdb4WxZOpr6HUPUfbKPqjEpyzzn3nOdhMHboNcMD J2OtfHTIQJWKY1ZvZGoJtVclHbLnTsd3XSacdtGUFT3pQvNkw1Z9GBJPh5NT0t8q Srno7qA6pvVz95siIlkn0NnbVECtShSmK761KBIRbqScJyxey4J87ShhZjT6hqE6 c39Vld4SaN+3nMB2oae1yP7HIruI6Hft/Fj3FKkGfx1LRuCwt7gWrS5nlsOg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=1715166254; x=1715252654; bh=4zn2XNPS2xuTM/GvMgF+g18tLHkU JuVGA1XZwAFvQ0o=; b=SD0C9c5+v2OtHdunZ127r106CLM7xL75ovZs1CBE7OzA 0pnCQc1JA2G8MZcaS2yWLPkFcEqtw+aH/a+Mn4Y1aBGZlS4h6xv0/F+xIX7CxYK2 dzmslT4FXdPzn3NfxR6hHQO8kapeniBWfTqJfpNABQgFacVvf+wlVMhIlwViABt4 Dt8MFcLyDF3RhM+x9O6kSDkcEYgsv3CFk3sp8FbVMmteWsaNXnm00nYZwL/4xeqx VQsgoZyK1e1MdU83j0qJW8RZUFQ/hj98IDTNl0O2FsKK90umEipzFs1zcYs4/DXV yNqwk5N2EFwLcu6ZsSObu2EPc4FAHrq7Yc9I8km4GA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeftddgfeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgepvdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 8 May 2024 07:04:13 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id eda0b46c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 8 May 2024 11:04:03 +0000 (UTC) Date: Wed, 8 May 2024 13:04:11 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 08/13] reftable/merged: simplify indices for subiterators 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 seeking on a merged table, we perform the seek for each of the subiterators. If the subiterator hasa 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 Wed May 8 11:04:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13658542 Received: from fout8-smtp.messagingengine.com (fout8-smtp.messagingengine.com [103.168.172.151]) (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 3A21681ACB for ; Wed, 8 May 2024 11:04:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166261; cv=none; b=XOTNMiSU/N3M/SBsatHGDkc2cai+4yhfL/vmyV21j2F1l8BT/BLNpDZH1+EXw6L930iMfpuRMnyx7f0eTSCbY1HVCuoftiu+vxRL2tKHV1K9/pzzCUW9so/FtU64E18EOkPmDJwO6XG3Ojnz96F+k3sPfJzB7PBS7J4VqbSBjw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166261; c=relaxed/simple; bh=gtIZz0tN0CeD2ACHsJepB10xLPHHvO+MSbgqhtPnfAk=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=APUebXuSUzJq/VTLrryML6uyPHWhzjlCpcZzM4v+zTupKBI/Kq4g23qbs44eb8W2gWFLXwcQAQ+pix/mdxARFIfUvjOv2+iUr9IZga/4ZNGORGDM4eALmmvl5Q7f8TY0uCT1c7PxTOSOFAsM6tnoiy6RxFaE+SuTSFUHz3+aspM= 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=hRNHK+9b; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=QupnhcTM; arc=none smtp.client-ip=103.168.172.151 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="hRNHK+9b"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="QupnhcTM" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 689E31380FDD for ; Wed, 8 May 2024 07:04:18 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 08 May 2024 07:04:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=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=1715166258; x=1715252658; bh=DY4LCbNXgi INPrL4LYXaxpZGquKiJ/PjUBZ+FsOZr3c=; b=hRNHK+9bQAmk0WJH47h+dfaktP rTMd4CR9aTghCMcSAYOPyk9IoUaJG043hwO+xLKqMTpmHIOUvZ1xzOGHluwH6DQI I9L03grj4Qx4LCX6xLDZmro+M0AacA5LTHQjjHbPzI3mtbqJl3Rys+cy5gAhnucY gB15e4aXnvLOxzVtUnoXqmfgG3p/KsEkFOXFzkTH5yx64uZe5RGLOMChZreztZyu q0td0jGgchiFwU24nWYPT33MVmuF2YJnGzFphZC4l6uWAnCLHKlN9GyFA1/0Mks/ qLtAXqffluHfQcUi59w/APFgK3i1r6iADbc1UtDINiLKzgAQp7DehAMDQYSg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=1715166258; x=1715252658; bh=DY4LCbNXgiINPrL4LYXaxpZGquKi J/PjUBZ+FsOZr3c=; b=QupnhcTM5TyUZiPzVyzn1q/ToxPUn0ALiecpwyFAZMHu Kx93d8N60OHBjYk3SJYV7V7tnPBrgrxoAlDXIQHwrqdvPXsjgr3MXTuQdfk3m1zb VG5h9jle3OvIXlfZp1rN9+i4eCPU8EqJGhins/krIuBJkByxJMozDQyWbgWbfz4M RKZKKELwwZiCEO3aUAsF2UZ/P9O6FQuZYfLqZrwwXIWf1oH1QqU3q4EzpyTY9dZ0 VulkOCSZwBCUZSgA+YIxFRqGB5hPnRAyqp7vVjTQzDiyZoTNUQEY3CmEYm8ZUiXd 0PWAXVSG8U43GB8qmZ6a3jaOVgfMWhQejDZcJ5jfeA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeftddgfeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgepudenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 8 May 2024 07:04:17 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 6c928add (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 8 May 2024 11:04:08 +0000 (UTC) Date: Wed, 8 May 2024 13:04:15 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 09/13] reftable/generic: move seeking of records into the iterator Message-ID: <859b399e71e92dd7aa0fa7fc9f2d9ca6f389d34a.1715166175.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 for example optimize seeks, for example 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 Wed May 8 11:04:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13658543 Received: from fout8-smtp.messagingengine.com (fout8-smtp.messagingengine.com [103.168.172.151]) (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 647E281ADB for ; Wed, 8 May 2024 11:04:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166266; cv=none; b=KMePFKREg4oe2rWk5IDe7E2f38+W1KMvoXGuwNYJWsjhiEWQuX+OhKfhkUjv6CrI+S1NVM9lpk9f8BsKbcv0y80fvnNHdSdKrvXJq4SoGH546fiCgIwmPHOvxOKkkWna9t92ib7xPJDNTrdd74ZKvFRucGXKUe04t6MDzPiIGGA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166266; c=relaxed/simple; bh=dNtgazP3paDLZTolGNwfBTwaqdWc6cO9SSS6XnFC2G8=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pYtdoJmiCh8kW6EjK2EhgNwNMATcAxyabXtAs0hJzmfV4OtzTpznGLKmuO4CGK+1z3/aXJt4HPmVHAj0hl8Xo+WVvoEBIR54q3ulHaecE+9uR0leAhOhGIFzY09v7/jmHkoMV+Enfx0Dn1sq7ElxGwoXcfh/lKhdxIUSVO0IONg= 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=DTYiHZ1X; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=bLBr4r9b; arc=none smtp.client-ip=103.168.172.151 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="DTYiHZ1X"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bLBr4r9b" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 694F31380FDE for ; Wed, 8 May 2024 07:04:23 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 08 May 2024 07:04:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=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=1715166263; x=1715252663; bh=PqJZl9BwNp jh/OogDXxKv5delp23NJLgBYeAYwJ5uyY=; b=DTYiHZ1XyvudH2GOy7tnqyPxp+ VY290PDBkV7he1+TMhpvvt/H20YXOj7+9cFJU2hSlM9QyR2bFY9p8rESV4PdtPjc 6VGJyZADhrOZWQmvm7C64UV5si/PVuFXjuP4KpRRY5AtDH7p9dp4fuGbdSQmOFxO 35fNC6IZyuqPVM/CUTtKdZAGb2Aa4c4Iu5hIJfA2ioGglWfmLnIadEMM0HuBjvXC I+7Y0KHCXHHXt89m7R2gJ251CWDCIJDwIeLgWCoBqX/cxBMUuPUOHOWVeRdntKPo neK51vth3QpICyvDHmiTYv5+BjNW5P1F4xWWKb5bmi3uZtcRT4GylvZwjhjQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=1715166263; x=1715252663; bh=PqJZl9BwNpjh/OogDXxKv5delp23 NJLgBYeAYwJ5uyY=; b=bLBr4r9bgnA/hUgBPf2VFNG11OBkv0VGvaWJHCsJntLd cYXRxaYaoQzvMB10MPyr9HGGoBJGhiBmj3ehwYL8z3G1Zul1CoWYLWyu3bFQAWW5 uHsS4xoqTy66Dsnb3lgkpDEzNNXvnlFeenTDcyXsoC0vAomKxi5/X99YVOUapT3J yO5MLE2IZVS21MlilqkbvwguqdSUk4qfCB8ISait14uEuFMtoqq5UGTJ9KoXTsrM HV6g1KOqAJFa5YOCsIqwzKsV1azudIPfozYPCN6jRm1KIRQCX0/9fm17Ljs/q6qD sHUtntFOuG98/XkOpO7WziJZ1g1h04W124j7qduKeA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeftddgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgepudenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 8 May 2024 07:04:22 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 880d599d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 8 May 2024 11:04:13 +0000 (UTC) Date: Wed, 8 May 2024 13:04:20 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 10/13] reftable/generic: adapt interface to allow reuse of iterators Message-ID: <727b8fa4327b710aba37b9cc7ca8de0f9bb2efaa.1715166175.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_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 Wed May 8 11:04:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13658544 Received: from fout8-smtp.messagingengine.com (fout8-smtp.messagingengine.com [103.168.172.151]) (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 397EF42ABC for ; Wed, 8 May 2024 11:04:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166270; cv=none; b=Sbea/MvTz+JKTk6TXyl/z9UDL2leX/3v2SVsyNhhXve8FV12BqcaDEyY91912U/Bp+EhnhmQgyFb4ZqnTqzqU01+8mvaHRjeRTSOCpFaISuoJVKRGAHiijI9hJIjixgUBZ7v8oZuaMj4mbUpDmKue3O84g1//amVRjxrBqCYvHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166270; c=relaxed/simple; bh=m4ATRuO9WcDfdW1khLM6f0uy8FgeqRJlzxiajFUXC/E=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LOGnCwwvCtEY4KzO9USoPAF+wEd9S8YXSMoeXkKs14rkDvk9NQgP5S0vcYlnZNVnGO0E2V0R+y5ujQJBYXDIbsmwi6fuqyxoguLbomP/KxUrCLzD9+OrAHz0EcJmnTc8g3NJJIAiWt9p9+SJsMfwD0QobtwygOIqITqG7vEaulo= 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=MseoFQDM; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=IFC7mKDo; arc=none smtp.client-ip=103.168.172.151 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="MseoFQDM"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="IFC7mKDo" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 5CC0C1380FDE for ; Wed, 8 May 2024 07:04:28 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 08 May 2024 07:04:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=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=1715166268; x=1715252668; bh=RdG7crNCWQ EEeLNOiewXH2LsJuj5QXqV+suySLxzCtY=; b=MseoFQDMw4ZhEsWTQ72vd3FoLl uvmNIgaY5Lbr3RJLXdLs7RT7kYkS6wFvdcaYzBXyYXKFP2T4wmHmal1nUNpcScE/ GUx4Jg9Ev7kD3HJk+/ziWu3JxLG0uMM86kH8QLIQYeh4ZcMHOMaIbwhaMoyTdL+D hwQ0hflHvdeufSJDUjfZCIvK9CDcnCPzsb3dqXidLjgR2zpNBP9Tt9EDWR8q/hw6 dr46/ZRzQdFayf5/hONHcq8ukSPCeCtP9sTDQM0vbcEHAUnDXK3ZoJTvI1GFqkgR V4Bdt0kMk9QC68PY/cAwGCFb6w3toV0ZGF+ddqlfO52f2kAy3+aeQ9KCAcgQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=1715166268; x=1715252668; bh=RdG7crNCWQEEeLNOiewXH2LsJuj5 QXqV+suySLxzCtY=; b=IFC7mKDo86uqgT1CXhmLPHqA1bKg4fm7wu9EoIgDZN6E daZpQvBnk1q8TKYfjZO8vOI4z5U0chNwWF3IhKSjzzsEPiEUnG6F1geSAGmz1wnu 2hU9nqqxgxl0lB7s36Zo2lUTJLLtdXFzvmrZYSYVbsGohJKKJkKrdl6NjkkFzDYg +RwIdXSDNOxwRa+EykVVG+w546LekoqSGWxgFl1lZu1AU7fblMHe8YMy04Cx4S2J kJEwLIjq3GzBNybhJJxl328XJqb/OrxZBUeKgYVXcv3J2+3l8XmaU0l5akW3Xdar 9F0uXbfeKcrpYTmWy35oXjx705xVvb+Ekyst/mA9gw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeftddgfeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepfeelleettdetvdeggeefhfefheeitdejhf ejveffudeludettdefgeeiieetgeehnecuffhomhgrihhnpehosghjpghofhhfshgvthhs rdhishenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 8 May 2024 07:04:27 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id c86a2cc6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 8 May 2024 11:04:17 +0000 (UTC) Date: Wed, 8 May 2024 13:04:25 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 11/13] reftable/reader: 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_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..35b9fb66e4 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 refs. */ +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 Wed May 8 11:04:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13658545 Received: from fout8-smtp.messagingengine.com (fout8-smtp.messagingengine.com [103.168.172.151]) (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 3F28742ABC for ; Wed, 8 May 2024 11:04:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166276; cv=none; b=A/q4zCxovIvaMx8lEYuSd+Wb7YuL+ZXL/0RTN8YFR8OLR3Rifawhgqkr3wlWDvttwqMer6KTkPPif6y/mfdsSgRG3M31SE/gmAPgFCrVTDdaZ23h56t2D5VV9rL5PfV1Oxqc9SqCZLJlmPNtkj9NE/2agEr2wGH0GaV2kV0zuO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166276; c=relaxed/simple; bh=kbslnTR2rnsx3ROqhP2Nuh3E2T9M6TnbC0vvaYq/P0Q=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=szenRq7K6IH6gjlybKZh5tSgQrIphD7fUzCz4cSY3O8zw6mrHmghHckbgqkYbhCgWZiMCzXABR1XczOgzAldTyPjth7Zzch3EpnWWZyixkTDe9jGzKCvMa5GPkKz/gjoigNHz1LRMuc8D5b+1RMt4wDH6YKeNnyYDHOi6Z4AS6s= 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=bl9I4sb6; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=DgGiBlq9; arc=none smtp.client-ip=103.168.172.151 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="bl9I4sb6"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="DgGiBlq9" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 505D61380FF3 for ; Wed, 8 May 2024 07:04:33 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 08 May 2024 07:04:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=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=1715166273; x=1715252673; bh=4o1C+ZlHjR f+cbcuKg80Sf9bqrWmOM2UQHWELDODf7A=; b=bl9I4sb6DZylqGdNEuM/2LEbka cLeC+XHbhm822kSIJZePfCQFLylc8MLrdpuG9ZpK+LloEQbmpv1cVFZMBfcsLEJO fjZ0Rfp0NXs8WAI4nPDoQo0QzclE8hlTzV2R83QrC49PC/dM6wsm1OOYcgGKxtZU GyUZ4FDTM8UKxBaS8jQEsWdsyerh2CSzgVvYVqVlYL1fQ9EZR3yT752IXNIRvdZ4 sYMLhrCa6ryJG4tLV1kyRPa6iRwB/I0jyqTtnM1l7cil04Y5n/43GLkSan0CnozW rT4wtp2+yiew2O04M73lvAZJYChcM0hRKKejC/cCRVYohv7XFJK1+NDLll8Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=1715166273; x=1715252673; bh=4o1C+ZlHjRf+cbcuKg80Sf9bqrWm OM2UQHWELDODf7A=; b=DgGiBlq9EJg3iYmjXszhba4yvECrWG5+HDeywtMv0FaX 3VvkK0TULONPtuleu1S0zmTQ6fT8mQz+bdbGVv5hscn0z92+izlyzngjP8naTz/2 quHQ6+LFY8EWOQq8e6cEiX1kB1uh7j+F732crdMlQ/C1STmdkb72wDLFkJBsM5/m hlK3XoHM1QCIR8xITOMY3bH2v7UYsUKkYs/JPNia8ukmlS3UEEzaLj3JxM2P1Evk F0tO0ZkLzKAx+cRkfeku21UO+MGrBtph1Q/WC9Q+QYKsxOd/sfi37KUZs/faa/PH c+lArN6v3oB+uVu/4URRAZ2YGONbKhH9ad8NxoIMbA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeftddgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgepvdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 8 May 2024 07:04:32 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id b8edb45c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 8 May 2024 11:04:23 +0000 (UTC) Date: Wed, 8 May 2024 13:04:30 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 12/13] reftable/stack: provide convenience functions to create iterators Message-ID: <68cc35919b9e3c232c4ab725b6249c2e543ad1ae.1715166175.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 Wed May 8 11:04:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13658546 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 296AB81AC6 for ; Wed, 8 May 2024 11:04:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166280; cv=none; b=IXV6KaSdLGxzFUZ3w7wWKadAZLUxWMAd+T9qLoDP0ufPRsjYPKIX/OvAl6uEBpIAI0F5mIdIL3wZtX4fiv6VIS1+FqXSAZ3dBtPvv0B+pu5zEUAkc71xZ1uwlMlrP+RfRFLCJ2RObNjoWprsQ8aOh2zPbC1eZz6dI3MfVfI7Jg8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715166280; c=relaxed/simple; bh=eBoySqkf27Q0KWpaAlTybHhiojZ8sWDJLk4dR73cTQo=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DyPxeuKEeLkTZ1nQ0hB7+WAqwXj7bmxAYzhbQ924KkKL7wgtnNYnF+2mAdcaB+20qcr/iNADp4ZlwP2d+ywMIZnhtv45rz/TIMboa5IjT/gGcBu558GE7hQaGoxyz0wKRAz8/8BdJ2VppNGr3B6wUdz6iBy2wwn7THi6DYLqogk= 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=fn6cda0u; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=UnLDqm1p; arc=none smtp.client-ip=103.168.172.155 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="fn6cda0u"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="UnLDqm1p" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 4E3551140244 for ; Wed, 8 May 2024 07:04:38 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Wed, 08 May 2024 07:04:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=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=1715166278; x=1715252678; bh=8KRbM0X1TB akb6vLHYqsNjMIfYVGHEpO08cuEXrclYw=; b=fn6cda0u036WO+iKYEK6UiQVSE DG0/hemyyxuKd+6TO9bnmRY8mP/QVFD4/LwAdz/O7hyD/NRF4++0Lj6Btn7jFYun rlhuuH46bwb7h5lcvGyAxhB9PZm/lIbm4wPXalt23aUhqstE1j2RmtIme7erwNCK QUDIDRoKFDQddhFhmoEx6yhHjh+/GMD9XsM+2OaWPxd3vLxT70s0mfBrnmxIVO8V wHPpGc2VjNlwPeIAHwz8/19MudCaOjYTGMapeBQ5COkj55YwzpO/zqCOdD9l3pjo RZ/z3hTp7U2+8Qrln9LoT0ES3ODZILY9YGDsiTJc94GdOiHn6uIfn+vfEsXQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=1715166278; x=1715252678; bh=8KRbM0X1TBakb6vLHYqsNjMIfYVG HEpO08cuEXrclYw=; b=UnLDqm1p27+T7/Hw+5Ky8VlgRJyCiDnv6TRmDMh/ToJt uR+yhomFI6e19PnG1/OzFiLAA1yzC2PhwMk41E4OpfFDUlPSRGhBvgMO4nFPeFZk ddilnVQN4nv38vYWhgSL6ZgXF96eaZjLkcvY9TtTdOsuOGx6/pSELxGXbXpPqQ4p EBf3DsrdFCtK2jWQMbsgGnecLC1i+flR+Bv2G8zpSaD2x/FNANbfMvCJa/ZIum7y 0V0/E7+ILkkOYxJOhliJGgq/fSM91XbNNqAiy/ZKI4PN1DHRFFr3+3Z7fsMpDZ3A l0yLPC4tZk/x1vlsXIwrKZkY+gvIlxVt4I00detsXg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeftddgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 8 May 2024 07:04:37 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 50e1c715 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 8 May 2024 11:04:27 +0000 (UTC) Date: Wed, 8 May 2024 13:04:35 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 13/13] reftable/merged: 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_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;