Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bhdOA-0003ap-MI for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Sep 2016 13:59:42 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bhdO9-0002iy-R9 for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Sep 2016 13:59:41 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bhdMm-0008DI-3q for pgsql-hackers@postgresql.org; Wed, 07 Sep 2016 13:58:16 +0000 Received: from mx.wagner.pp.ru ([78.46.190.96]) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bhdMj-0005O2-Cn for pgsql-hackers@postgresql.org; Wed, 07 Sep 2016 13:58:14 +0000 Received: from mail.wagner.pp.ru (unknown [192.168.217.131]) by mx.wagner.pp.ru (Postfix) with ESMTP id 631DAE0047 for ; Wed, 7 Sep 2016 16:56:36 +0300 (MSK) Received: from fafnir.local.vm (newmail.postgrespro.ru [93.174.131.138]) by mail.wagner.pp.ru (Postfix) with ESMTPSA id 3C18D27191 for ; Wed, 7 Sep 2016 16:56:35 +0300 (MSK) Date: Wed, 7 Sep 2016 16:56:34 +0300 From: Victor Wagner To: pgsql-hackers@postgresql.org Subject: Re: Patch: Implement failover on libpq connect level. Message-ID: <20160907165634.5f8e9675@fafnir.local.vm> In-Reply-To: <20160905110311.GA11351@e733> References: <56E0AD90.5090409@pgmasters.net> <56E9E978.5090103@pgmasters.net> <20160831111330.53a018ed@fafnir.local.vm> <20160905072215.4efd7b8a@wagner.wagner.home> <20160905110311.GA11351@e733> X-Mailer: Claws Mail 3.13.0 (GTK+ 2.24.25; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -3.0 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On Mon, 5 Sep 2016 14:03:11 +0300 Aleksander Alekseev 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