Skip to content

Commit

Permalink
Change bulk upload batch size when there is an error.
Browse files Browse the repository at this point in the history
Signed-off-by: Camila <[email protected]>
  • Loading branch information
Camila committed Oct 10, 2023
1 parent 58e51b0 commit b47cd71
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
31 changes: 29 additions & 2 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,30 @@ 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 false;
}

// 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 @@ -259,7 +284,9 @@ void BulkPropagatorJob::checkPropagationIsDone()
emit finished(_finalStatus);
propagator()->scheduleNextJob();
} else {
scheduleSelfOrChild();
if (handleBatchSize()) {
scheduleSelfOrChild();
}
}
}

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;
};

}

0 comments on commit b47cd71

Please sign in to comment.