Re: (Fwd) Re: Informix Message Log
Posted in 1996
Jack Parker wrote (in reply to a bunch of others):
> } : Shouldn't the OnLine be shutdown before moving the message file to
> } : archive area , keeping in mind that oninit / tbinit is constantly writing to
> } : the file ???
> }
> } Well, oninit isn't "constantly" writing to this file. (Unless you've got
> } some serious problem going on.) The file gets opened, written to, and closed
> } each time a message is written. So the file shouldn't usually be open.
> }
>
> There is still the risk that the file will be being written to during your
> mv. Which is why I prefer:
>
> tdy=`date +"%Y%j"`
> cp $logfile $logfile.$tdy
> cat /dev/null > $logfile
>
> The file is never 'gone' that way. Sure an 'mv' to the same file system
> is going to take a millsecond - so it's probably never going to be an issue.
> Sure a 'cp' is slower.
Your way is actually worse as there is a window of opportunity where you are
truncating the file while someone else is writting to it. When you use mv, you
are only renaming the directory entry. Any open file descriptors in the kernel
stay open and all pending messages will get correctly written and flushed. The
next open() will cause the file to be created. Under Unix this should be
guaranteed atomic. That is why creat() is used as a lock method. cp and > are
not, and there is the potential for loss.
Cosmo
--
simond@informix.com