diff mercurial/wireprotov2server.py @ 40172:30f70d11c224

wireprotov2: advertise recommended batch size for requests Currently, exchangev2 hardcodes the batch size for how many revisions to fetch per command request. A single value is not appropriate for every repository because some repositories may have a drastically different "shape" from other repositories. e.g. a repo with lots of small files may benefit from larger batch sizes than a repo with lots of large files. And depending on caching used by the server, the server may wish to control the number of commands (to e.g. mitigate overhead of following content redirects). This commit teaches wireprotov2 commands to declare extra metadata which is advertised as part of the command descriptor. The manifestdata command has been taught to advertise a recommended batch size for requests. Differential Revision: https://phab.mercurial-scm.org/D4975
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 08 Oct 2018 17:45:51 -0700
parents b5bf3dd6ec5b
children 6c42409691ec
line wrap: on
line diff
--- a/mercurial/wireprotov2server.py	Wed Oct 03 13:07:28 2018 -0700
+++ b/mercurial/wireprotov2server.py	Mon Oct 08 17:45:51 2018 -0700
@@ -518,6 +518,10 @@
             'permissions': [entry.permission],
         }
 
+        if entry.extracapabilitiesfn:
+            extracaps = entry.extracapabilitiesfn(repo, proto)
+            caps['commands'][command].update(extracaps)
+
     caps['rawrepoformats'] = sorted(repo.requirements &
                                     repo.supportedformats)
 
@@ -581,7 +585,8 @@
     """
     return []
 
-def wireprotocommand(name, args=None, permission='push', cachekeyfn=None):
+def wireprotocommand(name, args=None, permission='push', cachekeyfn=None,
+                     extracapabilitiesfn=None):
     """Decorator to declare a wire protocol command.
 
     ``name`` is the name of the wire protocol command being provided.
@@ -613,6 +618,12 @@
     ``cachekeyfn`` defines an optional callable that can derive the
     cache key for this request.
 
+    ``extracapabilitiesfn`` defines an optional callable that defines extra
+    command capabilities/parameters that are advertised next to the command
+    in the capabilities data structure describing the server. The callable
+    receives as arguments the repository and protocol objects. It returns
+    a dict of extra fields to add to the command descriptor.
+
     Wire protocol commands are generators of objects to be serialized and
     sent to the client.
 
@@ -675,7 +686,7 @@
 
         COMMANDS[name] = wireprototypes.commandentry(
             func, args=args, transports=transports, permission=permission,
-            cachekeyfn=cachekeyfn)
+            cachekeyfn=cachekeyfn, extracapabilitiesfn=extracapabilitiesfn)
 
         return func
 
@@ -1091,6 +1102,14 @@
 
     yield node
 
+def manifestdatacapabilities(repo, proto):
+    batchsize = repo.ui.configint(
+        b'experimental', b'server.manifestdata.recommended-batch-size')
+
+    return {
+        b'recommendedbatchsize': batchsize,
+    }
+
 @wireprotocommand(
     'manifestdata',
     args={
@@ -1115,7 +1134,8 @@
         },
     },
     permission='pull',
-    cachekeyfn=makecommandcachekeyfn('manifestdata', 1, allargs=True))
+    cachekeyfn=makecommandcachekeyfn('manifestdata', 1, allargs=True),
+    extracapabilitiesfn=manifestdatacapabilities)
 def manifestdata(repo, proto, haveparents, nodes, fields, tree):
     store = repo.manifestlog.getstorage(tree)