You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2012/09/26 18:56:58 UTC
svn commit: r1390601 - /subversion/trunk/subversion/libsvn_fs_fs/tree.c
Author: stefan2
Date: Wed Sep 26 16:56:58 2012
New Revision: 1390601
URL: http://svn.apache.org/viewvc?rev=1390601&view=rev
Log:
Some clients, e.g. our JAVA tests, indirectly allocate DAG nodes in pools
that live longer than the corresponding FS pool. These nodes become invalid
as soon as the FS gets destroyed, so it is fine to invalidate them together
with the FS.
However, those pools will hold a locks on the DAG cache and will try to
release these locks long after the cache got destroyed. Therefore, we must
keep a list of all locking pools and revoke their locks unconditionally if
the cache gets destroyed.
* subversion/libsvn_fs_fs/tree.c
(cache_lock_t): new data type
(fs_fs_dag_cache_t): use the new type to indicate the presense of locks
(unlock_cache): rewrite
(unregister_locks): new destructor for our cache
(svn_fs_fs__create_dag_cache): register destructor
(lock_cache): rewrite
(auto_clear_dag_cache): update
(dag_node_cache_get): clarify node lifetime in docstring
Modified:
subversion/trunk/subversion/libsvn_fs_fs/tree.c
Modified: subversion/trunk/subversion/libsvn_fs_fs/tree.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_fs_fs/tree.c?rev=1390601&r1=1390600&r2=1390601&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_fs_fs/tree.c (original)
+++ subversion/trunk/subversion/libsvn_fs_fs/tree.c Wed Sep 26 16:56:58 2012
@@ -172,6 +172,25 @@ typedef struct cache_entry_t
*/
enum { BUCKET_COUNT = 256 };
+/* Each pool that has received a DAG node, will hold at least on lock on
+ our cache to ensure that the node remains valid despite being allocated
+ in the cache's pool. This is the structure to represent the lock.
+ */
+typedef struct cache_lock_t
+{
+ /* pool holding the lock */
+ apr_pool_t *pool;
+
+ /* cache being locked */
+ fs_fs_dag_cache_t *cache;
+
+ /* next lock. NULL at EOL */
+ struct cache_lock_t *next;
+
+ /* previous lock. NULL at list head. Only then this==cache->first_lock */
+ struct cache_lock_t *prev;
+} cache_lock_t;
+
/* The actual cache structure. All nodes will be allocated in POOL.
When the number of INSERTIONS (i.e. objects created form that pool)
exceeds a certain threshold, the pool will be cleared and the cache
@@ -180,7 +199,7 @@ enum { BUCKET_COUNT = 256 };
To ensure that nodes returned from this structure remain valid, the
cache will get locked for the lifetime of the _receiving_ pools (i.e.
those in which we would allocate the node if there was no cache.).
- The cache will only be cleared LOCK_COUNT is 0.
+ The cache will only be cleared FIRST_LOCK is 0.
*/
struct fs_fs_dag_cache_t
{
@@ -197,35 +216,60 @@ struct fs_fs_dag_cache_t
Thus, remember the last hit location for optimistic lookup. */
apr_size_t last_hit;
- /* receiving pool that added the latest lock. NULL if not known. */
- apr_pool_t *last_registered;
-
- /* lock counter */
- apr_size_t lock_count;
+ /* List of receiving pools that are still alive. */
+ cache_lock_t *first_lock;
};
-fs_fs_dag_cache_t*
-svn_fs_fs__create_dag_cache(apr_pool_t *pool)
+/* Cleanup function to be called when a receiving pool gets cleared.
+ Unlocks the cache once.
+ */
+static apr_status_t
+unlock_cache(void *baton_void)
{
- fs_fs_dag_cache_t *result = apr_pcalloc(pool, sizeof(*result));
- result->pool = svn_pool_create(pool);
+ cache_lock_t *lock = baton_void;
- return result;
+ /* remove lock from chain. Update the head */
+ if (lock->next)
+ lock->next->prev = lock->prev;
+ if (lock->prev)
+ lock->prev->next = lock->next;
+ else
+ lock->cache->first_lock = lock->next;
+
+ return APR_SUCCESS;
}
-/* Cleanup function to be called when a receiving pool gets cleared.
- Unlocks the cache once.
+/* Cleanup function to be called when the cache itself gets destroyed.
+ In that case, we must unregister all unlock requests.
*/
static apr_status_t
-unlock_cache(void *baton_void)
+unregister_locks(void *baton_void)
{
fs_fs_dag_cache_t *cache = baton_void;
- cache->lock_count--;
- cache->last_registered = NULL;
-
+ cache_lock_t *lock;
+
+ for (lock = cache->first_lock; lock; lock = lock->next)
+ apr_pool_cleanup_kill(lock->pool,
+ lock,
+ unregister_locks);
+
return APR_SUCCESS;
}
+fs_fs_dag_cache_t*
+svn_fs_fs__create_dag_cache(apr_pool_t *pool)
+{
+ fs_fs_dag_cache_t *result = apr_pcalloc(pool, sizeof(*result));
+ result->pool = svn_pool_create(pool);
+
+ apr_pool_cleanup_register(pool,
+ result,
+ unregister_locks,
+ apr_pool_cleanup_null);
+
+ return result;
+}
+
/* Prevent the entries in CACHE from being destroyed, for as long as the
POOL lives.
*/
@@ -238,15 +282,31 @@ lock_cache(fs_fs_dag_cache_t* cache, apr
we may lock the cache more than once for the same pool (and register
just as many cleanup actions).
*/
- if (pool != cache->last_registered)
- {
- apr_pool_cleanup_register(pool,
- cache,
- unlock_cache,
- apr_pool_cleanup_null);
- cache->lock_count++;
- cache->last_registered = pool;
- }
+ cache_lock_t *lock = cache->first_lock;
+
+ /* try to find an existing lock for POOL.
+ But limit the time spent on chasing pointers. */
+ int limiter = 8;
+ while (lock && --limiter)
+ if (lock->pool == pool)
+ return;
+
+ /* create a new lock and put it at the beginning of the lock chain */
+ lock = apr_palloc(pool, sizeof(*lock));
+ lock->cache = cache;
+ lock->pool = pool;
+ lock->next = cache->first_lock;
+ lock->prev = NULL;
+
+ if (cache->first_lock)
+ cache->first_lock->prev = lock;
+ cache->first_lock = lock;
+
+ /* instruct POOL to remove the look upon cleanup */
+ apr_pool_cleanup_register(pool,
+ lock,
+ unlock_cache,
+ apr_pool_cleanup_null);
}
/* Clears the CACHE at regular intervals (destroying all cached nodes)
@@ -254,7 +314,7 @@ lock_cache(fs_fs_dag_cache_t* cache, apr
static void
auto_clear_dag_cache(fs_fs_dag_cache_t* cache)
{
- if (cache->lock_count == 0 && cache->insertions > BUCKET_COUNT)
+ if (cache->first_lock == NULL && cache->insertions > BUCKET_COUNT)
{
apr_pool_clear(cache->pool);
@@ -349,8 +409,8 @@ locate_cache(svn_cache__t **cache,
}
/* Return NODE for PATH from ROOT's node cache, or NULL if the node
- isn't cached; read it from the FS. *NODE remains valid until POOL
- gets cleared or destroyed.*/
+ isn't cached; read it from the FS. *NODE remains valid until either
+ POOL or the FS gets cleared or destroyed (whichever comes first). */
static svn_error_t *
dag_node_cache_get(dag_node_t **node_p,
svn_fs_root_t *root,
Re: svn commit: r1390601 - /subversion/trunk/subversion/libsvn_fs_fs/tree.c
Posted by Stefan Fuhrmann <st...@wandisco.com>.
On Thu, Sep 27, 2012 at 12:30 PM, Philip Martin
<ph...@wandisco.com>wrote:
> stefan2@apache.org writes:
>
> > Author: stefan2
> > Date: Wed Sep 26 16:56:58 2012
> > New Revision: 1390601
> >
> > URL: http://svn.apache.org/viewvc?rev=1390601&view=rev
> > Log:
> > Some clients, e.g. our JAVA tests, indirectly allocate DAG nodes in pools
> > that live longer than the corresponding FS pool. These nodes become
> invalid
> > as soon as the FS gets destroyed, so it is fine to invalidate them
> together
> > with the FS.
> >
> > However, those pools will hold a locks on the DAG cache and will try to
> > release these locks long after the cache got destroyed. Therefore, we
> must
> > keep a list of all locking pools and revoke their locks unconditionally
> if
> > the cache gets destroyed.
>
> The javahl tests are still crashing:
>
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread 0x7ffff7fd9700 (LWP 11226)]
> 0x00007fffc6301ffc in unlock_cache (baton_void=0x7ffff4062550)
> at ../src/subversion/libsvn_fs_fs/tree.c:237
> 237 lock->cache->first_lock = lock->next;
> (gdb) bt
> #0 0x00007fffc6301ffc in unlock_cache (baton_void=0x7ffff4062550)
> at ../src/subversion/libsvn_fs_fs/tree.c:237
> #1 0x00007fffc7201e08 in ?? () from /usr/lib/libapr-1.so.0
> #2 0x00007fffc7200c1d in apr_pool_destroy () from /usr/lib/libapr-1.so.0
> #3 0x00007fffc72021df in apr_pool_destroy_debug () from
> /usr/lib/libapr-1.so.0
> #4 0x00007fffec08b3a6 in svn_client_update4 (result_revs=0x7ffff7fd6ff0,
> paths=0x7ffff40a1150, revision=0x7ffff7fd7140, depth=svn_depth_unknown,
> depth_is_sticky=0, ignore_externals=0, allow_unver_obstructions=0,
> adds_as_modification=1, make_parents=0, ctx=0x7ffff7dff0a0,
> pool=0x7ffff40a0028) at ../src/subversion/libsvn_client/update.c:629
> #5 0x00007fffec507392 in SVNClient::update (this=0x7ffff0102710,
> targets=...,
> revision=..., depth=svn_depth_unknown, depthIsSticky=false,
> makeParents=false, ignoreExternals=false, allowUnverObstructions=false)
> at ../src/subversion/bindings/javahl/native/SVNClient.cpp:337
> #6 0x00007fffec513566 in
> Java_org_apache_subversion_javahl_SVNClient_update (
> env=0x7ffff00081d0, jthis=0x7ffff7fd7a88, jtargets=0x7ffff7fd7a80,
> jrevision=0x0, jdepth=0x7ffff7fd7a70, jdepthIsSticky=0 '\000',
> jmakeParents=0 '\000', jignoreExternals=0 '\000',
> jallowUnverObstructions=0 '\000')
> at
> ../src/subversion/bindings/javahl/native/org_apache_subversion_javahl_SVNClient.cpp:448
>
> (gdb) p lock->cache
> $1 = (fs_fs_dag_cache_t *) 0x7ffff407c028
> (gdb) p lock->cache[0]
> Cannot access memory at address 0x7ffff407c028
>
>
I've been painfully aware of this. Today, I have been
finally able to reproduce the problem on one of my
machines. It turned out to be a silly copy-n-pasto.
r1390935 should fix it for good.
-- Stefan^2.
--
*
Join us this October at Subversion Live
2012<http://www.wandisco.com/svn-live-2012>
for two days of best practice SVN training, networking, live demos,
committer meet and greet, and more! Space is limited, so get signed up
today<http://www.wandisco.com/svn-live-2012>
!
*
Re: svn commit: r1390601 - /subversion/trunk/subversion/libsvn_fs_fs/tree.c
Posted by Philip Martin <ph...@wandisco.com>.
stefan2@apache.org writes:
> Author: stefan2
> Date: Wed Sep 26 16:56:58 2012
> New Revision: 1390601
>
> URL: http://svn.apache.org/viewvc?rev=1390601&view=rev
> Log:
> Some clients, e.g. our JAVA tests, indirectly allocate DAG nodes in pools
> that live longer than the corresponding FS pool. These nodes become invalid
> as soon as the FS gets destroyed, so it is fine to invalidate them together
> with the FS.
>
> However, those pools will hold a locks on the DAG cache and will try to
> release these locks long after the cache got destroyed. Therefore, we must
> keep a list of all locking pools and revoke their locks unconditionally if
> the cache gets destroyed.
The javahl tests are still crashing:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff7fd9700 (LWP 11226)]
0x00007fffc6301ffc in unlock_cache (baton_void=0x7ffff4062550)
at ../src/subversion/libsvn_fs_fs/tree.c:237
237 lock->cache->first_lock = lock->next;
(gdb) bt
#0 0x00007fffc6301ffc in unlock_cache (baton_void=0x7ffff4062550)
at ../src/subversion/libsvn_fs_fs/tree.c:237
#1 0x00007fffc7201e08 in ?? () from /usr/lib/libapr-1.so.0
#2 0x00007fffc7200c1d in apr_pool_destroy () from /usr/lib/libapr-1.so.0
#3 0x00007fffc72021df in apr_pool_destroy_debug () from /usr/lib/libapr-1.so.0
#4 0x00007fffec08b3a6 in svn_client_update4 (result_revs=0x7ffff7fd6ff0,
paths=0x7ffff40a1150, revision=0x7ffff7fd7140, depth=svn_depth_unknown,
depth_is_sticky=0, ignore_externals=0, allow_unver_obstructions=0,
adds_as_modification=1, make_parents=0, ctx=0x7ffff7dff0a0,
pool=0x7ffff40a0028) at ../src/subversion/libsvn_client/update.c:629
#5 0x00007fffec507392 in SVNClient::update (this=0x7ffff0102710, targets=...,
revision=..., depth=svn_depth_unknown, depthIsSticky=false,
makeParents=false, ignoreExternals=false, allowUnverObstructions=false)
at ../src/subversion/bindings/javahl/native/SVNClient.cpp:337
#6 0x00007fffec513566 in Java_org_apache_subversion_javahl_SVNClient_update (
env=0x7ffff00081d0, jthis=0x7ffff7fd7a88, jtargets=0x7ffff7fd7a80,
jrevision=0x0, jdepth=0x7ffff7fd7a70, jdepthIsSticky=0 '\000',
jmakeParents=0 '\000', jignoreExternals=0 '\000',
jallowUnverObstructions=0 '\000')
at ../src/subversion/bindings/javahl/native/org_apache_subversion_javahl_SVNClient.cpp:448
(gdb) p lock->cache
$1 = (fs_fs_dag_cache_t *) 0x7ffff407c028
(gdb) p lock->cache[0]
Cannot access memory at address 0x7ffff407c028
--
Philip