From: | Aleksander Alekseev <aleksander(at)timescale(dot)com> |
---|---|
To: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Cc: | Daniel Gustafsson <daniel(at)yesql(dot)se>, Jelte Fennema <postgres(at)jeltef(dot)nl>, "Gregory Stark (as CFM)" <stark(dot)cfm(at)gmail(dot)com>, Andrey Borodin <amborodin86(at)gmail(dot)com>, Jacob Champion <jchampion(at)timescale(dot)com>, Maxim Orlov <orlovmg(at)gmail(dot)com>, Jelte Fennema <Jelte(dot)Fennema(at)microsoft(dot)com>, Michael Banck <mbanck(at)gmx(dot)net>, Andres Freund <andres(at)anarazel(dot)de> |
Subject: | Re: [EXTERNAL] Support load balancing in libpq |
Date: | 2023-03-27 13:32:20 |
Message-ID: | CAJ7c6TPsRBDnqBqb9cWzcZDpog3ypMJgZBo05eqROBHnm9ms4w@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi,
> So I think it should be:
>
> ```
> if (conn->addr == NULL && conn->naddr != 0)
> ```
>
> [...]
>
> I will take a look at v16 now.
The code coverage could be slightly better.
In v16-0001:
```
+ ret = store_conn_addrinfo(conn, addrlist);
+ pg_freeaddrinfo_all(hint.ai_family, addrlist);
+ if (ret)
+ goto error_return; /* message already logged */
```
The goto path is not test-covered.
In v16-0002:
```
+ }
+ else
+ conn->load_balance_type = LOAD_BALANCE_DISABLE;
```
The else branch is never executed.
```
if (ret)
goto error_return; /* message already logged */
+ /*
+ * If random load balancing is enabled we shuffle the addresses.
+ */
+ if (conn->load_balance_type == LOAD_BALANCE_RANDOM)
+ {
+ /*
+ * This is the "inside-out" variant of the Fisher-Yates shuffle
[...]
+ */
+ for (int i = 1; i < conn->naddr; i++)
+ {
+ int j =
pg_prng_uint64_range(&conn->prng_state, 0, i);
+ AddrInfo temp = conn->addr[j];
+
+ conn->addr[j] = conn->addr[i];
+ conn->addr[i] = temp;
+ }
+ }
```
Strangely enough the body of the for loop is never executed either.
Apparently only one address is used and there is nothing to shuffle?
Here is the exact command I used to build the code coverage report:
```
git clean -dfx && meson setup --buildtype debug -Db_coverage=true
-Dcassert=true -DPG_TEST_EXTRA="kerberos ldap ssl load_balance"
-Dldap=disabled -Dssl=openssl -Dtap_tests=enabled
-Dprefix=/home/eax/projects/pginstall build && ninja -C build &&
PG_TEST_EXTRA=1 meson test -C build && ninja -C build coverage-html
```
I'm sharing this for the sake of completeness. I don't have a strong
opinion on whether we should bother with covering every new line of
code with tests.
Except for the named nitpicks v16 looks good to me.
--
Best regards,
Aleksander Alekseev
From | Date | Subject | |
---|---|---|---|
Next Message | Aleksander Alekseev | 2023-03-27 13:35:50 | Re: [EXTERNAL] Support load balancing in libpq |
Previous Message | Julien Rouhaud | 2023-03-27 12:56:21 | Re: MacOS: xsltproc fails with "warning: failed to load external entity" |