Re: getaddrinfo() for threading instead of gethostbyname()

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: getaddrinfo() for threading instead of gethostbyname()
Date: 2003-09-27 16:25:52
Message-ID: 200309271625.h8RGPql09787@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


OK, the thread test program is read for platform testing,
src/tools/thread_test. You will find the README, Makefile tests, and
program output to be very clear and almost error-proof.

Please run it on platforms we support and report back. Thanks.

---------------------------------------------------------------------------

Bruce Momjian wrote:
> When FreeBSD didn't have gethostbyname_r(), and gethostbyname() wasn't
> thread-safe, Marc asked around and found out that the threaded solution
> for this is to use getaddrinfo(). This makes sense because
> getaddrinfo() is described as:
>
> getaddrinfo () function is defined for protocol-independent nodename-
> to-address translation. It performs functionality of gethostbyname(3)
> and getservbyname(3), in more sophisticated manner.
>
> A number of platforms have getpwuid_r(), but not gethostbyname_r(). I
> now realize it is because they are assuming you arew using getaddrinfo(),
> which has freeaddrinfo() to free the allocated memory in a thread-safe
> manner.
>
> Right now, we call gethostname() from two places:
>
> port/getaddrinfo() (if backend)
> port/thread.c::pqGethostbyname()
>
> and pqGethostbyname() (thread-safe) is called only by:
>
> port/getaddrinfo() (if frontend)
> libpq/fe-secure.c
>
> If we convert fe-secure.c to use getaddrinfo(), then all host address
> lookups go through getaddrinfo().
>
> Then, if we don't need our port/getaddrinfo(), we don't care about a
> non-thread-safe gethostbyname() on that platform. This improves our
> thread-safe support. Specifically, it prevents host name lookups from
> be serialized by our pthread locks.
>
> Once everything goes through getaddrinfo(), I will modify my thread test
> program to test gethostbyname() threading _only_ if getaddrinfo()
> doesn't exist.
>
> --
> Bruce Momjian | http://candle.pha.pa.us
> pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
> + If your life is a hard drive, | 13 Roberts Road
> + Christ can be your backup. | Newtown Square, Pennsylvania 19073
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
> joining column's datatypes do not match
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2003-09-27 16:29:47 Re: initdb failure (was Re: [GENERAL] sequence's plpgsql)
Previous Message Rémi Zara 2003-09-27 16:11:42 Re: Postgresql 7.3.4 compile failes on NetBSD 1.6 mac68k