Merged PR 1540011: [Add-node] More fixes for add-node scenarios

### Does this PR have any customer impact?
Yes

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Bugfix

### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No

### Are you introducing any new config? If yes, do you have tests with and without them being set?

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description

- Cluster Data was not replicated fully on add node (upgrades would fail)
- Checks for index wasn't handled in add-node scenarios. (Create/Drop indexes would fail)
- Get versions on the GW on MX of the added node reutrns NullRef - fix these.

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix for add-node scenarios.

#### PR Summary
This pull request addresses issues related to ensuring metadata tables are properly replicated during add-node operations.
- `distributed_hooks.c`: Refactored `EnsureMetadataTableReplicatedCore` to return a boolean and added `ExecuteMetadataChecksForReferenceTables`.
- `create_indexes_background.c`: Added checks to ensure metadata tables are replicated before starting index creation.
- `cluster_operations.c`: Ensured `cluster_data` table is replicated on all nodes during cluster setup.
- `api_hooks.c` and `api_hooks.h`: Modified `EnsureMetadataTableReplicated` to return a boolean indicating if replication occurred.
- `ExtensionVersionExtensions.cs`: Added null checks for version strings before writing them.
This commit is contained in:
Vinod Sridharan authored and Zhe Li committed 2025-01-15 07:48:39 +00:00
1 parent d3a92030fa
commit 3b609ecd8f
6 files changed
+49 -14

No files matched your search

@@ -134,6 +134,11 @@ SetupCluster(bool isInitialize)
ExtensionVersion lastUpgradeVersion = { 0 };
ExtensionVersion installedVersion = { 0 };
/* Ensure that the cluster_data table is replicated on all nodes
* otherwise, writes to cluster_data will fail.
*/
EnsureMetadataTableReplicated("collections");
char *lastUpgradeVersionString = UpdateClusterMetadata(isInitialize);
ParseVersionString(&lastUpgradeVersion, lastUpgradeVersionString);
@@ -401,14 +401,9 @@ GetDistributedApplicationNameCore(void)
}
static void
EnsureMetadataTableReplicatedCore(const char *tableName)
static bool
ExecuteMetadataChecksForReferenceTables(const char *tableName)
{
if (!EnableMetadataReferenceTableSync)
{
return;
}
/* First get the shard_id for the table */
StringInfo queryStringInfo = makeStringInfo();
appendStringInfo(queryStringInfo,
@@ -421,7 +416,7 @@ EnsureMetadataTableReplicatedCore(const char *tableName)
if (isNull)
{
return;
return false;
}
int64 shardId = DatumGetInt64(result);
@@ -432,7 +427,7 @@ EnsureMetadataTableReplicatedCore(const char *tableName)
false, SPI_OK_SELECT, &isNull);
if (isNull)
{
return;
return false;
}
int numNodes = DatumGetInt32(result);
@@ -445,7 +440,7 @@ EnsureMetadataTableReplicatedCore(const char *tableName)
&isNull);
if (isNull)
{
return;
return false;
}
int numPlacements = DatumGetInt32(result);
@@ -455,7 +450,29 @@ EnsureMetadataTableReplicatedCore(const char *tableName)
/* There was an add node but the metadata table needed wasn't replicated: Call replicate_reference_tables first */
ExtensionExecuteQueryOnLocalhostViaLibPQ(
"SELECT pg_catalog.replicate_reference_tables('block_writes')");
return true;
}
else
{
return false;
}
}
static bool
EnsureMetadataTableReplicatedCore(const char *tableName)
{
if (!EnableMetadataReferenceTableSync)
{
return false;
}
/* Set min messagees to reduce log spam in tests */
int savedGUCLevel = NewGUCNestLevel();
SetGUCLocally("client_min_messages", "WARNING");
bool result = ExecuteMetadataChecksForReferenceTables(tableName);
RollbackGUCChange(savedGUCLevel);
return result;
}