git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: Marcus Griep <marcus@griep.us>
Cc: Git Mailing List <git@vger.kernel.org>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 1/3] Git.pm: Add faculties to allow temp files to be cached
Date: Mon, 11 Aug 2008 20:08:09 -0700	[thread overview]
Message-ID: <20080812030809.GA14051@untitled> (raw)
In-Reply-To: <1218470035-13864-2-git-send-email-marcus@griep.us>

Marcus Griep <marcus@griep.us> wrote:
> This patch offers a generic interface to allow temp files to be
> cached while using an instance of the 'Git' package. If many
> temp files are created and destroyed during the execution of a
> program, this caching mechanism can help reduce the amount of
> files created and destroyed by the filesystem.
> 
> There are two methods offered for creating a new file: a no-lock and
> a acquire-lock version. The no-lock version provides no
> guarantee that a file is not in use or that the temp file may be
> stolen by a subsequent request. The acquire-lock version provides a
> weak guarantee that a temp file will not be stolen by subsequent
> requests even from a no-lock request. If a file is locked when
> another acquire request is made, a simple error is thrown.

I'm not sure if the no-lock version is worth the potential for
buggy or dangerous code.  I like this new idea of locking the
files to prevent bugs.

> +=item temp_release ( NAME [, BOOL] )
> +
> +=item temp_release ( FILEHANDLE [, BOOL] )
> +
> +Releases a lock acquired through C<temp_acquire()>. Can be called either with
> +the C<NAME> mapping used when acquiring the temp file or with the C<FILEHANDLE>
> +referencing a locked temp file.
> +
> +Warns if an attempt is made to release a file that is not locked.
> +
> +If called with C<BOOL> true, then the temp file will be truncated before being
> +released. This can help to reduce disk I/O where the system is smart enough to
> +detect the truncation while data is in the output buffers.

Always truncating on release makes the interface simpler.  With locking,
we can probably *only* truncate on release if you're that worried about
the extra overhead :)

> +=item temp_reset ( FILEHANDLE )
> +
> +Truncates and resets the position of the C<FILEHANDLE>.  Uses C<sysseek>.
> +
> +=cut
> +
> +sub temp_reset {
> +	my ($self, $temp_fd) = _maybe_self(@_);
> +
> +	truncate $temp_fd, 0
> +		or throw Error::Simple("couldn't truncate file");

I would do a regular seek() here in addition to the sysseek() below. I
am not certain one of the many userspace buffering layers Perl can
potentially use doesn't do anything funky with its offset accounting.

> +	sysseek $temp_fd, 0, SEEK_SET
> +		or throw Error::Simple("couldn't seek to beginning of file");

I would also put a tell() here after the sysseek and throw an error if
it returns a non-zero value just in case.  Yes, I'm really paranoid
about this stuff and have a huge distrust of userspace I/O layers :)

-- 
Eric Wong

  parent reply	other threads:[~2008-08-12  3:11 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-08 22:41 [PATCH] git-svn: Make it scream by minimizing temp files Marcus Griep
2008-08-08 22:59 ` Junio C Hamano
2008-08-09  1:12   ` Marcus Griep
2008-08-09  6:25 ` Eric Wong
2008-08-09 15:45   ` Marcus Griep
2008-08-10  1:46     ` Eric Wong
2008-08-10  3:53       ` Junio C Hamano
2008-08-10  7:47         ` Eric Wong
2008-08-10  8:26           ` Junio C Hamano
2008-08-10  8:09     ` Eric Wong
2008-08-11 15:53     ` [PATCH 0/3] git-svn and temporary file improvements Marcus Griep
2008-08-11 15:53       ` [PATCH 1/3] Git.pm: Add faculties to allow temp files to be cached Marcus Griep
2008-08-11 15:53         ` [PATCH 2/3] git-svn: Make it scream by minimizing temp files Marcus Griep
2008-08-11 15:53           ` [PATCH 3/3] git-svn: Reduce temp file usage when dealing with non-links Marcus Griep
2008-08-12  3:37             ` Eric Wong
2008-08-12 15:53               ` Marcus Griep
2008-08-12 16:01             ` Marcus Griep
2008-08-12 16:45               ` [PATCH v2 " Marcus Griep
2008-08-13  3:29               ` [PATCH " Eric Wong
2008-08-13  3:42                 ` Marcus Griep
2008-08-13  3:52                   ` Eric Wong
2008-08-12  3:14           ` [PATCH 2/3] git-svn: Make it scream by minimizing temp files Eric Wong
2008-08-12 15:50             ` Marcus Griep
2008-08-12 16:00           ` [PATCH 2/3] git-svn: Make it incrementally faster " Marcus Griep
2008-08-13  3:29             ` Eric Wong
2008-08-12  3:08         ` Eric Wong [this message]
2008-08-12 15:41           ` [PATCH 1/3] Git.pm: Add faculties to allow temp files to be cached Marcus Griep
2008-08-12 16:00         ` Marcus Griep
2008-08-13  3:28           ` Eric Wong
2008-08-13 20:05         ` Lea Wiemann
2008-08-13 20:13           ` Marcus Griep
2008-08-13 20:31             ` Marcus Griep
2008-08-13 20:38           ` Junio C Hamano
2008-08-13 22:28             ` Lea Wiemann
2008-08-13 22:30               ` [PATCH] Git.pm: require Perl 5.6.1 Lea Wiemann
2008-08-14  6:58             ` [PATCH 1/3] Git.pm: Add faculties to allow temp files to be cached Eric Wong
2008-08-15 15:10               ` [PATCH] Git.pm: Make File::Spec and File::Temp requirement lazy Marcus Griep
2008-08-15 19:31                 ` Bryan Donlan
2008-08-15 19:46                   ` Marcus Griep
2008-08-15 19:53                 ` [PATCH v2] " Marcus Griep
2008-08-13 20:52           ` [PATCH 1/3] Git.pm: Add faculties to allow temp files to be cached Miklos Vajna
2008-08-14  6:29         ` Junio C Hamano
2008-08-14 14:35           ` Marcus Griep

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=20080812030809.GA14051@untitled \
    --to=normalperson@yhbt.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=marcus@griep.us \
    /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).