From patchwork Wed Oct 18 18:32:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13427728 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 A43DD42C09 for ; Wed, 18 Oct 2023 18:32:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="vOFoyREu" Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BB7611F for ; Wed, 18 Oct 2023 11:32:32 -0700 (PDT) Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3b2e44c7941so949328b6e.2 for ; Wed, 18 Oct 2023 11:32:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1697653951; x=1698258751; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=qHGvlxqX2by4ndqlsFmQygviptCt2EfeSZBDIB5dfdU=; b=vOFoyREu+jM4oWOxpa9SinOJxtgWHXpqCXSlC5KChpKb8NLLUK7XdAzPoVHAvxeziZ Qg122lSNjwnGBVmXr14FdYSWHBW7EcNEwSolOzuEfsj9exmLCCsQ1TtjMrkWKFAmJUrT zGHz/weViWXqzGc4I2eVoGie/liovbrLDSYdbb1MPC1ZEn8AkLEIIYpp5fY9r+u99fQZ LFmVJtjM6fBAdIKoM9V9Ib4m5/mi1ckKIyO0uwRd9HWVkxBT9uLmzFZ2wwlGzHx4id/G b+Rd+0i0Dad0a87FpY7gxPkfCQy+PhCvOrrD1dzJ/+lTAdJR9GhisQQPv5uuKmJPBrEx 5MAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697653951; x=1698258751; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=qHGvlxqX2by4ndqlsFmQygviptCt2EfeSZBDIB5dfdU=; b=Jc/E6F15ZBe3WQiBRs8jnr6+SmF/YQE61/FcOuW9RxRZgJ/9rSVngDzr2XHnGZqYQF yUHFhqm9cGSAB56ngmWOOlPOoly2QAnLJ6f2OSN0OkNQSuzNoXX/R+2RzFWytfNh4pP6 FrLVX8QNxIrevpsehpzdBu0H+LVlsX4ndz5+OEZxcTB0d8ofPu3ke0FB0wFwnTD13qeK naE0zHCa06oj5+kq6BJTvbz+XwpoyS2wpBqXXxLH1+SunZ2f4dkYC3y/v71RAjwhdfH5 o2NZIrZlST9iycOupqY0nMnL9hKIz47hwH/XdoZTUEhMesHPnJ7Ba6EtVhX7j4cexKn5 +5FQ== X-Gm-Message-State: AOJu0YzIWZ801kUO1STPb74urbOvJ4fFoyUb9JahkA0h/hJdeCkhonFu p3EMzeRWoAxb/6e+sg/2RYz18uMy2BxeM8KGJp7L/g== X-Google-Smtp-Source: AGHT+IGKpTRfLFIZ/pzAhThwr5/ToqPtf4Zo8K1820lofn6QvJ6FYlau+9aueOMX3dC0DTWfWyqP0w== X-Received: by 2002:a05:6808:df2:b0:3b2:e5b7:7869 with SMTP id g50-20020a0568080df200b003b2e5b77869mr5544oic.17.1697653951346; Wed, 18 Oct 2023 11:32:31 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id z14-20020a0cf24e000000b0066d1e71e515sm141674qvl.113.2023.10.18.11.32.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 11:32:30 -0700 (PDT) Date: Wed, 18 Oct 2023 14:32:29 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , "Eric W. Biederman" , Jeff King , Junio C Hamano , Patrick Steinhardt Subject: [PATCH v4 01/17] t/t4216-log-bloom.sh: harden `test_bloom_filters_not_used()` 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: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net The existing implementation of test_bloom_filters_not_used() asserts that the Bloom filter sub-system has not been initialized at all, by checking for the absence of any data from it from trace2. In the following commit, it will become possible to load Bloom filters without using them (e.g., because `commitGraph.changedPathVersion` is incompatible with the hash version with which the commit-graph's Bloom filters were written). When this is the case, it's possible to initialize the Bloom filter sub-system, while still not using any Bloom filters. When this is the case, check that the data dump from the Bloom sub-system is all zeros, indicating that no filters were used. Signed-off-by: Taylor Blau --- t/t4216-log-bloom.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/t/t4216-log-bloom.sh b/t/t4216-log-bloom.sh index fa9d32facf..487fc3d6b9 100755 --- a/t/t4216-log-bloom.sh +++ b/t/t4216-log-bloom.sh @@ -81,7 +81,19 @@ test_bloom_filters_used () { test_bloom_filters_not_used () { log_args=$1 setup "$log_args" && - ! grep -q "statistics:{\"filter_not_present\":" "$TRASH_DIRECTORY/trace.perf" && + + if grep -q "statistics:{\"filter_not_present\":" "$TRASH_DIRECTORY/trace.perf" + then + # if the Bloom filter system is initialized, ensure that no + # filters were used + data="statistics:{" + data="$data\"filter_not_present\":0," + data="$data\"maybe\":0," + data="$data\"definitely_not\":0," + data="$data\"false_positive\":0}" + + grep -q "$data" "$TRASH_DIRECTORY/trace.perf" + fi && test_cmp log_wo_bloom log_w_bloom } From patchwork Wed Oct 18 18:32:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13427729 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 3AC4545F46 for ; Wed, 18 Oct 2023 18:32:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="2+4xM/zq" Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1CA611F for ; Wed, 18 Oct 2023 11:32:35 -0700 (PDT) Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-3b2b1af09c5so3008514b6e.0 for ; Wed, 18 Oct 2023 11:32:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1697653955; x=1698258755; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=8pl6l6TKRmdNdLybEKpOArG9XEo7r0EaJDuqt7GaMfU=; b=2+4xM/zqjkUFLLVCBrQbf7eg6Jzxr6jSbgpg4Fn/t7H7fjSB9PorsNRnYX7tYo+Q35 K4qKNBtrC6QCtmjt2tIl/3MjaHwvkb4dicd3VXreVE0o/lv64T6kmc+uvOHd2EFyehWl Glwfeht/61vlrctNJdm4a8uuO9YJqiwP/mfEyyK2GqmFPVXBV4r2/Xla9AflqRsfNkhr 5n8CnWU1o4OeY4jNoH8NJb3MxqkR06PFzNbxFGedJAouzYtMkRXy8bERf77uJ9GdapSM oaQ3JID4mvIQq6ddU2Yu1ElWyp9nmulBnGlj4ui5uGpZG1cLIqyoVRvdjUNLitDpCgSH D9ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697653955; x=1698258755; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8pl6l6TKRmdNdLybEKpOArG9XEo7r0EaJDuqt7GaMfU=; b=dpCx28QRwl3OoWCEnntIsMl2ia75x1E9woJ1e6Ayw4BAhhixtaEG0DSONSZ0nLAzO9 Y+lic0oXQqDcgxOtYV8kmR11Mckw1ZWQRlnhjTIhEQF5jBFe8gEETmE2R7Loi6KlGX6P lXfHpprmn6XD7BjUk+Dp4gJ+UpjqOITOuRMI51YrHajn+fbmptGu6/elykDUU2ac+dUf 8bgKaW57g1dTE1xSzRPR6mHRmvs3ZheIea8kkf2Zvgz+2dx4RaIoV+liuMSD8bbHN+bH oMLE+afRrwm0o5SuMJoEbhtmCNKzXJMF2FpOP/OVxQyieaS00K1TKdq1NpHuBmnLTUNv gKfA== X-Gm-Message-State: AOJu0YyaROl2LHI+226BCzLCpkX9pJMC1cUO0iSyHCKQRhiCW9AZKYCv km1IFpjGasN0+0yA1XFzixf2H0V29ecsBfXuesF9UA== X-Google-Smtp-Source: AGHT+IG65nNmpeN2NnABfOMxbEUr7SIMyxQVOo09c3cnDhlIJXdpmrzFQjLgiDCPJkthwsEAKxMRCQ== X-Received: by 2002:a05:6808:685:b0:3a9:e8e2:57a7 with SMTP id k5-20020a056808068500b003a9e8e257a7mr5689543oig.53.1697653954909; Wed, 18 Oct 2023 11:32:34 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id u1-20020a0562140b0100b0065896b9fb15sm151390qvj.29.2023.10.18.11.32.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 11:32:34 -0700 (PDT) Date: Wed, 18 Oct 2023 14:32:33 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , "Eric W. Biederman" , Jeff King , Junio C Hamano , Patrick Steinhardt Subject: [PATCH v4 02/17] revision.c: consult Bloom filters for root commits Message-ID: <87b09e6266a01e7fa4480d37f22e1ac3f4be6bc3.1697653929.git.me@ttaylorr.com> 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: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net The commit-graph stores changed-path Bloom filters which represent the set of paths included in a tree-level diff between a commit's root tree and that of its parent. When a commit has no parents, the tree-diff is computed against that commit's root tree and the empty tree. In other words, every path in that commit's tree is stored in the Bloom filter (since they all appear in the diff). Consult these filters during pathspec-limited traversals in the function `rev_same_tree_as_empty()`. Doing so yields a performance improvement where we can avoid enumerating the full set of paths in a parentless commit's root tree when we know that the path(s) of interest were not listed in that commit's changed-path Bloom filter. Suggested-by: SZEDER Gábor Original-patch-by: Jonathan Tan Signed-off-by: Taylor Blau --- revision.c | 26 ++++++++++++++++++++++---- t/t4216-log-bloom.sh | 8 ++++++-- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/revision.c b/revision.c index 219dc76716..6e9da518d9 100644 --- a/revision.c +++ b/revision.c @@ -834,17 +834,28 @@ static int rev_compare_tree(struct rev_info *revs, return tree_difference; } -static int rev_same_tree_as_empty(struct rev_info *revs, struct commit *commit) +static int rev_same_tree_as_empty(struct rev_info *revs, struct commit *commit, + int nth_parent) { struct tree *t1 = repo_get_commit_tree(the_repository, commit); + int bloom_ret = 1; if (!t1) return 0; + if (nth_parent == 1 && revs->bloom_keys_nr) { + bloom_ret = check_maybe_different_in_bloom_filter(revs, commit); + if (!bloom_ret) + return 1; + } + tree_difference = REV_TREE_SAME; revs->pruning.flags.has_changes = 0; diff_tree_oid(NULL, &t1->object.oid, "", &revs->pruning); + if (bloom_ret == 1 && tree_difference == REV_TREE_SAME) + count_bloom_filter_false_positive++; + return tree_difference == REV_TREE_SAME; } @@ -882,7 +893,7 @@ static int compact_treesame(struct rev_info *revs, struct commit *commit, unsign if (nth_parent != 0) die("compact_treesame %u", nth_parent); old_same = !!(commit->object.flags & TREESAME); - if (rev_same_tree_as_empty(revs, commit)) + if (rev_same_tree_as_empty(revs, commit, nth_parent)) commit->object.flags |= TREESAME; else commit->object.flags &= ~TREESAME; @@ -978,7 +989,14 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit) return; if (!commit->parents) { - if (rev_same_tree_as_empty(revs, commit)) + /* + * Pretend as if we are comparing ourselves to the + * (non-existent) first parent of this commit object. Even + * though no such parent exists, its changed-path Bloom filter + * (if one exists) is relative to the empty tree, using Bloom + * filters is allowed here. + */ + if (rev_same_tree_as_empty(revs, commit, 1)) commit->object.flags |= TREESAME; return; } @@ -1059,7 +1077,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit) case REV_TREE_NEW: if (revs->remove_empty_trees && - rev_same_tree_as_empty(revs, p)) { + rev_same_tree_as_empty(revs, p, nth_parent)) { /* We are adding all the specified * paths from this parent, so the * history beyond this parent is not diff --git a/t/t4216-log-bloom.sh b/t/t4216-log-bloom.sh index 487fc3d6b9..322640feeb 100755 --- a/t/t4216-log-bloom.sh +++ b/t/t4216-log-bloom.sh @@ -87,7 +87,11 @@ test_bloom_filters_not_used () { # if the Bloom filter system is initialized, ensure that no # filters were used data="statistics:{" - data="$data\"filter_not_present\":0," + # unusable filters (e.g., those computed with a + # different value of commitGraph.changedPathsVersion) + # are counted in the filter_not_present bucket, so any + # value is OK there. + data="$data\"filter_not_present\":[0-9][0-9]*," data="$data\"maybe\":0," data="$data\"definitely_not\":0," data="$data\"false_positive\":0}" @@ -174,7 +178,7 @@ test_expect_success 'setup - add commit-graph to the chain with Bloom filters' ' test_bloom_filters_used_when_some_filters_are_missing () { log_args=$1 - bloom_trace_prefix="statistics:{\"filter_not_present\":3,\"maybe\":6,\"definitely_not\":9" + bloom_trace_prefix="statistics:{\"filter_not_present\":3,\"maybe\":6,\"definitely_not\":10" setup "$log_args" && grep -q "$bloom_trace_prefix" "$TRASH_DIRECTORY/trace.perf" && test_cmp log_wo_bloom log_w_bloom From patchwork Wed Oct 18 18:32:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13427730 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 1681847360 for ; Wed, 18 Oct 2023 18:32:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="CtYq1NL8" Received: from mail-ua1-x930.google.com (mail-ua1-x930.google.com [IPv6:2607:f8b0:4864:20::930]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69595109 for ; Wed, 18 Oct 2023 11:32:39 -0700 (PDT) Received: by mail-ua1-x930.google.com with SMTP id a1e0cc1a2514c-7b6cd2afaf2so780761241.0 for ; Wed, 18 Oct 2023 11:32:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1697653958; x=1698258758; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=JUcQw7kAaQdhzODxXGXAyeWbNhclDHUqp1EG+fdzWqQ=; b=CtYq1NL8wRS0P5McWsjV/nK5QDmmH3W86YKk+QAvbEgObRp5VN8RorCKwi0/Y5JLPM 5QJBA+yQaMODWoOQgICkubVXOwsB3vA/lWRFYZddQafjUkPbokg4WO0yTk7/lK7j4gxO Zfj2cahQBXPNrb0R/taHyixxhCWlhRX+2bH4b6AOjF992jTeNAPMEURjuRwRByuyzizk oivdKPe5A8SrSgsry7cHx2frIqYHSRh6wCg72gRxdpvvsYi+dmjSR6Qjm5HkfYsD/1mk RgbTr3ZhRdFvjja00UnR3nA3mklf7ma1ao8nVZiMppqm1paYI9FhlITIcdgMO/q0Ym4+ NXng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697653958; x=1698258758; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JUcQw7kAaQdhzODxXGXAyeWbNhclDHUqp1EG+fdzWqQ=; b=E/rKkCm8ZxagnZikVtsSwiLHfiS3EX0Xh6qZ5LqDcL9u51iH+DIyvksSX19VQtxHEm KKbiiQvGdBji+chqQuEP0omoDF7+/60c+0bP+Waai/3C2JzyXVWNYMEd2pWPR5r/u5Id sals7Syksh8HVSHnmrdMMVgL5Y5s6CQsJ44Z7LBL9MkFBVwh8I2MOZf2j+xDs5XiPCi7 7YJ7/cMGeZ41rkqLx3NKscSwGxIX/FVfzLiZ5I+egq7HJ0wdruQKH9aY709M5NFSp2bA 3VpW/fvj5psl4GYEhPOq+hgOMfmI3Ddrc1EFAWiKnzcsm/USHZO5aUIlw9A/rxajMmCo dxSA== X-Gm-Message-State: AOJu0YxPdWPaKjqFbL4Ct+zMfyPXRiVCXZlE1vwijBN5MY59Voldb+nC Nw5vpyI/0fTfxZH3J/RI2Gcxt5NnO2ZWRNyF+qm+ug== X-Google-Smtp-Source: AGHT+IHrXa1BxQzwG5JNU+2LKvNrwS0ZL00lsBiZli93yCtseNoZMNzbbN8JY+0ZAR46zC4GkIXNiQ== X-Received: by 2002:a05:6102:4755:b0:452:603b:3d8b with SMTP id ej21-20020a056102475500b00452603b3d8bmr6889012vsb.33.1697653958328; Wed, 18 Oct 2023 11:32:38 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id h20-20020ac87774000000b004180fb5c6adsm148731qtu.25.2023.10.18.11.32.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 11:32:38 -0700 (PDT) Date: Wed, 18 Oct 2023 14:32:36 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , "Eric W. Biederman" , Jeff King , Junio C Hamano , Patrick Steinhardt Subject: [PATCH v4 03/17] commit-graph: ensure Bloom filters are read with consistent settings Message-ID: <46d8a41005a0431a4f03b5fced7e1bb3705d5ed9.1697653929.git.me@ttaylorr.com> 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: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net The changed-path Bloom filter mechanism is parameterized by a couple of variables, notably the number of bits per hash (typically "m" in Bloom filter literature) and the number of hashes themselves (typically "k"). It is critically important that filters are read with the Bloom filter settings that they were written with. Failing to do so would mean that each query is liable to compute different fingerprints, meaning that the filter itself could return a false negative. This goes against a basic assumption of using Bloom filters (that they may return false positives, but never false negatives) and can lead to incorrect results. We have some existing logic to carry forward existing Bloom filter settings from one layer to the next. In `write_commit_graph()`, we have something like: if (!(flags & COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS)) { struct commit_graph *g = ctx->r->objects->commit_graph; /* We have changed-paths already. Keep them in the next graph */ if (g && g->chunk_bloom_data) { ctx->changed_paths = 1; ctx->bloom_settings = g->bloom_filter_settings; } } , which drags forward Bloom filter settings across adjacent layers. This doesn't quite address all cases, however, since it is possible for intermediate layers to contain no Bloom filters at all. For example, suppose we have two layers in a commit-graph chain, say, {G1, G2}. If G1 contains Bloom filters, but G2 doesn't, a new G3 (whose base graph is G2) may be written with arbitrary Bloom filter settings, because we only check the immediately adjacent layer's settings for compatibility. This behavior has existed since the introduction of changed-path Bloom filters. But in practice, this is not such a big deal, since the only way up until this point to modify the Bloom filter settings at write time is with the undocumented environment variables: - GIT_TEST_BLOOM_SETTINGS_BITS_PER_ENTRY - GIT_TEST_BLOOM_SETTINGS_NUM_HASHES - GIT_TEST_BLOOM_SETTINGS_MAX_CHANGED_PATHS (it is still possible to tweak MAX_CHANGED_PATHS between layers, but this does not affect reads, so is allowed to differ across multiple graph layers). But in future commits, we will introduce another parameter to change the hash algorithm used to compute Bloom fingerprints itself. This will be exposed via a configuration setting, making this foot-gun easier to use. To prevent this potential issue, validate that all layers of a split commit-graph have compatible settings with the newest layer which contains Bloom filters. Reported-by: SZEDER Gábor Original-test-by: SZEDER Gábor Signed-off-by: Taylor Blau --- commit-graph.c | 25 +++++++++++++++++ t/t4216-log-bloom.sh | 64 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/commit-graph.c b/commit-graph.c index fd2f700b2e..0ac79aff5a 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -498,6 +498,30 @@ static int validate_mixed_generation_chain(struct commit_graph *g) return 0; } +static void validate_mixed_bloom_settings(struct commit_graph *g) +{ + struct bloom_filter_settings *settings = NULL; + for (; g; g = g->base_graph) { + if (!g->bloom_filter_settings) + continue; + if (!settings) { + settings = g->bloom_filter_settings; + continue; + } + + if (g->bloom_filter_settings->bits_per_entry != settings->bits_per_entry || + g->bloom_filter_settings->num_hashes != settings->num_hashes) { + g->chunk_bloom_indexes = NULL; + g->chunk_bloom_data = NULL; + FREE_AND_NULL(g->bloom_filter_settings); + + warning(_("disabling Bloom filters for commit-graph " + "layer '%s' due to incompatible settings"), + oid_to_hex(&g->oid)); + } + } +} + static int add_graph_to_chain(struct commit_graph *g, struct commit_graph *chain, struct object_id *oids, @@ -616,6 +640,7 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r, } validate_mixed_generation_chain(graph_chain); + validate_mixed_bloom_settings(graph_chain); free(oids); fclose(fp); diff --git a/t/t4216-log-bloom.sh b/t/t4216-log-bloom.sh index 322640feeb..2ea5e90955 100755 --- a/t/t4216-log-bloom.sh +++ b/t/t4216-log-bloom.sh @@ -420,4 +420,68 @@ test_expect_success 'Bloom generation backfills empty commits' ' ) ' +graph=.git/objects/info/commit-graph +graphdir=.git/objects/info/commit-graphs +chain=$graphdir/commit-graph-chain + +test_expect_success 'setup for mixed Bloom setting tests' ' + repo=mixed-bloom-settings && + + git init $repo && + for i in one two three + do + test_commit -C $repo $i file || return 1 + done +' + +test_expect_success 'ensure incompatible Bloom filters are ignored' ' + # Compute Bloom filters with "unusual" settings. + git -C $repo rev-parse one >in && + GIT_TEST_BLOOM_SETTINGS_NUM_HASHES=3 git -C $repo commit-graph write \ + --stdin-commits --changed-paths --split in && + git -C $repo commit-graph write --stdin-commits --no-changed-paths \ + --split=no-merge in && + git -C $repo commit-graph write --stdin-commits --changed-paths \ + --split=no-merge expect 2>err && + git -C $repo log --oneline --no-decorate -- file >actual 2>err && + test_cmp expect actual && + grep "disabling Bloom filters for commit-graph layer .$layer." err +' + +test_expect_success 'merge graph layers with incompatible Bloom settings' ' + # Ensure that incompatible Bloom filters are ignored when + # merging existing layers. + git -C $repo commit-graph write --reachable --changed-paths 2>err && + grep "disabling Bloom filters for commit-graph layer .$layer." err && + + test_path_is_file $repo/$graph && + test_dir_is_empty $repo/$graphdir && + + git -C $repo -c core.commitGraph=false log --oneline --no-decorate -- \ + file >expect && + trace_out="$(pwd)/trace.perf" && + GIT_TRACE2_PERF="$trace_out" \ + git -C $repo log --oneline --no-decorate -- file >actual 2>err && + + test_cmp expect actual && + grep "statistics:{\"filter_not_present\":0," trace.perf && + test_must_be_empty err +' + test_done From patchwork Wed Oct 18 18:32:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13427731 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 83DB747366 for ; Wed, 18 Oct 2023 18:32:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="PbMZSGTq" Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A89E118 for ; Wed, 18 Oct 2023 11:32:42 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id af79cd13be357-77897c4ac1fso45574685a.3 for ; Wed, 18 Oct 2023 11:32:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1697653961; x=1698258761; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=vZMUe/8alzUbB7b+lpZKgiTlzrBoUML86Vq+SVEl2Wg=; b=PbMZSGTqZLxGkhIJnJeDUojespU242p4PuaTWpMUJshgWHBJXGno3ZbW7CqqZhT5FC jYuTWsjaWUxsFH9y1nMoks32o4k/v3KMLMHPXzwxmzR3ka7WnMtvTqNSbhVlPe/BU3NU cP+QA5U/och5CNiTixM0vvy7zBLjmWPXcTozwa17WJSrx5E+uP3cnvrSBGSuZLNmQp3n zJZsdlKcxsG6qJwBz4EFtC0tJtZgKqabToJ/jj2QnxJWY5NqFvOoPGx6Q4u15TGw7Ey2 D48hw+GouM6SzhDyzK35vx9VYp7yZEULpSnMDMcSeCkToaooCBQT860hi4FhXb11OFxP LUeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697653961; x=1698258761; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=vZMUe/8alzUbB7b+lpZKgiTlzrBoUML86Vq+SVEl2Wg=; b=fOrqbFDMAXvvA/MkTEoCyYDzjFtuUXhv6FwcGUpJZODReR5zhyZyxef208w5UGfi+L OP7QEGtgaxvZjRutV+pmJf8xZNgOJA8zJjVSDUINRzhC9Euoe6hNkQ6xK5PHTrxqj8uy DjYflqO229WbAI2tjoOvO6U375kudKZa12o0jB19phARwfmwEY1h5sxlm5OipK40UO0a OYjR4QUddzVNTKaBQbNeo2//p+hpx7y5IBjMlzG7tkzh3yfVCbb6prRQcHMrwDzm7YV3 e033QO1IgZ2MONLGWXsP9aKIIvEYiULAwVg5YUB4xWNQxPzFYTdrVOu4S6rhT5wxP2ty QvJQ== X-Gm-Message-State: AOJu0YwDsjZac4Gx9P5ZLFNFhwwhCE42totpD4H3TSyR8H2DGF9Hx0G0 YdK4Ll6cnnq43+Cm7FqcWGgl7V7qbEV1yNyt5Hx8QQ== X-Google-Smtp-Source: AGHT+IE7tzosb/m9rNoMkUF/k67+f0UGvg8yW1nG9J2RvSF8jqzijpKXGpYEIFl4/HePEOaaq1MQ+w== X-Received: by 2002:a05:620a:44d0:b0:777:784:3458 with SMTP id y16-20020a05620a44d000b0077707843458mr7821937qkp.64.1697653961338; Wed, 18 Oct 2023 11:32:41 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id o14-20020ae9f50e000000b0076d6a08ac98sm149832qkg.76.2023.10.18.11.32.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 11:32:41 -0700 (PDT) Date: Wed, 18 Oct 2023 14:32:40 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , "Eric W. Biederman" , Jeff King , Junio C Hamano , Patrick Steinhardt Subject: [PATCH v4 04/17] gitformat-commit-graph: describe version 2 of BDAT Message-ID: <4d0190a9926bddc691cfa5b856d02b7bcc3a1d81.1697653929.git.me@ttaylorr.com> 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: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net From: Jonathan Tan The code change to Git to support version 2 will be done in subsequent commits. Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano Signed-off-by: Taylor Blau --- Documentation/gitformat-commit-graph.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Documentation/gitformat-commit-graph.txt b/Documentation/gitformat-commit-graph.txt index 31cad585e2..3e906e8030 100644 --- a/Documentation/gitformat-commit-graph.txt +++ b/Documentation/gitformat-commit-graph.txt @@ -142,13 +142,16 @@ All multi-byte numbers are in network byte order. ==== Bloom Filter Data (ID: {'B', 'D', 'A', 'T'}) [Optional] * It starts with header consisting of three unsigned 32-bit integers: - - Version of the hash algorithm being used. We currently only support - value 1 which corresponds to the 32-bit version of the murmur3 hash + - Version of the hash algorithm being used. We currently support + value 2 which corresponds to the 32-bit version of the murmur3 hash implemented exactly as described in https://en.wikipedia.org/wiki/MurmurHash#Algorithm and the double hashing technique using seed values 0x293ae76f and 0x7e646e2 as described in https://doi.org/10.1007/978-3-540-30494-4_26 "Bloom Filters - in Probabilistic Verification" + in Probabilistic Verification". Version 1 Bloom filters have a bug that appears + when char is signed and the repository has path names that have characters >= + 0x80; Git supports reading and writing them, but this ability will be removed + in a future version of Git. - The number of times a path is hashed and hence the number of bit positions that cumulatively determine whether a file is present in the commit. - The minimum number of bits 'b' per entry in the Bloom filter. If the filter From patchwork Wed Oct 18 18:32:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13427732 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 C1BB64368C for ; Wed, 18 Oct 2023 18:32:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="y852t2M7" Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE8C1125 for ; Wed, 18 Oct 2023 11:32:45 -0700 (PDT) Received: by mail-qk1-x72b.google.com with SMTP id af79cd13be357-777506c6109so355478285a.3 for ; Wed, 18 Oct 2023 11:32:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1697653965; x=1698258765; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Bs46mJLdtTTiZ7uimsM5rjSde3YMEpzT/41x50J7HDY=; b=y852t2M7FpErEm0UVl+FOhOem8DK6sahbEp5fvEfn9vwH8hC0u2vnwBr8iNZ7FCH9V yPWAIBbQ6seHdfLI73h+uK63HDvpHmTPD6hhVdAJNkTeT9KvzvBthAzlJ9CIHni9SZxp gkXsfLJ46FldEgysR0QsRw4d2RcuwPn+g6enlMBoQAazh9A5cSoHoy2TFrySTLpxl7xc tpy4tpy/IEMhLbwU06lxXPpyhcJVp9/VJSf27LmCcWm78b+uRCZlqPHSc55XJZ/K4yMT yT4mVLU2DRmZXRtiAfCIfgLbl5zJ5LRVFg9YNLZmoffMGtXPr+ymIa+UJywNvNpkCfgh zY0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697653965; x=1698258765; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Bs46mJLdtTTiZ7uimsM5rjSde3YMEpzT/41x50J7HDY=; b=b0dM1Ij80fIvwsHBMp73MnMGTe5RS9AePouc4C5pN55flGnK/SnZwxAxp36xPLRL3I krbJ1czT1P3N+3Po536JdjjAtI2In1FTtMcXfR3gKVy7EOd5XvQg5+Nuc2n7Vtb3SZ/x SzhpKZBXdJTQosssYV9Nlq4Vc6Rk9dCFBbHzr3zLMiAHamCL21SLQjIIMIqg+EPYeRdv hmqU6zKF1VuvpFmchtpWmY8B7/qRVXEAavkCdwCfVuJ0q5pA73sc1b5McEtWCQgDn4nH QXvUbpz3Y3+zNTFpC4mh+/RWfSSgy6TuT23qtCYxPNLNuGWXfBKfIeBqHftW4c5mR8I/ 0w4w== X-Gm-Message-State: AOJu0YwrGX21Djvb7JWcEJgIMbMQzv4WNc8vi9+TgCkSWjva0rSeozBC HYPFTHlNrQag/Tg7ZrCR71HnxOj7tTRD8NovVPd3Ew== X-Google-Smtp-Source: AGHT+IFypAugvlScti0ckZPMlZ8oid3+IT1Q7bDd2LzopUByu+OysZrd1Ys/Q/2prefbAfi31VuJYw== X-Received: by 2002:a05:620a:bd6:b0:775:ce76:474a with SMTP id s22-20020a05620a0bd600b00775ce76474amr6692485qki.52.1697653964834; Wed, 18 Oct 2023 11:32:44 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id bk40-20020a05620a1a2800b00765ab6d3e81sm147515qkb.122.2023.10.18.11.32.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 11:32:44 -0700 (PDT) Date: Wed, 18 Oct 2023 14:32:43 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , "Eric W. Biederman" , Jeff King , Junio C Hamano , Patrick Steinhardt Subject: [PATCH v4 05/17] t/helper/test-read-graph.c: extract `dump_graph_info()` Message-ID: <3c2057c11c9229794e9d410e34260b2e92b2907e.1697653929.git.me@ttaylorr.com> 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: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Prepare for the 'read-graph' test helper to perform other tasks besides dumping high-level information about the commit-graph by extracting its main routine into a separate function. Signed-off-by: Taylor Blau Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano Signed-off-by: Taylor Blau --- t/helper/test-read-graph.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c index 8c7a83f578..3375392f6c 100644 --- a/t/helper/test-read-graph.c +++ b/t/helper/test-read-graph.c @@ -5,20 +5,8 @@ #include "bloom.h" #include "setup.h" -int cmd__read_graph(int argc UNUSED, const char **argv UNUSED) +static void dump_graph_info(struct commit_graph *graph) { - struct commit_graph *graph = NULL; - struct object_directory *odb; - - setup_git_directory(); - odb = the_repository->objects->odb; - - prepare_repo_settings(the_repository); - - graph = read_commit_graph_one(the_repository, odb); - if (!graph) - return 1; - printf("header: %08x %d %d %d %d\n", ntohl(*(uint32_t*)graph->data), *(unsigned char*)(graph->data + 4), @@ -57,6 +45,23 @@ int cmd__read_graph(int argc UNUSED, const char **argv UNUSED) if (graph->topo_levels) printf(" topo_levels"); printf("\n"); +} + +int cmd__read_graph(int argc UNUSED, const char **argv UNUSED) +{ + struct commit_graph *graph = NULL; + struct object_directory *odb; + + setup_git_directory(); + odb = the_repository->objects->odb; + + prepare_repo_settings(the_repository); + + graph = read_commit_graph_one(the_repository, odb); + if (!graph) + return 1; + + dump_graph_info(graph); UNLEAK(graph); From patchwork Wed Oct 18 18:32:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13427733 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 44DE0450D2 for ; Wed, 18 Oct 2023 18:32:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="mzK26bQK" Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0525C119 for ; Wed, 18 Oct 2023 11:32:49 -0700 (PDT) Received: by mail-qt1-x835.google.com with SMTP id d75a77b69052e-41cc7379b23so434651cf.3 for ; Wed, 18 Oct 2023 11:32:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1697653968; x=1698258768; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=88cy3xkxr/QRAgozGxl3AsK//RK8uTvt0H3vDlw2PBo=; b=mzK26bQK+lt60o6eFQaKdlkZdtrkfOpbJDn7bLgqcPJgUIb8V5OMKthJc+5bvv71tU 1I6fVa+JNykad20775+EGu5+AFOptyhdVD/d+Z5AxFmtJl7YQwYbAcdVzaVXb++nN2ht GCOLSWVUTkQEWkIRohj7P9vMDyLiCMgUqgXyaeTyiWpjXgzPwVHWP0KWhGxrU3v6K8ly nAObqL/nvh/eS7vaFF/OA2pPtTBTbo8mug0S57cib8m5e6Lw0vahik5posBEwMBH1/6c cOdfiuX8GfxUOyqYkM19pkFqGfm0TMIDE/HfSajPSZlP7Pagw+lXz/7AjKp8XSiYMicZ Ycuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697653968; x=1698258768; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=88cy3xkxr/QRAgozGxl3AsK//RK8uTvt0H3vDlw2PBo=; b=LYmohNkAktbU3x6AzI/pAbFxYxMkhFUmEHcFSM1E/03A+aJ9hCU/6X/sqEC/g8NpkF zIa1KjgN0XsRDL4f6dos9frrZofHNOHoVDYTuItbwFMKT7MhscMhRDz9AN1cnJgnRbm/ RuO6HC8U6miI2kBQuosH1VNkLbOBS0cevpFhmi72FN85uxoRYUHEOkgG1Ma/jWdNF0bZ myVjL12JBRbxyV5Md364g5cUxBVjVUussXOPj9yuIqJ/umkRBb6TYa5N7P8eYtWJUqA5 7ZQhoyCgFNldqA2HgUPxhGhSXpVognqw5WSRP1BYFtLKHGaWp03kOu2X1YmOHYduQhKt LIBA== X-Gm-Message-State: AOJu0YyetOAodzLwf8R/nG9GKP1Du385YxmInLE6UYlmB+kcdEfPd8jb A8OTSBcpjYv3GlnsPZIJfb7CCFQeidbz18LmnVT2Kg== X-Google-Smtp-Source: AGHT+IF1NY1frRWuLNbt0+WwOEdAEQbVmNpFVwo/pgwfz+x81mmMGCmPb6Xisq3eQT1tJ5NTidZqtQ== X-Received: by 2002:a05:622a:282:b0:418:1194:42f3 with SMTP id z2-20020a05622a028200b00418119442f3mr106874qtw.56.1697653967948; Wed, 18 Oct 2023 11:32:47 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id i12-20020a05622a08cc00b00403cce833eesm149541qte.27.2023.10.18.11.32.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 11:32:47 -0700 (PDT) Date: Wed, 18 Oct 2023 14:32:46 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , "Eric W. Biederman" , Jeff King , Junio C Hamano , Patrick Steinhardt Subject: [PATCH v4 06/17] bloom.h: make `load_bloom_filter_from_graph()` public 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: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Prepare for a future commit to use the load_bloom_filter_from_graph() function directly to load specific Bloom filters out of the commit-graph for manual inspection (to be used during tests). Signed-off-by: Taylor Blau Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano Signed-off-by: Taylor Blau --- bloom.c | 6 +++--- bloom.h | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bloom.c b/bloom.c index aef6b5fea2..3e78cfe79d 100644 --- a/bloom.c +++ b/bloom.c @@ -29,9 +29,9 @@ static inline unsigned char get_bitmask(uint32_t pos) return ((unsigned char)1) << (pos & (BITS_PER_WORD - 1)); } -static int load_bloom_filter_from_graph(struct commit_graph *g, - struct bloom_filter *filter, - uint32_t graph_pos) +int load_bloom_filter_from_graph(struct commit_graph *g, + struct bloom_filter *filter, + uint32_t graph_pos) { uint32_t lex_pos, start_index, end_index; diff --git a/bloom.h b/bloom.h index adde6dfe21..1e4f612d2c 100644 --- a/bloom.h +++ b/bloom.h @@ -3,6 +3,7 @@ struct commit; struct repository; +struct commit_graph; struct bloom_filter_settings { /* @@ -68,6 +69,10 @@ struct bloom_key { uint32_t *hashes; }; +int load_bloom_filter_from_graph(struct commit_graph *g, + struct bloom_filter *filter, + uint32_t graph_pos); + /* * Calculate the murmur3 32-bit hash value for the given data * using the given seed. From patchwork Wed Oct 18 18:32:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13427734 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 6046447348 for ; Wed, 18 Oct 2023 18:32:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="139zBtaU" Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E77411B for ; Wed, 18 Oct 2023 11:32:52 -0700 (PDT) Received: by mail-qk1-x733.google.com with SMTP id af79cd13be357-7789577b53fso50738085a.3 for ; Wed, 18 Oct 2023 11:32:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1697653971; x=1698258771; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=jIDGriTomqbfCpZhujfid7f6s8be6EPNh9OcTJampgo=; b=139zBtaUP+ZJG124khorwTM12Z759n+5bbT6QXYFF/+wHSjV3Nw55naaP6OoSoajvU N30BQGI4DzoO36Ek/HraTvvcswT6usB352HSC8KWm94gQjRTuorpzsdOrJ5N50N/VTkS GI5Ku2h9+bPx82pS1pX9RL4lsAXEGyhqTgEW9FXlJ7+wV/LndNdLGQxcqNyGgjXJsVdr Imn+8M4bUg+V0IIiSkBIcqjuyrUl4pUKyoIG/BPAnC50VuRhSQxf5+47BMkduaJRBQCN bYMWAe0/jQ7WjDy2AqMkBIiUGnlH1R/hRcCBPYoRlz7VqVxPvdYwX5hrkHToo70/p8t9 ogLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697653971; x=1698258771; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=jIDGriTomqbfCpZhujfid7f6s8be6EPNh9OcTJampgo=; b=BW00nbOcu+g3djU+4ZjEHSzswMKfD0F2bOfBTnRA9qyRn0GZbJmnKdkAQF4mnuPnDv 4jZGgHy4vhyWSKXDZ5jYcr21nONdYPnPXqpsPxxkeFcLSHtslF7B1W2S5zquaXWSnZ9I cy/EDZELBf2zrsbQ5p3rfn7yn/W5SY8Tj2TCXbrPIax7rQ+2q+VbZ3Qd+grlVJ4IcV9A d9M1DOMp8/bcbRvdTZFwk1HO69EJgJXyXd83sEtSsSndHxhM0k9W7fCNxWIPqMh57Y/7 UoI5Xx+1KESB5q/4l0I/rllbBSMzmEbKT7BjDRp53DnBnuTskDcEsXPPaXrD33vNnBsE hUzw== X-Gm-Message-State: AOJu0YzvkjzaQdzEXM20TDWWgrw3/B4GiBzFFtUKr7rTiDS82C5TScfs yR81iVmtRoFdQkQsagUirEYilrIKHhDyzSkENLNP3g== X-Google-Smtp-Source: AGHT+IFRi1sLrJORvjS1a/mR6SZ1nhaAZu/JYMOZyj+LTZu+LPS+hEVNCWr6T1UBmFTQx9LYeK4xKQ== X-Received: by 2002:a05:6214:21ac:b0:66d:3690:7c2f with SMTP id t12-20020a05621421ac00b0066d36907c2fmr78067qvc.51.1697653971081; Wed, 18 Oct 2023 11:32:51 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id m17-20020ad44d51000000b00658266be23fsm153049qvm.41.2023.10.18.11.32.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 11:32:50 -0700 (PDT) Date: Wed, 18 Oct 2023 14:32:49 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , "Eric W. Biederman" , Jeff King , Junio C Hamano , Patrick Steinhardt Subject: [PATCH v4 07/17] t/helper/test-read-graph: implement `bloom-filters` mode 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: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Implement a mode of the "read-graph" test helper to dump out the hexadecimal contents of the Bloom filter(s) contained in a commit-graph. Signed-off-by: Taylor Blau Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano Signed-off-by: Taylor Blau --- t/helper/test-read-graph.c | 44 +++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c index 3375392f6c..da9ac8584d 100644 --- a/t/helper/test-read-graph.c +++ b/t/helper/test-read-graph.c @@ -47,10 +47,32 @@ static void dump_graph_info(struct commit_graph *graph) printf("\n"); } -int cmd__read_graph(int argc UNUSED, const char **argv UNUSED) +static void dump_graph_bloom_filters(struct commit_graph *graph) +{ + uint32_t i; + + for (i = 0; i < graph->num_commits + graph->num_commits_in_base; i++) { + struct bloom_filter filter = { 0 }; + size_t j; + + if (load_bloom_filter_from_graph(graph, &filter, i) < 0) { + fprintf(stderr, "missing Bloom filter for graph " + "position %"PRIu32"\n", i); + continue; + } + + for (j = 0; j < filter.len; j++) + printf("%02x", filter.data[j]); + if (filter.len) + printf("\n"); + } +} + +int cmd__read_graph(int argc, const char **argv) { struct commit_graph *graph = NULL; struct object_directory *odb; + int ret = 0; setup_git_directory(); odb = the_repository->objects->odb; @@ -58,12 +80,24 @@ int cmd__read_graph(int argc UNUSED, const char **argv UNUSED) prepare_repo_settings(the_repository); graph = read_commit_graph_one(the_repository, odb); - if (!graph) - return 1; + if (!graph) { + ret = 1; + goto done; + } - dump_graph_info(graph); + if (argc <= 1) + dump_graph_info(graph); + else if (!strcmp(argv[1], "bloom-filters")) + dump_graph_bloom_filters(graph); + else { + fprintf(stderr, "unknown sub-command: '%s'\n", argv[1]); + ret = 1; + } +done: UNLEAK(graph); - return 0; + return ret; } + + From patchwork Wed Oct 18 18:32:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13427735 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 907AA42BF3 for ; Wed, 18 Oct 2023 18:32:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="NhuY969x" Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EFFE114 for ; Wed, 18 Oct 2023 11:32:55 -0700 (PDT) Received: by mail-qv1-xf31.google.com with SMTP id 6a1803df08f44-66d122f6294so46170716d6.0 for ; Wed, 18 Oct 2023 11:32:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1697653974; x=1698258774; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=0+AG7bOM8F80vJ4PI/4QI9mBLxDX4rK3zxcNpcIjko8=; b=NhuY969xVE4CPlmtdpBpuVSlxgTj/zNE+dLMl3OMQ574WUqSUlNPHeSSiBdP9vj3AR S5jmWEZkAfBw9g9MvrHB+T2Kg40vMRJ7PL1vrAEa/Qt/zL6OCmnvADwT5kuSkI50V3KX SCGcuFTyJBXm8cval+Nb+SROnjVZjxYMhpi4kQdvopU+X6UsWH+bKHvlETOJDDnplAPB spzc3Kha1HKH9Jnz3xY7eXAbAxNrCvi/uPToX28FBq7eP6iWthZum9BIj5OtT++K5Bm4 3u8PFSRDvStALYkA0f6OHgOteRrVWkiGf5d/YUc9eDbADqP0Hlrk0VHy3ml5+qCM5iWf /7Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697653974; x=1698258774; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=0+AG7bOM8F80vJ4PI/4QI9mBLxDX4rK3zxcNpcIjko8=; b=Z5s7Jtenv3kQzjGFr4Gl0mkE3Df2Q69Z/vpUn3VvbAkeAgy42hL8z5AR59NGVV5YCq 6Gky8y9oMGGORA58Fcx8i71X/jBNnonMfSjPS5ZhASsvuZlIRIseRKqwsnNGWbpFj4rI GH7yANq/oAaGbyZb3DdyjrJ0jDM9OoVS4TZ+tSnLWC9/+nlmhAT6wsxqheuYR0hQhu4q eVqtvEA6N55RlTR5qCG5QgNDwgqfuaq6fpbCjSIH9APyiWMKbCUTWgTVF3dngZTg2ie7 HDOo3V6yzkaa5A5qu+ZjVDyWmhE1LH3BqBOddMM78NEbs+oHvQVB+It91kXujIJuIxN/ Ps1A== X-Gm-Message-State: AOJu0YwUlT+M7cUZu5i8Otz8mhFPcaJ5sxkes3tZtkyijb4y++PONCbU nkNp7+xt5Jrjv3IQ/53955B9Eax1O2AKvodM0L/JFQ== X-Google-Smtp-Source: AGHT+IFynILJbg1N/XAbR8KWL+ZPxaugS7S7ukZqoBNhK3UULos9iF7Yz/H57WKgkSGlS24WLbooiw== X-Received: by 2002:a05:6214:21e8:b0:66d:a4d:84f7 with SMTP id p8-20020a05621421e800b0066d0a4d84f7mr70900qvj.28.1697653974355; Wed, 18 Oct 2023 11:32:54 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id ml10-20020a056214584a00b0065d1380dd17sm150175qvb.61.2023.10.18.11.32.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 11:32:54 -0700 (PDT) Date: Wed, 18 Oct 2023 14:32:52 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , "Eric W. Biederman" , Jeff King , Junio C Hamano , Patrick Steinhardt Subject: [PATCH v4 08/17] t4216: test changed path filters with high bit paths 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: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net From: Jonathan Tan Subsequent commits will teach Git another version of changed path filter that has different behavior with paths that contain at least one character with its high bit set, so test the existing behavior as a baseline. Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano Signed-off-by: Taylor Blau Signed-off-by: Junio C Hamano Signed-off-by: Taylor Blau --- t/t4216-log-bloom.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/t/t4216-log-bloom.sh b/t/t4216-log-bloom.sh index 2ea5e90955..400dce2193 100755 --- a/t/t4216-log-bloom.sh +++ b/t/t4216-log-bloom.sh @@ -484,4 +484,55 @@ test_expect_success 'merge graph layers with incompatible Bloom settings' ' test_must_be_empty err ' +get_first_changed_path_filter () { + test-tool read-graph bloom-filters >filters.dat && + head -n 1 filters.dat +} + +# chosen to be the same under all Unicode normalization forms +CENT=$(printf "\302\242") + +test_expect_success 'set up repo with high bit path, version 1 changed-path' ' + git init highbit1 && + test_commit -C highbit1 c1 "$CENT" && + git -C highbit1 commit-graph write --reachable --changed-paths +' + +test_expect_success 'setup check value of version 1 changed-path' ' + ( + cd highbit1 && + echo "52a9" >expect && + get_first_changed_path_filter >actual + ) +' + +# expect will not match actual if char is unsigned by default. Write the test +# in this way, so that a user running this test script can still see if the two +# files match. (It will appear as an ordinary success if they match, and a skip +# if not.) +if test_cmp highbit1/expect highbit1/actual +then + test_set_prereq SIGNED_CHAR_BY_DEFAULT +fi +test_expect_success SIGNED_CHAR_BY_DEFAULT 'check value of version 1 changed-path' ' + # Only the prereq matters for this test. + true +' + +test_expect_success 'setup make another commit' ' + # "git log" does not use Bloom filters for root commits - see how, in + # revision.c, rev_compare_tree() (the only code path that eventually calls + # get_bloom_filter()) is only called by try_to_simplify_commit() when the commit + # has one parent. Therefore, make another commit so that we perform the tests on + # a non-root commit. + test_commit -C highbit1 anotherc1 "another$CENT" +' + +test_expect_success 'version 1 changed-path used when version 1 requested' ' + ( + cd highbit1 && + test_bloom_filters_used "-- another$CENT" + ) +' + test_done From patchwork Wed Oct 18 18:32:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13427736 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 0BC104449A for ; Wed, 18 Oct 2023 18:33:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="2SA452nW" Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBA94114 for ; Wed, 18 Oct 2023 11:32:58 -0700 (PDT) Received: by mail-qk1-x72a.google.com with SMTP id af79cd13be357-7789577b53fso50746785a.3 for ; Wed, 18 Oct 2023 11:32:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1697653977; x=1698258777; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=sFE64OU/sbzJ0Jfma9wcJimQd0SwUL/8QSgLe3eKaqY=; b=2SA452nWDK7xerJtB1Mf3BPug3l7aTWXJplJye/OuORWSF8vEj/bwOkYTtP5TlPBd+ SAF8mHL8SLu/4aYk+96XiHnPklm3KxVyIMtnQkwonUER8D56edMpnkD0FBatc8XfJu+k LDh5RS0pCzyOm336bcXlQoCUjujAFcE4j38fcFqcZWChztK8OA63621OF3brhYZWc2jJ 6leOPU7waHT3W16OAC/vrgGNy1XRKDgSgObe4AQbkBFqY7l8BvXKJPai2sgGPZhO9743 +hnn/Xd9zjEwOOsfwP1FvduLwnaeacvr1N7zgM6HQfFpxaRghw2DIlJyBlLMfEEitU/T bJoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697653977; x=1698258777; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=sFE64OU/sbzJ0Jfma9wcJimQd0SwUL/8QSgLe3eKaqY=; b=AEb+jWn91vntk6mpzCQLxO+2j4bS8vUaJxTyAuDl+XPNYs5NdAySeJO4U8e7kKevWr 4p0OSB1gOxRYleDlM93qJotE+qmrdRYgNqG/v+4CxB6qeau07zXDhDXqejHFV0yJcv0t mAobE0hW0g6RSbdOynGUuXuFhYPNyFZ3XANdwdl1FSE+ZoVL+zBcP8ADkENBDFowlbOw tX/JBAboOFCyxBI02RN6OiPeHsUC5zOHe3PcmYQ2S9EZTuZP6NSiOMjCqUvJIJBPxsQI sgaj+Dp7ATzMhbt/PgzyiKVlTVFF+D2MgbZYSHqyfSKqxJtQ6LySqOhXn2+9odnvoF7n 3jOA== X-Gm-Message-State: AOJu0YyMX6QkD39Q6n3nW2aN1EttHsW/N7hkv7nrh3jzwiW2tUxY9fW4 5amSZXnKcf8p1KrPD3NpKBUWwN8cGgg+6wBeAfsfNQ== X-Google-Smtp-Source: AGHT+IFNrDaOGA61/RFclRRcj3UeuiXjqB0YVrDDpx4gSzsblcp9RTa+NSOdCb/qt9eh0xrvi0W7mQ== X-Received: by 2002:ae9:ee19:0:b0:775:ced2:3c7 with SMTP id i25-20020ae9ee19000000b00775ced203c7mr5401348qkg.26.1697653977563; Wed, 18 Oct 2023 11:32:57 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id bq43-20020a05620a46ab00b00767177a5bebsm153109qkb.56.2023.10.18.11.32.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 11:32:57 -0700 (PDT) Date: Wed, 18 Oct 2023 14:32:56 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , "Eric W. Biederman" , Jeff King , Junio C Hamano , Patrick Steinhardt Subject: [PATCH v4 09/17] repo-settings: introduce commitgraph.changedPathsVersion Message-ID: <36d4e2202e88aa61a2d7a76df33395186e6b71be.1697653929.git.me@ttaylorr.com> 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: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net From: Jonathan Tan A subsequent commit will introduce another version of the changed-path filter in the commit graph file. In order to control which version to write (and read), a config variable is needed. Therefore, introduce this config variable. For forwards compatibility, teach Git to not read commit graphs when the config variable is set to an unsupported version. Because we teach Git this, commitgraph.readChangedPaths is now redundant, so deprecate it and define its behavior in terms of the config variable we introduce. This commit does not change the behavior of writing (Git writes changed path filters when explicitly instructed regardless of any config variable), but a subsequent commit will restrict Git such that it will only write when commitgraph.changedPathsVersion is a recognized value. Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano Signed-off-by: Taylor Blau --- Documentation/config/commitgraph.txt | 23 ++++++++++++++++++++--- commit-graph.c | 2 +- oss-fuzz/fuzz-commit-graph.c | 2 +- repo-settings.c | 6 +++++- repository.h | 2 +- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Documentation/config/commitgraph.txt b/Documentation/config/commitgraph.txt index 30604e4a4c..2dc9170622 100644 --- a/Documentation/config/commitgraph.txt +++ b/Documentation/config/commitgraph.txt @@ -9,6 +9,23 @@ commitGraph.maxNewFilters:: commit-graph write` (c.f., linkgit:git-commit-graph[1]). commitGraph.readChangedPaths:: - If true, then git will use the changed-path Bloom filters in the - commit-graph file (if it exists, and they are present). Defaults to - true. See linkgit:git-commit-graph[1] for more information. + Deprecated. Equivalent to commitGraph.changedPathsVersion=-1 if true, and + commitGraph.changedPathsVersion=0 if false. (If commitGraph.changedPathVersion + is also set, commitGraph.changedPathsVersion takes precedence.) + +commitGraph.changedPathsVersion:: + Specifies the version of the changed-path Bloom filters that Git will read and + write. May be -1, 0 or 1. ++ +Defaults to -1. ++ +If -1, Git will use the version of the changed-path Bloom filters in the +repository, defaulting to 1 if there are none. ++ +If 0, Git will not read any Bloom filters, and will write version 1 Bloom +filters when instructed to write. ++ +If 1, Git will only read version 1 Bloom filters, and will write version 1 +Bloom filters. ++ +See linkgit:git-commit-graph[1] for more information. diff --git a/commit-graph.c b/commit-graph.c index 0ac79aff5a..bcc9a15cfa 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -411,7 +411,7 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s, graph->read_generation_data = 1; } - if (s->commit_graph_read_changed_paths) { + if (s->commit_graph_changed_paths_version) { pair_chunk(cf, GRAPH_CHUNKID_BLOOMINDEXES, &graph->chunk_bloom_indexes); read_chunk(cf, GRAPH_CHUNKID_BLOOMDATA, diff --git a/oss-fuzz/fuzz-commit-graph.c b/oss-fuzz/fuzz-commit-graph.c index 2992079dd9..325c0b991a 100644 --- a/oss-fuzz/fuzz-commit-graph.c +++ b/oss-fuzz/fuzz-commit-graph.c @@ -19,7 +19,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) * possible. */ the_repository->settings.commit_graph_generation_version = 2; - the_repository->settings.commit_graph_read_changed_paths = 1; + the_repository->settings.commit_graph_changed_paths_version = 1; g = parse_commit_graph(&the_repository->settings, (void *)data, size); repo_clear(the_repository); free_commit_graph(g); diff --git a/repo-settings.c b/repo-settings.c index 525f69c0c7..db8fe817f3 100644 --- a/repo-settings.c +++ b/repo-settings.c @@ -24,6 +24,7 @@ void prepare_repo_settings(struct repository *r) int value; const char *strval; int manyfiles; + int read_changed_paths; if (!r->gitdir) BUG("Cannot add settings for uninitialized repository"); @@ -54,7 +55,10 @@ void prepare_repo_settings(struct repository *r) /* Commit graph config or default, does not cascade (simple) */ repo_cfg_bool(r, "core.commitgraph", &r->settings.core_commit_graph, 1); repo_cfg_int(r, "commitgraph.generationversion", &r->settings.commit_graph_generation_version, 2); - repo_cfg_bool(r, "commitgraph.readchangedpaths", &r->settings.commit_graph_read_changed_paths, 1); + repo_cfg_bool(r, "commitgraph.readchangedpaths", &read_changed_paths, 1); + repo_cfg_int(r, "commitgraph.changedpathsversion", + &r->settings.commit_graph_changed_paths_version, + read_changed_paths ? -1 : 0); repo_cfg_bool(r, "gc.writecommitgraph", &r->settings.gc_write_commit_graph, 1); repo_cfg_bool(r, "fetch.writecommitgraph", &r->settings.fetch_write_commit_graph, 0); diff --git a/repository.h b/repository.h index 5f18486f64..f71154e12c 100644 --- a/repository.h +++ b/repository.h @@ -29,7 +29,7 @@ struct repo_settings { int core_commit_graph; int commit_graph_generation_version; - int commit_graph_read_changed_paths; + int commit_graph_changed_paths_version; int gc_write_commit_graph; int fetch_write_commit_graph; int command_requires_full_index; From patchwork Wed Oct 18 18:32:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13427738 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 59AF347366 for ; Wed, 18 Oct 2023 18:33:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="ZIDwIEyR" Received: from mail-ua1-x92f.google.com (mail-ua1-x92f.google.com [IPv6:2607:f8b0:4864:20::92f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F262118 for ; Wed, 18 Oct 2023 11:33:03 -0700 (PDT) Received: by mail-ua1-x92f.google.com with SMTP id a1e0cc1a2514c-7b610279c8aso3354047241.3 for ; Wed, 18 Oct 2023 11:33:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1697653982; x=1698258782; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=QtxLmuLHbQFmui1lvZH3xBsp1KXecwUjRoMts1nMQ0g=; b=ZIDwIEyRMJbwtv3ezHFVlScErAtAtciF5fIhKzZgEOskPk3tbVwipf8YzX2Arsgfln xFtgEjom6OAe6/2Zlgavcl17HZzl33vAmsJ6TM+/SjkLgRyRxfrVzyznaKEvt1w5a7i5 3XE86Kc3R8xYEgZMS/W7+Hz4QVxhxTymYQXzanurw0WhTq9pn57miBC9OSaYMk04Fex4 2vDlGwTpgkR1l6AGcY8htSRu3HTGeHrq29Mk6Dm47G/EQh4JXOT72lUsAK5Kh+TTAKDT 8WkwmoNQexDbV+Fgy0JSIyNtOyrC+QP7uDG30zK4LbQgd3EzP8VxrrFEmPb/sxwYamhe +TaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697653982; x=1698258782; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=QtxLmuLHbQFmui1lvZH3xBsp1KXecwUjRoMts1nMQ0g=; b=Juop6d8yNPr/3hgRYz9GMMyBzJb0sPvR9jl+m1bIOQyUc/WEnEZNhQ+gTP+FssBFDb DgmEx41OmI26BALpH2R2ehwIhARJPvqt4oSXGUN5XZpkWYgP4rJ4bf6VYYAWm7y2LQDk lJhqZfImRSGTJCEgRmHcAdeCa6LFm1Zoc6S43+ABC7NYMj81gRtUUgwDXACmxaPmypvM 3TMkkP23Q7x+rY4mvYuxNMFgHfijaWSGsYClV/8mU6PvYYGXWijy8azR3ekUkpxdya+L p6NnZWERVHER70zQU5Mvqp30zzQRfN9K8WfFZRok2eJAt8wFnLDWuFXRlIVmis0ZPXk1 UyWw== X-Gm-Message-State: AOJu0YystzwdLIYY+l7QjH5p3djqHKCyKdbnjLhZ4OlnQegcSeoVDdHI UnKf8tMRrO32R6RpETXlgN54VIthECYxGNr/q9Wrxg== X-Google-Smtp-Source: AGHT+IFEvKlHBlFXI0D8nxknXQeEX+fU5u2XxUl/bTDTiOgEn+Wx9Ca/AVeynIesMjsKreW9XgMYgQ== X-Received: by 2002:a67:e108:0:b0:458:62c6:d7fc with SMTP id d8-20020a67e108000000b0045862c6d7fcmr2341844vsl.3.1697653981903; Wed, 18 Oct 2023 11:33:01 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id cn6-20020a05622a248600b0041812703b7esm146787qtb.52.2023.10.18.11.33.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 11:33:00 -0700 (PDT) Date: Wed, 18 Oct 2023 14:32:59 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , "Eric W. Biederman" , Jeff King , Junio C Hamano , Patrick Steinhardt Subject: [PATCH v4 10/17] commit-graph: new filter ver. that fixes murmur3 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: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net From: Jonathan Tan The murmur3 implementation in bloom.c has a bug when converting series of 4 bytes into network-order integers when char is signed (which is controllable by a compiler option, and the default signedness of char is platform-specific). When a string contains characters with the high bit set, this bug causes results that, although internally consistent within Git, does not accord with other implementations of murmur3 (thus, the changed path filters wouldn't be readable by other off-the-shelf implementatios of murmur3) and even with Git binaries that were compiled with different signedness of char. This bug affects both how Git writes changed path filters to disk and how Git interprets changed path filters on disk. Therefore, introduce a new version (2) of changed path filters that corrects this problem. The existing version (1) is still supported and is still the default, but users should migrate away from it as soon as possible. Because this bug only manifests with characters that have the high bit set, it may be possible that some (or all) commits in a given repo would have the same changed path filter both before and after this fix is applied. However, in order to determine whether this is the case, the changed paths would first have to be computed, at which point it is not much more expensive to just compute a new changed path filter. So this patch does not include any mechanism to "salvage" changed path filters from repositories. There is also no "mixed" mode - for each invocation of Git, reading and writing changed path filters are done with the same version number; this version number may be explicitly stated (typically if the user knows which version they need) or automatically determined from the version of the existing changed path filters in the repository. There is a change in write_commit_graph(). graph_read_bloom_data() makes it possible for chunk_bloom_data to be non-NULL but bloom_filter_settings to be NULL, which causes a segfault later on. I produced such a segfault while developing this patch, but couldn't find a way to reproduce it neither after this complete patch (or before), but in any case it seemed like a good thing to include that might help future patch authors. The value in t0095 was obtained from another murmur3 implementation using the following Go source code: package main import "fmt" import "github.com/spaolacci/murmur3" func main() { fmt.Printf("%x\n", murmur3.Sum32([]byte("Hello world!"))) fmt.Printf("%x\n", murmur3.Sum32([]byte{0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff})) } Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano Signed-off-by: Taylor Blau Signed-off-by: Junio C Hamano Signed-off-by: Taylor Blau --- Documentation/config/commitgraph.txt | 5 +- bloom.c | 69 +++++++++++++++- bloom.h | 8 +- commit-graph.c | 32 ++++++-- t/helper/test-bloom.c | 9 ++- t/t0095-bloom.sh | 8 ++ t/t4216-log-bloom.sh | 114 +++++++++++++++++++++++++++ 7 files changed, 232 insertions(+), 13 deletions(-) diff --git a/Documentation/config/commitgraph.txt b/Documentation/config/commitgraph.txt index 2dc9170622..acc74a2f27 100644 --- a/Documentation/config/commitgraph.txt +++ b/Documentation/config/commitgraph.txt @@ -15,7 +15,7 @@ commitGraph.readChangedPaths:: commitGraph.changedPathsVersion:: Specifies the version of the changed-path Bloom filters that Git will read and - write. May be -1, 0 or 1. + write. May be -1, 0, 1, or 2. + Defaults to -1. + @@ -28,4 +28,7 @@ filters when instructed to write. If 1, Git will only read version 1 Bloom filters, and will write version 1 Bloom filters. + +If 2, Git will only read version 2 Bloom filters, and will write version 2 +Bloom filters. ++ See linkgit:git-commit-graph[1] for more information. diff --git a/bloom.c b/bloom.c index 3e78cfe79d..ebef5cfd2f 100644 --- a/bloom.c +++ b/bloom.c @@ -66,7 +66,64 @@ int load_bloom_filter_from_graph(struct commit_graph *g, * Not considered to be cryptographically secure. * Implemented as described in https://en.wikipedia.org/wiki/MurmurHash#Algorithm */ -uint32_t murmur3_seeded(uint32_t seed, const char *data, size_t len) +uint32_t murmur3_seeded_v2(uint32_t seed, const char *data, size_t len) +{ + const uint32_t c1 = 0xcc9e2d51; + const uint32_t c2 = 0x1b873593; + const uint32_t r1 = 15; + const uint32_t r2 = 13; + const uint32_t m = 5; + const uint32_t n = 0xe6546b64; + int i; + uint32_t k1 = 0; + const char *tail; + + int len4 = len / sizeof(uint32_t); + + uint32_t k; + for (i = 0; i < len4; i++) { + uint32_t byte1 = (uint32_t)(unsigned char)data[4*i]; + uint32_t byte2 = ((uint32_t)(unsigned char)data[4*i + 1]) << 8; + uint32_t byte3 = ((uint32_t)(unsigned char)data[4*i + 2]) << 16; + uint32_t byte4 = ((uint32_t)(unsigned char)data[4*i + 3]) << 24; + k = byte1 | byte2 | byte3 | byte4; + k *= c1; + k = rotate_left(k, r1); + k *= c2; + + seed ^= k; + seed = rotate_left(seed, r2) * m + n; + } + + tail = (data + len4 * sizeof(uint32_t)); + + switch (len & (sizeof(uint32_t) - 1)) { + case 3: + k1 ^= ((uint32_t)(unsigned char)tail[2]) << 16; + /*-fallthrough*/ + case 2: + k1 ^= ((uint32_t)(unsigned char)tail[1]) << 8; + /*-fallthrough*/ + case 1: + k1 ^= ((uint32_t)(unsigned char)tail[0]) << 0; + k1 *= c1; + k1 = rotate_left(k1, r1); + k1 *= c2; + seed ^= k1; + break; + } + + seed ^= (uint32_t)len; + seed ^= (seed >> 16); + seed *= 0x85ebca6b; + seed ^= (seed >> 13); + seed *= 0xc2b2ae35; + seed ^= (seed >> 16); + + return seed; +} + +static uint32_t murmur3_seeded_v1(uint32_t seed, const char *data, size_t len) { const uint32_t c1 = 0xcc9e2d51; const uint32_t c2 = 0x1b873593; @@ -131,8 +188,14 @@ void fill_bloom_key(const char *data, int i; const uint32_t seed0 = 0x293ae76f; const uint32_t seed1 = 0x7e646e2c; - const uint32_t hash0 = murmur3_seeded(seed0, data, len); - const uint32_t hash1 = murmur3_seeded(seed1, data, len); + uint32_t hash0, hash1; + if (settings->hash_version == 2) { + hash0 = murmur3_seeded_v2(seed0, data, len); + hash1 = murmur3_seeded_v2(seed1, data, len); + } else { + hash0 = murmur3_seeded_v1(seed0, data, len); + hash1 = murmur3_seeded_v1(seed1, data, len); + } key->hashes = (uint32_t *)xcalloc(settings->num_hashes, sizeof(uint32_t)); for (i = 0; i < settings->num_hashes; i++) diff --git a/bloom.h b/bloom.h index 1e4f612d2c..138d57a86b 100644 --- a/bloom.h +++ b/bloom.h @@ -8,9 +8,11 @@ struct commit_graph; struct bloom_filter_settings { /* * The version of the hashing technique being used. - * We currently only support version = 1 which is + * The newest version is 2, which is * the seeded murmur3 hashing technique implemented - * in bloom.c. + * in bloom.c. Bloom filters of version 1 were created + * with prior versions of Git, which had a bug in the + * implementation of the hash function. */ uint32_t hash_version; @@ -80,7 +82,7 @@ int load_bloom_filter_from_graph(struct commit_graph *g, * Not considered to be cryptographically secure. * Implemented as described in https://en.wikipedia.org/wiki/MurmurHash#Algorithm */ -uint32_t murmur3_seeded(uint32_t seed, const char *data, size_t len); +uint32_t murmur3_seeded_v2(uint32_t seed, const char *data, size_t len); void fill_bloom_key(const char *data, size_t len, diff --git a/commit-graph.c b/commit-graph.c index bcc9a15cfa..6b21b17b20 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -314,17 +314,26 @@ static int graph_read_oid_lookup(const unsigned char *chunk_start, return 0; } +struct graph_read_bloom_data_context { + struct commit_graph *g; + int *commit_graph_changed_paths_version; +}; + static int graph_read_bloom_data(const unsigned char *chunk_start, size_t chunk_size, void *data) { - struct commit_graph *g = data; + struct graph_read_bloom_data_context *c = data; + struct commit_graph *g = c->g; uint32_t hash_version; - g->chunk_bloom_data = chunk_start; hash_version = get_be32(chunk_start); - if (hash_version != 1) + if (*c->commit_graph_changed_paths_version == -1) { + *c->commit_graph_changed_paths_version = hash_version; + } else if (hash_version != *c->commit_graph_changed_paths_version) { return 0; + } + g->chunk_bloom_data = chunk_start; g->bloom_filter_settings = xmalloc(sizeof(struct bloom_filter_settings)); g->bloom_filter_settings->hash_version = hash_version; g->bloom_filter_settings->num_hashes = get_be32(chunk_start + 4); @@ -412,10 +421,14 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s, } if (s->commit_graph_changed_paths_version) { + struct graph_read_bloom_data_context context = { + .g = graph, + .commit_graph_changed_paths_version = &s->commit_graph_changed_paths_version + }; pair_chunk(cf, GRAPH_CHUNKID_BLOOMINDEXES, &graph->chunk_bloom_indexes); read_chunk(cf, GRAPH_CHUNKID_BLOOMDATA, - graph_read_bloom_data, graph); + graph_read_bloom_data, &context); } if (graph->chunk_bloom_indexes && graph->chunk_bloom_data) { @@ -2436,6 +2449,13 @@ int write_commit_graph(struct object_directory *odb, } if (!commit_graph_compatible(r)) return 0; + if (r->settings.commit_graph_changed_paths_version < -1 + || r->settings.commit_graph_changed_paths_version > 2) { + warning(_("attempting to write a commit-graph, but " + "'commitgraph.changedPathsVersion' (%d) is not supported"), + r->settings.commit_graph_changed_paths_version); + return 0; + } CALLOC_ARRAY(ctx, 1); ctx->r = r; @@ -2448,6 +2468,8 @@ int write_commit_graph(struct object_directory *odb, ctx->write_generation_data = (get_configured_generation_version(r) == 2); ctx->num_generation_data_overflows = 0; + bloom_settings.hash_version = r->settings.commit_graph_changed_paths_version == 2 + ? 2 : 1; bloom_settings.bits_per_entry = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_BITS_PER_ENTRY", bloom_settings.bits_per_entry); bloom_settings.num_hashes = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_NUM_HASHES", @@ -2477,7 +2499,7 @@ int write_commit_graph(struct object_directory *odb, g = ctx->r->objects->commit_graph; /* We have changed-paths already. Keep them in the next graph */ - if (g && g->chunk_bloom_data) { + if (g && g->bloom_filter_settings) { ctx->changed_paths = 1; ctx->bloom_settings = g->bloom_filter_settings; } diff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c index aabe31d724..3cbc0a5b50 100644 --- a/t/helper/test-bloom.c +++ b/t/helper/test-bloom.c @@ -50,6 +50,7 @@ static void get_bloom_filter_for_commit(const struct object_id *commit_oid) static const char *bloom_usage = "\n" " test-tool bloom get_murmur3 \n" +" test-tool bloom get_murmur3_seven_highbit\n" " test-tool bloom generate_filter [...]\n" " test-tool bloom get_filter_for_commit \n"; @@ -64,7 +65,13 @@ int cmd__bloom(int argc, const char **argv) uint32_t hashed; if (argc < 3) usage(bloom_usage); - hashed = murmur3_seeded(0, argv[2], strlen(argv[2])); + hashed = murmur3_seeded_v2(0, argv[2], strlen(argv[2])); + printf("Murmur3 Hash with seed=0:0x%08x\n", hashed); + } + + if (!strcmp(argv[1], "get_murmur3_seven_highbit")) { + uint32_t hashed; + hashed = murmur3_seeded_v2(0, "\x99\xaa\xbb\xcc\xdd\xee\xff", 7); printf("Murmur3 Hash with seed=0:0x%08x\n", hashed); } diff --git a/t/t0095-bloom.sh b/t/t0095-bloom.sh index b567383eb8..c8d84ab606 100755 --- a/t/t0095-bloom.sh +++ b/t/t0095-bloom.sh @@ -29,6 +29,14 @@ test_expect_success 'compute unseeded murmur3 hash for test string 2' ' test_cmp expect actual ' +test_expect_success 'compute unseeded murmur3 hash for test string 3' ' + cat >expect <<-\EOF && + Murmur3 Hash with seed=0:0xa183ccfd + EOF + test-tool bloom get_murmur3_seven_highbit >actual && + test_cmp expect actual +' + test_expect_success 'compute bloom key for empty string' ' cat >expect <<-\EOF && Hashes:0x5615800c|0x5b966560|0x61174ab4|0x66983008|0x6c19155c|0x7199fab0|0x771ae004| diff --git a/t/t4216-log-bloom.sh b/t/t4216-log-bloom.sh index 400dce2193..68066b7928 100755 --- a/t/t4216-log-bloom.sh +++ b/t/t4216-log-bloom.sh @@ -535,4 +535,118 @@ test_expect_success 'version 1 changed-path used when version 1 requested' ' ) ' +test_expect_success 'version 1 changed-path not used when version 2 requested' ' + ( + cd highbit1 && + git config --add commitgraph.changedPathsVersion 2 && + test_bloom_filters_not_used "-- another$CENT" + ) +' + +test_expect_success 'version 1 changed-path used when autodetect requested' ' + ( + cd highbit1 && + git config --add commitgraph.changedPathsVersion -1 && + test_bloom_filters_used "-- another$CENT" + ) +' + +test_expect_success 'when writing another commit graph, preserve existing version 1 of changed-path' ' + test_commit -C highbit1 c1double "$CENT$CENT" && + git -C highbit1 commit-graph write --reachable --changed-paths && + ( + cd highbit1 && + git config --add commitgraph.changedPathsVersion -1 && + echo "options: bloom(1,10,7) read_generation_data" >expect && + test-tool read-graph >full && + grep options full >actual && + test_cmp expect actual + ) +' + +test_expect_success 'set up repo with high bit path, version 2 changed-path' ' + git init highbit2 && + git -C highbit2 config --add commitgraph.changedPathsVersion 2 && + test_commit -C highbit2 c2 "$CENT" && + git -C highbit2 commit-graph write --reachable --changed-paths +' + +test_expect_success 'check value of version 2 changed-path' ' + ( + cd highbit2 && + echo "c01f" >expect && + get_first_changed_path_filter >actual && + test_cmp expect actual + ) +' + +test_expect_success 'setup make another commit' ' + # "git log" does not use Bloom filters for root commits - see how, in + # revision.c, rev_compare_tree() (the only code path that eventually calls + # get_bloom_filter()) is only called by try_to_simplify_commit() when the commit + # has one parent. Therefore, make another commit so that we perform the tests on + # a non-root commit. + test_commit -C highbit2 anotherc2 "another$CENT" +' + +test_expect_success 'version 2 changed-path used when version 2 requested' ' + ( + cd highbit2 && + test_bloom_filters_used "-- another$CENT" + ) +' + +test_expect_success 'version 2 changed-path not used when version 1 requested' ' + ( + cd highbit2 && + git config --add commitgraph.changedPathsVersion 1 && + test_bloom_filters_not_used "-- another$CENT" + ) +' + +test_expect_success 'version 2 changed-path used when autodetect requested' ' + ( + cd highbit2 && + git config --add commitgraph.changedPathsVersion -1 && + test_bloom_filters_used "-- another$CENT" + ) +' + +test_expect_success 'when writing another commit graph, preserve existing version 2 of changed-path' ' + test_commit -C highbit2 c2double "$CENT$CENT" && + git -C highbit2 commit-graph write --reachable --changed-paths && + ( + cd highbit2 && + git config --add commitgraph.changedPathsVersion -1 && + echo "options: bloom(2,10,7) read_generation_data" >expect && + test-tool read-graph >full && + grep options full >actual && + test_cmp expect actual + ) +' + +test_expect_success 'when writing commit graph, do not reuse changed-path of another version' ' + git init doublewrite && + test_commit -C doublewrite c "$CENT" && + git -C doublewrite config --add commitgraph.changedPathsVersion 1 && + git -C doublewrite commit-graph write --reachable --changed-paths && + for v in -2 3 + do + git -C doublewrite config --add commitgraph.changedPathsVersion $v && + git -C doublewrite commit-graph write --reachable --changed-paths 2>err && + cat >expect <<-EOF && + warning: attempting to write a commit-graph, but ${SQ}commitgraph.changedPathsVersion${SQ} ($v) is not supported + EOF + test_cmp expect err || return 1 + done && + git -C doublewrite config --add commitgraph.changedPathsVersion 2 && + git -C doublewrite commit-graph write --reachable --changed-paths && + ( + cd doublewrite && + echo "c01f" >expect && + get_first_changed_path_filter >actual && + test_cmp expect actual + ) +' + test_done From patchwork Wed Oct 18 18:33:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13427737 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 7478247368 for ; Wed, 18 Oct 2023 18:33:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="HqiwmHRW" Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39CD311A for ; Wed, 18 Oct 2023 11:33:06 -0700 (PDT) Received: by mail-qk1-x730.google.com with SMTP id af79cd13be357-77891f362cfso94159185a.1 for ; Wed, 18 Oct 2023 11:33:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1697653985; x=1698258785; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=/NdqeADlm8MlHqMkDFkBT34FdrCZHUx2vMpvbO2dIUI=; b=HqiwmHRW6rOPP69aumUPeLm9WpCKbQ/W5Zscji/LaLbtMs5y1UiwSKAU4bm/ISNOtY 6nROp7G7zSOOwuKOypAYI7xmWUjBYqfGzQSJwQgnlTzRWyX/cmydDlyTJ3oVU4r0Wz5p IFUxyV761bhIhCsDnGOeg3ZUUg5SFdxcF8qk6pgfoLDeBqCWCWw0RCvB2P6eNM9ECOE0 AYJU8aTFNCK1WQ9IGHlpHHvbmG/xgeoUS1Srqx11VnVyFGGIA0gUvK+Tk6e1VhucgVZg OwyYeBWiVyMJZZR8ljJtHb6NQmlW7yUWQOkgtNHPc8kbZCbnObrskOEMwQgyhkyBpUM6 hv+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697653985; x=1698258785; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=/NdqeADlm8MlHqMkDFkBT34FdrCZHUx2vMpvbO2dIUI=; b=qj2nZ2QFr4wQ62T+TR6Ho9bfkdjQDEkIlrX85fXEywcoRl2qtFGzDgMGU2uoajuInJ 8K3CZQdfyoIWRcVhmRk5nsyGkyQQX657ghoJC8idhFDvc+18KTcBOq2MbghkVhSZY1yc SPvxkSZvIPGldxmHuaPiRlAsPJIHsuL5ao7BWKEvCqGTMFlNjhJdr5mp7HySRPtPALxH 3r0OEB9z4azBuFqTek/YBal7AmC+ryYujrWtNom38cdID07hOrW9KtFH3da2l6oKdXh0 saKy9bjvFfY4ZTyEakGQxu/e8LGU8m5yWvMMm5hMb0B/TrhGgpJtp2hDqYYTBw/3JeZt e2aw== X-Gm-Message-State: AOJu0YyuyV4CpFy9++VGg6r/iAw+jQT94kzFWjgkzkDYXMmO+c8vIvsH j4p/veP2CrL7rHfbmBfOjyIlTkNr+2Xz9MAwpyTH/g== X-Google-Smtp-Source: AGHT+IHF25VkaUbYLk9LUwUOtNY258TRVEShZ2+p7CPiIMY6VfzbNjkdF7LZ0GnZ9AKhkYB54gM0bQ== X-Received: by 2002:a05:620a:24c2:b0:775:c335:1f2a with SMTP id m2-20020a05620a24c200b00775c3351f2amr233071qkn.38.1697653985152; Wed, 18 Oct 2023 11:33:05 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id p19-20020a05620a22f300b00777063b89casm155978qki.5.2023.10.18.11.33.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 11:33:04 -0700 (PDT) Date: Wed, 18 Oct 2023 14:33:03 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , "Eric W. Biederman" , Jeff King , Junio C Hamano , Patrick Steinhardt Subject: [PATCH v4 11/17] bloom: annotate filters with hash version 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: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net In subsequent commits, we will want to load existing Bloom filters out of a commit-graph, even when the hash version they were computed with does not match the value of `commitGraph.changedPathVersion`. In order to differentiate between the two, add a "version" field to each Bloom filter. Signed-off-by: Taylor Blau --- bloom.c | 11 ++++++++--- bloom.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bloom.c b/bloom.c index ebef5cfd2f..9b6a30f6f6 100644 --- a/bloom.c +++ b/bloom.c @@ -55,6 +55,7 @@ int load_bloom_filter_from_graph(struct commit_graph *g, filter->data = (unsigned char *)(g->chunk_bloom_data + sizeof(unsigned char) * start_index + BLOOMDATA_CHUNK_HEADER_SIZE); + filter->version = g->bloom_filter_settings->hash_version; return 1; } @@ -240,11 +241,13 @@ static int pathmap_cmp(const void *hashmap_cmp_fn_data UNUSED, return strcmp(e1->path, e2->path); } -static void init_truncated_large_filter(struct bloom_filter *filter) +static void init_truncated_large_filter(struct bloom_filter *filter, + int version) { filter->data = xmalloc(1); filter->data[0] = 0xFF; filter->len = 1; + filter->version = version; } struct bloom_filter *get_or_compute_bloom_filter(struct repository *r, @@ -329,13 +332,15 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r, } if (hashmap_get_size(&pathmap) > settings->max_changed_paths) { - init_truncated_large_filter(filter); + init_truncated_large_filter(filter, + settings->hash_version); if (computed) *computed |= BLOOM_TRUNC_LARGE; goto cleanup; } filter->len = (hashmap_get_size(&pathmap) * settings->bits_per_entry + BITS_PER_WORD - 1) / BITS_PER_WORD; + filter->version = settings->hash_version; if (!filter->len) { if (computed) *computed |= BLOOM_TRUNC_EMPTY; @@ -355,7 +360,7 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r, } else { for (i = 0; i < diff_queued_diff.nr; i++) diff_free_filepair(diff_queued_diff.queue[i]); - init_truncated_large_filter(filter); + init_truncated_large_filter(filter, settings->hash_version); if (computed) *computed |= BLOOM_TRUNC_LARGE; diff --git a/bloom.h b/bloom.h index 138d57a86b..330a140520 100644 --- a/bloom.h +++ b/bloom.h @@ -55,6 +55,7 @@ struct bloom_filter_settings { struct bloom_filter { unsigned char *data; size_t len; + int version; }; /* From patchwork Wed Oct 18 18:33:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13427739 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 16E0741E2E for ; Wed, 18 Oct 2023 18:33:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="LvXXIrbo" Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1B5711A for ; Wed, 18 Oct 2023 11:33:09 -0700 (PDT) Received: by mail-qk1-x735.google.com with SMTP id af79cd13be357-7757f2d3956so687550185a.0 for ; Wed, 18 Oct 2023 11:33:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1697653989; x=1698258789; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=5PDoDCF/c0g93jQOE09nRI+IBg8OcKoukZkKyO7zGKQ=; b=LvXXIrbo070KkZR1vbGeBHzLUJb8mOhnflh3R6xhH6mftcFHoKMWPEL5pgaRWuXNn3 S66rN62RcCaqfCgt09gbo0mmyFk/r0I+aJFc9EYhz5Gt9NvcQqiM0k36mblZjS1O3Jw8 bkMtd2GhMGCsQEX7iU/J4me40ZPMEjX58O1A70/4KFuR2bDemrx10IQOYrP1Cq4c+4cJ PVsfw2Zt5eTHgvBc6bDaw/kWcCEMCi/4jqUeGUEftasnK6tOCewo9lKx8+ZgzPPI6H0K Xq3wibl0QJSl6kA3+26j1oNLhVrYXd8213158tEN3dm+3WgtRXOK4XaJ22cCCZDWayc6 S+Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697653989; x=1698258789; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=5PDoDCF/c0g93jQOE09nRI+IBg8OcKoukZkKyO7zGKQ=; b=f6e4ZNZ+e5TtC8/IKXN4uzzi8gZ+ndGTA+UqccindpIBTeJtxyteFAsCut+IGfaWRf 5/H6AoGjnFIo36O4gbt8l2sQpMuIV40dqWwl5PLSQD3mjyVW1ECW1pcWoIU/DsJN3KaA Vf7R8tvyvSFBH/Db53l+KWJtzRkSM/Ykdejz/IN97beG/sAQQeQiv35qIxI0YecT3SjN SmmB1j7qaSU8ME2oDKiOZ6mQDHy20G/vGckeCvSGEHhV0fYLijokQSwC9l81OFw1hQNt Otbaq/5gQJZYpdNl0T6Jik6eESSS1ElQg8+pqPuDPpkZUtaIiaOST6MH6r6i5cDEtq4l M9tA== X-Gm-Message-State: AOJu0Yzfq2DqjXsfwW6ow03hYZENJ/cTHDq87jrctPWqS6frItQVbbOR ZvWyhDAgMUqpwxnPgxdVg88HJAjYw9oRNRzbfur5Nw== X-Google-Smtp-Source: AGHT+IGenAUywz9ltpERoQLKm52ReZNifrQcwVaSTZF1rH+IbPlRYupa3V6h5Kc2OiKEsVprLsiMkA== X-Received: by 2002:a05:6214:21a5:b0:66d:8203:9433 with SMTP id t5-20020a05621421a500b0066d82039433mr172041qvc.31.1697653988791; Wed, 18 Oct 2023 11:33:08 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id mi1-20020a056214558100b0066d15724ff7sm154525qvb.52.2023.10.18.11.33.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 11:33:08 -0700 (PDT) Date: Wed, 18 Oct 2023 14:33:07 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , "Eric W. Biederman" , Jeff King , Junio C Hamano , Patrick Steinhardt Subject: [PATCH v4 12/17] bloom: prepare to discard incompatible Bloom filters Message-ID: <85dbdc4ed28058bcf4d1eff8f134fd2299bd18fb.1697653929.git.me@ttaylorr.com> 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: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Callers use the inline `get_bloom_filter()` implementation as a thin wrapper around `get_or_compute_bloom_filter()`. The former calls the latter with a value of "0" for `compute_if_not_present`, making `get_bloom_filter()` the default read-only path for fetching an existing Bloom filter. Callers expect the value returned from `get_bloom_filter()` is usable, that is that it's compatible with the configured value corresponding to `commitGraph.changedPathsVersion`. This is OK, since the commit-graph machinery only initializes its BDAT chunk (thereby enabling it to service Bloom filter queries) when the Bloom filter hash_version is compatible with our settings. So any value returned by `get_bloom_filter()` is trivially useable. However, subsequent commits will load the BDAT chunk even when the Bloom filters are built with incompatible hash versions. Prepare to handle this by teaching `get_bloom_filter()` to discard filters that are incompatible with the configured hash version. Callers who wish to read incompatible filters (e.g., for upgrading filters from v1 to v2) may use the lower level routine, `get_or_compute_bloom_filter()`. Signed-off-by: Taylor Blau --- bloom.c | 20 +++++++++++++++++++- bloom.h | 20 ++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/bloom.c b/bloom.c index 9b6a30f6f6..739fa093ba 100644 --- a/bloom.c +++ b/bloom.c @@ -250,6 +250,23 @@ static void init_truncated_large_filter(struct bloom_filter *filter, filter->version = version; } +struct bloom_filter *get_bloom_filter(struct repository *r, struct commit *c) +{ + struct bloom_filter *filter; + int hash_version; + + filter = get_or_compute_bloom_filter(r, c, 0, NULL, NULL); + if (!filter) + return NULL; + + prepare_repo_settings(r); + hash_version = r->settings.commit_graph_changed_paths_version; + + if (!(hash_version == -1 || hash_version == filter->version)) + return NULL; /* unusable filter */ + return filter; +} + struct bloom_filter *get_or_compute_bloom_filter(struct repository *r, struct commit *c, int compute_if_not_present, @@ -275,7 +292,8 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r, filter, graph_pos); } - if (filter->data && filter->len) + if ((filter->data && filter->len) && + (!settings || settings->hash_version == filter->version)) return filter; if (!compute_if_not_present) return NULL; diff --git a/bloom.h b/bloom.h index 330a140520..bfe389e29c 100644 --- a/bloom.h +++ b/bloom.h @@ -110,8 +110,24 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r, const struct bloom_filter_settings *settings, enum bloom_filter_computed *computed); -#define get_bloom_filter(r, c) get_or_compute_bloom_filter( \ - (r), (c), 0, NULL, NULL) +/* + * Find the Bloom filter associated with the given commit "c". + * + * If any of the following are true + * + * - the repository does not have a commit-graph, or + * - the repository disables reading from the commit-graph, or + * - the given commit does not have a Bloom filter computed, or + * - there is a Bloom filter for commit "c", but it cannot be read + * because the filter uses an incompatible version of murmur3 + * + * , then `get_bloom_filter()` will return NULL. Otherwise, the corresponding + * Bloom filter will be returned. + * + * For callers who wish to inspect Bloom filters with incompatible hash + * versions, use get_or_compute_bloom_filter(). + */ +struct bloom_filter *get_bloom_filter(struct repository *r, struct commit *c); int bloom_filter_contains(const struct bloom_filter *filter, const struct bloom_key *key, From patchwork Wed Oct 18 18:33:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13427740 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 9433947353 for ; Wed, 18 Oct 2023 18:33:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="SSchvAlV" Received: from mail-vs1-xe2d.google.com (mail-vs1-xe2d.google.com [IPv6:2607:f8b0:4864:20::e2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3618B11F for ; Wed, 18 Oct 2023 11:33:13 -0700 (PDT) Received: by mail-vs1-xe2d.google.com with SMTP id ada2fe7eead31-457c057bdb5so2459756137.0 for ; Wed, 18 Oct 2023 11:33:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1697653992; x=1698258792; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=FanJJajcn/KBmo9c7uu27oFtZUUHzBBDYrF7MNrLZyE=; b=SSchvAlVRoKYii4iwU5/cT3jIA55BXzM85lx4SCRlh/nXMUIGyUY97GbDqgR7slqkG zXDLFq8erVRhNfawCdqVMALygMnxykmkffRYzol3tYFjWcYQoJoMVzsrH4NoyZKxsIoP /orc+rqvDHtkZjWL+7iQvGcvSC5f4m1ARixBt5lK0V6bwnfLS2Dq72IU08IzfhTD+bNp Lx5u58xLsiafsNcdqEjwPSm2AcH3eduwJ6JJtr0+EI5CAdSZeRC55qvD6FkBJEbz+91c ziZnSB4ejZmORJn/+on8fEFEw6POSvc71pqsQq0m3oiTnJqYQ5UBbkbIhVH8fSgpGEjw +Dfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697653992; x=1698258792; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=FanJJajcn/KBmo9c7uu27oFtZUUHzBBDYrF7MNrLZyE=; b=CWQjRTX6pHLxtiaAAAvVlvxZ/ZalKKXxzX2C97MX0i1BHi7kUmC4zzj9G2d98XT7LE Yz5YZjuO7M5NKxrFU7t71EkVDsKrkYhGY7k111c1Y39gHRun9OXMQ3i7t3PTaDY1FKjQ HPBoy3x/99/j0RkUQ0R1O7Pek1hOA3ZFznZr/FmRJaYN2mweYZ1tNMOHfAIOeNtwdNIS o2mTsfW/2JzRWsxSNTMzA1q7UxePFBX2TKmc5NHKIiafcYxyMrU/debkZayD5SnwFAt6 BVxVvvpB2lavA9Is7lx80GYdFHvu7bNBSGb0NNVGPIyOafDVI8jJlNvPzB2fERByAW3p oSNA== X-Gm-Message-State: AOJu0YxaDzJcPcEx5D/+ZV/A2NrBHOsPhSeS/c8+99T2O51R2N7szHyB MvJRgJXftiTYS+bzV3al8aYfSzwRXk10flqGC+o/AQ== X-Google-Smtp-Source: AGHT+IE/uh0tPHSjE2L50PvYe1KmucNT/OXL4JJ0cebA+DMbtZ+/SbOsqlpUXYRAu67R8VNANVxc+Q== X-Received: by 2002:a05:6102:54ac:b0:452:c729:e9df with SMTP id bk44-20020a05610254ac00b00452c729e9dfmr8246785vsb.33.1697653992151; Wed, 18 Oct 2023 11:33:12 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id f5-20020ac84645000000b004181d77e08fsm141615qto.85.2023.10.18.11.33.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 11:33:11 -0700 (PDT) Date: Wed, 18 Oct 2023 14:33:10 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , "Eric W. Biederman" , Jeff King , Junio C Hamano , Patrick Steinhardt Subject: [PATCH v4 13/17] commit-graph.c: unconditionally load Bloom filters Message-ID: <3ff669a622355bd8eb63494cd90d241d47dd2d83.1697653929.git.me@ttaylorr.com> 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: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net In 9e4df4da07 (commit-graph: new filter ver. that fixes murmur3, 2023-08-01), we began ignoring the Bloom data ("BDAT") chunk for commit-graphs whose Bloom filters were computed using a hash version incompatible with the value of `commitGraph.changedPathVersion`. Now that the Bloom API has been hardened to discard these incompatible filters (with the exception of low-level APIs), we can safely load these Bloom filters unconditionally. We no longer want to return early from `graph_read_bloom_data()`, and similarly do not want to set the bloom_settings' `hash_version` field as a side-effect. The latter is because we want to wait until we know which Bloom settings we're using (either the defaults, from the GIT_TEST variables, or from the previous commit-graph layer) before deciding what hash_version to use. If we detect an existing BDAT chunk, we'll infer the rest of the settings (e.g., number of hashes, bits per entry, and maximum number of changed paths) from the earlier graph layer. The hash_version will be inferred from the previous layer as well, unless one has already been specified via configuration. Once all of that is done, we normalize the value of the hash_version to either "1" or "2". Signed-off-by: Taylor Blau --- commit-graph.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index 6b21b17b20..7d0fb32107 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -327,12 +327,6 @@ static int graph_read_bloom_data(const unsigned char *chunk_start, uint32_t hash_version; hash_version = get_be32(chunk_start); - if (*c->commit_graph_changed_paths_version == -1) { - *c->commit_graph_changed_paths_version = hash_version; - } else if (hash_version != *c->commit_graph_changed_paths_version) { - return 0; - } - g->chunk_bloom_data = chunk_start; g->bloom_filter_settings = xmalloc(sizeof(struct bloom_filter_settings)); g->bloom_filter_settings->hash_version = hash_version; @@ -2468,8 +2462,7 @@ int write_commit_graph(struct object_directory *odb, ctx->write_generation_data = (get_configured_generation_version(r) == 2); ctx->num_generation_data_overflows = 0; - bloom_settings.hash_version = r->settings.commit_graph_changed_paths_version == 2 - ? 2 : 1; + bloom_settings.hash_version = r->settings.commit_graph_changed_paths_version; bloom_settings.bits_per_entry = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_BITS_PER_ENTRY", bloom_settings.bits_per_entry); bloom_settings.num_hashes = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_NUM_HASHES", @@ -2501,10 +2494,18 @@ int write_commit_graph(struct object_directory *odb, /* We have changed-paths already. Keep them in the next graph */ if (g && g->bloom_filter_settings) { ctx->changed_paths = 1; - ctx->bloom_settings = g->bloom_filter_settings; + + /* don't propagate the hash_version unless unspecified */ + if (bloom_settings.hash_version == -1) + bloom_settings.hash_version = g->bloom_filter_settings->hash_version; + bloom_settings.bits_per_entry = g->bloom_filter_settings->bits_per_entry; + bloom_settings.num_hashes = g->bloom_filter_settings->num_hashes; + bloom_settings.max_changed_paths = g->bloom_filter_settings->max_changed_paths; } } + bloom_settings.hash_version = bloom_settings.hash_version == 2 ? 2 : 1; + if (ctx->split) { struct commit_graph *g = ctx->r->objects->commit_graph; From patchwork Wed Oct 18 18:33:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13427741 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 78C629CA5C for ; Wed, 18 Oct 2023 18:33:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="Hq04RakE" Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DB07122 for ; Wed, 18 Oct 2023 11:33:17 -0700 (PDT) Received: by mail-qk1-x72f.google.com with SMTP id af79cd13be357-776f84c6cc7so479864885a.2 for ; Wed, 18 Oct 2023 11:33:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1697653996; x=1698258796; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=sI5ZrjQEuF57E4hAqiEKGE2dRM6QFWR1Zi3nxln3p1U=; b=Hq04RakEGn70QypyxW7M0e3ZhatnZBFwRsS7IVBZ32bKH0oshjnpGrt9FdrZ1wvbPd FLNVrCAMUHE85Y7aPu9HlqS7v0WGPY0a2ccK9I2Ev1SFPi8GvgFDIjRKACT7+G2nZkzc LgZpBS11VVe96rTLxlIDtNmzo4nSCn5/h8E9kMNdmqRXmgO1gfS8AxVxAbfA45Bov7Zr NvnmiaGsNWPB5yh4TNSkliBlwi4wOb8IXUENgV8rhJRfSkOwB1Ep0rQzrrVp9rw5BnIw 98IVX9N4lJWcrsgAzJ3MDdJV9uGGz1V5Bkl82OBPu66cgqBGc/zuSrg0HxeP90ziqVKR Y2bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697653996; x=1698258796; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=sI5ZrjQEuF57E4hAqiEKGE2dRM6QFWR1Zi3nxln3p1U=; b=gGb44zXnZwvqq07X28TJbpF6Rx1fOAFx3GuVJFvABF4u0hPYxw2GJeJrozZo34YM26 nDxINEi26qgUEJ874n65Sr3PbxFcTSryBda8MjMRoRuEwfM0yf7tYGa1m0YEm9sK3j1R nmBBW0pcwUWPqvxg+RWcEEtR7TBougxTn+C7WvUyc2J5VAC35IDTOVdMAhbA/zoOdlvx lSSEOUZ9YPAi7ZBnitnxCsBYxHztQoMxHxre9u0xxaw6zggoCRgHUSTS4npFDWnsta+D IA05fRsO1fOszcHvT9224tVtmcwoclJ8LT7M3ZUKQFXzIv86YIgejZ05+t4krmLwoZT5 +E5A== X-Gm-Message-State: AOJu0YxkfCluq5JGQnl6JrLB8TF+zvWMXsjKrYjIJVZka7oGOBdLeK+y sim3V7olLWr9CEaThkhKQtFCEAgz1PAM41773mtgbw== X-Google-Smtp-Source: AGHT+IFJ/APCp7A/TxYY3NQZx5Yrj299lgGTs97GvDWaZ9R6MB2jRzvVX8W6BSqQJP9tY4SXTDYwNg== X-Received: by 2002:ae9:f208:0:b0:775:d49d:b439 with SMTP id m8-20020ae9f208000000b00775d49db439mr5330477qkg.76.1697653996005; Wed, 18 Oct 2023 11:33:16 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id w12-20020a05620a148c00b0076f0744ff50sm145029qkj.136.2023.10.18.11.33.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 11:33:15 -0700 (PDT) Date: Wed, 18 Oct 2023 14:33:14 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , "Eric W. Biederman" , Jeff King , Junio C Hamano , Patrick Steinhardt Subject: [PATCH v4 14/17] commit-graph: drop unnecessary `graph_read_bloom_data_context` Message-ID: <1c78e3d17804f64797fc13cd31dadfd51e550bf4.1697653929.git.me@ttaylorr.com> 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: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net The `graph_read_bloom_data_context` struct was introduced in an earlier commit in order to pass pointers to the commit-graph and changed-path Bloom filter version when reading the BDAT chunk. The previous commit no longer writes through the changed_paths_version pointer, making the surrounding context structure unnecessary. Drop it and pass a pointer to the commit-graph directly when reading the BDAT chunk. Noticed-by: Jonathan Tan Signed-off-by: Taylor Blau --- commit-graph.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index 7d0fb32107..b70d57b085 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -314,16 +314,10 @@ static int graph_read_oid_lookup(const unsigned char *chunk_start, return 0; } -struct graph_read_bloom_data_context { - struct commit_graph *g; - int *commit_graph_changed_paths_version; -}; - static int graph_read_bloom_data(const unsigned char *chunk_start, size_t chunk_size, void *data) { - struct graph_read_bloom_data_context *c = data; - struct commit_graph *g = c->g; + struct commit_graph *g = data; uint32_t hash_version; hash_version = get_be32(chunk_start); @@ -415,14 +409,10 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s, } if (s->commit_graph_changed_paths_version) { - struct graph_read_bloom_data_context context = { - .g = graph, - .commit_graph_changed_paths_version = &s->commit_graph_changed_paths_version - }; pair_chunk(cf, GRAPH_CHUNKID_BLOOMINDEXES, &graph->chunk_bloom_indexes); read_chunk(cf, GRAPH_CHUNKID_BLOOMDATA, - graph_read_bloom_data, &context); + graph_read_bloom_data, graph); } if (graph->chunk_bloom_indexes && graph->chunk_bloom_data) { From patchwork Wed Oct 18 18:33:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13427742 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 8B57142BE7 for ; Wed, 18 Oct 2023 18:33:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="K22lRv0W" Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D864114 for ; Wed, 18 Oct 2023 11:33:20 -0700 (PDT) Received: by mail-qv1-xf2d.google.com with SMTP id 6a1803df08f44-66cfd3a0e61so45732066d6.1 for ; Wed, 18 Oct 2023 11:33:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1697653999; x=1698258799; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=kIreURMbpMrMGWi/Xwgb/ztnwqGVTRyDmEVBfo+FjeQ=; b=K22lRv0WA9KgKY8/D2IFw7TvPU2QdwigW4g9remVUI0VOFUviz3yn57RPeV9sv4BC1 oXTzhSyjhQUj0nOg9Lrw+U8XqkIsMi+FTGgsXlxUDIjjcUsh8rQ7Wcl2kTQadIsdzcB9 g6LHjUQ7kIDB77XLhpdKsGTU5DfQDuB7+l+bT+Vay1muDrZu5evkTXYNDXp4x/p7Ph9c erqYYGVHxMV3eF1LzVVXxus78Fd+ffHWArAtLv2orsqv7ARa/HF1wXqXq2B/W70Ih+o4 GUfcAw4kcvlDCPJpo3GSkCgih8mcYsEj9T6//UfLrYEK2a8tP7k8RZlxQxQPcS8nACl3 nHwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697653999; x=1698258799; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=kIreURMbpMrMGWi/Xwgb/ztnwqGVTRyDmEVBfo+FjeQ=; b=wjrthF9VDJy2rlRpxY65hpMJEf0ITKEbiSZJOm15SKmJLA3O1RVW3JQf+WIB5Dm1Fb RmGpkNJ5YFczawICjqwlTuqX1lmxji74t+opf/m9MazK2QtND+w4Ly3WpAR0M53fMTUW 66sD1oxumn8Tt7jdijOZBm/LYtb9aM+e8nN5OBRKGtT4R+IL+bcO5w05NypM95m4Q1bW YG5oiIe+qura8hW/52ZnRcUvSHS1Chv0DovBnM7YC7Alcx62zbvLrEGqrHJcZJoyPeup HKmIRkdRgfWyO1eBc7npmlzkqSq2hXLKRHAHhTgZ4G1akiv7Pk8sqcv1D40XfZpHQif3 B2bQ== X-Gm-Message-State: AOJu0YwzxiVHLxA1kQ5o/DxBCdiF6MIW6B+gfnwAr7JXzjxVdpYD3vXL he9sABCLSqk5Q2MDyauYB3p01twEh1ydapa4mF/b4A== X-Google-Smtp-Source: AGHT+IGFCHFh2XZlU/5UQPuJwqcQ9vKhVRV8oGUeuyI8cWraXJsWyGnikMo2eyw65EbJ24eD10dNcw== X-Received: by 2002:a05:6214:2aa6:b0:66d:38e3:4ff7 with SMTP id js6-20020a0562142aa600b0066d38e34ff7mr146817qvb.10.1697653999581; Wed, 18 Oct 2023 11:33:19 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id t7-20020ac86a07000000b004197d6d97c4sm146621qtr.24.2023.10.18.11.33.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 11:33:19 -0700 (PDT) Date: Wed, 18 Oct 2023 14:33:17 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , "Eric W. Biederman" , Jeff King , Junio C Hamano , Patrick Steinhardt Subject: [PATCH v4 15/17] object.h: fix mis-aligned flag bits table 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: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Bit position 23 is one column too far to the left. Signed-off-by: Taylor Blau --- object.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/object.h b/object.h index 114d45954d..db25714b4e 100644 --- a/object.h +++ b/object.h @@ -62,7 +62,7 @@ void object_array_init(struct object_array *array); /* * object flag allocation: - * revision.h: 0---------10 15 23------27 + * revision.h: 0---------10 15 23------27 * fetch-pack.c: 01 67 * negotiator/default.c: 2--5 * walker.c: 0-2 From patchwork Wed Oct 18 18:33:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13427743 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 76333450DB for ; Wed, 18 Oct 2023 18:33:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="m3PbLkbC" Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28AE2F7 for ; Wed, 18 Oct 2023 11:33:24 -0700 (PDT) Received: by mail-qk1-x733.google.com with SMTP id af79cd13be357-77897c4ac1fso45629085a.3 for ; Wed, 18 Oct 2023 11:33:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1697654003; x=1698258803; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=9CBGsuv3AIMIXyzwCHP/4s3XBu0GOLw1cw5IcyigcHM=; b=m3PbLkbCAQ7sp5k06/5UCsR/DM+e6SH8Ui4TLsHacHb23aWRpxRzfbMe7KxABoIakP 9h/x3QVuToT2780SmNRiAlvOkmHDkyBCOut3eP7osu1zmm7Hr4rJ2jpW2dvo1nZJWjWy ST/S3Rfq7owDisAL2u4p0FoRnDqZOYCbStHMT83Kr78a/gkq8tUwPAAyuUovzAQHjPhI lXyyr4sUcSQoqgb2vtKFHrPlZj2kK5aEr+nd3w3WzaTKI7B5RejDijJ/r+Fkajy3MJte UjXJ2TJOV9dDhA1eI7g6hS8hRryglpPeZwD7kZ09/ihOcTiUbBGzk9+gXGQKCptddbjc V8IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697654003; x=1698258803; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9CBGsuv3AIMIXyzwCHP/4s3XBu0GOLw1cw5IcyigcHM=; b=RtGWOCAqoz5WUDWJ847xGaia5uRJyGlvIHx2vuRA96prnpNzGBRFLlf+wC5rOxIK5w gqYU++XkYaSBSVU5aC1TPAHh+kRs2y4UXW1eTNrNEqPOeZhsbyiZWvab+tbCKq2lPnew l8bMCqEFRD7Jxm/GRaWI1MSIY+SHAFFtXjNmBwHdcSTWF5sFDLs903xELvKEQ8ym9+Vm zimFzJExlnvm1+Sf8v0D8gBKQi0XykoHrlp66wLomlh79L2YZ3zfViW1JoIB0CU9JNjt 4ZFcL9RbcdBzvnebFA4z/aneyF8fQlXthu/mKa17sC88DdciX479u7i0gg8ezRmuxY/R WevA== X-Gm-Message-State: AOJu0YzqpRqH2PwAJ/LPlVjOD2ufD2SHu1aiXpdQRfY1XTyimxV1Zs/2 nlr8GHANr7b1buNH7O/YlUKnhBLJUhpdpGBCjot4Xg== X-Google-Smtp-Source: AGHT+IHDhKDwbarIXzF8MjmcA4UOtf0wkSDKhBCRV7gO7nATDcD+QuT/vq/2gHdoVW6hkUr1+67qXA== X-Received: by 2002:a05:620a:1a0a:b0:775:681d:dc06 with SMTP id bk10-20020a05620a1a0a00b00775681ddc06mr7099704qkb.63.1697654003022; Wed, 18 Oct 2023 11:33:23 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id j28-20020a05620a147c00b0077438383a07sm151162qkl.80.2023.10.18.11.33.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 11:33:22 -0700 (PDT) Date: Wed, 18 Oct 2023 14:33:21 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , "Eric W. Biederman" , Jeff King , Junio C Hamano , Patrick Steinhardt Subject: [PATCH v4 16/17] commit-graph: reuse existing Bloom filters where possible Message-ID: <6a12e39e7f5e2d68a23811a98276740646874662.1697653929.git.me@ttaylorr.com> 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: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net In 9e4df4da07 (commit-graph: new filter ver. that fixes murmur3, 2023-08-01), a bug was described where it's possible for Git to produce non-murmur3 hashes when the platform's "char" type is signed, and there are paths with characters whose highest bit is set (i.e. all characters >= 0x80). That patch allows the caller to control which version of Bloom filters are read and written. However, even on platforms with a signed "char" type, it is possible to reuse existing Bloom filters if and only if there are no changed paths in any commit's first parent tree-diff whose characters have their highest bit set. When this is the case, we can reuse the existing filter without having to compute a new one. This is done by marking trees which are known to have (or not have) any such paths. When a commit's root tree is verified to not have any such paths, we mark it as such and declare that the commit's Bloom filter is reusable. Note that this heuristic only goes in one direction. If neither a commit nor its first parent have any paths in their trees with non-ASCII characters, then we know for certain that a path with non-ASCII characters will not appear in a tree-diff against that commit's first parent. The reverse isn't necessarily true: just because the tree-diff doesn't contain any such paths does not imply that no such paths exist in either tree. So we end up recomputing some Bloom filters that we don't strictly have to (i.e. their bits are the same no matter which version of murmur3 we use). But culling these out is impossible, since we'd have to perform the full tree-diff, which is the same effort as computing the Bloom filter from scratch. But because we can cache our results in each tree's flag bits, we can often avoid recomputing many filters, thereby reducing the time it takes to run $ git commit-graph write --changed-paths --reachable when upgrading from v1 to v2 Bloom filters. To benchmark this, let's generate a commit-graph in linux.git with v1 changed-paths in generation order[^1]: $ git clone git@github.com:torvalds/linux.git $ cd linux $ git commit-graph write --reachable --changed-paths $ graph=".git/objects/info/commit-graph" $ mv $graph{,.bak} Then let's time how long it takes to go from v1 to v2 filters (with and without the upgrade path enabled), resetting the state of the commit-graph each time: $ git config commitGraph.changedPathsVersion 2 $ hyperfine -p 'cp -f $graph.bak $graph' -L v 0,1 \ 'GIT_TEST_UPGRADE_BLOOM_FILTERS={v} git.compile commit-graph write --reachable --changed-paths' On linux.git (where there aren't any non-ASCII paths), the timings indicate that this patch represents a speed-up over recomputing all Bloom filters from scratch: Benchmark 1: GIT_TEST_UPGRADE_BLOOM_FILTERS=0 git.compile commit-graph write --reachable --changed-paths Time (mean ± σ): 124.873 s ± 0.316 s [User: 124.081 s, System: 0.643 s] Range (min … max): 124.621 s … 125.227 s 3 runs Benchmark 2: GIT_TEST_UPGRADE_BLOOM_FILTERS=1 git.compile commit-graph write --reachable --changed-paths Time (mean ± σ): 79.271 s ± 0.163 s [User: 74.611 s, System: 4.521 s] Range (min … max): 79.112 s … 79.437 s 3 runs Summary 'GIT_TEST_UPGRADE_BLOOM_FILTERS=1 git.compile commit-graph write --reachable --changed-paths' ran 1.58 ± 0.01 times faster than 'GIT_TEST_UPGRADE_BLOOM_FILTERS=0 git.compile commit-graph write --reachable --changed-paths' On git.git, we do have some non-ASCII paths, giving us a more modest improvement from 4.163 seconds to 3.348 seconds, for a 1.24x speed-up. On my machine, the stats for git.git are: - 8,285 Bloom filters computed from scratch - 10 Bloom filters generated as empty - 4 Bloom filters generated as truncated due to too many changed paths - 65,114 Bloom filters were reused when transitioning from v1 to v2. [^1]: Note that this is is important, since `--stdin-packs` or `--stdin-commits` orders commits in the commit-graph by their pack position (with `--stdin-packs`) or in the raw input (with `--stdin-commits`). Since we compute Bloom filters in the same order that commits appear in the graph, we must see a commit's (first) parent before we process the commit itself. This is only guaranteed to happen when sorting commits by their generation number. Signed-off-by: Taylor Blau --- bloom.c | 90 ++++++++++++++++++++++++++++++++++++++++++-- bloom.h | 1 + commit-graph.c | 5 +++ object.h | 1 + t/t4216-log-bloom.sh | 35 ++++++++++++++++- 5 files changed, 128 insertions(+), 4 deletions(-) diff --git a/bloom.c b/bloom.c index 739fa093ba..24dd874e46 100644 --- a/bloom.c +++ b/bloom.c @@ -7,6 +7,9 @@ #include "commit-graph.h" #include "commit.h" #include "commit-slab.h" +#include "tree.h" +#include "tree-walk.h" +#include "config.h" define_commit_slab(bloom_filter_slab, struct bloom_filter); @@ -250,6 +253,73 @@ static void init_truncated_large_filter(struct bloom_filter *filter, filter->version = version; } +#define VISITED (1u<<21) +#define HIGH_BITS (1u<<22) + +static int has_entries_with_high_bit(struct repository *r, struct tree *t) +{ + if (parse_tree(t)) + return 1; + + if (!(t->object.flags & VISITED)) { + struct tree_desc desc; + struct name_entry entry; + + init_tree_desc(&desc, t->buffer, t->size); + while (tree_entry(&desc, &entry)) { + size_t i; + for (i = 0; i < entry.pathlen; i++) { + if (entry.path[i] & 0x80) { + t->object.flags |= HIGH_BITS; + goto done; + } + } + + if (S_ISDIR(entry.mode)) { + struct tree *sub = lookup_tree(r, &entry.oid); + if (sub && has_entries_with_high_bit(r, sub)) { + t->object.flags |= HIGH_BITS; + goto done; + } + } + + } + +done: + t->object.flags |= VISITED; + } + + return !!(t->object.flags & HIGH_BITS); +} + +static int commit_tree_has_high_bit_paths(struct repository *r, + struct commit *c) +{ + struct tree *t; + if (repo_parse_commit(r, c)) + return 1; + t = repo_get_commit_tree(r, c); + if (!t) + return 1; + return has_entries_with_high_bit(r, t); +} + +static struct bloom_filter *upgrade_filter(struct repository *r, struct commit *c, + struct bloom_filter *filter, + int hash_version) +{ + struct commit_list *p = c->parents; + if (commit_tree_has_high_bit_paths(r, c)) + return NULL; + + if (p && commit_tree_has_high_bit_paths(r, p->item)) + return NULL; + + filter->version = hash_version; + + return filter; +} + struct bloom_filter *get_bloom_filter(struct repository *r, struct commit *c) { struct bloom_filter *filter; @@ -292,9 +362,23 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r, filter, graph_pos); } - if ((filter->data && filter->len) && - (!settings || settings->hash_version == filter->version)) - return filter; + if (filter->data && filter->len) { + struct bloom_filter *upgrade; + if (!settings || settings->hash_version == filter->version) + return filter; + + /* version mismatch, see if we can upgrade */ + if (compute_if_not_present && + git_env_bool("GIT_TEST_UPGRADE_BLOOM_FILTERS", 1)) { + upgrade = upgrade_filter(r, c, filter, + settings->hash_version); + if (upgrade) { + if (computed) + *computed |= BLOOM_UPGRADED; + return upgrade; + } + } + } if (!compute_if_not_present) return NULL; diff --git a/bloom.h b/bloom.h index bfe389e29c..e3a9b68905 100644 --- a/bloom.h +++ b/bloom.h @@ -102,6 +102,7 @@ enum bloom_filter_computed { BLOOM_COMPUTED = (1 << 1), BLOOM_TRUNC_LARGE = (1 << 2), BLOOM_TRUNC_EMPTY = (1 << 3), + BLOOM_UPGRADED = (1 << 4), }; struct bloom_filter *get_or_compute_bloom_filter(struct repository *r, diff --git a/commit-graph.c b/commit-graph.c index b70d57b085..50dcbb4d9b 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -1102,6 +1102,7 @@ struct write_commit_graph_context { int count_bloom_filter_not_computed; int count_bloom_filter_trunc_empty; int count_bloom_filter_trunc_large; + int count_bloom_filter_upgraded; }; static int write_graph_chunk_fanout(struct hashfile *f, @@ -1709,6 +1710,8 @@ static void trace2_bloom_filter_write_statistics(struct write_commit_graph_conte ctx->count_bloom_filter_trunc_empty); trace2_data_intmax("commit-graph", ctx->r, "filter-trunc-large", ctx->count_bloom_filter_trunc_large); + trace2_data_intmax("commit-graph", ctx->r, "filter-upgraded", + ctx->count_bloom_filter_upgraded); } static void compute_bloom_filters(struct write_commit_graph_context *ctx) @@ -1750,6 +1753,8 @@ static void compute_bloom_filters(struct write_commit_graph_context *ctx) ctx->count_bloom_filter_trunc_empty++; if (computed & BLOOM_TRUNC_LARGE) ctx->count_bloom_filter_trunc_large++; + } else if (computed & BLOOM_UPGRADED) { + ctx->count_bloom_filter_upgraded++; } else if (computed & BLOOM_NOT_COMPUTED) ctx->count_bloom_filter_not_computed++; ctx->total_bloom_filter_data_size += filter diff --git a/object.h b/object.h index db25714b4e..2e5e08725f 100644 --- a/object.h +++ b/object.h @@ -75,6 +75,7 @@ void object_array_init(struct object_array *array); * commit-reach.c: 16-----19 * sha1-name.c: 20 * list-objects-filter.c: 21 + * bloom.c: 2122 * builtin/fsck.c: 0--3 * builtin/gc.c: 0 * builtin/index-pack.c: 2021 diff --git a/t/t4216-log-bloom.sh b/t/t4216-log-bloom.sh index 68066b7928..569f2b6f8b 100755 --- a/t/t4216-log-bloom.sh +++ b/t/t4216-log-bloom.sh @@ -221,6 +221,10 @@ test_filter_trunc_large () { grep "\"key\":\"filter-trunc-large\",\"value\":\"$1\"" $2 } +test_filter_upgraded () { + grep "\"key\":\"filter-upgraded\",\"value\":\"$1\"" $2 +} + test_expect_success 'correctly report changes over limit' ' git init limits && ( @@ -628,7 +632,13 @@ test_expect_success 'when writing another commit graph, preserve existing versio test_expect_success 'when writing commit graph, do not reuse changed-path of another version' ' git init doublewrite && test_commit -C doublewrite c "$CENT" && + git -C doublewrite config --add commitgraph.changedPathsVersion 1 && + GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \ + git -C doublewrite commit-graph write --reachable --changed-paths && + test_filter_computed 1 trace2.txt && + test_filter_upgraded 0 trace2.txt && + git -C doublewrite commit-graph write --reachable --changed-paths && for v in -2 3 do @@ -639,8 +649,13 @@ test_expect_success 'when writing commit graph, do not reuse changed-path of ano EOF test_cmp expect err || return 1 done && + git -C doublewrite config --add commitgraph.changedPathsVersion 2 && - git -C doublewrite commit-graph write --reachable --changed-paths && + GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \ + git -C doublewrite commit-graph write --reachable --changed-paths && + test_filter_computed 1 trace2.txt && + test_filter_upgraded 0 trace2.txt && + ( cd doublewrite && echo "c01f" >expect && @@ -649,4 +664,22 @@ test_expect_success 'when writing commit graph, do not reuse changed-path of ano ) ' +test_expect_success 'when writing commit graph, reuse changed-path of another version where possible' ' + git init upgrade && + + test_commit -C upgrade base no-high-bits && + + git -C upgrade config --add commitgraph.changedPathsVersion 1 && + GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \ + git -C upgrade commit-graph write --reachable --changed-paths && + test_filter_computed 1 trace2.txt && + test_filter_upgraded 0 trace2.txt && + + git -C upgrade config --add commitgraph.changedPathsVersion 2 && + GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \ + git -C upgrade commit-graph write --reachable --changed-paths && + test_filter_computed 0 trace2.txt && + test_filter_upgraded 1 trace2.txt +' + test_done From patchwork Wed Oct 18 18:33:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13427744 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 E69F947353 for ; Wed, 18 Oct 2023 18:33:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="mLVd59p5" Received: from mail-qv1-xf2a.google.com (mail-qv1-xf2a.google.com [IPv6:2607:f8b0:4864:20::f2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D34C11F for ; Wed, 18 Oct 2023 11:33:27 -0700 (PDT) Received: by mail-qv1-xf2a.google.com with SMTP id 6a1803df08f44-66d0169cf43so45636306d6.3 for ; Wed, 18 Oct 2023 11:33:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1697654006; x=1698258806; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=59wqNeBCli9n+XHZyvKFIhu32Ca1EgtEbPwN27M3Has=; b=mLVd59p5zX639ULlrp5Vt2SCKpeR4UiP/NCq3mQjlbVzMRrqBCIbKNovTH1s2F20Wm qokTlt031/mdN/mOMtJE16uA7NWkrMT90DIJlTYNT4YT4Ld3Vzz4JUCEKPXGsAqzAJOo IjgMqlRKg32j/HiDSNIF7ffyMgTd4aIoydx39jCezerusWT3FQGCp7y4MhXgqJ4k/pxJ 8IHCW7gpj9YlsHyc7tZ0jpssn9VkrVcSOqiHeMhCm2+g6KfjHzYIcaCvAN7+TrD8jrkT Ot73n7ee07R8mtZDis0M+g4MZTmACliN/P75hUI2ORfc4xszbt2FNgCyuSBg+VoSTC2Z 4S1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697654006; x=1698258806; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=59wqNeBCli9n+XHZyvKFIhu32Ca1EgtEbPwN27M3Has=; b=EskgA6auAPg1DiAOY9apurw0Cb9TQb/+GZLe3hzBG/yR77HxI8Cx3AIpbrxmoaE6ut VEYgA2Vxi38FIovS5m8zLo5UhjLIbk7IbRclsBu9GoxUiRYxLwpNUgKBJ2109SB8dkTg ZjYt/CBTM/B6P93yMCGS2ZMhI47cRnj8fkSw3fmvPoQYk8137Ot182ss/zAAgBxrmEBc LRisw+Mpa8XGP++XJRwgGlOT3boQCZL8N0GR/b7/faPEHeVc8fBHTZ25XJC+FVcXelie SJdaZiZx7WUnMqmoaBr2OQYssV+aHvzCi6692TNIOLkwyzA781yDnQ86g++N6eAnFkF2 TiWQ== X-Gm-Message-State: AOJu0YzEbDU0NHR+LuLmGUA6uXEWcT2OK0EgdMULIExPcIJLKVW4Yxsr SspC6jCMo5jmFGmkQoH9a3XgYDhh1+3MNqXGuYYARQ== X-Google-Smtp-Source: AGHT+IHZBAPelULAadeZ+tgfK1za1Fag2h3miKMji5J7+ASDhUE9S24I3ZxuR3Mg/wcRp5duviMJ+w== X-Received: by 2002:ad4:5fce:0:b0:66d:12a3:ec81 with SMTP id jq14-20020ad45fce000000b0066d12a3ec81mr70970qvb.62.1697654006089; Wed, 18 Oct 2023 11:33:26 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id w11-20020a0562140b2b00b0066cf09f5ba9sm146712qvj.131.2023.10.18.11.33.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 11:33:25 -0700 (PDT) Date: Wed, 18 Oct 2023 14:33:24 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , "Eric W. Biederman" , Jeff King , Junio C Hamano , Patrick Steinhardt Subject: [PATCH v4 17/17] bloom: introduce `deinit_bloom_filters()` Message-ID: <8942f205c84d204376033a931b1ba8a575181f1f.1697653929.git.me@ttaylorr.com> 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: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net After we are done using Bloom filters, we do not currently clean up any memory allocated by the commit slab used to store those filters in the first place. Besides the bloom_filter structures themselves, there is mostly nothing to free() in the first place, since in the read-only path all Bloom filter's `data` members point to a memory mapped region in the commit-graph file itself. But when generating Bloom filters from scratch (or initializing truncated filters) we allocate additional memory to store the filter's data. Keep track of when we need to free() this additional chunk of memory by using an extra pointer `to_free`. Most of the time this will be NULL (indicating that we are representing an existing Bloom filter stored in a memory mapped region). When it is non-NULL, free it before discarding the Bloom filters slab. Suggested-by: Jonathan Tan Signed-off-by: Taylor Blau Signed-off-by: Junio C Hamano Signed-off-by: Taylor Blau --- bloom.c | 16 +++++++++++++++- bloom.h | 3 +++ commit-graph.c | 4 ++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/bloom.c b/bloom.c index 24dd874e46..ff131893cd 100644 --- a/bloom.c +++ b/bloom.c @@ -59,6 +59,7 @@ int load_bloom_filter_from_graph(struct commit_graph *g, sizeof(unsigned char) * start_index + BLOOMDATA_CHUNK_HEADER_SIZE); filter->version = g->bloom_filter_settings->hash_version; + filter->to_free = NULL; return 1; } @@ -231,6 +232,18 @@ void init_bloom_filters(void) init_bloom_filter_slab(&bloom_filters); } +static void free_one_bloom_filter(struct bloom_filter *filter) +{ + if (!filter) + return; + free(filter->to_free); +} + +void deinit_bloom_filters(void) +{ + deep_clear_bloom_filter_slab(&bloom_filters, free_one_bloom_filter); +} + static int pathmap_cmp(const void *hashmap_cmp_fn_data UNUSED, const struct hashmap_entry *eptr, const struct hashmap_entry *entry_or_key, @@ -247,7 +260,7 @@ static int pathmap_cmp(const void *hashmap_cmp_fn_data UNUSED, static void init_truncated_large_filter(struct bloom_filter *filter, int version) { - filter->data = xmalloc(1); + filter->data = filter->to_free = xmalloc(1); filter->data[0] = 0xFF; filter->len = 1; filter->version = version; @@ -449,6 +462,7 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r, filter->len = 1; } CALLOC_ARRAY(filter->data, filter->len); + filter->to_free = filter->data; hashmap_for_each_entry(&pathmap, &iter, e, entry) { struct bloom_key key; diff --git a/bloom.h b/bloom.h index e3a9b68905..d20e64bfbb 100644 --- a/bloom.h +++ b/bloom.h @@ -56,6 +56,8 @@ struct bloom_filter { unsigned char *data; size_t len; int version; + + void *to_free; }; /* @@ -96,6 +98,7 @@ void add_key_to_filter(const struct bloom_key *key, const struct bloom_filter_settings *settings); void init_bloom_filters(void); +void deinit_bloom_filters(void); enum bloom_filter_computed { BLOOM_NOT_COMPUTED = (1 << 0), diff --git a/commit-graph.c b/commit-graph.c index 50dcbb4d9b..60fa64d956 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -779,6 +779,7 @@ struct bloom_filter_settings *get_bloom_filter_settings(struct repository *r) void close_commit_graph(struct raw_object_store *o) { clear_commit_graph_data_slab(&commit_graph_data_slab); + deinit_bloom_filters(); free_commit_graph(o->commit_graph); o->commit_graph = NULL; } @@ -2583,6 +2584,9 @@ int write_commit_graph(struct object_directory *odb, res = write_commit_graph_file(ctx); + if (ctx->changed_paths) + deinit_bloom_filters(); + if (ctx->split) mark_commit_graphs(ctx);