Skip to content

Include saved uploads in partial sync #10200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/unreleased/5382_2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Bugfix: Properly resume upload with a partial local discovery

https://github.com/owncloud/enterprise/issues/5382
https://github.com/owncloud/client/pull/10200
1 change: 1 addition & 0 deletions src/common/preparedsqlquerymanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class OCSYNC_EXPORT PreparedSqlQueryManager
SetDownloadInfoQuery,
DeleteDownloadInfoQuery,
GetUploadInfoQuery,
GetAllUploadInfoQuery,
SetUploadInfoQuery,
DeleteUploadInfoQuery,
DeleteFileRecordPhash,
Expand Down
74 changes: 53 additions & 21 deletions src/common/syncjournaldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1407,31 +1407,63 @@ SyncJournalDb::UploadInfo SyncJournalDb::getUploadInfo(const QString &file)
{
QMutexLocker locker(&_mutex);


if (!checkConnect()) {
return {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we log this case? It looks like this case should not occur really.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The db code already logs.
I also assume we should remove 90% of the checkConnect calls the db is supposed to be opened at this point...
The checkConnect is also the function that checked for the existance of the db file before all our sql calls.

}

const auto query = _queryManager.get(PreparedSqlQueryManager::GetUploadInfoQuery,
QByteArrayLiteral("SELECT chunk, transferid, errorcount, size, modtime, contentChecksum FROM uploadinfo WHERE path=?1"),
_db);
if (!query) {
return {};
}
query->bindValue(1, file);

if (!query->exec()) {
return {};
}

UploadInfo res;
if (query->next().hasData) {
res._chunk = query->intValue(0);
res._transferid = query->intValue(1);
res._errorCount = query->intValue(2);
res._size = query->int64Value(3);
res._modtime = query->int64Value(4);
res._contentChecksum = query->baValue(5);
res._valid = true;
}
return res;
}

if (checkConnect()) {
const auto query = _queryManager.get(PreparedSqlQueryManager::GetUploadInfoQuery, QByteArrayLiteral("SELECT chunk, transferid, errorcount, size, modtime, contentChecksum FROM "
"uploadinfo WHERE path=?1"),
_db);
if (!query) {
return res;
}
query->bindValue(1, file);
std::vector<SyncJournalDb::UploadInfo> SyncJournalDb::getUploadInfos()
{
QMutexLocker locker(&_mutex);

if (!query->exec()) {
return res;
}
const auto query = _queryManager.get(PreparedSqlQueryManager::GetAllUploadInfoQuery,
QByteArrayLiteral("SELECT chunk, transferid, errorcount, size, modtime, contentChecksum, path FROM uploadinfo"),
_db);
if (!query) {
return {};
}

if (query->next().hasData) {
bool ok = true;
res._chunk = query->intValue(0);
res._transferid = query->intValue(1);
res._errorCount = query->intValue(2);
res._size = query->int64Value(3);
res._modtime = query->int64Value(4);
res._contentChecksum = query->baValue(5);
res._valid = ok;
}
if (!query->exec()) {
return {};
}

std::vector<UploadInfo> res;
while (query->next().hasData) {
UploadInfo info;
info._chunk = query->intValue(0);
info._transferid = query->intValue(1);
info._errorCount = query->intValue(2);
info._size = query->int64Value(3);
info._modtime = query->int64Value(4);
info._contentChecksum = query->baValue(5);
info._path = query->baValue(6);
info._valid = true;
res.push_back(std::move(info));
}
return res;
}
Expand Down
23 changes: 9 additions & 14 deletions src/common/syncjournaldb.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,14 @@ class OCSYNC_EXPORT SyncJournalDb : public QObject
};
struct UploadInfo
{
UploadInfo()
: _chunk(0)
, _transferid(0)
, _size(0)
, _errorCount(0)
, _valid(false)
{
}
int _chunk;
uint _transferid;
qint64 _size;
qint64 _modtime;
int _errorCount;
bool _valid;
int _chunk = 0;
uint _transferid = 0;
qint64 _size = 0;
qint64 _modtime = 0;
int _errorCount = 0;
bool _valid = false;
QByteArray _contentChecksum;
QByteArray _path;
/**
* Returns true if this entry refers to a chunked upload that can be continued.
* (As opposed to a small file transfer which is stored in the db so we can detect the case
Expand All @@ -137,6 +130,8 @@ class OCSYNC_EXPORT SyncJournalDb : public QObject
int downloadInfoCount();

UploadInfo getUploadInfo(const QString &file);
std::vector<UploadInfo> getUploadInfos();

void setUploadInfo(const QString &file, const UploadInfo &i);
// Return the list of transfer ids that were removed.
QVector<uint> deleteStaleUploadInfos(const QSet<QString> &keep);
Expand Down
10 changes: 9 additions & 1 deletion src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,13 @@ void SyncEngine::setLocalDiscoveryOptions(LocalDiscoveryStyle style, std::set<QS
_localDiscoveryStyle = style;
_localDiscoveryPaths = std::move(paths);


// add running upload to the local discovery
const auto info = _journal->getUploadInfos();
for (const auto &i : info) {
_localDiscoveryPaths.insert(QString::fromUtf8(i._path));
}

// Normalize to make sure that no path is a contained in another.
// Note: for simplicity, this code consider anything less than '/' as a path separator, so for
// example, this will remove "foo.bar" if "foo" is in the list. This will mean we might have
Expand All @@ -908,8 +915,9 @@ void SyncEngine::setLocalDiscoveryOptions(LocalDiscoveryStyle style, std::set<QS

bool SyncEngine::shouldDiscoverLocally(const QString &path) const
{
if (_localDiscoveryStyle == LocalDiscoveryStyle::FilesystemOnly)
if (_localDiscoveryStyle == LocalDiscoveryStyle::FilesystemOnly) {
return true;
}

// The intention is that if "A/X" is in _localDiscoveryPaths:
// - parent folders like "/", "A" will be discovered (to make sure the discovery reaches the
Expand Down
2 changes: 2 additions & 0 deletions src/libsync/syncengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ private slots:
/** The kind of local discovery the last sync run used */
LocalDiscoveryStyle _lastLocalDiscoveryStyle = LocalDiscoveryStyle::FilesystemOnly;
LocalDiscoveryStyle _localDiscoveryStyle = LocalDiscoveryStyle::FilesystemOnly;

// must be ordered
std::set<QString> _localDiscoveryPaths;

// destructor called
Expand Down
2 changes: 2 additions & 0 deletions test/testchunkingng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ private slots:
fakeFolder.localModifier().insert(QStringLiteral("A/a0"), size);
QVERIFY(fakeFolder.applyLocalModificationsAndSync());
QVERIFY(fakeFolder.currentLocalState() != fakeFolder.currentRemoteState());
QVERIFY(fakeFolder.syncEngine().isAnotherSyncNeeded());
QCOMPARE(counter.nMOVE, 1);

counter.reset();
Expand All @@ -666,6 +667,7 @@ private slots:
QCOMPARE(counter.nPUT, 0);
QCOMPARE(counter.nMOVE, 1);
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
QVERIFY(!fakeFolder.syncEngine().isAnotherSyncNeeded());
}
};

Expand Down