From patchwork Mon May 13 08:47:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13663215 Received: from wfhigh5-smtp.messagingengine.com (wfhigh5-smtp.messagingengine.com [64.147.123.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF4EB147C90 for ; Mon, 13 May 2024 08:47:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590057; cv=none; b=DDnOoNhGxTTl13pdswxCQEr8XwTZsOt0EVwg4lbkC3MurIykiHEYc+O++nIS030rJB0xoQbm98TMn6dkBDXhFfuBfgVKjp2RuGuXad5CDzc89yrMVQVndI8VZW9swSQi7Ih6GwA++Et5tdzsV2Majnrbh3ooVLiPgLhdGZkJikQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590057; c=relaxed/simple; bh=W6wWELl+G0JcNH1+JM3SyhieiNYYlJOLHUSQ6akIVqQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=b2vsHJyicCoV62bosieQmthECFkIhTyFV3bsfMk6oaxHHxLKgAuYDOVClNp9Uy2YBXeSclpGNRAfndYswu+NswIow4EzRaCygNsD57cgRFlPIjYvWzVGFQ32XGQMDU/d/llXPYaH7iRmB5C1w7wTu8w52kIiTF3aooG0u1ok8Cw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=Q4NYDCjc; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=CKnj8LJ6; arc=none smtp.client-ip=64.147.123.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="Q4NYDCjc"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="CKnj8LJ6" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.west.internal (Postfix) with ESMTP id 3D3651800120; Mon, 13 May 2024 04:47:35 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 13 May 2024 04:47:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715590054; x=1715676454; bh=4PCKekwZIs og9BptFHJ2scRgWmaSUOu756PFhah0cQQ=; b=Q4NYDCjc+xz6xjj8UfhokU7xtK 1s1vgKwTrDunrErMd+xCHOnfzPGCWTA0RLeB0m2qbnESoWxFCQmdiRnT4T6fMLNy OfxaQWYsTPCkfM3LUsiNn67d4YFHCGYOOiCbf/TMeQVWX74jEfZa795oK3QXzmdo K4QqVb/3ZYTf8LeY/Ew25vpOslnweKMT6noMF/h/06/nyuf52a7YU8X4nd6hrK62 h0OO4NoS1hJyvTzVU+UY10hyGqbpVB3ax1xG6bPXL8Gm6tsEzcSFe5y99Oxs5k7B E+R6Qep3IBshwYZCbX7GoN9oPZ3+PTJ7ZxHxUpM3WdGY9ZLshyhz9O76A8EA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715590054; x=1715676454; bh=4PCKekwZIsog9BptFHJ2scRgWmaS UOu756PFhah0cQQ=; b=CKnj8LJ6R/eVeIvfkYCRmQWdDJPHUu5Lv8BfCGUuZVL9 Bb2JRjKEOD4pfSOF/wd11NJrqBi0yHvW3zmXO5Bj1ez/pqXzegG5L7pRCblLDZLJ YyQi2j4351yUGBBMGAJObaxDTF0+swXp+lpJOxRd1AjvkHV3OI4KE2QyAbi/XpTV 8ni9dRJqo4e+Ej0h4+6aaov9GqMREf20B/rYJinz5BqPr2zJU2qIRvRn2uKNRim3 6dMaY1CuYhjikKEBUhAVfXikLKjCT+SXFwo75tk4bVKfyPBd1Y86x5B8ncRlh0Tz cD1fDWpqYbmstz3OdQZLUUlHIHwcEem3oyj8d5RXtQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeggedgtdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 May 2024 04:47:34 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 1292fd8a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 13 May 2024 08:47:15 +0000 (UTC) Date: Mon, 13 May 2024 10:47:31 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Justin Tobler Subject: [PATCH v2 07/13] reftable/merged: split up initialization and seeking of records Message-ID: <12c10fd366c30a9e615d0928c2874a6099e04e21.1715589670.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: To initialize a `struct merged_iter`, we need to seek all subiterators to the wanted record and then add their results to the priority queue used to sort the records. This logic is split up across two functions, `merged_table_seek_record()` and `merged_iter_init()`. The scope of these functions is somewhat weird though, where `merged_iter_init()` is only responsible for adding the records of the subiterators to the priority queue. Clarify the scope of those functions such that `merged_iter_init()` is only responsible for initializing the iterator's structure. Performing the subiterator seeks are now part of `merged_table_seek_record()`. This step is required to move seeking of records into the generic `struct reftable_iterator` infrastructure. Signed-off-by: Patrick Steinhardt --- reftable/merged.c | 59 ++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/reftable/merged.c b/reftable/merged.c index f85a24c678..4e1b78e93f 100644 --- a/reftable/merged.c +++ b/reftable/merged.c @@ -25,34 +25,18 @@ struct merged_subiter { struct merged_iter { struct merged_subiter *subiters; struct merged_iter_pqueue pq; - uint32_t hash_id; size_t stack_len; - uint8_t typ; int suppress_deletions; ssize_t advance_index; }; -static int merged_iter_init(struct merged_iter *mi) +static void merged_iter_init(struct merged_iter *mi, + struct reftable_merged_table *mt) { - for (size_t i = 0; i < mi->stack_len; i++) { - struct pq_entry e = { - .index = i, - .rec = &mi->subiters[i].rec, - }; - int err; - - reftable_record_init(&mi->subiters[i].rec, mi->typ); - err = iterator_next(&mi->subiters[i].iter, - &mi->subiters[i].rec); - if (err < 0) - return err; - if (err > 0) - continue; - - merged_iter_pqueue_add(&mi->pq, &e); - } - - return 0; + memset(mi, 0, sizeof(*mi)); + mi->advance_index = -1; + mi->suppress_deletions = mt->suppress_deletions; + REFTABLE_CALLOC_ARRAY(mi->subiters, mt->stack_len); } static void merged_iter_close(void *p) @@ -246,32 +230,33 @@ static int merged_table_seek_record(struct reftable_merged_table *mt, struct reftable_iterator *it, struct reftable_record *rec) { - struct merged_iter merged = { - .typ = reftable_record_type(rec), - .hash_id = mt->hash_id, - .suppress_deletions = mt->suppress_deletions, - .advance_index = -1, - }; - struct merged_iter *p; + struct merged_iter merged, *p; int err; - REFTABLE_CALLOC_ARRAY(merged.subiters, mt->stack_len); + merged_iter_init(&merged, mt); + for (size_t i = 0; i < mt->stack_len; i++) { + reftable_record_init(&merged.subiters[merged.stack_len].rec, + reftable_record_type(rec)); + err = reftable_table_seek_record(&mt->stack[i], &merged.subiters[merged.stack_len].iter, rec); if (err < 0) goto out; - if (!err) - merged.stack_len++; - } + if (err > 0) + continue; - err = merged_iter_init(&merged); - if (err < 0) - goto out; + err = merged_iter_advance_subiter(&merged, merged.stack_len); + if (err < 0) + goto out; + + merged.stack_len++; + } - p = reftable_malloc(sizeof(struct merged_iter)); + p = reftable_malloc(sizeof(*p)); *p = merged; iterator_from_merged_iter(it, p); + err = 0; out: if (err < 0)