Mercurial > hg
comparison mercurial/exchange.py @ 50666:60f9602b413e
clonebundles: add support for inline (streaming) clonebundles
The idea behind inline clonebundles is to send them through
the ssh or https connection to the Mercurial server.
We've been using this specifically for streaming clonebundles,
although it works for 'regular' clonebundles as well
(but is less relevant, since pullbundles exist).
We've had this enabled for around 9 months for a part
of our users.
A few benefits are:
- no need to secure an external system,
since everything goes through the same Mercurial server
- easier scaling (in our case: no risk of inconsistencies
between multiple mercurial-server mirrors and nginx clonebundles hosts)
Remaining topics/questions right now:
- The inline clonebundles don't work for https yet.
This is because httppeer doesn't seem to support sending client
capabilities.
I didn't focus on that as my main goal was to get this working
for ssh.
author | Mathias De Mare <mathias.de_mare@nokia.com> |
---|---|
date | Wed, 08 Mar 2023 14:23:43 +0100 |
parents | f4a540c203d7 |
children | 2aaabd8f4471 |
comparison
equal
deleted
inserted
replaced
50646:c814101560d9 | 50666:60f9602b413e |
---|---|
2832 | 2832 |
2833 entries = bundlecaches.sortclonebundleentries(repo.ui, entries) | 2833 entries = bundlecaches.sortclonebundleentries(repo.ui, entries) |
2834 | 2834 |
2835 url = entries[0][b'URL'] | 2835 url = entries[0][b'URL'] |
2836 repo.ui.status(_(b'applying clone bundle from %s\n') % url) | 2836 repo.ui.status(_(b'applying clone bundle from %s\n') % url) |
2837 if trypullbundlefromurl(repo.ui, repo, url): | 2837 if trypullbundlefromurl(repo.ui, repo, url, remote): |
2838 repo.ui.status(_(b'finished applying clone bundle\n')) | 2838 repo.ui.status(_(b'finished applying clone bundle\n')) |
2839 # Bundle failed. | 2839 # Bundle failed. |
2840 # | 2840 # |
2841 # We abort by default to avoid the thundering herd of | 2841 # We abort by default to avoid the thundering herd of |
2842 # clients flooding a server that was expecting expensive | 2842 # clients flooding a server that was expecting expensive |
2853 b'"--config ui.clonebundles=false"' | 2853 b'"--config ui.clonebundles=false"' |
2854 ), | 2854 ), |
2855 ) | 2855 ) |
2856 | 2856 |
2857 | 2857 |
2858 def trypullbundlefromurl(ui, repo, url): | 2858 def inline_clone_bundle_open(ui, url, peer): |
2859 if not peer: | |
2860 raise error.Abort(_(b'no remote repository supplied for %s' % url)) | |
2861 clonebundleid = url[len(bundlecaches.CLONEBUNDLESCHEME) :] | |
2862 peerclonebundle = peer.get_inline_clone_bundle(clonebundleid) | |
2863 return util.chunkbuffer(peerclonebundle) | |
2864 | |
2865 | |
2866 def trypullbundlefromurl(ui, repo, url, peer): | |
2859 """Attempt to apply a bundle from a URL.""" | 2867 """Attempt to apply a bundle from a URL.""" |
2860 with repo.lock(), repo.transaction(b'bundleurl') as tr: | 2868 with repo.lock(), repo.transaction(b'bundleurl') as tr: |
2861 try: | 2869 try: |
2862 fh = urlmod.open(ui, url) | 2870 if url.startswith(bundlecaches.CLONEBUNDLESCHEME): |
2871 fh = inline_clone_bundle_open(ui, url, peer) | |
2872 else: | |
2873 fh = urlmod.open(ui, url) | |
2863 cg = readbundle(ui, fh, b'stream') | 2874 cg = readbundle(ui, fh, b'stream') |
2864 | 2875 |
2865 if isinstance(cg, streamclone.streamcloneapplier): | 2876 if isinstance(cg, streamclone.streamcloneapplier): |
2866 cg.apply(repo) | 2877 cg.apply(repo) |
2867 else: | 2878 else: |