Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize for newer PostgreSQL releases - part #1 #3

Merged
merged 8 commits into from
Nov 16, 2018

Conversation

praiskup
Copy link
Collaborator

No description provided.

@praiskup
Copy link
Collaborator Author

praiskup commented Nov 7, 2018

Anyone wants to review? Otherwise I'd merge this and continue forward, even though this doesn't fix the code entirely.

The testsuite is broken, I am aware of one server crash - and also note this https://postgr.es/m/4738198.8KVIIDhgEB@nb.usersys.redhat.com, we need even more work.

@praiskup praiskup changed the title Compat with PGv11 after upstream commit 726117243022178 Modernize for newer PostgreSQL releases - part #1 Nov 7, 2018
@praiskup praiskup mentioned this pull request Nov 7, 2018
Copy link

@jeltz jeltz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to see this project reviewed. I did a quick review of this MR.

It may also be worth taking a look at https://github.com/pg-plruby-ug/postgresql-plruby which seems to be the most modern version of PL/Ruby.

# In v10+, the second number means "minor" version - which is
# expected to be >= 10 one day. So rather mutiply by 100 to avoid
# overflow.
version = 100 * $1.to_i + $2.to_i
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not look right. Isn't the version just use for checking for for the major version in the code below? I think something like the below would be better:

when /^PostgreSQL ([7-9]|[1-9][0-9])\.([0-9]{1,3})(\.[0-9]{1,3})?$/
   if $1.to_i < 10
       # Before v10 the second number was also part of the major version 
       version = 10 * $1.to_i + $2.to_i
   else
       version = 10 * $1.to_i

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably prefer not to expand 10.1 => 100, that would look kind of weird. We usually check like VERSION >= NN anways. But I can admit it is matter of taste. Any other opinion? (I'd probably switch to what @jeltz suggests).

Isn't the version just use for checking for for the major version in the code below?

Plus it is a #define, used in code elsewhere.

Copy link

@jeltz jeltz Nov 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be consistent. In the current master 9.6.1 becomes 96, and in that case 10.1 should become 100. I would be perfectly fine with including the minor version, but in that case we need to do something like 9.6.1 => 90601 and 10.1 => 100001 since we need to support 9.6.11 => 90611 and 10.1 must be larger than 9.6.11.

Copy link

@jeltz jeltz Nov 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also why do we need that #define? PostgreSQL already defines PG_VERSION_NUM. I think I could submit a patch which starts to use PG_VERSION_NUM after you have merged this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Patch for PG_VERSION_NUM or PG_MAJORVERSION would be awesome.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out such a patch would not be necessary since none of the checks check for anything newer than 8.4.

WIP commit which removes the legacy ifdefs: jeltz@5c65ca1

extconf.rb Outdated
@@ -120,8 +120,15 @@ def rule(target, clean = nil)
end

case version_str = `#{pg_config} --version`
when /^PostgreSQL ([7-9])\.([0-9]{1,3})(\.[0-9]{1,3})?$/
version = 10 * $1.to_i + $2.to_i
when /^PostgreSQL ([7-9]|[1-9][0-9])\.([0-9]{1,3})(\.[0-9]{1,3})?$/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wont work on at least Debian (before or after your patch). My output is "PostgreSQL 11.1 (Debian 11.1-1.pgdg90+1)\n".

Also the regex seems needlessly complicated and will break once we release 10.10. Why not something like: /\APostgreSQL (\d+)\.(\d+)/

We also may want to support development versions like the current "12devel".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed for the Debian case. Support for development versions can be added later.

extconf.rb Outdated
raise <<-EOT

============================================================
#{version_str} is unsupported. Try plruby-0.4.2.
#{version_str} is not supported anymore. Try plruby-0.5.7 or older.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is rather ugly that this overflows outside the equals signs. I suggest just dropping the "anymore" because it is obvious from the context.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

@@ -132,11 +132,11 @@ def rule(target, clean = nil)
else
version = 0
end
if version < 73
if version < 92
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we drop support for anything before 9.2 we should also remove the check against 7.4 below in extconf.rb.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also update the README if we increase the max version.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but removing everything < 9.2 will be pretty huge cleanup in all the codebase. That said, it is something I'd like to do - but not here in #part1 (nor #part2) - the major thing is to allow successful build of plruby and make the testsuite pass again (start the Travis CI, etc.).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. It makes sense to do the clean up in a separate in a commit.

extconf.rb Outdated
wr << "\t@-rm tmp/* tests/tmp/* 2> /dev/null\n"
wr << "\t@rm Makefile\n" if clean
wr << "\t-rm -f tmp/* tests/tmp/* 2> /dev/null\n"
wr << "\trm Makefile\n" if clean
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't there be an added -f here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, thanks.

For versions smaller than 9.6.X, we keep the short '96' (major
version) form, and for >= 10 we use the longer form including
minor number (e.g. 1003 for 10.3).  This fix allows us to keep the
old code working, and support newer PG versions.
Previously we called SPI_finish() in pl_trigger_handler(), right
before calling the SPI_modifytuple() - but that's not allowed to
be called unconnected since PGv10 (commit 1833f1a1c3b0e12b3ea4).

So, call SPI_finish() upper in call stack - and share it with
pl_trigger_handler().
This is now mandatory on PGv11+ (upstream commit 726117243022178),
but it's available only on PGv9.2+.  It doesn't seem to be wise to
keep compatibility with anything older than 9.2 nowadays anyways
so let's avoid #if-else hacks.
@@ -363,6 +363,19 @@ pl_protect(plth)
else {
retval = pl_func_handler(plth);
}

PLRUBY_BEGIN_PROTECT(1);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what coding style is used for the project but the indentation here does not match the indentation above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, project has no unified whitespace indentation. The current part you talk about has mixed 8-tab width, with 4-space. Most of the code uses 4-space indent, so I followed it even here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I'd be against re-indentation of the whole project (that only breaks git-blame/bisect attempts). But specifying indentation rules in CONTRIBUTING file would be good thing.

extconf.rb Outdated
@@ -68,8 +68,8 @@ def rule(target, clean = nil)
\tdone;
"
if clean != nil
wr << "\t@-rm tmp/* tests/tmp/* 2> /dev/null\n"
wr << "\t@rm Makefile\n" if clean
wr << "\t-rm -f tmp/* tests/tmp/* 2> /dev/null\n"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is up with the minus before rm? I know it was there before as part of @-rm but should it really be there?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minus means "ignore non-zero exit status". But with -f it shouldn't be needed, let's drop that.

@jeltz
Copy link

jeltz commented Nov 14, 2018

I think your changes largely look good, minus my minor comments above. Thanks again for reviving this project.

@devrimgunduz
Copy link
Owner

Is this now ready to merge?

@praiskup
Copy link
Collaborator Author

Is this now ready to merge?

Hopefully, thanks a lot for the review @jeltz.

@praiskup
Copy link
Collaborator Author

@devrimgunduz I can only "merge with merge commit". Would it be possible to configure the project to have "rebase and merge" option?

The heap_formtuple() call has been deprecated for a long time, and
finally removed in PGv9.6 by commit 726117243022178e72966cb.  The
heap_form_tuple() variant exists in PGv8.1+.
Generate 'extconf.h', so we don't have to pass all the -DMACRO=DEF
statements through $CPPFLAGS/$CFLAGS.
Support newer ruby where rb_frame_last_func() is obsoleted.
Include some missing PG headers, and resolve unused/uninitialized
warnings.
Move from to HeapTupleGetDatum(), supported since PGv8.0.
Also fix argc/argv checks so that only one argument is allowed.
Use 'c' language, not 'C'.
Drop 'lancompiler' use.
@praiskup praiskup merged commit 67f4e4e into devrimgunduz:master Nov 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants