Skip to content

Commit

Permalink
Remove PollJob support
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOneRing committed Jan 27, 2021
1 parent e481859 commit ac0a3ac
Show file tree
Hide file tree
Showing 14 changed files with 9 additions and 579 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/8398
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Change: We removed the support for async jobs using OC-JobStatus-Location

We removed the support of async polling jobs after discovering potential issues.

https://github.com/owncloud/client/pull/8398
57 changes: 0 additions & 57 deletions src/common/syncjournaldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,15 +458,6 @@ bool SyncJournalDb::checkConnect()
return sqlFail(QStringLiteral("Create table blacklist"), createQuery);
}

createQuery.prepare("CREATE TABLE IF NOT EXISTS async_poll("
"path VARCHAR(4096),"
"modtime INTEGER(8),"
"filesize BIGINT,"
"pollpath VARCHAR(4096));");
if (!createQuery.exec()) {
return sqlFail(QStringLiteral("Create table async_poll"), createQuery);
}

// create the selectivesync table.
createQuery.prepare("CREATE TABLE IF NOT EXISTS selectivesync ("
"path VARCHAR(4096),"
Expand Down Expand Up @@ -1719,54 +1710,6 @@ void SyncJournalDb::setErrorBlacklistEntry(const SyncJournalErrorBlacklistRecord
query->exec();
}

QVector<SyncJournalDb::PollInfo> SyncJournalDb::getPollInfos()
{
QMutexLocker locker(&_mutex);

QVector<SyncJournalDb::PollInfo> res;

if (!checkConnect())
return res;

SqlQuery query("SELECT path, modtime, filesize, pollpath FROM async_poll", _db);

if (!query.exec()) {
return res;
}

while (query.next().hasData) {
PollInfo info;
info._file = query.stringValue(0);
info._modtime = query.int64Value(1);
info._fileSize = query.int64Value(2);
info._url = query.stringValue(3);
res.append(info);
}
return res;
}

void SyncJournalDb::setPollInfo(const SyncJournalDb::PollInfo &info)
{
QMutexLocker locker(&_mutex);
if (!checkConnect()) {
return;
}

if (info._url.isEmpty()) {
qCDebug(lcDb) << "Deleting Poll job" << info._file;
SqlQuery query("DELETE FROM async_poll WHERE path=?", _db);
query.bindValue(1, info._file);
query.exec();
} else {
SqlQuery query("INSERT OR REPLACE INTO async_poll (path, modtime, filesize, pollpath) VALUES( ? , ? , ? , ? )", _db);
query.bindValue(1, info._file);
query.bindValue(2, info._modtime);
query.bindValue(3, info._fileSize);
query.bindValue(4, info._url);
query.exec();
}
}

QStringList SyncJournalDb::getSelectiveSyncList(SyncJournalDb::SelectiveSyncListType type, bool *ok)
{
QStringList result;
Expand Down
10 changes: 0 additions & 10 deletions src/common/syncjournaldb.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,6 @@ class OCSYNC_EXPORT SyncJournalDb : public QObject
bool isChunked() const { return _transferid != 0; }
};

struct PollInfo
{
QString _file; // The relative path of a file
QString _url; // the poll url. (This pollinfo is invalid if _url is empty)
qint64 _modtime; // The modtime of the file being uploaded
qint64 _fileSize;
};

DownloadInfo getDownloadInfo(const QString &file);
void setDownloadInfo(const QString &file, const DownloadInfo &i);
QVector<DownloadInfo> getAndDeleteStaleDownloadInfos(const QSet<QString> &keep);
Expand All @@ -159,8 +151,6 @@ class OCSYNC_EXPORT SyncJournalDb : public QObject

void avoidRenamesOnNextSync(const QString &path) { avoidRenamesOnNextSync(path.toUtf8()); }
void avoidRenamesOnNextSync(const QByteArray &path);
void setPollInfo(const PollInfo &);
QVector<PollInfo> getPollInfos();

enum SelectiveSyncListType {
/** The black list is the list of folders that are unselected in the selective sync dialog.
Expand Down
50 changes: 0 additions & 50 deletions src/libsync/owncloudpropagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ namespace OCC {

Q_LOGGING_CATEGORY(lcPropagator, "sync.propagator", QtInfoMsg)
Q_LOGGING_CATEGORY(lcDirectory, "sync.propagator.directory", QtInfoMsg)
Q_LOGGING_CATEGORY(lcCleanupPolls, "sync.propagator.cleanuppolls", QtInfoMsg)

qint64 criticalFreeSpaceLimit()
{
Expand Down Expand Up @@ -1102,55 +1101,6 @@ void PropagateRootDirectory::slotDirDeletionJobsFinished(SyncFileItem::Status st

// ================================================================================

CleanupPollsJob::~CleanupPollsJob()
{
}

void CleanupPollsJob::start()
{
if (_pollInfos.empty()) {
emit finished();
deleteLater();
return;
}

auto info = _pollInfos.first();
_pollInfos.pop_front();
SyncJournalFileRecord record;
SyncFileItemPtr item(new SyncFileItem);
item->_file = info._file;
item->_modtime = info._modtime;
item->_size = info._fileSize;
PollJob *job = new PollJob(_account, info._url, item, _journal, _localPath, this);
connect(job, &PollJob::finishedSignal, this, &CleanupPollsJob::slotPollFinished);
job->start();
}

void CleanupPollsJob::slotPollFinished()
{
PollJob *job = qobject_cast<PollJob *>(sender());
OC_ASSERT(job);
if (job->_item->_status == SyncFileItem::FatalError) {
emit aborted(job->_item->_errorString);
deleteLater();
return;
} else if (job->_item->_status != SyncFileItem::Success) {
qCWarning(lcCleanupPolls) << "There was an error with file " << job->_item->_file << job->_item->_errorString;
} else {
if (!OwncloudPropagator::updateMetadata(*job->_item, _localPath, *_journal, *_vfs)) {
qCWarning(lcCleanupPolls) << "database error";
job->_item->_status = SyncFileItem::FatalError;
job->_item->_errorString = tr("Error writing metadata to the database");
emit aborted(job->_item->_errorString);
deleteLater();
return;
}
_journal->setUploadInfo(job->_item->_file, SyncJournalDb::UploadInfo());
}
// Continue with the next entry, or finish
start();
}

QString OwncloudPropagator::fullRemotePath(const QString &tmp_file_name) const
{
// TODO: should this be part of the _item (SyncFileItemPtr)?
Expand Down
39 changes: 0 additions & 39 deletions src/libsync/owncloudpropagator.h
Original file line number Diff line number Diff line change
Expand Up @@ -605,45 +605,6 @@ private slots:
const QString _remoteFolder; // remote folder, ends with '/'
};


/**
* @brief Job that wait for all the poll jobs to be completed
* @ingroup libsync
*/
class CleanupPollsJob : public QObject
{
Q_OBJECT
QVector<SyncJournalDb::PollInfo> _pollInfos;
AccountPtr _account;
SyncJournalDb *_journal;
QString _localPath;
QSharedPointer<Vfs> _vfs;

public:
explicit CleanupPollsJob(const QVector<SyncJournalDb::PollInfo> &pollInfos, AccountPtr account,
SyncJournalDb *journal, const QString &localPath, const QSharedPointer<Vfs> &vfs, QObject *parent = nullptr)
: QObject(parent)
, _pollInfos(pollInfos)
, _account(account)
, _journal(journal)
, _localPath(localPath)
, _vfs(vfs)
{
}

~CleanupPollsJob() override;

/**
* Start the job. After the job is completed, it will emit either finished or aborted, and it
* will destroy itself.
*/
void start();
signals:
void finished();
void aborted(const QString &error);
private slots:
void slotPollFinished();
};
}

#endif
107 changes: 0 additions & 107 deletions src/libsync/propagateupload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
namespace OCC {

Q_LOGGING_CATEGORY(lcPutJob, "sync.networkjob.put", QtInfoMsg)
Q_LOGGING_CATEGORY(lcPollJob, "sync.networkjob.poll", QtInfoMsg)
Q_LOGGING_CATEGORY(lcPropagateUpload, "sync.propagator.upload", QtInfoMsg)
Q_LOGGING_CATEGORY(lcPropagateUploadV1, "sync.propagator.upload.v1", QtInfoMsg)
Q_LOGGING_CATEGORY(lcPropagateUploadNG, "sync.propagator.upload.ng", QtInfoMsg)
Expand Down Expand Up @@ -102,81 +101,6 @@ bool PUTFileJob::finished()
return true;
}

void PollJob::start()
{
setTimeout(120 * 1000);
QUrl accountUrl = account()->url();
QUrl finalUrl = QUrl::fromUserInput(accountUrl.scheme() + QStringLiteral("://") + accountUrl.authority()
+ (path().startsWith(QLatin1Char('/')) ? QString() : QStringLiteral("/")) + path());
sendRequest("GET", finalUrl);
connect(reply(), &QNetworkReply::downloadProgress, this, &AbstractNetworkJob::resetTimeout, Qt::UniqueConnection);
AbstractNetworkJob::start();
}

bool PollJob::finished()
{
QNetworkReply::NetworkError err = reply()->error();
if (err != QNetworkReply::NoError) {
_item->_httpErrorCode = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
_item->_requestId = requestId();
_item->_status = classifyError(err, _item->_httpErrorCode);
_item->_errorString = errorString();

if (_item->_status == SyncFileItem::FatalError || _item->_httpErrorCode >= 400) {
if (_item->_status != SyncFileItem::FatalError
&& _item->_httpErrorCode != 503) {
SyncJournalDb::PollInfo info;
info._file = _item->_file;
// no info._url removes it from the database
_journal->setPollInfo(info);
_journal->commit(QStringLiteral("remove poll info"));
}
emit finishedSignal();
return true;
}
QTimer::singleShot(8 * 1000, this, &PollJob::start);
return false;
}

QByteArray jsonData = reply()->readAll().trimmed();
QJsonParseError jsonParseError;
QJsonObject json = QJsonDocument::fromJson(jsonData, &jsonParseError).object();
qCInfo(lcPollJob) << ">" << jsonData << "<" << reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() << json << jsonParseError.errorString();
if (jsonParseError.error != QJsonParseError::NoError) {
_item->_errorString = tr("Invalid JSON reply from the poll URL");
_item->_status = SyncFileItem::NormalError;
emit finishedSignal();
return true;
}

auto status = json[QStringLiteral("status")].toString();
if (status == QLatin1String("init") || status == QLatin1String("started")) {
QTimer::singleShot(5 * 1000, this, &PollJob::start);
return false;
}

_item->_responseTimeStamp = responseTimestamp();
_item->_httpErrorCode = json[QStringLiteral("errorCode")].toInt();

if (status == QLatin1String("finished")) {
_item->_status = SyncFileItem::Success;
_item->_fileId = json[QStringLiteral("fileId")].toString().toUtf8();
_item->_etag = parseEtag(json[QStringLiteral("ETag")].toString().toUtf8());
} else { // error
_item->_status = classifyError(QNetworkReply::UnknownContentError, _item->_httpErrorCode);
_item->_errorString = json[QStringLiteral("errorMessage")].toString();
}

SyncJournalDb::PollInfo info;
info._file = _item->_file;
// no info._url removes it from the database
_journal->setPollInfo(info);
_journal->commit(QStringLiteral("remove poll info"));

emit finishedSignal();
return true;
}

void PropagateUploadFileCommon::setDeleteExisting(bool enabled)
{
_deleteExisting = enabled;
Expand Down Expand Up @@ -480,37 +404,6 @@ void UploadDevice::setChoked(bool b)
}
}

void PropagateUploadFileCommon::startPollJob(const QString &path)
{
PollJob *job = new PollJob(propagator()->account(), path, _item,
propagator()->_journal, propagator()->localPath(), this);
connect(job, &PollJob::finishedSignal, this, &PropagateUploadFileCommon::slotPollFinished);
SyncJournalDb::PollInfo info;
info._file = _item->_file;
info._url = path;
info._modtime = _item->_modtime;
info._fileSize = _item->_size;
propagator()->_journal->setPollInfo(info);
propagator()->_journal->commit(QStringLiteral("add poll info"));
propagator()->_activeJobList.append(this);
job->start();
}

void PropagateUploadFileCommon::slotPollFinished()
{
PollJob *job = qobject_cast<PollJob *>(sender());
OC_ASSERT(job);

propagator()->_activeJobList.removeOne(this);

if (job->_item->_status != SyncFileItem::Success) {
done(job->_item->_status, job->_item->_errorString);
return;
}

finalize();
}

void PropagateUploadFileCommon::done(SyncFileItem::Status status, const QString &errorString)
{
_finished = true;
Expand Down
Loading

0 comments on commit ac0a3ac

Please sign in to comment.