wireproto: add request IDs to frames
One of my primary goals with the new wire protocol is to make
operations faster and enable both client and server-side
operations to scale to multiple CPU cores.
One of the ways we make server interactions faster is by reducing
the number of round trips to that server.
With the existing wire protocol, the "batch" command facilitates
executing multiple commands from a single request payload. The way
it works is the requests for multiple commands are serialized. The
server executes those commands sequentially then serializes all
their results. As an optimization for reducing round trips, this
is very effective. The technical implementation, however, is pretty
bad and suffers from a number of deficiencies. For example, it
creates a new place where authorization to run a command must be
checked. (The lack of this checking in older Mercurial releases
was CVE-2018-1000132.)
The principles behind the "batch" command are sound. However, the
execution is not. Therefore, I want to ditch "batch" in the
new wire protocol and have protocol level support for issuing
multiple requests in a single round trip.
This commit introduces support in the frame-based wire protocol to
facilitate this. We do this by adding a "request ID" to each frame.
If a server sees frames associated with different "request IDs," it
handles them as separate requests. All of this happening possibly
as part of the same message from client to server (the same request
body in the case of HTTP).
We /could/ model the exchange the way pipelined HTTP requests do,
where the server processes requests in order they are issued and
received. But this artifically constrains scalability. A better
model is to allow multi-requests to be executed concurrently and
for responses to be sent and handled concurrently. So the
specification explicitly allows this. There is some work to be done
around specifying dependencies between multi-requests. We take
the easy road for now and punt on this problem, declaring that
if order is important, clients must not issue the request until
responses to dependent requests have been received.
This commit focuses on the boilerplate of implementing the request
ID. The server reactor still can't manage multiple, in-flight
request IDs. This will be addressed in a subsequent commit.
Because the wire semantics have changed, we bump the version of the
media type.
Differential Revision: https://phab.mercurial-scm.org/D2869
Initial setup.
$ hg init repo
$ cd repo
$ touch thefile
$ hg ci -A -m 'Initial commit.'
adding thefile
Create a tag.
$ hg tag branchortag
Create a branch with the same name as the tag.
$ hg branch branchortag
marked working directory as branch branchortag
(branches are permanent and global, did you want a bookmark?)
$ hg ci -m 'Create a branch with the same name as a tag.'
This is what we have:
$ hg log
changeset: 2:10519b3f489a
branch: branchortag
tag: tip
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: Create a branch with the same name as a tag.
changeset: 1:2635c45ca99b
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: Added tag branchortag for changeset f57387372b5d
changeset: 0:f57387372b5d
tag: branchortag
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: Initial commit.
Update to the tag:
$ hg up 'tag(branchortag)'
0 files updated, 0 files merged, 1 files removed, 0 files unresolved
$ hg parents
changeset: 0:f57387372b5d
tag: branchortag
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: Initial commit.
Updating to the branch:
$ hg up 'branch(branchortag)'
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg parents
changeset: 2:10519b3f489a
branch: branchortag
tag: tip
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: Create a branch with the same name as a tag.
$ cd ..