summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipe David Borba Manana <fdmanana@apache.org>2010-11-18 11:11:00 +0000
committerFilipe David Borba Manana <fdmanana@apache.org>2010-11-18 11:11:00 +0000
commitcd0468cf3767a8854e50ce0741692883b21cfaed (patch)
treebabf67ce12afa881e4ee4900429d922ebed37cb5
parent5e05bcd220251d4b1c4e826156c50efb9e22ee12 (diff)
Make sure that after compaction of the authentication database the old reference counter is released.
Same type of issue as in COUCHDB-926. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@1036407 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--share/www/script/test/auth_cache.js31
-rw-r--r--src/couchdb/couch_auth_cache.erl9
2 files changed, 40 insertions, 0 deletions
diff --git a/share/www/script/test/auth_cache.js b/share/www/script/test/auth_cache.js
index 75827dbd..e48f7370 100644
--- a/share/www/script/test/auth_cache.js
+++ b/share/www/script/test/auth_cache.js
@@ -238,6 +238,37 @@ couchTests.auth_cache = function(debug) {
T(misses_after === misses_before);
T(hits_after === (hits_before + 1));
+
+ // login, compact authentication DB, login again and verify that
+ // there was a cache hit
+ hits_before = hits_after;
+ misses_before = misses_after;
+
+ T(CouchDB.login("johndoe", "123456").ok);
+
+ hits_after = hits();
+ misses_after = misses();
+
+ T(misses_after === (misses_before + 1));
+ T(hits_after === hits_before);
+
+ T(CouchDB.logout().ok);
+ T(authDb.compact().ok);
+
+ while (authDb.info().compact_running);
+
+ hits_before = hits_after;
+ misses_before = misses_after;
+
+ T(CouchDB.login("johndoe", "123456").ok);
+
+ hits_after = hits();
+ misses_after = misses();
+
+ T(misses_after === misses_before);
+ T(hits_after === (hits_before + 1));
+
+ T(CouchDB.logout().ok);
}
diff --git a/src/couchdb/couch_auth_cache.erl b/src/couchdb/couch_auth_cache.erl
index 2fbc4f0e..e0715b88 100644
--- a/src/couchdb/couch_auth_cache.erl
+++ b/src/couchdb/couch_auth_cache.erl
@@ -135,6 +135,7 @@ handle_db_event({Event, DbName}) ->
case Event of
deleted -> gen_server:call(?MODULE, auth_db_deleted, infinity);
created -> gen_server:call(?MODULE, auth_db_created, infinity);
+ compacted -> gen_server:call(?MODULE, auth_db_compacted, infinity);
_Else -> ok
end;
false ->
@@ -158,6 +159,14 @@ handle_call(auth_db_created, _From, State) ->
true = ets:insert(?STATE, {auth_db, open_auth_db()}),
{reply, ok, NewState};
+handle_call(auth_db_compacted, _From, State) ->
+ exec_if_auth_db(
+ fun(AuthDb) ->
+ true = ets:insert(?STATE, {auth_db, reopen_auth_db(AuthDb)})
+ end
+ ),
+ {reply, ok, State};
+
handle_call({new_max_cache_size, NewSize}, _From, State) ->
case NewSize >= State#state.cache_size of
true ->