[Pkg-owncloud-commits] [owncloud-client] 263/333: Make the chunk size configurable via an environement variable

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu Apr 17 23:17:02 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit a1fc7f0a25e12af6b4b6dafb4ff0323ccdc21e1e
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Fri Mar 28 11:11:02 2014 +0100

    Make the chunk size configurable via an environement variable
    
    OWNCLOUD_CHUNK_SIZE
---
 src/mirall/propagator_legacy.cpp |  6 +++++-
 src/mirall/propagator_qnam.cpp   | 26 ++++++++++++++++++--------
 2 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/src/mirall/propagator_legacy.cpp b/src/mirall/propagator_legacy.cpp
index ad7f10b..2aeada2 100644
--- a/src/mirall/propagator_legacy.cpp
+++ b/src/mirall/propagator_legacy.cpp
@@ -71,11 +71,15 @@ void PropagateUploadFileLegacy::start()
     do {
         Hbf_State state = HBF_SUCCESS;
         QScopedPointer<hbf_transfer_t, ScopedPointerHelpers> trans(hbf_init_transfer(uri.data()));
+        Q_ASSERT(trans);
         trans->user_data = this;
         hbf_set_log_callback(trans.data(), _log_callback);
         hbf_set_abort_callback(trans.data(), _user_want_abort);
         trans.data()->chunk_finished_cb = chunk_finished_cb;
-        Q_ASSERT(trans);
+        static uint chunkSize = qgetenv("OWNCLOUD_CHUNK_SIZE").toUInt();
+        if (chunkSize > 0)  {
+            trans->block_size = trans->threshold = chunkSize;
+        }
 
         state = hbf_splitlist(trans.data(), file.handle());
 
diff --git a/src/mirall/propagator_qnam.cpp b/src/mirall/propagator_qnam.cpp
index f30c521..13d9935 100644
--- a/src/mirall/propagator_qnam.cpp
+++ b/src/mirall/propagator_qnam.cpp
@@ -64,8 +64,16 @@ void PUTFileJob::start() {
     AbstractNetworkJob::start();
 }
 
-// FIXME:  increase and make configurable
-static const int CHUNKING_SIZE = (10*1024*1024);
+static uint chunkSize() {
+    static uint chunkSize;
+    if (!chunkSize) {
+        chunkSize = qgetenv("OWNCLOUD_CHUNK_SIZE").toUInt();
+        if (chunkSize == 0) {
+            chunkSize = 10*1024*1024; // default to 10 MiB
+        }
+    }
+    return chunkSize;
+}
 
 void PropagateUploadFileQNAM::start()
 {
@@ -80,7 +88,7 @@ void PropagateUploadFileQNAM::start()
     }
 
     quint64 fileSize = _file->size();
-    _chunkCount = std::ceil(fileSize/double(CHUNKING_SIZE));
+    _chunkCount = std::ceil(fileSize/double(chunkSize()));
     _startChunk = 0;
     _transferId = qrand() ^ _item._modtime ^ (_item._size << 16);
 
@@ -116,7 +124,7 @@ struct ChunkDevice : QIODevice {
     }
 
     virtual qint64 readData(char* data, qint64 maxlen) {
-        maxlen = qMin(maxlen, CHUNKING_SIZE - _read);
+        maxlen = qMin(maxlen, chunkSize() - _read);
         if (maxlen == 0)
             return 0;
         qint64 ret = _file->read(data, maxlen);
@@ -125,7 +133,7 @@ struct ChunkDevice : QIODevice {
     }
 
     virtual bool atEnd() const {
-        return  _read >= CHUNKING_SIZE || _file->atEnd();
+        return  _read >= chunkSize() || _file->atEnd();
     }
 };
 
@@ -163,9 +171,11 @@ void PropagateUploadFileQNAM::startNextChunk()
     QIODevice *device;
     if (_chunkCount > 1) {
         int sendingChunk = (_currentChunk + _startChunk) % _chunkCount;
-        path +=  QString("-chunking-%1-%2-%3").arg(uint(_transferId)).arg(_chunkCount).arg(sendingChunk);
+        // XOR with chunk size to make sure everything goes well if chunk size change between runs
+        uint transid = _transferId ^ chunkSize();
+        path +=  QString("-chunking-%1-%2-%3").arg(transid).arg(_chunkCount).arg(sendingChunk);
         headers["OC-Chunked"] = "1";
-        device = new ChunkDevice(_file, CHUNKING_SIZE * sendingChunk);
+        device = new ChunkDevice(_file, chunkSize() * sendingChunk);
     } else {
         device = _file;
     }
@@ -273,7 +283,7 @@ void PropagateUploadFileQNAM::slotUploadProgress(qint64 sent, qint64)
     int progressChunk = _currentChunk + _startChunk;
     if (progressChunk >= _chunkCount)
         progressChunk = _currentChunk;
-    emit progress(_item, sent + _currentChunk * CHUNKING_SIZE);
+    emit progress(_item, sent + _currentChunk * chunkSize());
 }
 
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list