File: mysqlx.proto

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (388 lines) | stat: -rw-r--r-- 11,880 bytes parent folder | download
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/*
 * Copyright (c) 2015, 2025, Oracle and/or its affiliates.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License, version 2.0,
 * as published by the Free Software Foundation.
 *
 * This program is designed to work with certain software (including
 * but not limited to OpenSSL) that is licensed under separate terms,
 * as designated in a particular file or component or in included license
 * documentation.  The authors of MySQL hereby grant you an additional
 * permission to link the program and your derivative works with the
 * separately licensed software that they have either included with
 * the program or referenced in the documentation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License, version 2.0, for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 */

/** @page mysqlx_protocol_messages Messages
Topics in this section:

-  @ref messages_Message_Structure
-  @ref messages_Message_Sequence
-  @ref messages_Common_Messages
-  @ref Mysqlx::Connection "Connection"
-  @ref Mysqlx::Session "Session"
-  @ref Mysqlx::Expect "Expectations"
-  @ref Mysqlx::Crud "CRUD"
-  @ref Mysqlx::Sql "SQL"
-  @ref Mysqlx::Resultset "Resultset"
-  @ref Mysqlx::Expr "Expressions
-  @ref Mysqlx::Datatypes "Datatypes"
-  @ref Mysqlx::Notice "Notice"
-  @ref Mysqlx::Prepare "Prepared statments"
-  @ref Mysqlx::Cursor "Cursor"


This section provides detailed information about how X %Protocol
defines messages.

@section messages_Message_Structure Message Structure

Messages have a:
-  4 byte *length* (little endian)
-  1 byte *message type*
-  a ``message_payload`` of length ``.length - 1``

@par Mysqlx.Message
    Container of all messages that are exchanged between client and server.
    @n@b Parameters
-  ``length`` -- length of the whole message
-  ``message_type`` -- type of the ``message_payload``
-  ``message_payload`` -- the message's payload encoded using
   [`Google Protobuf`](https://code.google.com/p/protobuf/) if
   not otherwise noted.

@code{unparsed}
struct Message {
  uint32          length;
  uint8           message_type;
  opaque          message_payload[Message.length - 1];
};
@endcode

@note
    The ``message_payload`` is generated from the protobuf files using
    ``protoc``:
  @code{shell}
  $ protoc --cpp_out=protodir mysqlx*.proto
  @endcode
-  [``mysqlx.proto``]
-  [``mysqlx_connection.proto``]
-  [``mysqlx_session.proto``]
-  [``mysqlx_crud.proto``]
-  [``mysqlx_sql.proto``]
-  [``mysqlx_resultset.proto``]
-  [``mysqlx_expr.proto``]
-  [``mysqlx_datatypes.proto``]
-  [``mysqlx_expect.proto``]
-  [``mysqlx_notice.proto``]

@par

@note
    The ``message_type`` can be taken from the
    @ref Mysqlx::ClientMessages for client-messages and from
    @ref Mysqlx::ServerMessages of server-side messages.
    @n In ``C++`` they are exposed in ``mysqlx.pb.h`` in the
    ``ClientMessages`` class.
    @code{unparsed}
    ClientMessages.MsgCase.kMsgConGetCap
    ClientMessages.kMsgConGetCapFieldNumber
    @endcode


@section messages_Message_Sequence Message Sequence

Messages usually appear in a sequence. Each initial message (one
referenced by @ref Mysqlx::ClientMessages) is
associated with a set of possible following messages.

A message sequence either:
-  finishes successfully if it reaches its end-state or
-  is aborted with a @ref Mysqlx::Error message

At any time in between local @ref Mysqlx::Notice "Notices"
may be sent by the server as part of the message sequence.

Global @ref Mysqlx::Notice "Notices" may be sent by the  server at any time.


@section messages_Common_Messages Common Messages

@subsection messages_Error_Message Error Message

After the client sent the initial message, the server may send a
@ref Mysqlx::Error message at any time to terminate the
current message sequence.
*/




// tell protobuf 3.0 to use protobuf 2.x rules
syntax = "proto2";

// ifdef PROTOBUF_LITE: option optimize_for = LITE_RUNTIME;

/**
@namespace Mysqlx
*/
package Mysqlx;
option java_package = "com.mysql.cj.x.protobuf";

import "google/protobuf/descriptor.proto"; // comment_out_if PROTOBUF_LITE

// style-guide:
//
// see https://developers.google.com/protocol-buffers/docs/style
//
// message CamelCaseMsg {
//   enum CamelCaseEnum {
//     FIRST_VALUE = 1;
//   }
//   required CamelCaseEnum some_enum = 1;
// }
//


/**
 IDs of messages that can be sent from client to the server.

 @note
   This message is never sent on the wire. It is only used to let ``protoc``:
   -  generate constants
   -  check for uniqueness
*/
message ClientMessages {
  enum Type {
    CON_CAPABILITIES_GET = 1;
    CON_CAPABILITIES_SET = 2;
    CON_CLOSE = 3;

    SESS_AUTHENTICATE_START = 4;
    SESS_AUTHENTICATE_CONTINUE  = 5;
    SESS_RESET = 6;
    SESS_CLOSE = 7;

    SQL_STMT_EXECUTE = 12;

    CRUD_FIND = 17;
    CRUD_INSERT = 18;
    CRUD_UPDATE = 19;
    CRUD_DELETE = 20;

    EXPECT_OPEN = 24;
    EXPECT_CLOSE = 25;

    CRUD_CREATE_VIEW = 30;
    CRUD_MODIFY_VIEW = 31;
    CRUD_DROP_VIEW = 32;

    PREPARE_PREPARE = 40;
    PREPARE_EXECUTE = 41;
    PREPARE_DEALLOCATE = 42;

    CURSOR_OPEN = 43;
    CURSOR_CLOSE = 44;
    CURSOR_FETCH = 45;

    COMPRESSION = 46;
  }
}


/**
IDs of messages that can be sent from server to client.

@note
   This message is never sent on the wire. It is only used to let ``protoc``:
   -  generate constants
   -  check for uniqueness
*/
message ServerMessages {
  enum Type {
    OK = 0;
    ERROR = 1;

    CONN_CAPABILITIES = 2;

    SESS_AUTHENTICATE_CONTINUE = 3;
    SESS_AUTHENTICATE_OK = 4;

    // NOTICE has to stay at 11 forever
    NOTICE = 11;

    RESULTSET_COLUMN_META_DATA = 12;
    RESULTSET_ROW = 13;
    RESULTSET_FETCH_DONE = 14;
    RESULTSET_FETCH_SUSPENDED = 15;
    RESULTSET_FETCH_DONE_MORE_RESULTSETS = 16;

    SQL_STMT_EXECUTE_OK = 17;
    RESULTSET_FETCH_DONE_MORE_OUT_PARAMS = 18;

    COMPRESSION = 19;
  }
}
// ifndef PROTOBUF_LITE
extend google.protobuf.MessageOptions {
  optional ClientMessages.Type client_message_id = 100001;
  optional ServerMessages.Type server_message_id = 100002;
}
// endif

/**
Generic Ok message.
*/

message Ok {
  optional string msg = 1;

  option (server_message_id) = OK; // comment_out_if PROTOBUF_LITE
}


/**
Generic Error message.

A ``severity`` of ``ERROR`` indicates the current message
sequence is aborted for the given error and the session is ready
for more.

In case of a ``FATAL`` error message the client should not
expect the server to continue handling any further messages and
should close the connection.
*/

message Error {
  /** severity of the error message */
  optional Severity severity = 1 [ default = ERROR ];

  /** error code */
  required uint32 code = 2;

  /** SQL state */
  required string sql_state = 4;

  /** human-readable error message */
  required string msg = 3;

  enum Severity {
    ERROR = 0;
    FATAL = 1;
  }

  option (server_message_id) = ERROR; // comment_out_if PROTOBUF_LITE
}


/** @page mysqlx_community_connector How to build a Community Connector

MySQL provides a set of official MySQL Connectors for several popular
development frameworks and languages like Node.js, .Net, Python, Java, C,
C++ and more. At the same time, we also encourage community developers to
create native connectors for their favorite languages. To improve the process
and encourage creating a community connector going forward, and allow for more
rapid new feature support within the MySQL communications protocol, we created
a new protocol called the MySQL X Protocol.

The new X Protocol leverages current industry standards. One of those standards
in use is protobuf (more formally know as Google Protobuffers).
The .proto formatted files provide the complete message definitions of the
X Protocol. Another feature of protobuf is the automatic code generation based
on those .proto files across a variety of languages for use in community
developed connectors for MySQL.

These language specific generated files can be used with no restrictions under
your own terms.

The X Protocol use of .proto makes our protocol design clear and concise,
no longer requiring the efforts previously required – no longer will you need
to directly analyze our message format. In addition to the layout of
the message format, the .proto also defines and documents message sequence
and flow between the connectors and the MySQL server. The information defined
in the .proto file makes it easy to implement X protocol support in connector
code. As those who have written a MySQL connector know, coding the protocol
is only a small part of the effort required.

Finally, you can focus on the big task of creating a MySQL community
connector - designing apis, coding, testing, selecting your license, packaging,
documentation. And, promoting and speaking about your work.

@section xprotocol_mysqlxshell_example X Protocol example

The following figure shows usage of the X %Protocol between MYSQLXSHELL and
MySQL Server 5.7.12 or higher with the X %Plugin enabled.
The object _X %Protocol_ on this figure represents rather some concept
than an implementation object. The aim is to show its role in the process
of information exchange between the client and the server.

@startuml "X Protocol Overview"
actor "User"
box "MySQLx Shell"
participant "X DevAPI" as devapi
participant "X Protocol" as xclproto
end box

box "MySQL Server"
participant "X Plugin" as xpl
participant "X Protocol" as xplproto
participant "Server" as serv
end box

User -> devapi: Request
activate devapi
devapi -> xclproto: Encode request
activate xclproto

xclproto --> devapi
deactivate xclproto

devapi -> xpl: Receive request << Network (TCP) >>
activate xpl

xpl -> xplproto: Decode request
activate xplproto

xplproto --> xpl
deactivate xplproto

xpl -> serv: Execute request
activate serv

serv --> xpl
deactivate serv

xpl --> devapi: << Network (TCP) >>
deactivate xpl

devapi --> User
deactivate devapi
...
@enduml

The documentation is based on the source files such as:

-  [``mysqlx.proto``](https://github.com/mysql/mysql-server/tree/8.0/plugin/x/protocol/protobuf/mysqlx.proto)
-  [``mysqlx_connection.proto``](https://github.com/mysql/mysql-server/tree/8.0/plugin/x/protocol/protobuf/mysqlx_connection.proto)
-  [``mysqlx_session.proto``](https://github.com/mysql/mysql-server/tree/8.0/plugin/x/protocol/protobuf/mysqlx_session.proto>)
-  [``mysqlx_crud.proto``](https://github.com/mysql/mysql-server/tree/8.0/plugin/x/protocol/protobuf/mysqlx_crud.proto>)
-  [``mysqlx_sql.proto``](https://github.com/mysql/mysql-server/tree/8.0/plugin/x/protocol/protobuf/mysqlx_sql.proto>)
-  [``mysqlx_resultset.proto``](https://github.com/mysql/mysql-server/tree/8.0/plugin/x/protocol/protobuf/mysqlx_resultset.proto>)
-  [``mysqlx_expr.proto``](https://github.com/mysql/mysql-server/tree/8.0/plugin/x/protocol/protobuf/mysqlx_expr.proto>)
-  [``mysqlx_datatypes.proto``](https://github.com/mysql/mysql-server/tree/8.0/plugin/x/protocol/protobuf/mysqlx_datatypes.proto>)
-  [``mysqlx_expect.proto``](https://github.com/mysql/mysql-server/tree/8.0/plugin/x/protocol/protobuf/mysqlx_expect.proto>)
-  [``mysqlx_notice.proto``](https://github.com/mysql/mysql-server/tree/8.0/plugin/x/protocol/protobuf/mysqlx_notice.proto>)
-  [``mysqlx_cursor.proto``](https://github.com/mysql/mysql-server/tree/8.0/plugin/x/protocol/protobuf/mysqlx_cursor.proto>)
-  [``mysqlx_prepare.proto``](https://github.com/mysql/mysql-server/tree/8.0/plugin/x/protocol/protobuf/mysqlx_prepare.proto>)

*/