You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2022/10/07 11:07:26 UTC
[couchdb] branch spurious_unlock_close_db_if_idle created (now 94d44eb72)
This is an automated email from the ASF dual-hosted git repository.
rnewson pushed a change to branch spurious_unlock_close_db_if_idle
in repository https://gitbox.apache.org/repos/asf/couchdb.git
at 94d44eb72 Fix spurious unlock in close_db_if_idle
This branch includes the following new commits:
new 94d44eb72 Fix spurious unlock in close_db_if_idle
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[couchdb] 01/01: Fix spurious unlock in close_db_if_idle
Posted by rn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rnewson pushed a commit to branch spurious_unlock_close_db_if_idle
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 94d44eb72991b1cca7eca994ee1452aedb43b130
Author: Robert Newson <rn...@apache.org>
AuthorDate: Fri Oct 7 12:06:40 2022 +0100
Fix spurious unlock in close_db_if_idle
---
src/couch/src/couch_server.erl | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)
diff --git a/src/couch/src/couch_server.erl b/src/couch/src/couch_server.erl
index 23fdd584b..33d7fc7ee 100644
--- a/src/couch/src/couch_server.erl
+++ b/src/couch/src/couch_server.erl
@@ -723,23 +723,29 @@ handle_cast({update_lru, DbName}, #server{lru = Lru, update_lru_on_read = true}
handle_cast({update_lru, _DbName}, Server) ->
{noreply, Server};
handle_cast({close_db_if_idle, DbName}, Server) ->
- case ets:update_element(couch_dbs(Server), DbName, {#entry.lock, locked}) of
- true ->
- [#entry{db = Db, db_options = DbOpts}] = ets:lookup(couch_dbs(Server), DbName),
- case couch_db:is_idle(Db) of
+ case ets:lookup(couch_dbs(Server), DbName) of
+ [#entry{db = Db, db_options = DbOpts, lock = unlocked} = Entry0] ->
+ Entry1 = Entry0#entry{lock = locked},
+ LockAcquired = (1 =:= ets:select_replace(couch_dbs(Server), [{Entry0, [], [{const, Entry1}]}])),
+ case LockAcquired of
true ->
- DbPid = couch_db:get_pid(Db),
- true = ets:delete(couch_dbs(Server), DbName),
- true = ets:delete(couch_dbs_pid_to_name(Server), DbPid),
- exit(DbPid, kill),
- {noreply, db_closed(Server, DbOpts)};
+ case couch_db:is_idle(Db) of
+ true ->
+ DbPid = couch_db:get_pid(Db),
+ true = ets:delete(couch_dbs(Server), DbName),
+ true = ets:delete(couch_dbs_pid_to_name(Server), DbPid),
+ exit(DbPid, kill),
+ {noreply, db_closed(Server, DbOpts)};
+ false ->
+ true = ets:update_element(
+ couch_dbs(Server), DbName, {#entry.lock, unlocked}
+ ),
+ {noreply, Server}
+ end;
false ->
- true = ets:update_element(
- couch_dbs(Server), DbName, {#entry.lock, unlocked}
- ),
{noreply, Server}
end;
- false ->
+ _ ->
{noreply, Server}
end;
handle_cast(Msg, Server) ->