File: gqtp.rst

package info (click to toggle)
groonga 15.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 163,080 kB
  • sloc: ansic: 770,564; cpp: 48,925; ruby: 40,447; javascript: 10,250; yacc: 7,045; sh: 5,602; python: 2,821; makefile: 1,672
file content (277 lines) | stat: -rw-r--r-- 8,950 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
.. -*- rst -*-

GQTP
====

GQTP is the acronym of Groonga Query Transfer Protocol. GQTP is the
original protocol for groonga.

Protocol
--------

GQTP is stateful client server model protocol. The following sequence
is one processing unit:

* Client sends a request
* Server receives the request
* Server processes the request
* Server sends a response
* Client receives the response

You can do zero or more processing units in a session.

Both request and response consist of GQTP header and body. GQTP header
is fixed size data. Body is variable size data and its size is stored
in GQTP header. The content of body isn't defined in GQTP.

.. _gqtp-header-spec:

GQTP header
^^^^^^^^^^^

GQTP header consists of the following unsigned integer values:

+----------------+-------+----------------------------+
|      Name      |  Size |        Description         |
+================+=======+============================+
|  ``protocol``  | 1byte | Protocol type.             |
+----------------+-------+----------------------------+
| ``query_type`` | 1byte | Content type of body.      |
+----------------+-------+----------------------------+
| ``key_length`` | 2byte | Not used.                  |
+----------------+-------+----------------------------+
|   ``level``    | 1byte | Not used.                  |
+----------------+-------+----------------------------+
|   ``flags``    | 1byte | Flags.                     |
+----------------+-------+----------------------------+
|   ``status``   | 2byte | Return code.               |
+----------------+-------+----------------------------+
|    ``size``    | 4byte | Body size.                 |
+----------------+-------+----------------------------+
|   ``opaque``   | 4byte | Not used.                  |
+----------------+-------+----------------------------+
|    ``cas``     | 8byte | Not used.                  |
+----------------+-------+----------------------------+

All header values are encoded by network byte order.

The following sections describes available values of each header value.

The total size of GQTP header is 24byte.

``protocol``
""""""""""""

The value is always ``0xc7`` in both request and response GQTP header.

``query_type``
""""""""""""""

The value is one of the following values:

+-------------+--------+----------------------------+
|    Name     | Value  |        Description         |
+=============+========+============================+
|  ``NONE``   |   0    | Free format.               |
+-------------+--------+----------------------------+
|   ``TSV``   |   1    | Tab Separated Values.      |
+-------------+--------+----------------------------+
|  ``JSON``   |   2    | JSON.                      |
+-------------+--------+----------------------------+
|   ``XML``   |   3    | XML.                       |
+-------------+--------+----------------------------+
| ``MSGPACK`` |   4    | MessagePack.               |
+-------------+--------+----------------------------+

This is not used in request GQTP header.

This is used in response GQTP header. Body is formatted as specified
type.

``flags``
"""""""""

The value is bitwise OR of the following values:

+-----------+--------+----------------------------+
|   Name    | Value  |        Description         |
+===========+========+============================+
| ``MORE``  |  0x01  | There are more data.       |
+-----------+--------+----------------------------+
| ``TAIL``  |  0x02  | There are no more data.    |
+-----------+--------+----------------------------+
| ``HEAD``  |  0x04  | Not used.                  |
+-----------+--------+----------------------------+
| ``QUIET`` |  0x08  | Be quiet.                  |
+-----------+--------+----------------------------+
| ``QUIT``  |  0x10  | Quit.                      |
+-----------+--------+----------------------------+

You must specify ``MORE`` or ``TAIL`` flag.

If you use ``MORE`` flag, you should also use ``QUIET`` flag. Because
you don't need to show a response for your partial request.

Use ``QUIT`` flag to quit this session.

``status``
""""""""""

Here are available values. The new statuses will be added in the
future.

* 0: ``SUCCESS``
* 1: ``END_OF_DATA``
* 65535: ``UNKNOWN_ERROR``
* 65534: ``OPERATION_NOT_PERMITTED``
* 65533: ``NO_SUCH_FILE_OR_DIRECTORY``
* 65532: ``NO_SUCH_PROCESS``
* 65531: ``INTERRUPTED_FUNCTION_CALL``
* 65530: ``INPUT_OUTPUT_ERROR``
* 65529: ``NO_SUCH_DEVICE_OR_ADDRESS``
* 65528: ``ARG_LIST_TOO_LONG``
* 65527: ``EXEC_FORMAT_ERROR``
* 65526: ``BAD_FILE_DESCRIPTOR``
* 65525: ``NO_CHILD_PROCESSES``
* 65524: ``RESOURCE_TEMPORARILY_UNAVAILABLE``
* 65523: ``NOT_ENOUGH_SPACE``
* 65522: ``PERMISSION_DENIED``
* 65521: ``BAD_ADDRESS``
* 65520: ``RESOURCE_BUSY``
* 65519: ``FILE_EXISTS``
* 65518: ``IMPROPER_LINK``
* 65517: ``NO_SUCH_DEVICE``
* 65516: ``NOT_A_DIRECTORY``
* 65515: ``IS_A_DIRECTORY``
* 65514: ``INVALID_ARGUMENT``
* 65513: ``TOO_MANY_OPEN_FILES_IN_SYSTEM``
* 65512: ``TOO_MANY_OPEN_FILES``
* 65511: ``INAPPROPRIATE_I_O_CONTROL_OPERATION``
* 65510: ``FILE_TOO_LARGE``
* 65509: ``NO_SPACE_LEFT_ON_DEVICE``
* 65508: ``INVALID_SEEK``
* 65507: ``READ_ONLY_FILE_SYSTEM``
* 65506: ``TOO_MANY_LINKS``
* 65505: ``BROKEN_PIPE``
* 65504: ``DOMAIN_ERROR``
* 65503: ``RESULT_TOO_LARGE``
* 65502: ``RESOURCE_DEADLOCK_AVOIDED``
* 65501: ``NO_MEMORY_AVAILABLE``
* 65500: ``FILENAME_TOO_LONG``
* 65499: ``NO_LOCKS_AVAILABLE``
* 65498: ``FUNCTION_NOT_IMPLEMENTED``
* 65497: ``DIRECTORY_NOT_EMPTY``
* 65496: ``ILLEGAL_BYTE_SEQUENCE``
* 65495: ``SOCKET_NOT_INITIALIZED``
* 65494: ``OPERATION_WOULD_BLOCK``
* 65493: ``ADDRESS_IS_NOT_AVAILABLE``
* 65492: ``NETWORK_IS_DOWN``
* 65491: ``NO_BUFFER``
* 65490: ``SOCKET_IS_ALREADY_CONNECTED``
* 65489: ``SOCKET_IS_NOT_CONNECTED``
* 65488: ``SOCKET_IS_ALREADY_SHUTDOWNED``
* 65487: ``OPERATION_TIMEOUT``
* 65486: ``CONNECTION_REFUSED``
* 65485: ``RANGE_ERROR``
* 65484: ``TOKENIZER_ERROR``
* 65483: ``FILE_CORRUPT``
* 65482: ``INVALID_FORMAT``
* 65481: ``OBJECT_CORRUPT``
* 65480: ``TOO_MANY_SYMBOLIC_LINKS``
* 65479: ``NOT_SOCKET``
* 65478: ``OPERATION_NOT_SUPPORTED``
* 65477: ``ADDRESS_IS_IN_USE``
* 65476: ``ZLIB_ERROR``
* 65475: ``LZO_ERROR``
* 65474: ``STACK_OVER_FLOW``
* 65473: ``SYNTAX_ERROR``
* 65472: ``RETRY_MAX``
* 65471: ``INCOMPATIBLE_FILE_FORMAT``
* 65470: ``UPDATE_NOT_ALLOWED``
* 65469: ``TOO_SMALL_OFFSET``
* 65468: ``TOO_LARGE_OFFSET``
* 65467: ``TOO_SMALL_LIMIT``
* 65466: ``CAS_ERROR``
* 65465: ``UNSUPPORTED_COMMAND_VERSION``

``size``
""""""""

The size of body. The maximum body size is 4GiB because ``size`` is
4byte unsigned integer. If you want to send 4GiB or more larger data,
use ``MORE`` flag.

Example
-------

How to run a GQTP server
^^^^^^^^^^^^^^^^^^^^^^^^

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.

Form::

  groonga [-p PORT_NUMBER] -s DB_PATH

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.

The following command runs a server that listens on the default port number. The server accepts operations to the specified database.

Execution example::

  % groonga -s /tmp/groonga-databases/introduction.db
  Ctrl-c
  %

How to run a GQTP daemon
^^^^^^^^^^^^^^^^^^^^^^^^

You can also run a GQTP server as a daemon by using the `-d` option, instead of the `-s` option.

Form::

  groonga [-p PORT_NUMBER] -d DB_PATH

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.

Execution example::

  % groonga -d /tmp/groonga-databases/introduction.db
  12345
  %

How to run a GQTP client
^^^^^^^^^^^^^^^^^^^^^^^^

You can run Groonga as a GQTP client as follows:

Form::

  groonga [-p PORT_NUMBER] -c [HOST_NAME_OR_IP_ADDRESS]

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.

.. groonga-command
.. database: spec_gqtp
.. include:: ../example/spec/gqtp/client.log
.. .. $ groonga -c
.. status
.. .. > ctrl-d
.. .. $

In interactive mode, Groonga reads commands from the standard input and executes them one by one.

How to terminate a GQTP server
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

You can terminate a GQTP server with a :doc:`/reference/commands/shutdown` command::

  $ groonga -c
  > shutdown
  $

See also
--------

* :doc:`/reference/executables/groonga`
* :doc:`/server/gqtp`