static-delta: add max-bsdiff-size option
authorGiuseppe Scrivano <gscrivan@redhat.com>
Tue, 28 Jul 2015 10:39:36 +0000 (12:39 +0200)
committerGiuseppe Scrivano <gscrivan@redhat.com>
Tue, 28 Jul 2015 11:02:27 +0000 (13:02 +0200)
It allows to specify the maximum size for input files to attempt
bsdiff compression for.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
src/libostree/ostree-repo-static-delta-compilation.c
src/ostree/ot-builtin-static-delta.c

index 6f1513c9b92bf7b005c5b1328da8f044a0ca8cda..aafe6fbadc0a2c29f8adef017700748d470d02b2 100644 (file)
@@ -53,6 +53,7 @@ typedef struct {
   GPtrArray *fallback_objects;
   guint64 loose_compressed_size;
   guint64 min_fallback_size_bytes;
+  guint64 max_bsdiff_size_bytes;
   guint64 max_chunk_size_bytes;
   guint64 rollsum_size;
   guint n_rollsum;
@@ -500,8 +501,9 @@ try_content_bsdiff (OstreeRepo                       *repo,
                     const char                       *from,
                     const char                       *to,
                     ContentBsdiff                    **out_bsdiff,
+                    guint64                          max_bsdiff_size_bytes,
                     GCancellable                     *cancellable,
-                    GError                          **error)
+                    GError                           **error)
 {
   gboolean ret = FALSE;
   g_autoptr(GHashTable) from_bsdiff = NULL;
@@ -521,8 +523,7 @@ try_content_bsdiff (OstreeRepo                       *repo,
                                       cancellable, error))
     goto out;
 
-  /* TODO: make this option configurable.  */
-  if (g_bytes_get_size (tmp_to) + g_bytes_get_size (tmp_from) > (200 * (1 << 20)))
+  if (g_bytes_get_size (tmp_to) + g_bytes_get_size (tmp_from) > max_bsdiff_size_bytes)
     {
       ret = TRUE;
       goto out;
@@ -1008,7 +1009,8 @@ generate_delta_lowlatency (OstreeRepo                       *repo,
       if (!(opts & DELTAOPT_FLAG_DISABLE_BSDIFF))
         {
           if (!try_content_bsdiff (repo, from_checksum, to_checksum,
-                                   &bsdiff, cancellable, error))
+                                   &bsdiff, builder->max_bsdiff_size_bytes,
+                                   cancellable, error))
             goto out;
 
           if (bsdiff)
@@ -1228,6 +1230,8 @@ get_fallback_headers (OstreeRepo               *self,
  * are known:
  *   - min-fallback-size: u: Minimume uncompressed size in megabytes to use fallback
  *   - max-chunk-size: u: Maximum size in megabytes of a delta part
+ *   - max-bsdiff-size: u: Maximum size in megabytes to consider bsdiff compression
+ *   for input files
  *   - compression: y: Compression type: 0=none, x=lzma, g=gzip
  *   - bsdiff-enabled: b: Enable bsdiff compression.  Default TRUE.
  *   - verbose: b: Print diagnostic messages.  Default FALSE.
@@ -1246,6 +1250,7 @@ ostree_repo_static_delta_generate (OstreeRepo                   *self,
   OstreeStaticDeltaBuilder builder = { 0, };
   guint i;
   guint min_fallback_size;
+  guint max_bsdiff_size;
   guint max_chunk_size;
   GVariant *metadata_source;
   DeltaOpts delta_opts = DELTAOPT_FLAG_NONE;
@@ -1268,6 +1273,9 @@ ostree_repo_static_delta_generate (OstreeRepo                   *self,
     min_fallback_size = 4;
   builder.min_fallback_size_bytes = ((guint64)min_fallback_size) * 1000 * 1000;
 
+  if (!g_variant_lookup (params, "max-bsdiff-size", "u", &max_bsdiff_size))
+    max_bsdiff_size = 128;
+  builder.max_bsdiff_size_bytes = ((guint64)max_bsdiff_size) * 1000 * 1000;
   if (!g_variant_lookup (params, "max-chunk-size", "u", &max_chunk_size))
     max_chunk_size = 32;
   builder.max_chunk_size_bytes = ((guint64)max_chunk_size) * 1000 * 1000;
index 04aab0b577a2a2167d4654ea36694b97da883bf8..abb0b6355c2bde394c5bab1f010d23e5fefa5651 100644 (file)
@@ -29,6 +29,7 @@
 static char *opt_from_rev;
 static char *opt_to_rev;
 static char *opt_min_fallback_size;
+static char *opt_max_bsdiff_size;
 static char *opt_max_chunk_size;
 static gboolean opt_empty;
 static gboolean opt_disable_bsdiff;
@@ -55,6 +56,7 @@ static GOptionEntry generate_options[] = {
   { "to", 0, 0, G_OPTION_ARG_STRING, &opt_to_rev, "Create delta to revision REV", "REV" },
   { "disable-bsdiff", 0, 0, G_OPTION_ARG_NONE, &opt_disable_bsdiff, "Disable use of bsdiff", NULL },
   { "min-fallback-size", 0, 0, G_OPTION_ARG_STRING, &opt_min_fallback_size, "Minimum uncompressed size in megabytes for individual HTTP request", NULL},
+  { "max-bsdiff-size", 0, 0, G_OPTION_ARG_STRING, &opt_max_bsdiff_size, "Maximum size in megabytes to consider bsdiff compression for input files", NULL},
   { "max-chunk-size", 0, 0, G_OPTION_ARG_STRING, &opt_max_chunk_size, "Maximum size of delta chunks in megabytes", NULL},
   { NULL }
 };
@@ -190,6 +192,9 @@ ot_static_delta_builtin_generate (int argc, char **argv, GCancellable *cancellab
       if (opt_min_fallback_size)
         g_variant_builder_add (parambuilder, "{sv}",
                                "min-fallback-size", g_variant_new_uint32 (g_ascii_strtoull (opt_min_fallback_size, NULL, 10)));
+      if (opt_max_bsdiff_size)
+        g_variant_builder_add (parambuilder, "{sv}",
+                               "max-bsdiff-size", g_variant_new_uint32 (g_ascii_strtoull (opt_max_bsdiff_size, NULL, 10)));
       if (opt_max_chunk_size)
         g_variant_builder_add (parambuilder, "{sv}",
                                "max-chunk-size", g_variant_new_uint32 (g_ascii_strtoull (opt_max_chunk_size, NULL, 10)));