Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit aa79bde

Browse files
author
Amit Kapila
committed
Fix the missing table sync due to improper invalidation handling.
We missed performing table sync if the invalidation happened while the non-ready tables list was being prepared. This occurs because the sync state was set to valid at the end of non-ready table list preparation irrespective of the invalidations processed while the list is being prepared. Fix it by changing the boolean variable to a tri-state enum and by setting table state to valid only if no invalidations have occurred while the list is being prepared. Reprted-by: Alexander Lakhin Diagnosed-by: Alexander Lakhin Author: Vignesh C Reviewed-by: Hou Zhijie, Alexander Lakhin, Ajin Cherian, Amit Kapila Backpatch-through: 15 Discussion: https://postgr.es/m/711a6afe-edb7-1211-cc27-1bef8239eec7@gmail.com
1 parent ee3ef4a commit aa79bde

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/backend/replication/logical/tablesync.c

+21-4
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,14 @@
123123
#include "utils/syscache.h"
124124
#include "utils/usercontext.h"
125125

126-
static bool table_states_valid = false;
126+
typedef enum
127+
{
128+
SYNC_TABLE_STATE_NEEDS_REBUILD,
129+
SYNC_TABLE_STATE_REBUILD_STARTED,
130+
SYNC_TABLE_STATE_VALID,
131+
} SyncingTablesState;
132+
133+
static SyncingTablesState table_states_validity = SYNC_TABLE_STATE_NEEDS_REBUILD;
127134
static List *table_states_not_ready = NIL;
128135
static bool FetchTableStates(bool *started_tx);
129136

@@ -273,7 +280,7 @@ wait_for_worker_state_change(char expected_state)
273280
void
274281
invalidate_syncing_table_states(Datum arg, int cacheid, uint32 hashvalue)
275282
{
276-
table_states_valid = false;
283+
table_states_validity = SYNC_TABLE_STATE_NEEDS_REBUILD;
277284
}
278285

279286
/*
@@ -1568,13 +1575,15 @@ FetchTableStates(bool *started_tx)
15681575

15691576
*started_tx = false;
15701577

1571-
if (!table_states_valid)
1578+
if (table_states_validity != SYNC_TABLE_STATE_VALID)
15721579
{
15731580
MemoryContext oldctx;
15741581
List *rstates;
15751582
ListCell *lc;
15761583
SubscriptionRelState *rstate;
15771584

1585+
table_states_validity = SYNC_TABLE_STATE_REBUILD_STARTED;
1586+
15781587
/* Clean the old lists. */
15791588
list_free_deep(table_states_not_ready);
15801589
table_states_not_ready = NIL;
@@ -1608,7 +1617,15 @@ FetchTableStates(bool *started_tx)
16081617
has_subrels = (table_states_not_ready != NIL) ||
16091618
HasSubscriptionRelations(MySubscription->oid);
16101619

1611-
table_states_valid = true;
1620+
/*
1621+
* If the subscription relation cache has been invalidated since we
1622+
* entered this routine, we still use and return the relations we just
1623+
* finished constructing, to avoid infinite loops, but we leave the
1624+
* table states marked as stale so that we'll rebuild it again on next
1625+
* access. Otherwise, we mark the table states as valid.
1626+
*/
1627+
if (table_states_validity == SYNC_TABLE_STATE_REBUILD_STARTED)
1628+
table_states_validity = SYNC_TABLE_STATE_VALID;
16121629
}
16131630

16141631
return has_subrels;

src/tools/pgindent/typedefs.list

+1
Original file line numberDiff line numberDiff line change
@@ -2764,6 +2764,7 @@ SupportRequestSelectivity
27642764
SupportRequestSimplify
27652765
SupportRequestWFuncMonotonic
27662766
Syn
2767+
SyncingTablesState
27672768
SyncOps
27682769
SyncRepConfigData
27692770
SyncRepStandbyData

0 commit comments

Comments
 (0)