New Discovery algorithm: Remove the sync cleanup phase
authorOlivier Goffart <ogoffart@woboq.com>
Tue, 9 Oct 2018 13:54:42 +0000 (15:54 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:08 +0000 (10:58 +0100)
Since we do not recurse within some directories, many files are not seen.

The stale entry will cleanup by themself as the sync engine try to remove
the files that are already removed.
Should we need to actually do this cleanup, it should be dotected in the
discovery.

src/common/syncjournaldb.cpp
src/common/syncjournaldb.h
src/libsync/syncengine.cpp
src/libsync/syncengine.h

index 610d85ddf4aff1847601a0da24084d1a9676e25c..c745e79391db0a5a67246315dd1df0b6a10ce655 100644 (file)
@@ -1161,57 +1161,6 @@ bool SyncJournalDb::getFilesBelowPath(const QByteArray &path, const std::functio
     return true;
 }
 
-bool SyncJournalDb::postSyncCleanup(const QSet<QString> &filepathsToKeep,
-    const QSet<QString> &prefixesToKeep)
-{
-    QMutexLocker locker(&_mutex);
-
-    if (!checkConnect()) {
-        return false;
-    }
-
-    SqlQuery query(_db);
-    query.prepare("SELECT phash, path, e2eMangledName FROM metadata order by path");
-
-    if (!query.exec()) {
-        return false;
-    }
-
-    QByteArrayList superfluousItems;
-
-    while (query.next()) {
-        const auto file = QString(query.baValue(1));
-        const auto mangledPath = QString(query.baValue(2));
-        bool keep = filepathsToKeep.contains(file) || filepathsToKeep.contains(mangledPath);
-        if (!keep) {
-            foreach (const QString &prefix, prefixesToKeep) {
-                if (file.startsWith(prefix) || mangledPath.startsWith(prefix)) {
-                    keep = true;
-                    break;
-                }
-            }
-        }
-        if (!keep) {
-            superfluousItems.append(query.baValue(0));
-        }
-    }
-
-    if (superfluousItems.count()) {
-        QByteArray sql = "DELETE FROM metadata WHERE phash in (" + superfluousItems.join(",") + ")";
-        qCInfo(lcDb) << "Sync Journal cleanup for" << superfluousItems;
-        SqlQuery delQuery(_db);
-        delQuery.prepare(sql);
-        if (!delQuery.exec()) {
-            return false;
-        }
-    }
-
-    // Incorporate results back into main DB
-    walCheckpoint();
-
-    return true;
-}
-
 int SyncJournalDb::getFileRecordCount()
 {
     QMutexLocker locker(&_mutex);
index f9992a71e2721d2d25ff322f8afbad4a3ae8898f..31e757a94928b4154e06d3677330b4b6b8dc251f 100644 (file)
@@ -184,9 +184,6 @@ public:
      */
     void forceRemoteDiscoveryNextSync();
 
-    bool postSyncCleanup(const QSet<QString> &filepathsToKeep,
-        const QSet<QString> &prefixesToKeep);
-
     /* Because sqlite transactions are really slow, we encapsulate everything in big transactions
      * Commit will actually commit the transaction and create a new one.
      */
index 718f8107c34b1c6df570623ce61c75360d728eb2..6b063f7750666cb1114bd7768d128f7d4d407cfc 100644 (file)
@@ -417,7 +417,6 @@ void SyncEngine::startSync()
     _hasForwardInTimeFiles = false;
     _backInTimeFiles = 0;
     _seenFiles.clear();
-    _temporarilyUnavailablePaths.clear();
 
     _progressInfo->reset();
 
@@ -812,10 +811,6 @@ void SyncEngine::slotFinished(bool success)
         _journal->setDataFingerprint(_discoveryPhase->_dataFingerprint);
     }
 
-    if (success && !_journal->postSyncCleanup(_seenFiles, _temporarilyUnavailablePaths)) {
-        qCDebug(lcEngine) << "Cleaning of synced ";
-    }
-
     conflictRecordMaintenance();
 
     _journal->commit("All Finished.", false);
@@ -844,7 +839,6 @@ void SyncEngine::finalize(bool success)
     // Delete the propagator only after emitting the signal.
     _propagator.clear();
     _seenFiles.clear();
-    _temporarilyUnavailablePaths.clear();
     _uniqueErrors.clear();
     _localDiscoveryPaths.clear();
     _localDiscoveryStyle = LocalDiscoveryStyle::FilesystemOnly;
index 1343fc493948de758c0c0bfaa5cd1b4a2d69c7ae..ac41798ac66f85c22dfd54ae27e8187f27cfadfc 100644 (file)
@@ -231,21 +231,9 @@ private:
     QScopedPointer<DiscoveryPhase> _discoveryPhase;
     QSharedPointer<OwncloudPropagator> _propagator;
 
-    // After a sync, only the syncdb entries whose filenames appear in this
-    // set will be kept. See _temporarilyUnavailablePaths.
+    // List of all files we seen
     QSet<QString> _seenFiles;
 
-    // Some paths might be temporarily unavailable on the server, for
-    // example due to 503 Storage not available. Deleting information
-    // about the files from the database in these cases would lead to
-    // incorrect synchronization.
-    // Therefore all syncdb entries whose filename starts with one of
-    // the paths in this set will be kept.
-    // The specific case that fails otherwise is deleting a local file
-    // while the remote says storage not available.
-    QSet<QString> _temporarilyUnavailablePaths;
-
-
     QScopedPointer<ProgressInfo> _progressInfo;
 
     QScopedPointer<ExcludedFiles> _excludedFiles;