client: Fix cache corruption on loadBefore and prefetch (#169)
Currently loadBefore and prefetch spawn async protocol.load_before task, and, after waking up on its completion, populate the cache with received data. But in between the time when protocol.load_before handler is run and the time when protocol.load_before caller wakes up, there is a window in which event loop might be running some other code, including the code that handles invalidateTransaction messages from the server. This means that cache updates and cache invalidations can be processed on the client not in the order that server sent it. And such difference in the order can lead to data corruption if e.g server sent <- loadBefore oid serial=tid1 next_serial=None <- invalidateTransaction tid2 oid and client processed it as invalidateTransaction tid2 oid cache.store(oid, tid1, next_serial=None) because here the end effect is that invalidation for oid@tid2 is not applied to the cache. The fix is simple: perform cache updates right after loadBefore reply is received. Fixes: https://github.com/zopefoundation/ZEO/issues/155 The fix is based on analysis and initial patch by @jmuchemb: https://github.com/zopefoundation/ZEO/issues/155#issuecomment-581046248 A tests corresponding to the fix is coming coming through https://github.com/zopefoundation/ZEO/pull/170 and https://github.com/zopefoundation/ZODB/pull/345 For the reference, my original ZEO-specific data corruption reproducer is here: https://github.com/zopefoundation/ZEO/issues/155#issuecomment-577602842 https://lab.nexedi.com/kirr/wendelin.core/blob/ecd0e7f0/zloadrace5.py /cc @jamadden, @dataflake, @jimfulton /reviewed-by @jmuchemb, @d-maurer /reviewed-on https://github.com/zopefoundation/ZEO/pull/169
Showing
Please register or sign in to comment