Skip to content

Commit

Permalink
[#25375] YSQL: fix leading_whitespace lint errors
Browse files Browse the repository at this point in the history
Summary:
1. Blacklist some upstream postgres files that do not properly follow
   the leading_whitespace rule.
1. Fix all leading_whitespace lint errors.  This involves some other
   lint fixes in the area of those fixes.
Jira: DB-14604

Test Plan:
On Almalinux 8, zsh:

    [ -z "$(git ls-tree --name-only -rz HEAD -- src/postgres \
            | xargs -0 arc lint \
            | grep leading_whitespace)" ]

Close: #25375
Jenkins: compile only

Reviewers: patnaik.balivada

Reviewed By: patnaik.balivada

Subscribers: patnaik.balivada, ycdcxcluster, yql

Differential Revision: https://phorge.dev.yugabyte.com/D40786
  • Loading branch information
jaki committed Dec 19, 2024
1 parent 429547f commit f0f54c4
Show file tree
Hide file tree
Showing 74 changed files with 1,116 additions and 1,060 deletions.
20 changes: 8 additions & 12 deletions src/postgres/src/backend/access/heap/heapam.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,9 @@ heapgetpage(TableScanDesc sscan, BlockNumber page)
lineoff <= lines;
lineoff++, lpp++)
{
if (ItemIdIsNormal(lpp))
if (ItemIdIsNormal(lpp))
{
HeapTupleData loctup;
HeapTupleData loctup;
bool valid;

loctup.t_tableOid = RelationGetRelid(scan->rs_base.rs_rd);
Expand Down Expand Up @@ -2071,12 +2071,10 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid,
bool all_visible_cleared = false;

if (IsYBRelation(relation))
{
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR), errmsg(
"Operation not allowed in YugaByte mode %s",
__func__)));
}
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("Operation not allowed in YugaByte mode %s",
__func__)));

/* Cheap, simplistic check that the tuple matches the rel's rowtype. */
Assert(HeapTupleHeaderGetNatts(tup->t_data) <=
Expand Down Expand Up @@ -2327,11 +2325,9 @@ heap_multi_insert(Relation relation, TupleTableSlot **slots, int ntuples,
bool need_cids = RelationIsAccessibleInLogicalDecoding(relation);

if (IsYBRelation(relation))
{
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("Operation not allowed in YugaByte mode")));
}
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("Operation not allowed in YugaByte mode")));

/* currently not needed (thus unsupported) for heap_multi_insert() */
AssertArg(!(options & HEAP_INSERT_NO_LOGICAL));
Expand Down Expand Up @@ -2740,7 +2736,7 @@ heap_delete(Relation relation, ItemPointer tid,
if (IsYBRelation(relation))
{
YBC_LOG_WARNING("Ignoring unsupported tuple delete for rel %s",
RelationGetRelationName(relation));
RelationGetRelationName(relation));
return TM_Ok; /* HeapTupleMayBeUpdated; */
}

Expand Down
12 changes: 5 additions & 7 deletions src/postgres/src/backend/access/index/genam.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,12 @@ systable_beginscan(Relation heapRelation,
Relation irel;

if (IsYugaByteEnabled())
{
return ybc_systable_beginscan(heapRelation,
indexId,
indexOK,
snapshot,
nkeys,
key);
}
indexId,
indexOK,
snapshot,
nkeys,
key);

if (indexOK &&
!IgnoreSystemIndexes &&
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/src/backend/access/index/indexam.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ do { \
#define CHECK_REL_PROCEDURE2(pname1, pname2) \
do { \
if (indexRelation->rd_indam->pname1 == NULL && \
indexRelation->rd_indam->pname2 == NULL) \
indexRelation->rd_indam->pname2 == NULL) \
elog(ERROR, "functions %s/%s are not defined for index %s", \
CppAsString(pname1), CppAsString(pname2), RelationGetRelationName(indexRelation)); \
} while(0)
Expand Down
45 changes: 23 additions & 22 deletions src/postgres/src/backend/bootstrap/ybcbootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ static void YBCAddSysCatalogColumns(YBCPgStatement yb_stmt,
}
}

void YBCCreateSysCatalogTable(const char *table_name,
Oid table_oid,
TupleDesc tupdesc,
bool is_shared_relation,
IndexStmt *pkey_idx)
void
YBCCreateSysCatalogTable(const char *table_name,
Oid table_oid,
TupleDesc tupdesc,
bool is_shared_relation,
IndexStmt *pkey_idx)
{
/* Database and schema are fixed when running inidb. */
Assert(IsBootstrapProcessingMode());
Expand All @@ -121,23 +122,23 @@ void YBCCreateSysCatalogTable(const char *table_name,
: PG_YBROWID_MODE_NONE);

HandleYBStatus(YBCPgNewCreateTable(db_name,
schema_name,
table_name,
Template1DbOid,
table_oid,
is_shared_relation,
true /* is_sys_catalog_table */,
false, /* if_not_exists */
ybrowid_mode,
true, /* is_colocated_via_database */
InvalidOid /* tablegroup_oid */,
InvalidOid /* colocation_id */,
InvalidOid /* tablespace_oid */,
false /* is_matview */,
InvalidOid /* pg_table_oid */,
InvalidOid /* old_relfilenode_oid */,
false /* is_truncate */,
&yb_stmt));
schema_name,
table_name,
Template1DbOid,
table_oid,
is_shared_relation,
true /* is_sys_catalog_table */,
false, /* if_not_exists */
ybrowid_mode,
true, /* is_colocated_via_database */
InvalidOid /* tablegroup_oid */,
InvalidOid /* colocation_id */,
InvalidOid /* tablespace_oid */,
false /* is_matview */,
InvalidOid /* pg_table_oid */,
InvalidOid /* old_relfilenode_oid */,
false /* is_truncate */,
&yb_stmt));

/* Add all key columns first, then the regular columns */
if (pkey_idx != NULL)
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/src/backend/catalog/aclchk.c
Original file line number Diff line number Diff line change
Expand Up @@ -5024,7 +5024,7 @@ pg_tablegroup_aclmask(Oid grp_oid, Oid roleid,
if (!HeapTupleIsValid(tuple))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("tablegroup with OID %u does not exist", grp_oid)));
errmsg("tablegroup with OID %u does not exist", grp_oid)));

ownerId = ((Form_pg_yb_tablegroup) GETSTRUCT(tuple))->grpowner;

Expand Down
7 changes: 4 additions & 3 deletions src/postgres/src/backend/catalog/dependency.c
Original file line number Diff line number Diff line change
Expand Up @@ -1375,9 +1375,10 @@ deleteOneObject(const ObjectAddress *object, Relation *depRel, int flags)
Form_pg_depend depform = (Form_pg_depend) GETSTRUCT(tup);
CatalogTupleDelete(*depRel, tup);

if (MyDatabaseColocated && depform->refclassid == YbTablegroupRelationId &&
!tablegroupHasDependents(depform->refobjid))
{
if (MyDatabaseColocated &&
depform->refclassid == YbTablegroupRelationId &&
!tablegroupHasDependents(depform->refobjid))
{
implicit_tablegroup.classId = depform->refclassid;
implicit_tablegroup.objectId = depform->refobjid;
implicit_tablegroup.objectSubId = depform->refobjsubid;
Expand Down
6 changes: 3 additions & 3 deletions src/postgres/src/backend/catalog/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ YbSetInitdbPermissions(Oid relid, char relkind, bool relisshared)
ACL_MODECHG_EQL, BOOTSTRAP_SUPERUSERID, DROP_RESTRICT);

Acl *superuser_default =
acldefault(relkind == RELKIND_SEQUENCE ? OBJECT_SEQUENCE
acldefault(relkind == RELKIND_SEQUENCE ? OBJECT_SEQUENCE
: OBJECT_TABLE,
BOOTSTRAP_SUPERUSERID);

Expand Down Expand Up @@ -1401,7 +1401,7 @@ heap_create_with_catalog(const char *relname,
ereport(ERROR,
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
errmsg("unsuppored reloptions were used for a system table "
"during YSQL upgrade"),
"during YSQL upgrade"),
errhint("Only a small subset is allowed due to BKI restrictions.")));
}

Expand Down Expand Up @@ -1866,7 +1866,7 @@ RemoveAttributeById(Oid relid, AttrNumber attnum)
}
else
{
/* Dropping user attributes is lots harder */
/* Dropping user attributes is lots harder */

/* Mark the attribute as dropped */
attStruct->attisdropped = true;
Expand Down
4 changes: 2 additions & 2 deletions src/postgres/src/backend/catalog/partition.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ has_partition_attrs(Relation rel, Bitmapset *attnums, bool *used_in_expr)
if (partattno != 0)
{
if (bms_is_member(partattno - YBGetFirstLowInvalidAttributeNumber(rel),
attnums))
attnums))
{
if (used_in_expr)
*used_in_expr = false;
Expand All @@ -295,7 +295,7 @@ has_partition_attrs(Relation rel, Bitmapset *attnums, bool *used_in_expr)
* YBGetFirstLowInvalidAttributeNumber + 1.
*/
pull_varattnos_min_attr(expr, 1, &expr_attrs,
YBGetFirstLowInvalidAttributeNumber(rel) + 1);
YBGetFirstLowInvalidAttributeNumber(rel) + 1);
partexprs_item = lnext(partexprs, partexprs_item);

if (bms_overlap(attnums, expr_attrs))
Expand Down
14 changes: 6 additions & 8 deletions src/postgres/src/backend/catalog/pg_shdepend.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,11 @@ shdepFindImplicitTablegroup(Oid tablespaceId, Oid *tablegroupId)

scan = systable_beginscan(sdepRel, SharedDependDependerIndexId, true, NULL, 2, key);

while (HeapTupleIsValid(tup = systable_getnext(scan)))
while (HeapTupleIsValid(tup = systable_getnext(scan)))
{
Form_pg_shdepend shdepForm = (Form_pg_shdepend) GETSTRUCT(tup);
if (shdepForm->refobjid == tablespaceId)
{
if (shdepForm->refobjid == tablespaceId)
{
*tablegroupId = shdepForm->objid;
break;
}
Expand Down Expand Up @@ -1378,19 +1378,17 @@ storeObjectDescription(StringInfo descs,
else if (deptype == SHARED_DEPENDENCY_POLICY)
appendStringInfo(descs, _("target of %s"), objdesc);
else if (deptype == SHARED_DEPENDENCY_TABLESPACE)
{
{
char implicit_tablegroup_name[33];
sprintf(implicit_tablegroup_name, "tablegroup colocation_%u", refobjid);

/*
* Do not report dependency from implicit tablegroup to tablespace.
* This would be fine since implicit tablegroup will be dropped if no tables
* are present in it.
*/
if (strcmp(implicit_tablegroup_name, objdesc) != 0)
{
if (strcmp(implicit_tablegroup_name, objdesc) != 0)
appendStringInfo(descs, _("tablespace for %s"), objdesc);
}
}
else if (deptype == SHARED_DEPENDENCY_PROFILE)
appendStringInfo(descs, _("profile of %s"), objdesc);
Expand Down
21 changes: 11 additions & 10 deletions src/postgres/src/backend/catalog/yb_catalog/yb_catalog_version.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ uint64_t YbGetMasterCatalogVersion()
{
case CATALOG_VERSION_CATALOG_TABLE:
if (YbGetMasterCatalogVersionFromTable(
YbMasterCatalogVersionTableDBOid(), &version))
YbMasterCatalogVersionTableDBOid(), &version))
return version;
/*
* In spite of the fact the pg_yb_catalog_version table exists it has no actual
Expand Down Expand Up @@ -482,9 +482,9 @@ YbCatalogVersionType YbGetCatalogVersionType()
HandleYBStatus(YBCPgTableExists(
Template1DbOid, YBCatalogVersionRelationId,
&catalog_version_table_exists));
yb_catalog_version_type = catalog_version_table_exists
? CATALOG_VERSION_CATALOG_TABLE
: CATALOG_VERSION_PROTOBUF_ENTRY;
yb_catalog_version_type = (catalog_version_table_exists ?
CATALOG_VERSION_CATALOG_TABLE :
CATALOG_VERSION_PROTOBUF_ENTRY);
}
return yb_catalog_version_type;
}
Expand Down Expand Up @@ -516,10 +516,10 @@ bool YbGetMasterCatalogVersionFromTable(Oid db_oid, uint64_t *version)
YBCPgStatement ybc_stmt;

HandleYBStatus(YBCPgNewSelect(Template1DbOid,
YBCatalogVersionRelationId,
NULL /* prepare_params */,
false /* is_region_local */,
&ybc_stmt));
YBCatalogVersionRelationId,
NULL /* prepare_params */,
false /* is_region_local */,
&ybc_stmt));

Datum oid_datum = Int32GetDatum(db_oid);
YBCPgExpr pkey_expr = YBCNewConstant(
Expand Down Expand Up @@ -566,7 +566,8 @@ bool YbGetMasterCatalogVersionFromTable(Oid db_oid, uint64_t *version)
* pick the row that matches db_oid. This work around should be removed
* when prefetching is enhanced to support filtering.
*/
while (true) {
while (true)
{
/* Fetch one row. */
HandleYBStatus(YBCPgDmlFetch(ybc_stmt,
natts,
Expand All @@ -588,7 +589,7 @@ bool YbGetMasterCatalogVersionFromTable(Oid db_oid, uint64_t *version)
result = true;
break;
}
}
}
}

pfree(values);
Expand Down
4 changes: 2 additions & 2 deletions src/postgres/src/backend/catalog/yb_catalog/yb_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,11 @@ Datum YbInt64ToDatum(const int64 *data, int64 bytes, const YBCPgTypeAttrs *type_
}

void YbDatumToUInt64(Datum datum, uint64 *data, uint64 *bytes) {
*data = DatumGetUInt64(datum);
*data = DatumGetUInt64(datum);
}

Datum YbUInt64ToDatum(const uint64 *data, uint64 bytes, const YBCPgTypeAttrs *type_attrs) {
return UInt64GetDatum(*data);
return UInt64GetDatum(*data);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ bool YbGetMasterLogicalClientVersionFromTable(Oid db_oid, uint64_t *version)
YBCPgStatement ybc_stmt;

HandleYBStatus(YBCPgNewSelect(Template1DbOid,
YBLogicalClientVersionRelationId,
NULL /* prepare_params */,
false /* is_region_local */,
&ybc_stmt));
YBLogicalClientVersionRelationId,
NULL /* prepare_params */,
false /* is_region_local */,
&ybc_stmt));

Datum oid_datum = Int32GetDatum(db_oid);
YBCPgExpr pkey_expr = YBCNewConstant(ybc_stmt,
oid_attrdesc->atttypid,
oid_attrdesc->attcollation,
oid_datum,
false /* is_null */);
oid_attrdesc->atttypid,
oid_attrdesc->attcollation,
oid_datum,
false /* is_null */);

HandleYBStatus(YBCPgDmlBindColumn(ybc_stmt, 1, pkey_expr));

Expand Down
2 changes: 1 addition & 1 deletion src/postgres/src/backend/commands/alter.c
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
case OBJECT_YBTABLEGROUP:
return AlterTablegroupOwner(strVal(stmt->object),
newowner);

case OBJECT_FUNCTION:
return AlterFunctionOwner(stmt, newowner);

Expand Down
8 changes: 4 additions & 4 deletions src/postgres/src/backend/commands/createas.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ create_ctas_internal(List *attrList, IntoClause *into)

/* parse and validate reloptions for the toast table */
toast_options = transformRelOptions((Datum) 0,
create->options,
"toast",
validnsps,
true, false);
create->options,
"toast",
validnsps,
true, false);

(void) heap_reloptions(RELKIND_TOASTVALUE, toast_options, true);

Expand Down
4 changes: 2 additions & 2 deletions src/postgres/src/backend/commands/event_trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ CreateEventTrigger(CreateEventTrigStmt *stmt)
errmsg("permission denied to create event trigger \"%s\"",
stmt->trigname),
errhint("Must be superuser or a member of the yb_db_admin "
"role to create an event trigger.")));
"role to create an event trigger.")));

/* Validate event name. */
if (strcmp(stmt->eventname, "ddl_command_start") != 0 &&
Expand Down Expand Up @@ -487,7 +487,7 @@ AlterEventTriggerOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
errmsg("permission denied to change owner of event trigger \"%s\"",
NameStr(form->evtname)),
errhint("The owner of an event trigger must be a superuser "
"or a member of the yb_db_admin role.")));
"or a member of the yb_db_admin role.")));

form->evtowner = newOwnerId;
CatalogTupleUpdate(rel, &tup->t_self, tup);
Expand Down
Loading

0 comments on commit f0f54c4

Please sign in to comment.