From: Junio C Hamano <gitster@pobox.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 4/8] reftable/stack: simplify tracking of table locks
Date: Fri, 02 Aug 2024 16:00:52 -0700 [thread overview]
Message-ID: <xmqqy15e8r8b.fsf@gitster.g> (raw)
In-Reply-To: <40d9f75cf20d4b76adb1683709e054e264d4e06f.1722435214.git.ps@pks.im> (Patrick Steinhardt's message of "Wed, 31 Jul 2024 16:15:06 +0200")
Patrick Steinhardt <ps@pks.im> writes:
> - size_t i;
> + size_t i, nlocks = 0;
>
> if (first > last || (!expiry && first == last)) {
> err = 0;
> @@ -1051,7 +1051,7 @@ static int stack_compact_range(struct reftable_stack *st,
> for (i = first; i <= last; i++) {
> stack_filename(&table_name, st, reader_name(st->readers[i]));
>
> - err = hold_lock_file_for_update(&table_locks[i - first],
> + err = hold_lock_file_for_update(&table_locks[nlocks],
> table_name.buf, LOCK_NO_DEREF);
> if (err < 0) {
> if (errno == EEXIST)
> @@ -1066,7 +1066,7 @@ static int stack_compact_range(struct reftable_stack *st,
> * run into file descriptor exhaustion when we compress a lot
> * of tables.
> */
> - err = close_lock_file_gently(&table_locks[i - first]);
> + err = close_lock_file_gently(&table_locks[nlocks++]);
> if (err < 0) {
> err = REFTABLE_IO_ERROR;
> goto done;
The only unusual control flow in this loop that runs i from first to
last is to leave it upon an error, so "i - first" and "nlocks" is
always the same, at this step in the patch series.
> @@ -1183,8 +1183,8 @@ static int stack_compact_range(struct reftable_stack *st,
> * Delete the old tables. They may still be in use by concurrent
> * readers, so it is expected that unlinking tables may fail.
> */
> - for (i = first; i <= last; i++) {
> - struct lock_file *table_lock = &table_locks[i - first];
> + for (i = 0; i < nlocks; i++) {
> + struct lock_file *table_lock = &table_locks[i];
> char *table_path = get_locked_file_path(table_lock);
> unlink(table_path);
> free(table_path);
And this one at this step in the patch series is skipped if the
earlier loop saw even a single error, so again, this is a benign
noop change.
> @@ -1192,8 +1192,8 @@ static int stack_compact_range(struct reftable_stack *st,
>
> done:
> rollback_lock_file(&tables_list_lock);
> - for (i = first; table_locks && i <= last; i++)
> - rollback_lock_file(&table_locks[i - first]);
> + for (i = 0; table_locks && i < nlocks; i++)
> + rollback_lock_file(&table_locks[i]);
This is a true bugfix, isn't it? If we failed to create lock file
somewhere in the middle, we used to still go ahead and attempted
rollback_lock_file() on all of them. Now we rollback only what we
successfully called hold_lock_file_for_update().
I wonder why nobody segfaulted where after a failed lock. The
answer probably is that lk->tempfile that is NULL will safely bypass
most of the things because is_tempfile_active() would say "false" on
such a lockfile. But still it probably still were wrong to call
rollback_lock_file() on a "struct lockfile" full of NUL-bytes, and
it is good that we no longer do that.
> reftable_free(table_locks);
>
> delete_tempfile(&new_table);
next prev parent reply other threads:[~2024-08-02 23:00 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-31 14:14 [PATCH 0/8] reftable: improvements and fixes for compaction Patrick Steinhardt
2024-07-31 14:14 ` [PATCH 1/8] reftable/stack: refactor function to gather table sizes Patrick Steinhardt
2024-08-02 20:26 ` Junio C Hamano
2024-07-31 14:14 ` [PATCH 2/8] reftable/stack: test compaction with already-locked tables Patrick Steinhardt
2024-08-02 21:05 ` Junio C Hamano
2024-08-05 12:11 ` Patrick Steinhardt
2024-07-31 14:15 ` [PATCH 3/8] reftable/stack: update stats on failed full compaction Patrick Steinhardt
2024-07-31 14:15 ` [PATCH 4/8] reftable/stack: simplify tracking of table locks Patrick Steinhardt
2024-07-31 21:57 ` Justin Tobler
2024-08-02 23:00 ` Junio C Hamano [this message]
2024-08-05 12:11 ` Patrick Steinhardt
2024-07-31 14:15 ` [PATCH 5/8] reftable/stack: do not die when fsyncing lock file files Patrick Steinhardt
2024-07-31 14:15 ` [PATCH 6/8] reftable/stack: use lock_file when adding table to "tables.list" Patrick Steinhardt
2024-07-31 23:02 ` Justin Tobler
2024-08-01 8:40 ` Patrick Steinhardt
2024-07-31 14:15 ` [PATCH 7/8] reftable/stack: fix corruption on concurrent compaction Patrick Steinhardt
2024-08-01 1:04 ` Justin Tobler
2024-08-01 8:41 ` Patrick Steinhardt
2024-07-31 14:15 ` [PATCH 8/8] reftable/stack: handle locked tables during auto-compaction Patrick Steinhardt
2024-08-02 23:24 ` Junio C Hamano
2024-08-05 12:11 ` Patrick Steinhardt
2024-08-05 13:07 ` [PATCH v2 0/9] reftable: improvements and fixes for compaction Patrick Steinhardt
2024-08-05 13:07 ` [PATCH v2 1/9] reftable/stack: refactor function to gather table sizes Patrick Steinhardt
2024-08-05 13:07 ` [PATCH v2 2/9] reftable/stack: extract function to setup stack with N tables Patrick Steinhardt
2024-08-05 13:07 ` [PATCH v2 3/9] reftable/stack: test compaction with already-locked tables Patrick Steinhardt
2024-08-08 10:46 ` Karthik Nayak
2024-08-05 13:08 ` [PATCH v2 4/9] reftable/stack: update stats on failed full compaction Patrick Steinhardt
2024-08-05 13:08 ` [PATCH v2 5/9] reftable/stack: simplify tracking of table locks Patrick Steinhardt
2024-08-05 13:08 ` [PATCH v2 6/9] reftable/stack: do not die when fsyncing lock file files Patrick Steinhardt
2024-08-05 13:08 ` [PATCH v2 7/9] reftable/stack: use lock_file when adding table to "tables.list" Patrick Steinhardt
2024-08-05 13:08 ` [PATCH v2 8/9] reftable/stack: fix corruption on concurrent compaction Patrick Steinhardt
2024-08-08 12:14 ` Karthik Nayak
2024-08-08 13:29 ` Patrick Steinhardt
2024-08-05 13:08 ` [PATCH v2 9/9] reftable/stack: handle locked tables during auto-compaction Patrick Steinhardt
2024-08-06 18:46 ` Justin Tobler
2024-08-07 5:31 ` Patrick Steinhardt
2024-08-07 19:12 ` Justin Tobler
2024-08-08 12:25 ` Karthik Nayak
2024-08-08 12:26 ` [PATCH v2 0/9] reftable: improvements and fixes for compaction Karthik Nayak
2024-08-08 14:06 ` [PATCH v3 " Patrick Steinhardt
2024-08-08 14:06 ` [PATCH v3 1/9] reftable/stack: refactor function to gather table sizes Patrick Steinhardt
2024-08-08 14:06 ` [PATCH v3 2/9] reftable/stack: extract function to setup stack with N tables Patrick Steinhardt
2024-08-08 14:06 ` [PATCH v3 3/9] reftable/stack: test compaction with already-locked tables Patrick Steinhardt
2024-08-08 14:06 ` [PATCH v3 4/9] reftable/stack: update stats on failed full compaction Patrick Steinhardt
2024-08-08 14:06 ` [PATCH v3 5/9] reftable/stack: simplify tracking of table locks Patrick Steinhardt
2024-08-08 14:06 ` [PATCH v3 6/9] reftable/stack: do not die when fsyncing lock file files Patrick Steinhardt
2024-08-08 14:06 ` [PATCH v3 7/9] reftable/stack: use lock_file when adding table to "tables.list" Patrick Steinhardt
2024-08-08 14:06 ` [PATCH v3 8/9] reftable/stack: fix corruption on concurrent compaction Patrick Steinhardt
2024-08-08 14:06 ` [PATCH v3 9/9] reftable/stack: handle locked tables during auto-compaction Patrick Steinhardt
2024-08-08 16:52 ` [PATCH v3 0/9] reftable: improvements and fixes for compaction Karthik Nayak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqy15e8r8b.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).