Akonadi

storagejanitor.h
1/*
2 SPDX-FileCopyrightText: 2011 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "akthread.h"
10#include "storage/dbconfig.h"
11
12#include <QDBusConnection>
13
14namespace Akonadi
15{
16namespace Server
17{
18class Collection;
19class AkonadiServer;
20class DataStore;
21
22/**
23 * Various database checking/maintenance features.
24 */
25class StorageJanitor : public AkThread
26{
28 Q_CLASSINFO("D-Bus Interface", "org.freedesktop.Akonadi.Janitor")
29
30protected:
31 /**
32 * Use AkThread::create() to create and start a new StorageJanitor thread.
33 */
34 explicit StorageJanitor(AkonadiServer *mAkonadi, DbConfig *config = DbConfig::configuredDatabase());
35
36public:
37 /**
38 * Use AkThread::create() to run StorageJanitor in a separate thread. Only use this constructor
39 * if you want to run StorageJanitor in the current thread.
40 */
41 explicit StorageJanitor(DbConfig *config);
42 ~StorageJanitor() override;
43
44public Q_SLOTS:
45 /** Triggers a consistency check of the internal storage. */
46 Q_SCRIPTABLE Q_NOREPLY void check();
47 /** Triggers a vacuuming of the database, that is compacting of unused space. */
48 Q_SCRIPTABLE Q_NOREPLY void vacuum();
49
51 /** Sends informational messages to a possible UI for this. */
52 Q_SCRIPTABLE void information(const QString &msg);
53 Q_SCRIPTABLE void done();
54
55protected:
56 void init() override;
57 void quit() override;
58
59private:
60 void registerTasks();
61
62 void inform(const char *msg);
63 void inform(const QString &msg);
64 /** Create a lost+found collection if necessary. */
65 qint64 lostAndFoundCollection();
66
67 /**
68 * Look for resources in the DB not existing in reality.
69 */
70 void findOrphanedResources();
71
72 /**
73 * Look for collections belonging to non-existent resources.
74 */
75 void findOrphanedCollections();
76
77 /**
78 * Verifies that each collection in the collection tree has a path to the root
79 * and that all collections along that path belong to the same resource.
80 */
81 void checkCollectionTreeConsistency();
82 void checkPathToRoot(const Collection &col);
83
84 /**
85 * Look for items belonging to non-existing collections.
86 */
87 void findOrphanedItems();
88
89 /**
90 * Look for parts belonging to non-existing items.
91 */
92 void findOrphanedParts();
93
94 /**
95 * Look for item flags belonging to non-existing items.
96 */
97 void findOrphanedPimItemFlags();
98
99 /**
100 * Look for duplicate item flags and fix them.
101 */
102 void findDuplicateFlags();
103
104 /**
105 * Look for duplicate mime type names and fix them.
106 */
107 void findDuplicateMimeTypes();
108
109 /**
110 * Look for duplicate part type names and fix them.
111 */
112 void findDuplicatePartTypes();
113
114 /**
115 * Look for duplicate tag names and fix them.
116 */
117 void findDuplicateTagTypes();
118
119 /**
120 * Look for duplicate relation type names and fix them.
121 */
122 void findDuplicateRelationTypes();
123
124 /**
125 * Look for parts referring to the same external file.
126 */
127 void findOverlappingParts();
128
129 /**
130 * Verify fs and db part state.
131 */
132 void verifyExternalParts();
133
134 /**
135 * Look for dirty objects.
136 */
137 void findDirtyObjects();
138
139 /**
140 * Look for duplicates by RID.
141 *
142 * ..and remove the one that doesn't match the parent collections content mimetype.
143 */
144 void findRIDDuplicates();
145
146 /**
147 * Check whether part sizes match what's in database.
148 *
149 * If SizeTreshold has change, it will move parts from or to database
150 * where necessary.
151 */
152 void checkSizeTreshold();
153
154 /**
155 * Check if all external payload files are migrated to the levelled folder
156 * hierarchy and migrates them if necessary
157 */
158 void migrateToLevelledCacheHierarchy();
159
160 /**
161 * Check if the search index contains any entries that refer to Akonadi
162 * Items that no longer exist in the DB.
163 */
164 void findOrphanSearchIndexEntries();
165
166 /**
167 * Make sure that the "Search" collection in the virtual search resource
168 * exists. It is only created during database initialization, so if user
169 * somehow manages to delete it, their search would be completely borked.
170 */
171 void ensureSearchCollection();
172
173 /**
174 * Clear cache that holds pre-computed collection statistics.
175 * They will be re-computed on demand.
176 */
177 void expireCollectionStatisticsCache();
178
179private:
180 qint64 m_lostFoundCollectionId;
181 AkonadiServer *m_akonadi = nullptr;
182 DbConfig *m_dbConfig = nullptr;
183 std::unique_ptr<DataStore> m_dataStore;
184
185 struct Task {
186 QString name;
187 void (StorageJanitor::*func)();
188 };
189 QList<Task> m_tasks;
190};
191
192} // namespace Server
193} // namespace Akonadi
Represents a collection of PIM items.
Definition collection.h:62
A base class that provides an unique access layer to configuration and initialization of different da...
Definition dbconfig.h:21
static DbConfig * configuredDatabase()
Returns the DbConfig instance for the database the user has configured.
Definition dbconfig.cpp:77
Various database checking/maintenance features.
Q_SCRIPTABLE Q_NOREPLY void vacuum()
Triggers a vacuuming of the database, that is compacting of unused space.
StorageJanitor(AkonadiServer *mAkonadi, DbConfig *config=DbConfig::configuredDatabase())
Use AkThread::create() to create and start a new StorageJanitor thread.
Q_SCRIPTABLE Q_NOREPLY void check()
Triggers a consistency check of the internal storage.
Q_SCRIPTABLE void information(const QString &msg)
Sends informational messages to a possible UI for this.
Helper integration between Akonadi and Qt.
Q_CLASSINFO(Name, Value)
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.