Source Connectors

CockroachDB

qianmoQqianmoQ· 更新于 2026-09-23· 阅读 273 分钟· 0 次阅读

登录后可跨设备保存划线和私人笔记登录

Debezium connector for CockroachDB

Table of Contents

The Debezium CockroachDB connector captures row-level changes from a CockroachDB enriched changefeed and streams them into Kafka topics.

CockroachDB changefeeds detects data changes in the database — inserts, updates, and deletes — in near-real-time. The connector creates a changefeed that publishes events to an intermediate Kafka cluster, then consumes those events, transforms them into the standard Debezium envelope format, and produces them to the output Kafka topics that downstream consumers subscribe to.

The CockroachDB connector is an incubating connector. An incubating connector is one that has been released for preview purposes and is subject to changes that may not always be backward compatible.

Overview

CockroachDB is a distributed SQL database that provides strong consistency, horizontal scalability, and survivability. Unlike traditional databases that rely on a write-ahead log (WAL) for change data capture, CockroachDB provides a native changefeed mechanism that streams row-level changes directly from the storage layer.

The Debezium CockroachDB connector leverages this native changefeed capability. The connector produces a change event for every row-level insert, update, and delete operation that it captures and sends change event records for each table to a separate Kafka topic. Client applications read the Kafka topics that correspond to the database tables of interest and can react to each row-level event that they receive from those topics.

The connector is tolerant of failures. As the connector reads changes and produces events, it records the last resolved timestamp it processes. If the connector stops for any reason (including communication failures, network problems, or crashes), after the connector restarts, it resumes streaming from the last record that it processed.

How the connector works

To optimally configure and run a Debezium CockroachDB connector, it is helpful to understand how the connector performs snapshots, streams change events, determines Kafka topic names, and uses metadata.

Architecture

The CockroachDB connector uses a two-stage Kafka architecture:

  1. CockroachDB changefeed to Intermediate Kafka: The connector creates a single CockroachDB changefeed that uses the enriched envelope format for all configured tables (CREATE CHANGEFEED FOR table1, table2, …​) CockroachDB automatically routes events to per-table Kafka topics in the intermediate cluster. The enriched format includes both schema metadata and the full before and after row states.
  2. Intermediate Kafka to Debezium to Output Kafka: The connector subscribes to all per-table Kafka topics in a single KafkaConsumer; routes each event to the correct table based on the topic name; transforms the enriched changefeed events into the standard Debezium envelope format (with before, after, source, and op fields); and produces them to the final output Kafka topics.

By using this architecture the connector can leverage the native, highly-available changefeed infrastructure of CockroachDB to reliably capture data and provide it to downstream consumers in the standard Debezium event format. By default, the connector consolidates all configured tables into a single changefeed. By consolidating data in a single changefeed job, the connector conforms to the recommended limit on the number of changefeeds per CockroachDB cluster (approximately 80 at the time of writing). To improve throughput and prevent performance coupling, CockroachDB best practices advise against using a single changefeed to monitor a large number of tables. In environments with large table counts, consider setting cockroachdb.changefeed.max.tables.per.changefeed to split the tables across several changefeeds, or running multiple connector instances so that each connector captures a related subset of the tables.

Snapshots

CockroachDB changefeeds natively support an initial_scan option that backfills all existing rows before streaming ongoing changes. The Debezium CockroachDB connector maps its snapshot.mode configuration to the CockroachDB initial_scan changefeed option, so the connector does not require a separate JDBC-based snapshot phase.

During the initial scan phase, captured events are marked op=r to designate a read operation, which distinguishes snapshot events from ongoing change events. After the initial scan completes and the changefeed transitions to streaming, events are marked with the appropriate operation type (c for create, u for update, d for delete).

The following table shows how each snapshot.mode maps to the CockroachDB initial_scan option:

Snapshot modeinitial_scan valueDescription
initial (default)yes on first start, no on restartOn first start (no prior offset), the snapshot backfills all existing rows. On restart with an existing offset, streaming resumes from the stored cursor.
alwaysyesThe snapshot always backfills all existing rows, even on restart.
initial_onlyonlyThe snapshot backfills all existing rows, then the connector stops. Useful for one-time data migration.
no_data / nevernoSkips the initial scan entirely. Only ongoing changes after the changefeed is created are captured.
when_neededyes on first start, no on restartSame as initial, but if the stored offset is no longer valid, the connector performs a new initial snapshot.

Table 1. Snapshot mode to initial_scan mapping

Streaming changes

After an initial scan completes, the CockroachDB connector streams changes continuously. When a row-level change occurs in CockroachDB, the changefeed writes a corresponding event to the intermediate Kafka topic. The connector consumes these events, transforms them into Debezium change events, and forwards them to the output Kafka topics.

CockroachDB changefeeds emit resolved timestamp messages at a configurable interval. These messages indicate that all changes up to that timestamp have been emitted. The connector uses resolved timestamps for offset tracking, so that on restart it can create a new changefeed with a cursor pointing to the last resolved timestamp, ensuring that it does not miss any events.

When the connector receives changes it transforms the events into Debezium read, create, update, or delete event records. The connector forwards these change records to the Kafka Connect framework, which is running in the same process. The Kafka Connect process asynchronously writes the change event records in the same order in which they were generated to the appropriate Kafka topic.

Periodically, Kafka Connect writes the most recent offset to another Kafka topic. The offset indicates source-specific position information that Debezium includes with each event. For the CockroachDB connector, the last resolved timestamp is the offset.

When Kafka Connect gracefully shuts down, it stops the connectors, flushes all event records to Kafka, and records the last offset received from each connector. When Kafka Connect restarts, it reads the last recorded offset for each connector, and starts each connector at its last recorded offset.

Reusing an existing changefeed

By default, the connector creates and manages its own CockroachDB changefeed. Before it creates a changefeed, the connector checks whether a running changefeed already covers the configured tables. If a matching changefeed is found, the connector skips creation and consumes from the existing changefeed instead. This behavior keeps connector restarts idempotent and avoids creating duplicate changefeed jobs on the cluster. It also lets an operator pre-provision a changefeed that the connector then attaches to.

A changefeed is considered a match only when both of the following are true for the running changefeed job:

  • Its description includes the fully-qualified name of each configured table.
  • Its description includes the topic_prefix that the connector expects, which is the value of cockroachdb.changefeed.sink.topic.prefix, or the value of topic.prefix when no sink topic prefix is set.

For the connector to consume the existing changefeed correctly, the changefeed must publish to Kafka topics whose names match the topics that the connector subscribes to, in the format topicPrefix.database.schema.table. To produce that topic layout, and to emit events in the structure that the connector expects, create the changefeed with the following options:

full_table_name

Required so that CockroachDB names topics in database.schema.table form.

topic_prefix='prefix.'

Required, and must equal the connector’s topic prefix described in the preceding list. The specified prefix must include a trailing dot (.).

envelope='enriched'

Required. The connector consumes the enriched envelope.

enriched_properties

Optional. The connector reads the base enriched fields (op, ts_ns, after, and before when diff is set), so it does not require any enriched property to consume the feed. The default value, source ensures that intermediate topics include origin and commit-time metadata.

format='json'

Required. The connector consumes JSON-encoded changefeed messages.

diff, updated, resolved

Set these to match the connector configuration so that before-images, update markers, and resolved timestamps are available.

If any of these conditions is not met, the connector does not recognize the existing changefeed and creates its own. A changefeed created with a different topic_prefix or without full_table_name is not recognized as a match, and the connector creates its own. If a running changefeed matches the connector’s topic prefix and tables, but it was created with an envelope other than enriched, the connector cannot consume it. The connector then fails to start and returns an error stating that you must recreate that changefeed with envelope='enriched' or else use a different topic prefix.

For most deployments, the simplest approach is to let the connector create and manage the changefeed. Reuse an existing changefeed only when you have a specific reason to do so, such as preserving an existing cursor position or a custom partitioning scheme.

Heartbeats

Resolved timestamps in the CockroachDB changefeed serve as natural heartbeats. When the connector receives a resolved timestamp, it performs the following operations:

  1. Updates the stored offset cursor to the resolved timestamp value.
  2. Dispatches a Debezium heartbeat event to advance Kafka Connect offsets.

By emitting heartbeat messages the connector helps to ensure that offsets advance even during idle periods in which no data changes occur. When offsets fail to advance, monitoring systems might report that the connector is unresponsive, which can cause CockroachDB protected timestamps to accumulate, preventing garbage collection.

To enable Debezium heartbeat records on the __debezium-heartbeat.<topic.prefix> Kafka topic, set heartbeat.interval.ms to a value greater than 0 (in milliseconds). The cockroachdb.changefeed.resolved.interval property controls how frequently CockroachDB emits resolved timestamps (default: 10s).

Schema evolution

The connector automatically detects DDL changes such as ALTER TABLE ADD COLUMN, DROP COLUMN, and RENAME COLUMN without requiring a restart. When an incoming changefeed event contains fields that do not match the registered table schema, the connector adapts the schema by performing the following tasks:

  1. Detects the mismatch by comparing event field names against registered column names.
  2. Re-queries information_schema to retrieve the updated table definition.
  3. Refreshes the internal schema and continues processing the table based on the adjusted column layout.

CockroachDB changefeeds handle schema changes natively by performing a backfill operation in which the Schema Change Manager re-emits all existing rows with the updated schema. A backfill ensures that no events are lost during the schema transition. After a backfill completes, the refreshed columns are immediately available to downstream consumers.

The connector adapts the schema of the change events that it emits, so that the records on the output topics always reflect the current table structure. It does not maintain a database history and does not emit DDL change events to a separate schema change topic. The schema that the connector uses comes from its own JDBC discovery of the table, not from the schema block in the changefeed message, so schema changes are handled even when cockroachdb.changefeed.enriched.properties is set to source alone.

Incremental snapshots

The CockroachDB connector supports Debezium signal-based incremental snapshots. An incremental snapshot re-reads existing rows from one or more tables and emits them as op=r (read) events, while the connector continues to capture ongoing changes without interruption.

You can use incremental snapshots to perform the following tasks:

  • Repopulate a downstream consumer that lost data.
  • Backfill a newly added sink or topic.
  • Verify source-target consistency by re-snapshotting and comparing.

Prepare to use incremental snapshots

To enable the connector to use incremental snapshots, you must create a signaling table and then update the connector configuration to recognize the signaling table.

Procedure

  1. Create a signaling table in CockroachDB by issuing the following SQL command:

    CREATE TABLE debezium_signal (
        id STRING PRIMARY KEY,
        type STRING NOT NULL,
        data STRING
    );
  2. Add the following properties to the connector configuration to reference the signaling table:

    {
        "signal.data.collection": "mydb.public.debezium_signal",
        "table.include.list": "public.my_table,public.debezium_signal"
    }

    You must include the signaling table in the table.include.list so that the changefeed can deliver signal events to the connector.

Trigger an incremental snapshot

You trigger an incremental snapshot by inserting a row in the connector’s signaling table.

Procedure

  • Run a SQL command that uses the following format to add a row to the signaling table to trigger an incremental snapshot:

    INSERT INTO debezium_signal (id, type, data) VALUES
        ('snap-1', 'execute-snapshot',
         '{"data-collections": ["mydb.public.my_table"]}');

The connector rereads all rows from the specified tables and emits them as op=r events.

For more information about signaling, see Sending signals to a Debezium connector.

Topic names

The CockroachDB connector emits all data change events for a table (insert, update, and delete) to a Kafka topic that is dedicated to that table. By default, the Kafka topic name is topicPrefix.schemaName.tableName where:

  • topicPrefix is the topic prefix as specified by the topic.prefix connector configuration property.
  • schemaName is the name of the database schema (default: public).
  • tableName is the name of the database table in which the operation occurred.

For example, suppose that cockroachdb is the topic prefix for a connector that captures changes from a database that contains two tables: orders and customers. The connector would stream records to the following two Kafka topics:

  • cockroachdb.public.orders
  • cockroachdb.public.customers

The connector applies naming conventions that are similar to those used by other Debezium connectors, and it supports the standard topic naming strategies.

Data change events

The Debezium CockroachDB connector generates a data change event for each row-level INSERT, UPDATE, and DELETE operation. Each event contains a key and a value. The key and value are separate documents. The structure of the key and the value depends on the table that was changed.

Debezium and Kafka Connect are designed around continuous streams of event messages. However, the structure of these events may change over time, which can be difficult for consumers to handle. To help consumers adapt to structural volatility, the connector emits self-contained events. That is, each event message either contains the schema for its content , or in environments that use a schema registry, each message contains a schema ID that a consumer can use to obtain the schema from the registry.

The following skeleton JSON documents show the basic structure of the key and value fields in an event message. However, the exact representation of the key and value documents depends on how you configure the Kafka Connect converter that you use in your application. A schema field is present a change event key or change event value only if you configure the converter to produce it. Likewise, the event key and event payload are present only if you configure a converter to produce it. If you use the JSON converter and you configure it to produce schemas, change events have the following structure:

// Key
{
 "schema": { (1)
   ...
  },
 "payload": { (2)
   ...
 }
}

// Value
{
 "schema": { (3)
   ...
 },
 "payload": { (4)
   ...
 }
}
ItemField nameDescription
1schemaThe first schema field is part of the event key. It specifies a Kafka Connect schema that describes what is in the event key’s payload portion. In other words, the first schema field describes the structure of the primary key.
2payloadThe first payload field is part of the event key. It has the structure described by the previous schema field and it contains the key for the row that was changed.
3schemaThe second schema field is part of the event value. It specifies the Kafka Connect schema that describes what is in the event value’s payload portion. In other words, the second schema describes the structure of the row that was changed. Typically, this schema contains nested schemas.
4payloadThe second payload field is part of the event value. It has the structure described by the previous schema field and it contains the actual data for the row that was changed.

Table 2. Overview of change event basic content

The default xref: topic naming behavior results in the connector streaming change event records to a topic whose name matches the name of the table that the event describes.

Change event keys

The change event key for a table contains fields for each column that was present in the table’s primary key at the time the event was created.

For example, consider the following definition for an orders table in the defaultdb database:

Example table

CREATE TABLE orders (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  customer_name STRING NOT NULL,
  amount DECIMAL NOT NULL,
  status STRING DEFAULT 'pending',
  created_at TIMESTAMP DEFAULT now()
);

Example change event key

Based on the preceding definition of the orders table, every change event for the table uses the same key structure. The following JSON represents this key structure:

{
  "schema": {
    "type": "struct",
    "name": "cockroachdb.public.orders.Key",
    "optional": false,
    "fields": [
      {
        "type": "string",
        "optional": false,
        "field": "id"
      }
    ]
  },
  "payload": {
    "id": "5f8a1c2e-3b4d-4e6f-8a9b-1c2d3e4f5a6b"
  }
}

Change event values

Consider the same sample orders table that was used in the change event key example:

CREATE TABLE orders (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  customer_name STRING NOT NULL,
  amount DECIMAL NOT NULL,
  status STRING DEFAULT 'pending',
  created_at TIMESTAMP DEFAULT now()
);

Based on the preceding orders table definition, the following examples show representative structures for the following types of change event values:

create events

The following example shows the value portion of a change event that the connector generates for an operation that inserts data in the orders table:

{
    "schema": { ... },
    "payload": {
        "before": null, (1)
        "after": { (2)
            "id": "5f8a1c2e-3b4d-4e6f-8a9b-1c2d3e4f5a6b",
            "customer_name": "Alice",
            "amount": "99.99",
            "status": "pending",
            "created_at": "2026-01-15T10:30:00"
        },
        "source": { (3)
            "version": "3.6.3.Final",
            "connector": "cockroachdb",
            "name": "cockroachdb_connector",
            "ts_ms": 1705312200000,
            "ts_us": 1705312200000000,
            "ts_ns": 1705312200000000000,
            "snapshot": "false",
            "db": "defaultdb",
            "sequence": "[]",
            "schema": "public",
            "table": "orders",
            "cluster": "cockroachdb_connector",
            "resolved_ts": null,
            "ts_hlc": null
        },
        "op": "c", (4)
        "ts_ms": 1705312200123, (5)
        "ts_us": 1705312200123456,
        "ts_ns": 1705312200123456789
    }
}

Table 3. Descriptions of create event value fields

Item Field name Description

1

before

An optional field that specifies the state of the row before the event occurred. When the op field is c for create, the before field is null since this change event is for new content.

2

after

An optional field that specifies the state of the row after the event occurred. In this example, the after field contains the values of the new row’s id, customer_name, amount, status, and created_at columns.

3

source

Mandatory field that describes the source metadata for the event. This field contains information that you can use to compare this event with other events, with regard to the origin of the events, the order in which the events occurred, and whether events were part of the same transaction. The source metadata includes:

  • Debezium version
  • Connector type and name
  • Database and table that contains the new row
  • Whether the event was part of a snapshot (initial scan)
  • The schema name
  • The logical cluster name
  • The resolved timestamp (for consistency tracking)
  • The Hybrid Logical Clock (HLC) timestamp. HLC is the internal timestamp format for CockroachDB.

4

op

Mandatory string that describes the type of operation that caused the connector to generate the event. In this example, c indicates that the operation created a row. Valid values are:

  • r = read (initial scan / snapshot)
  • c = create
  • u = update
  • d = delete

5

ts_ms, ts_us, ts_ns

Optional field that displays the time at which the connector processed the event. The time is based on the system clock in the JVM running the Kafka Connect task.

In the source object, ts_ms indicates the time that the change was made in the database. By comparing the value for payload.source.ts_ms with the value for payload.ts_ms, you can determine the lag between the source database update and Debezium.

update events

The value portion of a an event record for an update event in the sample orders table has the same schema as a create event for that table. Likewise, the event value’s payload has the same structure. However, the event value payload contains different values in an update event. The following example shows the JSON for the value portion of a change event that the connector generates for an update in the orders table:

{
    "schema": { ... },
    "payload": {
        "before": null, (1)
        "after": { (2)
            "id": "5f8a1c2e-3b4d-4e6f-8a9b-1c2d3e4f5a6b",
            "customer_name": "Alice",
            "amount": "99.99",
            "status": "shipped",
            "created_at": "2026-01-15T10:30:00"
        },
        "source": { (3)
            "version": "3.6.3.Final",
            "connector": "cockroachdb",
            "name": "cockroachdb_connector",
            "ts_ms": 1705312500000,
            "ts_us": 1705312500000000,
            "ts_ns": 1705312500000000000,
            "snapshot": "false",
            "db": "defaultdb",
            "sequence": "[]",
            "schema": "public",
            "table": "orders",
            "cluster": "cockroachdb_connector",
            "resolved_ts": null,
            "ts_hlc": null
        },
        "op": "u", (4)
        "ts_ms": 1705312500123,
        "ts_us": 1705312500123456,
        "ts_ns": 1705312500123456789
    }
}
ItemField nameDescription
1beforeAn optional field that contains the state of the row before the update. By default, CockroachDB changefeeds do not include the before state unless the diff changefeed option is enabled (cockroachdb.changefeed.include.diff=true). When diff is not enabled, this field is null.
2afterAn optional field that specifies the state of the row after the event occurred. In this example, the status value has been changed to shipped.
3sourceMandatory field that describes the source metadata for the event. The source field structure has the same fields as in a create event, but some values are different.
4opMandatory string that describes the type of operation. In an update event value, the op field value is u, signifying that this row changed because of an update.

Table 4. Descriptions of update event value fields

To include the before state in update events, set cockroachdb.changefeed.include.diff to true in the connector configuration. To include the before state for a row in update events, enable the CockroachDB changefeed diff option by setting cockroachdb.changefeed.include.diff to true in the connector configuration.

delete events

The value in a delete change event has the same schema portion as create and update events for the same table. A delete change event record provides a consumer with the information that it needs to process the removal of a row.

Debezium CockroachDB connector events are designed to work with Kafka log compaction. Log compaction enables removal of some older messages as long as at least the most recent message for every key is kept. Removing older messages lets Kafka reclaim storage space while ensuring that the topic contains a complete data set and can be used for reloading key-based state.

The following example shows the JSON for the payload portion of a change event that the connector generates for a delete event in the orders table:

{
    "schema": { ... },
    "payload": {
        "before": null,
        "after": null, (1)
        "source": { (2)
            "version": "3.6.3.Final",
            "connector": "cockroachdb",
            "name": "cockroachdb_connector",
            "ts_ms": 1705312800000,
            "ts_us": 1705312800000000,
            "ts_ns": 1705312800000000000,
            "snapshot": "false",
            "db": "defaultdb",
            "sequence": "[]",
            "schema": "public",
            "table": "orders",
            "cluster": "cockroachdb_connector",
            "resolved_ts": null,
            "ts_hlc": null
        },
        "op": "d", (3)
        "ts_ms": 1705312800123,
        "ts_us": 1705312800123456,
        "ts_ns": 1705312800123456789
    }
}
ItemField nameDescription
1afterThe after field is null, signifying that the row no longer exists.
2sourceMandatory field that describes the source metadata for the event. In a delete event value, the source field structure is the same as for create and update events for the same table.
3opMandatory string that describes the type of operation. The op field value is d, signifying that this row was deleted.

Table 5. Descriptions of delete event value fields

A delete change event record provides a consumer with the information it needs to process the removal of this row.

Tombstone events

When you delete a row, the delete event value still works with log compaction, because Kafka can remove all earlier messages that have that same key. However, for Kafka to remove all messages that have that same key, the message value must be null. To make this possible, the connector follows a delete event with a special tombstone event that has the same key but a null value.

Data type mappings

The CockroachDB connector represents changes to rows with events that are structured like the table in which the row exists. The event contains a field for each column value. The way in which Debezium represents values in the event record depends on the data type of the CockroachDB column. The following data type mappings are applied for CockroachDB data:

CockroachDB types

CockroachDB data typeKafka Connect schema typeNotes
BOOL, BOOLEANBOOLEAN
INT2, SMALLINTINT16
INT4, INT, INTEGERINT32
INT8, BIGINT, SERIALINT64
FLOAT4, REALFLOAT32
FLOAT8, DOUBLE PRECISION, FLOATFLOAT64
NUMERIC, DECIMAL, DECSTRINGRepresented as string to preserve arbitrary precision.
STRING, VARCHAR, CHAR, CHARACTER VARYING, TEXTSTRING
UUIDSTRINGRepresented as the standard UUID string format.
BYTES, BYTEA, BLOBBYTES
DATEINT32 (io.debezium.time.Date logical type)Number of days since the epoch.
TIMEINT64 (io.debezium.time.MicroTime logical type)Number of microseconds since midnight.
TIMETZSTRING (io.debezium.time.ZonedTime logical type)Offset-qualified ISO-8601 time (for example 14:36:34.873+02:00).
TIMESTAMPINT64 (io.debezium.time.MicroTimestamp logical type)Number of microseconds since the epoch, interpreted as UTC.
TIMESTAMPTZSTRING (io.debezium.time.ZonedTimestamp logical type)Offset-qualified ISO-8601 timestamp (for example 2026-06-15T14:36:34.873Z).
INTERVALSTRINGCockroachDB interval format.
JSONB, JSONSTRING (Json logical type)Represented as a JSON string using the Debezium Json logical type.
INETSTRINGIP address string.
BIT, VARBITSTRINGBit string representation.
ARRAYSTRINGJSON array format.
ENUMSTRINGEnum label string.
GEOMETRY, GEOGRAPHYSTRINGGeoJSON or WKT format.
VECTORARRAY of FLOAT64 (DoubleVector)pgvector-compatible type (CockroachDB 24.2+). Uses the Debezium DoubleVector logical type.

Table 6. Mappings for CockroachDB data types

Default values

When a CockroachDB column specifies a DEFAULT clause, the connector parses the JDBC-reported default expression into the Java type that matches the column’s Kafka Connect schema, and sets it as the schema default for that field. CockroachDB annotates default expressions with a CockroachDB-specific :::TYPE suffix (for example, 0:::INT8, 'PENDING':::STRING, '[1.0,2.0,3.0]':::VECTOR). The connector strips this annotation, unwraps quoted literals, and converts the value to the column’s Java type.

Function-generated defaults such as current_timestamp(), gen_random_uuid(), now(), and unique_rowid() are not evaluated by the connector. For these columns, the connector omits the default from the schema so that CockroachDB computes the value at insert time.

Setting up CockroachDB

Before you deploy the Debezium CockroachDB connector, prepare your CockroachDB environment so that the connector can create and read changefeeds. At a high level, ensure that the required components and connectivity are in place, enable rangefeeds on the cluster, and grant the database user that the connector uses the privileges that changefeeds require. For information about enabling rangefeeds and granting the required privileges, see Granting changefeed permissions.

Prerequisites

CockroachDB cluster

A CockroachDB cluster that supports sink-based changefeeds. All changefeed features are available in every CockroachDB edition without an enterprise license.

Intermediate Kafka cluster

A Kafka cluster where CockroachDB publishes changefeed events. This can be the same Kafka cluster that Kafka Connect uses, or a separate one.

Network connectivity

The CockroachDB cluster must be able to connect to the intermediate Kafka cluster to publish changefeed events. The Kafka Connect worker must be able to read from both the CockroachDB cluster (for JDBC) and the intermediate Kafka cluster (for consuming changefeed events).

Changefeed user account

A CockroachDB user that has one of the following privileges on the target tables:

  • The CHANGEFEED privilege (CockroachDB v22.2+)
  • The ALL privilege
  • Membership in the admin role

Granting changefeed permissions

Enable cluster-wide rangefeeds and grant the necessary privileges to the database user that the connector uses. CockroachDB validates changefeed privileges at CREATE CHANGEFEED time and returns accurate, version-specific error messages if the user lacks sufficient permissions.

Procedure

  • As a CockroachDB admin user, run the following SQL commands:

    -- Enable rangefeeds (required cluster-wide setting)
    SET CLUSTER SETTING kv.rangefeed.enabled = true;
    
    -- Grant changefeed privilege to a specific user
    GRANT CHANGEFEED ON TABLE orders TO myuser;
    GRANT VIEWCLUSTERSETTING TO myuser;
    
    -- Or grant on all tables in a database
    GRANT CHANGEFEED ON ALL TABLES IN DATABASE defaultdb TO myuser;

    Granting VIEWCLUSTERSETTING lets the connector verify that kv.rangefeed.enabled is set to true, which is a prerequisite for changefeeds.

Securing the changefeed sink

When a changefeed sink uses TLS or mutual TLS (mTLS), the connector can load PEM files from disk and automatically add their base64-encoded contents to the sink URI at startup. This automatic injection removes the need to manually copy large, encoded certificate strings into the connector configuration.

Set one or more of the following properties to specify the mechanism that the connector uses to encrypt sink connections:

cockroachdb.changefeed.sink.tls.ca.cert.file

Path to a PEM-encoded CA certificate that verifies the sink broker’s certificate.

cockroachdb.changefeed.sink.tls.client.cert.file

Path to a PEM-encoded client certificate used for mutual TLS to the sink.

cockroachdb.changefeed.sink.tls.client.key.file

Path to a PEM-encoded client private key used for mutual TLS to the sink.

For each property that is set, the connector reads the file, validates that it is readable and non-empty, base64-encodes the contents, URL-encodes the result, and appends a corresponding query parameter to cockroachdb.changefeed.sink.uri in the form expected by the configured sink type. For the Kafka sink, the appended parameters are ca_cert=…​, client_cert=…​, client_key=…​, and tls_enabled=true (added automatically whenever any of the three TLS file options is set). File-based values overwrite any same-named query parameter that is already present inline in the sink URI.

Example configuration for a Kafka sink secured with mTLS

{
  "cockroachdb.changefeed.sink.type": "kafka",
  "cockroachdb.changefeed.sink.uri": "kafka://kafka.example.com:9093",
  "cockroachdb.changefeed.sink.tls.ca.cert.file": "/etc/kafka/secrets/ca.pem",
  "cockroachdb.changefeed.sink.tls.client.cert.file": "/etc/kafka/secrets/client.pem",
  "cockroachdb.changefeed.sink.tls.client.key.file": "/etc/kafka/secrets/client-key.pem"
}

The connector validates each configured file path at startup and fails fast if the file does not exist, is unreadable, or is empty. Currently only the Kafka sink consumes these TLS parameters; for other sink types the sink URI passes through unchanged.

Deployment

To deploy a Debezium CockroachDB connector you obtain the connector plug-in files archive, add the JAR files to your Kafka Connect environment, and then edit the plugin.path configuration to reference the location of the files.

If you are working with immutable containers, see the Debezium container images for Kafka and Kafka Connect.

The Debezium container images that you obtain from quay.io do not undergo rigorous testing or security analysis, and are provided for testing and evaluation purposes only. These images are not intended for use in production environments. To mitigate risk in production deployments, deploy only containers that are actively maintained by trusted vendors, and thoroughly tested for potential vulnerabilities.

You can also run Debezium on Kubernetes and OpenShift.

Prerequisites

Procedure

  1. Download the archive file to a temporary directory.
  2. Copy the downloaded file to a directory in your Kafka Connect environment, for example, /usr/local/share/kafka/plugins.
  3. Extract the JAR file into the directory and then remove the downloaded archive file.
  4. Add an entry for the directory with the JAR files to the Kafka Connect plugin.path.
  5. Configure the connector and add the configuration to your Kafka Connect cluster.
  6. Restart the Kafka Connect process so that it picks up the new JAR files.

Connector configuration example

The following example shows a possible configuration for a CockroachDB connector that connects to a CockroachDB cluster and captures changes from all tables in the public schema of the defaultdb database.

{
  "name": "cockroachdb-connector",  (1)
  "config": {
    "connector.class": "io.debezium.connector.cockroachdb.CockroachDBConnector", (2)
    "database.hostname": "cockroachdb-host", (3)
    "database.port": "26257", (4)
    "database.user": "myuser", (5)
    "database.password": "mypassword", (6)
    "database.dbname": "defaultdb", (7)
    "topic.prefix": "cockroachdb", (8)
    "cockroachdb.changefeed.sink.uri": "kafka://kafka-broker:9092", (9)
    "snapshot.mode": "initial", (10)
    "tasks.max": "1" (11)
  }
}
1The name of the connector when registered with a Kafka Connect service.
2The name of this CockroachDB connector class.
3The address of the CockroachDB host.
4The port number of the CockroachDB server (default: 26257).
5The name of the CockroachDB user.
6The password of the CockroachDB user.
7The name of the CockroachDB database to connect to.
8The topic prefix for Kafka topics that the connector writes to.
9The URI of the Kafka cluster where CockroachDB publishes changefeed events.
10The snapshot mode; initial backfills existing rows on first start.
11The maximum number of tasks.

For more information about the properties that you can specify in the connector configuration, see the complete list of CockroachDB connector properties .

Adding the connector configuration

Edit the CockroachDB connector configuration to specify how you want the connector to behave. After you finalize the configuration, use the Kafka Connect API to apply the configuration to the cluster.

Prerequisites

  • CockroachDB is running and accessible.
  • The intermediate Kafka cluster is running and accessible from the CockroachDB cluster.
  • The CockroachDB connector is installed.

Procedure

  1. Create the configuration for the CockroachDB connector.

  2. Use the Kafka Connect REST API to submit a POST request that applies the JSON for the connector configuration to the Kafka Connect cluster.

    For example:

    curl -i -X POST -H "Accept:application/json" -H "Content-Type:application/json" \
      http://localhost:8083/connectors/ -d @connector-config.json

Results

When the connector starts, it connects to the CockroachDB database, creates a changefeed, and starts generating data change events for row-level operations and streaming change event records to Kafka topics.

Monitoring

The Debezium CockroachDB connector includes built-in support for both the JMX metrics that Kafka and Kafka Connect provide, as well as snapshot metrics and streaming metrics that provide insights into connector behavior during the initial scan and during the capture and streaming of change event records.

Additional resources

Customized MBean names

Debezium connectors expose metrics via the MBean name for the connector. These metrics, which are specific to each connector instance, provide data about the behavior of the connector’s snapshot, streaming, and schema history processes.

By default, when you deploy a correctly configured connector, Debezium generates a unique MBean name for each of the different connector metrics. To view the metrics for a connector process, you configure your observability stack to monitor its MBean. But these default MBean names depend on the connector configuration; configuration changes can result in changes to the MBean names. A change to the MBean name breaks the linkage between the connector instance and the MBean, disrupting monitoring activity. In this scenario, you must reconfigure the observability stack to use the new MBean name if you want to resume monitoring.

To prevent monitoring disruptions that result from MBean name changes, you can configure custom metrics tags. You configure custom metrics by adding the custom.metric.tags property to the connector configuration. The property accepts key-value pairs in which each key represents a tag for the MBean object name, and the corresponding value represents the value of that tag. For example: k1=v1,k2=v2. Debezium appends the specified tags to the MBean name of the connector.

After you configure the custom.metric.tags property for a connector, you can configure the observability stack to retrieve metrics associated with the specified tags. The observability stack then uses the specified tags, rather than the mutable MBean names to uniquely identify connectors. Later, if Debezium redefines how it constructs MBean names, or if the topic.prefix in the connector configuration changes, metrics collection is uninterrupted, because the metrics scrape task uses the specified tag patterns to identify the connector.

A further benefit of using custom tags, is that you can use tags that reflect the architecture of your data pipeline, so that metrics are organized in a way that suits you operational needs. For example, you might specify tags with values that declare the type of connector activity, the application context, or the data source, for example, db1-streaming-for-application-abc. If you specify multiple key-value pairs, all of the specified pairs are appended to the connector’s MBean name.

The following example illustrates how tags modify the default MBean name.

Example 1. How custom tags modify the connector MBean name

By default, the CockroachDB connector uses the following MBean name for streaming metrics:

debezium.CockroachDB:type=connector-metrics,context=streaming,server=<topic.prefix>

If you set the value of custom.metric.tags to database=salesdb-streaming,table=inventory, Debezium generates the following custom MBean name:

debezium.CockroachDB:type=connector-metrics,context=streaming,server=<topic.prefix>,database=salesdb-streaming,table=inventory

Snapshot metrics

The connector backfills existing rows through the CockroachDB changefeed initial_scan and drives the standard snapshot lifecycle around it, so the snapshot metrics are populated during the initial scan.

The MBean is debezium.CockroachDB:type=connector-metrics,context=snapshot,server=<topic.prefix>.

The following table lists the JMX metrics that are available for monitoring Debezium snapshot operations, including row counts, table progress, duration, and queue capacity. Snapshot metrics are not exposed unless a snapshot operation is active, or a snapshot has occurred since the last connector start.

AttributesTypeDescription
LastEventstringThe last snapshot event that the connector has read.
MilliSecondsSinceLastEventlongThe number of milliseconds since the connector has read and processed the most recent event.
NumberOfErroneousEventslongRecords the number of change events that the connector identifies as erroneous during a snapshot operation. The connector increments this metric each time that it encounters an event that it cannot process during an initial, incremental, or ad hoc snapshot. Events might fail processing if they are malformed, are incompatible with the schema, or if they encounter failures during transformation. The metric value persists for the lifetime of the connector task. If the snapshot is interrupted, and the connector task restarts, the metric count resets to 0.
TotalNumberOfEventsSeenlongThe total number of events that this connector has seen since last started or reset.
NumberOfEventsFilteredlongThe number of events that have been filtered by include/exclude list filtering rules configured on the connector.
CapturedTablesstring[]The list of tables that are captured by the connector.
QueueTotalCapacityintThe length the queue used to pass events between the snapshotter and the main Kafka Connect loop.
QueueRemainingCapacityintThe free capacity of the queue used to pass events between the snapshotter and the main Kafka Connect loop.
TotalTableCountintThe total number of tables that are being included in the snapshot.
RemainingTableCountintThe number of tables that the snapshot has yet to copy.
SnapshotRunningbooleanWhether the snapshot was started.
SnapshotPausedbooleanWhether the snapshot was paused.
SnapshotAbortedbooleanWhether the snapshot was aborted.
SnapshotCompletedbooleanWhether the snapshot completed.
SnapshotSkippedbooleanWhether the snapshot was skipped.
SnapshotDurationInSecondslongThe total number of seconds that the snapshot has taken so far, even if not complete. Includes also time when snapshot was paused.
SnapshotPausedDurationInSecondslongThe total number of seconds that the snapshot was paused. If the snapshot was paused several times, the paused time adds up.
RowsScannedMap<String, Long>Map containing the number of rows scanned for each table in the snapshot. Tables are incrementally added to the Map during processing. Updates every 10,000 rows scanned and upon completing a table.
TableChunkCountsMap<String, Long>Map containing the number of chunks for each table in the snapshot when using chunk-based multithreaded snapshots.
TableChunksCompletedCountsMap<String, Long>Map containing the number of chunks that have completed for each table in the snapshot when using chunk-based multithreaded snapshots.
MaxQueueSizeInByteslongThe maximum buffer of the queue in bytes. This metric is available if max.queue.size.in.bytes is set to a positive long value.
CurrentQueueSizeInByteslongThe current volume, in bytes, of records in the queue.

The following table lists the additional JMX metrics that are available when a connector runs an incremental snapshot, including chunk and table boundary identifiers that you can use to track snapshot progress.

AttributesTypeDescription
ChunkIdstringThe identifier of the current snapshot chunk.
ChunkFromstringThe lower bound of the primary key set defining the current chunk.
ChunkTostringThe upper bound of the primary key set defining the current chunk.
TableFromstringThe lower bound of the primary key set of the currently snapshotted table.
TableTostringThe upper bound of the primary key set of the currently snapshotted table.

Streaming metrics

The MBean is debezium.CockroachDB:type=connector-metrics,context=streaming,server=<topic.prefix>.

The following table lists the JMX metrics that are available for monitoring Debezium streaming operations, including event counts by type, lag behind the source, queue capacity, and connection status.

AttributesTypeDescription
LastEventstringThe last streaming event that the connector has read.
MilliSecondsSinceLastEventlongThe number of milliseconds since the connector has read and processed the most recent event.
NumberOfErroneousEventslongRecords the number of change events that the connector identifies as erroneous during streaming. The connector increments this metric each time that it encounters an event that it cannot process during the lifetime of the streaming session. Events might fail processing if they are malformed, are incompatible with the schema, or if they encounter failures during transformation. The metric value persists for the lifetime of the connector task. After a connector restart, the metric count resets to 0.
TotalNumberOfEventsSeenlongThe total number of data change events reported by the source database since the last connector start, or since a metrics reset. Represents the data change workload for Debezium to process.
TotalNumberOfCreateEventsSeenlongThe total number of create events processed by the connector since its last start or metrics reset.
TotalNumberOfUpdateEventsSeenlongThe total number of update events processed by the connector since its last start or metrics reset.
TotalNumberOfDeleteEventsSeenlongThe total number of delete events processed by the connector since its last start or metrics reset.
NumberOfEventsFilteredlongThe number of events that have been filtered by include/exclude list filtering rules configured on the connector.
NumberOfUnchangedEventsSkippedlongNumber of update events skipped since the last connector start or metrics reset because no monitored columns changed. Defaults to -1 if skip.messages.without.change is false. May remain 0 for CockroachDB and other connectors that do not support skipping unchanged events, even if the property is set to true.
CapturedTablesstring[]The list of tables that are captured by the connector.
QueueTotalCapacityintThe length the queue used to pass events between the streamer and the main Kafka Connect loop.
QueueRemainingCapacityintThe free capacity of the queue used to pass events between the streamer and the main Kafka Connect loop.
ConnectedbooleanFlag that denotes whether the connector is currently connected to the database server.
MilliSecondsBehindSourcelongThe number of milliseconds between the last change event’s timestamp and the connector processing it. The values will incorporate any differences between the clocks on the machines where the database server and the connector are running.
MilliSecondsBehindSourceMinValuelongThe minimum lag in milliseconds behind the source that is observed during the connector’s runtime.
MilliSecondsBehindSourceMaxValuelongThe maximum lag in milliseconds behind the source that is observed during the connector’s runtime.
MilliSecondsBehindSourceAverageValuedoubleThe average lag in milliseconds behind the source calculated across all observations during the connector’s runtime.
MilliSecondsBehindSourceP50doubleThe 50th percentile (median) of the lag in milliseconds behind the source. This metric provides a more robust measure of typical lag than the average, as it is less affected by outlier values. Available when statistics.metrics.enabled is set to true (default).
MilliSecondsBehindSourceP95doubleThe 95th percentile of the lag in milliseconds behind the source. This metric indicates that 95% of lag measurements are below this value, useful for identifying tail latencies and setting SLA thresholds. Available when statistics.metrics.enabled is set to true (default).
MilliSecondsBehindSourceP99doubleThe 99th percentile of the lag in milliseconds behind the source. This metric indicates that 99% of lag measurements are below this value, useful for understanding worst-case performance scenarios. Available when statistics.metrics.enabled is set to true (default).
NumberOfCommittedTransactionslongThe number of processed transactions that were committed.
SourceEventPositionMap<String, String>The coordinates of the last received event.
LastTransactionIdstringTransaction identifier of the last processed transaction.
MaxQueueSizeInByteslongThe maximum buffer of the queue in bytes. This metric is available if max.queue.size.in.bytes is set to a positive long value.
CurrentQueueSizeInByteslongThe current volume, in bytes, of records in the queue.

Connector configuration properties

The Debezium CockroachDB connector has many configuration properties that you can use to achieve the right connector behavior for your application. Many properties have default values. Information about the properties is organized as follows:

The following configuration properties are required unless a default value is available.

PropertyDefaultDescription
nameNo defaultUnique name for the connector. The name that you use to register a connector name must be unique. Registration fails if you reuse a connector name. This property is required by all Kafka Connect connectors.
connector.classNo defaultThe name of the Java class for the connector. Always use a value of io.debezium.connector.cockroachdb.CockroachDBConnector for the CockroachDB connector.
tasks.max1The maximum number of tasks that the connector can create.
database.hostnameNo defaultIP address or hostname of the CockroachDB database server.
database.port26257Integer port number of the CockroachDB database server. The CockroachDB default SQL port is 26257.
database.userNo defaultName of the CockroachDB database user for connecting to the database.
database.passwordNo defaultPassword of the CockroachDB database user for connecting to the database.
database.dbnameNo defaultThe name of the CockroachDB database from which to stream changes.
topic.prefixNo defaultTopic prefix that provides a namespace for the particular CockroachDB database server or cluster. The topic prefix should be unique across all other connectors, since it is used as the prefix for all Kafka topic names that receive events emitted by this connector. Only alphanumeric characters, hyphens, dots, and underscores must be used in the topic prefix.
cockroachdb.changefeed.sink.uriNo defaultThe URI for the intermediate Kafka cluster where CockroachDB publishes changefeed events. Format: kafka://host:port. This is a required property.

Table 7. Required connector configuration properties

The following properties configure the JDBC connection to the CockroachDB database.

PropertyDefaultDescription
database.sslmodepreferSpecifies whether Debezium establishes an encrypted connection to CockroachDB. Set one of the following options: disable, allow, prefer, require, verify-ca, verify-full. See the CockroachDB authentication docs for details.
database.sslrootcertNo defaultFile that contains the trusted root certificates for validating the database server.
database.sslcertNo defaultFile that contains the SSL certificate for the client.
database.sslkeyNo defaultFile that contains the SSL private key for the client.
database.sslpasswordNo defaultPassword to access the client private key from the file specified by database.sslkey.
database.tcpKeepAlivetrueSpecifies whether to enable TCP keep-alive probes to avoid dropping TCP connections.
database.on.connect.statementsNo defaultSpecifies a semicolon-separated list of SQL statements that the connector runs when it establishes a JDBC connection. Use double semicolons (;;) to specify a literal semicolon instead of treating it as a separator.
connection.timeout.ms30000Specifies the time, in milliseconds, that the connector waits for a connection to be established with the database.
connection.retry.delay.ms1000Base delay in milliseconds between connection retry attempts. The actual delay is multiplied by the attempt number (linear backoff).
connection.max.retries3Maximum number of times that the connector retries the connection before it abandons the attempt.
connection.validation.timeout.seconds5Timeout in seconds for validating that an existing JDBC connection is still usable.

Table 8. Connection configuration properties

The following properties configure the CockroachDB changefeed behavior.

PropertyDefaultDescription
cockroachdb.changefeed.resolved.interval10sThe interval for resolved timestamp messages. Format: 10s, 1m, and so on. Resolved timestamps are used for offset tracking.
cockroachdb.changefeed.include.updatedfalseSpecifies whether UPDATE events include information about which columns were updated.
cockroachdb.changefeed.include.difffalseSpecifies whether to include before and after diff information in changefeed events. When enabled, UPDATE events include the previous row state in the before field.
cockroachdb.changefeed.enriched.propertiessourceComma-separated list of enriched envelope properties, passed through verbatim to the CockroachDB CREATE CHANGEFEED statement. The connector always uses the enriched envelope, so this applies to every changefeed it creates. CockroachDB owns the set of valid values, currently source and schema, and validates them when the changefeed is created. The connector derives the schema of each event from the table metadata that it discovers over JDBC, and it identifies each event’s table from the topic on which the event arrives. The connector does not read the schema block, which duplicates information that it already has; schema is accepted and passed through for other consumers of the intermediate topics, but it is not used by the connector. The default value is source because that block identifies the originating database, schema, table, and commit timestamp. This information is useful when you inspect the intermediate topics or when other tools also consume them.
cockroachdb.changefeed.cursornowThe cursor position to start the changefeed from. Use now to start from the current time or specify an absolute timestamp. When the connector restarts from a stored offset, it uses the stored resolved timestamp instead of this value.
cockroachdb.changefeed.batch.size1000The batch size for changefeed processing.
cockroachdb.changefeed.poll.interval.ms100The poll interval in milliseconds for changefeed processing.
cockroachdb.changefeed.sink.typekafkaThe type of sink for changefeed events. Currently supported: kafka.
cockroachdb.changefeed.sink.topic.prefixemptyString that the connector prefixes to intermediate changefeed topic names. The connector uses the exact prefix string that you specify, so the resulting topics are named prefix__database.schema.table. Include your own separator if you want one: for example, crdb. yields crdb.mydb.public.orders, and env-prod- yields env-prod-mydb.public.orders. If you do not supply a value for this property, the connector defaults to using the value of topic.prefix followed by a dot.
cockroachdb.changefeed.max.tables.per.changefeed0Maximum number of tables to include in a single CockroachDB changefeed. The default of 0 places all configured tables in one changefeed. Set the value to a positive number to instruct the connector to split captured tables into multiple changefeeds. The specified value sets the maximum number of tables in each resulting changefeed. Split captured tables into multiple changefeeds if CockroachDB returns a warning about the high number of tables that a changefeed watches. Smaller values reduce coupling but create more changefeed jobs. Specify a value that optimizes performance while honoring CockroachDB recommendations for limiting the number of changefeed jobs per cluster.
cockroachdb.changefeed.sink.optionsNo default valueA comma-separated list of additional options for the sink in key=value format.
cockroachdb.changefeed.sink.tls.ca.cert.fileNo defaultPath to a PEM-encoded CA certificate file that the connector uses to verify the certificate of the changefeed sink server. When you set this property, the connector reads the file, base64-encodes the contents, and appends the CA certificate to the sink URI in the form expected by the configured sink type (for example, ca_cert=…​ for Kafka sinks). The specified value overrides any equivalent query parameter that is present in cockroachdb.changefeed.sink.uri. For more information, see Securing the changefeed sink.
cockroachdb.changefeed.sink.tls.client.cert.fileNo defaultPath to a PEM-encoded client certificate file used for mutual TLS to the changefeed sink. When this property is set, the connector reads the file, base64-encodes the contents, and appends the client certificate to the sink URI in the form expected by the configured sink type (for example, client_cert=…​ for Kafka sinks). The specified value overrides any equivalent query parameter that is present in cockroachdb.changefeed.sink.uri. For more information, see Securing the changefeed sink.
cockroachdb.changefeed.sink.tls.client.key.fileNo defaultPath to a PEM-encoded client private key file used for mutual TLS to the changefeed sink. When set, the connector reads the file, base64-encodes the contents, and appends the client key to the sink URI in the form expected by the configured sink type (for example, client_key=…​ for Kafka sinks). The specified value overrides any equivalent query parameter that is present in cockroachdb.changefeed.sink.uri. Setting any of the three sink TLS file options also implies tls_enabled=true on the sink URI. For more information, see Securing the changefeed sink.
cockroachdb.changefeed.kafka.consumer.group.prefixcockroachdb-connectorKafka consumer group ID used when consuming changefeed events from the intermediate Kafka cluster. If multiple connectors share the same intermediate Kafka cluster, specify a value that is unique for the connector instance.
cockroachdb.changefeed.kafka.poll.timeout.ms100Maximum time in milliseconds to block in each Kafka consumer poll() call when consuming from the intermediate Kafka cluster.
cockroachdb.changefeed.kafka.auto.offset.resetearliestSpecifies where the connector begins processing when it does not detect an initial offset in the intermediate Kafka cluster. Specify one of the following options: earliest (start from beginning), latest (start from end).
cockroachdb.changefeed.kafka.consumer.override.*No defaultProperties with this prefix are passed as-is to the connector’s changefeed consumer (a standard Kafka client), with the prefix stripped. For example, cockroachdb.changefeed.kafka.consumer.override.security.protocol=SSL sets the consumer’s security.protocol. Use this to configure SASL, custom trust or key stores (PEM or JKS), or to override any setting. When cockroachdb.changefeed.sink.tls.* is set, the consumer’s SSL is derived automatically from those PEM files (the CA becomes the consumer’s PEM truststore, and the client certificate and key become its PEM keystore), so this passthrough is only needed for additional or different settings.

Table 9. Changefeed configuration properties

Set the following properties to configure the connector’s snapshot and schema behavior.

PropertyDefaultDescription
snapshot.modeinitialSpecifies the criteria for running a snapshot when the connector starts. CockroachDB uses native changefeed initial_scan to backfill existing rows. For details about how each snapshot mode maps to the CockroachDB initial_scan option, see Snapshots. Set one of the following options: always, initial, initial_only, no_data, never, when_needed, configuration_based, custom.
snapshot.isolation.modeserializableSpecifies the transaction isolation level that the connector uses. Set one of the following options: serializable (CockroachDB default), read_committed.
snapshot.locking.modenoneSpecifies how the connector holds locks on tables when it performs a schema snapshot. Set one of the following options: shared, none, custom. Because changefeed-based snapshots in CockroachDB do not require table locks, the default and recommended setting is none.
schema.include.listNo defaultAn optional, comma-separated list of regular expressions that match names of schemas for which you want to capture changes. Any schema name not included in schema.include.list is excluded from having its changes captured. By default, the connector captures changes in all non-system schemas. To match the name of a schema, Debezium applies the regular expression that you specify as an anchored regular expression. That is, the specified expression is matched against the entire name string of the schema; it does not match substrings that might be present in a schema name. If you include this property in the configuration, do not also set the schema.exclude.list property.
schema.exclude.listNo defaultAn optional, comma-separated list of regular expressions that match names of schemas for which you do not want to capture changes. Any schema whose name is not included in schema.exclude.list has its changes captured, with the exception of system schemas. To match the name of a schema, Debezium applies the regular expression that you specify as an anchored regular expression. That is, the specified expression is matched against the entire name string of the schema; it does not match substrings that might be present in a schema name. If you include this property in the configuration, do not also set the schema.include.list property.
read.onlyfalseSpecifies whether the connector uses alternative methods to deliver signals to Debezium instead of writing to the signaling table.
status.update.interval.ms10000Specifies the interval, in milliseconds, at which the connector sends status updates to the server.

Table 10. Connector configuration properties

The following advanced configuration properties have defaults that work in most situations and therefore rarely need to be specified in the connector’s configuration.

PropertyDefaultDescription
schema.name.adjustment.modenoneSpecifies how to adjust schema names for compatibility with the message converter that the connector uses. Set one of the following options: none, avro, avro_unicode.
field.name.adjustment.modenoneSpecifies how to adjust field names for compatibility with the message converter that the connector uses. Set one of the following options: none, avro, avro_unicode. For details, see Avro naming.
unavailable.value.placeholder__debezium_unavailable_valuePlaceholder for unavailable values (for example, for toasted columns).
heartbeat.interval.ms0Specifies the interval, in milliseconds, at which the connector emits heartbeat records to the __debezium-heartbeat.<topic.prefix> Kafka topic. Set to 0 (the default) to disable heartbeat records. Even when disabled, resolved timestamps still advance the connector’s internal offsets. For more information, see Heartbeats .

Table 11. Advanced connector configuration properties

Behavior when things go wrong

Debezium is a distributed system that captures all changes in multiple upstream databases; it never misses or loses an event. When the system is operating normally and is managed carefully, Debezium provides exactly once delivery of every change event record.

If a fault occurs, the system is designed to prevent the loss of any events. However, while it is recovering from a fault, it might repeat some change events. In these abnormal situations, Debezium, like Kafka, provides at least once delivery of change events.

The rest of this section describes how Debezium handles various kinds of faults and problems.

Configuration and startup errors

In the following situations, the connector fails when trying to start, reports an error or exception in the log, and then stops running:

  • The connector’s configuration is invalid.
  • The connector cannot successfully connect to CockroachDB by using the specified connection parameters.
  • The connector cannot create a changefeed because the user lacks sufficient privileges (CHANGEFEED, ALL, or admin role membership).

In these cases, the error message has details about the problem and possibly a suggested workaround. After you correct the configuration or address the CockroachDB problem, restart the connector.

CockroachDB becomes unavailable

When the connector is running, the CockroachDB cluster could become unavailable for any number of reasons. Because CockroachDB is a distributed database, the cluster automatically handles individual node failures. If the entire cluster becomes unavailable, the changefeed stops producing events. After the cluster recovers, the connector resumes processing from the last stored offset.

The connector includes retry logic with configurable parameters (connection.max.retries, connection.retry.delay.ms) for handling transient connection failures, including CockroachDB-specific errors like serialization failures (SQL state 40001) and connection errors (SQL state 08xxx).

Kafka Connect process stops gracefully

Suppose that Kafka Connect is being run in distributed mode and a Kafka Connect process is stopped gracefully. Prior to shutting down that process, Kafka Connect migrates the process’s connector tasks to another Kafka Connect process in that group. The new connector tasks start processing exactly where the prior tasks stopped. There is a short delay in processing while the connector tasks are stopped gracefully and restarted on the new processes.

Kafka Connect process crashes

If the Kafka Connector process stops unexpectedly, any connector tasks it was running terminates without recording the most recently processed offsets. When Kafka Connect is being run in distributed mode, Kafka Connect restarts those connector tasks on other processes. However, CockroachDB connectors resume from the last offset that was recorded by the earlier processes. This means that the new replacement tasks might generate some of the same change events that were processed just prior to the crash. The number of duplicate events depends on the offset flush period and the volume of data changes just before the crash.

Because there is a chance that some events might be duplicated during a recovery from failure, consumers should always anticipate some duplicate events.

Kafka becomes unavailable

As the connector generates change events, the Kafka Connect framework records those events in Kafka by using the Kafka producer API. Periodically, at a frequency that you specify in the Kafka Connect configuration, Kafka Connect records the latest offset that appears in those change events. If the Kafka brokers become unavailable, the Kafka Connect process that is running the connectors repeatedly tries to reconnect to the Kafka brokers. In other words, the connector tasks pause until a connection can be re-established, at which point the connectors resume exactly where they left off.

Connector is stopped for an extended period

If the connector is gracefully stopped, the database can continue to be used. When the connector restarts, it resumes streaming changes where it left off. That is, it generates change event records for all database changes that were made while the connector was stopped.

The CockroachDB garbage collection TTL (default: 4 hours) limits how far back in time a changefeed can be started. If the connector is stopped for longer than the configured TTL interval, the stored offset may no longer be valid. In this case, use snapshot.mode=when_needed to automatically re-snapshot when the offset has expired.

Enabling debug logging

To diagnose connector behavior, enable DEBUG (or TRACE) logging for one or more of the connector’s loggers in the Kafka Connect worker’s logging configuration. The connector uses SLF4J, so the standard connect-log4j.properties mechanism (or the runtime /admin/loggers REST endpoint) controls the level.

The following table list the most useful logger names for triage.

LoggerWhat it traces
io.debezium.connector.cockroachdbTop-level connector lifecycle: task start/stop, configuration, signal processing.
io.debezium.connector.cockroachdb.CockroachDBSchemaSchema discovery (which tables and schemas were found, which were filtered out by schema.include.list / table.include.list), and per-table refresh on schema change.
io.debezium.connector.cockroachdb.CockroachDBStreamingChangeEventSourceChangefeed query construction, per-event dispatch, resolved-timestamp progression, and Kafka consumer wiring.
io.debezium.connector.cockroachdb.CockroachDBSnapshotChangeEventSourceSnapshot decisions and delegation to the CockroachDB initial_scan mode.
io.debezium.connector.cockroachdb.CockroachDBDefaultValueConverterParsing of column DEFAULT expressions; logs at DEBUG when a default expression cannot be mapped to the column’s Java type.
io.debezium.connector.cockroachdb.connection.CockroachDBConnectionJDBC connection attempts, retries, and successful connects.

For example, to enable schema-discovery and streaming traces, add the following to connect-log4j.properties:

log4j.logger.io.debezium.connector.cockroachdb.CockroachDBSchema=DEBUG
log4j.logger.io.debezium.connector.cockroachdb.CockroachDBStreamingChangeEventSource=DEBUG

Or set the levels at runtime against a running Kafka Connect worker:

curl -X PUT -H "Content-Type: application/json" \
    --data '{"level":"DEBUG"}' \
    http://localhost:8083/admin/loggers/io.debezium.connector.cockroachdb

Limitations

Kafka sink only

The connector currently only supports Kafka as the intermediate changefeed sink. Support for webhook, Pub/Sub, and cloud storage sinks is planned (see debezium/dbz#1632).

Before state in updates

By default, CockroachDB changefeeds do not include the previous row state. To include the before field in update events, set cockroachdb.changefeed.include.diff=true to enable the diff changefeed option.

评论

登录后参与评论

正在加载评论…