vitess.io/vitess@v0.16.2/proto/binlogdata.proto (about) 1 /* 2 Copyright 2019 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 // This file contains all the types and servers necessary to make 18 // RPC calls to VtTablet for the binlog protocol, used by filtered 19 // replication only. 20 21 syntax = "proto3"; 22 option go_package = "vitess.io/vitess/go/vt/proto/binlogdata"; 23 24 package binlogdata; 25 26 import "vtrpc.proto"; 27 import "query.proto"; 28 import "topodata.proto"; 29 30 // Charset is the per-statement charset info from a QUERY_EVENT binlog entry. 31 message Charset { 32 // @@session.character_set_client 33 int32 client = 1; 34 // @@session.collation_connection 35 int32 conn = 2; 36 // @@session.collation_server 37 int32 server = 3; 38 } 39 40 // BinlogTransaction describes a transaction inside the binlogs. 41 // It is streamed by vttablet for filtered replication, used during resharding. 42 message BinlogTransaction { 43 message Statement { 44 enum Category { 45 BL_UNRECOGNIZED = 0; 46 BL_BEGIN = 1; 47 BL_COMMIT = 2; 48 BL_ROLLBACK = 3; 49 // BL_DML is deprecated. 50 BL_DML_DEPRECATED = 4; 51 BL_DDL = 5; 52 BL_SET = 6; 53 BL_INSERT = 7; 54 BL_UPDATE = 8; 55 BL_DELETE = 9; 56 } 57 58 // what type of statement is this? 59 Category category = 1; 60 61 // charset of this statement, if different from pre-negotiated default. 62 Charset charset = 2; 63 64 // the sql 65 bytes sql = 3; 66 } 67 68 // the statements in this transaction 69 repeated Statement statements = 1; 70 71 // DEPRECATED (replaced by event_token): the timestamp of the statements. 72 // int64 timestamp = 2; 73 reserved 2; 74 75 // DEPRECATED (replaced by event_token): the Transaction ID after 76 // this statement was applied. 77 // string transaction_id = 3; 78 reserved 3; 79 80 // The Event Token for this event. 81 query.EventToken event_token = 4; 82 } 83 84 // StreamKeyRangeRequest is the payload to StreamKeyRange 85 message StreamKeyRangeRequest { 86 // where to start 87 string position = 1; 88 89 // what to get 90 topodata.KeyRange key_range = 2; 91 92 // default charset on the player side 93 Charset charset = 3; 94 } 95 96 // StreamKeyRangeResponse is the response from StreamKeyRange 97 message StreamKeyRangeResponse{ 98 BinlogTransaction binlog_transaction = 1; 99 } 100 101 // StreamTablesRequest is the payload to StreamTables 102 message StreamTablesRequest { 103 // where to start 104 string position = 1; 105 106 // what to get 107 repeated string tables = 2; 108 109 // default charset on the player side 110 Charset charset = 3; 111 } 112 113 // StreamTablesResponse is the response from StreamTables 114 message StreamTablesResponse { 115 BinlogTransaction binlog_transaction = 1; 116 } 117 118 // CharsetConversion represent a conversion of text from one charset to another 119 message CharsetConversion { 120 // FromCharset is the charset name from which we convert the text (e.g. latin1) 121 string from_charset = 1; 122 // ToCharset is the charset name to which we convert the text (e.g. utf8mb4) 123 string to_charset = 2; 124 } 125 126 // Rule represents one rule in a Filter. 127 message Rule { 128 // Match can be a table name or a regular expression. 129 // If it starts with a '/', it's a regular expression. 130 // For example, "t" matches a table named "t", whereas 131 // "/t.*" matches all tables that begin with 't'. 132 string match = 1; 133 // Filter: If empty, all columns and rows of the matching tables 134 // are sent. If it's a keyrange like "-80", only rows that 135 // match the keyrange are sent. 136 // If Match is a table name instead of a regular expression, 137 // the Filter can also be a select expression like this: 138 // "select * from t", same as an empty Filter, or 139 // "select * from t where in_keyrange('-80')", same as "-80", or 140 // "select col1, col2 from t where in_keyrange(col1, 'hash', '-80'), or 141 // What is allowed in a select expression depends on whether 142 // it's a vstreamer or vreplication request. For more details, 143 // please refer to the specific package documentation. 144 // On the vreplication side, Filter can also accept a special 145 // "exclude" value, which will cause the matched tables 146 // to be excluded. 147 // TODO(sougou): support this on vstreamer side also. 148 string filter = 2; 149 // ConvertEnumToText: optional, list per enum column name, the list of textual values. 150 // When reading the binary log, all enum values are numeric. But sometimes it 151 // is useful/needed to know what the textual mapping are. 152 // Online DDL provides such use case. 153 154 // Example: key="color", value="'red','green','blue'" 155 map<string, string> convert_enum_to_text = 3; 156 157 // ConvertCharset: optional mapping, between column name and a CharsetConversion. 158 // This hints to vreplication that columns are encoded from/to non-trivial charsets 159 // The map is only populated when either "from" or "to" charset of a column are non-trivial 160 // trivial charsets are utf8 and ascii variants. 161 map<string, CharsetConversion> convert_charset = 4; 162 163 // SourceUniqueKeyColumns represents the ordered columns in the index used by rowstreamer to iterate the table 164 // It is comma delimited, as in col1,col2,col3 (tokens are escaped via net/url) 165 string source_unique_key_columns = 5; 166 167 // TargetUniqueKeyColumns represents the ordered columns in that index used by vcopier and vplayer to apply rows 168 // It is comma delimited, as in col1,col2,col3 (tokens are escaped via net/url) 169 string target_unique_key_columns = 6; 170 171 // SourceUniqueKeyTargetColumns represents the names of columns in target table, mapped from the chosen unique 172 // key on source tables (some columns may be renamed from source to target) 173 string source_unique_key_target_columns = 7; 174 175 // ConvertIntToEnum lists any columns that are converted from an integral value into an enum. 176 // such columns need to have special transofrmation of the data, from an integral format into a 177 // string format. e.g. the value 0 needs to be converted to '0'. 178 map<string, bool> convert_int_to_enum = 8; 179 } 180 181 // Filter represents a list of ordered rules. The first 182 // match wins. 183 message Filter { 184 repeated Rule rules = 1; 185 enum FieldEventMode { 186 ERR_ON_MISMATCH = 0; 187 BEST_EFFORT = 1; 188 } 189 // FieldEventMode specifies the behavior if there is a mismatch 190 // between the current schema and the fields in the binlog. This 191 // can happen if the binlog position is before a DDL that would 192 // cause the fields to change. If vstreamer detects such 193 // an inconsistency, the behavior depends on the FieldEventMode. 194 // If the value is ERR_ON_MISMATCH (default), then it errors out. 195 // If it's BEST_EFFORT, it sends a field event with fake column 196 // names as "@1", "@2", etc. 197 FieldEventMode field_event_mode = 2; 198 199 int64 workflow_type = 3; 200 string workflow_name = 4; 201 } 202 203 // OnDDLAction lists the possible actions for DDLs. 204 enum OnDDLAction { 205 IGNORE = 0; 206 STOP = 1; 207 EXEC = 2; 208 EXEC_IGNORE = 3; 209 } 210 211 // VReplicationWorkflowType define types of vreplication workflows. 212 enum VReplicationWorkflowType { 213 Materialize = 0; 214 MoveTables = 1; 215 CreateLookupIndex = 2; 216 Migrate = 3; 217 Reshard = 4; 218 OnlineDDL = 5; 219 } 220 221 // VReplicationWorkflowSubType define types of vreplication workflows. 222 enum VReplicationWorkflowSubType { 223 None = 0; 224 Partial = 1; 225 } 226 227 // BinlogSource specifies the source and filter parameters for 228 // Filtered Replication. KeyRange and Tables are legacy. Filter 229 // is the new way to specify the filtering rules. 230 message BinlogSource { 231 // the source keyspace 232 string keyspace = 1; 233 234 // the source shard 235 string shard = 2; 236 237 // the source tablet type 238 topodata.TabletType tablet_type = 3; 239 240 // KeyRange is set if the request is for a keyrange 241 topodata.KeyRange key_range = 4; 242 243 // Tables is set if the request is for a list of tables 244 repeated string tables = 5; 245 246 // Filter is set if we're using the generalized representation 247 // for the filter. 248 Filter filter = 6; 249 250 // OnDdl specifies the action to be taken when a DDL is encountered. 251 OnDDLAction on_ddl = 7; 252 253 // Source is an external mysql. This attribute should be set to the username 254 // to use in the connection 255 string external_mysql = 8; 256 257 // StopAfterCopy specifies if vreplication should be stopped 258 // after copying is done. 259 bool stop_after_copy = 9; 260 261 // ExternalCluster is the name of the mounted cluster which has the source keyspace/db for this workflow 262 // it is of the type <cluster_type.cluster_name> 263 string external_cluster = 10; 264 265 // SourceTimeZone is the time zone in which datetimes on the source were stored, provided as an option in MoveTables 266 string source_time_zone = 11; 267 // TargetTimeZone is not currently specifiable by the user, defaults to UTC for the forward workflows 268 // and to the SourceTimeZone in reverse workflows 269 string target_time_zone = 12; 270 } 271 272 // VEventType enumerates the event types. Many of these types 273 // will not be encountered in RBR mode. 274 enum VEventType { 275 UNKNOWN = 0; 276 GTID = 1; 277 BEGIN = 2; 278 COMMIT = 3; 279 ROLLBACK = 4; 280 DDL = 5; 281 // INSERT, REPLACE, UPDATE, DELETE and SET will not be seen in RBR mode. 282 INSERT = 6; 283 REPLACE = 7; 284 UPDATE = 8; 285 DELETE = 9; 286 SET = 10; 287 // OTHER is a dummy event. If encountered, the current GTID must be 288 // recorded by the client to be able to resume. 289 OTHER = 11; 290 ROW = 12; 291 FIELD = 13; 292 // HEARTBEAT is sent if there is inactivity. If a client does not 293 // receive events beyond the hearbeat interval, it can assume that it's 294 // lost connection to the vstreamer. 295 HEARTBEAT = 14; 296 // VGTID is generated by VTGate's VStream that combines multiple 297 // GTIDs. 298 VGTID = 15; 299 JOURNAL = 16; 300 VERSION = 17; 301 LASTPK = 18; 302 SAVEPOINT = 19; 303 // COPY_COMPLETED is sent when VTGate's VStream copy operation is done. 304 // If a client experiences some disruptions before receiving the event, 305 // the client should restart the copy operation. 306 COPY_COMPLETED = 20; 307 } 308 309 // RowChange represents one row change. 310 // If Before is set and not After, it's a delete. 311 // If After is set and not Before, it's an insert. 312 // If both are set, it's an update. 313 message RowChange { 314 query.Row before = 1; 315 query.Row after = 2; 316 } 317 318 // RowEvent represent row events for one table. 319 message RowEvent { 320 string table_name = 1; 321 repeated RowChange row_changes = 2; 322 string keyspace = 3; 323 string shard = 4; 324 } 325 326 // FieldEvent represents the field info for a table. 327 message FieldEvent { 328 string table_name = 1; 329 repeated query.Field fields = 2; 330 string keyspace = 3; 331 string shard = 4; 332 } 333 334 // ShardGtid contains the GTID position for one shard. 335 // It's used in a request for requesting a starting position. 336 // It's used in a response to transmit the current position 337 // of a shard. It's also used in a Journal to indicate the 338 // list of targets and shard positions to migrate to. 339 message ShardGtid { 340 string keyspace = 1; 341 string shard = 2; 342 string gtid = 3; 343 repeated TableLastPK table_p_ks = 4; 344 } 345 346 // A VGtid is a list of ShardGtids. 347 message VGtid { 348 repeated ShardGtid shard_gtids = 1; 349 } 350 351 // KeyspaceShard represents a keyspace and shard. 352 message KeyspaceShard { 353 string keyspace = 1; 354 string shard = 2; 355 } 356 357 // MigrationType specifies the type of migration for the Journal. 358 enum MigrationType { 359 TABLES = 0; 360 SHARDS = 1; 361 } 362 363 // Journal contains the metadata for a journal event. 364 // The commit of a journal event indicates the point of no return 365 // for a migration. 366 message Journal { 367 // Id represents a unique journal id. 368 int64 id = 1; 369 MigrationType migration_type = 2; 370 // Tables is set if the journal represents a TABLES migration. 371 repeated string tables = 3; 372 // LocalPosition is the source position at which the migration happened. 373 string local_position = 4; 374 // ShardGtids is the list of targets to which the migration took place. 375 repeated ShardGtid shard_gtids = 5; 376 // Participants is the list of source participants for a migration. 377 // Every participant is expected to have an identical journal entry. 378 // While streaming, the client must wait for the journal entry to 379 // be received from all pariticipants, and then replace them with new 380 // streams specified by ShardGtid. 381 // If a stream does not have all participants, a consistent migration 382 // is not possible. 383 repeated KeyspaceShard participants = 6; 384 // SourceWorkflows is the list of workflows in the source shard that 385 // were migrated to the target. If a migration fails after a Journal 386 // is committed, this information is used to start the target streams 387 // that were created prior to the creation of the journal. 388 repeated string source_workflows = 7; 389 } 390 391 // VEvent represents a vstream event. 392 // A FieldEvent is sent once for every table, just before 393 // the first event for that table. The client is expected 394 // to cache this information and match it against the RowEvent 395 // which contains the table name. 396 // A GTID event always precedes a commitable event, which can be 397 // COMMIT, DDL or OTHER. 398 // OTHER events are non-material events that have no additional metadata. 399 message VEvent { 400 VEventType type = 1; 401 // Timestamp is the binlog timestamp in seconds. 402 // The value should be ignored if 0. 403 int64 timestamp = 2; 404 // Gtid is set if the event type is GTID. 405 string gtid = 3; 406 // Statement is set if the event type is DDL, DML or SAVEPOINT. 407 string statement = 4; 408 // RowEvent is set if the event type is ROW. 409 RowEvent row_event = 5; 410 // FieldEvent is set if the event type is FIELD. 411 FieldEvent field_event = 6; 412 // Vgtid is set if the event type is VGTID. 413 // This event is only generated by VTGate's VStream function. 414 VGtid vgtid = 7; 415 // Journal is set if the event type is JOURNAL. 416 Journal journal = 8; 417 // Dml is set if the event type is INSERT, REPLACE, UPDATE or DELETE. 418 string dml = 9; 419 // CurrentTime specifies the current time when the message was sent. 420 // This can be used to compenssate for clock skew. 421 int64 current_time = 20; 422 // LastPK is the last PK for a table 423 LastPKEvent last_p_k_event = 21; 424 // the source keyspace 425 string keyspace = 22; 426 // the source shard 427 string shard = 23; 428 // indicate that we are being throttled right now 429 bool throttled = 24; 430 } 431 432 message MinimalTable { 433 string name = 1; 434 repeated query.Field fields = 2; 435 repeated int64 p_k_columns = 3; 436 } 437 438 message MinimalSchema { 439 repeated MinimalTable tables = 1; 440 } 441 442 // VStreamRequest is the payload for VStreamer 443 message VStreamRequest { 444 vtrpc.CallerID effective_caller_id = 1; 445 query.VTGateCallerID immediate_caller_id = 2; 446 query.Target target = 3; 447 448 string position = 4; 449 Filter filter = 5; 450 repeated TableLastPK table_last_p_ks = 6; 451 } 452 453 // VStreamResponse is the response from VStreamer 454 message VStreamResponse { 455 repeated VEvent events = 1; 456 } 457 458 // VStreamRowsRequest is the payload for VStreamRows 459 message VStreamRowsRequest { 460 vtrpc.CallerID effective_caller_id = 1; 461 query.VTGateCallerID immediate_caller_id = 2; 462 query.Target target = 3; 463 464 string query = 4; 465 query.QueryResult lastpk = 5; 466 } 467 468 // VStreamRowsResponse is the response from VStreamRows 469 message VStreamRowsResponse { 470 repeated query.Field fields = 1; 471 repeated query.Field pkfields = 2; 472 string gtid = 3; 473 repeated query.Row rows = 4; 474 query.Row lastpk = 5; 475 // Throttled indicates that rowstreamer is being throttled right now 476 bool throttled = 6; 477 // Heartbeat indicates that this is a heartbeat message 478 bool heartbeat = 7; 479 } 480 481 message LastPKEvent { 482 TableLastPK table_last_p_k = 1; 483 bool completed = 2; 484 } 485 486 message TableLastPK { 487 string table_name = 1; 488 query.QueryResult lastpk = 3; 489 } 490 491 // VStreamResultsRequest is the payload for VStreamResults 492 // The ids match VStreamRows, in case we decide to merge the two. 493 // The ids match VStreamRows, in case we decide to merge the two. 494 message VStreamResultsRequest { 495 vtrpc.CallerID effective_caller_id = 1; 496 query.VTGateCallerID immediate_caller_id = 2; 497 query.Target target = 3; 498 499 string query = 4; 500 } 501 502 // VStreamResultsResponse is the response from VStreamResults 503 // The ids match VStreamRows, in case we decide to merge the two. 504 message VStreamResultsResponse { 505 repeated query.Field fields = 1; 506 string gtid = 3; 507 repeated query.Row rows = 4; 508 }