Patchwork [9,of,9,V2] transaction: open a file with checkambig=True to avoid file stat ambiguity

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Sept. 22, 2016, 12:59 p.m.
Message ID <c47d67e9412df24914ff.1474549168@feefifofum>
Download mbox | patch
Permalink /patch/16754/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - Sept. 22, 2016, 12:59 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1474548720 -32400
#      Thu Sep 22 21:52:00 2016 +0900
# Node ID c47d67e9412df24914ff4caaf1437a2c35a0af6b
# Parent  338febde64d5fe6a5aac79aff54741e201b5d88f
transaction: open a file with checkambig=True to avoid file stat ambiguity

Before this patch, if steps below occurs at "the same time in sec",
all of mtime, ctime and size are same between (1) and (3).

  1. append data to revlog-style file (and close transaction)
  2. discard appended data by truncation of rollback
  3. append same size but different data to revlog-style file again

Therefore, cache validation doesn't work after (3) as expected.

To avoid file stat ambiguity around truncation, this patch opens a
file with checkambig=True.

This is a part of ExactCacheValidationPlan.

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan
Pierre-Yves David - Sept. 23, 2016, 1:19 a.m.
On 09/22/2016 02:59 PM, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1474548720 -32400
> #      Thu Sep 22 21:52:00 2016 +0900
> # Node ID c47d67e9412df24914ff4caaf1437a2c35a0af6b
> # Parent  338febde64d5fe6a5aac79aff54741e201b5d88f
> transaction: open a file with checkambig=True to avoid file stat ambiguity

I've pushed this. I remember discussing this 1 year ago and I'm very 
happy to is it happening.

I've added a small inline comment about the new attribute for revlog.

Having the same header in each patches might have been a bit overkill. 
But at least it was clear.

Cheers,
Jun Wu - Sept. 26, 2016, 3:33 p.m.
Did you amend the patch to add two lines of comments for
"revlog: specify checkambig at writing to avoid file stat ambiguity"?

  +        #  When True, indexfile is opened with checkambig=True at writing, to
  +        #  avoid file stat ambiguity.
            ^^ - should be one single space

I'd note the spaces are wrong - we may want to add a check-code rule for
this.

Excerpts from Pierre-Yves David's message of 2016-09-23 03:19:34 +0200:
> On 09/22/2016 02:59 PM, FUJIWARA Katsunori wrote:
> > # HG changeset patch
> > # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> > # Date 1474548720 -32400
> > #      Thu Sep 22 21:52:00 2016 +0900
> > # Node ID c47d67e9412df24914ff4caaf1437a2c35a0af6b
> > # Parent  338febde64d5fe6a5aac79aff54741e201b5d88f
> > transaction: open a file with checkambig=True to avoid file stat ambiguity
> 
> I've pushed this. I remember discussing this 1 year ago and I'm very 
> happy to is it happening.
> 
> I've added a small inline comment about the new attribute for revlog.
> 
> Having the same header in each patches might have been a bit overkill. 
> But at least it was clear.
> 
> Cheers,
>
Pierre-Yves David - Sept. 27, 2016, 12:23 p.m.
On 09/26/2016 05:33 PM, Jun Wu wrote:
> Did you amend the patch to add two lines of comments for
> "revlog: specify checkambig at writing to avoid file stat ambiguity"?
>
>   +        #  When True, indexfile is opened with checkambig=True at writing, to
>   +        #  avoid file stat ambiguity.
>             ^^ - should be one single space
>
> I'd note the spaces are wrong - we may want to add a check-code rule for
> this.

Ha, good catch. We'll have to fix that in a follow up commit.

Patch

diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -48,7 +48,7 @@  def _playback(journal, report, opener, v
     for f, o, _ignore in entries:
         if o or not unlink:
             try:
-                fp = opener(f, 'a')
+                fp = opener(f, 'a', checkambig=True)
                 fp.truncate(o)
                 fp.close()
             except IOError: