From 99221a546b10545a7ed7af53044b088217e150eb Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 9 Sep 2021 08:43:34 +0200 Subject: Compress result manifest uploaded by worker These files contain build logs and can be quite large. And large files sometimes trip up upload on Windows. --- bbot/agent/agent.cxx | 4 ++-- bbot/types.hxx | 13 +++++++++++++ bbot/utility.hxx | 8 ++------ bbot/utility.txx | 21 +++++++++++++++++++-- bbot/worker/worker.cxx | 20 ++++++++++++-------- 5 files changed, 48 insertions(+), 18 deletions(-) diff --git a/bbot/agent/agent.cxx b/bbot/agent/agent.cxx index 31becd3..60f7271 100644 --- a/bbot/agent/agent.cxx +++ b/bbot/agent/agent.cxx @@ -836,8 +836,8 @@ try try_mkdir_p (gd); try_mkdir_p (pd); - path tf (gd / "task.manifest"); // Task manifest file. - path rf (pd / "result.manifest"); // Result manifest file. + path tf (gd / "task.manifest"); // Task manifest file. + path rf (pd / "result.manifest.lz4"); // Result manifest file. serialize_manifest (tm, tf, "task"); diff --git a/bbot/types.hxx b/bbot/types.hxx index 7e485f7..a39abe2 100644 --- a/bbot/types.hxx +++ b/bbot/types.hxx @@ -21,6 +21,8 @@ #include #include +#include +#include #include #include #include @@ -69,6 +71,17 @@ namespace bbot using butl::optional; using butl::nullopt; + // + // + using butl::auto_fd; + using butl::ifdstream; + using butl::ofdstream; + + // + // + using olz4stream = butl::lz4::ostream; + using ilz4stream = butl::lz4::istream; + // // using butl::vector_view; diff --git a/bbot/utility.hxx b/bbot/utility.hxx index 4545bd3..b93f8b6 100644 --- a/bbot/utility.hxx +++ b/bbot/utility.hxx @@ -16,7 +16,6 @@ #include #include #include // icasecmp(), reverse_iterate(), etc -#include #include #include @@ -46,10 +45,6 @@ namespace bbot using butl::setenv; using butl::unsetenv; - // - // - using butl::auto_fd; - // // using butl::auto_rmdir; @@ -132,7 +127,8 @@ namespace bbot // Manifest parsing and serialization. // - // For parsing, if path is '-', then read from stdin. + // For parsing, if path is '-', then read from stdin. If path has the .lz4 + // extension, then assume the content is compressed. // template T diff --git a/bbot/utility.txx b/bbot/utility.txx index e485a80..3199a61 100644 --- a/bbot/utility.txx +++ b/bbot/utility.txx @@ -150,8 +150,25 @@ namespace bbot if (!file_exists (f)) fail (fh) << what << " manifest file " << f << " does not exist"; - ifdstream ifs (f); - return parse_manifest (ifs, f.string (), what, fh, iu); + bool d (f.extension () == "lz4"); + + ifdstream ifs (f, (d + ? ifdstream::badbit + : ifdstream::badbit | ifdstream::failbit)); + ilz4stream izs; + + if (d) + izs.open (ifs, true /* end */); + + return parse_manifest (d + ? static_cast (izs) + : static_cast (ifs), + f.string (), what, fh, iu); + } + catch (const invalid_argument& e) // Invalid compressed content. + { + fail (fh) << "invalid " << what << " manifest " << f << ": " << e + << endf; } catch (const system_error& e) // EACCES, etc. { diff --git a/bbot/worker/worker.cxx b/bbot/worker/worker.cxx index 1f5c946..eb7f50b 100644 --- a/bbot/worker/worker.cxx +++ b/bbot/worker/worker.cxx @@ -547,9 +547,9 @@ run_b (step_id step, verbosity, buildspec, forward (a)...); } -// Upload manifest to the specified TFTP URL with curl. Issue diagnostics and -// throw failed on invalid manifest or process management errors and throw -// io_error for input/output errors or non-zero curl exit. +// Upload compressed manifest to the specified TFTP URL with curl. Issue +// diagnostics and throw failed on invalid manifest or process management +// errors and throw io_error for input/output errors or non-zero curl exit. // template static void @@ -564,9 +564,11 @@ upload_manifest (tracer& trace, // broken pipe error on the client and partial/truncated upload on the // server. This happens quite regularly on older Linux distributions // (e.g., Debian 8, Ubuntu 16.04) but also sometimes on Windows. On the - // other hand, uploading from a file appears to work reliably. + // other hand, uploading from a file appears to work reliably (we still + // get an odd error on Windows from time to time with larger uploads). // #if 0 + // Note: need to add compression support if re-enable this. tftp_curl c (trace, path ("-"), nullfd, @@ -582,10 +584,12 @@ upload_manifest (tracer& trace, auto_rmfile tmp; try { - tmp = auto_rmfile (path::temp_path (what + "-manifest")); + tmp = auto_rmfile (path::temp_path (what + "-manifest.lz4")); ofdstream ofs (tmp.path); - manifest_serializer s (ofs, tmp.path.string ()); + olz4stream ozs (ofs, 9, 5 /* 256KB */, nullopt /* content_size */); + manifest_serializer s (ozs, tmp.path.string ()); m.serialize (s); + ozs.close (); ofs.close (); } catch (const io_error& e) // In case not derived from system_error. @@ -2119,7 +2123,7 @@ build (size_t argc, const char* argv[]) // Upload the result. // - const string url ("tftp://" + ops.tftp_host () + "/result.manifest"); + const string url ("tftp://" + ops.tftp_host () + "/result.manifest.lz4"); try { @@ -2297,7 +2301,7 @@ startup () } catch (const failed&) { - const string url ("tftp://" + ops.tftp_host () + "/result.manifest"); + const string url ("tftp://" + ops.tftp_host () + "/result.manifest.lz4"); // If we failed before being able to parse the task manifest, use the // "unknown" values for the package name and version. -- cgit v1.1