Bug 389441 - kactivitymanagerd does not handle DB corruption properly
Summary: kactivitymanagerd does not handle DB corruption properly
Status: ASSIGNED
Alias: None
Product: kactivitymanagerd
Classification: Plasma
Component: general (show other bugs)
Version: 5.11.95
Platform: Other Linux
: NOR crash
Target Milestone: ---
Assignee: Ivan Čukić
URL:
Keywords:
: 376814 389640 390516 396340 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-01-26 01:59 UTC by Aleix Pol
Modified: 2022-09-03 18:15 UTC (History)
10 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Aleix Pol 2018-01-26 01:59:49 UTC
"SELECT start, end FROM ResourceEvent WHERE :usedActivity      = usedActivity AND :initiatingAgent   = initiatingAgent AND :targettedResource = targettedResource AND start > :start ORDER BY start ASC"
QSqlError("11", "Unable to fetch row", "database disk image is malformed")

BT:
#2 qt_message_fatal() at /home/apol/devel/frameworks/qt5/qtbase/src/corelib/global/qlogging.cpp:1710
#3 QMessageLogger::fatal() at /home/apol/devel/frameworks/qt5/qtbase/src/corelib/global/qlogging.cpp:816
#4 qt_assert_x() at /home/apol/devel/frameworks/qt5/qtbase/src/corelib/global/qglobal.cpp:3131
#5 Utils::exec() at /home/apol/devel/frameworks/kactivitymanagerd/src/service/plugins/sqlite/Utils.h:67
#6 Utils::exec<char const*, unsigned int>() at /home/apol/devel/frameworks/kactivitymanagerd/src/service/plugins/sqlite/Utils.h:79
#7 Utils::exec<char const*, QString, char const*, unsigned int>() at /home/apol/devel/frameworks/kactivitymanagerd/src/service/plugins/sqlite/Utils.h:79
#8 Utils::exec<char const*, QString, char const*, QString, char const*, unsigned int>() at /home/apol/devel/frameworks/kactivitymanagerd/src/service/plugins/sqlite/Utils.h:79
#9 Utils::exec<char [14], QString, char const*, QString, char const*, QString, char const*, unsigned int>() at /home/apol/devel/frameworks/kactivitymanagerd/src/service/plugins/sqlite/Utils.h:79
#10 ResourceScoreCache::update() at /home/apol/devel/frameworks/kactivitymanagerd/src/service/plugins/sqlite/ResourceScoreCache.cpp:208
#11 ResourceScoreMaintainer::Private::processActivity(QString const&, QHash<QString, QList<QString> > const&)::$_1::operator()(QString const&, QList<QString> const&) const() at /home/apol/devel/frameworks/kactivitymanagerd/src/service/plugins/sqlite/ResourceScoreMaintainer.cpp:108
#12 kamd::utils::details::qt_for_each_assoc<QHash<QString, QList<QString> >::const_iterator, ResourceScoreMaintainer::Private::processActivity(QString const&, QHash<QString, QList<QString> > const&)::$_1>(QHash<QString, QList<QString> >::const_iterator, QHash<QString, QList<QString> >::const_iterator, ResourceScoreMaintainer::Private::processActivity(QString const&, QHash<QString, QList<QString> > const&)::$_1)() at /home/apol/devel/frameworks/kactivitymanagerd/src/utils/for_each_assoc.h:41
#13 kamd::utils::details::_for_each_assoc_helper_container<QHash<QString, QList<QString> >, ResourceScoreMaintainer::Private::processActivity(QString const&, QHash<QString, QList<QString> > const&)::$_1>(QHash<QString, QList<QString> > const&, ResourceScoreMaintainer::Private::processActivity(QString const&, QHash<QString, QList<QString> > const&)::$_1, decltype (&QHash<QString, QList<QString> >::constBegin)*)() at /home/apol/devel/frameworks/kactivitymanagerd/src/utils/for_each_assoc.h:62
#14 kamd::utils::for_each_assoc<QHash<QString, QList<QString> >, ResourceScoreMaintainer::Private::processActivity(QString const&, QHash<QString, QList<QString> > const&)::$_1>(QHash<QString, QList<QString> > const&, ResourceScoreMaintainer::Private::processActivity(QString const&, QHash<QString, QList<QString> > const&)::$_1)() at /home/apol/devel/frameworks/kactivitymanagerd/src/utils/for_each_assoc.h:77
#15 ResourceScoreMaintainer::Private::processActivity() at /home/apol/devel/frameworks/kactivitymanagerd/src/service/plugins/sqlite/ResourceScoreMaintainer.cpp:105
#16 ResourceScoreMaintainer::Private::run() at /home/apol/devel/frameworks/kactivitymanagerd/src/service/plugins/sqlite/ResourceScoreMaintainer.cpp:86
#17 QThreadPrivate::start() at /home/apol/devel/frameworks/qt5/qtbase/src/corelib/thread/qthread_unix.cpp:376
#18 start_thread() at /usr/lib/libpthread.so.0
#19 clone() at /usr/lib/libc.so.6

Here's part of my coredumpctl so you see what kind of problem that is. It's about 5 crashes per minute:
Fri 2018-01-26 01:06:56 CET   12014  1000  1000   6 present   /home/apol/devel/kde5/bin/kactivitymanagerd
Fri 2018-01-26 01:06:58 CET   12033  1000  1000   6 present   /home/apol/devel/kde5/bin/kactivitymanagerd
Fri 2018-01-26 01:07:09 CET   12059  1000  1000   6 present   /home/apol/devel/kde5/bin/kactivitymanagerd
Fri 2018-01-26 01:07:55 CET   12099  1000  1000   6 present   /home/apol/devel/kde5/bin/kactivitymanagerd
Fri 2018-01-26 01:08:58 CET   12252  1000  1000   6 present   /home/apol/devel/kde5/bin/kactivitymanagerd
Fri 2018-01-26 01:09:05 CET   12272  1000  1000   6 present   /home/apol/devel/kde5/bin/kactivitymanagerd
Fri 2018-01-26 01:09:44 CET   12311  1000  1000   6 present   /home/apol/devel/kde5/bin/kactivitymanagerd
Fri 2018-01-26 01:09:47 CET   12332  1000  1000   6 present   /home/apol/devel/kde5/bin/kactivitymanagerd
Fri 2018-01-26 01:09:49 CET   12352  1000  1000   6 present   /home/apol/devel/kde5/bin/kactivitymanagerd
Fri 2018-01-26 01:10:35 CET   12441  1000  1000   6 present   /home/apol/devel/kde5/bin/kactivitymanagerd
Fri 2018-01-26 01:11:09 CET   12488  1000  1000   6 present   /home/apol/devel/kde5/bin/kactivitymanagerd
Fri 2018-01-26 01:11:31 CET   12530  1000  1000   6 present   /home/apol/devel/kde5/bin/kactivitymanagerd
Fri 2018-01-26 01:11:35 CET   12570  1000  1000   6 present   /home/apol/devel/kde5/bin/kactivitymanagerd
Fri 2018-01-26 01:11:42 CET   12612  1000  1000   6 present   /home/apol/devel/kde5/bin/kactivitymanagerd
Comment 1 Ivan Čukić 2018-01-28 19:33:17 UTC
"database disk image is malformed"

Seems you have a FS corruption. Can you move the database somewhere else and retry?

mv .local/share/kactivitymanagerd/resources .local/share/kactivitymanagerd/resources-old
Comment 2 Aleix Pol 2018-01-28 22:19:09 UTC
That solved the problem for me, yes.
I'd say the bug is more how kactivitymanagerd goes mental if the db goes corrupt for any reason.
Comment 3 Ivan Čukić 2018-01-29 08:01:19 UTC
Yes relying on upstream to work properly was not a good idea.

I'll probably have to go the Firefox way - export the database from time to time, and in the case of a DB problem, recreate it.
Comment 4 Luca Beltrame 2018-01-30 06:42:26 UTC
When corruption happens, this can lead to losing activity information completely (activity contents are reset to default state), so this effectively causes data loss. I'm not sure if it's due to kamd itself or its interaction with Plasma, though.
Comment 5 Marco Martin 2018-01-31 16:35:03 UTC
i managed to reproduce the error (actually by writing random nonsense in the database file with okteta :p)
tough i couldn't reproduce the loss of activities in plasma.
what i think it could be done is:(which is i think similar to what firefox does)
* when this error occurs, not asserting but try to move the database file in a database.corrupt file
* open it again and repopulate (since activity names and ids are saved in a config file all of this should be fine)
* every now and then backup the content of some tables (even just a text file with the inserts) at least the ResourceLink table
* when this emergency recreation happens, import that text file to have favorites back
Comment 6 Ivan Čukić 2018-02-01 17:07:48 UTC
@Luca

Activity info can not be lost. At least I don't see how it can. What can happen is KAMD refusing to start making Plasma think there is only one activity - 000000-0000-000-00000 (pretend this is a null uuid :) ). But all should be fine when KAMD is restarted with a functioning database. 

Unless something strange is going on.

@Marco

That Okteta use-case is not supported, sorry. :P

Yes, an approach like that would be fine - backup linked resources from time to time, and maybe the score caches, omitting the resource events as they are not that important.
Comment 7 Christoph Feck 2018-03-01 01:28:07 UTC
*** Bug 390516 has been marked as a duplicate of this bug. ***
Comment 8 Ivan Čukić 2018-03-07 22:27:13 UTC
The first step done - KAStats will not do any qFatals and Q_ASSERTS while reading from the database. As requested, it will fail silently (will do a qWarning) and report empty data sets.
Comment 9 Ivan Čukić 2018-03-10 19:08:03 UTC
*** Bug 389640 has been marked as a duplicate of this bug. ***
Comment 10 Nate Graham 2018-07-13 17:44:25 UTC
*** Bug 396340 has been marked as a duplicate of this bug. ***
Comment 11 Nate Graham 2018-08-20 14:10:10 UTC
*** Bug 376814 has been marked as a duplicate of this bug. ***