| 1 |
.. -*- rst -*- |
| 2 |
|
| 3 |
GQTP |
| 4 |
==== |
| 5 |
|
| 6 |
GQTP is the acronym of Groonga Query Transfer Protocol. GQTP is the |
| 7 |
original protocol for groonga. |
| 8 |
|
| 9 |
Protocol |
| 10 |
-------- |
| 11 |
|
| 12 |
GQTP is stateful client server model protocol. The following sequence |
| 13 |
is one processing unit: |
| 14 |
|
| 15 |
* Client sends a request |
| 16 |
* Server receives the request |
| 17 |
* Server processes the request |
| 18 |
* Server sends a response |
| 19 |
* Client receives the response |
| 20 |
|
| 21 |
You can do zero or more processing units in a session. |
| 22 |
|
| 23 |
Both request and response consist of GQTP header and body. GQTP header |
| 24 |
is fixed size data. Body is variable size data and its size is stored |
| 25 |
in GQTP header. The content of body isn't defined in GQTP. |
| 26 |
|
| 27 |
.. _gqtp-header-spec: |
| 28 |
|
| 29 |
GQTP header |
| 30 |
^^^^^^^^^^^ |
| 31 |
|
| 32 |
GQTP header consists of the following unsigned integer values: |
| 33 |
|
| 34 |
+----------------+-------+----------------------------+ |
| 35 |
| Name | Size | Description | |
| 36 |
+================+=======+============================+ |
| 37 |
| ``protocol`` | 1byte | Protocol type. | |
| 38 |
+----------------+-------+----------------------------+ |
| 39 |
| ``query_type`` | 1byte | Content type of body. | |
| 40 |
+----------------+-------+----------------------------+ |
| 41 |
| ``key_length`` | 2byte | Not used. | |
| 42 |
+----------------+-------+----------------------------+ |
| 43 |
| ``level`` | 1byte | Not used. | |
| 44 |
+----------------+-------+----------------------------+ |
| 45 |
| ``flags`` | 1byte | Flags. | |
| 46 |
+----------------+-------+----------------------------+ |
| 47 |
| ``status`` | 2byte | Return code. | |
| 48 |
+----------------+-------+----------------------------+ |
| 49 |
| ``size`` | 4byte | Body size. | |
| 50 |
+----------------+-------+----------------------------+ |
| 51 |
| ``opaque`` | 4byte | Not used. | |
| 52 |
+----------------+-------+----------------------------+ |
| 53 |
| ``cas`` | 8byte | Not used. | |
| 54 |
+----------------+-------+----------------------------+ |
| 55 |
|
| 56 |
All header values are encoded by network byte order. |
| 57 |
|
| 58 |
The following sections describes available values of each header value. |
| 59 |
|
| 60 |
The total size of GQTP header is 24byte. |
| 61 |
|
| 62 |
``protocol`` |
| 63 |
"""""""""""" |
| 64 |
|
| 65 |
The value is always ``0xc7`` in both request and response GQTP header. |
| 66 |
|
| 67 |
``query_type`` |
| 68 |
"""""""""""""" |
| 69 |
|
| 70 |
The value is one of the following values: |
| 71 |
|
| 72 |
+-------------+--------+----------------------------+ |
| 73 |
| Name | Value | Description | |
| 74 |
+=============+========+============================+ |
| 75 |
| ``NONE`` | 0 | Free format. | |
| 76 |
+-------------+--------+----------------------------+ |
| 77 |
| ``TSV`` | 1 | Tab Separated Values. | |
| 78 |
+-------------+--------+----------------------------+ |
| 79 |
| ``JSON`` | 2 | JSON. | |
| 80 |
+-------------+--------+----------------------------+ |
| 81 |
| ``XML`` | 3 | XML. | |
| 82 |
+-------------+--------+----------------------------+ |
| 83 |
| ``MSGPACK`` | 4 | MessagePack. | |
| 84 |
+-------------+--------+----------------------------+ |
| 85 |
|
| 86 |
This is not used in request GQTP header. |
| 87 |
|
| 88 |
This is used in response GQTP header. Body is formatted as specified |
| 89 |
type. |
| 90 |
|
| 91 |
``flags`` |
| 92 |
""""""""" |
| 93 |
|
| 94 |
The value is bitwise OR of the following values: |
| 95 |
|
| 96 |
+-----------+--------+----------------------------+ |
| 97 |
| Name | Value | Description | |
| 98 |
+===========+========+============================+ |
| 99 |
| ``MORE`` | 0x01 | There are more data. | |
| 100 |
+-----------+--------+----------------------------+ |
| 101 |
| ``TAIL`` | 0x02 | There are no more data. | |
| 102 |
+-----------+--------+----------------------------+ |
| 103 |
| ``HEAD`` | 0x04 | Not used. | |
| 104 |
+-----------+--------+----------------------------+ |
| 105 |
| ``QUIET`` | 0x08 | Be quiet. | |
| 106 |
+-----------+--------+----------------------------+ |
| 107 |
| ``QUIT`` | 0x10 | Quit. | |
| 108 |
+-----------+--------+----------------------------+ |
| 109 |
|
| 110 |
You must specify ``MORE`` or ``TAIL`` flag. |
| 111 |
|
| 112 |
If you use ``MORE`` flag, you should also use ``QUIET`` flag. Because |
| 113 |
you don't need to show a response for your partial request. |
| 114 |
|
| 115 |
Use ``QUIT`` flag to quit this session. |
| 116 |
|
| 117 |
``status`` |
| 118 |
"""""""""" |
| 119 |
|
| 120 |
Here are available values. The new statuses will be added in the |
| 121 |
future. |
| 122 |
|
| 123 |
* 0: ``SUCCESS`` |
| 124 |
* 1: ``END_OF_DATA`` |
| 125 |
* 65535: ``UNKNOWN_ERROR`` |
| 126 |
* 65534: ``OPERATION_NOT_PERMITTED`` |
| 127 |
* 65533: ``NO_SUCH_FILE_OR_DIRECTORY`` |
| 128 |
* 65532: ``NO_SUCH_PROCESS`` |
| 129 |
* 65531: ``INTERRUPTED_FUNCTION_CALL`` |
| 130 |
* 65530: ``INPUT_OUTPUT_ERROR`` |
| 131 |
* 65529: ``NO_SUCH_DEVICE_OR_ADDRESS`` |
| 132 |
* 65528: ``ARG_LIST_TOO_LONG`` |
| 133 |
* 65527: ``EXEC_FORMAT_ERROR`` |
| 134 |
* 65526: ``BAD_FILE_DESCRIPTOR`` |
| 135 |
* 65525: ``NO_CHILD_PROCESSES`` |
| 136 |
* 65524: ``RESOURCE_TEMPORARILY_UNAVAILABLE`` |
| 137 |
* 65523: ``NOT_ENOUGH_SPACE`` |
| 138 |
* 65522: ``PERMISSION_DENIED`` |
| 139 |
* 65521: ``BAD_ADDRESS`` |
| 140 |
* 65520: ``RESOURCE_BUSY`` |
| 141 |
* 65519: ``FILE_EXISTS`` |
| 142 |
* 65518: ``IMPROPER_LINK`` |
| 143 |
* 65517: ``NO_SUCH_DEVICE`` |
| 144 |
* 65516: ``NOT_A_DIRECTORY`` |
| 145 |
* 65515: ``IS_A_DIRECTORY`` |
| 146 |
* 65514: ``INVALID_ARGUMENT`` |
| 147 |
* 65513: ``TOO_MANY_OPEN_FILES_IN_SYSTEM`` |
| 148 |
* 65512: ``TOO_MANY_OPEN_FILES`` |
| 149 |
* 65511: ``INAPPROPRIATE_I_O_CONTROL_OPERATION`` |
| 150 |
* 65510: ``FILE_TOO_LARGE`` |
| 151 |
* 65509: ``NO_SPACE_LEFT_ON_DEVICE`` |
| 152 |
* 65508: ``INVALID_SEEK`` |
| 153 |
* 65507: ``READ_ONLY_FILE_SYSTEM`` |
| 154 |
* 65506: ``TOO_MANY_LINKS`` |
| 155 |
* 65505: ``BROKEN_PIPE`` |
| 156 |
* 65504: ``DOMAIN_ERROR`` |
| 157 |
* 65503: ``RESULT_TOO_LARGE`` |
| 158 |
* 65502: ``RESOURCE_DEADLOCK_AVOIDED`` |
| 159 |
* 65501: ``NO_MEMORY_AVAILABLE`` |
| 160 |
* 65500: ``FILENAME_TOO_LONG`` |
| 161 |
* 65499: ``NO_LOCKS_AVAILABLE`` |
| 162 |
* 65498: ``FUNCTION_NOT_IMPLEMENTED`` |
| 163 |
* 65497: ``DIRECTORY_NOT_EMPTY`` |
| 164 |
* 65496: ``ILLEGAL_BYTE_SEQUENCE`` |
| 165 |
* 65495: ``SOCKET_NOT_INITIALIZED`` |
| 166 |
* 65494: ``OPERATION_WOULD_BLOCK`` |
| 167 |
* 65493: ``ADDRESS_IS_NOT_AVAILABLE`` |
| 168 |
* 65492: ``NETWORK_IS_DOWN`` |
| 169 |
* 65491: ``NO_BUFFER`` |
| 170 |
* 65490: ``SOCKET_IS_ALREADY_CONNECTED`` |
| 171 |
* 65489: ``SOCKET_IS_NOT_CONNECTED`` |
| 172 |
* 65488: ``SOCKET_IS_ALREADY_SHUTDOWNED`` |
| 173 |
* 65487: ``OPERATION_TIMEOUT`` |
| 174 |
* 65486: ``CONNECTION_REFUSED`` |
| 175 |
* 65485: ``RANGE_ERROR`` |
| 176 |
* 65484: ``TOKENIZER_ERROR`` |
| 177 |
* 65483: ``FILE_CORRUPT`` |
| 178 |
* 65482: ``INVALID_FORMAT`` |
| 179 |
* 65481: ``OBJECT_CORRUPT`` |
| 180 |
* 65480: ``TOO_MANY_SYMBOLIC_LINKS`` |
| 181 |
* 65479: ``NOT_SOCKET`` |
| 182 |
* 65478: ``OPERATION_NOT_SUPPORTED`` |
| 183 |
* 65477: ``ADDRESS_IS_IN_USE`` |
| 184 |
* 65476: ``ZLIB_ERROR`` |
| 185 |
* 65475: ``LZO_ERROR`` |
| 186 |
* 65474: ``STACK_OVER_FLOW`` |
| 187 |
* 65473: ``SYNTAX_ERROR`` |
| 188 |
* 65472: ``RETRY_MAX`` |
| 189 |
* 65471: ``INCOMPATIBLE_FILE_FORMAT`` |
| 190 |
* 65470: ``UPDATE_NOT_ALLOWED`` |
| 191 |
* 65469: ``TOO_SMALL_OFFSET`` |
| 192 |
* 65468: ``TOO_LARGE_OFFSET`` |
| 193 |
* 65467: ``TOO_SMALL_LIMIT`` |
| 194 |
* 65466: ``CAS_ERROR`` |
| 195 |
* 65465: ``UNSUPPORTED_COMMAND_VERSION`` |
| 196 |
|
| 197 |
``size`` |
| 198 |
"""""""" |
| 199 |
|
| 200 |
The size of body. The maximum body size is 4GiB because ``size`` is |
| 201 |
4byte unsigned integer. If you want to send 4GiB or more larger data, |
| 202 |
use ``MORE`` flag. |
| 203 |
|
| 204 |
Example |
| 205 |
------- |
| 206 |
|
| 207 |
How to run a GQTP server |
| 208 |
^^^^^^^^^^^^^^^^^^^^^^^^ |
| 209 |
|
| 210 |
Groonga has a special protocol, named Groonga Query Transfer Protocol (GQTP), for remote access to a database. The following form shows how to run Groonga as a GQTP server. |
| 211 |
|
| 212 |
Form:: |
| 213 |
|
| 214 |
groonga [-p PORT_NUMBER] -s DB_PATH |
| 215 |
|
| 216 |
The `-s` option specifies to run Groonga as a server. DB_PATH specifies the path of the existing database to be hosted. The `-p` option and its argument, PORT_NUMBER, specify the port number of the server. The default port number is 10043, which is used when you don't specify PORT_NUMBER. |
| 217 |
|
| 218 |
The following command runs a server that listens on the default port number. The server accepts operations to the specified database. |
| 219 |
|
| 220 |
Execution example:: |
| 221 |
|
| 222 |
% groonga -s /tmp/groonga-databases/introduction.db |
| 223 |
Ctrl-c |
| 224 |
% |
| 225 |
|
| 226 |
How to run a GQTP daemon |
| 227 |
^^^^^^^^^^^^^^^^^^^^^^^^ |
| 228 |
|
| 229 |
You can also run a GQTP server as a daemon by using the `-d` option, instead of the `-s` option. |
| 230 |
|
| 231 |
Form:: |
| 232 |
|
| 233 |
groonga [-p PORT_NUMBER] -d DB_PATH |
| 234 |
|
| 235 |
A Groonga daemon prints its process ID as follows. In this example, the process ID is 12345. Then, the daemon opens a specified database and accepts operations to that database. |
| 236 |
|
| 237 |
Execution example:: |
| 238 |
|
| 239 |
% groonga -d /tmp/groonga-databases/introduction.db |
| 240 |
12345 |
| 241 |
% |
| 242 |
|
| 243 |
How to run a GQTP client |
| 244 |
^^^^^^^^^^^^^^^^^^^^^^^^ |
| 245 |
|
| 246 |
You can run Groonga as a GQTP client as follows: |
| 247 |
|
| 248 |
Form:: |
| 249 |
|
| 250 |
groonga [-p PORT_NUMBER] -c [HOST_NAME_OR_IP_ADDRESS] |
| 251 |
|
| 252 |
This command establishes a connection with a GQTP server and then enters into interactive mode. HOST_NAME_OR_IP_ADDRESS specifies the hostname or the IP address of the server. If not specified, Groonga uses the default hostname "localhost". The `-p` option and its argument, PORT_NUMBER, specify the port number of the server. If not specified, Groonga uses the default port number 10043. |
| 253 |
|
| 254 |
.. groonga-command |
| 255 |
.. database: spec_gqtp |
| 256 |
.. include:: ../example/spec/gqtp/client.log |
| 257 |
.. .. $ groonga -c |
| 258 |
.. status |
| 259 |
.. .. > ctrl-d |
| 260 |
.. .. $ |
| 261 |
|
| 262 |
In interactive mode, Groonga reads commands from the standard input and executes them one by one. |
| 263 |
|
| 264 |
How to terminate a GQTP server |
| 265 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 266 |
|
| 267 |
You can terminate a GQTP server with a :doc:`/reference/commands/shutdown` command:: |
| 268 |
|
| 269 |
$ groonga -c |
| 270 |
> shutdown |
| 271 |
$ |
| 272 |
|
| 273 |
See also |
| 274 |
-------- |
| 275 |
|
| 276 |
* :doc:`/reference/executables/groonga` |
| 277 |
* :doc:`/server/gqtp` |