| Lists: | pgsql-hackers |
|---|
| From: | a(dot)akenteva(at)postgrespro(dot)ru |
|---|---|
| To: | pgsql-hackers(at)postgresql(dot)org |
| Subject: | A weird bit in pg_upgrade/exec.c |
| Date: | 2017-11-09 15:07:35 |
| Message-ID: | [email protected] |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Lists: | pgsql-hackers |
Hello!
I've came across a weird bit in pg_upgrade/exec.c
We have a function check_bin_dir() which goes like this (old_cluster and
new_cluster are global variables):
void check_bin_dir(ClusterInfo *cluster)
{
...
get_bin_version(&old_cluster);
get_bin_version(&new_cluster);
...
}
This function has two calls:
check_bin_dir(&old_cluster);
check_bin_dir(&new_cluster);
I'd like to substitute these last two lines with this:
get_bin_version(cluster);
Doing it would simplify the patch I'm writing, but I'm worried I might
break something that's been there for a long time and has been working
fine. Is there maybe a reason for it to be this way that I don't happen
to understand?
Also, there's the exact same situation with the get_bin_version()
function in the same file.
| From: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
|---|---|
| To: | a(dot)akenteva(at)postgrespro(dot)ru |
| Cc: | pgsql-hackers(at)postgresql(dot)org |
| Subject: | Re: A weird bit in pg_upgrade/exec.c |
| Date: | 2017-11-09 16:06:08 |
| Message-ID: | [email protected] |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Lists: | pgsql-hackers |
a(dot)akenteva(at)postgrespro(dot)ru wrote:
> This function has two calls:
> check_bin_dir(&old_cluster);
> check_bin_dir(&new_cluster);
>
> I'd like to substitute these last two lines with this:
> get_bin_version(cluster);
Odd indeed. One would think that if a cluster variable is passed as
parameter, the global vars should not be used. +1 for fixing it, and
your proposal sounds as good as any.
> Doing it would simplify the patch I'm writing, but I'm worried I might break
> something that's been there for a long time and has been working fine.
I think odd coding this was introduced recently because of the
pg_resetxlog -> pg_resetwal renaming.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | a(dot)akenteva(at)postgrespro(dot)ru |
| Cc: | pgsql-hackers(at)postgresql(dot)org |
| Subject: | Re: A weird bit in pg_upgrade/exec.c |
| Date: | 2017-11-09 16:17:26 |
| Message-ID: | [email protected] |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Lists: | pgsql-hackers |
a(dot)akenteva(at)postgrespro(dot)ru writes:
> I've came across a weird bit in pg_upgrade/exec.c
> We have a function check_bin_dir() which goes like this (old_cluster and
> new_cluster are global variables):
> void check_bin_dir(ClusterInfo *cluster)
> {
> ...
> get_bin_version(&old_cluster);
> get_bin_version(&new_cluster);
> ...
> }
> This function has two calls:
> check_bin_dir(&old_cluster);
> check_bin_dir(&new_cluster);
> I'd like to substitute these last two lines with this:
> get_bin_version(cluster);
Yeah, the way it is now seems outright broken. It will try to do
get_bin_version on the new cluster before having done validate_exec
there, violating its own comment.
I think we should change this as a bug fix, independently of whatever
else you had in mind to do here.
regards, tom lane
| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
| Cc: | a(dot)akenteva(at)postgrespro(dot)ru, pgsql-hackers(at)postgresql(dot)org |
| Subject: | Re: A weird bit in pg_upgrade/exec.c |
| Date: | 2017-11-09 16:21:26 |
| Message-ID: | [email protected] |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Lists: | pgsql-hackers |
Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> writes:
> I think odd coding this was introduced recently because of the
> pg_resetxlog -> pg_resetwal renaming.
Dunno about that, but certainly somebody fat-fingered a refactoring
there. The 9.6 code looks quite different but doesn't seem to be
doing anything silly.
regards, tom lane
| From: | a(dot)akenteva(at)postgrespro(dot)ru |
|---|---|
| To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
| Cc: | pgsql-hackers(at)postgresql(dot)org, pgsql-hackers-owner(at)postgresql(dot)org |
| Subject: | Re: [HACKERS] A weird bit in pg_upgrade/exec.c |
| Date: | 2017-11-16 12:05:59 |
| Message-ID: | [email protected] |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Lists: | pgsql-hackers |
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
> Yeah, the way it is now seems outright broken. It will try to do
> get_bin_version on the new cluster before having done validate_exec
> there, violating its own comment.
>
> I think we should change this as a bug fix, independently of whatever
> else you had in mind to do here.
I see this bug is now fixed in pg_upgrade/exec.c => check_bin_dir().
There's another bit exactly like that in check_data_dir() though.
We use global variables instead of using the argument passed to the
function,
which makes the function not reusable. Sorry if I mentioned it too
vaguely
in the previous letter.
I attached a patch with the change that would fix it.
In pg_upgrade/exec.c => check_data_dir() I substituted these two lines
old_cluster.major_version = get_major_server_version(&old_cluster);
new_cluster.major_version = get_major_server_version(&new_cluster);
with this line:
cluster->major_version = get_major_server_version(cluster);
and changed the comment accordingly.
| Attachment | Content-Type | Size |
|---|---|---|
| Fixed-exec-c.patch | text/x-diff | 1.0 KB |
| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | a(dot)akenteva(at)postgrespro(dot)ru |
| Cc: | pgsql-hackers(at)postgresql(dot)org |
| Subject: | Re: [HACKERS] A weird bit in pg_upgrade/exec.c |
| Date: | 2017-11-16 16:20:02 |
| Message-ID: | [email protected] |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Lists: | pgsql-hackers |
a(dot)akenteva(at)postgrespro(dot)ru writes:
> I see this bug is now fixed in pg_upgrade/exec.c => check_bin_dir().
> There's another bit exactly like that in check_data_dir() though.
Oh, so there is ... and looking around, that seems to have been
copied-and-pasted out of check_cluster_versions(), without any
thought for the fact that those calls were thereby made redundant.
Fix pushed, thanks for noticing!
regards, tom lane