Merge lp:~charlesk/keeper/fix-slow-tar-creator-test into lp:keeper/devel

Proposed by Charles Kerr
Status: Merged
Approved by: Charles Kerr
Approved revision: 143
Merged at revision: 122
Proposed branch: lp:~charlesk/keeper/fix-slow-tar-creator-test
Merge into: lp:keeper/devel
Prerequisite: lp:~xavi-garcia-mena/keeper/restore
Diff against target: 98 lines (+31/-29)
1 file modified
src/tar/tar-creator.cpp (+31/-29)
To merge this branch: bzr merge lp:~charlesk/keeper/fix-slow-tar-creator-test
Reviewer Review Type Date Requested Status
Xavi Garcia (community) Approve
unity-api-1-bot continuous-integration Approve
Review via email: mp+311984@code.launchpad.net

Commit message

Fix TarCreator::step() to block less

Description of the change

Have TarCreator::step() take smaller steps so that in practice the function won't block.

Also, fix side bug: step() wasn't handling for the case of archive_write_data() returning a non-error status of having written less than the full buffer size.

To post a comment you must log in.
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:143
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~charlesk/keeper/fix-slow-tar-creator-test/+merge/311984/+edit-commit-message

https://jenkins.canonical.com/unity-api-1/job/lp-keeper-ci/143/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build/1199
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1206
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/992
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/992/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/992
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/992/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/992
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/992/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/992
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/992/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/992
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/992/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/992
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/992/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-keeper-ci/143/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

PASSED: Continuous integration, rev:
https://jenkins.canonical.com/unity-api-1/job/lp-keeper-ci/144/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build/1206
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1213
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/999
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/999/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/999
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/999/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/999
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/999/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/999
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/999/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/999
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/999/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/999
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/999/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-keeper-ci/144/rebuild

review: Approve (continuous-integration)
Revision history for this message
Xavi Garcia (xavi-garcia-mena) wrote :

Thanks for this, Charles...
It works much better that it did.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/tar/tar-creator.cpp'
2--- src/tar/tar-creator.cpp 2016-09-05 18:38:36 +0000
3+++ src/tar/tar-creator.cpp 2016-11-28 21:38:06 +0000
4@@ -78,24 +78,20 @@
5 step_filenum_ = -1;
6 }
7
8- for(;;)
9+ // if we don't have a file we're working on, then get one
10+ if (!step_file_)
11 {
12- // if we don't have a file we're working on, then get one
13- if (!step_file_)
14- {
15- if (step_filenum_ >= filenames_.size()) // tried to read past the end
16- {
17- success = false;
18- break;
19- }
20-
21- // step to next file
22- if (++step_filenum_ == filenames_.size()) // we made it to the end!
23- {
24- archive_write_close(step_archive_.get());
25- break;
26- }
27-
28+ if (step_filenum_ >= filenames_.size()) // tried to read past the end
29+ {
30+ success = false;
31+ }
32+ // step to next file
33+ else if (++step_filenum_ == filenames_.size()) // we made it to the end!
34+ {
35+ archive_write_close(step_archive_.get());
36+ }
37+ else
38+ {
39 // write the file's header
40 const auto& filename = filenames_[step_filenum_];
41 add_file_header_to_archive(step_archive_.get(), filename);
42@@ -104,15 +100,24 @@
43 step_file_.reset(new QFile(filename));
44 step_file_->open(QIODevice::ReadOnly);
45 }
46+ }
47
48+ if (step_file_)
49+ {
50 static constexpr int BUFSIZE {1024*10};
51 char inbuf[BUFSIZE];
52- const auto n = step_file_->read(inbuf, sizeof(inbuf));
53- if (n > 0) // got data
54+ auto inbuf_len = step_file_->read(inbuf, sizeof(inbuf));
55+ if (inbuf_len > 0) // got data
56 {
57- for(;;) {
58- if (archive_write_data(step_archive_.get(), inbuf, size_t(n)) != -1)
59- break;
60+ decltype(inbuf_len) offset = 0;
61+ while(offset < inbuf_len) {
62+ auto const n_written = archive_write_data(step_archive_.get(), inbuf+offset, inbuf_len-offset);
63+ if (n_written > 0) {
64+ offset += n_written;
65+ if (offset == inbuf_len)
66+ break;
67+ continue;
68+ }
69 const auto err = archive_errno(step_archive_.get());
70 if (err == ARCHIVE_RETRY)
71 continue;
72@@ -125,22 +130,19 @@
73 throw std::runtime_error(errstr.toStdString());
74 }
75 }
76- else if (n < 0) // read error
77+ else if (inbuf_len < 0) // read error
78 {
79 success = false;
80 auto errstr = QStringLiteral("read()ing %1 returned %2 (%3)")
81 .arg(step_file_->fileName())
82- .arg(n)
83+ .arg(inbuf_len)
84 .arg(step_file_->errorString());
85 qWarning() << errstr;
86 throw std::runtime_error(errstr.toStdString());
87 }
88- else if (step_file_->atEnd()) // eof
89- {
90- // loop to next file
91+
92+ if (step_file_->atEnd()) // if we're done with the file, close it
93 step_file_.reset();
94- continue;
95- }
96 }
97
98 std::swap(fillme,step_buf_);

Subscribers

People subscribed via source and target branches

to all changes: