You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/current/v24.3/create-logical-replication-stream.md
-8Lines changed: 0 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -50,14 +50,6 @@ Option | Description
50
50
`cursor` | Emits any changes after the specified timestamp. LDR will not perform an initial backfill with the `cursor` option, it will stream any changes after the specified timestamp. The LDR job will encounter an error if you specify a `cursor` timestamp that is before the configured [garbage collection]({% link {{ page.version.version }}/architecture/storage-layer.md %}#garbage-collection) window for that table. **Warning:** Apply the `cursor` option carefully to LDR streams. Using a timestamp in error could cause data loss.
51
51
<aid="discard-ttl-deletes-option"></a>`discard` | ([**Unidirectional LDR only**]({% link {{ page.version.version }}/logical-data-replication-overview.md %}#use-cases)) Ignore [TTL deletes]({% link {{ page.version.version }}/row-level-ttl.md %}) in an LDR stream with `discard = ttl-deletes`. **Note**: To ignore row-level TTL deletes in an LDR stream, it is necessary to set the [`ttl_disable_changefeed_replication`]({% link {{ page.version.version }}/row-level-ttl.md %}#ttl-storage-parameters) storage parameter on the source table. Refer to the [Ignore row-level TTL deletes](#ignore-row-level-ttl-deletes) example.
52
52
`label` | Tracks LDR metrics at the job level. Add a user-specified string with `label`. Refer to [Metrics labels]({% link {{ page.version.version }}/logical-data-replication-monitoring.md %}#metrics-labels).
53
-
`mode` | Determines how LDR replicates the data to the destination cluster. Possible values: `immediate`, `validated`. For more details, refer to [LDR modes](#ldr-modes).
54
-
55
-
## LDR modes
56
-
57
-
_Modes_ determine how LDR replicates the data to the destination cluster. There are two modes:
58
-
59
-
-`immediate` (default): {% include {{ page.version.version }}/ldr/immediate-description.md %}
60
-
-`validated`: {% include {{ page.version.version }}/ldr/validated-description.md %}
-**Table-level replication**: When you initiate LDR, it will replicate all of the source table's existing data to the destination table. From then on, LDR will replicate the source table's data to the destination table to achieve eventual consistency.
45
45
-**Last write wins conflict resolution**: LDR uses [_last write wins (LWW)_ conflict resolution]({% link {{ page.version.version }}/manage-logical-data-replication.md %}#conflict-resolution), which will use the latest [MVCC]({% link {{ page.version.version }}/architecture/storage-layer.md %}#mvcc) timestamp to resolve a conflict in row insertion.
46
46
-**Dead letter queue (DLQ)**: When LDR starts, the job will create a [DLQ table]({% link {{ page.version.version }}/manage-logical-data-replication.md %}#dead-letter-queue-dlq) with each replicating table in order to track unresolved conflicts. You can interact and manage this table like any other SQL table.
47
-
-**Replication modes**: LDR offers different [_modes_]({% link {{ page.version.version }}/create-logical-replication-stream.md %}#ldr-modes) that apply data differently during replication, which allows you to consider optimizing for throughput or constraints during replication.
48
47
-**Monitoring**: To [monitor]({% link {{ page.version.version }}/logical-data-replication-monitoring.md %}) LDR's initial progress, current status, and performance, you can view metrics available in the DB Console, Prometheus, and Metrics Export.
Copy file name to clipboardExpand all lines: src/current/v24.3/manage-logical-data-replication.md
+5-11Lines changed: 5 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ In LDR, conflicts are detected at both the [KV]({% link {{ page.version.version
22
22
23
23
### KV level conflicts
24
24
25
-
LDR uses _last write wins (LWW)_ conflict resolution based on the [MVCC timestamp]({% link {{ page.version.version }}/architecture/storage-layer.md %}#mvcc) of the replicating write. LDR will resolve conflicts by inserting the row with the latest MVCC timestamp. Conflicts at the KV level are detected in both `immediate` and `validated` mode.
25
+
LDR uses _last write wins (LWW)_ conflict resolution based on the [MVCC timestamp]({% link {{ page.version.version }}/architecture/storage-layer.md %}#mvcc) of the replicating write. LDR will resolve conflicts by inserting the row with the latest MVCC timestamp.
26
26
27
27
Conflicts at the KV level are detected when there is either:
28
28
@@ -31,20 +31,14 @@ Conflicts at the KV level are detected when there is either:
31
31
32
32
### SQL level conflicts
33
33
34
-
In `validated` mode, when a conflict cannot apply due to violating [constraints]({% link {{ page.version.version }}/constraints.md %}), for example, a foreign key constraint or schema constraint, it will be retried for up to a minute and then put in the [DLQ](#dead-letter-queue-dlq) if it could not be resolved.
34
+
When a conflict cannot apply due to violating [constraints]({% link {{ page.version.version }}/set-up-logical-data-replication.md %}#schema-validation), for example, a schema constraint, LDR will send the row to the [DLQ](#dead-letter-queue-dlq).
35
35
36
36
### Dead letter queue (DLQ)
37
37
38
-
When the LDR job starts, it will create a DLQ table with each replicating table so that unresolved conflicts can be tracked. The DLQ will contain the writes that LDR cannot apply after the retry period, which could occur if:
38
+
When the LDR job starts, it will create a DLQ table with each replicating table so that unresolved conflicts can be tracked. The DLQ will contain the writes that LDR cannot apply after the retry period of a minute, which could occur if:
39
39
40
-
- The destination table was dropped.
41
-
- The destination cluster is unavailable.
42
-
- Tables schemas do not match.
43
-
44
-
In `validated` mode, rows are also sent to the DLQ when:
45
-
46
-
-[Foreign key]({% link {{ page.version.version }}/foreign-key.md %}) dependencies are not met where there are foreign key constraints in the schema.
47
-
- Unique indexes and other constraints are not met.
40
+
-[Loss of quorum]({% link {{ page.version.version }}/architecture/replication-layer.md %}#overview) of the underlying [ranges]({% link {{ page.version.version }}/architecture/reads-and-writes-overview.md %}#range) in the destination table.
41
+
- There is a unique index on the destination table (for more details, refer to [Unique seconday indexes]({% link {{ page.version.version }}/set-up-logical-data-replication.md %}#unique-secondary-indexes)).
48
42
49
43
{{site.data.alerts.callout_info}}
50
44
LDR will not pause when the writes are sent to the DLQ, you must manage the DLQ manually.
Copy file name to clipboardExpand all lines: src/current/v24.3/set-up-logical-data-replication.md
+52-13Lines changed: 52 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ If you're setting up bidirectional LDR, both clusters will act as a source and a
22
22
23
23
1. Prepare the tables on each cluster with the prerequisites for starting LDR.
24
24
1. Set up an [external connection]({% link {{ page.version.version }}/create-external-connection.md %}) on cluster B (which will be the destination cluster initially) to hold the connection URI for cluster A.
25
-
1. Start LDR from cluster B with your required modes.
25
+
1. Start LDR from cluster B with your required options.
26
26
1. (Optional) Run Steps 1 to 3 again with cluster B as the source and A as the destination, which starts LDR streaming from cluster B to A.
27
27
1. Check the status of the LDR job in the [DB Console]({% link {{ page.version.version }}/ui-overview.md %}).
28
28
@@ -36,10 +36,6 @@ You'll need:
36
36
- All nodes in each cluster will need access to the Certificate Authority for the other cluster. Refer to [Step 2. Connect from the destination to the source](#step-2-connect-from-the-destination-to-the-source).
37
37
- LDR replicates at the table level, which means clusters can contain other tables that are not part of the LDR job. If both clusters are empty, create the tables that you need to replicate with **identical** schema definitions (excluding indexes) on both clusters. If one cluster already has an existing table that you'll replicate, ensure the other cluster's table definition matches. For more details on the supported schemas, refer to [Schema Validation](#schema-validation).
38
38
39
-
{% comment %}To add later, after further dev work{{site.data.alerts.callout_info}}
40
-
If you need to run LDR through a load balancer, use the load balancer IP address as the SQL advertise address on each cluster. It is important to note that using a load balancer with LDR can impair performance.
41
-
{{site.data.alerts.end}}{% endcomment %}
42
-
43
39
To create bidirectional LDR, you can complete the [optional step](#step-4-optional-set-up-bidirectional-ldr) to start the second LDR job that sends writes from the table on cluster B to the table on cluster A.
44
40
45
41
### Schema validation
@@ -52,10 +48,60 @@ You cannot use LDR on a table with a schema that contains the following:
52
48
-[Partial indexes]({% link {{ page.version.version }}/partial-indexes.md %}) and [hash-sharded indexes]({% link {{ page.version.version }}/hash-sharded-indexes.md %})
53
49
- Indexes with a [virtual computed column]({% link {{ page.version.version }}/computed-columns.md %})
54
50
- Composite types in the [primary key]({% link {{ page.version.version }}/primary-key.md %})
51
+
-[Foreign key]({% link {{ page.version.version }}/foreign-key.md %}) dependencies
55
52
56
53
For more details, refer to the LDR [Known limitations]({% link {{ page.version.version }}/logical-data-replication-overview.md %}#known-limitations).
57
54
58
-
When you run LDR in [`immediate` mode](#modes), you cannot replicate a table with [foreign key constraints]({% link {{ page.version.version }}/foreign-key.md %}). In [`validated` mode](#modes), foreign key constraints **must** match. All constraints are enforced at the time of SQL/application write.
55
+
LDR does not support replicating a table with [foreign key constraints]({% link {{ page.version.version }}/foreign-key.md %}).
56
+
57
+
#### Unique secondary indexes
58
+
59
+
When the destination table includes unique [secondary indexes]({% link {{ page.version.version }}/schema-design-indexes.md %}), it can cause rows to enter the [_dead letter queue_ (DLQ)]({% link {{ page.version.version }}/manage-logical-data-replication.md %}). The two clusters in LDR operate independently, so writes to one cluster can conflict with writes to the other.
60
+
61
+
If the application modifies the same row in both clusters, LDR resolves the conflict using [_last write wins_ (LWW)]({% link {{ page.version.version }}/manage-logical-data-replication.md %}#conflict-resolution) conflict resolution. [`UNIQUE` constraints]({% link {{ page.version.version }}/unique.md %}) are validated locally in each cluster, therefore if a replicated write violates a `UNIQUE` constraint on the destination cluster (possibly because a conflicting write was already applied to the row) the replicating row will be applied to the DLQ.
62
+
63
+
For example, consider a table with a unique `name` column where the following operations occur in this order in a source and destination cluster running LDR:
64
+
65
+
On the **source cluster**:
66
+
67
+
{% include_cached copy-clipboard.html %}
68
+
~~~sql
69
+
-- writes to the source table
70
+
INSERT INTO city (1, nyc); -- timestamp 1
71
+
UPDATE city SET name ='philly'WHERE id =1; -- timestamp 2
72
+
INSERT INTO city (100, nyc); -- timestamp 3
73
+
~~~
74
+
75
+
LDR replicates the write to the **destination cluster**:
76
+
77
+
{% include_cached copy-clipboard.html %}
78
+
~~~sql
79
+
-- replicates to the destination table
80
+
INSERT INTO city (100, nyc); -- timestamp 4
81
+
~~~
82
+
83
+
_Timestamp 5:_[Range]({% link {{ page.version.version }}/architecture/glossary.md %}#range) containing primary key `1` on the destination cluster is unavailable for a few minutes due to a [network partition]({% link {{ page.version.version }}/cluster-setup-troubleshooting.md %}#network-partition).
84
+
85
+
_Timestamp 6:_ On the destination cluster, LDR attempts to replicate the row `(1, nyc)`, but it enters the retry queue for 1 minute due to the unavailable range. LDR adds `1, nyc` to the DLQ table after retrying and observing the `UNIQUE` constraint violation:
86
+
87
+
{% include_cached copy-clipboard.html %}
88
+
~~~sql
89
+
-- writes to the DLQ
90
+
INSERT INTO city (1, nyc); -- timestamp 6
91
+
~~~
92
+
93
+
_Timestamp 7:_ LDR continues to replicate writes:
94
+
95
+
{% include_cached copy-clipboard.html %}
96
+
~~~sql
97
+
-- replicates to the destination table
98
+
INSERT INTO city (1, philly); -- timestamp 7
99
+
~~~
100
+
101
+
To prevent expected DLQ entries and allow LDR to be eventually consistent, we recommend:
102
+
103
+
- For **unidirectional** LDR, validate unique index constraints on the source cluster only.
104
+
- For **bidirectional** LDR, remove unique index constraints on both clusters.
59
105
60
106
## Step 1. Prepare the cluster
61
107
@@ -117,20 +163,13 @@ You can use the `cockroach encode-uri` command to generate a connection string c
117
163
118
164
In this step, you'll start the LDR job from the destination cluster. You can replicate one or multiple tables in a single LDR job. You cannot replicate system tables in LDR, which means that you must manually apply configurations and cluster settings, such as [row-level TTL]({% link {{ page.version.version }}/row-level-ttl.md %}) and user permissions on the destination cluster.
119
165
120
-
<a id="modes"></a>_Modes_ determine how LDR replicates the data to the destination cluster. There are two modes:
121
-
122
-
- `immediate` (default): {% include {{ page.version.version }}/ldr/immediate-description.md %}
123
-
- `validated`: {% include {{ page.version.version }}/ldr/validated-description.md %}
124
-
125
166
1. From the **destination** cluster, start LDR. Use the fully qualified table name for the source and destination tables:
126
167
127
168
{% include_cached copy-clipboard.html %}
128
169
~~~ sql
129
170
CREATE LOGICAL REPLICATION STREAM FROM TABLE {database.public.source_table_name} ON 'external://{source_external_connection}' INTO TABLE {database.public.destination_table_name};
130
171
~~~
131
172
132
-
You can change the default `mode` using the `WITH mode = validated` syntax.
133
-
134
173
If you would like to add multiple tables to the LDR job, ensure that the table name in the source table list and destination table list are in the same order:
Copy file name to clipboardExpand all lines: src/current/v25.1/create-logical-replication-stream.md
-8Lines changed: 0 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -54,14 +54,6 @@ Option | Description
54
54
`cursor` | Emits any changes after the specified timestamp. LDR will not perform an initial backfill with the `cursor` option, it will stream any changes after the specified timestamp. The LDR job will encounter an error if you specify a `cursor` timestamp that is before the configured [garbage collection]({% link {{ page.version.version }}/architecture/storage-layer.md %}#garbage-collection) window for that table. **Warning:** Apply the `cursor` option carefully to LDR streams. Using a timestamp in error could cause data loss.
55
55
<aid="discard-ttl-deletes-option"></a>`discard` | ([**Unidirectional LDR only**]({% link {{ page.version.version }}/logical-data-replication-overview.md %}#use-cases)) Ignore [TTL deletes]({% link {{ page.version.version }}/row-level-ttl.md %}) in an LDR stream with `discard = ttl-deletes`. **Note**: To ignore row-level TTL deletes in an LDR stream, it is necessary to set the [`ttl_disable_changefeed_replication`]({% link {{ page.version.version }}/row-level-ttl.md %}#ttl-storage-parameters) storage parameter on the source table. Refer to the [Ignore row-level TTL deletes](#ignore-row-level-ttl-deletes) example.
56
56
`label` | Tracks LDR metrics at the job level. Add a user-specified string with `label`. Refer to [Metrics labels]({% link {{ page.version.version }}/logical-data-replication-monitoring.md %}#metrics-labels).
57
-
`mode` | Determines how LDR replicates the data to the destination cluster. Possible values: `immediate`, `validated`. For more details, refer to [LDR modes](#ldr-modes).
58
-
59
-
## LDR modes
60
-
61
-
_Modes_ determine how LDR replicates the data to the destination cluster. There are two modes:
62
-
63
-
-`immediate` (default): {% include {{ page.version.version }}/ldr/immediate-description.md %}
64
-
-`validated`: {% include {{ page.version.version }}/ldr/validated-description.md %}
Copy file name to clipboardExpand all lines: src/current/v25.1/create-logically-replicated.md
+1-9Lines changed: 1 addition & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -55,14 +55,6 @@ Option | Description
55
55
-------+------------
56
56
`bidirectional on` / `unidirectional` | (**Required**) Specifies whether the LDR stream will be unidirectional or bidirectional. With `bidirectional on` specified, LDR will set up two LDR streams between the clusters. Refer to the examples for [unidirectional](#unidirectional) and [bidirectional](#bidirectional).
57
57
`label` | Tracks LDR metrics at the job level. Add a user-specified string with `label`. For more details, refer to [Metrics labels]({% link {{ page.version.version }}/logical-data-replication-monitoring.md %}#metrics-labels).
58
-
`mode` | Determines how LDR replicates the data to the destination cluster. Possible values: `immediate`, `validated`. For more details, refer to [LDR modes](#ldr-modes).
59
-
60
-
## LDR modes
61
-
62
-
_Modes_ determine how LDR replicates the data to the destination cluster. There are two modes:
63
-
64
-
-`immediate` (default): {% include {{ page.version.version }}/ldr/immediate-description.md %}
65
-
-`validated`: {% include {{ page.version.version }}/ldr/validated-description.md %}
66
58
67
59
## Examples
68
60
@@ -74,7 +66,7 @@ From the destination cluster of the LDR stream, run:
74
66
75
67
{% include_cached copy-clipboard.html %}
76
68
~~~sql
77
-
CREATE LOGICALLY REPLICATED TABLE {database.public.destination_table_name} FROM TABLE {database.public.source_table_name} ON'external://source' WITH unidirectional, mode=validated;
69
+
CREATE LOGICALLY REPLICATED TABLE {database.public.destination_table_name} FROM TABLE {database.public.source_table_name} ON'external://source' WITH unidirectional;
-**Table-level replication**: When you initiate LDR, it will replicate all of the source table's existing data to the destination table. From then on, LDR will replicate the source table's data to the destination table to achieve eventual consistency.
45
45
-**Last write wins conflict resolution**: LDR uses [_last write wins (LWW)_ conflict resolution]({% link {{ page.version.version }}/manage-logical-data-replication.md %}#conflict-resolution), which will use the latest [MVCC]({% link {{ page.version.version }}/architecture/storage-layer.md %}#mvcc) timestamp to resolve a conflict in row insertion.
46
46
-**Dead letter queue (DLQ)**: When LDR starts, the job will create a [DLQ table]({% link {{ page.version.version }}/manage-logical-data-replication.md %}#dead-letter-queue-dlq) with each replicating table in order to track unresolved conflicts. You can interact and manage this table like any other SQL table.
47
-
-**Replication modes**: LDR offers different [_modes_]({% link {{ page.version.version }}/create-logical-replication-stream.md %}#ldr-modes) that apply data differently during replication, which allows you to consider optimizing for throughput or constraints during replication.
48
47
-**Monitoring**: To [monitor]({% link {{ page.version.version }}/logical-data-replication-monitoring.md %}) LDR's initial progress, current status, and performance, you can view metrics available in the DB Console, Prometheus, and Metrics Export.
0 commit comments