Changeset View
Changeset View
Standalone View
Standalone View
src/engine/database.cpp
Show All 35 Lines | |||||
36 | #include "andpostingiterator.h" | 36 | #include "andpostingiterator.h" | ||
37 | #include "orpostingiterator.h" | 37 | #include "orpostingiterator.h" | ||
38 | #include "phraseanditerator.h" | 38 | #include "phraseanditerator.h" | ||
39 | 39 | | |||
40 | #include "writetransaction.h" | 40 | #include "writetransaction.h" | ||
41 | #include "idutils.h" | 41 | #include "idutils.h" | ||
42 | #include "fsutils.h" | 42 | #include "fsutils.h" | ||
43 | 43 | | |||
44 | #include "enginedebug.h" | ||||
45 | | ||||
44 | #include <QFile> | 46 | #include <QFile> | ||
45 | #include <QFileInfo> | 47 | #include <QFileInfo> | ||
46 | #include <QDir> | 48 | #include <QDir> | ||
47 | #include <QMutexLocker> | 49 | #include <QMutexLocker> | ||
48 | 50 | | |||
49 | using namespace Baloo; | 51 | using namespace Baloo; | ||
50 | 52 | | |||
51 | Database::Database(const QString& path) | 53 | Database::Database(const QString& path) | ||
Show All 28 Lines | 69 | { | |||
80 | QFileInfo indexInfo(dir, QStringLiteral("index")); | 82 | QFileInfo indexInfo(dir, QStringLiteral("index")); | ||
81 | 83 | | |||
82 | if ((mode != CreateDatabase) && !indexInfo.exists()) { | 84 | if ((mode != CreateDatabase) && !indexInfo.exists()) { | ||
83 | return false; | 85 | return false; | ||
84 | } | 86 | } | ||
85 | 87 | | |||
86 | if (mode == CreateDatabase) { | 88 | if (mode == CreateDatabase) { | ||
87 | if (!QFileInfo(dir.absolutePath()).permission(QFile::WriteOwner)) { | 89 | if (!QFileInfo(dir.absolutePath()).permission(QFile::WriteOwner)) { | ||
88 | qCritical() << m_path << "does not have write permissions. Aborting"; | 90 | qCCritical(ENGINE) << m_path << "does not have write permissions. Aborting"; | ||
89 | return false; | 91 | return false; | ||
90 | } | 92 | } | ||
91 | 93 | | |||
92 | if (!indexInfo.exists()) { | 94 | if (!indexInfo.exists()) { | ||
93 | FSUtils::disableCoW(m_path); | 95 | FSUtils::disableCoW(m_path); | ||
94 | } | 96 | } | ||
95 | } | 97 | } | ||
96 | 98 | | |||
Show All 21 Lines | |||||
118 | rc = mdb_env_open(m_env, arr.constData(), MDB_NOSUBDIR | MDB_NOMEMINIT | ((mode == ReadOnlyDatabase) ? MDB_RDONLY : 0), 0664); | 120 | rc = mdb_env_open(m_env, arr.constData(), MDB_NOSUBDIR | MDB_NOMEMINIT | ((mode == ReadOnlyDatabase) ? MDB_RDONLY : 0), 0664); | ||
119 | if (rc) { | 121 | if (rc) { | ||
120 | mdb_env_close(m_env); | 122 | mdb_env_close(m_env); | ||
121 | m_env = nullptr; | 123 | m_env = nullptr; | ||
122 | return false; | 124 | return false; | ||
123 | } | 125 | } | ||
124 | 126 | | |||
125 | rc = mdb_reader_check(m_env, nullptr); | 127 | rc = mdb_reader_check(m_env, nullptr); | ||
126 | Q_ASSERT_X(rc == 0, "Database::open reader_check", mdb_strerror(rc)); | 128 | | ||
127 | if (rc) { | 129 | if (rc) { | ||
130 | qCWarning(ENGINE) << "Database::open reader_check" << mdb_strerror(rc); | ||||
128 | mdb_env_close(m_env); | 131 | mdb_env_close(m_env); | ||
129 | m_env = nullptr; | 132 | m_env = nullptr; | ||
130 | return false; | 133 | return false; | ||
131 | } | 134 | } | ||
132 | 135 | | |||
133 | // | 136 | // | ||
134 | // Individual Databases | 137 | // Individual Databases | ||
135 | // | 138 | // | ||
136 | MDB_txn* txn; | 139 | MDB_txn* txn; | ||
137 | if (mode != CreateDatabase) { | 140 | if (mode != CreateDatabase) { | ||
138 | int rc = mdb_txn_begin(m_env, nullptr, MDB_RDONLY, &txn); | 141 | int rc = mdb_txn_begin(m_env, nullptr, MDB_RDONLY, &txn); | ||
139 | Q_ASSERT_X(rc == 0, "Database::transaction ro begin", mdb_strerror(rc)); | | |||
140 | if (rc) { | 142 | if (rc) { | ||
143 | qCWarning(ENGINE) << "Database::transaction ro begin" << mdb_strerror(rc); | ||||
141 | mdb_env_close(m_env); | 144 | mdb_env_close(m_env); | ||
142 | m_env = nullptr; | 145 | m_env = nullptr; | ||
143 | return false; | 146 | return false; | ||
144 | } | 147 | } | ||
145 | 148 | | |||
146 | m_dbis.postingDbi = PostingDB::open(txn); | 149 | m_dbis.postingDbi = PostingDB::open(txn); | ||
147 | m_dbis.positionDBi = PositionDB::open(txn); | 150 | m_dbis.positionDBi = PositionDB::open(txn); | ||
148 | 151 | | |||
149 | m_dbis.docTermsDbi = DocumentDB::open("docterms", txn); | 152 | m_dbis.docTermsDbi = DocumentDB::open("docterms", txn); | ||
150 | m_dbis.docFilenameTermsDbi = DocumentDB::open("docfilenameterms", txn); | 153 | m_dbis.docFilenameTermsDbi = DocumentDB::open("docfilenameterms", txn); | ||
151 | m_dbis.docXattrTermsDbi = DocumentDB::open("docxatrrterms", txn); | 154 | m_dbis.docXattrTermsDbi = DocumentDB::open("docxatrrterms", txn); | ||
152 | 155 | | |||
153 | m_dbis.idTreeDbi = IdTreeDB::open(txn); | 156 | m_dbis.idTreeDbi = IdTreeDB::open(txn); | ||
154 | m_dbis.idFilenameDbi = IdFilenameDB::open(txn); | 157 | m_dbis.idFilenameDbi = IdFilenameDB::open(txn); | ||
155 | 158 | | |||
156 | m_dbis.docTimeDbi = DocumentTimeDB::open(txn); | 159 | m_dbis.docTimeDbi = DocumentTimeDB::open(txn); | ||
157 | m_dbis.docDataDbi = DocumentDataDB::open(txn); | 160 | m_dbis.docDataDbi = DocumentDataDB::open(txn); | ||
158 | 161 | | |||
159 | m_dbis.contentIndexingDbi = DocumentIdDB::open("indexingleveldb", txn); | 162 | m_dbis.contentIndexingDbi = DocumentIdDB::open("indexingleveldb", txn); | ||
160 | m_dbis.failedIdDbi = DocumentIdDB::open("failediddb", txn); | 163 | m_dbis.failedIdDbi = DocumentIdDB::open("failediddb", txn); | ||
161 | 164 | | |||
162 | m_dbis.mtimeDbi = MTimeDB::open(txn); | 165 | m_dbis.mtimeDbi = MTimeDB::open(txn); | ||
163 | 166 | | |||
164 | Q_ASSERT(m_dbis.isValid()); | | |||
165 | if (!m_dbis.isValid()) { | 167 | if (!m_dbis.isValid()) { | ||
168 | qCWarning(ENGINE) << "dbis is invalid"; | ||||
166 | mdb_txn_abort(txn); | 169 | mdb_txn_abort(txn); | ||
167 | mdb_env_close(m_env); | 170 | mdb_env_close(m_env); | ||
168 | m_env = nullptr; | 171 | m_env = nullptr; | ||
169 | return false; | 172 | return false; | ||
170 | } | 173 | } | ||
171 | 174 | | |||
172 | rc = mdb_txn_commit(txn); | 175 | rc = mdb_txn_commit(txn); | ||
173 | Q_ASSERT_X(rc == 0, "Database::transaction ro commit", mdb_strerror(rc)); | | |||
174 | if (rc) { | 176 | if (rc) { | ||
177 | qCWarning(ENGINE) << "Database::transaction ro commit" << mdb_strerror(rc); | ||||
175 | mdb_env_close(m_env); | 178 | mdb_env_close(m_env); | ||
176 | m_env = nullptr; | 179 | m_env = nullptr; | ||
177 | return false; | 180 | return false; | ||
178 | } | 181 | } | ||
179 | } else { | 182 | } else { | ||
180 | int rc = mdb_txn_begin(m_env, nullptr, 0, &txn); | 183 | int rc = mdb_txn_begin(m_env, nullptr, 0, &txn); | ||
181 | Q_ASSERT_X(rc == 0, "Database::transaction begin", mdb_strerror(rc)); | | |||
182 | if (rc) { | 184 | if (rc) { | ||
185 | qCWarning(ENGINE) << "Database::transaction begin" << mdb_strerror(rc); | ||||
183 | mdb_env_close(m_env); | 186 | mdb_env_close(m_env); | ||
184 | m_env = nullptr; | 187 | m_env = nullptr; | ||
185 | return false; | 188 | return false; | ||
186 | } | 189 | } | ||
187 | 190 | | |||
188 | m_dbis.postingDbi = PostingDB::create(txn); | 191 | m_dbis.postingDbi = PostingDB::create(txn); | ||
189 | m_dbis.positionDBi = PositionDB::create(txn); | 192 | m_dbis.positionDBi = PositionDB::create(txn); | ||
190 | 193 | | |||
191 | m_dbis.docTermsDbi = DocumentDB::create("docterms", txn); | 194 | m_dbis.docTermsDbi = DocumentDB::create("docterms", txn); | ||
192 | m_dbis.docFilenameTermsDbi = DocumentDB::create("docfilenameterms", txn); | 195 | m_dbis.docFilenameTermsDbi = DocumentDB::create("docfilenameterms", txn); | ||
193 | m_dbis.docXattrTermsDbi = DocumentDB::create("docxatrrterms", txn); | 196 | m_dbis.docXattrTermsDbi = DocumentDB::create("docxatrrterms", txn); | ||
194 | 197 | | |||
195 | m_dbis.idTreeDbi = IdTreeDB::create(txn); | 198 | m_dbis.idTreeDbi = IdTreeDB::create(txn); | ||
196 | m_dbis.idFilenameDbi = IdFilenameDB::create(txn); | 199 | m_dbis.idFilenameDbi = IdFilenameDB::create(txn); | ||
197 | 200 | | |||
198 | m_dbis.docTimeDbi = DocumentTimeDB::create(txn); | 201 | m_dbis.docTimeDbi = DocumentTimeDB::create(txn); | ||
199 | m_dbis.docDataDbi = DocumentDataDB::create(txn); | 202 | m_dbis.docDataDbi = DocumentDataDB::create(txn); | ||
200 | 203 | | |||
201 | m_dbis.contentIndexingDbi = DocumentIdDB::create("indexingleveldb", txn); | 204 | m_dbis.contentIndexingDbi = DocumentIdDB::create("indexingleveldb", txn); | ||
202 | m_dbis.failedIdDbi = DocumentIdDB::create("failediddb", txn); | 205 | m_dbis.failedIdDbi = DocumentIdDB::create("failediddb", txn); | ||
203 | 206 | | |||
204 | m_dbis.mtimeDbi = MTimeDB::create(txn); | 207 | m_dbis.mtimeDbi = MTimeDB::create(txn); | ||
205 | 208 | | |||
206 | Q_ASSERT(m_dbis.isValid()); | 209 | if (!m_dbis.isValid()) | ||
207 | if (!m_dbis.isValid()) { | 210 | qCWarning(ENGINE) << "dbis is invalid";{ | ||
208 | mdb_txn_abort(txn); | 211 | mdb_txn_abort(txn); | ||
209 | mdb_env_close(m_env); | 212 | mdb_env_close(m_env); | ||
210 | m_env = nullptr; | 213 | m_env = nullptr; | ||
211 | return false; | 214 | return false; | ||
212 | } | 215 | } | ||
213 | 216 | | |||
214 | rc = mdb_txn_commit(txn); | 217 | rc = mdb_txn_commit(txn); | ||
215 | Q_ASSERT_X(rc == 0, "Database::transaction commit", mdb_strerror(rc)); | | |||
216 | if (rc) { | 218 | if (rc) { | ||
219 | qCWarning(ENGINE) << "Database::transaction commit" << mdb_strerror(rc); | ||||
217 | mdb_env_close(m_env); | 220 | mdb_env_close(m_env); | ||
218 | m_env = nullptr; | 221 | m_env = nullptr; | ||
219 | return false; | 222 | return false; | ||
220 | } | 223 | } | ||
221 | } | 224 | } | ||
222 | 225 | | |||
223 | Q_ASSERT(m_env); | 226 | Q_ASSERT(m_env); | ||
224 | return true; | 227 | return true; | ||
Show All 13 Lines |