Skip to content

Commit

Permalink
[#25438] YSQL: fix all trailing whitespace
Browse files Browse the repository at this point in the history
Summary:
Fix the trailing_whitespace postgres lint rule to ignore certain
directories where upstream postgres itself has trailing whitespace
problems.  Then, run this script to clean up all the YB trailing
whitespace issues:

    git ls-tree --name-only -r HEAD -- src/postgres/^third-party-extensions \
    | grep -E '\.(c|h)$' \
    | grep -Ev "src/postgres/src/interfaces/ecpg/test/expected|src/postgres/src/backend/snowball/libstemmer" \
    | while read -r line; do if [ ! -h "$line" ]; then sed -Ei 's/\s+$//' "$line"; fi; done
Jira: DB-14675

Test Plan:
On Almalinux 8:

    git ls-tree --name-only -rz HEAD -- src/postgres \
      | grep -zE '\.(c|h)$' \
      | xargs -0 arc lint \
      | grep trailing_whitespace

Close: #25438
Jenkins: compile only

Reviewers: patnaik.balivada

Reviewed By: patnaik.balivada

Subscribers: yql, ycdcxcluster

Differential Revision: https://phorge.dev.yugabyte.com/D40870
  • Loading branch information
jaki committed Dec 26, 2024
1 parent 6404af4 commit 3af60d8
Show file tree
Hide file tree
Showing 24 changed files with 90 additions and 87 deletions.
4 changes: 2 additions & 2 deletions src/postgres/src/backend/access/heap/heaptoast.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ yb_toast_compress_tuple(HeapTuple tup, TupleDesc tupleDesc)
* Look at non-null varlena attributes that are over the toast threshold in size
* and whose attstorage is marked for compression.
*/
if (!toast_isnull[i] &&
TupleDescAttr(tupleDesc, i)->attlen == -1 &&
if (!toast_isnull[i] &&
TupleDescAttr(tupleDesc, i)->attlen == -1 &&
(TupleDescAttr(tupleDesc, i)->attstorage == 'm' ||
TupleDescAttr(tupleDesc, i)->attstorage == 'x'))
{
Expand Down
4 changes: 2 additions & 2 deletions src/postgres/src/backend/catalog/dependency.c
Original file line number Diff line number Diff line change
Expand Up @@ -1388,14 +1388,14 @@ deleteOneObject(const ObjectAddress *object, Relation *depRel, int flags)
systable_endscan(scan);

/*
* Check if implicit tablegroup has any more tables in it.
* Check if implicit tablegroup has any more tables in it.
* If not delete it.
*/

if (is_colocated_tables_with_tablespace_enabled &&
OidIsValid(implicit_tablegroup.objectId))
{
deleteSharedDependencyRecordsFor(implicit_tablegroup.classId, implicit_tablegroup.objectId,
deleteSharedDependencyRecordsFor(implicit_tablegroup.classId, implicit_tablegroup.objectId,
implicit_tablegroup.objectSubId);
RemoveTablegroupById(implicit_tablegroup.objectId, true);
}
Expand Down
8 changes: 4 additions & 4 deletions src/postgres/src/backend/catalog/pg_constraint.c
Original file line number Diff line number Diff line change
Expand Up @@ -1122,8 +1122,8 @@ get_primary_key_attnos(Oid relid, bool deferrableOk, Oid *constraintOid)
/* Set *constraintOid, to avoid complaints about uninitialized vars */
*constraintOid = InvalidOid;

/*
* YB change: Search the catcache here to avoid having to go to master.
/*
* YB change: Search the catcache here to avoid having to go to master.
* This will trigger a master RPC if this is the first time we're looking
* up the primary key for this relation.
*/
Expand Down Expand Up @@ -1165,8 +1165,8 @@ get_primary_key_attnos(Oid relid, bool deferrableOk, Oid *constraintOid)
break;

/* Extract the conkey array, ie, attnums of PK's columns */
adatum = IsYugaByteEnabled()
? SysCacheGetAttr(CONSTROID, tuple, Anum_pg_constraint_conkey, &isNull)
adatum = IsYugaByteEnabled()
? SysCacheGetAttr(CONSTROID, tuple, Anum_pg_constraint_conkey, &isNull)
: heap_getattr(tuple, Anum_pg_constraint_conkey, RelationGetDescr(pg_constraint), &isNull);
if (isNull)
elog(ERROR, "null conkey for constraint %u",
Expand Down
8 changes: 4 additions & 4 deletions src/postgres/src/backend/catalog/pg_shdepend.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ shdepChangeDep(Relation sdepRel,
}

void
shdepFindImplicitTablegroup(Oid tablespaceId, Oid *tablegroupId)
shdepFindImplicitTablegroup(Oid tablespaceId, Oid *tablegroupId)
{
Oid databaseId;
ScanKeyData key[2];
Expand All @@ -359,10 +359,10 @@ shdepFindImplicitTablegroup(Oid tablespaceId, Oid *tablegroupId)
sdepRel = table_open(SharedDependRelationId, RowExclusiveLock);


ScanKeyInit(&key[0], Anum_pg_shdepend_dbid,
ScanKeyInit(&key[0], Anum_pg_shdepend_dbid,
BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(databaseId));

ScanKeyInit(&key[1], Anum_pg_shdepend_classid,
ScanKeyInit(&key[1], Anum_pg_shdepend_classid,
BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(YbTablegroupRelationId));

scan = systable_beginscan(sdepRel, SharedDependDependerIndexId, true, NULL, 2, key);
Expand Down Expand Up @@ -1377,7 +1377,7 @@ storeObjectDescription(StringInfo descs,
appendStringInfo(descs, _("privileges for %s"), objdesc);
else if (deptype == SHARED_DEPENDENCY_POLICY)
appendStringInfo(descs, _("target of %s"), objdesc);
else if (deptype == SHARED_DEPENDENCY_TABLESPACE)
else if (deptype == SHARED_DEPENDENCY_TABLESPACE)
{
char implicit_tablegroup_name[33];
sprintf(implicit_tablegroup_name, "tablegroup colocation_%u", refobjid);
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/src/backend/commands/functioncmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt)
}
else
{
/*
/*
* If untrusted language, must be superuser, or someone with the
* yb_extension role in the midst of creating an extension.
*/
Expand Down
10 changes: 5 additions & 5 deletions src/postgres/src/backend/commands/matview.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,10 @@ transientrel_receive(TupleTableSlot *slot, DestReceiver *self)
myState->ti_options,
myState->bistate);

/*
/*
* In this case when the transient relation is a temporary relation, heap_insert
* will set a transaction id. However, we must clear this transaction id, since
* REFRESH matview should not invoke any TxnWithPGRel code paths
* REFRESH matview should not invoke any TxnWithPGRel code paths
* (that are used for temp tables).
*/
YbClearCurrentTransactionId();
Expand Down Expand Up @@ -896,7 +896,7 @@ refresh_by_match_merge(Oid matviewOid, Oid tempOid, Oid relowner,
/* Can't use TID in YB mode */
appendStringInfo(&querybuf,
"DELETE FROM %s mv WHERE mv.*::%s OPERATOR(pg_catalog.=) ANY "
"(SELECT mv FROM %s diff WHERE (",
"(SELECT mv FROM %s diff WHERE (",
matviewname, matviewname, diffname);
TupleDesc tuple_desc = RelationGetDescr(matviewRel);

Expand All @@ -908,7 +908,7 @@ refresh_by_match_merge(Oid matviewOid, Oid tempOid, Oid relowner,
appendStringInfo(&querybuf, "OR ");
}

appendStringInfo(&querybuf, ") AND diff.newdata IS NULL)");
appendStringInfo(&querybuf, ") AND diff.newdata IS NULL)");
}
else
{
Expand All @@ -930,7 +930,7 @@ refresh_by_match_merge(Oid matviewOid, Oid tempOid, Oid relowner,
appendStringInfo(&querybuf,
"INSERT INTO %s SELECT (diff.newdata).* "
"FROM %s diff WHERE mv IS NULL",
matviewname, diffname);
matviewname, diffname);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/src/backend/libpq/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -3732,7 +3732,7 @@ ybReadFromUrl(const char *url)
YBCStatusMessageBegin(status))));
YBCFreeStatus(status);
return NULL;
}
}
if(!url_contents)
return NULL;

Expand Down
6 changes: 3 additions & 3 deletions src/postgres/src/backend/libpq/hba.c
Original file line number Diff line number Diff line change
Expand Up @@ -1830,7 +1830,7 @@ parse_hba_line(TokenizedAuthLine *tok_line, int elevel)

/*
* Caching various string lengths
*/
*/
size_t total_len = strlen(parsedline->rawline);
size_t prefix_len = passfield - parsedline->rawline;
size_t passkey_len = strlen(passkey);
Expand All @@ -1846,13 +1846,13 @@ parse_hba_line(TokenizedAuthLine *tok_line, int elevel)
head += copy_size;

copy_size = pass_replacement_string_len;
strncpy(parsedline->maskedline + head,
strncpy(parsedline->maskedline + head,
pass_replacement_string, copy_size);
head += copy_size;

copy_size = total_len - prefix_len - passkey_len
- passwd_len;
strncpy(parsedline->maskedline + head,
strncpy(parsedline->maskedline + head,
passfield + passkey_len
+ passwd_len, copy_size);
head += copy_size;
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/src/backend/replication/logical/logical.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ LoadOutputPlugin(OutputPluginCallbacks *callbacks, const char *plugin)
load_external_function(PG_OUTPUT_PLUGIN,"_PG_output_plugin_init", false, NULL);
else
plugin_init = (LogicalOutputPluginInit)
load_external_function(plugin, "_PG_output_plugin_init", false, NULL);
load_external_function(plugin, "_PG_output_plugin_init", false, NULL);

if (plugin_init == NULL)
elog(ERROR, "output plugins have to declare the _PG_output_plugin_init symbol");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4249,7 +4249,7 @@ ReorderBufferRestoreChanges(ReorderBuffer *rb, ReorderBufferTXN *txn,

XLByteToSeg(txn->final_lsn, last_segno, wal_segment_size);

while ((restored <
while ((restored <
(IsYugaByteEnabled() ? yb_reorderbuffer_max_changes_in_memory : max_changes_in_memory))
&& (*segno <= last_segno))
{
Expand Down
4 changes: 2 additions & 2 deletions src/postgres/src/backend/replication/logical/yb_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ YBFindAttributeIndexInDescriptor(TupleDesc tupdesc, const char *column_name);
static void
YBHandleRelcacheRefresh(LogicalDecodingContext *ctx, XLogReaderState *record);

static void
static void
YBLogTupleDescIfRequested(const YBCPgVirtualWalRecord *yb_record,
TupleDesc tupdesc);

Expand Down Expand Up @@ -594,7 +594,7 @@ YBHandleRelcacheRefresh(LogicalDecodingContext *ctx, XLogReaderState *record)
}
}

static void
static void
YBLogTupleDescIfRequested(const YBCPgVirtualWalRecord *yb_record,
TupleDesc tupdesc)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ InitVirtualWal(List *publication_names)
tables = YBCGetTables(publication_names);
table_oids = YBCGetTableOids(tables);

/*
/*
* Throw an error if the plugin being used is pgoutput and there exist a
* table in publication with YB specific replica identity (CHANGE).
*/
Expand All @@ -226,7 +226,7 @@ InitVirtualWal(List *publication_names)
ereport(ERROR,
(errmsg("Replica identity CHANGE is not supported for output "
"plugin pgoutput. Consider using output plugin yboutput instead.")));
}
}
}

YBCInitVirtualWalForCDC(MyReplicationSlot->data.yb_stream_id, table_oids,
Expand Down Expand Up @@ -620,11 +620,11 @@ YBCRefreshReplicaIdentities()
YBCPgReplicaIdentityDescriptor *desc =
&yb_replication_slot->replica_identities[replica_identity_idx];

/*
/*
* Throw an error if the plugin being used is pgoutput and there exist a
* table with YB specific replica identity (CHANGE).
*/
if (strcmp(MyReplicationSlot->data.plugin.data, PG_OUTPUT_PLUGIN) == 0
if (strcmp(MyReplicationSlot->data.plugin.data, PG_OUTPUT_PLUGIN) == 0
&& desc->identity_type == YBC_YB_REPLICA_IDENTITY_CHANGE)
ereport(ERROR,
(errmsg("Replica identity CHANGE is not supported for output "
Expand Down
4 changes: 2 additions & 2 deletions src/postgres/src/backend/replication/pgoutput/pgoutput.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ static void send_repl_origin(LogicalDecodingContext *ctx,
static void update_replication_progress(LogicalDecodingContext *ctx,
bool skipped_xact);

/*
/*
* This indicates whether the plugin being used is yboutput or pgoutput. In
* yboutput mode, we also support yb-specific replica identity
* yboutput mode, we also support yb-specific replica identity
* (CHANGE for now).
*/
static bool yb_is_yboutput_mode;
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/src/backend/replication/slotfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pg_create_logical_replication_slot(PG_FUNCTION_ARGS)
if (IsYugaByteEnabled())
{
if (temporary)
ereport(ERROR,
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("Temporary replication slot is not yet supported"),
errhint("See https://github.com/yugabyte/yugabyte-db/"
Expand Down
4 changes: 2 additions & 2 deletions src/postgres/src/backend/replication/walsender.c
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
need_full_snapshot = true;
}

/*
/*
* YB has its own snapshot mechanism that does not require the command
* to be created within a transaction, so we disable these checks here.
*/
Expand Down Expand Up @@ -1441,7 +1441,7 @@ DropReplicationSlot(DropReplicationSlotCmd *cmd)
"system upgrade is in progress")));

if (IsYugaByteEnabled() && cmd->wait)
ereport(ERROR,
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("Waiting for a replication slot is not yet"
" supported")));
Expand Down
6 changes: 3 additions & 3 deletions src/postgres/src/backend/utils/cache/catcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -2341,9 +2341,9 @@ CatalogCacheCreateEntry(CatCache *cache, HeapTuple ntp, Datum *arguments,
/* We should never have out-of-line toasted fields in YB. */
Assert(!IsYugaByteEnabled());
dtp = toast_flatten_tuple(ntp, cache->cc_tupdesc);
} else if (IsYugaByteEnabled() &&
yb_toast_catcache_threshold > 0 &&
ntp->t_len > yb_toast_catcache_threshold)
} else if (IsYugaByteEnabled() &&
yb_toast_catcache_threshold > 0 &&
ntp->t_len > yb_toast_catcache_threshold)
dtp = yb_toast_compress_tuple(ntp, cache->cc_tupdesc);
else
dtp = ntp;
Expand Down
4 changes: 2 additions & 2 deletions src/postgres/src/backend/utils/cache/lsyscache.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ get_mergejoin_opfamilies(Oid opno)
Form_pg_amop aform = (Form_pg_amop) GETSTRUCT(tuple);

/* must be btree equality */
if ((aform->amopmethod == BTREE_AM_OID || aform->amopmethod == LSM_AM_OID) &&
if ((aform->amopmethod == BTREE_AM_OID || aform->amopmethod == LSM_AM_OID) &&
aform->amopstrategy == BTEqualStrategyNumber)
result = lappend_oid(result, aform->amopfamily);
}
Expand Down Expand Up @@ -3185,7 +3185,7 @@ get_attavgwidth(Oid relid, AttrNumber attnum)
/*
* This functionality was left disabled even after ANALYZE was implemented.
* This oversight was detected during cost model project. We protect it
* under this feature toggle to prevent regressions.
* under this feature toggle to prevent regressions.
*/
if (!yb_enable_base_scans_cost_model)
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/src/backend/utils/cache/relcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,7 @@ YbCompleteAttrProcessingImpl(const YbAttrProcessorState *state)
{
pfree(constr);
relation->rd_att->constr = NULL;
}
}

/* Fetch rules and triggers that affect this relation */
if (relation->rd_rel->relhasrules)
Expand Down
4 changes: 2 additions & 2 deletions src/postgres/src/bin/pg_upgrade/controldata.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ check_control_data(ControlData *oldctrl,
if (oldctrl->index == 0 || oldctrl->index != newctrl->index)
pg_fatal("old and new pg_controldata maximum indexed columns are invalid or do not match\n");

#ifdef YB_TODO
/* Investigate/implement this check */
#ifdef YB_TODO
/* Investigate/implement this check */
if (oldctrl->toast == 0 || oldctrl->toast != newctrl->toast)
pg_fatal("old and new pg_controldata maximum TOAST chunk sizes are invalid or do not match\n");
#endif
Expand Down
26 changes: 13 additions & 13 deletions src/postgres/src/bin/pgbench/pgbench.c
Original file line number Diff line number Diff line change
Expand Up @@ -4706,13 +4706,13 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg)
st->state = CSTATE_ABORTED;
break;
}
else
{
// Connection init sql
if (yb_connection_init_sql != NULL) {
else
{
// Connection init sql
if (yb_connection_init_sql != NULL) {
executeStatement(st->con,
yb_connection_init_sql);
}
yb_connection_init_sql);
}
}

/* reset now after connection */
Expand Down Expand Up @@ -8359,8 +8359,8 @@ main(int argc, char **argv)
}
yb_metrics_arg_set = true;
break;
case 18: /* yb-connection-init-sql */
yb_connection_init_sql = pg_strdup(optarg);
case 18: /* yb-connection-init-sql */
yb_connection_init_sql = pg_strdup(optarg);
break;
default:
/* getopt_long already emitted a complaint */
Expand Down Expand Up @@ -8866,11 +8866,11 @@ threadRun(void *arg)
pg_fatal("could not create connection for client %d",
state[i].id);
}
else
{
if (yb_connection_init_sql != NULL) {
executeStatement(state[i].con, yb_connection_init_sql);
}
else
{
if (yb_connection_init_sql != NULL) {
executeStatement(state[i].con, yb_connection_init_sql);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/src/include/nodes/plannodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ typedef struct YbUpdateAffectedEntities
AttrNumber attnum;

/*
* A list of entities that reference the column.
* A list of entities that reference the column.
* Entities are identified by their index in the entity_list.
*/
List *entity_refs;
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/src/include/optimizer/cost.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#define YB_DEFAULT_SEEK_COST_FACTOR 50
#define YB_DEFAULT_BACKWARD_SEEK_COST_FACTOR 10

/*
/*
* The value for the fast backward scan seek cost factor has been selected based on the smallest
* improvement (2.8 times) for the backward scan related Order By workloads of Featurebench. It
* might be good to use a different factor for colocated case, where the smallest improvement
Expand Down
Loading

0 comments on commit 3af60d8

Please sign in to comment.