storagejanitor.h 3.76 KB
Newer Older
Volker Krause's avatar
Volker Krause committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
    Copyright (c) 2011 Volker Krause <vkrause@kde.org>

    This library is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This library is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to the
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
*/

#ifndef STORAGEJANITOR_H
#define STORAGEJANITOR_H

23
#include "akthread.h"
24

Daniel Vrátil's avatar
Daniel Vrátil committed
25
#include <QDBusConnection>
Volker Krause's avatar
Volker Krause committed
26

Laurent Montel's avatar
Laurent Montel committed
27
28
29
30
namespace Akonadi
{
namespace Server
{
31

32
33
class Collection;

Volker Krause's avatar
Volker Krause committed
34
35
36
/**
 * Various database checking/maintenance features.
 */
37
class StorageJanitor : public AkThread
Volker Krause's avatar
Volker Krause committed
38
{
39
40
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "org.freedesktop.Akonadi.Janitor")
41

42
public:
Laurent Montel's avatar
Laurent Montel committed
43
    explicit StorageJanitor(QObject *parent = nullptr);
44
    ~StorageJanitor();
Volker Krause's avatar
Volker Krause committed
45

46
public Q_SLOTS:
Volker Krause's avatar
Volker Krause committed
47
48
49
50
51
    /** Triggers a consistency check of the internal storage. */
    Q_SCRIPTABLE Q_NOREPLY void check();
    /** Triggers a vacuuming of the database, that is compacting of unused space. */
    Q_SCRIPTABLE Q_NOREPLY void vacuum();

52
Q_SIGNALS:
Volker Krause's avatar
Volker Krause committed
53
    /** Sends informational messages to a possible UI for this. */
54
    Q_SCRIPTABLE void information(const QString &msg);
55
    Q_SCRIPTABLE void done();
Volker Krause's avatar
Volker Krause committed
56

57
protected:
58
59
    void init() override;
    void quit() override;
60

61
62
63
private:
    void inform(const char *msg);
    void inform(const QString &msg);
64
65
    /** Create a lost+found collection if necessary. */
    qint64 lostAndFoundCollection();
66

67
68
69
70
71
    /**
     * Look for resources in the DB not existing in reality.
     */
    void findOrphanedResources();

72
73
74
75
76
    /**
     * Look for collections belonging to non-existent resources.
     */
    void findOrphanedCollections();

77
    /**
78
     * Verifies there is a path from @p col to the root of the collection tree
Yuri Chornoivan's avatar
Yuri Chornoivan committed
79
     * and that everything along that path belongs to the same resource.
80
     */
81
    void checkPathToRoot(const Collection &col);
82
83
84
85
86

    /**
     * Look for items belonging to non-existing collections.
     */
    void findOrphanedItems();
87
88
89
90
91

    /**
     * Look for parts belonging to non-existing items.
     */
    void findOrphanedParts();
92

93
94
95
96
97
    /**
     * Look for item flags belonging to non-existing items.
     */
    void findOrphanedPimItemFlags();

98
    /**
Christophe Giboudeaux's avatar
Typos    
Christophe Giboudeaux committed
99
     * Look for parts referring to the same external file.
100
101
     */
    void findOverlappingParts();
102
103
104
105
106

    /**
     * Verify fs and db part state.
     */
    void verifyExternalParts();
107

108
109
110
111
112
    /**
     * Look for dirty objects.
     */
    void findDirtyObjects();

113
114
115
116
117
118
119
    /**
     * Look for duplicates by RID.
     *
     * ..and remove the one that doesn't match the parent collections content mimetype.
     */
    void findRIDDuplicates();

120
121
122
123
124
125
126
127
    /**
     * Check whether part sizes match what's in database.
     *
     * If SizeTreshold has change, it will move parts from or to database
     * where necessary.
     */
    void checkSizeTreshold();

128
129
130
131
132
133
    /**
     * Check if all external payload files are migrated to the levelled folder
     * hierarchy and migrates them if necessary
     */
    void migrateToLevelledCacheHierarchy();

134
135
136
137
    /**
     * Check if the search index contains any entries that refer to Akonadi
     * Items that no longer exist in the DB.
     */
Andreas Hartmetz's avatar
Andreas Hartmetz committed
138
    void findOrphanSearchIndexEntries();
139

140
private:
141
    qint64 m_lostFoundCollectionId;
Volker Krause's avatar
Volker Krause committed
142
143
};

144
145
146
} // namespace Server
} // namespace Akonadi

Volker Krause's avatar
Volker Krause committed
147
#endif // STORAGEJANITOR_H