diff options
author | Jay Doane <jaydoane@apache.org> | 2020-10-26 09:59:20 -0700 |
---|---|---|
committer | Jay Doane <jay.s.doane@gmail.com> | 2020-10-26 10:36:53 -0700 |
commit | dfb27b48af05ba99c5dd47247580d7f14b7764a6 (patch) | |
tree | 2310c69af87eeb8673238c612bdf64be66c00c11 | |
parent | 4c1980e9d890b4800193de4c7bb0072a2de2ad3b (diff) | |
download | couchdb-dfb27b48af05ba99c5dd47247580d7f14b7764a6.tar.gz |
Use snapshot for cache insertionpost-fdb-merge
Too many parallel attempts to insert the same keys can result in
`{erlfdb_error, 1020}`, which translates to:
"Transaction not committed due to conflict with another transaction"
This attempts to mitigate the problem by using a snapshot to read the
primary key during insertion.
-rw-r--r-- | src/couch_expiring_cache/src/couch_expiring_cache_fdb.erl | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/couch_expiring_cache/src/couch_expiring_cache_fdb.erl b/src/couch_expiring_cache/src/couch_expiring_cache_fdb.erl index 3f6e1aa13..fe37a7c00 100644 --- a/src/couch_expiring_cache/src/couch_expiring_cache_fdb.erl +++ b/src/couch_expiring_cache/src/couch_expiring_cache_fdb.erl @@ -41,7 +41,8 @@ insert(#{jtx := true} = JTx, Name, Key, Val, StaleTS, ExpiresTS) -> #{tx := Tx, layer_prefix := LayerPrefix} = couch_jobs_fdb:get_jtx(JTx), PK = primary_key(Name, Key, LayerPrefix), - case get_val(Tx, PK) of + % Use snapshot here to minimize conflicts on parallel inserts + case get_val(erlfdb:snapshot(Tx), PK) of not_found -> ok; {_OldVal, _OldStaleTS, OldExpiresTS} -> |