D20326: Akonadiserver: rework handling of database deadlocks.

David Faure noreply at phabricator.kde.org
Sat Apr 6 22:47:17 BST 2019


dfaure created this revision.
dfaure added reviewers: dvratil, vkrause.
Herald added a project: KDE PIM.
dfaure requested review of this revision.

REVISION SUMMARY
  We can't just replay the SQL commands, that's too low-level: if we do
  INSERT, then use the resulting ID into e.g. another INSERT command, at replay
  time we might get a different ID from the first command, and then insert
  the wrong ID in the second one...
  
  So instead we want to re-run the entire handler's parseStream(), which we
  do by throwing a DbDeadlockException (from QueryBuilder), and catching that
  in the caller (Connection) using a helper class (DbDeadlockCatcher, unittested)
  which retries up to 5 times.
  
  For this to work, it means:
  
  - we must also rollback any chances made to in-memory caches (done by
  
  clearing those caches, good enough since DB deadlocks are rare)
  
  - ItemModifyJob which sends parts on demand, shouldn't delete after
  
  sending (it might be asked again) -- this was hit by GidTest (fetchAndSetGid).
  
  Still TODO:
  
  - delaying the updating of intervalChecker and cacheCleaner by NotificationCollector until commit time;
  - checking other users of QueryBuilder (who now can get a DbDeadlockException...)

TEST PLAN
  all this was triggered by a unittest that creates 10 sessions
  and adds 10 different attributes to the same time, one in each session. This very
  often hits the DB deadlock scenario.

REPOSITORY
  R165 Akonadi

BRANCH
  master

REVISION DETAIL
  https://phabricator.kde.org/D20326

AFFECTED FILES
  autotests/libs/itemstoretest.cpp
  autotests/libs/itemstoretest.h
  autotests/server/CMakeLists.txt
  autotests/server/dbdeadlockcatchertest.cpp
  src/core/jobs/itemmodifyjob.cpp
  src/server/connection.cpp
  src/server/connection.h
  src/server/storage/datastore.cpp
  src/server/storage/datastore.h
  src/server/storage/dbdeadlockcatcher.h
  src/server/storage/dbexception.cpp
  src/server/storage/dbexception.h
  src/server/storage/querybuilder.cpp
  src/server/storage/querybuilder.h
  src/server/storage/transaction.cpp

To: dfaure, dvratil, vkrause
Cc: kde-pim, dvasin, rodsevich, winterz, vkrause, mlaurent, knauss, dvratil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-pim/attachments/20190406/a7fe108e/attachment.html>


More information about the kde-pim mailing list