Path: usenet.cis.ufl.edu!usenet.eel.ufl.edu!hookup!news.kei.com!simtel!news.sprintlink.net!psgrain!nntp.teleport.com!usenet
From: [email protected] (Tim Freeman)
Newsgroups: comp.lang.perl.announce,comp.lang.perl.misc,comp.lang.perl
Subject: Atomic Transactions on Files
Followup-To: comp.lang.perl.misc
Date: 15 Jul 1995 12:53:58 GMT
Organization: NETCOM On-line Communication Services (408 261-4700 guest)
Lines: 48
Approved: [email protected] (comp.lang.perl.announce)
Message-ID: <[email protected]>
NNTP-Posting-Host: linda.teleport.com
X-Disclaimer: The "Approved" header verifies header information for article transmission and does not imply approval of content.
Xref: usenet.cis.ufl.edu comp.lang.perl.announce:76 comp.lang.perl.misc:1773 comp.lang.perl:54392

I wrote a package that implements atomic transactions on Unix files in
Perl.  The package can ensure that consistent changes are made to a
set of files, even in the presence of power failures, concurrent use,
and errors.

The package includes (and requires installation of) an interface to
the sync and fsync Unix calls.

It is available by downloading the URL
file://ftp.netcom.com/pub/ts/tsf/trans.tar.gz, or if you can't parse
URL's you can get it by anonymous FTP to ftp.netcom.com, directory
pub/ts/tsf/trans.tar.gz.  It requires Perl 5.000 or higher and I tested
it with Linux 1.2.2, Perl 5.001e.

For example, the following program will never reach the
"Integrity lost" error unless some other code manipulates a and b,
even in the presence of power failures as the script is running:

  sub doit {
      my ($num);
      if (! -e "a") {
          $num = 0;
      } else {
          open (A, "<a") || die "Can't read a: $!";
          $num = <A>; chop $num;
          close (A);
          open (B, "<b") || die "Can't read b: $!";
          die "Integrity lost" unless <B>=="$num\n";
          close (B);
      }
      $num++;
      open (A, ">a") || die "Can't write a: $!";
      print A $num,"\n";
      close (A);
      open (B, ">b") || die "Can't write b: $!";
      print B $num,"\n";
      close (B);
  }

  Trans::transact (\&doit, "a", "b");

Tim Freeman
[email protected]
[email protected]
--
Tim Freeman
[email protected]