| 1 |
<?xml version="1.0" encoding="utf-8"?> |
| 2 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 3 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| 4 |
<head> |
| 5 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 6 |
<meta name="generator" content="Docutils 0.21.2: https://docutils.sourceforge.io/" /> |
| 7 |
<title>clonebundles</title> |
| 8 |
<link rel="stylesheet" href="../style.css" type="text/css" /> |
| 9 |
</head> |
| 10 |
<body> |
| 11 |
<div class="document" id="clonebundles"> |
| 12 |
<span id="ext-clonebundles"></span> |
| 13 |
<h1 class="title">clonebundles</h1> |
| 14 |
|
| 15 |
<div class="contents htmlonly topic" id="contents"> |
| 16 |
<p class="topic-title"><a class="reference internal" href="#top">Contents</a></p> |
| 17 |
<ul class="simple"> |
| 18 |
<li><a class="reference internal" href="#description" id="toc-entry-1">Description</a><ul> |
| 19 |
<li><a class="reference internal" href="#inline-clonebundles" id="toc-entry-2">inline clonebundles</a></li> |
| 20 |
<li><a class="reference internal" href="#auto-generation-of-clone-bundles" id="toc-entry-3">auto-generation of clone bundles</a></li> |
| 21 |
</ul> |
| 22 |
</li> |
| 23 |
<li><a class="reference internal" href="#commands" id="toc-entry-4">Commands</a><ul> |
| 24 |
<li><a class="reference internal" href="#uncategorized-commands" id="toc-entry-5">Uncategorized commands</a></li> |
| 25 |
</ul> |
| 26 |
</li> |
| 27 |
</ul> |
| 28 |
</div> |
| 29 |
<p>advertise pre-generated bundles to seed clones</p> |
| 30 |
<div class="section" id="description"> |
| 31 |
<h1><a class="toc-backref" href="#contents">Description</a></h1> |
| 32 |
<p>"clonebundles" is a server-side extension used to advertise the existence |
| 33 |
of pre-generated, externally hosted bundle files to clients that are |
| 34 |
cloning so that cloning can be faster, more reliable, and require less |
| 35 |
resources on the server. "pullbundles" is a related feature for sending |
| 36 |
pre-generated bundle files to clients as part of pull operations.</p> |
| 37 |
<p>Cloning can be a CPU and I/O intensive operation on servers. Traditionally, |
| 38 |
the server, in response to a client's request to clone, dynamically generates |
| 39 |
a bundle containing the entire repository content and sends it to the client. |
| 40 |
There is no caching on the server and the server will have to redundantly |
| 41 |
generate the same outgoing bundle in response to each clone request. For |
| 42 |
servers with large repositories or with high clone volume, the load from |
| 43 |
clones can make scaling the server challenging and costly.</p> |
| 44 |
<p>This extension provides server operators the ability to offload |
| 45 |
potentially expensive clone load to an external service. Pre-generated |
| 46 |
bundles also allow using more CPU intensive compression, reducing the |
| 47 |
effective bandwidth requirements.</p> |
| 48 |
<p>Here's how clone bundles work:</p> |
| 49 |
<ol class="arabic simple"> |
| 50 |
<li>A server operator establishes a mechanism for making bundle files available |
| 51 |
on a hosting service where Mercurial clients can fetch them.</li> |
| 52 |
<li>A manifest file listing available bundle URLs and some optional metadata |
| 53 |
is added to the Mercurial repository on the server.</li> |
| 54 |
<li>A client initiates a clone against a clone bundles aware server.</li> |
| 55 |
<li>The client sees the server is advertising clone bundles and fetches the |
| 56 |
manifest listing available bundles.</li> |
| 57 |
<li>The client filters and sorts the available bundles based on what it |
| 58 |
supports and prefers.</li> |
| 59 |
<li>The client downloads and applies an available bundle from the |
| 60 |
server-specified URL.</li> |
| 61 |
<li>The client reconnects to the original server and performs the equivalent |
| 62 |
of <a class="reference external" href="hg-pull.html"><tt class="docutils literal">hg pull</tt></a> to retrieve all repository data not in the bundle. (The |
| 63 |
repository could have been updated between when the bundle was created |
| 64 |
and when the client started the clone.) This may use "pullbundles".</li> |
| 65 |
</ol> |
| 66 |
<p>Instead of the server generating full repository bundles for every clone |
| 67 |
request, it generates full bundles once and they are subsequently reused to |
| 68 |
bootstrap new clones. The server may still transfer data at clone time. |
| 69 |
However, this is only data that has been added/changed since the bundle was |
| 70 |
created. For large, established repositories, this can reduce server load for |
| 71 |
clones to less than 1% of original.</p> |
| 72 |
<p>Here's how pullbundles work:</p> |
| 73 |
<ol class="arabic simple"> |
| 74 |
<li>A manifest file listing available bundles and describing the revisions |
| 75 |
is added to the Mercurial repository on the server.</li> |
| 76 |
<li>A new-enough client informs the server that it supports partial pulls |
| 77 |
and initiates a pull.</li> |
| 78 |
<li>If the server has pull bundles enabled and sees the client advertising |
| 79 |
partial pulls, it checks for a matching pull bundle in the manifest. |
| 80 |
A bundle matches if the format is supported by the client, the client |
| 81 |
has the required revisions already and needs something from the bundle.</li> |
| 82 |
<li>If there is at least one matching bundle, the server sends it to the client.</li> |
| 83 |
<li>The client applies the bundle and notices that the server reply was |
| 84 |
incomplete. It initiates another pull.</li> |
| 85 |
</ol> |
| 86 |
<p>To work, this extension requires the following of server operators:</p> |
| 87 |
<ul class="simple"> |
| 88 |
<li>Generating bundle files of repository content (typically periodically, |
| 89 |
such as once per day).</li> |
| 90 |
<li>Clone bundles: A file server that clients have network access to and that |
| 91 |
Python knows how to talk to through its normal URL handling facility |
| 92 |
(typically an HTTP/HTTPS server).</li> |
| 93 |
<li>A process for keeping the bundles manifest in sync with available bundle |
| 94 |
files.</li> |
| 95 |
</ul> |
| 96 |
<p>Strictly speaking, using a static file hosting server isn't required: a server |
| 97 |
operator could use a dynamic service for retrieving bundle data. However, |
| 98 |
static file hosting services are simple and scalable and should be sufficient |
| 99 |
for most needs.</p> |
| 100 |
<p>Bundle files can be generated with the <a class="reference external" href="hg-bundle.html"><tt class="docutils literal">hg bundle</tt></a> command. Typically |
| 101 |
<a class="reference external" href="hg-bundle.html"><tt class="docutils literal">hg bundle <span class="pre">--all</span></tt></a> is used to produce a bundle of the entire repository.</p> |
| 102 |
<p>The bundlespec option <cite>stream</cite> (see <a class="reference external" href="topic-bundlespec.html"><tt class="docutils literal">hg help bundlespec</tt></a>) |
| 103 |
can be used to produce a special <em>streaming clonebundle</em>, typically using |
| 104 |
<a class="reference external" href="hg-bundle.html"><tt class="docutils literal">hg bundle <span class="pre">--all</span> <span class="pre">--type="none-streamv2"</span></tt></a>. |
| 105 |
These are bundle files that are extremely efficient |
| 106 |
to produce and consume (read: fast). However, they are larger than |
| 107 |
traditional bundle formats and require that clients support the exact set |
| 108 |
of repository data store formats in use by the repository that created them. |
| 109 |
Typically, a newer server can serve data that is compatible with older clients. |
| 110 |
However, <em>streaming clone bundles</em> don't have this guarantee. <strong>Server |
| 111 |
operators need to be aware that newer versions of Mercurial may produce |
| 112 |
streaming clone bundles incompatible with older Mercurial versions.</strong></p> |
| 113 |
<p>A server operator is responsible for creating a <tt class="docutils literal">.hg/clonebundles.manifest</tt> |
| 114 |
file containing the list of available bundle files suitable for seeding |
| 115 |
clones. If this file does not exist, the repository will not advertise the |
| 116 |
existence of clone bundles when clients connect. For pull bundles, |
| 117 |
<tt class="docutils literal">.hg/pullbundles.manifest</tt> is used.</p> |
| 118 |
<p>The manifest file contains a newline (n) delimited list of entries.</p> |
| 119 |
<p>Each line in this file defines an available bundle. Lines have the format:</p> |
| 120 |
<blockquote> |
| 121 |
<URL> [<key>=<value>[ <key>=<value>]]</blockquote> |
| 122 |
<p>That is, a URL followed by an optional, space-delimited list of key=value |
| 123 |
pairs describing additional properties of this bundle. Both keys and values |
| 124 |
are URI encoded.</p> |
| 125 |
<p>For pull bundles, the URL is a path under the <tt class="docutils literal">.hg</tt> directory of the |
| 126 |
repository.</p> |
| 127 |
<p>Keys in UPPERCASE are reserved for use by Mercurial and are defined below. |
| 128 |
All non-uppercase keys can be used by site installations. An example use |
| 129 |
for custom properties is to use the <em>datacenter</em> attribute to define which |
| 130 |
data center a file is hosted in. Clients could then prefer a server in the |
| 131 |
data center closest to them.</p> |
| 132 |
<p>The following reserved keys are currently defined:</p> |
| 133 |
<dl class="docutils"> |
| 134 |
<dt>BUNDLESPEC</dt> |
| 135 |
<dd><p class="first">A "bundle specification" string that describes the type of the bundle.</p> |
| 136 |
<p>These are string values that are accepted by the "--type" argument of |
| 137 |
<a class="reference external" href="hg-bundle.html"><tt class="docutils literal">hg bundle</tt></a>.</p> |
| 138 |
<p>The values are parsed in strict mode, which means they must be of the |
| 139 |
"<compression>-<type>" form. See |
| 140 |
mercurial.exchange.parsebundlespec() for more details.</p> |
| 141 |
<p><a class="reference external" href="hg-debugbundle.html"><tt class="docutils literal">hg debugbundle <span class="pre">--spec</span></tt></a> can be used to print the bundle specification |
| 142 |
string for a bundle file. The output of this command can be used verbatim |
| 143 |
for the value of <tt class="docutils literal">BUNDLESPEC</tt> (it is already escaped).</p> |
| 144 |
<p>Clients will automatically filter out specifications that are unknown or |
| 145 |
unsupported so they won't attempt to download something that likely won't |
| 146 |
apply.</p> |
| 147 |
<p>The actual value doesn't impact client behavior beyond filtering: |
| 148 |
clients will still sniff the bundle type from the header of downloaded |
| 149 |
files.</p> |
| 150 |
<p class="last"><strong>Use of this key is highly recommended</strong>, as it allows clients to |
| 151 |
easily skip unsupported bundles. If this key is not defined, an old |
| 152 |
client may attempt to apply a bundle that it is incapable of reading.</p> |
| 153 |
</dd> |
| 154 |
<dt>REQUIRESNI</dt> |
| 155 |
<dd><p class="first">Whether Server Name Indication (SNI) is required to connect to the URL. |
| 156 |
SNI allows servers to use multiple certificates on the same IP. It is |
| 157 |
somewhat common in CDNs and other hosting providers. Older Python |
| 158 |
versions do not support SNI. Defining this attribute enables clients |
| 159 |
with older Python versions to filter this entry without experiencing |
| 160 |
an opaque SSL failure at connection time.</p> |
| 161 |
<p>If this is defined, it is important to advertise a non-SNI fallback |
| 162 |
URL or clients running old Python releases may not be able to clone |
| 163 |
with the clonebundles facility.</p> |
| 164 |
<p class="last">Value should be "true".</p> |
| 165 |
</dd> |
| 166 |
<dt>REQUIREDRAM</dt> |
| 167 |
<dd><p class="first">Value specifies expected memory requirements to decode the payload. |
| 168 |
Values can have suffixes for common bytes sizes. e.g. "64MB".</p> |
| 169 |
<p class="last">This key is often used with zstd-compressed bundles using a high |
| 170 |
compression level / window size, which can require 100+ MB of memory |
| 171 |
to decode.</p> |
| 172 |
</dd> |
| 173 |
<dt>heads</dt> |
| 174 |
<dd>Used for pull bundles. This contains the <tt class="docutils literal">;</tt> separated changeset |
| 175 |
hashes of the heads of the bundle content.</dd> |
| 176 |
<dt>bases</dt> |
| 177 |
<dd>Used for pull bundles. This contains the <tt class="docutils literal">;</tt> separated changeset |
| 178 |
hashes of the roots of the bundle content. This can be skipped if |
| 179 |
the bundle was created without <tt class="docutils literal"><span class="pre">--base</span></tt>.</dd> |
| 180 |
</dl> |
| 181 |
<p>Manifests can contain multiple entries. Assuming metadata is defined, clients |
| 182 |
will filter entries from the manifest that they don't support. The remaining |
| 183 |
entries are optionally sorted by client preferences |
| 184 |
(<tt class="docutils literal">ui.clonebundleprefers</tt> config option). The client then attempts |
| 185 |
to fetch the bundle at the first URL in the remaining list.</p> |
| 186 |
<p><strong>Errors when downloading a bundle will fail the entire clone operation: |
| 187 |
clients do not automatically fall back to a traditional clone.</strong> The reason |
| 188 |
for this is that if a server is using clone bundles, it is probably doing so |
| 189 |
because the feature is necessary to help it scale. In other words, there |
| 190 |
is an assumption that clone load will be offloaded to another service and |
| 191 |
that the Mercurial server isn't responsible for serving this clone load. |
| 192 |
If that other service experiences issues and clients start mass falling back to |
| 193 |
the original Mercurial server, the added clone load could overwhelm the server |
| 194 |
due to unexpected load and effectively take it offline. Not having clients |
| 195 |
automatically fall back to cloning from the original server mitigates this |
| 196 |
scenario.</p> |
| 197 |
<p>Because there is no automatic Mercurial server fallback on failure of the |
| 198 |
bundle hosting service, it is important for server operators to view the bundle |
| 199 |
hosting service as an extension of the Mercurial server in terms of |
| 200 |
availability and service level agreements: if the bundle hosting service goes |
| 201 |
down, so does the ability for clients to clone. Note: clients will see a |
| 202 |
message informing them how to bypass the clone bundles facility when a failure |
| 203 |
occurs. So server operators should prepare for some people to follow these |
| 204 |
instructions when a failure occurs, thus driving more load to the original |
| 205 |
Mercurial server when the bundle hosting service fails.</p> |
| 206 |
<div class="section" id="inline-clonebundles"> |
| 207 |
<h2><a class="toc-backref" href="#contents">inline clonebundles</a></h2> |
| 208 |
<p>It is possible to transmit clonebundles inline in case repositories are |
| 209 |
accessed over SSH. This avoids having to setup an external HTTPS server |
| 210 |
and results in the same access control as already present for the SSH setup.</p> |
| 211 |
<p>Inline clonebundles should be placed into the <cite>.hg/bundle-cache</cite> directory. |
| 212 |
A clonebundle at <cite>.hg/bundle-cache/mybundle.bundle</cite> is referred to |
| 213 |
in the <cite>clonebundles.manifest</cite> file as <cite>peer-bundle-cache://mybundle.bundle</cite>.</p> |
| 214 |
</div> |
| 215 |
<div class="section" id="auto-generation-of-clone-bundles"> |
| 216 |
<h2><a class="toc-backref" href="#contents">auto-generation of clone bundles</a></h2> |
| 217 |
<p>It is possible to set Mercurial to automatically re-generate clone bundles when |
| 218 |
enough new content is available.</p> |
| 219 |
<p>Mercurial will take care of the process asynchronously. The defined list of |
| 220 |
bundle-type will be generated, uploaded, and advertised. Older bundles will get |
| 221 |
decommissioned as newer ones replace them.</p> |
| 222 |
<div class="section" id="bundles-generation"> |
| 223 |
<h3>Bundles Generation:</h3> |
| 224 |
<p>The extension can generate multiple variants of the clone bundle. Each |
| 225 |
different variant will be defined by the "bundle-spec" they use:</p> |
| 226 |
<pre class="literal-block"> |
| 227 |
[clone-bundles] |
| 228 |
auto-generate.formats= zstd-v2, gzip-v2 |
| 229 |
</pre> |
| 230 |
<p>See <cite>hg help bundlespec</cite> for details about available options.</p> |
| 231 |
<p>By default, new bundles are generated when 5% of the repository contents or at |
| 232 |
least 1000 revisions are not contained in the cached bundles. This option can |
| 233 |
be controlled by the <cite>clone-bundles.trigger.below-bundled-ratio</cite> option |
| 234 |
(default 0.95) and the <cite>clone-bundles.trigger.revs</cite> option (default 1000):</p> |
| 235 |
<pre class="literal-block"> |
| 236 |
[clone-bundles] |
| 237 |
trigger.below-bundled-ratio=0.95 |
| 238 |
trigger.revs=1000 |
| 239 |
</pre> |
| 240 |
<p>This logic can be manually triggered using the <cite>admin::clone-bundles-refresh</cite> |
| 241 |
command, or automatically on each repository change if |
| 242 |
<cite>clone-bundles.auto-generate.on-change</cite> is set to <cite>yes</cite>:</p> |
| 243 |
<pre class="literal-block"> |
| 244 |
[clone-bundles] |
| 245 |
auto-generate.on-change=yes |
| 246 |
auto-generate.formats= zstd-v2, gzip-v2 |
| 247 |
</pre> |
| 248 |
</div> |
| 249 |
<div class="section" id="automatic-inline-serving"> |
| 250 |
<h3>Automatic Inline serving</h3> |
| 251 |
<p>The simplest way to serve the generated bundle is through the Mercurial |
| 252 |
protocol. However it is not the most efficient as request will still be served |
| 253 |
by that main server. It is useful in case where authentication is complexe or |
| 254 |
when an efficient mirror system is already in use anyway. See the <cite>inline |
| 255 |
clonebundles</cite> section above for details about inline clonebundles</p> |
| 256 |
<p>To automatically serve generated bundle through inline clonebundle, simply set |
| 257 |
the following option:</p> |
| 258 |
<pre class="literal-block"> |
| 259 |
auto-generate.serve-inline=yes |
| 260 |
</pre> |
| 261 |
<p>Enabling this option disable the managed upload and serving explained below.</p> |
| 262 |
</div> |
| 263 |
<div class="section" id="bundles-upload-and-serving"> |
| 264 |
<h3>Bundles Upload and Serving:</h3> |
| 265 |
<p>This is the most efficient way to serve automatically generated clone bundles, |
| 266 |
but requires some setup.</p> |
| 267 |
<p>The generated bundles need to be made available to users through a "public" URL. |
| 268 |
This should be donne through <cite>clone-bundles.upload-command</cite> configuration. The |
| 269 |
value of this command should be a shell command. It will have access to the |
| 270 |
bundle file path through the <cite>$HGCB_BUNDLE_PATH</cite> variable. And the expected |
| 271 |
basename in the "public" URL is accessible at:</p> |
| 272 |
<pre class="literal-block"> |
| 273 |
[clone-bundles] |
| 274 |
upload-command=sftp put $HGCB_BUNDLE_PATH sftp://bundles.host/clone-bundles/$HGCB_BUNDLE_BASENAME |
| 275 |
</pre> |
| 276 |
<p>If the file was already uploaded, the command must still succeed.</p> |
| 277 |
<p>After upload, the file should be available at an url defined by |
| 278 |
<cite>clone-bundles.url-template</cite>.</p> |
| 279 |
<blockquote> |
| 280 |
[clone-bundles] |
| 281 |
url-template=https://bundles.host/cache/clone-bundles/{basename}</blockquote> |
| 282 |
</div> |
| 283 |
<div class="section" id="old-bundles-cleanup"> |
| 284 |
<h3>Old bundles cleanup:</h3> |
| 285 |
<p>When new bundles are generated, the older ones are no longer necessary and can |
| 286 |
be removed from storage. This is done through the <cite>clone-bundles.delete-command</cite> |
| 287 |
configuration. The command is given the url of the artifact to delete through |
| 288 |
the <cite>$HGCB_BUNDLE_URL</cite> environment variable.</p> |
| 289 |
<blockquote> |
| 290 |
[clone-bundles] |
| 291 |
delete-command=sftp rm sftp://bundles.host/clone-bundles/$HGCB_BUNDLE_BASENAME</blockquote> |
| 292 |
<p>If the file was already deleted, the command must still succeed.</p> |
| 293 |
</div> |
| 294 |
</div> |
| 295 |
</div> |
| 296 |
<div class="section" id="commands"> |
| 297 |
<h1><a class="toc-backref" href="#contents">Commands</a></h1> |
| 298 |
<div class="section" id="uncategorized-commands"> |
| 299 |
<h2><a class="toc-backref" href="#contents">Uncategorized commands</a></h2> |
| 300 |
<div class="section" id="admin-clone-bundles-clear"> |
| 301 |
<h3>admin::clone-bundles-clear</h3> |
| 302 |
<p>remove existing clone bundle caches:</p> |
| 303 |
<pre class="literal-block"> |
| 304 |
hg admin::clone-bundles-clear |
| 305 |
</pre> |
| 306 |
<p>See <cite>hg help admin::clone-bundles-refresh</cite> for details on how to regenerate |
| 307 |
them.</p> |
| 308 |
<p>This command will only affect bundles currently available, it will not |
| 309 |
affect bundles being asynchronously generated.</p> |
| 310 |
</div> |
| 311 |
<div class="section" id="admin-clone-bundles-refresh"> |
| 312 |
<h3>admin::clone-bundles-refresh</h3> |
| 313 |
<p>generate clone bundles according to the configuration:</p> |
| 314 |
<pre class="literal-block"> |
| 315 |
hg admin::clone-bundles-refresh |
| 316 |
</pre> |
| 317 |
<p>This runs the logic for automatic generation, removing outdated bundles and |
| 318 |
generating new ones if necessary. See <a class="reference external" href="hg.1.html#-e"><tt class="docutils literal">hg help <span class="pre">-e</span> <span class="pre">clone-bundles</span></tt></a> for |
| 319 |
details about how to configure this feature.</p> |
| 320 |
<p>Options:</p> |
| 321 |
<table class="docutils option-list" frame="void" rules="none"> |
| 322 |
<col class="option" /> |
| 323 |
<col class="description" /> |
| 324 |
<tbody valign="top"> |
| 325 |
<tr><td class="option-group"> |
| 326 |
<kbd><span class="option">--background</span></kbd></td> |
| 327 |
<td>start bundle generation in the background</td></tr> |
| 328 |
</tbody> |
| 329 |
</table> |
| 330 |
</div> |
| 331 |
</div> |
| 332 |
</div> |
| 333 |
</div> |
| 334 |
</body> |
| 335 |
</html> |