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;