Hi,
> I don't think the two lines need to name the same relation, because
> they report different things. The CONTEXT describes the change as it
> arrived: it is set from the map entry of the relation named in the
> replication message, before tuple routing picks a partition. The ERROR
> reports the relation that failed the check, which for a routed change
> is the leaf partition. Both are subscriber relations, so "target" fits
> both.
>
> This is also what the apply worker already does elsewhere for routed
> changes. Conflict reports name the leaf partition while the CONTEXT
> names the replicated table; for example, 013_partition.pl checks for
> 'conflict detected on relation "public.tab1_2_2"', and tab1_2_2 exists
> only on the subscriber. CheckSubscriptionTargetRel() also reports the
> leaf partition. With 0001, check_relation_updatable() behaves the same
> way.
Thanks for the detailed description. I have never considered the theory and you
sound right.
One small comment:
```
+$node_subscriber2->wait_for_log(
+ qr/ERROR: ( [A-Z0-9]+:)? logical replication target relation "[^"]+"
has neither REPLICA IDENTITY index nor PRIMARY KEY/,
+ $log_location);
+
+$logfile = slurp_file($node_subscriber2->logfile(), $log_location);
+like(
+ $logfile,
+ qr/logical replication target relation "public.tab5_1" has neither
REPLICA IDENTITY index nor PRIMARY KEY/,
+ 'error names the leaf partition that has no replica identity');
```
This looks redundant because similar lines appear twice at near place.
How about using an error pattern and extract the relation's name? It's clearer
where is a problem.
(might be matter of taste)
```
my $err_pattern =
qr/ERROR: (?: [A-Z0-9]+:)? logical replication target relation "([^"]+)" has
neither REPLICA IDENTITY index nor PRIMARY KEY/;
$node_subscriber2->wait_for_log($err_pattern, $log_location);
$logfile = slurp_file($node_subscriber2->logfile(), $log_location);
my ($reported_relation) = $logfile =~ $err_pattern;
is($reported_relation, 'public.tab5_1',
'error names the leaf partition that has no replica identity');
```
Best regards,
Hayato Kuroda
FUJITSU LIMITED