You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We should work with driver developers well in advance of the 1.13 release if possible so that they have a heads up on the new JSON API, once it's in a more stable form.
@mglukhovsky -- me, you, and @mlucy discussed this before. 1.13 will still ship with the protobuf API, so we won't break anything. It's better to ship a concrete implementation and then tell people, so they can migrate the drivers at their own pace.
@coffeemug, I remember, I'm fine with that. However, I think that it'd be nice to send out @mlucy's typical email to driver developers notifying them of changes sooner than we typically do (by a week or two, if possible).
Obviously, this shouldn't get in the way of ensuring a good implementation of the JSON API.
Ok, I've done a good amount of work on the protocol, so I'm putting a partial writeup here in case it's useful. Could still use some more details and examples.
Driver Handshake
The client should send the following things to the server's driver port (default is 28015):
4-byte version magic number, little-endian, corresponding to VersionDummy::Version::V0_3, for this version of the protocol
4-byte length, little-endian, giving the length of the authorization key string (this may be 0 if no authorization key is given)
authorization key string, in ASCII
4-byte wire protocol magic number, little-endian, corresponding to VersionDummy::Protocol::JSON, for this version of the protocol
The server will then reply with a NULL-terminated ASCII string regarding the result of the connection attempt. If the string is "SUCCESS", the client may begin sending queries and receive responses, as detailed below. On an error, the string should contain some description of why the attempt failed, and the TCP connection will be closed.
The query format (client to server) is as follows:
8-byte token, little-endian, providing a unique ID for the query
4-byte length, little-endian, giving the length in bytes of the JSON string following this
JSON string request, as an array with the following elements:
The type of the query, an integer given by Query::QueryType in ql2.proto
The terms for the query, (see below). This should only be included for queries with Query::QueryType::START.
The global optargs for the query, as a dict (see below). This should only be included for queries with Query::QueryType::START, and may be omitted if the dict has no entries.
Query terms: TODO
Valid global optargs:
db - a string giving the default database to use if no r.db(...) is included in the query
use_outdated - a boolean indicating whether outdated reads may be performed
noreply - a boolean telling the server whether to send a response for the query
profile - a boolean telling the server whether to include profiler data in the response
durability - a string telling the server the type of write durability to use, possible values are "hard" and "soft"
Examples
TODO
Responses
The response format (server to client) is as follows:
8-byte token, little-endian, corresponding to the token given in a previous query
4-byte length, little-endian, giving the length in bytes of the JSON string following this
JSON string response as a dict with the following keys:
t - required, the type of the response, an integer given by Response::ResponseType in ql2.proto
r - required, the result data from the query, as an array
b - optional, the backtrace from the query if an error occurred
p - optional, the profile data from the query if profile=True was specified in the global optargs
Examples
TODO
Atom
Sequence
Error
Things to Be Careful About
Unicode string lengths
When passing length-prefixed strings to the server, make sure that the length given is the number of bytes, not the number of characters
NaN/Infinity
NaN and Infinity are not allowed in Datums on the server
These values are not valid in JSON, so some libraries might write them as strings
The driver should reject NaN and Infinity rather than attempt to send them to the server
@Tryneus thank you! I've been working on a driver for Rust and was able to piece together some of the new protocol from the new Ruby driver and json_shim.cc but a comprehensive document like this is worth its weight in gold. 🍺
@tomjakubowski, I should mention, some of this isn't in next yet, since it's still in code review. But everything including the updated python and javascript drivers are in my branch grey_issue_2224_js if that helps at all.
Also, I'm told by somebody writing a driver that the JSON response contains the token inside of itself. Is this true? Is the response actually sending the token twice?
Why is it a 4-byte length instead of 8 bytes or a varint?
I don't think we have any intention of allowing queries or responses greater than 4 GB in one message. I can change this, if you think otherwise.
How can this possibly be a 64-bit integer, if it's encoded in a JSON string?
Good point, it's treated on the server as a 64-bit integer, but I should have just said 'integer'
Wait, the requests send a token in JSON and the response receives it outside JSON?
We could send the token outside of JSON. That might actually be better for certain error cases in the server. We receive it outside of JSON so that the driver can know what query it is even if parsing fails.
Is the response actually sending the token twice?
No, I removed that because redundancy like that just adds more surface area for errors.
I think we should pull the token out of requests as well as responses -- there's no reason we can't just send the token right before the size of the JSON string (in fact it's probably better, because if we fail to parse the JSON string we can tell the client what token we failed to parse on).
Updated the description for the changes from #2283. Also of note, the wire protocol is now a magic number rather than a string, values are in ql2.proto.
For those that may be interested, I just pushed some changes on rethinkdb-driver-development.
Check out the branch v1.13 if you want to see how the JSON protocol works.
Activity
mglukhovsky commentedon Apr 8, 2014
We should work with driver developers well in advance of the 1.13 release if possible so that they have a heads up on the new JSON API, once it's in a more stable form.
coffeemug commentedon Apr 8, 2014
@mglukhovsky -- me, you, and @mlucy discussed this before. 1.13 will still ship with the protobuf API, so we won't break anything. It's better to ship a concrete implementation and then tell people, so they can migrate the drivers at their own pace.
mglukhovsky commentedon Apr 8, 2014
@coffeemug, I remember, I'm fine with that. However, I think that it'd be nice to send out @mlucy's typical email to driver developers notifying them of changes sooner than we typically do (by a week or two, if possible).
Obviously, this shouldn't get in the way of ensuring a good implementation of the JSON API.
neumino commentedon Apr 8, 2014
We should write docs as soon as possible because
Tryneus commentedon Apr 18, 2014
Ok, I've done a good amount of work on the protocol, so I'm putting a partial writeup here in case it's useful. Could still use some more details and examples.
Driver Handshake
The client should send the following things to the server's driver port (default is
28015):The server will then reply with a NULL-terminated ASCII string regarding the result of the connection attempt. If the string is "SUCCESS", the client may begin sending queries and receive responses, as detailed below. On an error, the string should contain some description of why the attempt failed, and the TCP connection will be closed.
Example
No authorization key
Client to Server:
3e e8 75 5f00 00 00 00c7 70 69 7eServer to Client:
53 55 43 43 45 53 5300Incorrect Authorization Key
Client to Server:
3e e8 75 5f07 00 00 0068 75 6e 74 65 72 32c7 70 69 7eServer to Client:
45 52 52 4f 52 3a 20 49 6e 63 6f 72 72 65 63 74 20 61 75 74 68 6f 72 69 7a 61 74 69 6f 6e 20 6b 65 79 2e00Queries
The query format (client to server) is as follows:
ql2.protoQuery terms:
TODO
Valid global optargs:
db- a string giving the default database to use if nor.db(...)is included in the queryuse_outdated- a boolean indicating whether outdated reads may be performednoreply- a boolean telling the server whether to send a response for the queryprofile- a boolean telling the server whether to include profiler data in the responsedurability- a string telling the server the type of write durability to use, possible values are "hard" and "soft"Examples
TODO
Responses
The response format (server to client) is as follows:
t- required, the type of the response, an integer given by Response::ResponseType inql2.protor- required, the result data from the query, as an arrayb- optional, the backtrace from the query if an error occurredp- optional, the profile data from the query ifprofile=Truewas specified in the global optargsExamples
TODO
Atom
Sequence
Error
Things to Be Careful About
tomjakubowski commentedon Apr 18, 2014
@Tryneus thank you! I've been working on a driver for Rust and was able to piece together some of the new protocol from the new Ruby driver and json_shim.cc but a comprehensive document like this is worth its weight in gold. 🍺
Tryneus commentedon Apr 18, 2014
@tomjakubowski, I should mention, some of this isn't in
nextyet, since it's still in code review. But everything including the updated python and javascript drivers are in my branchgrey_issue_2224_jsif that helps at all.srh commentedon Apr 18, 2014
Why is it a 4-byte length instead of 8 bytes or a varint?
srh commentedon Apr 18, 2014
How can this possibly be a 64-bit integer, if it's encoded in a JSON string?
srh commentedon Apr 18, 2014
Wait, the requests send a token in JSON and the response receives it outside JSON??
srh commentedon Apr 18, 2014
Also, I'm told by somebody writing a driver that the JSON response contains the token inside of itself. Is this true? Is the response actually sending the token twice?
tomjakubowski commentedon Apr 18, 2014
That appears to have been removed on the topic branch mentioned earlier f64981e. My mistake.
Tryneus commentedon Apr 18, 2014
@srh:
I don't think we have any intention of allowing queries or responses greater than 4 GB in one message. I can change this, if you think otherwise.
Good point, it's treated on the server as a 64-bit integer, but I should have just said 'integer'
We could send the token outside of JSON. That might actually be better for certain error cases in the server. We receive it outside of JSON so that the driver can know what query it is even if parsing fails.
No, I removed that because redundancy like that just adds more surface area for errors.
mlucy commentedon Apr 18, 2014
I think we should pull the token out of requests as well as responses -- there's no reason we can't just send the token right before the size of the JSON string (in fact it's probably better, because if we fail to parse the JSON string we can tell the client what token we failed to parse on).
Tryneus commentedon Apr 18, 2014
@mlucy, agreed, I'll change that.
Tryneus commentedon Apr 18, 2014
Ok, opened #2283 for moving the token out, working on that now.
Tryneus commentedon Apr 23, 2014
Updated the description for the changes from #2283. Also of note, the wire protocol is now a magic number rather than a string, values are in
ql2.proto.mlucy commentedon Apr 24, 2014
@Tryneus -- since you've already started a writeup for this, could I re-assign to you?
Tryneus commentedon Apr 24, 2014
@mlucy, sure, I'll go ahead and add some more details.
neumino commentedon May 2, 2014
For those that may be interested, I just pushed some changes on
rethinkdb-driver-development.Check out the branch
v1.13if you want to see how the JSON protocol works.https://github.com/neumino/rethinkdb-driver-development/tree/v1.13
coffeemug commentedon May 28, 2014
@mlucy -- do you think the doc up in #2225 (comment) is good enough? Is there anything left to do here?
mlucy commentedon May 28, 2014
@coffeemug -- several sections of that comment are still marked TODO.
coffeemug commentedon May 28, 2014
Ok -- closing this in favor of rethinkdb/docs#320.