einhverfr has asked for the wisdom of the Perl Monks concerning the following question:
Hi
I am trying to write a small program that reads from the logical replication stream of PostgreSQL and writes to etcd after some transformations of the data. I also need another program which reads from etcd using watches and both writes to Postgres and handles various conditions along the way including possibly starting, stopping, or restarting other programs. This is part of a larger control plane system and fills a specific role.
The obvious module to use on the logical replication side is AnyEvent::PGRecvlogical and on the etcd side, since I need watches on the other piece, Net::Etcd. My plan was to receive messages, parse them, transform them as needed, and then send them of to Net::Etcd.
Simplified callback code:
my $callback = sub { my ($message, $guard) = @_; my $hashref = parse($message); if ($hashref && ($hashref->{schema} eq 'storage')) { my $key = kval_key($hashref->{tablename}, $hashref->{row_ +data}); my $value = encode_json($hashref); my $resp = $kvstore->write($key, $value); # TODO: Handle errors, see issue #77 } undef $guard; };
The kvstore->write maps to Net::Etcd's put function.
The problem:
Net::Etcd uses HTTP::AnyEvent behind the scenes, and this means there are blocking calls to condvars inside the put command. The result is that I get the following error:
AnyEvent::CondVar: recursive blocking wait attempted at /usr/lib64/perl5/vendor_perl/5.38/x86_64-linux/AnyEvent.pm line 2027.
AnyEvent::CondVar::Base::recv(AnyEvent::CondVar=HASH(0x56071b8f82d0)) called at /usr/lib64/perl5/vendor_perl/5.38/Net/Etcd/Role/Actions.pm line 232
Net::Etcd::Role::Actions::_build_request(Net::Etcd::KV::Put=HASH(0x56071bd65aa0)) called at (eval 740) line 20
Net::Etcd::Role::Actions::request(Net::Etcd::KV::Put=HASH(0x56071bd65aa0)) called at /usr/lib64/perl5/vendor_perl/5.38/Net/Etcd/KV.pm line 102
Net::Etcd::KV::put(Net::Etcd=HASH(0x56071bc2f0a0), HASH(0x560717e87588)) called at /home/chris/github/omd-bagger/lib/Bagger/Agent/Drivers/KVStore/Etcd.pm line 153
Bagger::Agent::Drivers::KVStore::Etcd::kvwrite(Bagger::Agent::Drivers::KVStore::Etcd=HASH(0x56071b8db328), "/PostgresInstance/host3/5432", "{\"row_data\":{\"host\":\"host3\",\"id\":\"3\",\"username\":\"bagger\",\"por"...) called at /home/chris/github/omd-bagger/lib/Bagger/Agent/KVStore.pm line 136
Any ideas on how to solve this? Do I need to write my own etcd interaction layer or use a different driver for this?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using Net:Etcd from inside AnyEvent Callback leads to Recorsive Blocking Wait Attempted
by Corion (Patriarch) on Oct 29, 2023 at 08:06 UTC | |
by einhverfr (Friar) on Oct 29, 2023 at 08:52 UTC | |
|
Re: Using Net:Etcd from inside AnyEvent Callback leads to Recorsive Blocking Wait Attempted
by einhverfr (Friar) on Oct 30, 2023 at 00:58 UTC |