Re: Patch: Implement failover on libpq connect level.

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Victor Wagner <vitus(at)wagner(dot)pp(dot)ru>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Patch: Implement failover on libpq connect level.
Date: 2016-09-13 18:58:50
Message-ID: CA+TgmoamO_XWL6hmLVGG0akHPGmq=KQ-6Ymgf6ZYt7R9V=xFhg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-jdbc

On Fri, Sep 9, 2016 at 4:49 AM, Victor Wagner <vitus(at)wagner(dot)pp(dot)ru> wrote:
> Random permutation is much more computationally complex than random
> picking.

It really isn't. The pseudocode given at
https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle is all of 4
lines long, and one of those lines is a comment. The C implementation
is longer, but not by much.

Mind you, I haven't read the patch, so I don't know whether using
something like this would make the code simpler or more complicated.
However, if the two modes of operation are (1) try all hosts in random
order and (2) try all hosts in the listed order, it's worth noting
that the code for the second thing can be used to implement the first
thing just by shuffling the list before you begin.

> So, using random permutation instead of random pick wouln't help.
> And keeping somewhere number of elements in the list wouldn't help
> either unless we change linked list to completely different data
> structure which allows random access.

Is there a good reason not to use an array rather than a linked list?

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jesper Pedersen 2016-09-13 18:59:01 Re: Hash Indexes
Previous Message Peter Geoghegan 2016-09-13 18:56:49 Re: Vacuum: allow usage of more than 1GB of work mem

Browse pgsql-jdbc by date

  From Date Subject
Next Message danap 2016-09-13 21:02:55 Re: Filtering DatabaseMetaData to show only the items for which the current user has access
Previous Message Vladimir Sitnikov 2016-09-13 16:03:16 Re: Filtering DatabaseMetaData to show only the items for which the current user has access