Fixes compile errors

create_drop_db_gh
gindibay 2023-09-23 13:28:49 +03:00
parent ae9cd9c895
commit 8c93c65351
8 changed files with 59 additions and 23 deletions

View File

@ -24,6 +24,7 @@
#include "distributed/deparse_shard_query.h" #include "distributed/deparse_shard_query.h"
#include "distributed/listutils.h" #include "distributed/listutils.h"
#include "distributed/metadata_sync.h" #include "distributed/metadata_sync.h"
#include "distributed/pooler/pgbouncer_manager.h"
#include "distributed/remote_commands.h" #include "distributed/remote_commands.h"
#include "distributed/shared_library_init.h" #include "distributed/shared_library_init.h"
#include "distributed/worker_transaction.h" #include "distributed/worker_transaction.h"
@ -80,7 +81,7 @@ PreProcessUtilityInDatabaseShard(Node *parseTree, const char *queryString,
{ {
if (IsA(parseTree, CreatedbStmt)) if (IsA(parseTree, CreatedbStmt))
{ {
char *command = DeparseCreatedbStmt(parseTree); char *command = DeparseCreateDatabaseStmt(parseTree);
ExecuteCommandInControlDatabase(command); ExecuteCommandInControlDatabase(command);
/* command is fully delegated to control database */ /* command is fully delegated to control database */
@ -88,7 +89,7 @@ PreProcessUtilityInDatabaseShard(Node *parseTree, const char *queryString,
} }
else if (IsA(parseTree, DropdbStmt)) else if (IsA(parseTree, DropdbStmt))
{ {
char *command = DeparseDropdbStmt(parseTree); char *command = DeparseDropDatabaseStmt(parseTree);
ExecuteCommandInControlDatabase(command); ExecuteCommandInControlDatabase(command);
/* command is fully delegated to control database */ /* command is fully delegated to control database */

View File

@ -196,18 +196,6 @@ DeparseAlterDatabaseSetStmt(Node *node)
return str.data; return str.data;
} }
char *
DeparseCreateDatabaseSetStmt(Node *node)
{
CreatedbStmt *stmt = castNode(CreatedbStmt, node);
StringInfoData str = {0};
initStringInfo(&str);
AppendCreatedbStmt(&str, stmt);
return str.data;
}
static void static void
AppendCreatedbStmt(StringInfo buf, CreatedbStmt *stmt) AppendCreatedbStmt(StringInfo buf, CreatedbStmt *stmt)
{ {
@ -338,18 +326,17 @@ AppendCreatedbStmt(StringInfo buf, CreatedbStmt *stmt)
} }
char * char *
DeparseDropDatabaseStmt(Node *node) DeparseCreateDatabaseStmt(Node *node)
{ {
DropdbStmt *stmt = castNode(DropdbStmt, node); CreatedbStmt *stmt = castNode(CreatedbStmt, node);
StringInfoData str = {0}; StringInfoData str = {0};
initStringInfo(&str); initStringInfo(&str);
AppendDropDatabaseStmt(&str, stmt); AppendCreatedbStmt(&str, stmt);
return str.data; return str.data;
} }
static void static void
AppendDropDatabaseStmt(StringInfo buf, DropdbStmt *stmt) AppendDropDatabaseStmt(StringInfo buf, DropdbStmt *stmt)
{ {
@ -373,3 +360,18 @@ AppendDropDatabaseStmt(StringInfo buf, DropdbStmt *stmt)
} }
} }
} }
char *
DeparseDropDatabaseStmt(Node *node)
{
DropdbStmt *stmt = castNode(DropdbStmt, node);
StringInfoData str = { 0 };
initStringInfo(&str);
AppendDropDatabaseStmt(&str, stmt);
return str.data;
}

View File

@ -53,7 +53,7 @@
static char * CreatePgDistObjectEntryCommand(const ObjectAddress *objectAddress); static char * CreatePgDistObjectEntryCommand(const ObjectAddress *objectAddress);
static int ExecuteCommandAsSuperuser(char *query, int paramCount, Oid *paramTypes, static int ExecuteCommandAsSuperuser(char *query, int paramCount, Oid *paramTypes,
Datum *paramValues); Datum *paramValues);
static bool IsObjectDistributed(const ObjectAddress *address); bool IsObjectDistributed(const ObjectAddress *address);
PG_FUNCTION_INFO_V1(citus_unmark_object_distributed); PG_FUNCTION_INFO_V1(citus_unmark_object_distributed);
PG_FUNCTION_INFO_V1(master_unmark_object_distributed); PG_FUNCTION_INFO_V1(master_unmark_object_distributed);
@ -392,7 +392,7 @@ UnmarkObjectDistributed(const ObjectAddress *address)
* IsObjectDistributed returns if the object addressed is already distributed in the * IsObjectDistributed returns if the object addressed is already distributed in the
* cluster. This performs a local indexed lookup in pg_dist_object. * cluster. This performs a local indexed lookup in pg_dist_object.
*/ */
static bool bool
IsObjectDistributed(const ObjectAddress *address) IsObjectDistributed(const ObjectAddress *address)
{ {
ScanKeyData key[3]; ScanKeyData key[3];

View File

@ -182,6 +182,8 @@ typedef struct MetadataCacheData
Oid citusTaskStatusUnscheduledId; Oid citusTaskStatusUnscheduledId;
Oid citusTaskStatusCancelledId; Oid citusTaskStatusCancelledId;
Oid citusTaskStatusCancellingId; Oid citusTaskStatusCancellingId;
Oid databaseShardRelationId;
Oid databaseShardPKeyIndexId;
Oid distRebalanceStrategyRelationId; Oid distRebalanceStrategyRelationId;
Oid distNodeRelationId; Oid distNodeRelationId;
Oid distNodeNodeIdIndexId; Oid distNodeNodeIdIndexId;
@ -2769,12 +2771,34 @@ DistRebalanceStrategyRelationId(void)
return MetadataCache.distRebalanceStrategyRelationId; return MetadataCache.distRebalanceStrategyRelationId;
} }
/* return oid of citus_catalog.database_sharding relation */
Oid
DatabaseShardRelationId(void)
{
CachedRelationNamespaceLookup("database_shard", CitusCatalogNamespaceId(),
&MetadataCache.databaseShardRelationId);
return MetadataCache.databaseShardRelationId;
}
/* return oid of citus_catalog.database_sharding primary key */
Oid
DatabaseShardPrimaryKeyIndexId(void)
{
CachedRelationNamespaceLookup("database_shard_pkey", CitusCatalogNamespaceId(),
&MetadataCache.databaseShardPKeyIndexId);
return MetadataCache.databaseShardPKeyIndexId;
}
/* return the oid of citus namespace */ /* return the oid of citus namespace */
Oid Oid
CitusCatalogNamespaceId(void) CitusCatalogNamespaceId(void)
{ {
CachedNamespaceLookup("citus", &MetadataCache.citusCatalogNamespaceId); CachedNamespaceLookup("citus_catalog", &MetadataCache.citusCatalogNamespaceId);
return MetadataCache.citusCatalogNamespaceId; return MetadataCache.citusCatalogNamespaceId;
} }
@ -2805,12 +2829,14 @@ DistObjectRelationId(void)
true); true);
if (!OidIsValid(MetadataCache.distObjectRelationId)) if (!OidIsValid(MetadataCache.distObjectRelationId))
{ {
Oid citusNamespaceId = get_namespace_oid("citus", false);
/* /*
* We can only ever reach here while we are creating/altering our extension before * We can only ever reach here while we are creating/altering our extension before
* the table is moved to pg_catalog. * the table is moved to pg_catalog.
*/ */
CachedRelationNamespaceLookupExtended("pg_dist_object", CachedRelationNamespaceLookupExtended("pg_dist_object",
CitusCatalogNamespaceId(), citusNamespaceId,
&MetadataCache.distObjectRelationId, &MetadataCache.distObjectRelationId,
false); false);
} }

View File

@ -172,6 +172,8 @@ static GucStringAssignHook OldApplicationNameAssignHook = NULL;
*/ */
static bool FinishedStartupCitusBackend = false; static bool FinishedStartupCitusBackend = false;
char *CitusMainDatabase = "postgres";
static object_access_hook_type PrevObjectAccessHook = NULL; static object_access_hook_type PrevObjectAccessHook = NULL;
#if PG_VERSION_NUM >= PG_VERSION_15 #if PG_VERSION_NUM >= PG_VERSION_15

View File

@ -40,6 +40,7 @@ typedef enum
extern PropSetCmdBehavior PropagateSetCommands; extern PropSetCmdBehavior PropagateSetCommands;
extern bool EnableDDLPropagation; extern bool EnableDDLPropagation;
extern int CreateObjectPropagationMode; extern int CreateObjectPropagationMode;
extern bool EnableCreateDatabasePropagation;
extern bool EnableCreateTypePropagation; extern bool EnableCreateTypePropagation;
extern bool EnableCreateRolePropagation; extern bool EnableCreateRolePropagation;
extern bool EnableAlterRolePropagation; extern bool EnableAlterRolePropagation;

View File

@ -247,6 +247,7 @@ extern Oid DistLocalGroupIdRelationId(void);
extern Oid DistObjectRelationId(void); extern Oid DistObjectRelationId(void);
extern Oid DistEnabledCustomAggregatesId(void); extern Oid DistEnabledCustomAggregatesId(void);
extern Oid DistTenantSchemaRelationId(void); extern Oid DistTenantSchemaRelationId(void);
extern Oid DatabaseShardRelationId(void);
/* index oids */ /* index oids */
extern Oid DistNodeNodeIdIndexId(void); extern Oid DistNodeNodeIdIndexId(void);
@ -271,6 +272,7 @@ extern Oid DistObjectPrimaryKeyIndexId(void);
extern Oid DistCleanupPrimaryKeyIndexId(void); extern Oid DistCleanupPrimaryKeyIndexId(void);
extern Oid DistTenantSchemaPrimaryKeyIndexId(void); extern Oid DistTenantSchemaPrimaryKeyIndexId(void);
extern Oid DistTenantSchemaUniqueColocationIdIndexId(void); extern Oid DistTenantSchemaUniqueColocationIdIndexId(void);
extern Oid DatabaseShardPrimaryKeyIndexId(void);
/* sequence oids */ /* sequence oids */
extern Oid DistBackgroundJobJobIdSequenceId(void); extern Oid DistBackgroundJobJobIdSequenceId(void);

View File

@ -17,6 +17,8 @@
#define MAX_SHARD_COUNT 64000 #define MAX_SHARD_COUNT 64000
#define MAX_SHARD_REPLICATION_FACTOR 100 #define MAX_SHARD_REPLICATION_FACTOR 100
extern char *CitusMainDatabase;
extern PGDLLEXPORT ColumnarSupportsIndexAM_type extern_ColumnarSupportsIndexAM; extern PGDLLEXPORT ColumnarSupportsIndexAM_type extern_ColumnarSupportsIndexAM;
extern PGDLLEXPORT CompressionTypeStr_type extern_CompressionTypeStr; extern PGDLLEXPORT CompressionTypeStr_type extern_CompressionTypeStr;
extern PGDLLEXPORT IsColumnarTableAmTable_type extern_IsColumnarTableAmTable; extern PGDLLEXPORT IsColumnarTableAmTable_type extern_IsColumnarTableAmTable;