From: Neeraj Singh <nksingh85@gmail.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org, "Jeff King" <peff@peff.net>,
"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Junio C Hamano" <gitster@pobox.com>, "Eric Wong" <e@80x24.org>,
"Neeraj K. Singh" <neerajsi@microsoft.com>
Subject: Re: [PATCH v2 3/3] refs: add configuration to enable flushing of refs
Date: Wed, 10 Nov 2021 16:18:03 -0800 [thread overview]
Message-ID: <20211111001803.GA787@neerajsi-x1.localdomain> (raw)
In-Reply-To: <d9aa96913b1730f1d0c238d7d52e27c20bc55390.1636544377.git.ps@pks.im>
On Wed, Nov 10, 2021 at 12:41:03PM +0100, Patrick Steinhardt wrote:
>
> +static int sync_loose_ref(int fd)
> +{
> + switch (fsync_ref_files) {
> + case FSYNC_REF_FILES_OFF:
> + return 0;
> + case FSYNC_REF_FILES_ON:
> + return git_fsync(fd, FSYNC_HARDWARE_FLUSH);
> + case FSYNC_REF_FILES_BATCH:
> + return git_fsync(fd, FSYNC_WRITEOUT_ONLY);
> + default:
> + BUG("invalid fsync mode %d", fsync_ref_files);
> + }
> +}
> +
> +#define SYNC_LOOSE_REF_GITDIR (1 << 0)
> +#define SYNC_LOOSE_REF_COMMONDIR (1 << 1)
> +
> +static int sync_loose_refs_flags(const char *refname)
> +{
> + switch (ref_type(refname)) {
> + case REF_TYPE_PER_WORKTREE:
> + case REF_TYPE_PSEUDOREF:
> + return SYNC_LOOSE_REF_GITDIR;
> + case REF_TYPE_MAIN_PSEUDOREF:
> + case REF_TYPE_OTHER_PSEUDOREF:
> + case REF_TYPE_NORMAL:
> + return SYNC_LOOSE_REF_COMMONDIR;
> + default:
> + BUG("unknown ref type %d of ref %s",
> + ref_type(refname), refname);
> + }
> +}
> +
> +static int sync_loose_refs(struct files_ref_store *refs,
> + int flags,
> + struct strbuf *err)
> +{
> + if (fsync_ref_files != FSYNC_REF_FILES_BATCH)
> + return 0;
> +
> + if ((flags & SYNC_LOOSE_REF_GITDIR) &&
> + git_fsync_dir(refs->base.gitdir) < 0)
> + return -1;
> +
> + if ((flags & SYNC_LOOSE_REF_COMMONDIR) &&
> + git_fsync_dir(refs->gitcommondir) < 0)
> + return -1;
> +
> + return 0;
> +}
> +
Now that I understand it better, I agree with Ævar's feedback. I think
only a single sync is needed to cover everything in .git/.
I'd also suggest renaming 'sync_loose_refs' to something which makes
it clearer that it's the batch-flush step. Maybe s/do_batch_fsync/do_batch_objects_fsync
and s/sync_loose_refs/do_batch_refs_fsync.
Thanks
Neeraj
next prev parent reply other threads:[~2021-11-11 0:18 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-04 12:38 [PATCH] refs: sync loose refs to disk before committing them Patrick Steinhardt
2021-11-04 13:14 ` Ævar Arnfjörð Bjarmason
2021-11-04 14:51 ` Patrick Steinhardt
2021-11-04 21:24 ` Junio C Hamano
2021-11-04 22:36 ` Neeraj Singh
2021-11-05 1:40 ` Junio C Hamano
2021-11-05 6:36 ` Jeff King
2021-11-05 8:35 ` Ævar Arnfjörð Bjarmason
2021-11-05 9:04 ` Jeff King
2021-11-05 7:07 ` Jeff King
2021-11-05 7:17 ` Jeff King
2021-11-05 9:12 ` Johannes Schindelin
2021-11-05 9:22 ` Patrick Steinhardt
2021-11-05 9:34 ` Jeff King
2021-11-09 11:25 ` Patrick Steinhardt
2021-11-10 8:36 ` Jeff King
2021-11-10 9:16 ` Patrick Steinhardt
2021-11-10 11:40 ` [PATCH v2 0/3] " Patrick Steinhardt
2021-11-10 11:40 ` [PATCH v2 1/3] wrapper: handle EINTR in `git_fsync()` Patrick Steinhardt
2021-11-10 14:33 ` Johannes Schindelin
2021-11-10 14:39 ` Ævar Arnfjörð Bjarmason
2021-11-10 11:40 ` [PATCH v2 2/3] wrapper: provide function to sync directories Patrick Steinhardt
2021-11-10 14:40 ` Ævar Arnfjörð Bjarmason
2021-11-10 11:41 ` [PATCH v2 3/3] refs: add configuration to enable flushing of refs Patrick Steinhardt
2021-11-10 14:49 ` Ævar Arnfjörð Bjarmason
2021-11-10 19:15 ` Neeraj Singh
2021-11-10 20:23 ` Ævar Arnfjörð Bjarmason
2021-11-11 0:03 ` Neeraj Singh
2021-11-11 12:14 ` Patrick Steinhardt
2021-11-11 12:06 ` Patrick Steinhardt
2021-11-11 0:18 ` Neeraj Singh [this message]
2021-11-10 14:44 ` [PATCH v2 0/3] refs: sync loose refs to disk before committing them Johannes Schindelin
2021-11-10 20:45 ` Jeff King
2021-11-11 11:47 ` Patrick Steinhardt
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=20211111001803.GA787@neerajsi-x1.localdomain \
--to=nksingh85@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=avarab@gmail.com \
--cc=e@80x24.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=neerajsi@microsoft.com \
--cc=peff@peff.net \
--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).