Skip to content

Commit 222d57a

Browse files
committed
Add Skyhash spec and EOL terrapipe
1 parent 30d12ea commit 222d57a

File tree

5 files changed

+207
-41
lines changed

5 files changed

+207
-41
lines changed

docs/1.index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Once you've learned the basics, start using a [client driver](clients)!
1313

1414
## Developers
1515

16-
You can find information on how to build your own clients [here](Protocol/terrapipe). The primary idea is to implement the Terrapipe Protocol.
16+
You can find information on how to build your own clients [here](protocol/skyhash). The primary idea is to implement the Skyhash Protocol.
1717

1818
## Contributing
1919

docs/Protocol/skyhash.md

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
---
2+
id: skyhash
3+
title: Skyhash Protocol 1.0
4+
---
5+
:::note About this document
6+
Copyright (c) 2021 Sayan Nandan <[email protected]>
7+
**In effect since:** v0.6.0
8+
**Date:** 11<sup>th</sup> May, 2021
9+
:::
10+
11+
## Introduction
12+
13+
Skyhash or the Skytable Serialization Protocol (SSP) is a serialization protocol built on top of TCP that is
14+
used by Skytable for client/server communication. All clients willing to communicate with Skytable need to implement this protocol.
15+
16+
## Concepts
17+
18+
Skyhash uses a query/response action just like HTTP's request/response action &mdash;
19+
clients send queries while the server sends responses. All the bytes sent by a client to a server is called a _Query Packet_ while all the bytes sent by the server in response to this is called the _Response packet_.
20+
21+
Irrespective of the action type, all these packets are made of a metaframe and a dataframe.
22+
23+
### The Metaframe
24+
The metaframe is the first part of the packet separated from the rest of the packet by a line feed (`\n`) character. It looks like
25+
this:
26+
```
27+
*<c>\n
28+
```
29+
where `<c>` tells us the number of actions this packet corresponds to. For simple queries which run one action, this will be one while for batch queries it can have any value in the range (1, +∞).
30+
31+
### The Dataframe
32+
The dataframe is made up of elements. Each element corresponds to
33+
a single action and hence corresponds to a single query. Simple queries will run one action and hence will have one element while batch queries will run a number of actions and hence will have a number of elements.
34+
35+
Every element is of a certain [data type](#common-data-types) and this type determines how the element is serialized with Skyhash. Responses receive some extra data types which are
36+
highlighted in [response specific data types](#response-specific-data-types).
37+
38+
## Common Data Types
39+
40+
Usually serialized data types look like:
41+
```
42+
<tsymbol><len>\n
43+
-----DATA-------
44+
```
45+
where the `<tsymbol>` corresponds to the Type Symbol and the `<len>` corresponds to the length of
46+
this element. Below is a list of data types and their `<tsymbol>`s.
47+
48+
### Strings (+)
49+
String elements are serialized like:
50+
```
51+
+<c>\n
52+
<mystring>\n
53+
```
54+
Where `<c>` is the number of bytes in the string '`<mystring>`'.
55+
So a string 'Sayan' will be serialized into:
56+
```
57+
+5\n
58+
Sayan\n
59+
```
60+
61+
Strings are binary safe because they have prefixed lengths
62+
63+
### Unsigned integers (:)
64+
65+
64-bit usigned integers are serialized into:
66+
```
67+
:<c>\n
68+
<myint>\n
69+
```
70+
Where `<c>` is the number of digits in the integer and `<myint>` is the integer itself.
71+
72+
### Arrays (&)
73+
74+
Arrays are recursive data types, that is an array can contain another array which in turn can contain another array and so on. And array is essentially a collection of data types, including itself. Also, arrays can be multi-type.
75+
76+
Skyhash serializes arrays into:
77+
```
78+
&<c>\n
79+
<elements>
80+
```
81+
Where `<c>` is the number of elements in this array and `<elements>` are the elements present in the array. Take a look at the following examples:
82+
83+
1. An array containing two strings:
84+
```
85+
&2\n
86+
+5\n
87+
Hello
88+
+5\n
89+
World\n
90+
```
91+
This can be represented as:
92+
```js
93+
Array([String("Hello"), String("World")])
94+
```
95+
2. An array containing a string an two integers:
96+
```
97+
&3\n
98+
+5\n
99+
Hello
100+
:1\n
101+
0\n
102+
:1\n
103+
1\n
104+
```
105+
Which can be represented as:
106+
```js
107+
Array([String("Hello"), UnsignedInt64(0), UnsignedInt64(1)])
108+
```
109+
3. An array containing two arrays:
110+
Pipe symbols (|) and underscores (_) were added for explaining the logical parts of the array:
111+
112+
```
113+
___________________________
114+
&2\n |_____________| |
115+
&2\n | | |
116+
+5\n | | |
117+
Hello\n | Array 1 | |
118+
+5\n | | |
119+
World\n |_____________| |
120+
&3\n | | Nested |
121+
+5\n | | Array |
122+
Hello\n | | |
123+
+5\n | Array 2 | |
124+
World\n | | |
125+
+5\n | | |
126+
Again\n |_____________|_____________|
127+
```
128+
129+
This can be represented as:
130+
```js
131+
Array([
132+
Array([String("Hello"), String("World")]),
133+
Array([String("Hello"), String("World"), String("Again")])
134+
])
135+
```
136+
This can be nested even more!
137+
138+
139+
### Important notes
140+
141+
These data types and `<tsymbols>` are non-exhaustive. Whenever you are attempting to deserialize a packet, always throw some kind of `UnimplementedError` to indicate that your client cannot yet deserialize this specific type. See all current data types and their tsymbols [in this table](data-types).
142+
143+
## Response Specific Data Types
144+
145+
Responses will return some additional data types. This is a _non-exhaustive_ list of such types.
146+
147+
### Response Codes (!)
148+
149+
Response codes are often returned by the server when no
150+
'producable' data can be returned, i.e something like FLUSHDB can only possibly return 'Okay' or an error. This distinction
151+
is made to reduce errors while matching responses. Skyhash will serialize a response code like:
152+
```
153+
!<c>\n
154+
<code>\n
155+
```
156+
Where `<c>` is the number of characters in the code and `<code>` is the code itself. So Code `0` that corresponds to `OKAY` will be serialized into:
157+
```
158+
!1\n
159+
0\n
160+
```
161+
162+
You find a full list of response codes [in this table](response-codes).

docs/Protocol/terrapipe.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ id: terrapipe
33
title: Terrapipe 1.0
44
---
55
:::note About this document
6-
Copyright (c) 2020 Sayan <<ohsayan@outlook.com>>
6+
Copyright (c) 2020 Sayan Nandan &lt;nandansayan@outlook.com&gt;
77
**Date:** Aug 23, 2020
88
**In effect since:** v0.4.0
9-
**Date:** 6<sup>th</sup> Aug, 2020
10-
Copyright &copy; 2020 Sayan Nandan
9+
**Revision Date:** 6<sup>th</sup> Aug, 2020
10+
**EOL since:** v0.6.0
11+
:::
12+
:::danger EOL Notice
13+
This protocol has reached EOL since Skytable 0.6. Please use the [Skyhash Protocol](skyhash) instead.
1114
:::
1215
## Introduction
1316

docs/actions.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ title: Actions overview
44
---
55
Actions are like shell commands: they take arguments and do something! Skytable currently supports the following actions:
66

7-
* [DBSIZE](Actions/DBSIZE.md)
8-
* [DEL](Actions/DEL.md)
9-
* [EXISTS](Actions/EXISTS.md)
10-
* [FLUSHDB](Actions/FLUSHDB.md)
11-
* [GET](Actions/GET.md)
12-
* [KEYLEN](Actions/KEYLEN.md)
13-
* [MGET](Actions/MGET.md)
14-
* [MKSNAP](Actions/MKSNAP.md)
15-
* [MSET](Actions/MSET.md)
16-
* [MUPDATE](Actions/MUPDATE.md)
17-
* [SDEL](Actions/SDEL.md)
18-
* [SET](Actions/SET.md)
19-
* [SSET](Actions/SSET.md)
20-
* [SUPDATE](Actions/SUPDATE.md)
21-
* [UPDATE](Actions/UPDATE.md)
22-
* [USET](Actions/USET.md)
7+
* [DBSIZE](actions/DBSIZE.md)
8+
* [DEL](actions/DEL.md)
9+
* [EXISTS](actions/EXISTS.md)
10+
* [FLUSHDB](actions/FLUSHDB.md)
11+
* [GET](actions/GET.md)
12+
* [KEYLEN](actions/KEYLEN.md)
13+
* [MGET](actions/MGET.md)
14+
* [MKSNAP](actions/MKSNAP.md)
15+
* [MSET](actions/MSET.md)
16+
* [MUPDATE](actions/MUPDATE.md)
17+
* [SDEL](actions/SDEL.md)
18+
* [SET](actions/SET.md)
19+
* [SSET](actions/SSET.md)
20+
* [SUPDATE](actions/SUPDATE.md)
21+
* [UPDATE](actions/UPDATE.md)
22+
* [USET](actions/USET.md)

sidebars.auto.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,34 @@ module.exports = {
1616
"type": "category",
1717
"label": "Actions",
1818
"items": [
19-
"Actions/dbsize",
20-
"Actions/del",
21-
"Actions/exists",
22-
"Actions/flushdb",
23-
"Actions/get",
24-
"Actions/heya",
25-
"Actions/keylen",
26-
"Actions/mget",
27-
"Actions/mksnap",
28-
"Actions/mset",
29-
"Actions/mupdate",
30-
"Actions/sdel",
31-
"Actions/set",
32-
"Actions/sset",
33-
"Actions/supdate",
34-
"Actions/update",
35-
"Actions/uset"
19+
"actions/dbsize",
20+
"actions/del",
21+
"actions/exists",
22+
"actions/flushdb",
23+
"actions/get",
24+
"actions/heya",
25+
"actions/keylen",
26+
"actions/mget",
27+
"actions/mksnap",
28+
"actions/mset",
29+
"actions/mupdate",
30+
"actions/sdel",
31+
"actions/set",
32+
"actions/sset",
33+
"actions/supdate",
34+
"actions/update",
35+
"actions/uset"
3636
]
3737
},
3838
{
3939
"type" : "category",
4040
"label" : "Protocol",
4141
"items" : [
42-
"Protocol/terrapipe",
43-
"Protocol/data-types",
44-
"Protocol/response-codes",
45-
"Protocol/errors"
42+
"protocol/skyhash",
43+
"protocol/terrapipe",
44+
"protocol/data-types",
45+
"protocol/response-codes",
46+
"protocol/errors"
4647
]
4748
}
4849
]

0 commit comments

Comments
 (0)