Skip to content

Commit

Permalink
Pre-beta mechanical code beautification.
Browse files Browse the repository at this point in the history
Run pgindent, pgperltidy, and reformat-dat-files.

The pgindent part of this is pretty small, consisting mainly of
fixing up self-inflicted formatting damage from patches that
hadn't bothered to add their new typedefs to typedefs.list.
In order to keep it from making anything worse, I manually added
a dozen or so typedefs that appeared in the existing typedefs.list
but not in the buildfarm's list.  Perhaps we should formalize that,
or better find a way to get those typedefs into the automatic list.

pgperltidy is as opinionated as always, and reformat-dat-files too.
  • Loading branch information
tglsfdc committed May 14, 2024
1 parent 3ddbac3 commit da256a4
Show file tree
Hide file tree
Showing 60 changed files with 971 additions and 691 deletions.
2 changes: 1 addition & 1 deletion contrib/sepgsql/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ typedef struct
* command. Elsewhere (including the case of default) NULL.
*/
const char *createdb_dtemplate;
} sepgsql_context_info_t;
} sepgsql_context_info_t;

static sepgsql_context_info_t sepgsql_context_info;

Expand Down
2 changes: 1 addition & 1 deletion contrib/sepgsql/label.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ typedef struct
{
SubTransactionId subid;
char *label;
} pending_label;
} pending_label;

/*
* sepgsql_get_client_label
Expand Down
2 changes: 1 addition & 1 deletion contrib/sepgsql/uavc.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ typedef struct
/* true, if tcontext is valid */
char *ncontext; /* temporary scontext on execution of trusted
* procedure, or NULL elsewhere */
} avc_cache;
} avc_cache;

/*
* Declaration of static variables
Expand Down
110 changes: 55 additions & 55 deletions src/backend/catalog/Catalog.pm
Original file line number Diff line number Diff line change
Expand Up @@ -315,72 +315,72 @@ sub ParseData
my $catname = $1;
my $data = [];

# Scan the input file.
while (<$ifd>)
{
my $hash_ref;
# Scan the input file.
while (<$ifd>)
{
my $hash_ref;

if (/{/)
if (/{/)
{
# Capture the hash ref
# NB: Assumes that the next hash ref can't start on the
# same line where the present one ended.
# Not foolproof, but we shouldn't need a full parser,
# since we expect relatively well-behaved input.

# Quick hack to detect when we have a full hash ref to
# parse. We can't just use a regex because of values in
# pg_aggregate and pg_proc like '{0,0}'. This will need
# work if we ever need to allow unbalanced braces within
# a field value.
my $lcnt = tr/{//;
my $rcnt = tr/}//;

if ($lcnt == $rcnt)
{
# Capture the hash ref
# NB: Assumes that the next hash ref can't start on the
# same line where the present one ended.
# Not foolproof, but we shouldn't need a full parser,
# since we expect relatively well-behaved input.

# Quick hack to detect when we have a full hash ref to
# parse. We can't just use a regex because of values in
# pg_aggregate and pg_proc like '{0,0}'. This will need
# work if we ever need to allow unbalanced braces within
# a field value.
my $lcnt = tr/{//;
my $rcnt = tr/}//;

if ($lcnt == $rcnt)
# We're treating the input line as a piece of Perl, so we
# need to use string eval here. Tell perlcritic we know what
# we're doing.
eval "\$hash_ref = $_"; ## no critic (ProhibitStringyEval)
if (!ref $hash_ref)
{
# We're treating the input line as a piece of Perl, so we
# need to use string eval here. Tell perlcritic we know what
# we're doing.
eval "\$hash_ref = $_"; ## no critic (ProhibitStringyEval)
if (!ref $hash_ref)
{
die "$input_file: error parsing line $.:\n$_\n";
}

# Annotate each hash with the source line number.
$hash_ref->{line_number} = $.;

# Expand tuples to their full representation.
AddDefaultValues($hash_ref, $schema, $catname);
die "$input_file: error parsing line $.:\n$_\n";
}
else
{
my $next_line = <$ifd>;
die "$input_file: file ends within Perl hash\n"
if !defined $next_line;
$_ .= $next_line;
redo;
}
}

# If we found a hash reference, keep it, unless it is marked as
# autogenerated; in that case it'd duplicate an entry we'll
# autogenerate below. (This makes it safe for reformat_dat_file.pl
# with --full-tuples to print autogenerated entries, which seems like
# useful behavior for debugging.)
#
# Otherwise, we have a non-data string, which we keep only if
# the caller requested it.
if (defined $hash_ref)
{
push @$data, $hash_ref if !$hash_ref->{autogenerated};
# Annotate each hash with the source line number.
$hash_ref->{line_number} = $.;

# Expand tuples to their full representation.
AddDefaultValues($hash_ref, $schema, $catname);
}
else
{
push @$data, $_ if $preserve_comments;
my $next_line = <$ifd>;
die "$input_file: file ends within Perl hash\n"
if !defined $next_line;
$_ .= $next_line;
redo;
}
}

# If we found a hash reference, keep it, unless it is marked as
# autogenerated; in that case it'd duplicate an entry we'll
# autogenerate below. (This makes it safe for reformat_dat_file.pl
# with --full-tuples to print autogenerated entries, which seems like
# useful behavior for debugging.)
#
# Otherwise, we have a non-data string, which we keep only if
# the caller requested it.
if (defined $hash_ref)
{
push @$data, $hash_ref if !$hash_ref->{autogenerated};
}
else
{
push @$data, $_ if $preserve_comments;
}
}

close $ifd;

# If this is pg_type, auto-generate array types too.
Expand Down
7 changes: 2 additions & 5 deletions src/bin/pg_amcheck/t/002_nonesuch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,7 @@
));

$node->command_checks_all(
[
'pg_amcheck', '-d', 'regression_invalid'
],
[ 'pg_amcheck', '-d', 'regression_invalid' ],
1,
[qr/^$/],
[
Expand All @@ -314,8 +312,7 @@

$node->command_checks_all(
[
'pg_amcheck', '-d', 'postgres',
'-t', 'regression_invalid.public.foo',
'pg_amcheck', '-d', 'postgres', '-t', 'regression_invalid.public.foo',
],
1,
[qr/^$/],
Expand Down
17 changes: 10 additions & 7 deletions src/bin/pg_basebackup/t/010_pg_basebackup.pl
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,9 @@
$tblspc_tars[0] =~ m|/([0-9]*)\.tar$|;
my $tblspcoid = $1;
my $realRepTsDir = "$real_sys_tempdir/tblspc1replica";
$node2->init_from_backup($node, 'tarbackup2', tar_program => $tar,
$node2->init_from_backup(
$node, 'tarbackup2',
tar_program => $tar,
'tablespace_map' => { $tblspcoid => $realRepTsDir });

$node2->start;
Expand Down Expand Up @@ -776,10 +778,8 @@
'stream', '-d', "dbname=db1", '-R',
],
'pg_basebackup with dbname and -R runs');
like(
slurp_file("$tempdir/backup_dbname_R/postgresql.auto.conf"),
qr/dbname=db1/m,
'recovery conf file sets dbname');
like(slurp_file("$tempdir/backup_dbname_R/postgresql.auto.conf"),
qr/dbname=db1/m, 'recovery conf file sets dbname');

rmtree("$tempdir/backup_dbname_R");

Expand Down Expand Up @@ -976,8 +976,11 @@
$node2->start;

$node2->command_fails_like(
[ @pg_basebackup_defs, '-D', "$tempdir" . '/diff_sysid',
'--incremental', "$backupdir" . '/backup_manifest' ],
[
@pg_basebackup_defs, '-D',
"$tempdir" . '/diff_sysid', '--incremental',
"$backupdir" . '/backup_manifest'
],
qr/manifest system identifier is .*, but database system identifier is/,
"pg_basebackup fails with different database system manifest");

Expand Down
106 changes: 55 additions & 51 deletions src/bin/pg_basebackup/t/040_pg_createsubscriber.pl
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@
'pg_createsubscriber', '--verbose',
'--dry-run', '--pgdata',
$node_t->data_dir, '--publisher-server',
$node_p->connstr('pg1'),
'--socket-directory', $node_t->host,
'--subscriber-port', $node_t->port,
'--database', 'pg1',
'--database', 'pg2'
$node_p->connstr('pg1'), '--socket-directory',
$node_t->host, '--subscriber-port',
$node_t->port, '--database',
'pg1', '--database',
'pg2'
],
'target server is not in recovery');

Expand All @@ -154,11 +154,11 @@
'pg_createsubscriber', '--verbose',
'--dry-run', '--pgdata',
$node_s->data_dir, '--publisher-server',
$node_p->connstr('pg1'),
'--socket-directory', $node_s->host,
'--subscriber-port', $node_s->port,
'--database', 'pg1',
'--database', 'pg2'
$node_p->connstr('pg1'), '--socket-directory',
$node_s->host, '--subscriber-port',
$node_s->port, '--database',
'pg1', '--database',
'pg2'
],
'standby is up and running');

Expand Down Expand Up @@ -188,11 +188,11 @@
'pg_createsubscriber', '--verbose',
'--dry-run', '--pgdata',
$node_c->data_dir, '--publisher-server',
$node_s->connstr('pg1'),
'--socket-directory', $node_c->host,
'--subscriber-port', $node_c->port,
'--database', 'pg1',
'--database', 'pg2'
$node_s->connstr('pg1'), '--socket-directory',
$node_c->host, '--subscriber-port',
$node_c->port, '--database',
'pg1', '--database',
'pg2'
],
'primary server is in recovery');

Expand All @@ -201,7 +201,8 @@
$node_p->wait_for_replay_catchup($node_s);

# Check some unmet conditions on node P
$node_p->append_conf('postgresql.conf', q{
$node_p->append_conf(
'postgresql.conf', q{
wal_level = replica
max_replication_slots = 1
max_wal_senders = 1
Expand All @@ -214,24 +215,26 @@
'pg_createsubscriber', '--verbose',
'--dry-run', '--pgdata',
$node_s->data_dir, '--publisher-server',
$node_p->connstr('pg1'),
'--socket-directory', $node_s->host,
'--subscriber-port', $node_s->port,
'--database', 'pg1',
'--database', 'pg2'
$node_p->connstr('pg1'), '--socket-directory',
$node_s->host, '--subscriber-port',
$node_s->port, '--database',
'pg1', '--database',
'pg2'
],
'primary contains unmet conditions on node P');
# Restore default settings here but only apply it after testing standby. Some
# standby settings should not be a lower setting than on the primary.
$node_p->append_conf('postgresql.conf', q{
$node_p->append_conf(
'postgresql.conf', q{
wal_level = logical
max_replication_slots = 10
max_wal_senders = 10
max_worker_processes = 8
});

# Check some unmet conditions on node S
$node_s->append_conf('postgresql.conf', q{
$node_s->append_conf(
'postgresql.conf', q{
max_replication_slots = 1
max_logical_replication_workers = 1
max_worker_processes = 2
Expand All @@ -241,14 +244,15 @@
'pg_createsubscriber', '--verbose',
'--dry-run', '--pgdata',
$node_s->data_dir, '--publisher-server',
$node_p->connstr('pg1'),
'--socket-directory', $node_s->host,
'--subscriber-port', $node_s->port,
'--database', 'pg1',
'--database', 'pg2'
$node_p->connstr('pg1'), '--socket-directory',
$node_s->host, '--subscriber-port',
$node_s->port, '--database',
'pg1', '--database',
'pg2'
],
'standby contains unmet conditions on node S');
$node_s->append_conf('postgresql.conf', q{
$node_s->append_conf(
'postgresql.conf', q{
max_replication_slots = 10
max_logical_replication_workers = 4
max_worker_processes = 8
Expand All @@ -262,15 +266,15 @@
'pg_createsubscriber', '--verbose',
'--dry-run', '--pgdata',
$node_s->data_dir, '--publisher-server',
$node_p->connstr('pg1'),
'--socket-directory', $node_s->host,
'--subscriber-port', $node_s->port,
'--publication', 'pub1',
'--publication', 'pub2',
'--subscription', 'sub1',
'--subscription', 'sub2',
'--database', 'pg1',
'--database', 'pg2'
$node_p->connstr('pg1'), '--socket-directory',
$node_s->host, '--subscriber-port',
$node_s->port, '--publication',
'pub1', '--publication',
'pub2', '--subscription',
'sub1', '--subscription',
'sub2', '--database',
'pg1', '--database',
'pg2'
],
'run pg_createsubscriber --dry-run on node S');

Expand All @@ -286,10 +290,10 @@
'pg_createsubscriber', '--verbose',
'--dry-run', '--pgdata',
$node_s->data_dir, '--publisher-server',
$node_p->connstr('pg1'),
'--socket-directory', $node_s->host,
'--subscriber-port', $node_s->port,
'--replication-slot', 'replslot1'
$node_p->connstr('pg1'), '--socket-directory',
$node_s->host, '--subscriber-port',
$node_s->port, '--replication-slot',
'replslot1'
],
'run pg_createsubscriber without --databases');

Expand All @@ -299,15 +303,15 @@
'pg_createsubscriber', '--verbose',
'--verbose', '--pgdata',
$node_s->data_dir, '--publisher-server',
$node_p->connstr('pg1'),
'--socket-directory', $node_s->host,
'--subscriber-port', $node_s->port,
'--publication', 'pub1',
'--publication', 'Pub2',
'--replication-slot', 'replslot1',
'--replication-slot', 'replslot2',
'--database', 'pg1',
'--database', 'pg2'
$node_p->connstr('pg1'), '--socket-directory',
$node_s->host, '--subscriber-port',
$node_s->port, '--publication',
'pub1', '--publication',
'Pub2', '--replication-slot',
'replslot1', '--replication-slot',
'replslot2', '--database',
'pg1', '--database',
'pg2'
],
'run pg_createsubscriber on node S');

Expand Down
Loading

0 comments on commit da256a4

Please sign in to comment.