From patchwork Wed Jan 31 22:52:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13540087 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A4E73A278 for ; Wed, 31 Jan 2024 22:52:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741544; cv=none; b=Eemvp0BDbZIk6HlMcCKBvYQTxK0GFD03Eo/12Xc/xVRwRbwSPIZEGXJBNWDSW1WwkLSNpGJ1GpcWX1QGthfMj2viP/YquJoTCZzQH81s0lV3mSI/JOoCxbeVPv19yYSwlFVa8yuB5pZPkgr55nrFELkoc0l3eVA6mvhIamMN9Wo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741544; c=relaxed/simple; bh=wF/EljokfllV1dedwfgR+L1vbdImHtnhGOWcacTY1B8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mPrwIKebyaRHqw/1jBgaDCi3T309z9ZT5wdoyxFJn8IfckFtWBinyNa9BaZSLfdqn6iJM8LYGvNtdx6NGH9ytnj5upiT1q6ukcRL1knM9AtVSEMUnZ/wdFf9bnnJ3A011r9HjNnaAUVafNYpDOfoakvmxN56iKAojlFq1KmEnfk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com; spf=none smtp.mailfrom=ttaylorr.com; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b=UMa9QGvf; arc=none smtp.client-ip=209.85.222.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ttaylorr.com 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="UMa9QGvf" Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-7838af983c1so25733285a.3 for ; Wed, 31 Jan 2024 14:52:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1706741541; x=1707346341; 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=YGwE8+t5LRl8gqzZPTWr8hA4p69o91574PxxOFbiavs=; b=UMa9QGvfQ8bpkl+jRMgemLT/YyA5exCiHSGGeeB1NbDUCXXntNE9xqc8ksolqZ41nW 5utDiVGeI8Luggh4oa2bCU348TwBpvlz9sOpci5DT6rFSw+skDam/eirZGT29NwxaEwU IhWy8NZudIWcCrpp7IJbWiwijZjKl4QqlcwLEeywxI4Tu5kdJiYuX9o8/LkXTCEIS//c AHTIfi5TBYjsfLts2uFnP1bHz4O9ixmdE9qRfWfx9ro0LWuTY+38waiNA5miaRdlQCGI iszQMs84N8EgZDgez/V4UdNbeRgZHDD+I9EYryysCoT3Bh0rPkQsg9L/o+llsHkpOl7/ nQmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706741541; x=1707346341; 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=YGwE8+t5LRl8gqzZPTWr8hA4p69o91574PxxOFbiavs=; b=adwkVuJOES+ehRf7z9eiONHHwHpqeemXN6Bc4anmrhuHrQS5Q5jvZWLP0KpQT0haeL s3i2SnhNzzUR80yQhi4h8YJ/wDqMFdOfz8BKUZ18wtK4Hs4IdrjUwNIC50+TT2bHizcQ ecn0LrnAbntlQdaB0GkQwL2ZFQjPRy/KXH5lzQxjoz6+xfavbnDeA1836435961jlwe9 2/dnHMCMAY4xC2uoLLmldmTtdakN5LxcvOkfZ1zCcn8osljZFGeJUrw0LKpSBz8rrgn9 CCsHJqWryZlHMiON3W40AJdGnuo1ULZYQVb8cUXLqZhfXzHAUtQ0xTHKMCYaJ9ize+q+ m6tw== X-Gm-Message-State: AOJu0Yyhc6uIi+LRZiRl4E6bkr03fVFutbOVU7dFWbeewG3gAUSplCDZ vp7dncNQlpq/SmA2nLu1rLT3PlaiAzUdQ8u79tSbV052ZT4qEjJ9MVYdypsbu4EtQ6UKg10C5E7 ahb0= X-Google-Smtp-Source: AGHT+IG9v3hUdbVuFQe3qf5swz6uAph33xwE/e/47GN3QvrSQibpwa5/g+LEWiiuAJObdKCOgkKCXA== X-Received: by 2002:ae9:e913:0:b0:783:81b4:c156 with SMTP id x19-20020ae9e913000000b0078381b4c156mr840907qkf.48.1706741541644; Wed, 31 Jan 2024 14:52:21 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id a27-20020a05620a02fb00b00783f388ff13sm3756714qko.56.2024.01.31.14.52.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 14:52:21 -0800 (PST) Date: Wed, 31 Jan 2024 17:52:20 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Jonathan Tan , SZEDER =?utf-8?b?R8OhYm9y?= Subject: [PATCH v6 01/16] t/t4216-log-bloom.sh: harden `test_bloom_filters_not_used()` Message-ID: <9df34a2f4f588c3ce998bbcd51fc83b93726787e.1706741516.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: 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 the `commitGraph.changedPathVersion` introduced later in this series 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 2ba0324a69..b7baf49d62 100755 --- a/t/t4216-log-bloom.sh +++ b/t/t4216-log-bloom.sh @@ -82,7 +82,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 Jan 31 22:52:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13540088 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B7933A8D8 for ; Wed, 31 Jan 2024 22:52:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741548; cv=none; b=jLFCd7sMeW1fbHNTxzn/QXLA8KaHiGCcj9EnM2j9VUI3bXzLpMBCul3lRP1dytMxCfRmBUxakLWy67TOTlWswR/jCcYbzIuvcj/KHNUkWVRf1e/jv7gOmCrGdwlepSMgUET1SkCVUqcnjYjuzVMdSVw9FGdphrGB/KR2RC3NFQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741548; c=relaxed/simple; bh=pUd/X8NFfCFpEiWOyQIbhiv2bPzxlaFqxa3ThbssICg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tyobfsjZjhtlkmOSp72MVhnhXIVLT3Q11hlQHsNJIt76YYX31Bz4BX2Ckqs3gBJVD1wBDvdBZvaBxBel2wMzufg7xvVnIuXBrZAMgNk/bXeZ/2dKGTNnstMONUHMnD24skc2iAPtbEWwXpVUW6ZCpEcFjA/40zpNGJMYEYUTuuU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com; spf=none smtp.mailfrom=ttaylorr.com; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b=ZKlgRm/t; arc=none smtp.client-ip=209.85.222.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ttaylorr.com 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="ZKlgRm/t" Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-783e22a16d4so104942885a.0 for ; Wed, 31 Jan 2024 14:52:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1706741544; x=1707346344; 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=9BniYaMPwayL90qzNYpZNYvso3bcVW7OgFrLipKNQrk=; b=ZKlgRm/t7+OhIFmbTK/fxIzHnnSmQ/ntArgtrDmtHGS5Dmr3toNPbM42UQ96mMhh+i 4o4mGiNxwjCzE650N/wmdap3COBvTwJyH6f863XhPfs5Wdic5Dzd7gqTCPbnIWpYlNBv 7DYkgZrGAZahgGoTtEZI12wjpQWtvXV2Q/THobqkBd6mcciiAfHl1HJ9nsvhWFvPypYm dZ9ro+m83+FPymdX8gjUbJbwlEXfu2aGEWimMyCFwugPVUqRi9ljNuMZErD6AgrvFAom D4OWDtntGy0LReaIdw90m/MGU68RvmfmE7LF3+Yu4OL3bSgWEtFOO369YWZe3VcxvVwn qOtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706741544; x=1707346344; 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=9BniYaMPwayL90qzNYpZNYvso3bcVW7OgFrLipKNQrk=; b=XfzDb6ymTGCakeKko0Z6uxJbmwgbQzo2ZGA7zRSPEUxTETnKY8jUOQDWeNIJWDFwNG AWo8wy6LVFYk8YJxw/Y+i0q2BGT0Z5zafCiUrRdkqPfCE1RLAedCT/iysclsd15/8cKD 9P6F9QiAeIV1+xo5Al76Q0cFHWnBg8zmt2k6MFK2WAGZB8owH7WWFuNA2XETz5ajibWF XRFwkaY4Htgut8SOkTVSeeJpJ+kId0ajWX6zFY/0RDTjlepimlZWkfoby4Fwg2KJnqHk k+TMMfh5Kh6sQXUw/66c3oL6ECe6Gmns4t7dtgLyRBHEBggDoSPUBadOFvjGu2LZNlRe W2gA== X-Gm-Message-State: AOJu0Yy9FOCSCzs71x7bo240w/4kq+i2FtnIa2Jw/pKQPRkF5/7nW7cf KXiCMt89X3EyCixKRRSWAdBD0d8jjiIOmj0zF52DtCsH1BrRnaJa2C1oqBQd7TnLshJWp74e35h cuYw= X-Google-Smtp-Source: AGHT+IFMl6yY88LUuPCOhvRd1MVm/inobZtgkncSMLrV53II/ySJ6SGfwnwaXQVX4f9CWcU364MWew== X-Received: by 2002:a0c:f10c:0:b0:68c:4475:2f2a with SMTP id i12-20020a0cf10c000000b0068c44752f2amr7047856qvl.18.1706741544646; Wed, 31 Jan 2024 14:52:24 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id eo10-20020ad4594a000000b0068179afede6sm3150343qvb.100.2024.01.31.14.52.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 14:52:24 -0800 (PST) Date: Wed, 31 Jan 2024 17:52:23 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Jonathan Tan , SZEDER =?utf-8?b?R8OhYm9y?= Subject: [PATCH v6 02/16] revision.c: consult Bloom filters for root commits Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The 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 2424c9bd67..0e6f7d02b6 100644 --- a/revision.c +++ b/revision.c @@ -833,17 +833,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 && 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; } @@ -881,7 +892,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; @@ -977,7 +988,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, 0)) commit->object.flags |= TREESAME; return; } @@ -1058,7 +1076,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 b7baf49d62..cc6ebc8140 100755 --- a/t/t4216-log-bloom.sh +++ b/t/t4216-log-bloom.sh @@ -88,7 +88,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}" @@ -175,7 +179,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 Jan 31 22:52:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13540089 Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3AAA3A8E0 for ; Wed, 31 Jan 2024 22:52:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741550; cv=none; b=Fb7Jf1H4wOseRH7yLpXux7siRTsPfAXdFUjC+gAajlJmfZgFMw01muoejwvCUjez+G33JkLQYwBO9ZHZggVRftpHR1no88FrH8f+C7LAdsJhOMbTkw3zYNEuYlbfjdfd1UuAiIdLsKhmOR3L0S1Wlnf8XZ6JKKcd9YksTsXsTq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741550; c=relaxed/simple; bh=Tx53PZbRBDMeIHiec7/7WqFNf3mZcEiYy9/Dp0+afvA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Yq6qJdcGumfSfHXVDTls14+aiBBG40dH17jXHg/rWGfLX43XEBgAs/004Rgx34erHiS3vAD7QzRkP8mnwbjIBW6O3Y8a6kZ7QmlGkqiRYQlMe1PmgUluSLDQ4xmx8mImylN0jfHz9eVosL5TN27hjnB/aQZkQshJkCTtkeNaRYM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com; spf=none smtp.mailfrom=ttaylorr.com; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b=F+YQvscz; arc=none smtp.client-ip=209.85.219.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ttaylorr.com 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="F+YQvscz" Received: by mail-yb1-f174.google.com with SMTP id 3f1490d57ef6-dc6b7df1169so230646276.0 for ; Wed, 31 Jan 2024 14:52:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1706741547; x=1707346347; 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=L7JmEiC/QvMRZuCY1vDkFxL1XU/ro565ss6SRiED2gI=; b=F+YQvsczA8RHKb8moo/gKa8NSePwBc7lx1BggvgF4l8OCeSwc3ylA4E6bHgTQLjm5/ 4SO3lPOrxsR65ol3hAB/MNByBLR6G56H8INTMq69W6ao+ZTly+2MxxvMX6PVZreDChzB XNxqFAfzZNcNUHf1qUL1vnTwh7FpcWxWLhTWz9zMItpKAi0hknA1xT+Yc76HAl+Rlccm n+di1gSGeou/k6J14FRy9e+iRzdQKejwRNvwSFEH9SiA0vUC/EA6Ob1y+ub6wLOLnTjU pgdnoDGP6qRBgE/EwSIfDDzZ88Ln58N7lVwMHchXwTz3sWWB/CDA3ITz5TWNyc6dcAlb mS7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706741547; x=1707346347; 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=L7JmEiC/QvMRZuCY1vDkFxL1XU/ro565ss6SRiED2gI=; b=RR0rQQGAp8ZafZMzJHNVcSBuZ6DWeNRjmfuppykdryG+aW/1f/hovIPUtznWdxf1CJ advTmeGGy9jihxWXO3qL68EStohkpOeyW792X4vOXI9J37h4hz0Tjl9U6dDhsURKdXY8 gzfktcnhJB7ICkBRogR0ZZyI4X1drd4233EGovYrq46P8D3fFpE7dAv4HakdEWK/oyWu js47H9REKCq8Aqp8Lqgz7TgG8wvhQi2cxn8Z6yukzH3udnpn8D7kbW0S2mqVTOYPHxXr YxYF9HCqodkEDkfgIfbTF5SU52SUfhTsc+l5CKmFiXSxnFmiAzPoNaBGBg/MQv58SSYD NDpA== X-Gm-Message-State: AOJu0Yy+01nH2ELutbcDmcNIn8eQokBkvM62QzhlnZ/8YDpHZqxCxjV7 tRDkppYN6wuMZPBmF7tnzWaTyGl1jpQsP4OiH9TS0/Zlga9tCgU0n2bhRkm5W8UO7URRfq7wFiJ Kfn8= X-Google-Smtp-Source: AGHT+IHHa+6VjiMD15sIezGXVizIv9wxyx0fSZ2ZZcLZQs2SYhu5+VZ5Htaux/aadWV5WOvijp7uxw== X-Received: by 2002:a25:b1a4:0:b0:dc6:8b4:7388 with SMTP id h36-20020a25b1a4000000b00dc608b47388mr490938ybj.35.1706741547367; Wed, 31 Jan 2024 14:52:27 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id ow11-20020a0562143f8b00b0068c41c0d346sm1207209qvb.27.2024.01.31.14.52.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 14:52:27 -0800 (PST) Date: Wed, 31 Jan 2024 17:52:26 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Jonathan Tan , SZEDER =?utf-8?b?R8OhYm9y?= Subject: [PATCH v6 03/16] commit-graph: ensure Bloom filters are read with consistent settings Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The 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 | 65 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/commit-graph.c b/commit-graph.c index 45417d7412..216cf03da1 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -543,6 +543,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, @@ -666,6 +690,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 cc6ebc8140..64737b6ee9 100755 --- a/t/t4216-log-bloom.sh +++ b/t/t4216-log-bloom.sh @@ -421,8 +421,71 @@ 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 Bloom filters with incompatible settings 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 +' + corrupt_graph () { - graph=.git/objects/info/commit-graph && test_when_finished "rm -rf $graph" && git commit-graph write --reachable --changed-paths && corrupt_chunk_file $graph "$@" From patchwork Wed Jan 31 22:52:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13540090 Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BD3C3A8E4 for ; Wed, 31 Jan 2024 22:52:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741553; cv=none; b=KBUppihhowpWQIVQPYjbO4/xDu1Pniyz1t0LPspuz1t/nHbuBFZE0MuGXk3UelTWnV7l53OF0S7J5SpY2lJ5qTnEfieY5TNiazsB7+pW4B4qGiRdM68XSJvoVQakmZ/TRhxgB9nga8B73jDOUT26d4IB/XvxaOFWXF/7SpVcgjk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741553; c=relaxed/simple; bh=6fayB0pzbqY0SSuq1+LMbdKYgnZFeQDprowmSXeJY0k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tiDRndaFAw/cCcLUNF8HmM6ohImVv4/AULVw798JmcS9VxWttYBOEMop6cAuJ455+F4ldS+9fMvk0RtAE00mdOv5KwobKJUaZQFwMAppfbY0vwwtfO9NOpDjjzaIHB+ust0HOoPnm1VBaWHg4TgldhLxQHq6UZ11ypfHg/XmJ5o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com; spf=none smtp.mailfrom=ttaylorr.com; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b=u/Q+7ZEu; arc=none smtp.client-ip=209.85.167.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ttaylorr.com 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="u/Q+7ZEu" Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3bbbc6b4ed1so216117b6e.2 for ; Wed, 31 Jan 2024 14:52:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1706741550; x=1707346350; 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=0er1k/e891E7VZYgtccUhj/xF/eCgQLRnf6QB/xQh2s=; b=u/Q+7ZEuvqPqVxMYKfIWDmc22jp06rrhfhN99M5S6/6xXsnDue8XBuuj7A9x3JxgYO GdLy3r7kPdA9NQ/UYzDS1PaU4g2j6fluE8J1V6+X+6ZV7wWSemovirFvEfH7bh4550qw AFKxhsRwds+RYhaW6Cey9IDOKxJqw8B21MfF1hK5GxttJ2uBR+sRjizh2gJ9PdKgVLbv I+X6dsUII+aKQIZs4gj/zeMqkoV20NhKJNdTJRVaYIJT1c+KJYvqSkcviU0yzwnRPnLb TTrSTBFC07q/dlkqd/yR4sRwUYQ3Lsq5pwAPHLu5RvTmWU7kfrd1EBio130Ab+hkEvRn E+Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706741550; x=1707346350; 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=0er1k/e891E7VZYgtccUhj/xF/eCgQLRnf6QB/xQh2s=; b=WHgoCYTW2/z914CIzrnDXylOq6wAS8Vf214JQWP32qXgPOT/2fjjNkJy7gtH09m4ZK Q2JAUj3OKbknU8DJ42p28nx93pLOfMMvcuvIas9GLfSCVTtZzxazBnymRnp4cC/d1aJq 4OwnQE+9dfqdzWsoTaFxslvQKXGBAUhfGOuaeZ+Fcsk/3qCebSzwUJIY0FX0UPsS2CgJ JeaPSlnYZ2/BuiJWld5KhhB2a/z3gmx05qQjTrYSIgODLUiQ5Ux1gk9oR4fDNNdXdEov XMhlhhTNUTfnUKn44P/hFbld4N2klWiMNcCMaJ+yggsmRkViMwpAluK5BahZkiaYNCJR nLDQ== X-Gm-Message-State: AOJu0YxP9QE0cOAHZ+v6WZC4Y9ZpkG2DOEjjVCuWP+RUm5AOUCMD0sbd fXTdESD3rN4t8dxVFZHTAGvL9Wcw1GETMEbrAySxoyDJsOvX3+9D/f3dXj1AKFKfXouxeGCx+lJ 2SLg= X-Google-Smtp-Source: AGHT+IH9Mp7uasqrHWKJ+tDD71BNBD9C4WOfl1lGKQplzPFJbsDKYM8Yjv7+8TFH/F8PBIcYLWHSUg== X-Received: by 2002:a05:6808:114c:b0:3bf:1a8c:75b3 with SMTP id u12-20020a056808114c00b003bf1a8c75b3mr443117oiu.26.1706741550083; Wed, 31 Jan 2024 14:52:30 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id c19-20020a37e113000000b00783fb14c67bsm3192563qkm.48.2024.01.31.14.52.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 14:52:29 -0800 (PST) Date: Wed, 31 Jan 2024 17:52:29 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Jonathan Tan , SZEDER =?utf-8?b?R8OhYm9y?= Subject: [PATCH v6 04/16] gitformat-commit-graph: describe version 2 of BDAT Message-ID: <56a9fdaff02e8b4488a44d4995a25651f33ccc2c.1706741516.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: 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 Jan 31 22:52:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13540091 Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71F913AC0C for ; Wed, 31 Jan 2024 22:52:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741555; cv=none; b=jqKWrl4N6of4MU7MyomVAdBeQqlWJ+zkazWTmqLzngxZ18t/1E88TheyFxdUbBmuTLFfZ9/s2595FoJB67YEhX3ti4487GdhD9BfQcj7qa85vLVZNI4/X5mCK5+PFM/t0YvlqNmxSvCuowEDfY5D9jRsYjwkyNLhDiLMQmeVUxE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741555; c=relaxed/simple; bh=4XhSqhJ8JVRpKFDRekH/n+lbH+xqkm2X1r3AFFo+4uA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MaJPVzf+c1xv/E/y73W4vKRP4gmsApWksoAPqnK+aELzBC5ACYB59owhjFlD0pE/lGiYi96F7FYPBwGnE8w9EnGAhHgJqiLD8M3gxst06G240ki8stlLQjgZZPMgTx0V3gc+JyJxwXGvSYMLSFm7/QhkaEQZ3bwk7WOLp1AmEK4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com; spf=none smtp.mailfrom=ttaylorr.com; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b=THg/lgQ0; arc=none smtp.client-ip=209.85.219.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ttaylorr.com 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="THg/lgQ0" Received: by mail-qv1-f41.google.com with SMTP id 6a1803df08f44-68c3d51ecebso1639646d6.3 for ; Wed, 31 Jan 2024 14:52:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1706741553; x=1707346353; 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=Wr9AYQwXdBciiOcJb83i1K/quz2L7bBhtA0Rvd+PWnQ=; b=THg/lgQ0UDqXGFcZI3k9/DRisD9or198GZvMuUpBL/5ZokJNB/Ts+yFhcss1l/H9jt 8m74yyRHv7JWuDpxYAe1DxXxcUk27ihy5Dabg5h0wFHz3PqD4mdrkfB85qygr4vl7pKx phOzdIPjsIOFFZAFbhfNv0nHaskipBENF7ADk99P8KbBTJzxxtpiOTCwAM9rUUgKlVJT 2W6jF7LdO6cOE2z6vmRTlRgeUrKVxfbqTx/dsopX2OGh+RCARkHOgqkvQJpsHV6GIKmC o2faZ6ywUz3fmdglZ/fDTs0tYJ7KN8KXWBsFfOFR7W3IeHrUwBJED/DxOGE0liaGfGwH EJ8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706741553; x=1707346353; 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=Wr9AYQwXdBciiOcJb83i1K/quz2L7bBhtA0Rvd+PWnQ=; b=ZLh44SE/KtgumFtphDU9gfaVuUww/MwFdDyq0xKHzSrQRtbSpIWGmo2qM/EO+X37tC AP7o/tz0l53zke9gPd3VjDKgN4c6GpjXSGnnUCiIoiCf99AdMZ6Uu1qqKwhTjfV8fJTo S5eYm2+awsP0HaBWYhwBb0Pv6D/RZrHabFurDw6fglBcs1YnYWLK764ucarvKfsMuc7I h4gFRnrSd505qZxPR8QDrt15DDUr5YMSPPZGcQKSX3JKr6s8886/OCMZRxs6NE+z1EP4 fh7lyf/24QA+hzA/yq9GaXQALJMsrBGvAPThqvBhHZVjxab/UaBzXdplDs/JN76cMvNR kZvw== X-Gm-Message-State: AOJu0Ywme1QB9NBzHa+J/4Pa8rfGn7xodgQIaZOai9ZUOsDaM94L2EQ8 x55StTXtBGApy7zTT7wylTfaeM6fVy1U7dMME1UYBkTlIOeek301SfqnrqeP63YTnyPlehogBqF n23c= X-Google-Smtp-Source: AGHT+IHcz983P/VvH/L0uRPPmPC2ZDFWSry9CTUM7jAcUn/aT/1FtGezZ/RDpkEOnxsG9HU1QwvBDw== X-Received: by 2002:a05:6214:c8b:b0:686:10cc:f695 with SMTP id r11-20020a0562140c8b00b0068610ccf695mr3394150qvr.21.1706741552960; Wed, 31 Jan 2024 14:52:32 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id lu19-20020a0562145a1300b00686a4f9312bsm5952677qvb.50.2024.01.31.14.52.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 14:52:32 -0800 (PST) Date: Wed, 31 Jan 2024 17:52:31 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Jonathan Tan , SZEDER =?utf-8?b?R8OhYm9y?= Subject: [PATCH v6 05/16] t/helper/test-read-graph.c: extract `dump_graph_info()` Message-ID: <7484a82f7f3dc2cae32fac90d6f8e94f3d46aa93.1706741516.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: 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 Jan 31 22:52:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13540092 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 111D33B191 for ; Wed, 31 Jan 2024 22:52:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741558; cv=none; b=at/bByWI58IDoiTbEsbdbaFmHBslEp7ZFq6BOUKpJZgPjonUo05319SdLSTe5p+fmR1CZx+F7jGGN4v662vLuamZi7iulayQvEgFGhnVmLFbpoA48nAy8RoAcYx9dynxv1QhF7TIT7tPLg7q7LvBSeVQlPMJZYelakRt8TidRls= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741558; c=relaxed/simple; bh=siryQCCwKmp0FcIkCQGjRg7gCrnrAyHd+X131cmCfow=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GYknztDZuh9wG9dHtx5y4tnB3tla6hh2Yn73+YjDs6lvHsc0SlG8uA9zhqwpaTv4UA8IU8bL9OBZp+ogQwDCSquTbw3JXv6tZRvLtFyecnBs36F/g71BgTTgbsrgmcbyonxX61B7J9orztRN1eMJq5MFY9K2V70iErCzxFGZob4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com; spf=none smtp.mailfrom=ttaylorr.com; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b=LGs2XdOr; arc=none smtp.client-ip=209.85.222.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ttaylorr.com 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="LGs2XdOr" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-783f0995029so21845585a.1 for ; Wed, 31 Jan 2024 14:52:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1706741555; x=1707346355; 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=B+yx99PTfiTSh93zIKTfSShNWWIupRnP2PqqMJweWww=; b=LGs2XdOrLR1A0v6R+bj2cRJ1Mk1UdrlMn6gPQRCGArXiRyf9O6i1HMZ4tDbiZ42xei Ev1nkCKZ89bKdXKV3XhKpU0+v+haClGr1xS2fdOJZFq8SNmd6Ohg1HxmMRaPSlmXgn/P OHUT6P6kUvlShRA0dajQxXYtmD8nD7iEDiB1S4x9x7sp7OK95PmWTWUOqDSqRZcdC4Rf q+TxgcmQnNsXAWUDKRe4DN8RW1owP88nZY62MFSnmijHPT4vy8kiHjzdcxFcOnmQaCUY sbVnhlFW4s1hU8LT1oEyK3xpSI5keyS9gOoInWGvyVnkj9nUC1lczliDRuBJoiJFmRpi bF3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706741555; x=1707346355; 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=B+yx99PTfiTSh93zIKTfSShNWWIupRnP2PqqMJweWww=; b=VoIFMcqob9LbwPMnKeJPL1CB5CGe1PDyMF1JUYtQ0UxUfYii/sL6AR9ujSYE0SJCHQ zzzdg1ecojLg9MTUM4Sts5mzLYpS9OX8mLbue+NK0DkFq+TijVsOIx/5lvOCXNMNqXVU ucXy02+toqeeOZKhtbPdWG2NViG5cuEFjMYli8NwufB0F178PKRAd+M276nA4ZCcBj5t o/7YEdLvEKRTfU5nT7NC1PRqYVXv1Itlbit5icDJGJNxqRMNH4RBc+Dh6YduAzjEpeo/ OvNI9bmcHDvVWcLPvzDlsuy3tTY66MuuiBv414hj4g5MQe7ir+ilerJJ+RXeGO3BPQhL bL4g== X-Gm-Message-State: AOJu0YyAkwFGlmN0LamvquPC9dmjWHeIOql8JvVg4geFqTxKo0s0e4Bo iDihKxriZZcoxsJpIrIvPWvT8NedrhHbf/tPm9C4qNrgGqejmL3xlKzXzFIjTkt0X2Y1pzcqtrX l2HM= X-Google-Smtp-Source: AGHT+IHpTfBlTZA6kCryB/aRGeeGYvYwYkORXVaIT+HHBaNEPIveeEo5hDUlpWFZVwPlm+VhDP9pNQ== X-Received: by 2002:a05:620a:55b2:b0:785:3422:8353 with SMTP id vr18-20020a05620a55b200b0078534228353mr823674qkn.22.1706741555638; Wed, 31 Jan 2024 14:52:35 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id c8-20020a05620a11a800b00783ff37c473sm2855449qkk.103.2024.01.31.14.52.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 14:52:35 -0800 (PST) Date: Wed, 31 Jan 2024 17:52:34 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Jonathan Tan , SZEDER =?utf-8?b?R8OhYm9y?= Subject: [PATCH v6 06/16] bloom.h: make `load_bloom_filter_from_graph()` public Message-ID: <48343f93a27eababbbf5ab1355906229d151a8b7.1706741516.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: 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 e529f7605c..401999ed3c 100644 --- a/bloom.c +++ b/bloom.c @@ -48,9 +48,9 @@ static int check_bloom_offset(struct commit_graph *g, uint32_t pos, return -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 Jan 31 22:52:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13540093 Received: from mail-oi1-f179.google.com (mail-oi1-f179.google.com [209.85.167.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98E423AC0C for ; Wed, 31 Jan 2024 22:52:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741561; cv=none; b=K988pqpHZFuefvZXoq6bf/mVaoqzC6tpdQAdRLV2SPRHOn0eGTjEJQZGQ3rgfOeJPJZfiEv4YhROIzghthQmpmc4XNCP+ThSdOXPWN3f1SurObiBKjmaXW37FnpmGZPON7kM03g7RdlaIxkYxbB3UYBYPUoiatXd6Dk+Eqjf6Yo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741561; c=relaxed/simple; bh=QpKvygj6Xou3dpJDwqltvAKZw5Z6t+KtEbx3R6fAtho=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FK9H3qZn0Mg1CRlFT6gRSieuVxXEL8TRykv4rMY9orshF1kaflpXKzpuNlbAq/mvqDEVmM2y0ayGmbv7NUBk3pAp17EkVOjE55jXbdUNpdYNxYAf7/rvlfKehQrxwI7R/WKEb13YYkvVIIn6mOerHLPbvpW8HeuKqDvOniLeylU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com; spf=none smtp.mailfrom=ttaylorr.com; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b=i2K2g9CJ; arc=none smtp.client-ip=209.85.167.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ttaylorr.com 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="i2K2g9CJ" Received: by mail-oi1-f179.google.com with SMTP id 5614622812f47-3be6df6bc9bso201926b6e.0 for ; Wed, 31 Jan 2024 14:52:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1706741558; x=1707346358; 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=XZLhdjkO2DzqFkBbfjp+wv5cgZ1vxqohVhDihCPq9a8=; b=i2K2g9CJSuaImRaIHq0C+5sidKK/pGPMV+Nj5vO1h9lAg0asdowO40EEluz4JcamU+ xk22KfmxFoCKJvkvGA4fv6uQtV9U+WzEllSGyZoKwiuPvIMnFpFkszbqjCWOYnlLqXNM rlELZAcp5CPRA/TxvvUKU1sh9+8OZuadCc4CcAktvGEezLft62h2Cjn3yoKP+EFiqWok sZ3d1MC+AIQ76UVUZZexYjKGSi8EeWwF152V7p4td6IYyMrVvSey7sMWWAldbXjF0X5J zskLrnbk/i3RMUbPNpNG98hjXiZDLVCg/wf8kAZjzE9BA9O1w5JptDYRAbu2FGdW8iLK VVvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706741558; x=1707346358; 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=XZLhdjkO2DzqFkBbfjp+wv5cgZ1vxqohVhDihCPq9a8=; b=dsiRlWFSkVItXh9JpXsSZASE2KXEtlyB7q+6MxRGejn7b+JX6iMkQFkhWEGLQUtecI IjLUzZCMwtZIpSI7XagC2v/9vpJKyvwc92QnInAS7YZ+vq8pdJSKOkobhPnnyoCwrvZP G8Wb7VYHnLB2jFRYFYuuQ64jzuWMb1uY0hzdwDGZuNvIP6C7rSyHS+/j9DVDwkjXIjyS bhT2ZgK8gZb/j3LQh0VM9s3mbE6TBHSmgXB+ZmXhxeewDJjxOQbdA9Dt92Vyi9DcT5be U88eX2K+W+w0E4N2WjwokcSu6DBkFeMmi9j4hzVReNG/vxDqVAxl1yy/TNxm3r3v5H2U xing== X-Gm-Message-State: AOJu0Yw/7BqTsSgPm/E+bwQUqMVkCjQJHO7DXG8mkkyzeebIWy7UImeG EOu+1JXPsZ7z4IY7iva4UscsWJ1XGqp7IPKjYmNdfJZBBHrN6g3l6yGxUm+SoGrf0XrQGLO6jXI JYjs= X-Google-Smtp-Source: AGHT+IHN2AaSEIC6GGDPdm0x60xeMJ1aXSwDRjtl8vhIgwCssE1uJZr7Ni6QrIC3nrZfai8s5HQPWg== X-Received: by 2002:a05:6808:200e:b0:3be:c20:5b72 with SMTP id q14-20020a056808200e00b003be0c205b72mr3742695oiw.7.1706741558570; Wed, 31 Jan 2024 14:52:38 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id fw8-20020a05622a4a8800b0042a0a3d29a2sm2031795qtb.49.2024.01.31.14.52.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 14:52:38 -0800 (PST) Date: Wed, 31 Jan 2024 17:52:37 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Jonathan Tan , SZEDER =?utf-8?b?R8OhYm9y?= Subject: [PATCH v6 07/16] t/helper/test-read-graph: implement `bloom-filters` mode Message-ID: <286fd7dcdb99af9b06b2f8e9f9adfcdc6b7d70d8.1706741516.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: 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 Jan 31 22:52:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13540094 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B301E3B2A2 for ; Wed, 31 Jan 2024 22:52:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741564; cv=none; b=oniWHKJsVrGH01Bh9pY2cOp/5MbAzDfE4XAUaPQ/e4bb+h5APOkSIezZzsTbBK4K9fSrveKlqr157TKPaHLjg7Y7EaqBizqBMy5u5cQkg0CrlSuK6cUEr9kKBboNv3cnAQ4A7YsNiFsw3Y3B4elMi1D7q2rjuGlw97xraJWtdGk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741564; c=relaxed/simple; bh=8E6KBsxvECdOD3bvKFyO8GhHhKtAZ4prwm0qYAwR9M0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bz6FqDJuTten0BsgQEbF0oV7t6tstd3wJXg80jUuW+4El5ym5jVR51dOPeAcYTJt+PR7O1ruiEjwok6s8QzpVIfQOc94oxJEj/06NSj10pH0EZLXrLg5Ezl7huDojzk3t9vPHwpV617IVjv5H9lFExqGEgFOo/XkwRyxWzbmHtI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com; spf=none smtp.mailfrom=ttaylorr.com; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b=tBpno5jP; arc=none smtp.client-ip=209.85.222.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ttaylorr.com 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="tBpno5jP" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-783d8e09a1cso18905885a.3 for ; Wed, 31 Jan 2024 14:52:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1706741561; x=1707346361; 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=ITwzgS0eVmO5uULQt5Bo//sN7vdqNO58ibwbBGz1MZU=; b=tBpno5jPQqUElOibryABPt+7vF7sxX6ztXx+/zZSxs3b+FFqs8i/fTqHzdfK/oehPG z53pceNc/3aLs5S3ZirGV4tep48MO2rxP87nVfrnoMU6xKNKsf2ET8nCgqD4tQ8CePTK DvvEyaqHIvNMx0RwSJDkqjlow+AcaZjyn6oRcsQk76QcKimSyNTh85GoQyelAnhGIXc0 +8kSC84BjtlqTOXzGHzUcG4wmDTg6vBemr5qB0vpvDEcKLgyJl8TZiDM9CZx/k+IAUSC 1ZzMGMi2y9hECczndD5ko6+8UaAMCarlxEDYmHWZXM70mHkC0aFcSwHlbgXFxZ9QUnzy dlkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706741561; x=1707346361; 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=ITwzgS0eVmO5uULQt5Bo//sN7vdqNO58ibwbBGz1MZU=; b=mgg3khET4Z+vy0chjX47FHn31ZxPrAoO9NRdO2w6WCMpezzFbPtolBncpJyQ1mFnX2 HEdguvk9g+1p+0B80jEh2Q5+kOyfJalMXhsUiCBtRgTaQSfW2gc4NsuKc8kejqLqk4rb 3Lk4MvN9ZLWwFO/5y1n/6rW09Yr/eYZ5RQ/sXVeJcz27uZGMYKvfTuwY/6eW2jhPf5wX EDGzuYxRa/pN4EB2DoPJQt23JM0J3BE+1nsj/SXeOkB/pkm5uMtRqiJq31ubAypo5lKZ oi/7x8cGzUFTiVo8KC+e0D/L20Rleos8X6o4pfSHcbyHDbw6L9N3OOQhoOlrr4XHrOIG k+lQ== X-Gm-Message-State: AOJu0YwOCMw5Z1MlgndRpTZPJeAIpbU2b3pziYSnHyAux08lRyNLZgg/ UlmPVm7xLov/UMg4CYx8YAM+VzweFTlwmbpGNr21+fnL8wbKGk2JJ2DB3hsJTSN2N/9IgzvB7Yg GpEw= X-Google-Smtp-Source: AGHT+IF9KGW95xMqgXFduDhB2qbt+1js48i4mlzO+vmBlJMlHtvyDU7/U3/p06nNtiWfArfY7vR6Rg== X-Received: by 2002:ad4:5cca:0:b0:68c:4306:b8a7 with SMTP id iu10-20020ad45cca000000b0068c4306b8a7mr3663368qvb.9.1706741561379; Wed, 31 Jan 2024 14:52:41 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id on6-20020a056214448600b00685ad9090basm2336527qvb.97.2024.01.31.14.52.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 14:52:41 -0800 (PST) Date: Wed, 31 Jan 2024 17:52:40 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Jonathan Tan , SZEDER =?utf-8?b?R8OhYm9y?= Subject: [PATCH v6 08/16] t4216: test changed path filters with high bit paths Message-ID: <7de7b89da072513c6e095fccdcac92dae7cda14a.1706741516.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: 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 64737b6ee9..93b8d096cf 100755 --- a/t/t4216-log-bloom.sh +++ b/t/t4216-log-bloom.sh @@ -485,6 +485,57 @@ 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" + ) +' + corrupt_graph () { test_when_finished "rm -rf $graph" && git commit-graph write --reachable --changed-paths && From patchwork Wed Jan 31 22:52:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13540095 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B58A3B787 for ; Wed, 31 Jan 2024 22:52:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741567; cv=none; b=MUYOHHXGcLEVouPhDOrDU3jP1KyZwE0jbQWqbKLavXNrw0CJCyorylxAHISYc00VDJG6i99n6KnuYMZwZEila2QxE49rbdT0umyfNPTUPanVAKSCE/tiJrq0PsQgOu7p43SFXF+vJeqUAChdTcLI9ZmN5tSTgEA9rJf8u6xYM58= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741567; c=relaxed/simple; bh=w6/JmHtq3W/XFJPWhIgWmsEh1Gm/avH/upAp0ujalZg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=K0fMkVDwiHbOUcd5fBSa4Bbc94qBitGT4eDb4Vwcq5t0B9toBHCz1yijP38ogEjPi3+e5q5md976leD9tFaS89aYeym/JRUeuRfb6a5NQIJpdUqZZxZxsA4OrxwBUqx6v8MxwSiug8unlcTgAUNHDQHpednKXa7Vf418uvidKO0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com; spf=none smtp.mailfrom=ttaylorr.com; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b=IfafW0T3; arc=none smtp.client-ip=209.85.222.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ttaylorr.com 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="IfafW0T3" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-78406c22dc7so26911985a.0 for ; Wed, 31 Jan 2024 14:52:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1706741564; x=1707346364; 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=K+qJCc4C16jR0f6W2tHmNYuk/U+XF38U0iOkbqJ7sMI=; b=IfafW0T3NJHkEccf/bGmBBvfX6ofuJcOEi4Oot180/Fm4h9ZcrmUcztuqoiiEwfpRT 0qAlqTSsgAUmFc88B0ka5Er1wp90kzfdJdMmZFpx753tuCF33BQqT1iEh/9dXdsmnJ2N Vf5MCngHOpkqH53dclwc4hn+Zj00ImwE7NvxVXKhByzEGOvKbpr8rodxUCiWYfCWmSSp jVO3ueNmVzjdr1ZPkxcxYYvJmlCJQYBsBZqqdLcArG0xr9+rhTyuFEEFmixZZRN5BkAh SEggWdw1eDoBGmCbhoILTs5NtfaSauvJSBuslkGedbMkbq+IvvRbrUwXThwUaTDZiptF JcPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706741564; x=1707346364; 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=K+qJCc4C16jR0f6W2tHmNYuk/U+XF38U0iOkbqJ7sMI=; b=Mr1eVfwPkMsKyyvIoHAhESxPRDW+6m+i43Oe3KG4xE7+O+ZvwlIbgWXSvv2RN2XiJS iJNuVg8uQOHxvO2Zv9zPKez2iqXWSSsd92nORyzwwPHVhqD+s5SX390AuW+ofLCyDC2K 0UGIM6fZESmMNAvhn/KwYITZx8lEUWFwK2gCHfaANAA7MQ13iP4P+nKmKN8pnpOg1Jfj d9D9s3qlhPYVEAtI8Xu51J25P5jC+3Eta2f6/YC3ICVV+tj9IiFRL5hDyVBS43rVPwal X8e1yA0BokT3KhIjfWse8FW+oEAf5ci9fsWrR9EUg6c2QpUNVVpnAH8rCEE+YL19JfkX 6aUQ== X-Gm-Message-State: AOJu0Yz0taxTnF8VmjYDPd1GbdhtPGdyECNiNuunhZ8LjQb5afPL9csr GXIUFkAaqq+x43FOsSlTDa8Kpz5L0gIXzji7PP1S5srsHw7rDL8TrZ2dsej5prAOR59bvZPRkSy 7B2Q= X-Google-Smtp-Source: AGHT+IF+GdoNIlCWaZGEuXili2HvZC13WSHOvvyV/n7KOTQ50Cfwu8Xe9zTS6/OzDkf/KFHWwxT5UQ== X-Received: by 2002:ae9:c105:0:b0:783:4dfb:11ae with SMTP id z5-20020ae9c105000000b007834dfb11aemr656396qki.63.1706741564109; Wed, 31 Jan 2024 14:52:44 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id j5-20020a05620a0a4500b00783f5432f2esm3635438qka.54.2024.01.31.14.52.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 14:52:43 -0800 (PST) Date: Wed, 31 Jan 2024 17:52:43 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Jonathan Tan , SZEDER =?utf-8?b?R8OhYm9y?= Subject: [PATCH v6 09/16] repo-settings: introduce commitgraph.changedPathsVersion 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: 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 | 26 +++++++++++++++++++++++--- commit-graph.c | 5 +++-- oss-fuzz/fuzz-commit-graph.c | 2 +- repo-settings.c | 6 +++++- repository.h | 2 +- 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/Documentation/config/commitgraph.txt b/Documentation/config/commitgraph.txt index 30604e4a4c..e68cdededa 100644 --- a/Documentation/config/commitgraph.txt +++ b/Documentation/config/commitgraph.txt @@ -9,6 +9,26 @@ 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. Note that values greater than 1 may be + incompatible with older versions of Git which do not yet understand + those versions. Use caution when operating in a mixed-version + environment. ++ +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 216cf03da1..b80bf36720 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -459,7 +459,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) { read_chunk(cf, GRAPH_CHUNKID_BLOOMINDEXES, graph_read_bloom_index, graph); read_chunk(cf, GRAPH_CHUNKID_BLOOMDATA, @@ -555,7 +555,8 @@ static void validate_mixed_bloom_settings(struct commit_graph *g) } if (g->bloom_filter_settings->bits_per_entry != settings->bits_per_entry || - g->bloom_filter_settings->num_hashes != settings->num_hashes) { + g->bloom_filter_settings->num_hashes != settings->num_hashes || + g->bloom_filter_settings->hash_version != settings->hash_version) { g->chunk_bloom_indexes = NULL; g->chunk_bloom_data = NULL; FREE_AND_NULL(g->bloom_filter_settings); 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 30cd478762..c821583fe5 100644 --- a/repo-settings.c +++ b/repo-settings.c @@ -23,6 +23,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"); @@ -53,7 +54,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 7a250a6605..1edc4d4a67 100644 --- a/repository.h +++ b/repository.h @@ -32,7 +32,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 Jan 31 22:52:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13540096 Received: from mail-oi1-f175.google.com (mail-oi1-f175.google.com [209.85.167.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF4783B2AF for ; Wed, 31 Jan 2024 22:52:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741569; cv=none; b=KbAz++73XZ9OUkT9+OecyjOfNPyw+aPBzumsdpuxxsxeqb736L7M7gt26QRHW5X1P3etX0k/a/9di0oNHYISRuBE1ZYolKfnOaDwxxPw+tvAiSaHkeDWRT9PsJN4UuYeKVw6JDwR6gTcqn9CfAlz03mLU3BiywW/12ayPat8LDc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741569; c=relaxed/simple; bh=ZCgThCsRmOwQ1+xIGt/3w+tcFn4H8aq/vJ9EJ0M7aWE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Q+BUnS97UFWrEcJrRQZNfHh36z//2G9icaKKTOm96RzLUKruXji8vGEcY6MKkVgnaIv8PQHOYVo4NzDxcVwa2s5/I1YkvabWyOxTk0gDDffx0UUAra/qghDnsJ3M/CTQSRsnB2DTaukZAUOattvwNTsd6BLAgrrbGVKTZiKLcSk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com; spf=none smtp.mailfrom=ttaylorr.com; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b=q/sbZzLW; arc=none smtp.client-ip=209.85.167.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ttaylorr.com 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="q/sbZzLW" Received: by mail-oi1-f175.google.com with SMTP id 5614622812f47-3bd884146e9so228553b6e.0 for ; Wed, 31 Jan 2024 14:52:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1706741567; x=1707346367; 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=D6GHsYvyBHhvzMYU5PMG4d+UGghW4W5NWZxOZg1CJR8=; b=q/sbZzLW4owBYn6uHtaVuvdEW7gfn+pxHAmdKYws4KRK1JqOddl/w19lpp72+eLXtv xsaWnC5lqjuoiylVM/vCdy5HfIegDq7SR/vWNllb6NtsR2G2bde5a5eE4qrlDSQnacNa BVyc6KIkVR1fjcLPr8ydEXkunOQG0ViOSNp1Rx7s2bpK0gPSeIREiIYTIdjroKM12ZsI xtunDgiauEJJdUvL00Wbcji6nnVYV0CjewE/3s4+ps1arSNyueReTDgwBOjFfSo9IvwS lN6GRM/2SkZVxXejoOCyLFSmZzddI7JqFzeIUGAMgOw9/CnwnnLwiKIP7T5FOwZkBw57 T9Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706741567; x=1707346367; 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=D6GHsYvyBHhvzMYU5PMG4d+UGghW4W5NWZxOZg1CJR8=; b=DnSXs6Y+zNMJmcDDL+l8466HDKo1RKSscgpMmwzJDpYA5O8IwY1G5dNj2/PAkbDNJ7 CoCDqaRa4dXgehK1Geqp0ZNEBEmIG26k8N5a2k8pRxfI3740Pgjauu5yVScH4TBkB29E C+gv+A0BzEUwk+Slxh+yGI3xWWb5PVDzpLvyFcZedZjYBKtsD1O+HKeFgpT1sO28O0Pi R/QkaJ8bZKajTxEIzyxC1KFlmV5xnywexcvcqjMyfTJ1Z0Yh3PfjBEK+NO/PODR0OtBB RWhN5QUftZ0Q7gPqKKjBZmedJUIUM/fNrJAJYJLaNrcYZFtXnucF69FnmYsCQPc4zY4G srkw== X-Gm-Message-State: AOJu0Yx9f2bW3LvpIjHhxkLKoSnqhxIbmrIFVgUG4LiHFLPDIY+J7CDT FPoqCu6ioBQ7nt6lv8QshpxUihyRMS0V6soSvLlEWB3c0bb+GOivIX0MmANpU6hgOuG7157fxpX RXBQ= X-Google-Smtp-Source: AGHT+IFAhYwy8WNfBFWCep3nqRqYTXDn7p9L67EBh9OQBC9Yf40g0Pv5DjFu9sg2pBnxauD4+zKoaQ== X-Received: by 2002:a05:6808:23d3:b0:3be:b756:a456 with SMTP id bq19-20020a05680823d300b003beb756a456mr3654081oib.4.1706741566879; Wed, 31 Jan 2024 14:52:46 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id t8-20020a05620a034800b007840164c230sm2624623qkm.79.2024.01.31.14.52.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 14:52:46 -0800 (PST) Date: Wed, 31 Jan 2024 17:52:45 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Jonathan Tan , SZEDER =?utf-8?b?R8OhYm9y?= Subject: [PATCH v6 10/16] bloom: annotate filters with hash version Message-ID: <09c44c51a53026d757a5d08acd9a7e0aa6288eb1.1706741516.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: 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 401999ed3c..e64e53bc4c 100644 --- a/bloom.c +++ b/bloom.c @@ -88,6 +88,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; } @@ -210,11 +211,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, @@ -299,13 +302,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; @@ -325,7 +330,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 1e4f612d2c..c9dd7d4022 100644 --- a/bloom.h +++ b/bloom.h @@ -53,6 +53,7 @@ struct bloom_filter_settings { struct bloom_filter { unsigned char *data; size_t len; + int version; }; /* From patchwork Wed Jan 31 22:52:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13540097 Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BAD913A8CD for ; Wed, 31 Jan 2024 22:52:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741572; cv=none; b=Zh4TC9uNAbjHeiVoK9aNj6ke7QBnQY8l/gSf3RpSsiBeSnwFilCRYzfOp5Wn+cvzZvLnPO6CrnkpVvH1UtJPqQIieyi7bB/p3nbJ8uAYvY6B2Sw1RZmFCDJLckI4VBDRhcFQxVXGeCL5fm/bCdqDNLy1W963lmWr4jR3YDF/wU8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741572; c=relaxed/simple; bh=aF0u7+G9GSIyMTSV2Bc1s6QZ1I15D85QNDParD6BJbM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZtKAtnY0dgVr7gwjcpIucbAwJblS+S+lijJJL6bZSBEE+9e7EgW7mfqPav/3Ln45bMIjQHygXHSDLczY9cRKsJsaOuYct9kCFSya56GRdTOTLEHYzYYkr3F2f7jnOV2wxD5DMFFrJNAb1MeNH3gSCbu6f7CNGfPxY7i7/9QUoZM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com; spf=none smtp.mailfrom=ttaylorr.com; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b=KnN8wrTJ; arc=none smtp.client-ip=209.85.210.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ttaylorr.com 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="KnN8wrTJ" Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-6e11cda9f6fso145222a34.2 for ; Wed, 31 Jan 2024 14:52:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1706741569; x=1707346369; 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=lr+uHGJQfKi8Y8GV0ULJwVjZzWQtlGzGmxiIZWQixu0=; b=KnN8wrTJ3CDqRh0RBHGLyHthpeXt61FS7qy+aJUqYu3bwentaDjYCj2lxJivAuj7Ng NBsb6sgEFZ7HKRFqkb5A7b1t3Kh5Iwjy4bnz+m6yJZSjmPbL5O3Y5aLQXAVP9ws1wNza d0NE+Qdel+YvfFdUuGVrf9hwkSuRklxyV/6V0YQ1DWhhcfpaM/o8A6+BuZ+fD4BzUbmg JLLa6sVCfk0aFhaYDMEITOEuqZtQixY5Dx4ZqMoCgu9nEMcgbciLtjPahJllRKPFV5pZ coAMSv8p70W+DBlEs1FeevTjAcgmF3yc+hcWTo5J0QO40nAlXghaFyrX/8nd1/C5yWL/ Y4DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706741569; x=1707346369; 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=lr+uHGJQfKi8Y8GV0ULJwVjZzWQtlGzGmxiIZWQixu0=; b=EdtKHARlG4OnUCM9soXjjGuA2E+muJCFFvG4KaC8zGulKe8p5g42m5jcZCpCtsaZd2 bNtc+wN8jXmsbxZDykcN9QMCDwZbKJbuUuTd1Z+GMpTklNPvZnNZZxa7+9BKphn8rY+U WAfiaSGMrnHnv7QiU+dZ5wZd1lwmXCp3bMqiK4j7gAarqv3ZDnV1VzBKlHa/VrIP2XjH U7KaUpcDrVwahpFr5ykMpr02RlRnR5J5asogSNhOrDFd4EaKyOsz/kUJvWGqhcF/bmJY Q4bX/MzsUlRlI0Hf7+zF5a9qbgunOVvK+0i6memz1On9CDF7Me9DxTMNA3ajVxntvrA3 3s6w== X-Gm-Message-State: AOJu0Yy8vDU64EMnz+w+ZdGIo4DUykgu2aIZ8Mnltothza+c0PzPV+mI 4f5JD9URn/RRjNFazoWs9x6sa3PHvL9gd1/kwy8swFV9nJaBng/PVQeS7/CzLwxITwGBYLC8QaQ WIc4= X-Google-Smtp-Source: AGHT+IGfWWwVybbzSdcElNsyKk8glzr3A7B6FDVWEEhWHyH7CbX3pNu9flUarDaKP1WKoX6ytA3VNQ== X-Received: by 2002:a05:6830:1256:b0:6dd:e00c:8350 with SMTP id s22-20020a056830125600b006dde00c8350mr2978984otp.15.1706741569684; Wed, 31 Jan 2024 14:52:49 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id ck9-20020a05622a230900b00427e0e9c22dsm1092042qtb.54.2024.01.31.14.52.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 14:52:49 -0800 (PST) Date: Wed, 31 Jan 2024 17:52:48 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Jonathan Tan , SZEDER =?utf-8?b?R8OhYm9y?= Subject: [PATCH v6 11/16] bloom: prepare to discard incompatible Bloom filters 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: 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 e64e53bc4c..c24489dbcf 100644 --- a/bloom.c +++ b/bloom.c @@ -220,6 +220,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, @@ -245,7 +262,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 c9dd7d4022..052a993aab 100644 --- a/bloom.h +++ b/bloom.h @@ -108,8 +108,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 Jan 31 22:52:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13540098 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4EEB3B7A8 for ; Wed, 31 Jan 2024 22:52:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741575; cv=none; b=e/fjozNJCt11jrPAcOx2kQAGq/JEOdsTaiyoEmEu95m1ctb+cy4Du/dNIZN9xF+Xzr7tUeKvd7U7OgB02kXldJ3UVd3uazBnPuB3uYp0gDteUxfeBp/NAQ7JRC/ryvqB2f8AAnpHuHrSVFAvZ69fCOWj3oL7ufBgnzQkJpNJL58= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741575; c=relaxed/simple; bh=9sKSru5iEog9Wdq1YNqplmrnhrJSDJCsLl62t4LuWwM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gkCex/veqv6lL9m+SvSjqcdkUeyHaMie/Pr0oWALS5gqQa570LaqkxpKeMtntMxJQMGB9xqgop7Obh6F+kmwGmarXfhPPlXLTKvJro6jqfCdh8ciwFuHHWIQmkMeW979X6QLsv8xYtaEHXRhwxGk1hT27Bj+mW5+pQu78xy+rP8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com; spf=none smtp.mailfrom=ttaylorr.com; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b=fvndLF07; arc=none smtp.client-ip=209.85.160.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ttaylorr.com 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="fvndLF07" Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-42a4516ec5dso2269991cf.3 for ; Wed, 31 Jan 2024 14:52:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1706741572; x=1707346372; 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=OtyqUkEgrQnnMAkBDyGmD5wWrqdoe4EurbjMO3timpA=; b=fvndLF07mDT2iTiqGoCQtEsB6Omxk51PZORL2aFcnIw8VQsjRCzVhcNzUi/Hf2ZCem na0d6dSUZM0ECs1wywrfHhqUVrssl1aSwU+0Eevc9FXEydO05n4gnDjAmWaeNJ60Ls9y WLw7gAFC8y8tGMdkvjorbPqA/LVKfGkWxJkHBkOSpk7Yj3p+ZHOyEzuaDCKUXWVrP8sh 8CD6j7gwBsZSJaCpYeOQ4P5LCXs0lm6/nL8WFgr9afs4Tdr5nzmecZt3qRTd3FD5T9yj X/d1lwbkctLN2aX70IuMe3FhalVnbAPgE2Vc2ddz1YdMunBEwUZF8MdhKGnubcZ7Hla8 Pidw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706741572; x=1707346372; 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=OtyqUkEgrQnnMAkBDyGmD5wWrqdoe4EurbjMO3timpA=; b=obuMBUzcK+nuUZzPYIn43svWkoJbwTKqbZSbgr5CvUqtjS3jKGg50hDTfh1C2uLm4g rvqbg/UVNub/yYPscZthchAZtPPJewv/WCHLyB/xZpTsXe5iT13obm982i0ok9vMK8vq 0zBmAEbNIGbdHS9bKg26ULKLOWoaXT8jGvVBSp9YXnzd6JuB8xwstoe6q/a78QB2dbm1 oyGGrlkgey9O5mFhJWwcOHqmBC2KwtJj98sV045ueOlUA1GoKT5xnHDVrUdWq3C7TQvP mTS80ZlPD/mNQjguWyxijiWJmULuJ44nECeArJ4cJ7GEYLskea+Kp+WFpqV3QUzxEX96 uuRg== X-Gm-Message-State: AOJu0YytP9gHBGv50FdZ+2yed5C3YQ1tCVgDXvJYywkKJ0y1FZkuNYdY gapY32dSbOacFOqCmeMu35NdDMyPsbKqI7ropOwkBg8hyER1RBrTTs+wQcRJq5KKEle1CWPS/Cu +n1o= X-Google-Smtp-Source: AGHT+IEXR6gsZNMBziNI669xqvo6uFJ3Pfyu7k/98kxW7QunSYjV3iPA8l3IHyNG5izHufF2x9fWow== X-Received: by 2002:a05:6214:f25:b0:686:964a:fda with SMTP id iw5-20020a0562140f2500b00686964a0fdamr867862qvb.49.1706741572338; Wed, 31 Jan 2024 14:52:52 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id os21-20020a05620a811500b007853eb72c49sm617218qkn.46.2024.01.31.14.52.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 14:52:52 -0800 (PST) Date: Wed, 31 Jan 2024 17:52:51 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Jonathan Tan , SZEDER =?utf-8?b?R8OhYm9y?= Subject: [PATCH v6 12/16] commit-graph: unconditionally load Bloom filters 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: In an earlier commit, 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 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index b80bf36720..6c3fbae142 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -358,9 +358,6 @@ static int graph_read_bloom_data(const unsigned char *chunk_start, g->chunk_bloom_data_size = chunk_size; hash_version = get_be32(chunk_start); - if (hash_version != 1) - return 0; - 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); @@ -2516,6 +2513,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; 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", @@ -2547,10 +2545,18 @@ int write_commit_graph(struct object_directory *odb, /* 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; + + /* 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 Jan 31 22:52:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13540099 Received: from mail-oi1-f171.google.com (mail-oi1-f171.google.com [209.85.167.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82D973BB20 for ; Wed, 31 Jan 2024 22:52:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741578; cv=none; b=sfI6Wn3sNS+UQ4e4999SVb1cW8m8k5X6KGH9uIYJdLYvBsqeNsLaXMj6bB4AY6jr0tLWqqPwAPURQYH5MYqBCT9DhkgeQuqLPERNUpkGq6ReerEfPTJAfn0iYbpusMlzvt4rV8B5u0zc5ban+bL3VxV6f1Zg0BH7rN00sQeL6f4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741578; c=relaxed/simple; bh=SkPqFtEVdAYOIW1zKYgO9xHEyxnA3Nt4cRULiWacK+Q=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nWwkOriV63TWWacahhESx3Jh7V5Bc2/3zd3tzTd2TSJ9glbB6J0qC48W9fHD16NlzQ09snosf667La4CJxQoH2EJBIAK5xCbnzRMX57TPHQobdrCAKKl/VNWLAqcOOZei8dbgCg1rn68lKwfO9UQGHIFrRxAReZeRlofd01QReU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com; spf=none smtp.mailfrom=ttaylorr.com; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b=GPhfJZ45; arc=none smtp.client-ip=209.85.167.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ttaylorr.com 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="GPhfJZ45" Received: by mail-oi1-f171.google.com with SMTP id 5614622812f47-3bb9d54575cso197803b6e.2 for ; Wed, 31 Jan 2024 14:52:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1706741575; x=1707346375; 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=bVDmOtERVGWKjotuRPY7uuh9VoEHqELinFQnOoAAj+o=; b=GPhfJZ45Ml91v1/KzRdlDXU8kbLkH1r8Q+VaouCzm1V0ANgKTrA0+9ZYapuCvysXIQ ivq162mLJ0lAm8ouNJWz0ko8xjw4+Lr6QlCe7EjoHmc+AHXh+wgZBynCEajlst6/zAma GfLC0t4zkrjAfUIDSqfls8w3a0oxlPAIxW+Zc7rM4AUd5WsBp2xowSW5NxJjizM0Fzhc t6E9LO+yGvZRVuRWMtjt5/FwsuZOcsifXD358Oqq3XEJcRaL3kitIo7zWWMnuUOHvWnZ zTdTi9upzbz9VzbXp2gNqeEg10DI/x6KagUOTEVIpQbmTcttgZNTFFZGgQ0hO3o2OLJQ ifyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706741575; x=1707346375; 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=bVDmOtERVGWKjotuRPY7uuh9VoEHqELinFQnOoAAj+o=; b=jUVpaSobAblJOHJDpDNsqGWwPst6lIPvGB8aK3n/7kNsbYiap0bf0InzPbU7TNCtlK Hi+DDdIvAgvPgecip30hL2OUv5LGNLE2F9MkcqC8J8L/9QWDqq/wYXrK/awpbkrnqVhg JE0QlDYvhQjS7GJXlIvg2jcGMo4Kkw5E5NLQLxHni4SPcq9/WBt4TYhLTA8w9dWqzYV2 gQbP2cn4N42mRApNx/wFikq7xm2ZDSuzE2GDRSOpwUjyqEgTcyjafnvVJmhqE7UUzsc8 tcLCU4OjeW0sbMXc3kaKqRmHxNTBv9yBTicZcpKFW4GdBF/oNJgt3qARfCLj1c+QVHyt 0uig== X-Gm-Message-State: AOJu0Yz1xIlZkduCwR14pstHrno0skSi3FAfatDV/l+WSn+z0NV+CKYn ucGGl28BIblMXIzzLge8stV6z1vBeyVDnNzR1WG/lS/0nZ0igfrTRDczPOvUPtBdKH6+ZCi0ypx qsRQ= X-Google-Smtp-Source: AGHT+IHGVbBZmRM0w0n3Ac5sp8SZ4e7LfEqCwMlFDkIoWZscVI9LKXniTOJkQ07AGXvuN8zW+l1vnA== X-Received: by 2002:a05:6808:17a5:b0:3be:b787:e461 with SMTP id bg37-20020a05680817a500b003beb787e461mr3874997oib.43.1706741575070; Wed, 31 Jan 2024 14:52:55 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id vz18-20020a05620a495200b0078408de98e6sm1885050qkn.72.2024.01.31.14.52.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 14:52:54 -0800 (PST) Date: Wed, 31 Jan 2024 17:52:54 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Jonathan Tan , SZEDER =?utf-8?b?R8OhYm9y?= Subject: [PATCH v6 13/16] commit-graph: new Bloom filter version 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: 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 | 13 ++- t/helper/test-bloom.c | 9 +- t/t0095-bloom.sh | 8 ++ t/t4216-log-bloom.sh | 141 +++++++++++++++++++++++++++ 7 files changed, 241 insertions(+), 12 deletions(-) diff --git a/Documentation/config/commitgraph.txt b/Documentation/config/commitgraph.txt index e68cdededa..7f8c9d6638 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. Note that values greater than 1 may be + write. May be -1, 0, 1, or 2. Note that values greater than 1 may be incompatible with older versions of Git which do not yet understand those versions. Use caution when operating in a mixed-version environment. @@ -31,4 +31,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 c24489dbcf..323d8012b8 100644 --- a/bloom.c +++ b/bloom.c @@ -100,7 +100,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; @@ -165,8 +222,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 052a993aab..bfe389e29c 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; @@ -81,7 +83,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 6c3fbae142..6f9cab181e 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -344,7 +344,6 @@ static int graph_read_bloom_data(const unsigned char *chunk_start, size_t chunk_size, void *data) { struct commit_graph *g = data; - uint32_t hash_version; if (chunk_size < BLOOMDATA_CHUNK_HEADER_SIZE) { warning(_("ignoring too-small changed-path chunk" @@ -356,10 +355,9 @@ static int graph_read_bloom_data(const unsigned char *chunk_start, g->chunk_bloom_data = chunk_start; g->chunk_bloom_data_size = chunk_size; - hash_version = get_be32(chunk_start); g->bloom_filter_settings = xmalloc(sizeof(struct bloom_filter_settings)); - g->bloom_filter_settings->hash_version = hash_version; + g->bloom_filter_settings->hash_version = get_be32(chunk_start); g->bloom_filter_settings->num_hashes = get_be32(chunk_start + 4); g->bloom_filter_settings->bits_per_entry = get_be32(chunk_start + 8); g->bloom_filter_settings->max_changed_paths = DEFAULT_BLOOM_MAX_CHANGES; @@ -2501,6 +2499,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; @@ -2543,7 +2548,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; /* don't propagate the hash_version unless unspecified */ diff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c index 1281e66876..eefc1668c7 100644 --- a/t/helper/test-bloom.c +++ b/t/helper/test-bloom.c @@ -49,6 +49,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"; @@ -63,7 +64,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 93b8d096cf..a7bf3a7dca 100755 --- a/t/t4216-log-bloom.sh +++ b/t/t4216-log-bloom.sh @@ -485,6 +485,33 @@ test_expect_success 'merge graph layers with incompatible Bloom settings' ' test_must_be_empty err ' +test_expect_success 'ensure Bloom filter with incompatible versions are ignored' ' + rm "$repo/$graph" && + + git -C $repo log --oneline --no-decorate -- $CENT >expect && + + # Compute v1 Bloom filters for commits at the bottom. + git -C $repo rev-parse HEAD^ >in && + git -C $repo commit-graph write --stdin-commits --changed-paths \ + --split in && + git -C $repo -c commitGraph.changedPathsVersion=2 commit-graph write \ + --stdin-commits --changed-paths --split=no-merge actual 2>err && + test_cmp expect actual && + + layer="$(head -n 1 $repo/$chain)" && + cat >expect.err <<-EOF && + warning: disabling Bloom filters for commit-graph layer $SQ$layer$SQ due to incompatible settings + EOF + test_cmp expect.err err +' + get_first_changed_path_filter () { test-tool read-graph bloom-filters >filters.dat && head -n 1 filters.dat @@ -536,6 +563,120 @@ 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 + ) +' + corrupt_graph () { test_when_finished "rm -rf $graph" && git commit-graph write --reachable --changed-paths && From patchwork Wed Jan 31 22:52:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13540100 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 190093B7AC for ; Wed, 31 Jan 2024 22:52:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741580; cv=none; b=A3kkTUGqcH/XFqdeU9CZgREM+ZhMPGM8MNYGaUViJeQQBXbC0BjNaJINWjGB08nfg+5kv+6AqrferisInpm4Byyr1kDE0LLntfIUvSjG4Ah5JZANC7U71Du4+OP35c5o7IUoZMEeTDAfzj/FjYW0te97tR5p1tvbEg0LcnxxHtk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741580; c=relaxed/simple; bh=X7oko/yvIs3oAeldXN656seuSi7zcQTvgC2SAfCoHIs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KqZPxj8b0QXXq0Qg9x7xuXjKWMJh90Y0wdytiCMZekNioRnvpDwPITjMpLUJ2L5IrSY+1MwmLQo+EtpxTC1HuIEkQn0CFxGsXj3lvh0cNQaXIsma93VeCTLMnf06+hHk2w1ggT8zYVWcB35jTly/x+n56WGXgeoqr5sQYZ2YDKg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com; spf=none smtp.mailfrom=ttaylorr.com; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b=Zqfboui3; arc=none smtp.client-ip=209.85.222.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ttaylorr.com 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="Zqfboui3" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-781753f52afso20224185a.2 for ; Wed, 31 Jan 2024 14:52:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1706741577; x=1707346377; 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=D2rdylrQlR8d3cmxxNnUi24Is1YeLY9eW34nzYmFj9I=; b=Zqfboui34KZKV11Pm7YB+OhlbDYf68gAumOLYVy2C/3ZYonBlGP9MltPCZ5Qw+Bqmo k72UM9zbvLlFMqOYn8E4OVSlKy8/cJZHu5EhZf98dWRHJpWw0nckiMraGTSf9SfO8tId nKn7FWxCNnEyMGtR1c0iEjrJzrM1BzDLLJHrgMJJF7THJTOfc5o0OHKyd4w1QghU2VYa OOtjZZzb+GJNbxi2Fz5GWIMn3pqIB25XOuxGvvCoVKxr/6Gbc/J6aosIn5v07hnYKWXk 8fO3feQ1ydG6EHoJqzkMhBe2wyRYbPiDkrV5VuBYtGvg5Fy5F4fllCAp7lg3UW/EWEeo I+qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706741577; x=1707346377; 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=D2rdylrQlR8d3cmxxNnUi24Is1YeLY9eW34nzYmFj9I=; b=HPj3iSeDfTBwRUzWiwil2tgK4mSpcMO748ubbbYpgfJ/3G1qWGX80Sv+RkFcqvKU0i wFz2QLjcyHCkb6PLu5wfw/WubgRKuUfSUEcQ6w4LGsM7aH3szPdCifeENDoyVly6Z0go YjFiSYIFxywoXvk6AgysAGF/xv5PNRX1HJIZYMW7NzpfLu8wF7r4GFHIWHr1AvnEnXVE CtSlRBEf3+c5kAqF65NSDBCXDu9LGuCp1IgylpsVhXR+gBrKVp39NkFoLtNKqzbr+czX OC9WZZV5wqTC0btsP+PgtUXoBHBJsuxRObzHsw0PYBbrJ/s1oDsCmj2osVtyDOcQJhCf 0H7Q== X-Gm-Message-State: AOJu0YwY7UNYrGWFt6Ul3nVRFWzgRS9bnAEDQWNKW6TmO3aHtC2CAumF BQKnRJMTZp6L78WzHmKqAeb4VygJbNmLi7ZHSp+TwBBoE13Bo0cO4zHTlAKe/OM1zIMWXiX1EAs ZGi8= X-Google-Smtp-Source: AGHT+IGu6EJLUxDZlus1LIdjns6gY77R5B9i08tipPcc1BxQ/CIocwvJe24W3l6+/PHZvC3QUSfwEA== X-Received: by 2002:a05:620a:3712:b0:783:7e10:c524 with SMTP id de18-20020a05620a371200b007837e10c524mr1208056qkb.28.1706741577665; Wed, 31 Jan 2024 14:52:57 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id i22-20020ae9ee16000000b007815c25b32bsm5214176qkg.35.2024.01.31.14.52.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 14:52:57 -0800 (PST) Date: Wed, 31 Jan 2024 17:52:56 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Jonathan Tan , SZEDER =?utf-8?b?R8OhYm9y?= Subject: [PATCH v6 14/16] object.h: fix mis-aligned flag bits table Message-ID: <9f54a376fb317e9df9a37c3de0c8f219d4768d0b.1706741516.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: 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 Jan 31 22:52:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13540101 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C08543BB33 for ; Wed, 31 Jan 2024 22:53:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741583; cv=none; b=QIkqXRAO8BLeO5Py9Ktoj1gXTEuUv1B2RaFEdLvVqtmnDd40L9Kma6K6nAL0toYKlLFELpbRghe/pI4ozfkYs/6V5RiaJ651fPZuYcpMSTmEhi5g8ZXwLqtMmZq5eBIC8gwkDkdb+yfHgQhO1vfPKR/ie8WCOyLW/Mwv8gZVuts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741583; c=relaxed/simple; bh=RYV9Qjam4ER+Zp8oZyrkeWq7y6HN3Ns2PhExvumWwYI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pzqosl/KnnYB06SbHElLwPpT8AskDoArISDgmZcSMhCylb+269LPN34I1i04kX0Abam8EC/M0ujFq5rVv3VhmdvMJfeCl3IYk2FB5gD3Ic/WeeW4UwkFgDLksPIA8dqWyGufBOAoTZtceVGEx38J1oZy1Cw+wGPLTwLf48JN1IQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com; spf=none smtp.mailfrom=ttaylorr.com; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b=I3FBAxN7; arc=none smtp.client-ip=209.85.222.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ttaylorr.com 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="I3FBAxN7" Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-78406c22dc7so26925685a.0 for ; Wed, 31 Jan 2024 14:53:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1706741580; x=1707346380; 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=tV08mjbJqIemo+xl9npdfPwJLfv+Qb2KSAVfke+aAKI=; b=I3FBAxN7nlEpokgSYRosxenM0KRDFgZEb3U8BkPhSEHCoN1dEuG3hJQVe3hI5PlLS+ 8TXFm8OMNDmjB72RoObAdTg8Y88MfZdIyrp6bUezmyUf4vG267tExv8eRjTGddJWxxp/ we1E0I1t9kBC/CQiAROOdfCynubF5/mzKfb/Ewok8yOFUkzl25QCUzidrquLGEFXOKSE a9Xqor26gmMfAjbw5ix6zpufC8fY/Yd470xVq7tGiXXwYY3J9XO5Wq4wtUp6F1lH3acd 4Owskunc5vsuouC7vZobnh2kBvmPUnVfGejcS9N94grouXMFkhNqaIQgUWt4ty2C2oNX 7V3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706741580; x=1707346380; 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=tV08mjbJqIemo+xl9npdfPwJLfv+Qb2KSAVfke+aAKI=; b=gSPshDWzG+IXUBPKiHfpB13SzShVQs4FirmncvFSScXq98vkZ6IxN6dYbXdqzkpIRt IMwH9zK0k8RyAkmJs+/CqlV0x/QblFBF0ztXAjWm9mYoDAheaGKHJTtMkjtDqT7OKWTF y2Ofrje5aNAJl/GQhtr/gxi7qr2dCKTI3M+B7Q8+zUQqjuNup9DPYbFXI9YSOzgzDUsJ OlrQVFhpDWZ/3inv0rcpA5RxR95Y0xmwG3bDfUTm/2yFzyvu8aiP7TkE3siMFvwqGhfW 8ThbDG/1y5oBfWM/qVuFetNfLHReh4+uHMWWGO8oCwJkjGTNPadpNKENgqeCPLet0hpw biPA== X-Gm-Message-State: AOJu0Yz6lZ7hx6mUCLesmJx6Hxg2sTCAd4ua9viWUMsVc3k0Bt25tugy n+E9cFWJvenm+lW2u2yWsP2ZMGBxRrbVTRrYg41WSL4iNDGcLKct2MNvrM80wf0KXIw8EG8S4N2 r/eg= X-Google-Smtp-Source: AGHT+IE6Wl+ZSvwAFArg3fJmKc8+bk1SxZGrdwkzOlWoUG0Exvy8a3ee5K5w36NPN2BVgwncmcItow== X-Received: by 2002:a05:620a:248b:b0:783:9ab7:374 with SMTP id i11-20020a05620a248b00b007839ab70374mr752641qkn.8.1706741580273; Wed, 31 Jan 2024 14:53:00 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id y5-20020a37e305000000b007840529eb5dsm2295767qki.95.2024.01.31.14.52.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 14:53:00 -0800 (PST) Date: Wed, 31 Jan 2024 17:52:59 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Jonathan Tan , SZEDER =?utf-8?b?R8OhYm9y?= Subject: [PATCH v6 15/16] commit-graph: reuse existing Bloom filters where possible Message-ID: <67991dea7cb54229da695e2b22aa2a24515d9eca.1706741516.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: In an earlier commit, 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 323d8012b8..a1c616bc71 100644 --- a/bloom.c +++ b/bloom.c @@ -6,6 +6,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); @@ -283,6 +286,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; @@ -325,9 +395,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 6f9cab181e..320ac856ca 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -1168,6 +1168,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, @@ -1775,6 +1776,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) @@ -1816,6 +1819,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 a7bf3a7dca..823d1cf773 100755 --- a/t/t4216-log-bloom.sh +++ b/t/t4216-log-bloom.sh @@ -222,6 +222,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 && ( @@ -656,7 +660,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 @@ -667,8 +677,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 && @@ -677,6 +692,24 @@ 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 +' + corrupt_graph () { test_when_finished "rm -rf $graph" && git commit-graph write --reachable --changed-paths && From patchwork Wed Jan 31 22:53:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13540102 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3308F3A8EF for ; Wed, 31 Jan 2024 22:53:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741585; cv=none; b=IM39ae9N1LXOsfBrPnqtb2xih9+FmU1KI8zlruh7e0sTQJqLHWg+emt5IxmYQrTUMU+91wMPI8qfZYks+EUp8/T1V4tHxMswPkXX5zLY0X4F8yfC+B/wGMmU2+nqBloO2IMlcKKmWPWerB3JUKLhgV6GOzPTJaDniUlDm/AzJbA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741585; c=relaxed/simple; bh=TG03iqpczV3tLPyif87DeBzhQYXYsK5w8rtoUrswU4Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=p1afFsmBVkwOyFyzWMHvOTTEAqkQ0gdjzW1Cvtn6ki4DOqiZVBYxKddDPbAC4/RzZOnMOZa+LKH6+RIQ70YT8KqsCUc0yKB/+/3wsMjjb9vuse4xgKIu2ij5h2qVwiQ8jZLqhcRovNXxVR/lPyWsw5/LlzXdxrQ44hwVeiyvWpg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com; spf=none smtp.mailfrom=ttaylorr.com; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b=qupn2PnL; arc=none smtp.client-ip=209.85.222.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ttaylorr.com 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="qupn2PnL" Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-783cd9ca29eso17607085a.1 for ; Wed, 31 Jan 2024 14:53:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1706741583; x=1707346383; 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=AoXFd8aZI+HRPO7Aqwkb8bI5B96LhDXQk+2y/4N+w3Q=; b=qupn2PnL8AMMvtZAP3+bn0dX3RVZivzSM7rveaTsKU3GpucZB0mLdK5Fff/a5DhR3f eiFmPcMiNQIbOXr52xPkNBxvR1DaEQ+fVpidStp2qUMqnvjosTVA4DZv+nbIeEe+aArS /q06kD+Iyx6nEUaVUvmNHVmFqeC+bzAhZHS9740st25hlyYoFLLb1B254QSkRZ7ARjog lvloEJ4C1JzWYTChWEQ0RzAaiXXlRzGSvPRAWr4jCtpnx158w8Crt6YWV81u0NJDXiPL +U1zLn2xO/18i65AU9S3HdVzO0h2hfhTPg89AzX4ZN3fUIiGsmgfhn5kQSf4UniGHfU+ F9/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706741583; x=1707346383; 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=AoXFd8aZI+HRPO7Aqwkb8bI5B96LhDXQk+2y/4N+w3Q=; b=aLtxEbTi8VMf/pNLCws+kHpR98hgh1G7lHms2MwBRIV6Ke/4qPPoCKuFDr21xZqLmD k1umn2mVprw1C6vas9PAtKOZNmnG3oeKI4fL/nBKIou8r7/LDzESaGZhDe2ZeH0ujSzp fMEDVdqHOZuSHL2aNk3y/ekDghndfYjVcE/v41Rj07Cj4/pRhtiJVrdZAy9nJEbKYueW /P048lOet32c71EWTK24NWnhrhnqpOyvbUa6UW1zIseF0xcR0UzVV98c5Bv5glQKJTgc UfgMf/tu3lGQ1wrZjjQ4kNXHAUHuVZJgcztImqc40tKvf1EmQ8DLt/hVPZyaf3NohVmo p2mg== X-Gm-Message-State: AOJu0YzXLPzTlCVI+BDNysK8Mcobgu/LYZiMPGWlUnWjTz5ime8YkIRK tfdeE3HZZWyiR4KzjJhCfym+lvnJ5vDryTqX0z7Q4ann8N441HDigmFUjEwBAwL84QBWRTkkI5I RhQ0= X-Google-Smtp-Source: AGHT+IEG4mweCW/b7Bz5JpNgLnIH6k5endr5lof0pfcAAVy4crDLgmUS4V+2o0EvJJVc9KI9Pq1mUQ== X-Received: by 2002:a05:620a:a88:b0:783:b5ca:2a39 with SMTP id v8-20020a05620a0a8800b00783b5ca2a39mr630152qkg.19.1706741582786; Wed, 31 Jan 2024 14:53:02 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id c18-20020a05620a165200b007840c63ad70sm1664099qko.15.2024.01.31.14.53.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 14:53:02 -0800 (PST) Date: Wed, 31 Jan 2024 17:53:01 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Jonathan Tan , SZEDER =?utf-8?b?R8OhYm9y?= Subject: [PATCH v6 16/16] bloom: introduce `deinit_bloom_filters()` Message-ID: <12058a074d8fa5a936f672c24943ebffc9c8ab0e.1706741516.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: 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 a1c616bc71..dbcc0f4f50 100644 --- a/bloom.c +++ b/bloom.c @@ -92,6 +92,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; } @@ -264,6 +265,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, @@ -280,7 +293,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; @@ -482,6 +495,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 320ac856ca..6f5f8f158f 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -831,6 +831,7 @@ void close_commit_graph(struct raw_object_store *o) return; clear_commit_graph_data_slab(&commit_graph_data_slab); + deinit_bloom_filters(); free_commit_graph(o->commit_graph); o->commit_graph = NULL; } @@ -2649,6 +2650,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);