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

WIP: Add full compatibility to Fiber.scheduler of Ruby-3.0 #397

Merged
merged 62 commits into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
d4488d5
Add async_connect and async_send methods and add specific specs for F…
larskanis Aug 23, 2021
f4b7d12
More verbose CI output
larskanis Aug 24, 2021
e86d7af
Exclude scheduler spec from ruby < 3
larskanis Aug 24, 2021
f3ec80c
Scheduler: Improve debugging
larskanis Aug 24, 2021
ad901ec
Fixup: wait for connect
larskanis Aug 24, 2021
1ec6938
Work around issues on Windows
larskanis Aug 24, 2021
b92ef92
Fix workaround on COPY tests
larskanis Aug 24, 2021
b677920
We can use io.wait to wait for readability or writability
larskanis Aug 25, 2021
e4ec261
Better workaround on Windows
larskanis Aug 25, 2021
8a7fab1
More scheduler specs
larskanis Aug 25, 2021
80e3a74
Revert "We can use io.wait to wait for readability or writability"
larskanis Aug 25, 2021
99664bf
Add ruby-3.0 to verify scheduler on it's first ruby release.
larskanis Aug 25, 2021
e075048
Add some domumantation to the TcpGateScheduler
larskanis Aug 25, 2021
ecc5e18
Add async_get_result and async_get_last_result
larskanis Aug 25, 2021
f69cd62
Use monotonic time source on Windows
larskanis Aug 26, 2021
74ca456
Disable GVL unlock/lock mechanism
larskanis Aug 28, 2021
00e0ca4
Add scheduler compatible get_copy_data
larskanis Aug 29, 2021
b3fea30
Improve markup in docs
larskanis Aug 29, 2021
d72606e
TCP-Gate: Improve write handling
larskanis Aug 29, 2021
d273782
Implement async_put_copy_data/async_put_copy_end
larskanis Aug 29, 2021
8d452a2
Fix race condition with write data transfer
larskanis Sep 3, 2021
3f63c1f
Treat IO.select errors as timeout
larskanis Sep 3, 2021
f2afb65
Scheduler: Make sure connections are closed at finish
larskanis Sep 4, 2021
87e430d
Scheduler: Handle forcibly closed connections
larskanis Sep 4, 2021
f68e06e
Scheduler: Better debug output
larskanis Sep 4, 2021
82eb48b
Remove duplicated code in tests
larskanis Sep 4, 2021
15d23ff
Make discard_results scheduler friendly
larskanis Sep 6, 2021
5df6a71
Fix compat to ruby < 3.0
larskanis Sep 7, 2021
63e00c2
ID values can be allocated in Init
larskanis Sep 7, 2021
6c885e8
Use rb_io_wait if available and remove Windows specific wait functions
larskanis Sep 7, 2021
5ef9bae
Remove now unused variable
larskanis Sep 7, 2021
4799946
Implement async_reset method using the nonblocking libpq API
larskanis Sep 7, 2021
1fc4ece
Move async_exec methods back to C
larskanis Sep 7, 2021
7944e1a
Add an option to extconf.rb to enable nogvl-wrapping of libpq functions.
larskanis Sep 7, 2021
56a764e
Catch EINVAL while remote_address
larskanis Sep 7, 2021
3b2fa5e
Add async_set_client_encoding which is compatible to scheduler
larskanis Sep 10, 2021
5bc7f7c
Remove PostgreSQL version guard since we don't support PostgreSQL-9.0
larskanis Sep 12, 2021
4a9b334
Avoid PG.connect blocking while address resolution
larskanis Sep 12, 2021
1c538cf
Avoid double fault, when the connection couldn't be established
larskanis Sep 12, 2021
8cab8a1
Avoid compiler warning about mixed declaration and code
larskanis Sep 13, 2021
cacf429
Bump required ruby version to 2.5
larskanis Sep 13, 2021
c324d0b
Add test case for invalid argument to #connect_string_to_hash
larskanis Sep 13, 2021
5e8c911
Allow specification of multiple PostgreSQL hosts to connect to
larskanis Sep 13, 2021
238ddd2
Add async_cancel as a nonblocking version of conn#cancel
larskanis Sep 14, 2021
5b10f80
better method name async_connect_or_reset
larskanis Sep 15, 2021
004235f
Improve TcpGateScheduler
larskanis Sep 15, 2021
b92a08d
Add timeout support to Scheduler#io_wait and fix cancel test
larskanis Sep 15, 2021
e82ade8
Change test to run 3 PG.connect concurrently
larskanis Sep 15, 2021
e9d1f93
Ensure conn.block is called before each conn.get_result call
larskanis Sep 15, 2021
72b77cb
Use Socket class instead of BasicSocket
larskanis Sep 15, 2021
1e40851
TcpGateScheduler: some refine on debug prints
larskanis Sep 15, 2021
fc44071
Compat with Macos
larskanis Sep 15, 2021
29084ea
Avoid recursive calls of puts
larskanis Sep 16, 2021
581c780
TcpGateScheduler: Gather events on fds, that are not yet accepted
larskanis Sep 16, 2021
7bdf4a4
Windows: Add a workaround for nonworking nonblocking-IO on Windows
larskanis Sep 16, 2021
45e179a
Add workaround for Truffleruby and revert conn.socket_io to BasicSocket
larskanis Sep 18, 2021
72d5b32
Implement async_encrypt_password
larskanis Sep 19, 2021
7fe6dac
Add scheduler aware Connection.ping version
larskanis Sep 19, 2021
6b4cd3f
Enable GVL unlocking per default and rename it
larskanis Sep 20, 2021
0871be7
TcpGate: Ignore EBADF error
larskanis Sep 20, 2021
7191132
Replace Resolv.getaddress by IPSocket to avoid inconsistencies
larskanis Oct 1, 2021
1b155a9
Allow truffleruby to fail on github actions and add it to travis-ci
larskanis Oct 1, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ install:
build_script:
- bundle exec rake -rdevkit compile --trace
test_script:
- bundle exec rake test
- bundle exec rake test PG_DEBUG=1
environment:
matrix:
- ruby_version: "head"
RUBYDOWNLOAD: x86
PGVERSION: 10.16-1-windows
PGVER: 10
- ruby_version: "24"
- ruby_version: "25"
PGVERSION: 9.3.25-1-windows
PGVER: 9.3
2 changes: 1 addition & 1 deletion .github/workflows/binary-gems.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- ruby: "3.0"
PGVERSION: 13.2-1-windows-x64
PGVER: "13"
- ruby: "2.4"
- ruby: "2.5"
PGVERSION: 10.16-1-windows
PGVER: "10"

Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/source-gem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ jobs:
PGVERSION: 13.2-1-windows-x64
PGVER: "13"
- os: windows
ruby: "2.4"
ruby: "2.5"
PGVERSION: 9.3.25-1-windows-x64
PGVER: "9.3"
- os: ubuntu
ruby: "head"
PGVER: "13"
- os: ubuntu
ruby: "2.4"
ruby: "3.0"
PGVER: "12"
- os: ubuntu
ruby: "2.5"
PGVER: "9.3"
- os: ubuntu
ruby: "truffleruby"
Expand Down Expand Up @@ -110,8 +113,12 @@ jobs:
- run: bundle install

- run: gem install --local *.gem --verbose

- name: Run specs
run: ruby -rpg -S rspec spec/**/*_spec.rb
continue-on-error: ${{ matrix.ruby == 'truffleruby' }}
env:
PG_DEBUG: 1
run: ruby -rpg -S rspec spec/**/*_spec.rb -cfdoc

- name: Print logs if job failed
if: ${{ failure() && matrix.os == 'windows' }}
Expand Down
11 changes: 8 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sudo: required
dist: xenial
dist: focal
services:
- docker
language: ruby
Expand All @@ -17,12 +17,17 @@ matrix:
script: |
docker run --rm -t --network=host ruby-pg

- rvm: "2.4"
- rvm: "2.5"
env:
- "PGVERSION=9.3"
# Use Ubuntu-16.04 since postgresql-9.3 depends on openssl-1.0.0, which isn't available in 20.04
dist: xenial
- rvm: ruby-head
env:
- "PGVERSION=13"
- rvm: truffleruby
env:
- "PGVERSION=13"

allow_failures:
- rvm: ruby-head
Expand All @@ -38,7 +43,7 @@ before_install:
- export PATH=/usr/lib/postgresql/$PGVERSION/bin:$PATH

script:
- bundle exec rake compile test
- bundle exec rake compile test PG_DEBUG=1

after_failure:
- "find tmp -name mkmf.log | xargs cat"
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Rake::ExtensionTask.new do |ext|
end
end

RSpec::Core::RakeTask.new(:spec).rspec_opts = "--profile"
RSpec::Core::RakeTask.new(:spec).rspec_opts = "--profile -cfdoc"
task :test => :spec

# Use the fivefish formatter for docs generated from development checkout
Expand Down
2 changes: 1 addition & 1 deletion Rakefile.cross
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ CrossLibraries.each do |xlib|
RakeCompilerDock.sh <<-EOT, platform: platform
(cp build/gem/gem-*.pem ~/.gem/ || true) &&
bundle install --local &&
rake native:#{platform} pkg/#{$gem_spec.full_name}-#{platform}.gem MAKE="make -j`nproc`"
rake native:#{platform} pkg/#{$gem_spec.full_name}-#{platform}.gem MAKE="make -j`nproc`" RUBY_CC_VERSION=3.0.0:2.7.0:2.6.0:2.5.0
EOT
end
desc "Build the windows binary gems"
Expand Down
8 changes: 8 additions & 0 deletions ext/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
ENV['PATH'] = "#{pgdir}/bin" + File::PATH_SEPARATOR + ENV['PATH']
end

if enable_config("gvl-unlock", true)
$defs.push( "-DENABLE_GVL_UNLOCK" )
$stderr.puts "Calling libpq with GVL unlocked"
else
$stderr.puts "Calling libpq with GVL locked"
end

if enable_config("windows-cross")
# Avoid dependency to external libgcc.dll on x86-mingw32
$LDFLAGS << " -static-libgcc"
Expand Down Expand Up @@ -142,6 +149,7 @@ module PG
have_func 'timegm'
have_func 'rb_gc_adjust_memory_usage' # since ruby-2.4
have_func 'rb_gc_mark_movable' # since ruby-2.7
have_func 'rb_io_wait' # since ruby-3.0

# unistd.h confilicts with ruby/win32.h when cross compiling for win32 and ruby 1.9.1
have_header 'unistd.h'
Expand Down
4 changes: 4 additions & 0 deletions ext/gvl_wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
char *PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user, const char *algorithm){return NULL;}
#endif

#ifdef ENABLE_GVL_UNLOCK
FOR_EACH_BLOCKING_FUNCTION( DEFINE_GVL_WRAPPER_STRUCT );
FOR_EACH_BLOCKING_FUNCTION( DEFINE_GVL_SKELETON );
#endif
FOR_EACH_BLOCKING_FUNCTION( DEFINE_GVL_STUB );
#ifdef ENABLE_GVL_UNLOCK
FOR_EACH_CALLBACK_FUNCTION( DEFINE_GVL_WRAPPER_STRUCT );
FOR_EACH_CALLBACK_FUNCTION( DEFINE_GVLCB_SKELETON );
#endif
FOR_EACH_CALLBACK_FUNCTION( DEFINE_GVLCB_STUB );
20 changes: 20 additions & 0 deletions ext/gvl_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

#include <ruby/thread.h>

#ifdef RUBY_EXTCONF_H
# include RUBY_EXTCONF_H
#endif

#define DEFINE_PARAM_LIST1(type, name) \
name,

Expand Down Expand Up @@ -46,6 +50,7 @@
return NULL; \
}

#ifdef ENABLE_GVL_UNLOCK
#define DEFINE_GVL_STUB(name, when_non_void, rettype, lastparamtype, lastparamname) \
rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
struct gvl_wrapper_##name##_params params = { \
Expand All @@ -54,6 +59,13 @@
rb_thread_call_without_gvl(gvl_##name##_skeleton, &params, RUBY_UBF_IO, 0); \
when_non_void( return params.retval; ) \
}
#else
#define DEFINE_GVL_STUB(name, when_non_void, rettype, lastparamtype, lastparamname) \
rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
when_non_void( return ) \
name( FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST1) lastparamname ); \
}
#endif

#define DEFINE_GVL_STUB_DECL(name, when_non_void, rettype, lastparamtype, lastparamname) \
rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname);
Expand All @@ -66,6 +78,7 @@
return NULL; \
}

#ifdef ENABLE_GVL_UNLOCK
#define DEFINE_GVLCB_STUB(name, when_non_void, rettype, lastparamtype, lastparamname) \
rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
struct gvl_wrapper_##name##_params params = { \
Expand All @@ -74,6 +87,13 @@
rb_thread_call_with_gvl(gvl_##name##_skeleton, &params); \
when_non_void( return params.retval; ) \
}
#else
#define DEFINE_GVLCB_STUB(name, when_non_void, rettype, lastparamtype, lastparamname) \
rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
when_non_void( return ) \
name( FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST1) lastparamname ); \
}
#endif

#define GVL_TYPE_VOID(string)
#define GVL_TYPE_NONVOID(string) string
Expand Down
3 changes: 3 additions & 0 deletions ext/pg.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <sys/types.h>
#if !defined(_WIN32)
# include <sys/time.h>
# include <sys/socket.h>
#endif
#if defined(HAVE_UNISTD_H) && !defined(_WIN32)
# include <unistd.h>
Expand Down Expand Up @@ -113,6 +114,8 @@ typedef struct {
int enc_idx : PG_ENC_IDX_BITS;
/* flags controlling Symbol/String field names */
unsigned int flags : 2;
/* enable automatic flushing of send data at the end of send_query calls */
unsigned int flush_data : 1;

#if defined(_WIN32)
/* File descriptor to be used for rb_w32_unwrap_io_handle() */
Expand Down
Loading