Skip to content

Commit

Permalink
Fix PG14 failure, register label provider in Citus for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
naisila committed Nov 2, 2023
1 parent fd7c32a commit aca5abf
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
35 changes: 28 additions & 7 deletions src/backend/distributed/commands/seclabel.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
List *
PreprocessSecLabelStmt(Node *node, const char *queryString,
ProcessUtilityContext processUtilityContext)
ProcessUtilityContext processUtilityContext)
{
if (!IsCoordinator() || !ShouldPropagate())
{
Expand All @@ -37,8 +37,8 @@ PreprocessSecLabelStmt(Node *node, const char *queryString,

SecLabelStmt *secLabelStmt = castNode(SecLabelStmt, node);

List * objectAddresses = GetObjectAddressListFromParseTree(node, false, false);
if(!IsAnyObjectDistributed(objectAddresses))
List *objectAddresses = GetObjectAddressListFromParseTree(node, false, false);
if (!IsAnyObjectDistributed(objectAddresses))
{
return NIL;
}
Expand Down Expand Up @@ -70,6 +70,7 @@ PreprocessSecLabelStmt(Node *node, const char *queryString,
return NodeDDLTaskList(NON_COORDINATOR_NODES, commandList);
}


/*
* PostprocessSecLabelStmt
*/
Expand All @@ -88,8 +89,8 @@ PostprocessSecLabelStmt(Node *node, const char *queryString)
return NIL;
}

List * objectAddresses = GetObjectAddressListFromParseTree(node, false, false);
if(IsAnyObjectDistributed(objectAddresses))
List *objectAddresses = GetObjectAddressListFromParseTree(node, false, false);
if (IsAnyObjectDistributed(objectAddresses))
{
EnsureAllObjectDependenciesExistOnAllNodes(objectAddresses);
}
Expand All @@ -107,10 +108,30 @@ SecLabelStmtObjectAddress(Node *node, bool missing_ok, bool isPostprocess)
SecLabelStmt *secLabelStmt = castNode(SecLabelStmt, node);

Relation rel = NULL; /* not used, but required to pass to get_object_address */
ObjectAddress address = get_object_address(secLabelStmt->objtype, secLabelStmt->object, &rel,
AccessShareLock, missing_ok);
ObjectAddress address = get_object_address(secLabelStmt->objtype,
secLabelStmt->object, &rel,
AccessShareLock, missing_ok);

ObjectAddress *addressPtr = palloc0(sizeof(ObjectAddress));
*addressPtr = address;
return list_make1(addressPtr);
}


/*
* citus_test_object_relabel
*/
void
citus_test_object_relabel(const ObjectAddress *object, const char *seclabel)
{
if (seclabel == NULL ||
strcmp(seclabel, "citus_unclassified") == 0 ||
strcmp(seclabel, "citus_classified") == 0)
{
return;
}

ereport(ERROR,
(errcode(ERRCODE_INVALID_NAME),
errmsg("'%s' is not a valid security label for Citus tests.", seclabel)));
}
13 changes: 7 additions & 6 deletions src/backend/distributed/deparser/deparse_seclabel_stmts.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "distributed/deparser.h"
#include "nodes/parsenodes.h"
#include "utils/builtins.h"

static void AppendSecLabelStmt(StringInfo buf, SecLabelStmt *stmt);

Expand Down Expand Up @@ -41,18 +42,18 @@ AppendSecLabelStmt(StringInfo buf, SecLabelStmt *stmt)
{
appendStringInfoString(buf, "SECURITY LABEL ");

if (stmt->provider != NULL)
{
appendStringInfo(buf, "FOR %s ", stmt->provider);
}
if (stmt->provider != NULL)
{
appendStringInfo(buf, "FOR %s ", stmt->provider);
}

appendStringInfoString(buf, "ON ");

switch (stmt->objtype)
{
case OBJECT_ROLE:
{
appendStringInfo(buf, "ROLE %s ", strVal(castNode(String, stmt->object)));
appendStringInfo(buf, "ROLE %s ", strVal(stmt->object));
break;
}

Expand All @@ -67,7 +68,7 @@ AppendSecLabelStmt(StringInfo buf, SecLabelStmt *stmt)

if (stmt->label != NULL)
{
appendStringInfo(buf, "%s", stmt->label);
appendStringInfo(buf, "%s", quote_literal_cstr(stmt->label));
}
else
{
Expand Down
3 changes: 3 additions & 0 deletions src/backend/distributed/shared_library_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "citus_version.h"
#include "commands/explain.h"
#include "commands/extension.h"
#include "commands/seclabel.h"
#include "common/string.h"
#include "executor/executor.h"
#include "distributed/backend_data.h"
Expand Down Expand Up @@ -574,6 +575,8 @@ _PG_init(void)
INIT_COLUMNAR_SYMBOL(PGFunction, columnar_storage_info);
INIT_COLUMNAR_SYMBOL(PGFunction, columnar_store_memory_stats);
INIT_COLUMNAR_SYMBOL(PGFunction, test_columnar_storage_write_new_page);

register_label_provider("citus_tests_label_provider", citus_test_object_relabel);
}


Expand Down
1 change: 1 addition & 0 deletions src/include/distributed/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ extern List * PreprocessSecLabelStmt(Node *node, const char *queryString,
ProcessUtilityContext processUtilityContext);
extern List * PostprocessSecLabelStmt(Node *node, const char *queryString);
extern List * SecLabelStmtObjectAddress(Node *node, bool missing_ok, bool isPostprocess);
extern void citus_test_object_relabel(const ObjectAddress *object, const char *seclabel);

/* sequence.c - forward declarations */
extern List * PreprocessAlterSequenceStmt(Node *node, const char *queryString,
Expand Down

0 comments on commit aca5abf

Please sign in to comment.