Commit 16a563bc authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Server: Improve debug, warning and error log messages

The log messages should be understandable even without wider context
and should contain references to entities or tasks that have failed.
parent 7de3e6d1
......@@ -177,7 +177,7 @@ void ItemSyncPrivate::checkDone()
if (allProcessed() && !mFinished) {
// prevent double result emission, can happen since checkDone() is called from all over the place
qCDebug(AKONADICORE_LOG) << "finished";
qCDebug(AKONADICORE_LOG) << "ItemSync of collection" mSyncCollection.id() << "finished";
mFinished = true;
q->emitResult();
}
......
......@@ -176,6 +176,8 @@ private:
friend AKONADIPRIVATE_EXPORT void toJson(const Akonadi::Protocol::Command *cmd, QJsonObject &json);
};
AKONADIPRIVATE_EXPORT QDebug operator<<(QDebug dbg, Command::Type type);
} // namespace Protocol
} // namespace Akonadi
......@@ -183,6 +185,7 @@ Q_DECLARE_METATYPE(Akonadi::Protocol::Command::Type)
Q_DECLARE_METATYPE(Akonadi::Protocol::CommandPtr)
namespace Akonadi {
namespace Protocol {
......
......@@ -73,6 +73,8 @@ AkonadiServer::AkonadiServer(QObject *parent)
bool AkonadiServer::init()
{
qCInfo(AKONADISERVER_LOG) << "Starting up the Akonadi Server...";
const QString serverConfigFile = StandardDirs::serverConfigFile(StandardDirs::ReadWrite);
QSettings settings(serverConfigFile, QSettings::IniFormat);
// Restrict permission to 600, as the file might contain database password in plaintext
......
......@@ -137,12 +137,12 @@ void CacheCleaner::collectionExpired(const Collection &collection)
if (qb.exec()) {
const Part::List parts = qb.result();
if (!parts.isEmpty()) {
qCDebug(AKONADISERVER_LOG) << "found" << parts.count() << "item parts to expire in collection" << collection.name();
qCInfo(AKONADISERVER_LOG) << "CacheCleaner found" << parts.count() << "item parts to expire in collection" << collection.name();
// clear data field
for (Part part : parts) {
try {
if (!PartHelper::truncate(part)) {
qCDebug(AKONADISERVER_LOG) << "failed to update item part" << part.id();
qCWarning(AKONADISERVER_LOG) << "CacheCleaner failed to expire item part" << part.id();
}
} catch (const PartHelperException &e) {
qCCritical(AKONADISERVER_LOG) << e.type() << e.what();
......
......@@ -176,7 +176,7 @@ void Connection::slotConnectionIdle()
// But it is safer to abort and leave the connection open, until
// a later operation causes the idle timer to fire (than crash
// the akonadi server).
qCDebug(AKONADISERVER_LOG) << m_sessionId << "NOT Closing idle db connection; we are in transaction";
qCInfo(AKONADISERVER_LOG) << m_sessionId << "NOT Closing idle db connection; we are in transaction";
return;
}
m_backend->close();
......@@ -235,16 +235,19 @@ void Connection::handleIncomingData()
try {
cmd = Protocol::deserialize(m_socket);
} catch (const Akonadi::ProtocolException &e) {
qCWarning(AKONADISERVER_LOG) << "ProtocolException:" << e.what();
qCWarning(AKONADISERVER_LOG) << "ProtocolException while deserializing incoming data on connection"
<< m_identifier << ":" << e.what();
setState(Server::LoggingOut);
return;
} catch (const std::exception &e) {
qCWarning(AKONADISERVER_LOG) << "Unknown exception:" << e.what();
qCWarning(AKONADISERVER_LOG) << "Unknown exception while deserializing incoming data on connection"
<< m_identifier << ":" << e.what();
setState(Server::LoggingOut);
return;
}
if (cmd->type() == Protocol::Command::Invalid) {
qCWarning(AKONADISERVER_LOG) << "Received an invalid command: resetting connection";
qCWarning(AKONADISERVER_LOG) << "Received an invalid command on connection" << m_identifier
<< ": resetting connection";
setState(Server::LoggingOut);
return;
}
......@@ -258,7 +261,8 @@ void Connection::handleIncomingData()
m_currentHandler = std::unique_ptr<Handler>(findHandlerForCommand(cmd->type()));
if (!m_currentHandler) {
qCWarning(AKONADISERVER_LOG) << "Invalid command: no such handler for" << cmd->type();
qCWarning(AKONADISERVER_LOG) << "Invalid command: no such handler for" << cmd->type()
<< "on connection" << m_identifier;
setState(Server::LoggingOut);
return;
}
......@@ -272,34 +276,38 @@ void Connection::handleIncomingData()
try {
if (!m_currentHandler->parseStream()) {
try {
m_currentHandler->failureResponse("Unknown error while handling a command");
m_currentHandler->failureResponse("Error while handling a command");
} catch (...) {
qCWarning(AKONADISERVER_LOG) << "Unknown error while handling a command";
m_connectionClosing = true;
}
qCWarning(AKONADISERVER_LOG) << "Error while handling command" << cmd->type()
<< "on connection" << m_identifier;
}
} catch (const Akonadi::Server::HandlerException &e) {
if (m_currentHandler) {
try {
m_currentHandler->failureResponse(e.what());
} catch (...) {
qCWarning(AKONADISERVER_LOG) << "Handler exception:" << e.what();
m_connectionClosing = true;
}
qCWarning(AKONADISERVER_LOG) << "Handler exception when handling command" << cmd->type()
<< "on connection" << m_identifier << ":" << e.what();
}
} catch (const Akonadi::Server::Exception &e) {
if (m_currentHandler) {
try {
m_currentHandler->failureResponse(QString::fromUtf8(e.type()) + QLatin1String(": ") + QString::fromUtf8(e.what()));
} catch (...) {
qCWarning(AKONADISERVER_LOG) << e.type() << "exception:" << e.what();
m_connectionClosing = true;
}
qCWarning(AKONADISERVER_LOG) << "General exception when handling command" << cmd->type()
<< "on connection" << m_identifier << ":" << e.what();
}
} catch (const Akonadi::ProtocolException &e) {
// No point trying to send anything back to client, the connection is
// already messed up
qCWarning(AKONADISERVER_LOG) << "Protocol exception:" << e.what();
qCWarning(AKONADISERVER_LOG) << "Protocol exception when handling command" << cmd->type()
<< "on connection" << m_identifier << ":" << e.what();
m_connectionClosing = true;
#if defined(Q_OS_LINUX)
} catch (abi::__forced_unwind&) {
......@@ -313,12 +321,12 @@ void Connection::handleIncomingData()
throw;
#endif
} catch (...) {
qCCritical(AKONADISERVER_LOG) << "Unknown exception caught in Connection for session" << m_sessionId;
qCCritical(AKONADISERVER_LOG) << "Unknown exception while handling command" << cmd->type()
<< "on connection" << m_identifier;
if (m_currentHandler) {
try {
m_currentHandler->failureResponse("Unknown exception caught");
} catch (...) {
qCWarning(AKONADISERVER_LOG) << "Unknown exception caught";
m_connectionClosing = true;
}
}
......
......@@ -433,9 +433,9 @@ bool AkAppend::parseStream()
}
storageTrx.commit();
} else {
qCDebug(AKONADISERVER_LOG) << "Multiple merge candidates:";
qCWarning(AKONADISERVER_LOG) << "Multiple merge candidates:";
for (const PimItem &item : result) {
qCDebug(AKONADISERVER_LOG) << "\tID:" << item.id() << ", RID:" << item.remoteId()
qCWarning(AKONADISERVER_LOG) << "\tID:" << item.id() << ", RID:" << item.remoteId()
<< ", GID:" << item.gid()
<< ", Collection:" << item.collection().name() << "(" << item.collectionId() << ")"
<< ", Resource:" << item.collection().resource().name() << "(" << item.collection().resourceId() << ")";
......
......@@ -61,7 +61,8 @@ QStack<Collection> List::ancestorsForCollection(const Collection &col)
parent = mCollections.value(parent.parentId());
}
if (!parent.isValid()) {
qCWarning(AKONADISERVER_LOG) << col.id();
qCWarning(AKONADISERVER_LOG) << "Found an invalid parent in ancestors of Collection" << col.name()
<< "(ID:" << col.id() << ")";
throw HandlerException("Found invalid parent in ancestors");
}
ancestors.prepend(parent);
......@@ -272,7 +273,6 @@ void List::retrieveCollections(const Collection &topParent, int depth)
if (mCollectionsToSynchronize) {
qb.addCondition(filterCondition(Collection::syncPrefFullColumnName()));
} else if (mCollectionsToDisplay) {
qCDebug(AKONADISERVER_LOG) << "only display";
qb.addCondition(filterCondition(Collection::displayPrefFullColumnName()));
} else if (mCollectionsToIndex) {
qb.addCondition(filterCondition(Collection::indexPrefFullColumnName()));
......@@ -439,7 +439,6 @@ void List::retrieveCollections(const Collection &topParent, int depth)
auto it = mCollections.begin();
while (it != mCollections.end()) {
const Collection col = it.value();
// qCDebug(AKONADISERVER_LOG) << "col " << col.id();
QStringList mimeTypes;
{
......@@ -451,9 +450,7 @@ void List::retrieveCollections(const Collection &topParent, int depth)
mimeTypeQuery.next(); //place at first record
}
// qCDebug(AKONADISERVER_LOG) << mimeTypeQuery.isValid() << mimeTypeQuery.value(0).toLongLong();
while (mimeTypeQuery.isValid() && mimeTypeQuery.value(0).toLongLong() < col.id()) {
qCDebug(AKONADISERVER_LOG) << "skipped: " << mimeTypeQuery.value(0).toLongLong() << mimeTypeQuery.value(2).toString();
if (!mimeTypeQuery.next()) {
break;
}
......@@ -477,9 +474,7 @@ void List::retrieveCollections(const Collection &topParent, int depth)
attributeQuery.next(); //place at first record
}
// qCDebug(AKONADISERVER_LOG) << attributeQuery.isValid() << attributeQuery.value(0).toLongLong();
while (attributeQuery.isValid() && attributeQuery.value(0).toLongLong() < col.id()) {
qCDebug(AKONADISERVER_LOG) << "skipped: " << attributeQuery.value(0).toLongLong() << attributeQuery.value(1).toByteArray();
if (!attributeQuery.next()) {
break;
}
......
......@@ -143,7 +143,8 @@ bool Modify::parseStream()
if (cmd.modifiedParts() & Protocol::ModifyCollectionCommand::RemoteID) {
if (cmd.remoteId() != collection.remoteId() && !cmd.remoteId().isEmpty()) {
if (!connection()->isOwnerResource(collection)) {
qCWarning(AKONADISERVER_LOG) << "Invalid attempt to modify the collection remoteID from" << collection.remoteId() << "to" << cmd.remoteId();
qCWarning(AKONADISERVER_LOG) << "Invalid attempt to modify the collection remoteID from"
<< collection.remoteId() << "to" << cmd.remoteId();
return failureResponse("Only resources can modify remote identifiers");
}
collection.setRemoteId(cmd.remoteId());
......
......@@ -57,7 +57,7 @@ bool Store::replaceFlags(const PimItem::List &item, const QSet<QByteArray> &flag
DataStore *store = connection()->storageBackend();
if (!store->setItemsFlags(item, flagList, &flagsChanged)) {
qCDebug(AKONADISERVER_LOG) << "Store::replaceFlags: Unable to replace flags";
qCWarning(AKONADISERVER_LOG) << "Store::replaceFlags: Unable to replace flags";
return false;
}
......@@ -70,7 +70,7 @@ bool Store::addFlags(const PimItem::List &items, const QSet<QByteArray> &flags,
DataStore *store = connection()->storageBackend();
if (!store->appendItemsFlags(items, flagList, &flagsChanged)) {
qCDebug(AKONADISERVER_LOG) << "Store::addFlags: Unable to add new item flags";
qCWarning(AKONADISERVER_LOG) << "Store::addFlags: Unable to add new item flags";
return false;
}
return true;
......@@ -92,7 +92,7 @@ bool Store::deleteFlags(const PimItem::List &items, const QSet<QByteArray> &flag
}
if (!store->removeItemsFlags(items, flagList, &flagsChanged)) {
qCDebug(AKONADISERVER_LOG) << "Store::deleteFlags: Unable to remove item flags";
qCWarning(AKONADISERVER_LOG) << "Store::deleteFlags: Unable to remove item flags";
return false;
}
return true;
......@@ -102,7 +102,7 @@ bool Store::replaceTags(const PimItem::List &item, const Scope &tags, bool &tags
{
const Tag::List tagList = HandlerHelper::tagsFromScope(tags, connection());
if (!connection()->storageBackend()->setItemsTags(item, tagList, &tagsChanged)) {
qCDebug(AKONADISERVER_LOG) << "Store::replaceTags: unable to replace tags";
qCWarning(AKONADISERVER_LOG) << "Store::replaceTags: unable to replace tags";
return false;
}
return true;
......@@ -112,7 +112,7 @@ bool Store::addTags(const PimItem::List &items, const Scope &tags, bool &tagsCha
{
const Tag::List tagList = HandlerHelper::tagsFromScope(tags, connection());
if (!connection()->storageBackend()->appendItemsTags(items, tagList, &tagsChanged)) {
qCDebug(AKONADISERVER_LOG) << "Store::addTags: Unable to add new item tags";
qCWarning(AKONADISERVER_LOG) << "Store::addTags: Unable to add new item tags";
return false;
}
return true;
......@@ -122,7 +122,7 @@ bool Store::deleteTags(const PimItem::List &items, const Scope &tags, bool &tags
{
const Tag::List tagList = HandlerHelper::tagsFromScope(tags, connection());
if (!connection()->storageBackend()->removeItemsTags(items, tagList, &tagsChanged)) {
qCDebug(AKONADISERVER_LOG) << "Store::deleteTags: Unable to remove item tags";
qCWarning(AKONADISERVER_LOG) << "Store::deleteTags: Unable to remove item tags";
return false;
}
return true;
......
......@@ -213,7 +213,6 @@ Protocol::FetchTagsResponse HandlerHelper::fetchTagsResponse(const Tag &tag,
{
Protocol::FetchTagsResponse response;
response.setId(tag.id());
qCDebug(AKONADISERVER_LOG) << "TAGFETCH IDONLY" << tagFetchScope.fetchIdOnly();
if (tagFetchScope.fetchIdOnly()) {
return response;
}
......@@ -221,9 +220,7 @@ Protocol::FetchTagsResponse HandlerHelper::fetchTagsResponse(const Tag &tag,
response.setType(tag.tagType().name().toUtf8());
response.setParentId(tag.parentId());
response.setGid(tag.gid().toUtf8());
qCDebug(AKONADISERVER_LOG) << "TAGFETCH" << tagFetchScope.fetchRemoteID() << connection;
if (tagFetchScope.fetchRemoteID() && connection) {
qCDebug(AKONADISERVER_LOG) << connection->context()->resource().name();
// Fail silently if retrieving tag RID is not allowed in current context
if (connection->context()->resource().isValid()) {
QueryBuilder qb(TagRemoteIdResourceRelation::tableName());
......
......@@ -77,7 +77,7 @@ int main(int argc, char **argv)
const int result = app.exec();
qCDebug(AKONADISERVER_LOG) << "Shutting down AkonadiServer...";
qCInfo(AKONADISERVER_LOG) << "Shutting down AkonadiServer...";
Akonadi::Server::AkonadiServer::instance()->quit();
Q_CLEANUP_RESOURCE(akonadidb);
......
......@@ -104,7 +104,7 @@ void NotificationManager::registerConnection(quintptr socketDescriptor)
Q_ASSERT(thread() == QThread::currentThread());
NotificationSubscriber *subscriber = new NotificationSubscriber(this, socketDescriptor);
qCDebug(AKONADISERVER_LOG) << "New notification connection (registered as" << subscriber << ")";
qCInfo(AKONADISERVER_LOG) << "New notification connection (registered as" << subscriber << ")";
connect(subscriber, &NotificationSubscriber::notificationDebuggingChanged,
this, [this](bool enabled) {
if (enabled) {
......
......@@ -91,16 +91,16 @@ void NotificationSubscriber::handleIncomingData()
try {
cmd = Protocol::deserialize(mSocket);
} catch (const Akonadi::ProtocolException &e) {
qCWarning(AKONADISERVER_LOG) << "ProtocolException:" << e.what();
qCWarning(AKONADISERVER_LOG) << "ProtocolException while reading from notification bus for" << mSubscriber << ":" << e.what();
disconnectSubscriber();
return;
} catch (const std::exception &e) {
qCWarning(AKONADISERVER_LOG) << "Unknown exception:" << e.what();
qCWarning(AKONADISERVER_LOG) << "Unknown exception while reading from notification bus for" << mSubscriber << ":" << e.what();
disconnectSubscriber();
return;
}
if (cmd->type() == Protocol::Command::Invalid) {
qCWarning(AKONADISERVER_LOG) << "Received an invalid command: resetting connection";
qCWarning(AKONADISERVER_LOG) << "Invalid command while reading from notification bus for " << mSubscriber << ", resetting connection";
disconnectSubscriber();
return;
}
......@@ -112,7 +112,7 @@ void NotificationSubscriber::handleIncomingData()
break;
case Protocol::Command::ModifySubscription:
if (mSubscriber.isEmpty()) {
qCWarning(AKONADISERVER_LOG) << "Received ModifySubscription command before RegisterSubscriber";
qCWarning(AKONADISERVER_LOG) << "Notification subscriber received ModifySubscription command before RegisterSubscriber";
disconnectSubscriber();
return;
}
......@@ -123,7 +123,7 @@ void NotificationSubscriber::handleIncomingData()
disconnectSubscriber();
break;
default:
qCWarning(AKONADISERVER_LOG) << "Invalid command" << cmd->type() << "received by NotificationSubscriber" << mSubscriber;
qCWarning(AKONADISERVER_LOG) << "Notification subscriber for" << mSubscriber << "received an invalid command" << cmd->type();
disconnectSubscriber();
break;
}
......@@ -132,7 +132,7 @@ void NotificationSubscriber::handleIncomingData()
void NotificationSubscriber::socketDisconnected()
{
qCDebug(AKONADISERVER_LOG) << "Subscriber" << mSubscriber << "disconnected";
qCInfo(AKONADISERVER_LOG) << "Subscriber" << mSubscriber << "disconnected";
disconnectSubscriber();
}
......@@ -171,7 +171,7 @@ void NotificationSubscriber::registerSubscriber(const Protocol::CreateSubscripti
{
QMutexLocker locker(&mLock);
qCDebug(AKONADISERVER_LOG) << "Subscriber" << this << "identified as" << command.subscriberName();
qCInfo(AKONADISERVER_LOG) << "Subscriber" << this << "identified as" << command.subscriberName();
mSubscriber = command.subscriberName();
mSession = command.session();
......@@ -667,7 +667,7 @@ bool NotificationSubscriber::acceptsNotification(const Protocol::ChangeNotificat
return acceptsDebugChangeNotification(static_cast<const Protocol::DebugChangeNotification &>(msg));
default:
qCDebug(AKONADISERVER_LOG) << "Received invalid change notification!";
qCWarning(AKONADISERVER_LOG) << "NotificationSubscriber" << mSubscriber << "received an invalid notification type" << msg.type();
return false;
}
}
......@@ -723,12 +723,12 @@ void NotificationSubscriber::writeCommand(qint64 tag, const Protocol::CommandPtr
Protocol::serialize(mSocket, cmd);
if (!mSocket->waitForBytesWritten()) {
if (mSocket->state() == QLocalSocket::ConnectedState) {
qCWarning(AKONADISERVER_LOG) << "Notification socket write timeout!";
qCWarning(AKONADISERVER_LOG) << "NotificationSubscriber for" << mSubscriber << ": timeout writing into stream";
} else {
// client has disconnected, just discard the message
}
}
} catch (const ProtocolException &e) {
qCWarning(AKONADISERVER_LOG) << "Notification protocol exception:" << e.what();
qCWarning(AKONADISERVER_LOG) << "ProtocolException while writing into stream for subscriber" << mSubscriber << ":" << e.what();
}
}
......@@ -157,7 +157,7 @@ void SearchManager::loadSearchPlugins()
QStringList loadedPlugins;
const QString pluginOverride = QString::fromLatin1(qgetenv("AKONADI_OVERRIDE_SEARCHPLUGIN"));
if (!pluginOverride.isEmpty()) {
qCDebug(AKONADISERVER_SEARCH_LOG) << "Overriding the search plugins with: " << pluginOverride;
qCInfo(AKONADISERVER_SEARCH_LOG) << "Overriding the search plugins with: " << pluginOverride;
}
const QStringList dirs = QCoreApplication::libraryPaths();
......@@ -170,7 +170,6 @@ void SearchManager::loadSearchPlugins()
std::unique_ptr<QPluginLoader> loader(new QPluginLoader(filePath));
const QVariantMap metadata = loader->metaData().value(QStringLiteral("MetaData")).toVariant().toMap();
if (metadata.value(QStringLiteral("X-Akonadi-PluginType")).toString() != QLatin1String("SearchPlugin")) {
qCDebug(AKONADISERVER_SEARCH_LOG) << "===>" << fileName << metadata.value(QStringLiteral("X-Akonadi-PluginType")).toString();
continue;
}
......@@ -374,9 +373,9 @@ void SearchManager::updateSearchImpl(const Collection &collection)
DataStore::self()->notificationCollector()->itemsUnlinked(removedItems, collection);
}
qCDebug(AKONADISERVER_SEARCH_LOG) << "Search update finished";
qCDebug(AKONADISERVER_SEARCH_LOG) << "All results:" << results.count();
qCDebug(AKONADISERVER_SEARCH_LOG) << "Removed results:" << toRemove.count();
qCInfo(AKONADISERVER_SEARCH_LOG) << "Search update for collection" << collection.name()
<< "(" << collection.id() << ") finished:"
<< "all results: " << results.count() << ", removed results:" << toRemove.count();
}
void SearchManager::searchUpdateResultsAvailable(const QSet<qint64> &results)
......@@ -444,7 +443,7 @@ void SearchManager::searchUpdateResultsAvailable(const QSet<qint64> &results)
}
if (!transaction.commit()) {
qCDebug(AKONADISERVER_SEARCH_LOG) << "Failed to commit transaction";
qCWarning(AKONADISERVER_SEARCH_LOG) << "Failed to commit search results transaction";
return;
}
......
......@@ -113,7 +113,7 @@ void SearchRequest::searchPlugins()
void SearchRequest::exec()
{
qCDebug(AKONADISERVER_SEARCH_LOG) << "Executing search" << mConnectionId;
qCInfo(AKONADISERVER_SEARCH_LOG) << "Executing search" << mConnectionId;
//TODO should we move this to the AgentSearchManager as well? If we keep it here the agents can be searched in parallel
//since the plugin search is executed in this thread directly.
......@@ -121,7 +121,7 @@ void SearchRequest::exec()
// If remote search is disabled, just finish here after searching the plugins
if (!mRemoteSearch) {
qCDebug(AKONADISERVER_SEARCH_LOG) << "Search done" << mConnectionId << "(without remote search)";
qCInfo(AKONADISERVER_SEARCH_LOG) << "Search " << mConnectionId << "done (without remote search)";
return;
}
......@@ -137,17 +137,16 @@ void SearchRequest::exec()
task.sharedLock.lock();
Q_FOREVER {
if (task.complete) {
qCDebug(AKONADISERVER_SEARCH_LOG) << "All queries processed!";
break;
} else {
task.notifier.wait(&task.sharedLock);
qCDebug(AKONADISERVER_SEARCH_LOG) << task.pendingResults.count() << "search results available in search" << task.id;
if (!task.pendingResults.isEmpty()) {
emitResults(task.pendingResults);
}
task.pendingResults.clear();
}
task.notifier.wait(&task.sharedLock);
qCDebug(AKONADISERVER_SEARCH_LOG) << task.pendingResults.count() << "search results available in search" << task.id;
if (!task.pendingResults.isEmpty()) {
emitResults(task.pendingResults);
}
task.pendingResults.clear();
}
if (!task.pendingResults.isEmpty()) {
......@@ -155,5 +154,5 @@ void SearchRequest::exec()
}
task.sharedLock.unlock();
qCDebug(AKONADISERVER_SEARCH_LOG) << "Search done" << mConnectionId;
qCInfo(AKONADISERVER_SEARCH_LOG) << "Search" << mConnectionId << "done (with remote search)";
}
......@@ -352,7 +352,7 @@ bool DataStore::doAppendItemsFlag(const PimItem::List &items, const Flag &flag,
qb2.setColumnValue(PimItemFlagRelation::rightColumn(), flagIds);
qb2.setIdentificationColumn(QString());
if (!qb2.exec()) {
qCDebug(AKONADISERVER_LOG) << "Failed to execute query:" << qb2.query().lastError();
qCWarning(AKONADISERVER_LOG) << "Failed to append flag" << flag.name() << "to Items" << appendIds;
return false;
}
......@@ -386,7 +386,7 @@ bool DataStore::appendItemsFlags(const PimItem::List &items, const QVector<Flag>
qb.addCondition(cond);
if (!qb.exec()) {
qCDebug(AKONADISERVER_LOG) << "Failed to execute query:" << qb.query().lastError();
qCWarning(AKONADISERVER_LOG) << "Failed to retrieve existing flags for Items " << itemsIds;
return false;
}
......@@ -452,6 +452,7 @@ bool DataStore::removeItemsFlags(const PimItem::List &items, const QVector<Flag>
cond.addValueCondition(PimItemFlagRelation::leftFullColumnName(), Query::In, itemsIds);
qb.addCondition(cond);
if (!qb.exec()) {
qCWarning(AKONADISERVER_LOG) << "Failed to remove flags" << flags << "from Items" << itemsIds;
return false;
}
......@@ -509,6 +510,7 @@ bool DataStore::setItemsTags(const PimItem::List &items, const Tag::List &tags,
QueryBuilder qb(PimItemTagRelation::tableName(), QueryBuilder::Delete);
qb.addCondition(delConds);
if (!qb.exec()) {
qCWarning(AKONADISERVER_LOG) << "Failed to remove tags" << removedTags << "from Items";
return false;
}
}
......@@ -519,6 +521,7 @@ bool DataStore::setItemsTags(const PimItem::List &items, const Tag::List &tags,
qb2.setColumnValue(PimItemTagRelation::rightColumn(), insTags);
qb2.setIdentificationColumn(QString());
if (!qb2.exec()) {
qCWarning(AKONADISERVER_LOG) << "Failed to add tags" << addedTags << "to Items";
return false;
}
}
......@@ -558,13 +561,12 @@ bool DataStore::doAppendItemsTag(const PimItem::List &items, const Tag &tag,
qb2.setColumnValue(PimItemTagRelation::rightColumn(), tagIds);
qb2.setIdentificationColumn(QString());
if (!qb2.exec()) {
qCDebug(AKONADISERVER_LOG) << "Failed to execute query:" << qb2.query().lastError();
qCWarning(AKONADISERVER_LOG) << "Failed to append tag" << tag << "to Items" << appendItems;
return false;
}
if (!silent) {
notificationCollector()->itemsTagsChanged(appendItems, QSet<qint64>() << tag.id(),
QSet<qint64>(), col);
notificationCollector()->itemsTagsChanged(appendItems, {tag.id()}, {}, col);
}
return true;
......@@ -593,7 +595,7 @@ bool DataStore::appendItemsTags(const PimItem::List &items, const Tag::List &tag
qb.addCondition(cond);
if (!qb.exec()) {
qCDebug(AKONADISERVER_LOG) << "Failed to execute query:" << qb.query().lastError();
qCWarning(AKONADISERVER_LOG) << "Failed to retrieve existing tag" << tag << "for Items" << itemsIds;
return false;
}
......@@ -652,6 +654,7 @@ bool DataStore::removeItemsTags(const PimItem::List &items, const Tag::List &tag
cond.addValueCondition(PimItemTagRelation::leftFullColumnName(), Query::In, itemsIds);
qb.addCondition(cond);
if (!qb.exec()) {
qCWarning(AKONADISERVER_LOG) << "Failed to remove tags" << tagsIds << "from Items" << itemsIds;
return false;
}
......@@ -685,7 +688,7 @@ bool DataStore::removeTags(const Tag::List &tags, bool silent)
itemsQuery.addValueCondition(PimItemTagRelation::rightFullColumnName(), Query::In, removedTagsIds);
if (!itemsQuery.exec()) {
qCDebug(AKONADISERVER_LOG) << "Failed to execute query: " << itemsQuery.query().lastError();
qCWarning(AKONADISERVER_LOG) << "Removing tags failed: failed to query Items for given tags" << removedTagsIds;
return false;
}
const PimItem::List items = itemsQuery.result();
......@@ -703,7 +706,7 @@ bool DataStore::removeTags(const Tag::List &tags, bool silent)
qb.addColumn(Resource::nameFullColumnName());
qb.addValueCondition(TagRemoteIdResourceRelation::tagIdFullColumnName(), Query::Equals, tag.id());
if (!qb.exec()) {
qCDebug(AKONADISERVER_LOG) << "Failed to execute query: " << qb.query().lastError();
qCWarning(AKONADISERVER_LOG) << "Removing tags failed: failed to retrieve RIDs for tag" << tag.id();
return false;
}
......@@ -725,7 +728,7 @@ bool DataStore::removeTags(const Tag::List &tags, bool silent)
QueryBuilder qb(Tag::tableName(), QueryBuilder::Delete);
qb.addValueCondition(Tag::idColumn(), Query::In, removedTagsIds);
if (!qb.exec()) {
qCDebug(AKONADISERVER_LOG) << "Failed to execute query: " << itemsQuery.query().lastError();
qCWarning(AKONADISERVER_LOG) << "Failed to remove tags" << removedTagsIds;
return false;
}
......@@ -741,10 +744,16 @@ bool DataStore::removeItemParts(const PimItem &item, const QSet<QByteArray> &par
qb.addValueCondition(Part::pimItemIdFullColumnName(), Query::Equals, item.id());
qb.addCondition(PartTypeHelper::conditionFromFqNames(parts));
qb.exec();
if (!qb.exec()) {
qCWarning(AKONADISERVER_LOG) << "Removing item parts failed: failed to query parts" << parts << "from Item " << item.id();
return false;
}
const Part::List existingParts = qb.result();
for (Part part : qAsConst(existingParts)) { //krazy:exclude=foreach
if (!PartHelper::remove(&part)) {
qCWarning(AKONADISERVER_LOG) << "Failed to remove part" << part.id() << "(" << part.partType().ns()
<< ":" << part.partType().name() << ") from Item" << item.id();
return false;
}
}
......@@ -765,6 +774,7 @@ bool DataStore::invalidateItemCache(const PimItem &item)
qb.addValueCondition(PimItem::dirtyFullColumnName(), Query::Equals, false);
if (!qb.exec()) {
qCWarning(AKONADISERVER_LOG) << "Failed to invalidate cache for Item" << item.id();
return false;
}
......@@ -772,6 +782,8 @@ bool DataStore::invalidateItemCache(const PimItem &item)
// clear data field
for (Part part : parts) {
if (!PartHelper::truncate(part)) {
qCWarning(AKONADISERVER_LOG) << "Failed to truncate payload part" << part.id() << "(" << part.partType().ns()
<< ":" << part.partType().name() << ") of Item" << item.id();
return false;
}
}
......@@ -785,15 +797,21 @@ bool DataStore::appendCollection(Collection &collection, const QStringList &mime
// no need to check for already existing collection with the same name,
// a unique index on parent + name prevents that in the database
if (!collection.insert()) {
qCWarning(AKONADISERVER_LOG) << "Failed to append Collection" << collection.name() << "in resource"
<< collection.resource().name();