pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Victor Wagner <vitus@wagner.pp.ru>
To: pgsql-hackers@postgresql.org
Subject: Re: Patch: Implement failover on libpq connect level.
Date: Wed, 7 Sep 2016 16:56:34 +0300
Message-ID: <20160907165634.5f8e9675@fafnir.local.vm> (raw)
In-Reply-To: <20160905110311.GA11351@e733>
References: <56E0AD90.5090409@pgmasters.net>
	<CANP8+jKPORaK2Xhuwc6KJ6qwfL8KiVZjxDw16sS0XoDe0Kh7qw@mail.gmail.com>
	<56E9E978.5090103@pgmasters.net>
	<CAD__OugniD9nz6weXCvnEELKX2iTK3xCmVWttVjLH0k5rn_NOA@mail.gmail.com>
	<CAD__Ouh53ttKfZ-439R9OGDOx=1xbBHS34SKOgTLqu73=gcp7Q@mail.gmail.com>
	<20160831111330.53a018ed@fafnir.local.vm>
	<CAD__OuimXSFUNCXXfcXXGEceuH8ik+Hr9qSYU0BidZw4gSxdig@mail.gmail.com>
	<CAD__Oui-3m6W83HyQNQLczrGRDQr4R67jv76DGwf1tT764zQ5A@mail.gmail.com>
	<CAD__OuhfOL-TQz-BBrFMj_tu8DqTc+ccxbwLkj+tUHAzvH14Pw@mail.gmail.com>
	<20160905072215.4efd7b8a@wagner.wagner.home>
	<20160905110311.GA11351@e733>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

On Mon, 5 Sep 2016 14:03:11 +0300
Aleksander Alekseev <a.alekseev@postgrespro.ru> wrote:

> Hello, Victor.
> 
> 
> 1) It looks like code is not properly formatted.
> 

Thanks for pointing to the documentation and formatting problems. I'll
fix them 
 
> >  static int 
> >  connectDBStart(PGconn *conn)
> >  {
> > +       struct nodeinfo
> > +       {
> > +               char       *host;
> > +               char       *port;
> > +       };  
> 
> Not sure if all compilers we support can parse this. I suggest to
> declare nodinfo structure outside of procedure, just to be safe.
> 

Block-local structs  are part of C language standard. I don't remember
when they appeared first (may be in K&R C), but at least since C89 AFAIR
they are allowed explicitely.

And using most local scope possible is always a good thing.

So, I'll leave this structure function local for now.


> 
> You should check return values of malloc, calloc and strdup
> procedures, or use safe pg_* equivalents.

Thanks, I'll fix this one.
 
> 6) 
> 
> > +                       for (p = addrs; p->ai_next != NULL; p =
> >   p->ai_next);
> > +                       p->ai_next = this_node_addrs;  
> 
> Looks a bit scary. I suggest to add an empty scope ( {} ) and a
> comment to make our intention clear here.

Ok, it really would make code more clear.
 
> 7) Code compiles with following warnings (CLang 3.8):
> 
> > 1 warning generated.
> > fe-connect.c:5239:39: warning: if statement has empty body
> > [-Wempty-body]
> >                                                                    errorMessage,
> > false, true));
> >                                                                                               ^
> > fe-connect.c:5239:39: note: put the semicolon on a separate line to
> > silence this warning
> > 1 warning generated.  

Oops, it looks like logic error, which should be fixed. Thanks for
testing my patch by more picky compiler.

> 8) get_next_element procedure implementation is way too smart (read
> "complicated"). You could probably just store current list length and
> generate a random number between 0 and length-1.

No, algorithm here is more complicated. It must ensure that there would
not be second attempt to connect to host, for which unsuccessful
connection attempt was done. So, there is list rearrangement.

Algorithm for pick random list element by single pass is quite trivial.




-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



view thread (165+ messages)  latest in thread

Message-ID: <20160907165634.5f8e9675@fafnir.local.vm>
Permalink:  ../20160907165634.5f8e9675@fafnir.local.vm/
Also on:    postgresql.org/message-id/20160907165634.5f8e9675@fafnir.local.vm

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: vitus@wagner.pp.ru, pgsql-hackers@postgresql.org
  Subject: Re: Patch: Implement failover on libpq connect level.
  In-Reply-To: <20160907165634.5f8e9675@fafnir.local.vm>
  References: <56E0AD90.5090409@pgmasters.net> <CANP8+jKPORaK2Xhuwc6KJ6qwfL8KiVZjxDw16sS0XoDe0Kh7qw@mail.gmail.com> <56E9E978.5090103@pgmasters.net> <CAD__OugniD9nz6weXCvnEELKX2iTK3xCmVWttVjLH0k5rn_NOA@mail.gmail.com> <CAD__Ouh53ttKfZ-439R9OGDOx=1xbBHS34SKOgTLqu73=gcp7Q@mail.gmail.com> <20160831111330.53a018ed@fafnir.local.vm> <CAD__OuimXSFUNCXXfcXXGEceuH8ik+Hr9qSYU0BidZw4gSxdig@mail.gmail.com> <CAD__Oui-3m6W83HyQNQLczrGRDQr4R67jv76DGwf1tT764zQ5A@mail.gmail.com> <CAD__OuhfOL-TQz-BBrFMj_tu8DqTc+ccxbwLkj+tUHAzvH14Pw@mail.gmail.com> <20160905072215.4efd7b8a@wagner.wagner.home> <20160905110311.GA11351@e733> <20160907165634.5f8e9675@fafnir.local.vm>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox