Re: Conflict detection and logging in logical replication
shveta malik <shveta.malik@gmail.com>
From: shveta malik <shveta.malik@gmail.com>
To: "Zhijie Hou (Fujitsu)" <houzj.fnst@fujitsu.com>
Cc: Nisha Moond <nisha.moond412@gmail.com>,
pgsql-hackers <pgsql-hackers@postgresql.org>, Dilip Kumar <dilipbalaut@gmail.com>, Jan Wieck <jan@wi3ck.info>, Tomas Vondra <tomas.vondra@enterprisedb.com>,
Amit Kapila <amit.kapila16@gmail.com>, Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>,
shveta malik <shveta.malik@gmail.com>
Date: 2024-07-11T09:06:13Z
Lists: pgsql-hackers
On Wed, Jul 10, 2024 at 3:09 PM shveta malik <shveta.malik@gmail.com> wrote: > > On Wed, Jul 3, 2024 at 8:31 AM Zhijie Hou (Fujitsu) > <houzj.fnst@fujitsu.com> wrote: > > > > On Wednesday, June 26, 2024 10:58 AM Zhijie Hou (Fujitsu) <houzj.fnst@fujitsu.com> wrote: > > > > > > > Hi, > > > > As suggested by Sawada-san in another thread[1]. > > > > I am attaching the V4 patch set which tracks the delete_differ > > conflict in logical replication. > > > > delete_differ means that the replicated DELETE is deleting a row > > that was modified by a different origin. > > Thanks for the patch. please find few comments for patch002: 1) Commit msg says: The conflicts will be tracked only when track_conflict option of the subscription is enabled. track_conflict --> detect_conflict 2) monitoring.sgml: Below are my suggestions, please change if you feel apt. 2a) insert_exists_count : Number of times inserting a row that violates a NOT DEFERRABLE unique constraint while applying changes. Suggestion: Number of times a row insertion violated a NOT DEFERRABLE unique constraint while applying changes. 2b) update_differ_count : Number of times updating a row that was previously modified by another source while applying changes. Suggestion: Number of times update was performed on a row that was previously modified by another source while applying changes. 2c) delete_differ_count: Number of times deleting a row that was previously modified by another source while applying changes. Suggestion: Number of times delete was performed on a row that was previously modified by another source while applying changes. 2d) To be consistent, we can change 'is not found' to 'was not found' in update_missing_count , delete_missing_count cases as well. 3) create_subscription.sgml has: When conflict detection is enabled, additional logging is triggered and the conflict statistics are collected in the following scenarios: --Can we rephrase a little and link pg_stat_subscription_stats structure here for reference. 4) IIUC, conflict_count array (in pgstat.h) maps directly to ConflictType enum. So if the order of entries ever changes in this enum, without changing it in pg_stat_subscription_stats and pg_proc, we may get wrong values under each column when querying pg_stat_subscription_stats. If so, then perhaps it is good to add a comment atop ConflictType that if someone changes this order, order in other files too needs to be changed. 5) conflict.h:CONFLICT_NUM_TYPES --Shall the macro be CONFLICT_TYPES_NUM instead? 6) pgstatsfuncs.c ----- /* conflict count */ for (int i = 0; i < CONFLICT_NUM_TYPES; i++) values[3 + i] = Int64GetDatum(subentry->conflict_count[i]); /* stats_reset */ if (subentry->stat_reset_timestamp == 0) nulls[8] = true; else values[8] = TimestampTzGetDatum(subentry->stat_reset_timestamp); ----- After setting values for [3+i], we abruptly had [8]. I think it will be better to use i++ to increment values' index. And at the end, we can check if it reached 'PG_STAT_GET_SUBSCRIPTION_STATS_COLS'. thanks Shveta
Commits
-
Rename the conflict types for the origin differ cases.
- 640178c92e3f 18.0 landed
-
Doc: explain the log format of logical replication conflicts.
- edcb71258504 18.0 landed
-
Log the conflicts while applying changes in logical replication.
- 9758174e2e5c 18.0 landed
-
Avoid duplicate table scans for cross-partition updates during logical replication.
- a67da49e1d98 18.0 cited