Commit Graph

7458 Commits

Author SHA1 Message Date
Randall Hauch
096ea24000 DBZ-37 Upgraded the BinlogClient library from 0.2.4 to 0.3.1, which is the latest 2016-06-02 17:08:46 -05:00
Randall Hauch
40663cb595 Merge pull request #54 from rhauch/dbz-64
DBZ-64 Added Avro Converter to record verification utilities
2016-06-02 17:00:11 -05:00
Randall Hauch
264a9041df DBZ-64 Added Avro Converter to record verification utilities
The `VerifyRecord` utility class has methods that will verify a `SourceRecord`, and is used in many of our integration tests to check whether records are constructed in a valid manner. The utility already checks whether the records can be serialized and deserialized using the JSON converter (provided with Kafka Connect); this change also checks with the Avro Converter (which produces much smaller records and is more suitable for production).

Note that version 3.0.0 of the Confluent Avro Converter is required; version 2.1.0-alpha1 could not properly handle complex Schema objects with optional fields (see https://github.com/confluentinc/schema-registry/pull/280).

Also, the names of the Kafka Connect schemas used in MySQL source records has changed.

# The record's envelope Schema used to be "<serverName>.<database>.<table>" but is now "<serverName>.<database>.<table>.Envelope".
# The Schema for record keys used to be named "<database>.<table>/pk", but the '/' character is not valid within a Avro name, and has been changed to "<serverName>.<database>.<table>.Key".
# The Schema for record values used to be named "<database>.<table>", but to better fit with the other Schema names it has been changed to "<serverName>.<database>.<table>.Value".

Thus, all of the Schemas for a single database table have the same Avro namespace "<serverName>.<database>.<table>" (or "<topicName>") with Avro schema names of "Envelope", "Key", and "Value".

All unit and integration tests pass.
2016-06-02 16:54:21 -05:00
Randall Hauch
a25d380214 Merge pull request #53 from rhauch/dbz-58
DBZ-58 Added MDC logging contexts to connector
2016-06-02 14:52:41 -05:00
Randall Hauch
46c0ce9882 DBZ-58 Added MDC logging contexts to connector
Changed the MySQL connector to make use of MDC logging contexts, which allow thread-specific parameters that can be written out on every log line by simply changing the logging configuration (e.g., Log4J configuration file).

We adopt a convention for all Debezium connectors with the following MDC properties:

* `dbz.connectorType` - the type of connector, which would be a single well-known value for each connector (e.g., "MySQL" for the MySQL connector)
* `dbz.connectorName` - the name of the connector, which for the MySQL connector is simply the value of the `server.name` property (e.g., the logical name for the MySQL server/cluster). Unfortunately, Kafka Connect does not give us its name for the connector.
* `dbz.connectorContext` - the name of the thread, which is "main" for thread running the connector; the MySQL connector uses "snapshot" for the thread started by the snapshot reader, and "binlog" for the thread started by the binlog reader.

Different logging frameworks have their own way of using MDC properties. In a Log4J configuration, for example, simply use `%X{name}` in the logger's layout, where "name" is one of the properties listed above (or another MDC property).
2016-06-02 14:05:06 -05:00
Randall Hauch
1eb1ccfa9d Merge pull request #52 from rhauch/dbz-31
DBZ-31 MySQL connector can now start with a consistent snapshot
2016-06-02 11:14:52 -05:00
Randall Hauch
aca863c225 DBZ-31 Write MySQL schema changes to topic by default 2016-06-02 11:00:04 -05:00
Randall Hauch
58a5d8c033 DBZ-31 Added support for possibly performing snapshot upon startup
Refactored the MySQL connector to break out the logic of reading the binlog into a separate class, added a similar class to read a full snapshot, and then updated the MySQL connector task class to use both. Added several test cases and updated the existing tests.
2016-06-01 21:40:53 -05:00
Randall Hauch
e6c0ff5e4d DBZ-31 Refactored the MySQL Connector
Several of the MySQL connector classes were fairly large and complicated, and to prepare for upcoming changes/enhancements these larger classes were refactored to pull out units of functionality. Currently all unit tests pass with these changes, with additional unit tests for these new components.
2016-05-26 15:58:58 -05:00
Randall Hauch
24e99fb28f DBZ-31 DDL parser now supports '#' as comment line prefix 2016-05-26 15:40:50 -05:00
Randall Hauch
048a8839ad Merge pull request #51 from DataPipelineInc/FixAvroSchemaParseExceptionIllegalcharacterInServerId
DBZ-63 Fix POM dependency management.
2016-05-25 09:51:05 -05:00
David Chen
339f03859c DBZ-63 Fix POM dependency management.
Thanks for the reminding from https://issues.jboss.org/browse/DBZ-63\?focusedCommentId\=13242595\&page\=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel\#comment-13242595
2016-05-25 15:21:45 +01:00
Randall Hauch
c1a098552a Merge pull request #50 from DataPipelineInc/FixAvroSchemaParseExceptionIllegalcharacterInServerId
DBZ-63 Rename "server-id" to "server_id" to fix org.apache.avro.SchemaParseE…
2016-05-25 08:44:05 -05:00
David Chen
b1a71318df DBZ-63 Rename "server-id" to "server_id" to fix org.apache.avro.SchemaParseException: Illegal character in: server-id 2016-05-25 14:33:20 +01:00
Randall Hauch
57e6c73a7a Merge pull request #49 from rhauch/dbz-55
DBZ-55 Corrected filtering of DDL statements based upon affected database
2016-05-23 19:45:38 -05:00
Randall Hauch
dc5a379764 DBZ-55 Corrected filtering of DDL statements based upon affected database
Previously, the DDL statements were being filtered and recorded based upon the name of the database that appeared in the binlog. However, that database name is actually the name of the database to which the client submitting the operation is connected, and is not necessarily the database _affected_ by the operation (e.g., when an operation includes a fully-qualified table name not in the connected-to database).

With these changes, the table/database affected by the DDL statements is now being used to filter the recording of the statements. The order of the DDL statements is still maintained, but since each DDL statement can apply to a separate database the DDL statements are batched (in the same original order) based upon the affected database. For example, two statements affecting "db1" will get batched together into one schema change record, followed by one statement affecting "db2" as a second schema change record, followed by another statement affecting "db1" as a third schema record.

Meanwhile, this change does not affect how the database history records the changes: it still records them as submitted using a single record for each separate binlog event/position. This is much safer as each binlog event (with specific position) is written atomically to the history stream. Also, since the database history stream is what the connector uses upon recovery, the database history records are now written _after_ any schema change records to ensure that, upon recovery after failure, no schema change records are lost (and instead have at-least-once delivery guarantees).
2016-05-23 11:01:27 -05:00
Randall Hauch
4840650c41 Merge pull request #48 from rhauch/dbz-45
DBZ-45 Confirmed and tested support for 'before' and 'after' states in UPDATE events
2016-05-20 12:19:35 -05:00
Randall Hauch
bb40875b2b DBZ-45 Confirmed and tested support for 'before' and 'after' states in UPDATE events
Added integration test logic to verify that UPDATE events include both 'before' and 'after' states (previously added as part of DBZ-52), to verify that altering a table does not generate events for the rows in that table, and that the 'before' and 'after' states (read from the binlog) are always defined in terms of the _current_ table schema. IOW, no special logic is needed to handle a 'before' state that has different columns than defined in the current table's definition.
2016-05-20 12:06:06 -05:00
Randall Hauch
b6ca57c6c1 DBZ-45 Added proper support for FIRST and AFTER clauses in an ALTER TABLE column definition
Added support for properly handling an ALTER TABLE statement that adds columns AFTER another existing column.
2016-05-20 12:05:53 -05:00
Randall Hauch
0a4068a8c3 Merge pull request #47 from rhauch/dbz-60
DBZ-60 Added MySQL server ID and timestamp to event's source info
2016-05-20 10:51:37 -05:00
Randall Hauch
47a93b3ae1 DBZ-60 Added MySQL server ID and timestamp to event's source info
Added to the Debezium event message's `source` information the MySQL server ID for the cluster process that recorded the event and the MySQL timestamp at which the event was recorded.
2016-05-20 09:32:35 -05:00
Randall Hauch
a857fc919f Merge pull request #46 from rhauch/dbz-57
DBZ-57 Support CHARSET alias for CHARACTER SET
2016-05-20 08:43:12 -05:00
Randall Hauch
b3167cd264 DBZ-57 Added unit test to confirm that DDL parser supports multi-column primary keys 2016-05-20 08:33:39 -05:00
Randall Hauch
c20b49a8fc DBZ-57 Added support for the shortened CHARSET alias for CHARACTER SET in MySQL DDL statements
Added explicit support for handling `CHARSET` as an alias for `CHARACTER SET` in both tables and columns.  `CREATE DATABASE` and `ALTER DATABASE` statements can also specify character sets, but the DDL parser handles but does not explicitly parse them so no modification is needed for them. Several unit tests were added to confirm the behavior.
2016-05-20 08:23:50 -05:00
Randall Hauch
4f40cc8332 Merge pull request #39 from rhauch/dbz-43
DBZ-43 Changed form of schema change topic to use schemas
2016-05-19 17:20:04 -05:00
Randall Hauch
e06f5c596c DBZ-43 Added explicit checking and validation of Schemas and Structs in integration tests 2016-05-19 17:06:22 -05:00
Randall Hauch
07315f2b4b DBZ-43 Changed form of schema change topic to use schemas 2016-05-19 16:54:22 -05:00
Randall Hauch
6d66a0ed2d Merge pull request #45 from rhauch/dbz-52
DBZ-52 Added top-level container structure to all messages
2016-05-19 14:28:50 -05:00
Randall Hauch
c0b7114424 DBZ-52 Added top-level container structure to all messages
The new envelope Struct contains fields for the local time at which the connector processed the event, the kind of operation (e.g., read, insert, update, or delete), the state of the record before and after the change, and the information about the event source. The latter two items are connector-specific. The timestamp is merely the time using the connector's process clock, and no guarantees are provided about accuracy, monotonicity, or relationship to the original source event.

The envelope structure is now used as the value for each event message in the MySQL connector; they keys of the event messages remain unchanged. Note that to facilitate Kafka log compaction (which requires a null value), a delete event containing the envelope with details about the deletion is followed by a "tombstone" event that contains the same key but null value.

An example of a message value with this new envelope is as follows:

{
    "schema" : {
      "type" : "struct",
      "fields" : [ {
        "type" : "struct",
        "fields" : [ {
          "type" : "int32",
          "optional" : false,
          "name" : "org.apache.kafka.connect.data.Date",
          "version" : 1,
          "field" : "order_date"
        }, {
          "type" : "int32",
          "optional" : false,
          "field" : "purchaser"
        }, {
          "type" : "int32",
          "optional" : false,
          "field" : "quantity"
        }, {
          "type" : "int32",
          "optional" : false,
          "field" : "product_id"
        } ],
        "optional" : true,
        "name" : "connector_test.orders",
        "field" : "before"
      }, {
        "type" : "struct",
        "fields" : [ {
          "type" : "int32",
          "optional" : false,
          "name" : "org.apache.kafka.connect.data.Date",
          "version" : 1,
          "field" : "order_date"
        }, {
          "type" : "int32",
          "optional" : false,
          "field" : "purchaser"
        }, {
          "type" : "int32",
          "optional" : false,
          "field" : "quantity"
        }, {
          "type" : "int32",
          "optional" : false,
          "field" : "product_id"
        } ],
        "optional" : true,
        "name" : "connector_test.orders",
        "field" : "after"
      }, {
        "type" : "struct",
        "fields" : [ {
          "type" : "string",
          "optional" : false,
          "field" : "server"
        }, {
          "type" : "string",
          "optional" : false,
          "field" : "file"
        }, {
          "type" : "int64",
          "optional" : false,
          "field" : "pos"
        }, {
          "type" : "int32",
          "optional" : false,
          "field" : "row"
        } ],
        "optional" : false,
        "name" : "io.debezium.connector.mysql.Source",
        "field" : "source"
      }, {
        "type" : "string",
        "optional" : false,
        "field" : "op"
      }, {
        "type" : "int64",
        "optional" : true,
        "field" : "ts"
      } ],
      "optional" : false,
      "name" : "kafka-connect-2.connector_test.orders",
      "version" : 1
    },
    "payload" : {
      "before" : null,
      "after" : {
        "order_date" : 16852,
        "purchaser" : 1003,
        "quantity" : 1,
        "product_id" : 107
      },
      "source" : {
        "server" : "kafka-connect-2",
        "file" : "mysql-bin.000002",
        "pos" : 2887680,
        "row" : 4
      },
      "op" : "c",
      "ts" : 1463437199134
    }
}

Notice how the Schema is significantly larger, since it must describe all of the envelope's fields even when those fields are not used. In this case, the event signifies that a record was created as the 4th record of a single event recorded in the binlog.
2016-05-19 12:40:16 -05:00
Randall Hauch
69ec112a17 Merge pull request #43 from rhauch/dbz-44
DBZ-44 Generate a tombstone for old key when row's key is changed
2016-05-13 17:51:48 -05:00
Randall Hauch
e6710a5300 DBZ-44 Generate a tombstone for old key when row's key is change
When a row is updated in the database and the primary/unique key for that table is changed, the MySQL connector continues to generate an update event with the new key and new value, but now also generates a tombstone event for the old key. This ensures that when a Kafka topic is compacted, all prior events with the old key will (eventually) be removed. It also ensures that consumers see that the row represented by the old key has been removed.
2016-05-13 17:43:29 -05:00
Randall Hauch
7c296b83d5 Merge pull request #42 from rhauch/dbz-49
DBZ-49 MySQL DDL parser should be more tolerant of REFERENCE clauses in CREATE TABLE statements
2016-05-13 09:38:46 -05:00
Randall Hauch
97d5caa2db DBZ-49 MySQL DDL parser is more tolerant of REFERENCE clauses in CREATE TABLE statements
MySQL 5.6 using the MyISAM engine will create the `help_relation` system table using a CREATE TABLE statement that does not have in the columns' REFERENCE clause a list of columns in the referenced table. MySQL 5.7 using the InnoDB engine does not include the REFERENCE clauses.

Because Debezium's MySQL DDL parser is meant only to understand the statements recorded in the binlog, it does not have to validate the statements and therefore the DDL parser can be a bit more lenient by not requiring the list of columns in a REFERENCE clause in a CREATE TABLE statement's column definitions.

This commit also adds several unit tests that validate all of the DDL statements used by MySQL 5.6 and 5.7 during startup (in the configurations used in our integration tests).
2016-05-13 09:32:47 -05:00
Randall Hauch
83967e0e53 Merge pull request #41 from rhauch/dbz-50
DBZ-50 Added parameters for length, maxLength and whether the field is masked
2016-05-12 16:55:37 -05:00
Randall Hauch
6d56a8f3d0 DBZ-50 Added parameters for truncated length and when the field is masked. 2016-05-12 16:31:33 -05:00
Randall Hauch
7ce096adaa Merge pull request #40 from rhauch/dbz-29b
DBZ-29 Refactored ColumnMappers
2016-05-12 12:59:33 -05:00
Randall Hauch
b1e6eb1028 DBZ-29 Refactored ColumnMappers and enabled ColumnMapper impls to add parameters to the Kafka Connect Schema. 2016-05-12 12:26:04 -05:00
Randall Hauch
18995abfbd Merge pull request #38 from rhauch/dbz-29
DBZ-29 Changed MySQL connector to be able to hide, truncate, and mask specific columns
2016-05-12 08:27:15 -05:00
Randall Hauch
ff9d0fc240 DBZ-29 Changed MySQL connector to be able to hide, truncate, and mask specific columns
Changed the MySQL connector to use comma-separated lists of regular expressions for the database
and table whitelist/blacklists. Literals are still accepted and will match fully-qualified table names,
although the '.' character used as a delimiter is also a special character in regular expressions and
therefore may need to be escaped with a double backslash ('\\') to more carefully match fully-qualified
table names.

Added several new configuration properties for the MySQL connector that instruct it to hide,
truncate, and/or mask certain columns. The properties' values are all lists of regular expressions
or literal fully-qualified column names. For example, the following configuration property:

    column.blacklist=server.users.picture,server.users.other

will cause the connector to leave out of change event messages for the `server.users` table those
fields that correspond to the `picture` and `others` columns. This capability can be used to
This capability can be used to prevent dissemination of sensitive information in the change event
stream.

An alternative to blacklisting is masking. The following configuration property:

    column.mask.with.10.chars=server\\.users\\.(\\w*email)

will cause the connector to mask in the change event messages for the `server.users` table
all values for columns whose name ends in `email`. The values will be replaced in this case with
a constant string of 10 asterisk ('*') characters, even when the email value is null.
This capability can also be used to prevent dissemination of sensitive information in the change event
stream.

Another option is to truncate string values for specific columns. The following configuration
property:

    column.truncate.to.120.chars=server[.]users[.](description|biography)

will cause the connector to truncate to at most 120 characters the values of the `description` and
`biography` columns in the change event messages for the `server.users` table. Although this example
used a limit of 120 characters, any positive length can be specified; separate properties should
be used when different lengths are required. Note how the '.' delimiter in the fully-qualified names
is escaped since that same character is a special character in regular expressions. This capability
can be used to reduce the size of change event messages.
2016-05-11 15:57:06 -05:00
Randall Hauch
5c83d40187 Merge pull request #37 from christian-posta/ceposta-commit-parse-errors
DBZ-48 Cannot parse COMMIT and flush statements
2016-05-06 01:41:02 +02:00
Christian Posta
8b736ef654 DBZ-48 Cannot parse COMMIT and flush statements 2016-05-05 15:36:24 -07:00
Randall Hauch
56cb15cb3f Merge pull request #36 from christian-posta/hack-it
DBZ-42 Use custom mysql images with custom config and startup scripts for integration tests
2016-04-26 17:14:30 -05:00
Christian Posta
ab2cdce279 DBZ-42 inherit from mysql images and add the custom config and startup scripts useful for integration testing 2016-04-26 08:49:27 -07:00
Randall Hauch
cfc795cd75 Merge pull request #34 from rhauch/dbz-38
DBZ-38 Changed the listening framework of the DDL parser
2016-04-13 07:28:47 -05:00
Randall Hauch
1fcb4b02cf DBZ-38 Changed DROP VIEW and TABLE to include single-table statements in events
Drop table/view statements that involve more than one table generate one event for each table/view. Previously, each of those statements had the original multi-table/view statement. Now, each event has a statement that applies to only that table (generated from the original with all the same clauses).
2016-04-12 18:18:13 -05:00
Randall Hauch
b1e428c986 DBZ-38 Adjusted how events are generated for RENAME TO statements
The previous change did not correctly capture the statements for a `RENAME TO` that renamed multiple tables, so fixed the code so that it generates a single `RENAME TO` for each table rename.
2016-04-12 17:58:07 -05:00
David Chen
eeff81b65d MySqlDdlParser should support "RENAME TABLE blue_table TO red_table, orange_table TO green_table, black_table TO white_table;" form. (#1) 2016-04-12 17:40:00 -05:00
Randall Hauch
5b30568650 DBZ-38 Changed the listening framework of the DDL parser
Refactored the mechanism by which components can listen to the activities of a DDL parser. The new approach
should be significantly more flexible for additional types of DDL events while making it easier to maintain
backward compatibility. It also will enable passing event-specific information on each DDL event.
2016-04-12 11:00:02 -05:00
Randall Hauch
75955945ee Merge pull request #33 from rhauch/dbz-38
DBZ-38 Changed the DDL parser framework to notify listeners as statements are applied
2016-04-11 15:44:39 -05:00
Randall Hauch
137b9f6d4d DBZ-38 Changed the DDL parser framework to notify listeners as statements are applied. 2016-04-11 15:16:04 -05:00