Skip to content

Commit

Permalink
Change bulk upload batch size when there is a sync error.
Browse files Browse the repository at this point in the history
- Cancel sync after try with smaller bulk upload batch size also throws error.
- Continue syncing when there is no error.
- Remove file from bulk upload black list only when upload succeeded.

Signed-off-by: Camila <[email protected]>
  • Loading branch information
Camila committed Oct 16, 2023
1 parent 4ca69f6 commit 274c9bc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
42 changes: 36 additions & 6 deletions src/libsync/bulkpropagatorjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Q_LOGGING_CATEGORY(lcBulkPropagatorJob, "nextcloud.sync.propagator.bulkupload",
BulkPropagatorJob::BulkPropagatorJob(OwncloudPropagator *propagator, const std::deque<SyncFileItemPtr> &items)
: PropagatorJob(propagator)
, _items(items)
, _currentBatchSize(batchSize)
{
_filesToUpload.reserve(batchSize);
_pendingChecksumFiles.reserve(batchSize);
Expand All @@ -83,7 +84,7 @@ bool BulkPropagatorJob::scheduleSelfOrChild()

_state = Running;

for(auto i = 0; i < batchSize && !_items.empty(); ++i) {
for(auto i = 0; i < _currentBatchSize && !_items.empty(); ++i) {
const auto currentItem = _items.front();
_items.pop_front();
_pendingChecksumFiles.insert(currentItem->_file);
Expand All @@ -107,6 +108,29 @@ bool BulkPropagatorJob::scheduleSelfOrChild()
return _items.empty() && _filesToUpload.empty();
}

bool BulkPropagatorJob::handleBatchSize()
{
// no error, no batch size to change
if (_finalStatus == SyncFileItem::Success || _finalStatus == SyncFileItem::NoStatus) {
qCDebug(lcBulkPropagatorJob) << "No error, no need to change the bulk upload batch size!";
return true;
}

// change this value more times? or try only once?
const auto halfBatchSize = batchSize/2;

// we already tried to upload with half of the batch size
if(_currentBatchSize == halfBatchSize) {
qCDebug(lcBulkPropagatorJob) << "There was another error, stop syncing now!";
return false;
}

// try to upload with half of the batch size
_currentBatchSize = halfBatchSize;
qCDebug(lcBulkPropagatorJob) << "There was an error, sync again with bulk upload batch size cut to half!";
return true;
}

PropagatorJob::JobParallelism BulkPropagatorJob::parallelism() const
{
return PropagatorJob::JobParallelism::FullParallelism;
Expand Down Expand Up @@ -254,13 +278,16 @@ void BulkPropagatorJob::checkPropagationIsDone()
// just wait for the other job to finish.
return;
}

qCInfo(lcBulkPropagatorJob) << "final status" << _finalStatus;
emit finished(_finalStatus);
propagator()->scheduleNextJob();
} else {
scheduleSelfOrChild();
if (handleBatchSize()) {
scheduleSelfOrChild();
return;
}
}

qCInfo(lcBulkPropagatorJob) << "final status" << _finalStatus;
emit finished(_finalStatus);
propagator()->scheduleNextJob();
}

void BulkPropagatorJob::slotComputeTransmissionChecksum(SyncFileItemPtr item,
Expand Down Expand Up @@ -371,6 +398,9 @@ void BulkPropagatorJob::slotPutFinishedOneFile(const BulkUploadItem &singleFile,

singleFile._item->_status = SyncFileItem::Success;

// upload succeeded, so remove from black list
propagator()->removeFromBulkUploadBlackList(singleFile._item->_file);

// Check the file again post upload.
// Two cases must be considered separately: If the upload is finished,
// the file is on the server and has a changed ETag. In that case,
Expand Down
3 changes: 3 additions & 0 deletions src/libsync/bulkpropagatorjob.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ private slots:

void checkPropagationIsDone();

bool handleBatchSize();

std::deque<SyncFileItemPtr> _items;

QVector<AbstractNetworkJob *> _jobs; /// network jobs that are currently in transit
Expand All @@ -164,6 +166,7 @@ private slots:
std::vector<BulkUploadItem> _filesToUpload;

SyncFileItem::Status _finalStatus = SyncFileItem::Status::NoStatus;
int _currentBatchSize = 0;
};

}
5 changes: 2 additions & 3 deletions src/libsync/owncloudpropagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,6 @@ std::unique_ptr<PropagateUploadFileCommon> OwncloudPropagator::createUploadJob(S

job->setDeleteExisting(deleteExisting);

removeFromBulkUploadBlackList(item->_file);

return job;
}

Expand Down Expand Up @@ -1261,8 +1259,9 @@ void PropagatorCompositeJob::finalize()
{
// The propagator will do parallel scheduling and this could be posted
// multiple times on the event loop, ignore the duplicate calls.
if (_state == Finished)
if (_state == Finished) {
return;
}

_state = Finished;
emit finished(_hasError == SyncFileItem::NoStatus ? SyncFileItem::Success : _hasError);
Expand Down
3 changes: 2 additions & 1 deletion src/libsync/owncloudpropagator.h
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,9 @@ private slots:
/** Emit the finished signal and make sure it is only emitted once */
void emitFinished(OCC::SyncFileItem::Status status)
{
if (!_finishedEmited)
if (!_finishedEmited) {
emit finished(status == SyncFileItem::Success);
}
_abortRequested = false;
_finishedEmited = true;
}
Expand Down

0 comments on commit 274c9bc

Please sign in to comment.