You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2023/11/09 18:16:51 UTC
(couchdb) branch fix-bug-in-ets-lru-insert created (now 827ee310b)
This is an automated email from the ASF dual-hosted git repository.
vatamane pushed a change to branch fix-bug-in-ets-lru-insert
in repository https://gitbox.apache.org/repos/asf/couchdb.git
at 827ee310b Fix update bug in ets_lru
This branch includes the following new commits:
new 827ee310b Fix update bug in ets_lru
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 update bug in ets_lru
Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vatamane pushed a commit to branch fix-bug-in-ets-lru-insert
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 827ee310bb6caf5c26286256702464b2715ff618
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Thu Nov 9 12:51:34 2023 -0500
Fix update bug in ets_lru
Previously, when an existing cache entry was updated, we didn't update the
atime. Subsequently, when the entry was removed, we never cleaned the orphan
atime entry. During trimming, we traverse the atime entries, and since the
orphaned one didn't have any matching objects or ctime entrie, the ets_lru
cache would crash, possibly taking down the primary couch supervisor.
---
src/ets_lru/src/ets_lru.erl | 4 +++-
src/ets_lru/test/ets_lru_test.erl | 28 ++++++++++++++++++++++++++++
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/src/ets_lru/src/ets_lru.erl b/src/ets_lru/src/ets_lru.erl
index 891aeeb57..47e34a2a1 100644
--- a/src/ets_lru/src/ets_lru.erl
+++ b/src/ets_lru/src/ets_lru.erl
@@ -168,7 +168,9 @@ handle_call({insert, Key, Val}, _From, St) ->
case ets:match(St#st.objects, Pattern) of
[[ATime]] ->
Update = {#entry.val, Val},
- true = ets:update_element(St#st.objects, Key, Update),
+ true = ets:update_element(St#st.objects, Key, [
+ {#entry.val, Val}, {#entry.atime, NewATime}
+ ]),
true = ets:delete(St#st.atimes, ATime),
true = ets:insert(St#st.atimes, {NewATime, Key});
[] ->
diff --git a/src/ets_lru/test/ets_lru_test.erl b/src/ets_lru/test/ets_lru_test.erl
index be003bee2..9f8b166ac 100644
--- a/src/ets_lru/test/ets_lru_test.erl
+++ b/src/ets_lru/test/ets_lru_test.erl
@@ -132,6 +132,34 @@ basic_behavior_test_() ->
?_assertEqual(not_found, ets_lru:lookup(LRU, foo))
}
]
+ end,
+ fun({ok, LRU}) ->
+ [
+ {
+ "Insert the value twice",
+ ?_assertEqual(ok, ets_lru:insert(LRU, foo, bar))
+ },
+ {
+ "Objects table size should be 1",
+ ?_assertEqual(1, ets:info(test_lru_objects, size))
+ },
+ {
+ "ATimes table size should be 1",
+ ?_assertEqual(1, ets:info(test_lru_atimes, size))
+ },
+ {
+ "CTimes table size should be 1",
+ ?_assertEqual(1, ets:info(test_lru_ctimes, size))
+ },
+ {
+ "Clear LRU after duplicate insert",
+ ?_assertEqual(ok, ets_lru:clear(LRU))
+ },
+ {
+ "Lookup returned not_found after a clear after a duplicate insert",
+ ?_assertEqual(not_found, ets_lru:lookup(LRU, foo))
+ }
+ ]
end
]}
}.