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

Commit 7b37823

Browse files
committed
Expand AclMode to 64 bits
We're running out of bits for new permissions. This change doubles the number of permissions we can accomodate from 16 to 32, so the forthcoming new ones for vacuum/analyze don't exhaust the pool. Nathan Bossart Reviewed by: Bharath Rupireddy, Kyotaro Horiguchi, Stephen Frost, Robert Haas, Mark Dilger, Tom Lane, Corey Huinker, David G. Johnston, Michael Paquier. Discussion: https://postgr.es/m/20220722203735.GB3996698@nathanxps13
1 parent b607484 commit 7b37823

File tree

6 files changed

+56
-21
lines changed

6 files changed

+56
-21
lines changed

src/backend/nodes/outfuncs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ _outRangeTblEntry(StringInfo str, const RangeTblEntry *node)
560560
WRITE_BOOL_FIELD(lateral);
561561
WRITE_BOOL_FIELD(inh);
562562
WRITE_BOOL_FIELD(inFromCl);
563-
WRITE_UINT_FIELD(requiredPerms);
563+
WRITE_UINT64_FIELD(requiredPerms);
564564
WRITE_OID_FIELD(checkAsUser);
565565
WRITE_BITMAPSET_FIELD(selectedCols);
566566
WRITE_BITMAPSET_FIELD(insertedCols);

src/bin/pg_upgrade/check.c

+35
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static void check_for_incompatible_polymorphics(ClusterInfo *cluster);
2828
static void check_for_tables_with_oids(ClusterInfo *cluster);
2929
static void check_for_composite_data_type_usage(ClusterInfo *cluster);
3030
static void check_for_reg_data_type_usage(ClusterInfo *cluster);
31+
static void check_for_aclitem_data_type_usage(ClusterInfo *cluster);
3132
static void check_for_jsonb_9_4_usage(ClusterInfo *cluster);
3233
static void check_for_pg_role_prefix(ClusterInfo *cluster);
3334
static void check_for_new_tablespace_dir(ClusterInfo *new_cluster);
@@ -107,6 +108,13 @@ check_and_dump_old_cluster(bool live_check)
107108
check_for_reg_data_type_usage(&old_cluster);
108109
check_for_isn_and_int8_passing_mismatch(&old_cluster);
109110

111+
/*
112+
* PG 16 increased the size of the 'aclitem' type, which breaks the on-disk
113+
* format for existing data.
114+
*/
115+
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 1500)
116+
check_for_aclitem_data_type_usage(&old_cluster);
117+
110118
/*
111119
* PG 14 changed the function signature of encoding conversion functions.
112120
* Conversions from older versions cannot be upgraded automatically
@@ -1319,6 +1327,33 @@ check_for_reg_data_type_usage(ClusterInfo *cluster)
13191327
check_ok();
13201328
}
13211329

1330+
/*
1331+
* check_for_aclitem_data_type_usage
1332+
*
1333+
* aclitem changed its storage format in 16, so check for it.
1334+
*/
1335+
static void
1336+
check_for_aclitem_data_type_usage(ClusterInfo *cluster)
1337+
{
1338+
char output_path[MAXPGPATH];
1339+
1340+
prep_status("Checking for incompatible aclitem data type in user tables");
1341+
1342+
snprintf(output_path, sizeof(output_path), "tables_using_aclitem.txt");
1343+
1344+
if (check_for_data_type_usage(cluster, "pg_catalog.aclitem", output_path))
1345+
{
1346+
pg_log(PG_REPORT, "fatal");
1347+
pg_fatal("Your installation contains the \"aclitem\" data type in user tables.\n"
1348+
"The internal format of \"aclitem\" changed in PostgreSQL version 16\n"
1349+
"so this cluster cannot currently be upgraded. You can drop the\n"
1350+
"problem columns and restart the upgrade. A list of the problem\n"
1351+
"columns is in the file:\n"
1352+
" %s", output_path);
1353+
}
1354+
else
1355+
check_ok();
1356+
}
13221357

13231358
/*
13241359
* check_for_jsonb_9_4_usage()

src/include/catalog/catversion.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
*/
5858

5959
/* yyyymmddN */
60-
#define CATALOG_VERSION_NO 202211211
60+
#define CATALOG_VERSION_NO 202211221
6161

6262
#endif

src/include/catalog/pg_type.dat

+2-2
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@
267267
# OIDS 1000 - 1099
268268

269269
{ oid => '1033', array_type_oid => '1034', descr => 'access control list',
270-
typname => 'aclitem', typlen => '12', typbyval => 'f', typcategory => 'U',
270+
typname => 'aclitem', typlen => '16', typbyval => 'f', typcategory => 'U',
271271
typinput => 'aclitemin', typoutput => 'aclitemout', typreceive => '-',
272-
typsend => '-', typalign => 'i' },
272+
typsend => '-', typalign => 'd' },
273273
{ oid => '1042', array_type_oid => '1014',
274274
descr => 'char(length), blank-padded string, fixed storage length',
275275
typname => 'bpchar', typlen => '-1', typbyval => 'f', typcategory => 'S',

src/include/nodes/parsenodes.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ typedef enum SetQuantifier
7373

7474
/*
7575
* Grantable rights are encoded so that we can OR them together in a bitmask.
76-
* The present representation of AclItem limits us to 16 distinct rights,
77-
* even though AclMode is defined as uint32. See utils/acl.h.
76+
* The present representation of AclItem limits us to 32 distinct rights,
77+
* even though AclMode is defined as uint64. See utils/acl.h.
7878
*
7979
* Caution: changing these codes breaks stored ACLs, hence forces initdb.
8080
*/
81-
typedef uint32 AclMode; /* a bitmask of privilege bits */
81+
typedef uint64 AclMode; /* a bitmask of privilege bits */
8282

8383
#define ACL_INSERT (1<<0) /* for relations */
8484
#define ACL_SELECT (1<<1)

src/include/utils/acl.h

+14-14
Original file line numberDiff line numberDiff line change
@@ -59,33 +59,33 @@ typedef struct AclItem
5959
} AclItem;
6060

6161
/*
62-
* The upper 16 bits of the ai_privs field of an AclItem are the grant option
63-
* bits, and the lower 16 bits are the actual privileges. We use "rights"
62+
* The upper 32 bits of the ai_privs field of an AclItem are the grant option
63+
* bits, and the lower 32 bits are the actual privileges. We use "rights"
6464
* to mean the combined grant option and privilege bits fields.
6565
*/
66-
#define ACLITEM_GET_PRIVS(item) ((item).ai_privs & 0xFFFF)
67-
#define ACLITEM_GET_GOPTIONS(item) (((item).ai_privs >> 16) & 0xFFFF)
66+
#define ACLITEM_GET_PRIVS(item) ((item).ai_privs & 0xFFFFFFFF)
67+
#define ACLITEM_GET_GOPTIONS(item) (((item).ai_privs >> 32) & 0xFFFFFFFF)
6868
#define ACLITEM_GET_RIGHTS(item) ((item).ai_privs)
6969

70-
#define ACL_GRANT_OPTION_FOR(privs) (((AclMode) (privs) & 0xFFFF) << 16)
71-
#define ACL_OPTION_TO_PRIVS(privs) (((AclMode) (privs) >> 16) & 0xFFFF)
70+
#define ACL_GRANT_OPTION_FOR(privs) (((AclMode) (privs) & 0xFFFFFFFF) << 32)
71+
#define ACL_OPTION_TO_PRIVS(privs) (((AclMode) (privs) >> 32) & 0xFFFFFFFF)
7272

7373
#define ACLITEM_SET_PRIVS(item,privs) \
74-
((item).ai_privs = ((item).ai_privs & ~((AclMode) 0xFFFF)) | \
75-
((AclMode) (privs) & 0xFFFF))
74+
((item).ai_privs = ((item).ai_privs & ~((AclMode) 0xFFFFFFFF)) | \
75+
((AclMode) (privs) & 0xFFFFFFFF))
7676
#define ACLITEM_SET_GOPTIONS(item,goptions) \
77-
((item).ai_privs = ((item).ai_privs & ~(((AclMode) 0xFFFF) << 16)) | \
78-
(((AclMode) (goptions) & 0xFFFF) << 16))
77+
((item).ai_privs = ((item).ai_privs & ~(((AclMode) 0xFFFFFFFF) << 32)) | \
78+
(((AclMode) (goptions) & 0xFFFFFFFF) << 32))
7979
#define ACLITEM_SET_RIGHTS(item,rights) \
8080
((item).ai_privs = (AclMode) (rights))
8181

8282
#define ACLITEM_SET_PRIVS_GOPTIONS(item,privs,goptions) \
83-
((item).ai_privs = ((AclMode) (privs) & 0xFFFF) | \
84-
(((AclMode) (goptions) & 0xFFFF) << 16))
83+
((item).ai_privs = ((AclMode) (privs) & 0xFFFFFFFF) | \
84+
(((AclMode) (goptions) & 0xFFFFFFFF) << 32))
8585

8686

87-
#define ACLITEM_ALL_PRIV_BITS ((AclMode) 0xFFFF)
88-
#define ACLITEM_ALL_GOPTION_BITS ((AclMode) 0xFFFF << 16)
87+
#define ACLITEM_ALL_PRIV_BITS ((AclMode) 0xFFFFFFFF)
88+
#define ACLITEM_ALL_GOPTION_BITS ((AclMode) 0xFFFFFFFF << 32)
8989

9090
/*
9191
* Definitions for convenient access to Acl (array of AclItem).

0 commit comments

Comments
 (0)