Skip to content

Commit

Permalink
backend server hostnames are resolved lazily
Browse files Browse the repository at this point in the history
  • Loading branch information
manjuraj committed Jun 19, 2015
1 parent d3c19ad commit fd34c29
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/nc_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1635,10 +1635,13 @@ conf_add_server(struct conf *cf, struct command *cmd, void *conf)
return CONF_ERROR;
}

status = nc_resolve(&field->addrstr, field->port, &field->info);
if (status != NC_OK) {
return CONF_ERROR;
}
/*
* The address resolution of the backend server hostname is lazy.
* The resolution occurs when a new connection to the server is
* created, which could either be the first time or every time
* or every time the server gets re-added to the pool after an
* auto ejection.
*/

field->valid = 1;

Expand Down
27 changes: 24 additions & 3 deletions src/nc_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@
#include <nc_server.h>
#include <nc_conf.h>

static void
server_resolve(struct server *server, struct conn *conn)
{
rstatus_t status;

status = nc_resolve(&server->addrstr, server->port, &server->info);
if (status != NC_OK) {
conn->err = EHOSTDOWN;
conn->done = 1;
return;
}

conn->family = server->info.family;
conn->addrlen = server->info.addrlen;
conn->addr = (struct sockaddr *)&server->info.addr;
}

void
server_ref(struct conn *conn, void *owner)
{
Expand All @@ -30,9 +47,7 @@ server_ref(struct conn *conn, void *owner)
ASSERT(!conn->client && !conn->proxy);
ASSERT(conn->owner == NULL);

conn->family = server->info.family;
conn->addrlen = server->info.addrlen;
conn->addr = (struct sockaddr *)&server->info.addr;
server_resolve(server, conn);

server->ns_conn_q++;
TAILQ_INSERT_TAIL(&server->s_conn_q, conn, conn_tqe);
Expand Down Expand Up @@ -454,6 +469,12 @@ server_connect(struct context *ctx, struct server *server, struct conn *conn)

ASSERT(!conn->client && !conn->proxy);

if (conn->err) {
ASSERT(conn->done && conn->sd < 0);
errno = conn->err;
return NC_ERROR;
}

if (conn->sd > 0) {
/* already connected on server connection */
return NC_OK;
Expand Down

0 comments on commit fd34c29

Please sign in to comment.