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?

In reply to Using Net:Etcd from inside AnyEvent Callback leads to Recorsive Blocking Wait Attempted by einhverfr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.