From patchwork Tue Jun 25 17:39:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13711751 Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) (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 A81BF135A69 for ; Tue, 25 Jun 2024 17:39:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337154; cv=none; b=aLS/eNhCRkWht+jcqKbLCpJOJFcPXwQ33ba9jzfx7Bc/wEwKWxbX0YSzFQT+aifmd6HtnKPg0nu0+JkN/PZzRohIdOAGv9Y7He6Py0xNduxKMdNR6fPxedBEJcTm8WwLu7bA+e06aZJLJKBcWVrvXnjKIi0+gI1roL5wFOZtRk8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337154; c=relaxed/simple; bh=6gXO+totGY31SES4g4eYJku+FGPuNNE4sEfNSfhE6Jo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fkaiOZWApKUX4FKwY9anLlpWjYznzvhSyYYSjdl/XZ+hog5OWA30dRTS6Jls/G5tVCTI5NLC7tmee3v8+yv37/gvZGO25Nz1ySxwcV+9MMK3a17cTmxPo7VdnCamjtEnR55gYQCICPQH3AEpytA8jZAOGYNtD4MCbGSVfBuoc/w= 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=npgE7I0R; arc=none smtp.client-ip=209.85.219.44 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="npgE7I0R" Received: by mail-qv1-f44.google.com with SMTP id 6a1803df08f44-6ae093e8007so11556336d6.3 for ; Tue, 25 Jun 2024 10:39:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1719337151; x=1719941951; 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=C4qEkFni4Bgh7sDrKVW8ET9ia4dpoUkZqZUPnBjt8qk=; b=npgE7I0RjvdoUdRV6HcCiYy3sWLx0I5QRq/T+ckftNe+Cms2IFi0aR+hyZC/Dj/jCQ /Uh+r+IpygWKA4vujv8ZHRLoquYo6UNIi/0GjS0mwepaEnJ7qp/wqrnk6K7UsNKQaX4S j3YF+QyJGn1KwBVWizGwI1lyB8JVjBBBrn+baPOeqX3CATvOAvgSFJCit2oFwdsBmy5u Fy8Iqov9SWwLAQfJLMtlsn1GC2+jWCLKeR/0nCNEpFdJrG76pzPZp5LvDS1U54UfH47k L5dxenqImC9vNc+lfciow7FYoV1rerj7i67cW7brWI4bzyuT5zYg8xFBmVaXAItFT//3 TBmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719337151; x=1719941951; 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=C4qEkFni4Bgh7sDrKVW8ET9ia4dpoUkZqZUPnBjt8qk=; b=VHLPqRdxqwrlBhkx4K3hD1VfZW6703/N6kRSjXakYLOPNmpg55Yw+UGzaW6OYPE6l7 2XXif+OyKo75EwqhJaBZY7AyGwPdQJrgIbJqCtUt9DVEFuE/cw6JxtqUrM2TD2FaU48x Jdj+MdrHV5AWiNGhoDVm2gMyTvcWMdrHzUt86mp6eGejPHCmmJqQZDlL0tJ3+KKnb0ni xk1BTBqt5zhIeBoVSJnATGYIun1N6Zra8nNHfM+07v7V+G9hF3jR+Krs4Dc9Di52UP5D BUZdYgJEUpD2q7dmD0brluq4nm7r422pNW7E0Gj5rl2Df9Fm1KS7ls9wb4I4gbr4Yr/1 a9Vw== X-Gm-Message-State: AOJu0Yz6elBr16pAmcxf0SSgxNdxyFb8sDhPmpIWy4sYYdV59RamwzFC j6At1fJhBUwzexXb73M1DwXpGmXWPrnknJkfXgUqUqNSZaVwlqQnQeiYph5z4RhdPVT8dcuvtFe zOVY= X-Google-Smtp-Source: AGHT+IGAjt2q9A1E3krz6oWzVECbz02egwoZSOn9hEAZEQgRkZYqU+Gc8nVxBMdlskRJPcfjKM7L9Q== X-Received: by 2002:a05:6214:5d2:b0:6b5:eea:dc00 with SMTP id 6a1803df08f44-6b53baaac92mr83567256d6.21.1719337151254; Tue, 25 Jun 2024 10:39:11 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b51ef30e6fsm46575376d6.84.2024.06.25.10.39.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 10:39:10 -0700 (PDT) Date: Tue, 25 Jun 2024 13:39:09 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , Jeff King , Jiang Xin , Jonathan Tan , Junio C Hamano , SZEDER =?utf-8?b?R8OhYm9y?= , Elijah Newren Subject: [PATCH v7 01/16] t/t4216-log-bloom.sh: harden `test_bloom_filters_not_used()` Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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 Tue Jun 25 17:39:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13711752 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 35181135A69 for ; Tue, 25 Jun 2024 17:39:16 +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=1719337157; cv=none; b=hAt4r8Mlke6tmq0T367n3PJoFfO5KRUOdEjVfxHiW+GXkhc5N84Tlr1Gdte1p8l2AnJev7LEPv19bhkpsXITIp9bgUtXfc/ihpRSOhQil1LeemUUXuDD7g6OfGHDWNUV14pmuRcfJbtzL4MJvOCSPJcOPoH65CUtPoHn0sH5urQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337157; c=relaxed/simple; bh=51xxuzSI6iNBiOCdKklaUwfqcZlbSz/gtBX100hO2+0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MCg+RF+hUs9j9u3UonEcAr3TXefI1sywXGgaTWUlXC8h11maSjx7wIcz8ahm58WMVf6si9tDOiv3iEKMzes/1YnkIqCpJTM6TOzZ1stTDT+Tnxfvrc6uHK/8HXX9xgg8h/0yOSODb+8L1d0LX9CG00CHPbnXc/WL/XMXjRx1i8c= 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=ArPDaUkd; 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="ArPDaUkd" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-79c0c19ff02so56719785a.1 for ; Tue, 25 Jun 2024 10:39:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1719337155; x=1719941955; 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=yDerfUd+xKFIMVjj49xx4Y05lookJawgsr/D4wJCfCw=; b=ArPDaUkdxl4uNFORMysqW1phFqsRVtFxODe+ZbsiUfiEj3qZt0Q/AUGCJwpgB4A4Cb xus5eKLiivZaBZyB0PlKH68SxXXD+Yr3k0XwMMGQjC4vN4uA4H5TL9b1IQ9Mi3Q3czqP jZTMSCotZu4krb5zAU4JWMYiBDgOyongkIhUuUu6BFIZ9RsE5kueeJKnubXycjqvmOQ5 UNT0GQfPN2HRp9ja76j1z8wMstDd41f2lai2Vbapxq+biikhK9xBQS7Ygn3xKmhiR3zL fuag815H78Pag0/E+U8c+v+DdEaJy/SIpxzydWBVq/k6+VvnUvSJOkb+1af5Yd9SCjPb M33Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719337155; x=1719941955; 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=yDerfUd+xKFIMVjj49xx4Y05lookJawgsr/D4wJCfCw=; b=fmR8nXvbp1b02RgcMVRWF1wf8I4cy/AanPmopTOw/DCjhEdsjIXiitBFauPfYGIXwN w1yX5KL+m/tK+4A5jNAr3BL9/JlgwrdKd3IIb3saFrlipvtZ9fkybhRi5rXHcMcTi0LS IayC1yJxeNeeQCbtyDVQh7pGXys89DOrQNYyv2xVjEfESH0k79/t2/cZaCvyyzwN2gfC hlTfSjvbvoRiMVi88ReoAyVdgXkZ5oOaZOX3Q7SS7TXGDHcRidVsSIDYnzj4hjzawaBS 1esMdd4A7Ll2Lw7BDtwXRQ7nRn88AR1HsxLNKvmS/lr05MiaA6pNxXTD369L5wNr1rNy +wTA== X-Gm-Message-State: AOJu0YzYZ1pFUrPrJypQbwIRNSK/QdhcC00TAL5Nqv3mAAjDhdeUXtkK Qbc3yGLN6kn7MsxFE+duFycylENcuKyqeTxfj61AIpjw6bDZfFdIzKeCfAkXm6xSyCZVLN9maeu 8pQY= X-Google-Smtp-Source: AGHT+IHgWdO2yhnRFvlSOzpnN1nJZRPmSJeyy4XMpXzxLect8FNToBR7dVljEZvvZyn2zPSg1aP/wA== X-Received: by 2002:a05:620a:4591:b0:795:4836:33b with SMTP id af79cd13be357-79be6e6e324mr979086085a.35.1719337154753; Tue, 25 Jun 2024 10:39:14 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id af79cd13be357-79c04daf1d6sm73616985a.98.2024.06.25.10.39.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 10:39:14 -0700 (PDT) Date: Tue, 25 Jun 2024 13:39:13 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , Jeff King , Jiang Xin , Jonathan Tan , Junio C Hamano , SZEDER =?utf-8?b?R8OhYm9y?= , Elijah Newren Subject: [PATCH v7 02/16] revision.c: consult Bloom filters for root commits Message-ID: <5d88ad6c905c040322f360884b756ece83eefa66.1719333276.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 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 c68deb57ce..6931665b95 100644 --- a/revision.c +++ b/revision.c @@ -845,17 +845,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; } @@ -893,7 +904,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; @@ -989,7 +1000,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; } @@ -1070,7 +1088,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 Tue Jun 25 17:39:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13711753 Received: from mail-yb1-f172.google.com (mail-yb1-f172.google.com [209.85.219.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 4FFEA135A69 for ; Tue, 25 Jun 2024 17:39:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337161; cv=none; b=Cu2fFAuJLOptJwDNyXU5egSu4VYh7OtdEslly7ORTAtWzP/Yrh8uJcw9cP6x770kPc9N085A2tdF267ubd0euSxg8KKKVtv4cX43eIlC2JCYpheFXi4Ake7qnOyw8KnkE1Dk5IBg4lOXRz8vDfu7qVkjtqs4Zsu6+XUH8DPYwtU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337161; c=relaxed/simple; bh=67pqoho0rZtX6XgF1sZBla1YYQUDFKa4eaJtIUWpJLw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fMbaD7JkI1jb93JnqOK0crwwZkZhtxpUEg8m9oLHy9IhPDMsoUbVx9fWHIfRPbY0GW94IQGEniNyhjWvoy2FVRl/qlgRhTUF2adVA+PB41jyifQRkWU9nF7Dt3oMdgecV7gqvzyzOMxyF1QeumXB9W4G+WSGfYGla4AcDdXQncI= 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=1wFB1xcw; arc=none smtp.client-ip=209.85.219.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="1wFB1xcw" Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-dfab4779d95so5738541276.0 for ; Tue, 25 Jun 2024 10:39:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1719337158; x=1719941958; 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=ni/yv9aus9DfElXlnyWyNuzjC9sTbva/aRjxmi0SH5w=; b=1wFB1xcwQVwFxvI2DBAU2c8bi7p3A3JRF60Lqmb1LhOnPD/lb7YhdHHmg1s4ioYtlT TqCGZ2tnYIL6XE803yHZPxf44VapKF/4NkfYX0Msfqw3NGdo6GGWuYP//nJO9ss38CWa m69UdgISw/T55IPd9P2hOHfhv0iZI6wvng+hBhPARzjOZKL2THtPRnSVneB6Df3SlcvR TLCCLm6XimJrhO6MC5bsEEmRJdJnK99lRVpCxNSpmucSLQXzfA+hPVON88zhH31mup+K APFiO41ZzS0o15//uAOulbTIT+JlHBGAHBhB9p6KeIRqD7JkST4Vwb5Gm0q3keg2fAz9 VA7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719337158; x=1719941958; 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=ni/yv9aus9DfElXlnyWyNuzjC9sTbva/aRjxmi0SH5w=; b=Xtyf9AVrUVkgXCY3SHHRB6kS9S8YBwb2x7oqnq5AJQY1zZdNll6rOBtfczX7YdWIlR Nz7y/p3n/zfauvzrk4UeDO5SOJw+PIPxxzysFc1bzFH5q38s00bsQPwNaeVZPwLVawKT tq3CeInI+9s+NIuIQ36Fii7s3FYUPhokwzhLAKo5qxX0XGczEA3gX4283dUQ2kt1YrSB VBytzMNFrpI/FlhndhmLgy+4wSDvEH0MZCk24JDjzzACxJkBmx4uYHSwkACoJS0UWa45 9RpukgD35P5D2AeN37sObeqUV0/eZ3D9boEkA4YTUeoC30ScUSi78Y5da0bn5yFnvqgW DEqQ== X-Gm-Message-State: AOJu0Yx9wP4NMQKfvwrsoGt1p7SMA3aMtmjgJc3Joh06rXjV+NsTaI5v aUqbrpH+tbxRXMNT5TJo1v/hNcvz7T2DvoPJ9ZeR9rPDPjs2JvjapEc82Ge5R+9OfM1FGlJPxQR xqiA= X-Google-Smtp-Source: AGHT+IFNJtabgRDAgzjZvTriBVEvHS7DcUzfv8s/L5mM1UxFSm9YbcNqVt4sNKacdEU4ycrVlh2LsQ== X-Received: by 2002:a25:2b89:0:b0:dff:af1:8976 with SMTP id 3f1490d57ef6-e030404eec7mr8272750276.64.1719337158024; Tue, 25 Jun 2024 10:39:18 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b51ef30eebsm46756436d6.97.2024.06.25.10.39.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 10:39:17 -0700 (PDT) Date: Tue, 25 Jun 2024 13:39:16 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , Jeff King , Jiang Xin , Jonathan Tan , Junio C Hamano , SZEDER =?utf-8?b?R8OhYm9y?= , Elijah Newren Subject: [PATCH v7 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 | 68 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/commit-graph.c b/commit-graph.c index 595a349c56..3d89febae4 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..c1977961d0 100755 --- a/t/t4216-log-bloom.sh +++ b/t/t4216-log-bloom.sh @@ -421,8 +421,74 @@ 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. + >trace2.txt && + GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \ + git -C $repo commit-graph write --reachable --changed-paths 2>err && + grep "disabling Bloom filters for commit-graph layer .$layer." err && + grep "{\"hash_version\":1,\"num_hashes\":7,\"bits_per_entry\":10,\"max_changed_paths\":512" trace2.txt && + + 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 Tue Jun 25 17:39: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: 13711754 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (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 78E0D135A69 for ; Tue, 25 Jun 2024 17:39:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337178; cv=none; b=GWFFbzfIHbA6DDuWSDdVzWTaeUby89xw3Zm7VV8G4Qyek5kli6sPvRF/2mdAMKa+qHG+OevHN+e28k8dlQEjLOC5p3aYfqlJjBe7QLPwbC3TtFeZSEm/BWlaVA9xmUQlF9kB2YqUrLxFI2b04K39xZdK7klIGPmxHx/k1eTLoG0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337178; c=relaxed/simple; bh=YmWOwAz4SB/hukFsI3KQur+L37M/LGRkoFUEk72JVv0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YW2tCC5WMD4KRCyofP72++KHfEL1uKQsewfmSedHrJKyM3XeXi/wrkr2wbQgWta9KiY57x8JSEZ1Ga0nyBTVF6Oz15ZQYdQcJCKZsycHyMrxiFOgR4kZ8x/W5dWUL6pvsfDpr8wu6IszD9jDwWluldzGRG0dr54eaNKAuatjH2Q= 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=XFSVRpS5; arc=none smtp.client-ip=209.85.222.181 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="XFSVRpS5" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-79c03abfb18so55007085a.0 for ; Tue, 25 Jun 2024 10:39:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1719337176; x=1719941976; 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=S364uJfHiVxGn18CK1EUhoShH/JRj2hyg7M6i/YyePU=; b=XFSVRpS5Y3plUGL/NcG+rwn+ztK16KR2OYB9kpL6F4mYIVFrQZWlVrq3MXvaynwuaT 7JkPCTha45H+or3HRC+z5Db0MrbtnLLPNnyT4fSQCzYhjKIFazdvWeOgbiFNkZbfUmv0 hKpq65I54W0iuYebpvEzqZqeyiGCrWmQHvRml6fNRxHN0lHVaQT+hrvHddGvNJDfusDJ V5rj2ff6diPOQ6e8RlPNeSpdsER9CeUbkZRYjDZc1yj+IvdU7atu6JxU4bNbq3fm4GB8 tqYGGLisvOLfqTwnUEB+bH+fXckuF+iO/MaFoxdY2VrMGhrxQiLXI4kXp9LmZ3RbNt7k dIMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719337176; x=1719941976; 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=S364uJfHiVxGn18CK1EUhoShH/JRj2hyg7M6i/YyePU=; b=ByCNxg0PTJMCN2vL3um9c89HapubgJKU4T/asTEfAZWhwImiOWTlKGpr3hUlyake2O Qu8M1nz4QgRCxKq/YOBHldejIgKw7gHhkfjj4dFyqrFUIe1g+8dj0mXjpnjiSx/QYBms c9+RJe9Xv2fI8Lu2P0HeGIgBHz4DGy7CXbYN3F72eCAR90l7bAT2J+gOu494a/TVJ70r FdZ2Ll07gCwyTGU8LCWKf72u8LfGbZAZGUDKh3dHXaTCAS/qadWMozFwHa5JkCjsAcqk 1I0nPS15s2qgqRAdhMWsRbw/fAhN60EuDyMIQCNyNuAsnneUY5qEsvTHEq0CrXbA1Jtt 349A== X-Gm-Message-State: AOJu0Yx0fd6nKrl/C1Ug6GDhw53x8x4Cbf7e8+/UeL2TzwS+W5TfzDGA ysRl0sppRqXuWHQwBsZgDgGuSbwkYfU5k2t+6k7NFis/VlY90Tj/jVKyPj2XC23g+cfdY0wBaZf Hyqo= X-Google-Smtp-Source: AGHT+IGsu7fL8ulf/iGkchgu1Pq+DS8fVyrVSJHfDw8JIfGcT3UeCLr3F2DKWrYjxIkJJrA6oQSofA== X-Received: by 2002:a05:620a:3727:b0:79b:f36e:831e with SMTP id af79cd13be357-79bf36e839emr736916385a.13.1719337176087; Tue, 25 Jun 2024 10:39:36 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id af79cd13be357-79bce89de24sm427024985a.23.2024.06.25.10.39.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 10:39:35 -0700 (PDT) Date: Tue, 25 Jun 2024 13:39:34 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , Jeff King , Jiang Xin , Jonathan Tan , Junio C Hamano , SZEDER =?utf-8?b?R8OhYm9y?= , Elijah Newren Subject: [PATCH v7 04/16] gitformat-commit-graph: describe version 2 of BDAT Message-ID: <0041600f31d23f149c20a648bbb5cd61561d9488.1719333276.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 Tue Jun 25 17:39: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: 13711755 Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) (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 A4BE7135A69 for ; Tue, 25 Jun 2024 17:39:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337182; cv=none; b=PwWDzm/1gYm6ESZXHouB/0MXhKu4eOKS5yKrvQdyxIhQVPTGpusRVjL5+C3YHlqh5gQV+rzbn4JO86se5hUMA/Ho3OIvRFy3qG/2rYMqySdBZBCHigQZFIbrWem5VO97Z6upGahliaMbVFI+pvYnVqwLgymwytRUcI5Nu6milOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337182; c=relaxed/simple; bh=+3EpfMtQkIkpOp8Ehg03cv+DcM5OgbcBEWSRDjl9VSw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EaMbqKnCoxygvH/wndCDBE+yEViMvzl5BoJjQts3FcD1lJYbwmh/iMNOK+t3XCTmWo66yzu5cqdm5F6FJkU+SIOprkshFOqMbgBVy/xt9DXppGn5wRM00CjXyJiJSFLcuHvJ3DNRRThcJM+G/N4jsPcECQK4zpb4s3GTKvS1ySA= 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=h6HyTKiC; arc=none smtp.client-ip=209.85.167.181 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="h6HyTKiC" Received: by mail-oi1-f181.google.com with SMTP id 5614622812f47-3d55e2e0327so284714b6e.0 for ; Tue, 25 Jun 2024 10:39:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1719337179; x=1719941979; 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=7kLqU5sGy/a1eA9Od+3sZKP2rDOvtSyQ5DTW/Kis1VA=; b=h6HyTKiCGHkSjB3oXMSREbLh6QAxfGdBFCxXr+HcWGuRa0rUF2catpgLdwJcvATYkE RFtolH0rTreiWfyESgCtev25KrBo4kN4wKc7DcDAlDnO2QmkrshTwvnG3YBwCY5Tb36W nABFvzecsRTETxh3qcCrxR/C+HkWsS3jyeyh+aT4x68bQEm80ZNHlG1zGU0oYrAuxtvJ JzVhmtafjWhMmqe+3xkcxc+3DxtDe9ywcEYJuQGKHzbQj+/PXWjpt2ZuoaHbPlX3tejY jg1970FqvkridL52T6tqB6u8MDNp0H2nVbW2wfuvijNYrFzdWBWdd7uZoROnfgAbxVCr 8UkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719337179; x=1719941979; 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=7kLqU5sGy/a1eA9Od+3sZKP2rDOvtSyQ5DTW/Kis1VA=; b=gYS59XJenik8XR21zkIRRtciKHOOItA0G8uinadu0M+L4fqBRgW5kcPzc2LjDkkzL0 pRDSeMql/rdBjCW3foZQ68/P+Df6/y37TLXqTMhkUZgqCdeTUxnc9UA1qtMB25OILZuY OPBKvgHeHyqgsR5r9BG7wo7wklqohxQ2LBignYHPi+bSk/3eDIrpH8SVr6GcBqMCxGMH Juj5eep3twDB7v8XwnF93JSzwH1yzxpze8QZjhWDvlAZIvsGba802niykeJ9KQiZuexd gdGhaWdKm6i2qGFzudBnDVIaAjoiuyLyBbb8z/K8L6FQpYEjI87yQpuXOnyIzAwll7s9 7ONg== X-Gm-Message-State: AOJu0YzSfLcUb6Bxio6Q4YkzN+VN9B51YiVEx5iwC2wknTtExvChUPNW ZmKjSMU61DryrLHM5E7g+hXKX5F32bFBsM8MjOdrIGdAqzfVZzdV8tXN8JHQPSOmNEfGl7jdMAe jc/A= X-Google-Smtp-Source: AGHT+IFl+u9eSt1FR81BHCjMH3t3X370AOHwrLNqjMCUcnHxOSHbm0+7ZbtJXFqMGSGCOgdInwejeg== X-Received: by 2002:a05:6808:300f:b0:3d2:2721:8a7e with SMTP id 5614622812f47-3d543b1617bmr8912034b6e.34.1719337179437; Tue, 25 Jun 2024 10:39:39 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-444f6ab41dcsm9530681cf.78.2024.06.25.10.39.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 10:39:39 -0700 (PDT) Date: Tue, 25 Jun 2024 13:39:37 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , Jeff King , Jiang Xin , Jonathan Tan , Junio C Hamano , SZEDER =?utf-8?b?R8OhYm9y?= , Elijah Newren Subject: [PATCH v7 05/16] t/helper/test-read-graph.c: extract `dump_graph_info()` Message-ID: <6e7f317551d31ee38bfb2b8abe8268898158b161.1719333276.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 Tue Jun 25 17:39:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13711756 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (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 79B55135A69 for ; Tue, 25 Jun 2024 17:39:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337185; cv=none; b=AOvkIEUBSZOwxeZ3p0Z+byDi9FmuCJniIJE/vP2/l/iGeR9suCgP1W6DpJFc6mZa+M8ac4Z5pSq4R36e/BGIMaTo+oXaH15neMF0eUqRW7sUrVqZE01QXp+SdRv6Y5+97U/AGRj1KJoqftt+aqS3rAC02ViWXJ0MKnwcBWV6rSA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337185; c=relaxed/simple; bh=Dn9eGIGm5EPSLPBb1fjXgOSVeR1wdmbvicSwGcv+tJI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Ppw8YleCrZhtajXDkpoby9CwDBXoTtfb8+bAdt8w1rXw6PduqqKlXzZpbU9snngDnnBzD4JHl6WFSQWQIR5A4tssshFajT0rAIE5td2gNwOchEhAyP1Ak9Mps4BahbeqlH1L9l2LzP5btvzl8PZyWx2Rw+E91uEhiB2PEFr/jtU= 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=OMZj6Nl5; arc=none smtp.client-ip=209.85.222.181 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="OMZj6Nl5" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-79c0b7af837so26025485a.2 for ; Tue, 25 Jun 2024 10:39:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1719337183; x=1719941983; 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=JdZZ9UgcEgjNd+ygTbClHrOZSoHLcWTQNJuZAgMNkls=; b=OMZj6Nl5pjiv+6cvG8iQ8W+WM1CzeFrTwopTGdT80ewgH4PB4WlPyMeFNyQf7WaKxf cFBmKpAUQK1PXaTcuPvuvgkamqsTZfFPtSaKCFvJuOC6tlLkT6BmFroJNk3HKuWJijIT 8uev7M+lKjKTlLdAP0Q9CH6TW8hyMuO3tZA9q9bJvkSMW+dWGJchsO/BLTOVMKu2VeD4 tuDfuTYHa7OKPrxXznYBHxXhIZkYLGyogbOvtSqSph+X8r05Xx5puUN2UShKvdwcHXtq xcyw+jWON5gFsH/WcB01+asYL+A9SVYnHJpVIuZk46r6+O4QkGnmoZ5W6dxV7I6zETy1 WL8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719337183; x=1719941983; 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=JdZZ9UgcEgjNd+ygTbClHrOZSoHLcWTQNJuZAgMNkls=; b=uYkqEf3LgQlPcz8yYb0OcteeIZGzmGBqlcYF2oWQIDj0egJS8efoK45Mi9I0a9cILd RAp3Aq7Mx32cwWDQItKimMD2pq6A/OPXMuXxXdv14KT+4O6Lawh+ZQfswLXjqk6QFDJc uIqmTxI0E1/kawOMMs652YSLOhoyapslLagvMzNpo2eQNwVKCyyksgF/slTfzAApWD40 eEr6ZJ3KcATZadM+BTk61CZsdNobxR2GbmyyNQcnQ236aZIu5Hn7cZskhvxKWYvf5eyK yx/K8TW1TVasl8EAA5PM9swsPseMc98360bKVxavlkgivZPd2szA6rkTtf3j7odjPE56 iuFA== X-Gm-Message-State: AOJu0YxblMtplreciAChGoTkzK/o8hbKvWvIvAw5IRer+XdHT9Opu2VS ru01kk58vCQVBV2lHRLAcgTE0vHzg4saw4ZnkafxnnXgqol7ObaAE4ESmCQXUtc1nL8JlqMis4L PIbA= X-Google-Smtp-Source: AGHT+IHfoV87MoQ6wYEMHPEE3STRondNuzD+3iboZ57recpEDJMpkYmNKmJKq7MhkZOXWy46whduYw== X-Received: by 2002:a05:620a:254b:b0:797:876d:6d35 with SMTP id af79cd13be357-79be6edde67mr930976685a.30.1719337183116; Tue, 25 Jun 2024 10:39:43 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id af79cd13be357-79bce942edasm425873385a.128.2024.06.25.10.39.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 10:39:42 -0700 (PDT) Date: Tue, 25 Jun 2024 13:39:41 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , Jeff King , Jiang Xin , Jonathan Tan , Junio C Hamano , SZEDER =?utf-8?b?R8OhYm9y?= , Elijah Newren Subject: [PATCH v7 06/16] bloom.h: make `load_bloom_filter_from_graph()` public Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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 Tue Jun 25 17:39:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13711757 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (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 523AD135A69 for ; Tue, 25 Jun 2024 17:39:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337188; cv=none; b=K3MvoS45wfnkesGWRHZuJND5Smf5yP934QCSwRNvGc6nAga4N1BStK6qVI5K7mun0G7VOieo7AZwpvcOuGlD0cDX50IvxcAyphSsqmUF1qpJYffO5G82Q04X9rC15EvVCvOTM/xoQ946ZCIX3uqMaPLIxybyyLSevr2+13Saofg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337188; c=relaxed/simple; bh=hxMf0mMFOS+sn9ANpDYwiVnkPu3yRLvIHC7ipzUjl3Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iSgtKtpIVHkJYXKmNJINQ3M6Jdr+wNhIDEY1uREYJvCOigjwk+OyAHysgG66YIK/pytXaTEE3sgoXZyxgSFkPd6xk/6z4euK6Cfg3/b7hMwNbaYNTIQLYDJhjZ6ErENb7y4k52iCoaM3u1KZ7Hr/fY9czyqHajCs+kj+MQn4DQ0= 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=xjOwNn4/; arc=none smtp.client-ip=209.85.222.173 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="xjOwNn4/" Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-79c04e6e1b9so66574185a.0 for ; Tue, 25 Jun 2024 10:39:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1719337186; x=1719941986; 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=NTgOHYrKELet2F67+EI2R71m0GwI1ZMN3b2KiqVBW9g=; b=xjOwNn4/slRFtEZByZjrgKzAjvXYiaCscNbngVltRJ5nqnsDQ8kazEqIzCbX05+pVe XD64qs7xhseFiUfn9R7pOUYhEDPdqB6xqbqOl+Z+N94XP5JURQ6dqoAchif9OV30ZMLh nfndXJb2X9N21JF3IfVgLNdJlp+ikZRvSeRazFse6k3oDPxkP6CjWfYB+qNsz2bJvE5O 8wgF2cZSVIZs9CwJpGMQxQrybWwOF1ZZPDSIznE6yifVvlX0gt/K+x/Ne6hkrQtCq4wo WFzq+E3snRtfr7BH3T3MZUmDaY3C8Wc/7co+DtZGxKUzuvMsKqfeJNv3BYn64uiNP3bu 95Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719337186; x=1719941986; 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=NTgOHYrKELet2F67+EI2R71m0GwI1ZMN3b2KiqVBW9g=; b=IB82vs7kKKnFHJvNCNDL3Yd42sZMRdzsTTTCxl5bDGhU//Abmt4fbItyKXpV07ZrI5 6J3MtIJljZkK0fU+7blw7rpQyLoUS75eOlhTHqE4sA7MZuErUJGYpVggC7WQFeTrFJRs LcWfTlZVz1W+Um3E+sm0+7LRUgGr1/YJpIjyZBii1UjtiE9SUmYnYWP5IsF2aVmoP2T8 EB+jGYcYankMHxsV+BbIfuiMV8Tp+d9AsBVjIR3aMKXihEbX5UcdH4q6mdxk6w2zPgiw d61K5Rqu7qdkz3pcc05iWdDlOGM2PzMA37O2rsl9Rg5XjBVF4q8fX4/EnXc2mHErlY4G RRfA== X-Gm-Message-State: AOJu0YwNquKtvT4A3S/veYjyk+3uabkcXJDQ3084lKEatcKWfxAmTSxd rfOsyyijqNqOAnazBiYmjde9dkINC29Q7HXzalQ1aJjp7Y6SD6AxOuPYHPe+7W6aZu2WRnRyzpK 8Vj8= X-Google-Smtp-Source: AGHT+IFoR/HQRF8/QBUDG9aSOxR/q8lXZMRlb0bIV7KS6wVgWwcOIT7GzM+n4BLgTNoWvkyZXpLX3Q== X-Received: by 2002:a0c:c983:0:b0:6b2:d51c:f5b3 with SMTP id 6a1803df08f44-6b5363ceea0mr88900236d6.18.1719337186107; Tue, 25 Jun 2024 10:39:46 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b526616900sm40646736d6.66.2024.06.25.10.39.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 10:39:45 -0700 (PDT) Date: Tue, 25 Jun 2024 13:39:44 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , Jeff King , Jiang Xin , Jonathan Tan , Junio C Hamano , SZEDER =?utf-8?b?R8OhYm9y?= , Elijah Newren Subject: [PATCH v7 07/16] t/helper/test-read-graph: implement `bloom-filters` mode Message-ID: <0dfd1a361e93bb4eab672f94f9447b99f63fc4c0.1719333276.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 Tue Jun 25 17:39:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13711758 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (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 AEA0A135A69 for ; Tue, 25 Jun 2024 17:39:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337192; cv=none; b=Y96ZMl+JNm8ETQzhhJAyyqcEH1IYFGBosoZ+K1CQB5dLqqMiKJZTdrfIbN7Hvv9Qy0/B5M0zMCbjStZLAhr1fJe8CM4H4ql03ntidy5UxwrXD4oDJfjPSBELDDJ5llDOK21KtAUOQXe4WMmqPhy4pCshGQnztXczOUQy5pIhWdQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337192; c=relaxed/simple; bh=HExtNAt9qYRbWRrnHaRceTp9U99VKjMNV2WtjBjXqs0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iWB/1LclAvl3+d2tz0+W4EJ5bVhnQcbcnfqUBEXo2guhbpUZGFdScLiwqvC2LW7SQR0e0gBx71La1HD4o6VVm5SiPUeQgeLcX4S9vGNoiTrVDCls0nk56WytDeCJUTo/+VDbb83sqUrAfjQYoHmA7yHY59pUaz2NtPwFd7Ep/3o= 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=j672Hb6A; arc=none smtp.client-ip=209.85.222.177 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="j672Hb6A" Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-79c0b1eb94dso39927685a.1 for ; Tue, 25 Jun 2024 10:39:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1719337189; x=1719941989; 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=4Vs3tnu4meWjmIYRJ7lDBRU6mz410QWbZZuo9HFZiQ8=; b=j672Hb6ArQYKrutEydBAbCOnBrynTTqoQEWTjP11yWx9NerUSwHn/cjoDgUtg1VCPl iN2hM1eXMPpOBvHuNin0dW/cFu7HEBY/A5QcgFm7QzZ/pQ7VkQGuTpxo9NNLFsg5bRzM jNMLNCxNeO6Lf7KVaofoXgSEIS6nMG8zac/CYEmM+EFQal4N+WByDimLHPjj2olC6IL0 p8WYEEdbJcsUShjGPB47TmqtgVohjSI4yaemzcHfcnymUzlFM33y6PcKDelI1PyIuu7B i8P0fL3sSRNRbazServZvhCF6dyFwXW2CT1cGq4Zos5OXvmR4u604XvWA7I+55ZguMow uoyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719337189; x=1719941989; 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=4Vs3tnu4meWjmIYRJ7lDBRU6mz410QWbZZuo9HFZiQ8=; b=OpTQ81i5eTiNn84S15c3nZAx4GhiSotq4g5ZugQswjvHpbXmipE316SZ16OL7szMPc BOvizL6pIYUXxyBiLCNsydegJTeSl15VB1sAl/NIehIJLWiLusRc75D5B/Qa5ET+GHB5 927Ug52dZ05BIiFBnTvEsbHsOAVQB22y7HV8GrI5xwbE1yzAGiFzk4TqY5onSTWZwinA YUSBnd4+5Vv5A6K7sDR3gwUJuVeRDGZ6Gf2buLevxLmtWMoPjeJC3bXsdiTuIQUVRfa5 KwWXZ5Y9B0oiNje7ILIEgqrIrllQ7L82OwnGCyfUj3fsfEGgliJoie9du6M00q/a4ulT RuZQ== X-Gm-Message-State: AOJu0YzfJDYUKebK/3LZPE4JZO9UZ2mhaFm72Ptys4aOIoXedNhW+OYk cWhP65Dlu+arjMG8iTydyEfymGpdJjRhw5TL8n76p4MvJ4MbVDxeNQ2U1Vl0IfuT3lJgi1kaAS2 xwTU= X-Google-Smtp-Source: AGHT+IHhNScVWbW4zu4S3mbrEGEjrPtj3TL0VI7WS9/LQqIzrwGbVnH1L8in1CAWHkwsHJLO448Xug== X-Received: by 2002:a05:620a:2688:b0:795:4671:d494 with SMTP id af79cd13be357-79be6e50e7fmr883509785a.25.1719337189278; Tue, 25 Jun 2024 10:39:49 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id af79cd13be357-79bce89a369sm428452385a.20.2024.06.25.10.39.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 10:39:48 -0700 (PDT) Date: Tue, 25 Jun 2024 13:39:47 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , Jeff King , Jiang Xin , Jonathan Tan , Junio C Hamano , SZEDER =?utf-8?b?R8OhYm9y?= , Elijah Newren Subject: [PATCH v7 08/16] t4216: test changed path filters with high bit paths Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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 c1977961d0..49d1113171 100755 --- a/t/t4216-log-bloom.sh +++ b/t/t4216-log-bloom.sh @@ -488,6 +488,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 Tue Jun 25 17:39:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13711759 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (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 CF95D135A69 for ; Tue, 25 Jun 2024 17:39:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337195; cv=none; b=S0eH3fbHjsYOHRTYXICw/2nvv3wmrEfy9wmd7CMvTyzqdIgZBV9Rfa+PK5F8uqzv0YVmT61MeatyR4k44wfu8oz3twoZJsHJ/Ma1yESE489QZr/xbMscJaZr0TVFkrgL4q8NIA0NredqNn44HH+/XDQJayLh8slcBjoH/oipJmc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337195; c=relaxed/simple; bh=JgtwCzjBckp3YHD9dUDpxe0aKb2T0n6kxi1lGWleDjQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pUMsNaMkZddWdK6arz6m34aCiRUUGS1XN0kcirgC8HfISFezd3bU2pOij+TxhVrlh7MlxbvwRUB3iCuBl2OauI5l23n+lB57KqR8+hp9vlWeZDIRm6z+ICSD1kjND01JEE6xSknOQE8t70uw1DKVMhcuLhpCVExzA6Lf1CX9ouk= 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=Aa4kzbkf; arc=none smtp.client-ip=209.85.222.177 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="Aa4kzbkf" Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-79c0c19ff02so56783085a.1 for ; Tue, 25 Jun 2024 10:39:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1719337192; x=1719941992; 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=9t6xq6qLTTwHHmF3vN7MvS2P4wEOHzKelOXt+QaYtzE=; b=Aa4kzbkfDY1qCHn2iapfb6Yg32tWhTcwtKehShNKddxgjS75xZ16mm0mCCoYhXHxoh rcG/mTtIzttRBWi11QZwXEniDN8PzDVNkXGTIIo/rmT43AL8BFYqZ+EHZP9qNEkXLT2d 7lyMZpQIWq86OuWbc6K5LfIofzxOEQM+4GgGtvv3zmsgHH5aAvdKRW49arc0GInJoAeM aIx42YEUgnaWjXV8lavUIQV577VPm9ywV78MnHuL6vEBtFvzdio04NxzdViZ0jpUfC29 jIMuW0w9MG/i+b0J0yMT4PmM1tsDXDSUzrRaKG4sms/S4RYWj2LIPSri0Ktp6K9vIFp8 fjIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719337192; x=1719941992; 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=9t6xq6qLTTwHHmF3vN7MvS2P4wEOHzKelOXt+QaYtzE=; b=XiRylXX1pxNoAbkKt3Cn2vWEfFY/ZsMz1uK07PGi38bNthQGAYZ8vpRohKCxRey+fa lmt5cb/Pd2RBmYckmCV2u290SxocPuCiLlsq7lmhB0doxF7nfxI2g4aBmy+447/j8aEo DTQj0TF8bXNv6soU6sisK/roDqCjIAlMVXfgjcL/q5yqMLymBqB3/7/l2xBXS7X6BceQ q2U/hzmqAOv+O4Ma6pyp3yYF9TIP/dXwV13iZtnsRmUM42DDpMAsIqnK+zSHnkZ6r7fk xkWYR4N6torlRF//ltXPWHOx6sJDJ3xf+jneYXQgpZD8Fdr12kePNXXhGMf4JdnZpp2Q gRvA== X-Gm-Message-State: AOJu0YyNHQNZp4bss6QYfRFiMFlqNmn83FIl+uD1YSisw8F8JLzX2wfj 9Q6S2bQgGKdw/9iAP1w5l73i7MX5Fw3V+pmOf/OY55Wj4rDfBelBJnu+tiuWgE/CGsoldghcg8W +5ks= X-Google-Smtp-Source: AGHT+IH6Z2rUhV8QOz5ek2MuUD4bjlENjWdix56wCmSgFed6LwOanmPRpi1n/V1y84kpI7R/E7TxEg== X-Received: by 2002:a05:622a:4b0e:b0:444:ee8e:75c0 with SMTP id d75a77b69052e-444ee8e796amr42138191cf.6.1719337192470; Tue, 25 Jun 2024 10:39:52 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-44504570578sm349791cf.3.2024.06.25.10.39.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 10:39:52 -0700 (PDT) Date: Tue, 25 Jun 2024 13:39:50 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , Jeff King , Jiang Xin , Jonathan Tan , Junio C Hamano , SZEDER =?utf-8?b?R8OhYm9y?= , Elijah Newren Subject: [PATCH v7 09/16] repo-settings: introduce commitgraph.changedPathsVersion Message-ID: <60c063ca4aa86e0397b42f2c742f986987490683.1719333276.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: 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 3d89febae4..87b07e7b85 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 75e668a057..c4e555fbe3 100644 --- a/oss-fuzz/fuzz-commit-graph.c +++ b/oss-fuzz/fuzz-commit-graph.c @@ -21,7 +21,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) */ repo_set_hash_algo(the_repository, GIT_HASH_SHA1); 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 a0b590bc6c..2b4e68731b 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"); @@ -54,7 +55,10 @@ void prepare_repo_settings(struct repository *r) /* Commit graph config or default, does not cascade (simple) */ repo_cfg_bool(r, "core.commitgraph", &r->settings.core_commit_graph, 1); repo_cfg_int(r, "commitgraph.generationversion", &r->settings.commit_graph_generation_version, 2); - repo_cfg_bool(r, "commitgraph.readchangedpaths", &r->settings.commit_graph_read_changed_paths, 1); + repo_cfg_bool(r, "commitgraph.readchangedpaths", &read_changed_paths, 1); + repo_cfg_int(r, "commitgraph.changedpathsversion", + &r->settings.commit_graph_changed_paths_version, + read_changed_paths ? -1 : 0); repo_cfg_bool(r, "gc.writecommitgraph", &r->settings.gc_write_commit_graph, 1); repo_cfg_bool(r, "fetch.writecommitgraph", &r->settings.fetch_write_commit_graph, 0); diff --git a/repository.h b/repository.h index a35cd77c35..bd7a408013 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 Tue Jun 25 17:39: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: 13711760 Received: from mail-oi1-f172.google.com (mail-oi1-f172.google.com [209.85.167.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 45EEB14D2A4 for ; Tue, 25 Jun 2024 17:39:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337199; cv=none; b=k+ygpiKjrnoViPvEdwsPECKhEsr3vrevmUYuOK1XKXq1vkbT2mkwAU1mwBLXm0EEUYPkxIn3xmHjLs9uDmOHuTOawW/xVixQiC6y6LhNqVTw1adhdRueYqAeR+oFDHzxBEYg0+QRlAjk5mDsLapOWoPpVOvxHmS7bJnTh/oS5r0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337199; c=relaxed/simple; bh=OapTbIosrIajL09/vZFHJo721sPAotzCHLHUNs4iMw4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fw753pKhno9DohcHUL9qPXzpfHyim9cht5b+lfIejnNadib8n5vPAL84CY5/boQKvF7J3fq6YuFpbxyW7Aqs328NSAFaYp+CR5rRth1D2DyeMn+5iW+m91lD5P7YHTCi5cry7Obn5IZ88U6leUjATna+TJPFo8N945UistC3VdM= 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=T/4L0Fz6; arc=none smtp.client-ip=209.85.167.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="T/4L0Fz6" Received: by mail-oi1-f172.google.com with SMTP id 5614622812f47-3d24724514eso3423574b6e.0 for ; Tue, 25 Jun 2024 10:39:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1719337197; x=1719941997; 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=kbBLQT3DHpcs61UmOdhqSA2YCfp81/pB0JqciA+w0kc=; b=T/4L0Fz6ZMw+nDT+kKvu/9tA1Gmdkfk78Bf0RAJCDzOENEQ8Pulp6A+/BLUmmiEa0/ sXmdsGejGpz6SJIO//WLrGtDrNpf5pY1Uz4UUTfvmPC21sfwLSNrLyf7PHwlrDSny52u Ymk8JjwMBQgLnWmqkAq3QR94jR9b4He/jH0s9KWLwKlBM4bHDZlL4dKl/Vj0DQFLiuB0 TcAMGMdcUbHdX6aiesJgsAwHdcu722A11GArDJJnBbu8hSaENONcQDO+hJaHsWgi9JbF I/pNiaDroTWcIAiVf+d0LrJhk8RxkBmBrFqxQi8fm2cl/LH1MhPervBeEN2j98+Q3YeC JUCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719337197; x=1719941997; 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=kbBLQT3DHpcs61UmOdhqSA2YCfp81/pB0JqciA+w0kc=; b=qYmo48D2yjnPdI14APseiYcj35VC+MOHpoFn9bbjjw28c5oOsRDVvWockmHHvinFbK Um8oI7ojLeGKyFcOUF3ZUydeKbtpU8yZx2an11lCPJX5lxit8VGjIiCRZokzk8mQ8GQb b2UuKEKfvyK0k46HC/kNxKK9iDG1MlH6QShv98BqZiQRmTRl0ixIkLOOaTf+H9NMMlg4 86oCnfQFWR3NcJkgTG8aB6KUYmvaEWk1IGI3cMqbC/ty1qTPLsYO+A8QoOzex0jOP2Vo wK6HTrYyIO5cD2FUgl4MfoVhBQlz5yY7IVPlxn9M4o9D4+5lUlSGOneDNsRIEhRvkIfM vPgQ== X-Gm-Message-State: AOJu0Yx1yZkHmgwGTEK2EPwS0wBqRNQNEhkNnyXdmVsmqZDCriPz2bD0 Lfl5b/ergFzDXSgV/gHHjQdrH/vCMUEn4+FAg/PGVMB08sV2ogP2hhJPWVoxF9iQGfr7AV2ekZG Zsgs= X-Google-Smtp-Source: AGHT+IGiHo5n9j2D/MB3xpcwOMzSNPHOSNETTQx5g6+M3BzhAjmuX95SP8qr+vj47nivu4BTz7W/Lg== X-Received: by 2002:a05:6808:1442:b0:3d5:4ecb:43af with SMTP id 5614622812f47-3d54ecb448emr5939923b6e.27.1719337195643; Tue, 25 Jun 2024 10:39:55 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-444c2c3e5b5sm57640161cf.75.2024.06.25.10.39.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 10:39:55 -0700 (PDT) Date: Tue, 25 Jun 2024 13:39:54 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , Jeff King , Jiang Xin , Jonathan Tan , Junio C Hamano , SZEDER =?utf-8?b?R8OhYm9y?= , Elijah Newren Subject: [PATCH v7 10/16] bloom: annotate filters with hash version Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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 Tue Jun 25 17:39:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13711761 Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) (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 37FFC176AC5 for ; Tue, 25 Jun 2024 17:40:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337201; cv=none; b=P5bbwap3t4lTQql3yfbEVUx+MYO0uTKYyjehb5OxA1ysLKuoB4fcln8cCYbuJFSaqqs2zNy2zgLbXLgvaEsRGiqcfYeyBANRYFL2FX3t1O3E8WyVXu1rA9O47P2ldJv7/ZhykoZJ1ww7AyDfWkQQPWzVX9Ye1xDWCqH00GFamUE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337201; c=relaxed/simple; bh=uuf6Qkp5eRaQyMMLmuQsuR92oFbDgOwgNn8tf1nVnNc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PgYfxQK8DSFrS0J/825zN5axag3LrS0ohRlTBfpTGCqLAeW8iJEBxw+j/quCsT/4YE52cqUJBWPAZi59XAezex5AbfFAWrtqKfQwmIFhVxWUHBrI1LP/VrrVaK05xuqJysN2JWwy1DHw4kXnRUbQhjdRdeS0+SY/4GcsxUA3wTY= 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=g4NZovwk; arc=none smtp.client-ip=209.85.219.43 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="g4NZovwk" Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-6b2c6291038so45758636d6.0 for ; Tue, 25 Jun 2024 10:40:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1719337199; x=1719941999; 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=9YxQ/CZVncWLlMe30ZL35K6LfZ16N4CyQDQIJ8XtVbQ=; b=g4NZovwkId5xMECXNwZ24eZGThmvTWTSjwS4XAqOygihvh9Wat354KczSzHWe6w6zV Ml6Yac/WKO3q81rm5M5dNIOmzCv8aS53Cd6j36dl/e+KwbQgjL+3s9ywvmfRIsn1ylbK fv6F8mAvZ8KkqYt8zKnaKN6RqTrF6Nf2f0JAK8wrF5VvAohdY2rAnP2n+revZ+Y8b60d CfL3OlhiyqErXv+2bY0xo/8FFhmNva/y52UcOJWAs+Zr1DFJL1BHdeWDtW04AYiW2jJx faJ6MDDwKfBT9RCffBu38PwhFAF9T1ZIgSmu80wCIj5Sf3d6yCDc0mpE11e4mvy4tunc k3Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719337199; x=1719941999; 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=9YxQ/CZVncWLlMe30ZL35K6LfZ16N4CyQDQIJ8XtVbQ=; b=ugd3iGxHYiUID2H7oYLU7lneJli6MbGNvSxJOV0jRNZAdiPOuZnnGWDzQusnZoHaZh xqSe6Yu7Xl1vy8FpB5P1MoWHXMdLrOm5ELWKZKe+2aRCiO0qv0QKJDOtf53Q0t7bz6dd eJj0Fqo0fvvpKoAxek1HOUwJ3qS6fw6Vt+d06h/brcll2PCByPeJe1yW4bQa0u7zEQbz a5oNyjyFeOMgLoh9gj/OFCFZ1/FCIl4abRWbgyMIlw7RL59mr1fKoyXIpwm6bp7zmdCx +qS6ePO5ezg6oQ+bvldD+PaAydG22tgk+M6w59Bz94q8auPviw8x04RCqOB3B613hzjL altw== X-Gm-Message-State: AOJu0Yw5olgKTjRHkYPmYP+Akrf4k5qjw2JgJ/VHY9rIA8Y4uAYcgtGI +IflWdIihQrHvs8ZQc5/xa3dhVGVwQH7+mU92CaOO0gKtZDJ2W1XMEPqTAHVNet5ihLb4i0yetM AqZs= X-Google-Smtp-Source: AGHT+IGK18hXFoWigF0xdbsf9P5QCItsqIUWHblrJ6qjTWWip1gEFk3SgJLmaPNPUZgdoljhRjS8qw== X-Received: by 2002:ad4:4d4a:0:b0:6b4:ff88:5363 with SMTP id 6a1803df08f44-6b56330a5d6mr65941856d6.13.1719337198943; Tue, 25 Jun 2024 10:39:58 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b5223fa4d4sm44329756d6.78.2024.06.25.10.39.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 10:39:58 -0700 (PDT) Date: Tue, 25 Jun 2024 13:39:57 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , Jeff King , Jiang Xin , Jonathan Tan , Junio C Hamano , SZEDER =?utf-8?b?R8OhYm9y?= , Elijah Newren Subject: [PATCH v7 11/16] bloom: prepare to discard incompatible Bloom filters Message-ID: <99ab9cf448eea65db1a561a79223fe70073d1be0.1719333276.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: 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 Tue Jun 25 17:40:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13711762 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 CD9D9176AC5 for ; Tue, 25 Jun 2024 17:40:03 +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=1719337205; cv=none; b=TEkPEr6sGWOmHLfEKedLcyCpI5Jj1kFuJrVRZiQa14vb7eJCbh2LBKix+E+CKjhAD7VMbA1wQ2mSzPNQX46lK8WyOD7IQSVBR8gXNFznMjGL82VGMBzpsW+Jx1uMSIBSHTmI69jO4TbNFcMk9VGesWcyWoV6J5gWMBgz2iu3XYE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337205; c=relaxed/simple; bh=57yMmr9vAbwChO6+SRkpKoA11gx9FtkKwB5rQr67Y4g=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jGANX3xOs0insD2ObDUcqM9Zne+NeV7AuYivoEzU/BhfZ+BD2CJ6A5Udek60yqPUmzmJaCfKjoH6w1BecdvLrXKh9fXycpEAEnW7jTEDnfeMEguI+o9XbItmOd8t7IhExRmeMcqZjPubbVbIXTpr3TAqb+eZ8h24/Zj4+1wGttE= 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=tMbvgk8Z; 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="tMbvgk8Z" Received: by mail-qv1-f41.google.com with SMTP id 6a1803df08f44-6b505f11973so48774236d6.1 for ; Tue, 25 Jun 2024 10:40:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1719337202; x=1719942002; 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=TvFXyyN2OaU/u75fN6VWxaQwCGVrJ/qgw7a5GtATHY8=; b=tMbvgk8Z/F9w7myu7EENPG/nQe+0vg+GKLtkLLBypU+kf5DVlw1IUrhSfCymzuj7of H2i5QCMX/4KD9fc5BvotAUlKKcGsmcZUlCV+jDPKUrWp99sdEPob7u06fXCOK/bGTjuR Q0FoO1uKyfc3f5mruMo/zvjWXUOQh1navpOyKewZLHz1F+98G4XYL1pNYlUMU2PKysVn OrTPKc9E70ZkSPuARz2XUJjmngh/xYUJFVEi6eblWxuxjjf4sr3j1JVKaZqSD5F4SVdf 5U0NiTahd9HwHrWbyoiVWECWfuSPaaWFNnkSvt/rAf31qUVpQiMb0jgKb71jGKWgak6Y p9lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719337202; x=1719942002; 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=TvFXyyN2OaU/u75fN6VWxaQwCGVrJ/qgw7a5GtATHY8=; b=YBEhun+uoYIspQQEC0o+aAtAPm3bb7mn4x20DzJFi4eS5Zk0Z/8Vu1Ra0wSDKq2L9P 2P4FlBtXQO1W9RrL1cf+ZAR5uMF6s5H1kgUthakxM7fhEkn1xyPnNjBN3qm+Ffk6P8C2 EcxU/arwOy71pexRDQxtuiZg3qzzhMbUeMrN6R+LqKIyDEmYpRQAiGgwajwWac3cIKaQ zY5pgQGcHU3+hvo02M5z3vt63K/LZ+DIPqgxAtKM91KESpa6IJG6iUp2o7rQAhV+n5hB zgByRJFUxTdMU2BtbFayK8OuD34rs+ws1qMILUKnbQ9QEyPMw0EK64LQxNXKWwVKEF/2 6fjg== X-Gm-Message-State: AOJu0Yz0RVnTb8cJ4Qy/SK3QYi/TpIuY/fwEze6k+FkDbiSar1zz+gZG u00JCSY6bpMrKeA9MoynspylMUxNDchmxP8rqiFg1dFw99xuZFcdDHFK3jxNMwbJ8wKGLk07XUs unDk= X-Google-Smtp-Source: AGHT+IF2lo8z6uSmHPtrKIgSd1sz7j+y7AgS/4H6P4e4F5jrKap7y2uBwlhJ936TKpVuIPRvyoJrpw== X-Received: by 2002:a05:6214:301b:b0:6ad:84aa:2956 with SMTP id 6a1803df08f44-6b532038fc8mr132975776d6.13.1719337202329; Tue, 25 Jun 2024 10:40:02 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b5265bc978sm41390626d6.43.2024.06.25.10.40.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 10:40:01 -0700 (PDT) Date: Tue, 25 Jun 2024 13:40:00 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , Jeff King , Jiang Xin , Jonathan Tan , Junio C Hamano , SZEDER =?utf-8?b?R8OhYm9y?= , Elijah Newren Subject: [PATCH v7 12/16] commit-graph: unconditionally load Bloom filters Message-ID: <99e66d1dba5c4d7d57859ba5f6ef9e0d349dd356.1719333276.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, 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 87b07e7b85..8129a4f5dc 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); @@ -2514,6 +2511,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", @@ -2545,10 +2543,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 Tue Jun 25 17:40:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13711763 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 7AF30176AA9 for ; Tue, 25 Jun 2024 17:40:07 +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=1719337209; cv=none; b=HyDZ2DGAR7Vr4GKqv3su28vrVvDwxoez12OHFxdcUXOVo40xqfwzQFuC+nFAIK+OIp+6vcTayiRzWpDa6LRuDNXWKKcNd0Vyqmz6podmFU6w67O/6of7eHkqiwM9FzFzQIISziZGW3ovtMvyjH+OywvFb6/ckeZCEGAumzk6wBs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337209; c=relaxed/simple; bh=CmPzFrYg0qr5M9s9AHgYI0SyOYyZp8VI/fUWgFLFCoo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GKjOy5Uh2RIZu2U+ctpLETdfMTqZE0Uk8b0MKbpyecJpvPlqi5ZfhooJWU1Ah7auRSeN4wASYrmRUWupQBnxvvKO7ZT3Svvxxzb+75snxLcMihkpdEuglIyxHrfEJobxPEQn17zOTUNs6snWKdCBmQykrohiFX0FBXbPgfVoJO8= 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=qLt1SVkr; 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="qLt1SVkr" Received: by mail-yb1-f174.google.com with SMTP id 3f1490d57ef6-dff0712ede2so5686541276.2 for ; Tue, 25 Jun 2024 10:40:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1719337206; x=1719942006; 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=NRgkspQdOJYlPIpbMbNw7+qBNTZYY7v7oD/+fbbZu70=; b=qLt1SVkrQfXE5KHUQVRc/dyy+tLWEH0d3FjsI1AymTeQiOQyby0tGYk4THjBEMp5bQ AZIsBtEsrvTACiNh31ROZXspVGvR6M4Hyp2N4U9os7watE1B3v418SuDU05z5IN4uvfW wMAME8M8PjlOpZpiAGVf8hdHD65KbHuQ3AQGuAklmke2bGvAXAlCsOWbT3e51dwbaVQ7 e/ohnRdAgkhb8gGWPqJkc1SQvNhu9U+WVfpf+XAIldBAATbw3zw3tP70yoU/BFYbWHVm +PWuWa6fjQjSesWJy25DzhTcnxhczhLrhk9hXAUzpcfsSoe1jXRFhZ5AKb6ftl3WjIdD QjUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719337206; x=1719942006; 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=NRgkspQdOJYlPIpbMbNw7+qBNTZYY7v7oD/+fbbZu70=; b=VWPXlVWe/WR8GUTE8zDOKrJrzwkQON4q21NH1dWAFBNBDEfeSij+Hj6Bbp1YcupVXW DmZoqMxJVs5vTXcBg4+WgJXVsjgD+a7fBlUIftytBf24MO9J1duwwYbNr0OThJksJwLB kxexT/BAc2Wk6KNx0rQEy9vfW50mg6yz3kMNmA1VqJKFAzaS/PKGuJBrKw2f5gpzHWTI 2MVAWQny3xRX+qaodDFqO5Ul7BA/EgFFYfb6KEw+MipboR4h7GoJwssug2YUbr2TEWFz tITvZeknA/lwNDM8RNyo6MjlrodmNJikGJCPirycrZwtTWAVobaQZPHK7NRQBAwWuH1z aNCQ== X-Gm-Message-State: AOJu0YzG0elwjdfV0L3OjO6Ij36tOvZtLo4TqZ4Qsbf+QfVNSv5s3/mL CzzPMO4H5WbcKWai1Xp+Rlg1m7yT1trF5JjmPcnZfZC2U8EfQRVTFvqzeuHc4oN9TjKpVce5lIN cva0= X-Google-Smtp-Source: AGHT+IEr5zSQSltHuqIuGZV3vIplAoUF57ThZjVB7kv2bJf+xGLyYjIUI3r9YfKdDP3HS6zo3nwsgw== X-Received: by 2002:a25:8688:0:b0:e02:c36f:1fba with SMTP id 3f1490d57ef6-e0303f3c7d1mr7580606276.14.1719337206072; Tue, 25 Jun 2024 10:40:06 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b546709673sm26424736d6.37.2024.06.25.10.40.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 10:40:05 -0700 (PDT) Date: Tue, 25 Jun 2024 13:40:04 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , Jeff King , Jiang Xin , Jonathan Tan , Junio C Hamano , SZEDER =?utf-8?b?R8OhYm9y?= , Elijah Newren Subject: [PATCH v7 13/16] commit-graph: new Bloom filter version that fixes murmur3 Message-ID: <2e945c3d2e3ac6b5cb3e56689691b6f251a77262.1719333276.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 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 | 155 ++++++++++++++++++++++++++- 7 files changed, 252 insertions(+), 15 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 8129a4f5dc..c1177631bb 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; @@ -2499,6 +2497,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; @@ -2541,7 +2546,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 49d1113171..cc6e5733f6 100755 --- a/t/t4216-log-bloom.sh +++ b/t/t4216-log-bloom.sh @@ -488,14 +488,49 @@ test_expect_success 'merge graph layers with incompatible Bloom settings' ' test_must_be_empty err ' +# chosen to be the same under all Unicode normalization forms +CENT=$(printf "\302\242") + +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 && + + # Merge the two layers with incompatible bloom filter versions, + # ensuring that the v2 filters are used. + >trace2.txt && + GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \ + git -C $repo -c commitGraph.changedPathsVersion=2 commit-graph write --reachable --changed-paths 2>err && + grep "disabling Bloom filters for commit-graph layer .$layer." err && + grep "{\"hash_version\":2,\"num_hashes\":7,\"bits_per_entry\":10,\"max_changed_paths\":512" trace2.txt +' + 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" && @@ -539,6 +574,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 Tue Jun 25 17:40:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13711764 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 67C51147C74 for ; Tue, 25 Jun 2024 17:40:11 +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=1719337212; cv=none; b=ZhkrXFC2yq5DiJGSPlIrlT4wHGFzcxmFacgWm2I/na0VZhccVZmOYgGlh2lwEHQ56gN/+XlRAUeJBbtKlil8gIwK1TbVw00yHAI/6iggibSbUNmvPPlUfIG+yy/tx4O6bL58g0YWkwn1Adh0b+WSrqcaeHYJhDG7isjzjTtJIi4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337212; c=relaxed/simple; bh=/cZ1HueBLXv1D4w+L11jbLDFm1XV1wXUUm6PU473iVE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LeKvSBKOrIKJXwmK8Hqga8kFSlHHxcxgjhD9Ym6Su2tK7rarDvE9nDHLfUu/l7QEhvQCS4SUDp1bKeYd8zvsBeHZYMpKkLCKLLDTJmb5bqvvUiJTG1g1UTl6ai4f3sdhdPD3a0nEu7kCYRK8gWrUz7XZ0SS54yPzFyX+Nm8UbLU= 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=cUSZwbJg; 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="cUSZwbJg" Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-795569eedcaso306085885a.3 for ; Tue, 25 Jun 2024 10:40:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1719337210; x=1719942010; 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=rvkxjfmXzuvpa0ad46fYcL5t/G8FT2GID4hxoaI33Ok=; b=cUSZwbJgyqUR8gOIAKRnT64uXCFdNI2/CYjoDUsavBxI/tVZM8uiZlovUlzwcr26hL rS//3tfLqiFtNUrzGtf7P/NY7QU8JgFy/Hx/RyixPjrz0XGMgv8bJYty8sZ5WOl/6MrR 59JJUCSm00epHM5rqnpq6RNAVnSTXXxSIGvm4hKrmvCHTRoUcWSmt/+vyCMSfnwDKViw lXCvbWFn2ZvmrAbvX2dW90dn9oqHFk/G0sDCzmQ19Oj5shQIEL2hnfWjErav2/sr/liH ngv+8EkL5+9CeeKa5E9zA8Tp/+f4DvgAVfTEgh4leGv2SBpWBCiVa8sYOYanqWhvDxJA e0Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719337210; x=1719942010; 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=rvkxjfmXzuvpa0ad46fYcL5t/G8FT2GID4hxoaI33Ok=; b=hKCpsVI1r6kArXlQf/u6NZSL2qCspsfg0SHLJ0obI+4Pa8Dh4CF1mFAL0+d/s3+GOc e8DbHwijnu9qFRjtXc9M7W22Qzb470Xbsx7rbglK9SHHNZ/j5fgIk8ikYXfpoz/ZL/A+ XgoajJ9d2fMrcU/EdmS8EIgzkmqUXwOkEZWBMr57Dx9v5rwyqDOBxWTd4hz+JdJcOlSh B3VqHJ/21CFbsBEvJ63lMA9amriMwcYzxekwdk+bq7xBNaGqED1HCiAAaWlKVDtDuDwg /U/Y9PUvKnk9fyp1EKdlakBXp9DsTjKAQK+LexvLaIIwujHi2JgZ/oYS9FF39kz3bP/9 CbXQ== X-Gm-Message-State: AOJu0YzyRzlv+GA7CBtW1VqV1jVGaH9U1eqvuUyJXJFy/jNRoWzvqOqD QNTV3Vl4YZAV2q8/g8qakYkIVLtdKfVgZl4jW3a361XyrumtxKg5QlWAWSCLwzsRQzIoDq6qK3n CKWQ= X-Google-Smtp-Source: AGHT+IFDfJD5Zkr6Q/xaLyfE5gNhXB4qSAz7/n/uSvjn4GWXTNrUyPzDGlqs4gXy+dU23/Kqg0Sa1A== X-Received: by 2002:a05:6214:4c05:b0:6b5:9fa:3224 with SMTP id 6a1803df08f44-6b54099a199mr84670156d6.13.1719337209185; Tue, 25 Jun 2024 10:40:09 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b51ed16142sm46863236d6.31.2024.06.25.10.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 10:40:08 -0700 (PDT) Date: Tue, 25 Jun 2024 13:40:07 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , Jeff King , Jiang Xin , Jonathan Tan , Junio C Hamano , SZEDER =?utf-8?b?R8OhYm9y?= , Elijah Newren Subject: [PATCH v7 14/16] object.h: fix mis-aligned flag bits table Message-ID: <242f023135cfc2301576786172639cc5664d3449.1719333276.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 669b6a18fa..d2f9de6bb5 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 Tue Jun 25 17:40:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13711765 Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.45]) (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 A0F71147C74 for ; Tue, 25 Jun 2024 17:40:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337216; cv=none; b=JUUlRBSJWX84+vB9BVoJrk7xa7VCqAy+xdOVqylPXEwrbn+R+vrakDlO8UxeV9pzAjP4GrBcOwbTe6XVhJ8z2oYrmREM3CuC2iv04npa4sxnl53RzqqAOPxVkEFLntABgkfrwJtBXmyYEo0XUR6OQKzYzxikT34/KBcA2DkQpBc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337216; c=relaxed/simple; bh=jJWgJ87/1kwoUVAqtFCbm+VX1dIMDQMItt7HH+ZM8Gs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NkuBkBdwG0d4ii93GcDWwEqkNgdShKRUt+58TUeIy8G98QLd2+1kQzJyhHK5wcMc8j+T0lh4D6eodZkrarj6RRzFhtqYoxLF2TjqdffqApaPIvn305G4gJg/s6iw34UDcJB8u2BSdFNxyDCuofIJq1pRHRd5um+cXnbE/lBfZ7Q= 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=yPSbOOTD; arc=none smtp.client-ip=209.85.161.45 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="yPSbOOTD" Received: by mail-oo1-f45.google.com with SMTP id 006d021491bc7-5c21f3fbdd3so74526eaf.2 for ; Tue, 25 Jun 2024 10:40:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1719337213; x=1719942013; 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=UJAIsPkUFBKA/UN4l9nn4xwTqPX839jcQOTeSFBAZJ4=; b=yPSbOOTDAPwSgbvOQDpbc9AZwBwJB3zFJ8gb4JCSCq6FFsSSs2PAFuD0fQAWGEP3vV kPWhK8TkAaxeZztRufcKS3BpptnrDkVNto2JkX3Kva07Hfbh4MKDNIOyGV/VqoAvjYff vOjVA1wo0EaFR4NnpXF/be3CNNEc3WauUeSPyw6jTqsZ4wLyjgByMcb/fxCJizosqx7M w5TOkmnavUMze9xZVEhkh9TKXMnHkwNwKZj2eeLtJJ+lC+pofN2tVi/k2gcaR7lGdQLA Ty14zCW4uZSYSdPDJmpp1NQLkEGaor87qcHyrQ/Y+9zPNTjPJDv6QAzwy752sYIDjYXB WM1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719337213; x=1719942013; 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=UJAIsPkUFBKA/UN4l9nn4xwTqPX839jcQOTeSFBAZJ4=; b=ZqkiM0HQ/L95FxgdAIQj3w0xEdA4qiDFelEDK7A8mDH/QzbvFzf9e2PIIFrYY+kT/y sCUGewSyLDH1vzuo1XlFR8qySRtp8+j8jRteraPTFM+2piT3HcHZc7eA7HuxfcwmvwBc AWZFZWuxGAZCfshhZy+yxpjpk/m/i5ALG9jP+72L4BCJjGnZ+RPMomZdaGBYBg8n+dYl r4pDd7MWt43l1Ly2q5xCAGnv1zXKoAXoD4tYWql82Wnrc4APPehmcgI2V92UY99aOfc3 DHcQcybjQ+RiKxOALsvdkEjoQftpjRyfi6eQaQuc6gAxJwgm9y5dWwOZWNzlJTQZ1gOk WtmQ== X-Gm-Message-State: AOJu0Yw/qZ8Kbbcn4lfP9qGTUT24OJE28s+iftpQTp+wNrhi9c1t/Kks 58uCKD2CE7ew4QcJ7BierAzPkFpeQSImy1jno5yG8gEB3+nPMsyBqDF/6CMjjO2J+ZMvFHdkr7j B+34= X-Google-Smtp-Source: AGHT+IFmLzy3f4BEJ5MVlLTLrXTFxFWZzcvQwvpqN7Hi0gTJVmxKppnoBWYuUCER50+awembI7XsMQ== X-Received: by 2002:a05:6870:d204:b0:254:ccac:133c with SMTP id 586e51a60fabf-25d06e5a2d9mr9317499fac.41.1719337213531; Tue, 25 Jun 2024 10:40:13 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id af79cd13be357-79bd711418dsm357893585a.4.2024.06.25.10.40.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 10:40:12 -0700 (PDT) Date: Tue, 25 Jun 2024 13:40:11 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , Jeff King , Jiang Xin , Jonathan Tan , Junio C Hamano , SZEDER =?utf-8?b?R8OhYm9y?= , Elijah Newren Subject: [PATCH v7 15/16] commit-graph: reuse existing Bloom filters where possible Message-ID: <1b80023e57cc61e6d7f9bffbc0426c703ddce31a.1719333276.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 | 39 ++++++++++++++++++- 5 files changed, 132 insertions(+), 4 deletions(-) diff --git a/bloom.c b/bloom.c index 323d8012b8..740c1767ea 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->object.oid, 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 c1177631bb..2f0a08f302 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 d2f9de6bb5..0a04661a34 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 cc6e5733f6..3f163dc396 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 && ( @@ -667,7 +671,14 @@ 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 && + >trace2.txt && + 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 @@ -678,8 +689,14 @@ 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 && + >trace2.txt && + 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 && @@ -688,6 +705,26 @@ 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 && + >trace2.txt && + 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 && + >trace2.txt && + 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 Tue Jun 25 17:40:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13711766 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (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 57544147C74 for ; Tue, 25 Jun 2024 17:40:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337219; cv=none; b=OZ7MSfRlATytIOKe5FwcukiTwrO990KVLaYYeRBgti/O8bK5eIRjPJRNEUWWhtHnsBtVuengW/o+UeC0DDKiTN5hIbZENE//0PrMs0RF/Qb4CefKn7DNFhP5XAZOpvYe5NIZ0jjm188EoGEjHJUsYhlD0INlVaUuGJZq8PqmSHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719337219; c=relaxed/simple; bh=ojcbMuB1E2tSdBKHQAD3AmRSmi3YgxAw3pW7HuOE/d0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EJup2CkUYv7dBD+NM1i+q4xbJBBhgQtLIaOap789DQ3E0eNVhflrEq7IHfO2GEfiOPwmHae0Hx3xhzcwDYgvEk1PpYMaxhqwDGbpQeDEnQFcQSWjBX0n1VSluPjxuAUPwfkY8aAF2qIyedGxFCn58XIK+JyrOoT4xRd5dqt98Pc= 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=d0OB/zzo; arc=none smtp.client-ip=209.85.222.173 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="d0OB/zzo" Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-79c10f03a5dso21373585a.0 for ; Tue, 25 Jun 2024 10:40:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1719337217; x=1719942017; 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=IfNKn3C7TDjPbsX5uodEZ/FaBSWhJexijVXkNTwpPow=; b=d0OB/zzoZZ1wdgnOB5pQn0WgAw3bHcCR1IB9jSql9rHIAmCV9s2UnOkplOhus5NNAX saYACm5gjiTOC50cY9mTVFSbbPYtgNeSjtg0necOo33lv8NsZExi2CSN8/41uXbnflOu gcfausvHRq87HO4hLsjferuK6nPxjYiIegKDta/vqgs+AHXJeJ1AQ/wHsbhDR+CMVLqL F5c2xpH3VeTc7KPj35lP0C/NDZQP8O6zOhEwn3q2m7MOrc9t5Q6UZ80VwIVbXobPbxqF JoWXGqto5fnyotj8zNqoxttz0Y7XEXHVoJDeWmV31j8xVTwhDTcyZapYrfzUoAWTv+fS 5iBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719337217; x=1719942017; 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=IfNKn3C7TDjPbsX5uodEZ/FaBSWhJexijVXkNTwpPow=; b=RC5DHcHoxYyOZYr0HxHMlw3kPQ+8uxuS8kZyaC6IajtI68vGCds8dmfFC2Kn58iknB Ghw+FxPGSIroPEX1H/TeC71CgERHl67SUhEVCmzrB2w58QDscGXWZck09Ibb/mBIeRcH 9eBVjiUrwAZ0LKxIs40db4VENnKGUWdTXc5Pg0gNL7yBWgufpzLBucM1Ev9uKaPkBvEr 8icOQcMFYl9fCZ5HeOR7d9xMU5DiTt8vT6xeWIwh6+1AGKT3a7Sheu1+Qcxh7ETquWAc UBrS6UnMYvc4WlaW8GVt9/gNeZHAq1w05396SVaXmHzvN9K0ucKhWl+m0Jxv7goJS/66 WgyA== X-Gm-Message-State: AOJu0YwVtBdq3soSP7J2K9SVlUL3bzluNC1v9hacLGBTpl5CxUQHI1sC MRWzTPg1TdLsvmDunMWzqJWTJGf6PTBU+al4vKEb0Ug+ooqYr1MwZtv3EbssfNyZpx/38dDFTaq TFCE= X-Google-Smtp-Source: AGHT+IHoH75bcqnqrF3HsIqfsUz3TP4rpsabEL0/3+6IfSeGgYm5dXNQDEsch5X4GS5jQsdZ2E5Jzg== X-Received: by 2002:a0c:8bca:0:b0:6b0:7a47:ca7a with SMTP id 6a1803df08f44-6b540a92d85mr74417886d6.42.1719337216696; Tue, 25 Jun 2024 10:40:16 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b51ef694fcsm46127716d6.131.2024.06.25.10.40.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 10:40:16 -0700 (PDT) Date: Tue, 25 Jun 2024 13:40:15 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , Jeff King , Jiang Xin , Jonathan Tan , Junio C Hamano , SZEDER =?utf-8?b?R8OhYm9y?= , Elijah Newren Subject: [PATCH v7 16/16] bloom: introduce `deinit_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: 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 740c1767ea..d080a1b616 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 2f0a08f302..c02bef7e72 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; } @@ -2647,6 +2648,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);