You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Julian Foad <ju...@btopenworld.com> on 2009/10/13 17:06:56 UTC

FSFS "rev cache" operation [was: obliterate in trunk]

Daniel,

OK, I think I get it now. The "rep cache" is a cache of rep locations,
keyed by rep checksum. When we want to add a new rep, we look in the
cache to see if we have a copy of it stored already. If a location is
not found in the cache, we might nonetheless already have a copy of the
rep and we could search the rev files exhaustively, but we prefer not to
spend the time doing so, so we just store (another copy of) the new rep
in full.

You raise the issue of deleting stale references from the cache, and
ensuring stale entries do not end up being used in new committed revs.
We can invalidate such entries in the cache synchronously with
obliteration, but you point out that the reference may have already been
read from the cache and stored in a pending transaction before we
invalidate it. Therefore it seems we will need to validate all such
references in a new revision txn at commit finalization time. It might
be acceptable to abort a commit if it contains any stale reference, and
the user could re-try. The more correct action would be to ensure we
have a full copy of the rep available until we convert it into a
reference at finalization time.

A way to describe this is that the conceptual "reference count" of a rep
needs to include references in pending transactions: if any pending
transaction refers to a given rep, then we can't (yet) delete that rep.
When we abort a transaction, then we can look through its references and
delete any reps for which it was the only reference. That sounds like it
would be inefficient to implement in the obvious way but I'm sure we can
find a good equivalent.

- Julian


Daniel Shahaf wrote:
> Representations are stored in the rev files.  The DB only stores the 
> coordinates (offsets into rev files) of representations, keyed by the 
> sha1 of the file generated by the representation.
> 
> Commits that want to use a representation write out its coordinates in 
> full in the revision file they create.  (In particular, they *do not* 
> refer to the DB; this is why the latter can be removed at any point.)
> 
> For example, in a Greek tree (r1) with 'svn ps foo bar iota' (r2) and
> '/bin/cp iota iota2; svn add iota2' (r3):
> 
>     % sha1sum < wc1/trunk/iota
>     2c0aa9014a0cd07f01795a333d82485ef6d083e2  -
> 
>     % sqlite3 r/db/rep-cache.db "select * from rep_cache where hash = '2c0aa9014a0cd07f01795a333d82485ef6d083e2';"
>     2c0aa9014a0cd07f01795a333d82485ef6d083e2|1|547|37|25
> 
>     ### [1]
>     % grep -ar 2c0aa9014a0cd07f01795a333d82485ef6d083e2 r/db/revs
>     r/db/revs/0.pack/pack:text: 1 547 37 25 2d18c5e57e84c5b8a5e9a6e13fa394dc 2c0aa9014a0cd07f01795a333d82485ef6d083e2 0-0/_16
>     r/db/revs/0.pack/pack:text: 1 547 37 25 2d18c5e57e84c5b8a5e9a6e13fa394dc 2c0aa9014a0cd07f01795a333d82485ef6d083e2 0-0/_16
>     r/db/revs/0.pack/pack:text: 1 547 37 25 2d18c5e57e84c5b8a5e9a6e13fa394dc 2c0aa9014a0cd07f01795a333d82485ef6d083e2 2-2/_3
> 
>     ### [2]
>     # that's the representation
>     % xxd -s 347 -l 50 r/db/revs/0/1
>     0000223: 4445 4c54 410a 5356 4e01 0000 1902 1a01  DELTA.SVN.......
>     0000233: 9919 5468 6973 2069 7320 7468 6520 6669  ..This is the fi
>     0000243: 6c65 2027 696f 7461 272e 0a45 4e44 5245  le 'iota'..ENDRE
>     0000253: 500a                                     P.
> 
> Daniel
> (The docs I got this info from are the 'Revision file format' section of
> the FSFS 'structure' file.)
> 
> 
> [1] There is a pack file because I build with PACK_AFTER_EVERY_COMMIT and
>     with SVN_FS_FS_DEFAULT_MAX_FILES_PER_DIR=4.  A normal build would
>     see matches in revs/0/{1,2,3}.
>     
> [2] 50 == 37 + strlen("DELTA\n") + strlen("ENDREP\n")
> 
> 
> > > Actually, after r39897, it's possible that DB rows referencing the 
> > > revision-being-obliterated[1] will be added at an arbitrary time after
> > > that revision has been committed: it's (theoretically, depending on
> > > the order SQLite hands out write locks) possible that the sequence
> > > 
> > >     # make a few large (multi-file) commits
> > >     # commit rBO
> > >     # obliterate rBO
> > >     # wait 3 seconds
> > > 
> > > will result in rep-cache rows referring the obliterated version of rBO.
> > > 
> > > 
> > > Not sure how to solve that.  We want to ensure that the obliterate doesn't
> > > get the SQLite write lock before "its" commit gets the same lock. [2]
> > > 
> > > 
> > > Possible damage?  If the DB rows relating to the original rBO are added
> > > after its obliteration its complete, then reps created in the future may
> > > rely on these rows and avoid writing themselves out explicitly --- even
> > > though the reps may no longer be in the rBO rev file.

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2407219

Re: FSFS "rev cache" operation [was: obliterate in trunk]

Posted by Greg Stein <gs...@gmail.com>.
On Tue, Oct 13, 2009 at 15:15, Daniel Shahaf <d....@daniel.shahaf.name> wrote:
>...
> Unrelated question: Do we keep a history of obliterations?  (I see it
> may be undesired for users, but it might make the implementation
> easier...)

I'd think, "we probably HAVE to keep the history."

Consider that a client could have a working copy that was checked out
at any point in time. It may have the obliterated content in it. We
have to tell the client, "that was obliterated. remove it from your
working copy." Not in the sense of data protection, but simply to keep
all the metadata synchronized. "DIR has 5 children [not 6]."

>...

Cheers,
-g

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2407365

Re: FSFS "rev cache" operation [was: obliterate in trunk]

Posted by Julian Foad <ju...@btopenworld.com>.
Daniel Shahaf wrote:
> Julian Foad wrote on Tue, 13 Oct 2009 at 18:06 +0100:
> > You raise the issue of deleting stale references from the cache, and
> > ensuring stale entries do not end up being used in new committed revs.
> > We can invalidate such entries in the cache synchronously with
> > obliteration, but you point out that the reference may have already been
> > read from the cache and stored in a pending transaction before we
> > invalidate it.
> 
> Good point, this is possible, but it isn't what I said.  The scenario I 
> described below (search for 'rBO') is a race condition around the sqlite 
> write lock that (theoretically) may cause cache entries for a given 
> revision to be first inserted into the DB only after the obliterate of 
> that revision has finished.
> 
> (I'm thinking of the case where the 'obliterate' gets the sqlite write
> lock before the commit-it-obliterates gets the sqlite write lock.)

OK, I see.

> > Therefore it seems we will need to validate all such
> > references in a new revision txn at commit finalization time. It might
> > be acceptable to abort a commit if it contains any stale reference, and
> > the user could re-try. The more correct action would be to ensure we
> > have a full copy of the rep available until we convert it into a
> > reference at finalization time.
> 
> IOW, when we take the write lock to finalize a commit, at that point we
> should make sure that all the reps we refer to are still alive and well.

Yes.

> Unrelated question: Do we keep a history of obliterations?  (I see it
> may be undesired for users, but it might make the implementation
> easier...)

Not sure yet. We will not keep a "full" history, because that would
effectively mean meta-versioning the repository, and that is not what
this feature is about. We might want to keep a trace of metadata about
what was obliterated, but my intuition says we should not strictly need
any such info for functional correctness. We will want to record such a
trace as a server log file for external consumption.

For performance, we will need at least a sequence number that enables us
to detect whether an obliteration has occurred since we recorded some
previous sequence number.


> > A way to describe this is that the conceptual "reference count" of a rep
> > needs to include references in pending transactions: if any pending
> > transaction refers to a given rep, then we can't (yet) delete that rep.
> > When we abort a transaction, then we can look through its references and
> > delete any reps for which it was the only reference. That sounds like it
> > would be inefficient to implement in the obvious way but I'm sure we can
> > find a good equivalent.
> > 
> 
> IOW: if we have other references for the rep, we should obliterate the
> file without physically deleting the rep?

Yes.

- Julian

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2407352

Re: FSFS "rev cache" operation [was: obliterate in trunk]

Posted by Daniel Shahaf <d....@daniel.shahaf.name>.
Julian Foad wrote on Tue, 13 Oct 2009 at 18:06 +0100:
> Daniel,
> 
> OK, I think I get it now. The "rep cache" is a cache of rep locations,
> keyed by rep checksum. When we want to add a new rep, we look in the
> cache to see if we have a copy of it stored already. If a location is
> not found in the cache, we might nonetheless already have a copy of the
> rep and we could search the rev files exhaustively, but we prefer not to
> spend the time doing so, so we just store (another copy of) the new rep
> in full.
> 

Yes.

> You raise the issue of deleting stale references from the cache, and
> ensuring stale entries do not end up being used in new committed revs.
> We can invalidate such entries in the cache synchronously with
> obliteration, but you point out that the reference may have already been
> read from the cache and stored in a pending transaction before we
> invalidate it.

Good point, this is possible, but it isn't what I said.  The scenario I 
described below (search for 'rBO') is a race condition around the sqlite 
write lock that (theoretically) may cause cache entries for a given 
revision to be first inserted into the DB only after the obliterate of 
that revision has finished.

(I'm thinking of the case where the 'obliterate' gets the sqlite write
lock before the commit-it-obliterates gets the sqlite write lock.)

> Therefore it seems we will need to validate all such
> references in a new revision txn at commit finalization time. It might
> be acceptable to abort a commit if it contains any stale reference, and
> the user could re-try. The more correct action would be to ensure we
> have a full copy of the rep available until we convert it into a
> reference at finalization time.
> 

IOW, when we take the write lock to finalize a commit, at that point we
should make sure that all the reps we refer to are still alive and well.

Unrelated question: Do we keep a history of obliterations?  (I see it
may be undesired for users, but it might make the implementation
easier...)

> A way to describe this is that the conceptual "reference count" of a rep
> needs to include references in pending transactions: if any pending
> transaction refers to a given rep, then we can't (yet) delete that rep.
> When we abort a transaction, then we can look through its references and
> delete any reps for which it was the only reference. That sounds like it
> would be inefficient to implement in the obvious way but I'm sure we can
> find a good equivalent.
> 

IOW: if we have other references for the rep, we should obliterate the
file without physically deleting the rep?

> - Julian
> 

Daniel
(a bit cloudy)

> 
> Daniel Shahaf wrote:
> > Representations are stored in the rev files.  The DB only stores the 
> > coordinates (offsets into rev files) of representations, keyed by the 
> > sha1 of the file generated by the representation.
> > 
> > Commits that want to use a representation write out its coordinates in 
> > full in the revision file they create.  (In particular, they *do not* 
> > refer to the DB; this is why the latter can be removed at any point.)
> > 
> > For example, in a Greek tree (r1) with 'svn ps foo bar iota' (r2) and
> > '/bin/cp iota iota2; svn add iota2' (r3):
> > 
> >     % sha1sum < wc1/trunk/iota
> >     2c0aa9014a0cd07f01795a333d82485ef6d083e2  -
> > 
> >     % sqlite3 r/db/rep-cache.db "select * from rep_cache where hash = '2c0aa9014a0cd07f01795a333d82485ef6d083e2';"
> >     2c0aa9014a0cd07f01795a333d82485ef6d083e2|1|547|37|25
> > 
> >     ### [1]
> >     % grep -ar 2c0aa9014a0cd07f01795a333d82485ef6d083e2 r/db/revs
> >     r/db/revs/0.pack/pack:text: 1 547 37 25 2d18c5e57e84c5b8a5e9a6e13fa394dc 2c0aa9014a0cd07f01795a333d82485ef6d083e2 0-0/_16
> >     r/db/revs/0.pack/pack:text: 1 547 37 25 2d18c5e57e84c5b8a5e9a6e13fa394dc 2c0aa9014a0cd07f01795a333d82485ef6d083e2 0-0/_16
> >     r/db/revs/0.pack/pack:text: 1 547 37 25 2d18c5e57e84c5b8a5e9a6e13fa394dc 2c0aa9014a0cd07f01795a333d82485ef6d083e2 2-2/_3
> > 
> >     ### [2]
> >     # that's the representation
> >     % xxd -s 347 -l 50 r/db/revs/0/1
> >     0000223: 4445 4c54 410a 5356 4e01 0000 1902 1a01  DELTA.SVN.......
> >     0000233: 9919 5468 6973 2069 7320 7468 6520 6669  ..This is the fi
> >     0000243: 6c65 2027 696f 7461 272e 0a45 4e44 5245  le 'iota'..ENDRE
> >     0000253: 500a                                     P.
> > 
> > Daniel
> > (The docs I got this info from are the 'Revision file format' section of
> > the FSFS 'structure' file.)
> > 
> > 
> > [1] There is a pack file because I build with PACK_AFTER_EVERY_COMMIT and
> >     with SVN_FS_FS_DEFAULT_MAX_FILES_PER_DIR=4.  A normal build would
> >     see matches in revs/0/{1,2,3}.
> >     
> > [2] 50 == 37 + strlen("DELTA\n") + strlen("ENDREP\n")
> > 
> > 
> > > > Actually, after r39897, it's possible that DB rows referencing the 
> > > > revision-being-obliterated[1] will be added at an arbitrary time after
> > > > that revision has been committed: it's (theoretically, depending on
> > > > the order SQLite hands out write locks) possible that the sequence
> > > > 
> > > >     # make a few large (multi-file) commits
> > > >     # commit rBO
> > > >     # obliterate rBO
> > > >     # wait 3 seconds
> > > > 
> > > > will result in rep-cache rows referring the obliterated version of rBO.
> > > > 
> > > > 
> > > > Not sure how to solve that.  We want to ensure that the obliterate doesn't
> > > > get the SQLite write lock before "its" commit gets the same lock. [2]
> > > > 
> > > > 
> > > > Possible damage?  If the DB rows relating to the original rBO are added
> > > > after its obliteration its complete, then reps created in the future may
> > > > rely on these rows and avoid writing themselves out explicitly --- even
> > > > though the reps may no longer be in the rBO rev file.
> 
> ------------------------------------------------------
> http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2407219
>

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2407282

Re: FSFS "rev cache" operation [was: obliterate in trunk]

Posted by Branko Cibej <br...@xbc.nu>.
David Glasser wrote:
> Well, the actual problem here is that the rep cache doesn't have a ref count.
>
> So let's say you want to obliterate the node /foo/bar@1234.  Its text
> may be in the rep r1234/9876.  If you actually want to remove that
> data from the backend (and not just mask it from clients), you need to
> know if any other nodes (which may not be related to this node via
> ancestry relations) use that rep.  Since the DB doesn't even have a
> refcount, you can't even know if it's safe to wipe the rep text (let
> alone where the other uses are).
>   

You could possibly solve this by adding another flag column o the
rep-cache table ... (lots of hand-waving now):

    * svn_fs_obliterate would just say, "this rep may have been
      obliterated". New commits that see this hint keep using the same rep.
    * A separate (periodic?) scanner would look at each such rep-cache
      entry, mark it as "now obliterating" and proceed to scan the
      repository to determine if any references remain.
    * Wave hands, prevent races with new commits that need this
      representation. It could be a simple as letting new commits just
      change that flag to "not obliterated" and let the scanner notice
      that before it actually tries to remove data.

> As Greg said, you can basically get around this by doing a bunch of
> slow repository walks to try to find other places that use the same
> rep.  (Of course half the reason that we want an obliterate feature is
> that people find dump/load to be too slow :) )
>   

These scans should obviously be offline, or rather, they shouldn't block
normal repository operations. This would require some more admin work to
set up a repository, but only when you use rep-sharing *and* need the
space-saving obliterate. And with proper design, the repository admin
could enable such periodic scans at any time after the repository was
created.

Better yet, when a poor admin notices that his lusers tend to obliterate
every second commit, she could turn off rep-sharing to make obliterate
more efficient. :D

-- Brane

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2407408

Re: FSFS "rev cache" operation [was: obliterate in trunk]

Posted by David Glasser <gl...@davidglasser.net>.
Well, the actual problem here is that the rep cache doesn't have a ref count.

So let's say you want to obliterate the node /foo/bar@1234.  Its text
may be in the rep r1234/9876.  If you actually want to remove that
data from the backend (and not just mask it from clients), you need to
know if any other nodes (which may not be related to this node via
ancestry relations) use that rep.  Since the DB doesn't even have a
refcount, you can't even know if it's safe to wipe the rep text (let
alone where the other uses are).

As Greg said, you can basically get around this by doing a bunch of
slow repository walks to try to find other places that use the same
rep.  (Of course half the reason that we want an obliterate feature is
that people find dump/load to be too slow :) )

Note that Hyrum's original implementation had ref counts but since we
were combining two different attempts at ACID-style semantics (svn
FSFS and sqlite) in an unsound way, there were many ways that the ref
count could become incorrect, so we removed it rather than try to make
it perfect.

--dave

On Tue, Oct 13, 2009 at 10:06 AM, Julian Foad
<ju...@btopenworld.com> wrote:
> Daniel,
>
> OK, I think I get it now. The "rep cache" is a cache of rep locations,
> keyed by rep checksum. When we want to add a new rep, we look in the
> cache to see if we have a copy of it stored already. If a location is
> not found in the cache, we might nonetheless already have a copy of the
> rep and we could search the rev files exhaustively, but we prefer not to
> spend the time doing so, so we just store (another copy of) the new rep
> in full.
>
> You raise the issue of deleting stale references from the cache, and
> ensuring stale entries do not end up being used in new committed revs.
> We can invalidate such entries in the cache synchronously with
> obliteration, but you point out that the reference may have already been
> read from the cache and stored in a pending transaction before we
> invalidate it. Therefore it seems we will need to validate all such
> references in a new revision txn at commit finalization time. It might
> be acceptable to abort a commit if it contains any stale reference, and
> the user could re-try. The more correct action would be to ensure we
> have a full copy of the rep available until we convert it into a
> reference at finalization time.
>
> A way to describe this is that the conceptual "reference count" of a rep
> needs to include references in pending transactions: if any pending
> transaction refers to a given rep, then we can't (yet) delete that rep.
> When we abort a transaction, then we can look through its references and
> delete any reps for which it was the only reference. That sounds like it
> would be inefficient to implement in the obvious way but I'm sure we can
> find a good equivalent.
>
> - Julian
>
>
> Daniel Shahaf wrote:
>> Representations are stored in the rev files.  The DB only stores the
>> coordinates (offsets into rev files) of representations, keyed by the
>> sha1 of the file generated by the representation.
>>
>> Commits that want to use a representation write out its coordinates in
>> full in the revision file they create.  (In particular, they *do not*
>> refer to the DB; this is why the latter can be removed at any point.)
>>
>> For example, in a Greek tree (r1) with 'svn ps foo bar iota' (r2) and
>> '/bin/cp iota iota2; svn add iota2' (r3):
>>
>>     % sha1sum < wc1/trunk/iota
>>     2c0aa9014a0cd07f01795a333d82485ef6d083e2  -
>>
>>     % sqlite3 r/db/rep-cache.db "select * from rep_cache where hash = '2c0aa9014a0cd07f01795a333d82485ef6d083e2';"
>>     2c0aa9014a0cd07f01795a333d82485ef6d083e2|1|547|37|25
>>
>>     ### [1]
>>     % grep -ar 2c0aa9014a0cd07f01795a333d82485ef6d083e2 r/db/revs
>>     r/db/revs/0.pack/pack:text: 1 547 37 25 2d18c5e57e84c5b8a5e9a6e13fa394dc 2c0aa9014a0cd07f01795a333d82485ef6d083e2 0-0/_16
>>     r/db/revs/0.pack/pack:text: 1 547 37 25 2d18c5e57e84c5b8a5e9a6e13fa394dc 2c0aa9014a0cd07f01795a333d82485ef6d083e2 0-0/_16
>>     r/db/revs/0.pack/pack:text: 1 547 37 25 2d18c5e57e84c5b8a5e9a6e13fa394dc 2c0aa9014a0cd07f01795a333d82485ef6d083e2 2-2/_3
>>
>>     ### [2]
>>     # that's the representation
>>     % xxd -s 347 -l 50 r/db/revs/0/1
>>     0000223: 4445 4c54 410a 5356 4e01 0000 1902 1a01  DELTA.SVN.......
>>     0000233: 9919 5468 6973 2069 7320 7468 6520 6669  ..This is the fi
>>     0000243: 6c65 2027 696f 7461 272e 0a45 4e44 5245  le 'iota'..ENDRE
>>     0000253: 500a                                     P.
>>
>> Daniel
>> (The docs I got this info from are the 'Revision file format' section of
>> the FSFS 'structure' file.)
>>
>>
>> [1] There is a pack file because I build with PACK_AFTER_EVERY_COMMIT and
>>     with SVN_FS_FS_DEFAULT_MAX_FILES_PER_DIR=4.  A normal build would
>>     see matches in revs/0/{1,2,3}.
>>
>> [2] 50 == 37 + strlen("DELTA\n") + strlen("ENDREP\n")
>>
>>
>> > > Actually, after r39897, it's possible that DB rows referencing the
>> > > revision-being-obliterated[1] will be added at an arbitrary time after
>> > > that revision has been committed: it's (theoretically, depending on
>> > > the order SQLite hands out write locks) possible that the sequence
>> > >
>> > >     # make a few large (multi-file) commits
>> > >     # commit rBO
>> > >     # obliterate rBO
>> > >     # wait 3 seconds
>> > >
>> > > will result in rep-cache rows referring the obliterated version of rBO.
>> > >
>> > >
>> > > Not sure how to solve that.  We want to ensure that the obliterate doesn't
>> > > get the SQLite write lock before "its" commit gets the same lock. [2]
>> > >
>> > >
>> > > Possible damage?  If the DB rows relating to the original rBO are added
>> > > after its obliteration its complete, then reps created in the future may
>> > > rely on these rows and avoid writing themselves out explicitly --- even
>> > > though the reps may no longer be in the rBO rev file.
>
> ------------------------------------------------------
> http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2407219
>



-- 
glasser@davidglasser.net | langtonlabs.org | flickr.com/photos/glasser/

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2407239