Re: Conflict Detection and Resolution - Mailing list pgsql-hackers
From | Amit Kapila |
---|---|
Subject | Re: Conflict Detection and Resolution |
Date | |
Msg-id | CAA4eK1Kty4mLrmpWPRMOyAzJk9m9VAWfrNB7dophjQAip17W+A@mail.gmail.com Whole thread Raw |
In response to | Re: Conflict Detection and Resolution (Dilip Kumar <dilipbalaut@gmail.com>) |
List | pgsql-hackers |
On Tue, Jun 18, 2024 at 11:34 AM Dilip Kumar <dilipbalaut@gmail.com> wrote: > > On Tue, Jun 18, 2024 at 10:17 AM Dilip Kumar <dilipbalaut@gmail.com> wrote: > > > > > > > > I think the unbounded size of the vector could be a problem to store > > > for each event. However, while researching previous discussions, it > > > came to our notice that we have discussed this topic in the past as > > > well in the context of standbys. For recovery_min_apply_delay, we > > > decided the clock skew is not a problem as the settings of this > > > parameter are much larger than typical time deviations between servers > > > as mentioned in docs. Similarly for casual reads [1], there was a > > > proposal to introduce max_clock_skew parameter and suggesting the user > > > to make sure to have NTP set up correctly. We have tried to check > > > other databases (like Ora and BDR) where CDR is implemented but didn't > > > find anything specific to clock skew. So, I propose to go with a GUC > > > like max_clock_skew such that if the difference of time between the > > > incoming transaction's commit time and the local time is more than > > > max_clock_skew then we raise an ERROR. It is not clear to me that > > > putting bigger effort into clock skew is worth especially when other > > > systems providing CDR feature (like Ora or BDR) for decades have not > > > done anything like vector clocks. It is possible that this is less of > > > a problem w.r.t CDR and just detecting the anomaly in clock skew is > > > good enough. > > > > I believe that if we've accepted this solution elsewhere, then we can > > also consider the same. Basically, we're allowing the application to > > set its tolerance for clock skew. And, if the skew exceeds that > > tolerance, it's the application's responsibility to synchronize; > > otherwise, an error will occur. This approach seems reasonable. > > This model can be further extended by making the apply worker wait if > the remote transaction's commit_ts is greater than the local > timestamp. This ensures that no local transactions occurring after the > remote transaction appear to have happened earlier due to clock skew > instead we make them happen before the remote transaction by delaying > the remote transaction apply. Essentially, by having the remote > application wait until the local timestamp matches the remote > transaction's timestamp, we ensure that the remote transaction, which > seems to occur after concurrent local transactions due to clock skew, > is actually applied after those transactions. > > With this model, there should be no ordering errors from the > application's perspective as well if synchronous commit is enabled. > The transaction initiated by the publisher cannot be completed until > it is applied to the synchronous subscriber. This ensures that if the > subscriber's clock is lagging behind the publisher's clock, the > transaction will not be applied until the subscriber's local clock is > in sync, preventing the transaction from being completed out of order. > As per the discussion, this idea will help us to resolve transaction ordering issues due to clock skew. I was thinking of having two variables max_clock_skew (indicates how much clock skew is acceptable), max_clock_skew_options: ERROR, LOG, WAIT (indicates the action we need to take once the clock skew is detected). There could be multiple ways to provide these parameters, one is providing them as GUCs, and another at the subscription or the table level. I am thinking whether users would only like to care about a table or set of tables or they would like to set such variables at the system level. We already have an SKIP option (that allows us to skip the transactions till a particular LSN) at the subscription level, so I am wondering if there is a sense to provide these new parameters related to conflict resolution also at the same level? -- With Regards, Amit Kapila.
pgsql-hackers by date: