Run a changefeed job by locality
Use theexecution_locality option to set locality filter requirements that a node must meet to take part in executing a job. This will pin the and the nodes that process the to the defined locality.
Defining an execution locality for a changefeed job, could be useful in the following cases:
- Your is only available in one region. There is no network connectivity between regions and you need to send all changefeed messages through the node(s) in the sink’s region.
- Your cluster runs on a and you need to send changefeed messages within the same environment.
- Your cluster is and you need the nodes that are physically closest to the sink to emit changefeed messages. This can avoid cross-regional traffic to reduce expense.
- Your cluster is running through VPC peering connections and you need all the data sent through a particular locality.
Syntax
To specify the locality requirements for the coordinating node, runexecution_locality with key-value pairs that represent the assigned to the cluster at startup.
execution_locality, consider the following:
- The changefeed job will fail if no nodes match the locality filter.
- Selection of the coordinating node that matches the locality filter may noticeably increase the startup latency of the changefeed job.
- Even though a changefeed job has been pinned to a locality, it does not guarantee the job will not read from another locality if there are no replicas in the defined locality.
Job coordination using the execution locality option
When you start or a changefeed withexecution_locality, it is necessary to determine the coordinating node for the job. If a node that does not match the locality filter is the first node to claim the job, it will find a node that does match the filter and transfer the execution to it. This can result in a short delay in starting or resuming a changefeed job that has execution locality requirements. When there is no node matching the specified locality, CockroachDB will return an error.
Once the coordinating node is determined, nodes that match the locality requirements will take part in emitting changefeed messages to the sink. The following will happen in different cases:
- If a for the change data matches the filter, it will emit the changefeed messages.
- If a replica does not match the locality filter, a node will be selected matching the locality filter with a preference for nodes with localities that are more similar to a replica.
Run changefeeds on regional by row tables
Changefeeds are supported on . When working with changefeeds on regional by row tables, it is necessary to consider the following:- Setting a table’s locality to is equivalent to a as the becomes a hidden column for each of the rows in the table and is part of the . Therefore, when existing tables targeted by changefeeds are made regional by row, it will trigger a backfill of the table through the changefeed. (See for more details on the effects of schema changes on changefeeds.)
If the changefeed option is configured to
stop, the backfill will cause the changefeed to fail.-
Setting a table to
REGIONAL BY ROWwill have an impact on the changefeed’s output as a result of the schema change. The backfill and future updated or inserted rows will emit output that includes the newly addedcrdb_regioncolumn as part of the schema. Therefore, it is necessary to ensure that programs consuming the changefeed can manage the new format of the primary keys. -
will appear as an insert and delete in the emitted changefeed output. For example, in the following output in which the region has been updated to
us-east1, the insert messages are emitted followed by the :

