Skip to content

Commit

Permalink
Merge pull request #843 from jfsmig/3.1.x-shorter-getvers-timeouts
Browse files Browse the repository at this point in the history
sqliterepo: Shorten the cnx timeout for USE and GETVERS requests
  • Loading branch information
jfsmig authored Feb 1, 2017
2 parents ed01ed4 + 25dbf79 commit 1809cef
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 29 deletions.
4 changes: 3 additions & 1 deletion BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,12 @@ Used by `gcc`
| M2V2_CLIENT_TIMEOUT | 10.0 | <double> value telling the default timeout for meta2 requests, in seconds. |
| M2V2_CLIENT_TIMEOUT_HUGE | 10.0 | <double> value telling the default timeout for meta2 requests, in seconds. |
| SQLX_CLIENT_TIMEOUT | 30.0 | <double> value telling the default timeout for sqlx requests, in seconds. |
| SQLX_CNX_TIMEOUT_GETVERS | 0.5 | <double> value telling the default timeout for DB_VERS requests, in seconds. |
| SQLX_CNX_TIMEOUT_USE | 0.25 | <double> value telling the default timeout for DB_USE (tcp) requests, in seconds. |
| SQLX_SYNC_TIMEOUT | 4.0 | <double> value telling the default timeout for sqlx requests, in seconds. |
| SQLX_REPLI_TIMEOUT | 10.0 | <double> value telling the default timeout for sqlx requests, in seconds. |
| SQLX_RESYNC_TIMEOUT | 30.0 | <double> value telling the default timeout for sqlx requests, in seconds. |
| COMMON_CNX_TIMEOUT | 2 * G_TIME_SPAN_SECOND | In monotonic clock's precision |
| COMMON_CNX_TIMEOUT | 2.0 | <double> value in seconds |
| COMMON_CLIENT_TIMEOUT | 30.0 | In monotonic clock's precision |
| COMMON_STAT_TIMEOUT | 5.0 | <double> value telling the default timeout for /stat requests outgoing the proxy, in seconds. |

Expand Down
16 changes: 14 additions & 2 deletions core/oiocfg.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
OpenIO SDS core library
Copyright (C) 2015-2016 OpenIO, original work as part of OpenIO SDS
Copyright (C) 2015-2017 OpenIO, original work as part of OpenIO SDS
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -179,7 +179,7 @@ extern "C" {
# endif

# ifndef COMMON_CNX_TIMEOUT
# define COMMON_CNX_TIMEOUT (2*G_TIME_SPAN_SECOND)
# define COMMON_CNX_TIMEOUT 2.0
# endif

# ifndef COMMON_CLIENT_TIMEOUT
Expand All @@ -194,6 +194,18 @@ extern "C" {
# define SQLX_CLIENT_TIMEOUT 30.0
# endif

/* Timeout when connecting for DB_USE requests
in seconds */
# ifndef SQLX_CNX_TIMEOUT_USE
# define SQLX_CNX_TIMEOUT_USE 0.25
# endif

/* Timeout when connecting for GETVERS requests
in seconds */
# ifndef SQLX_CNX_TIMEOUT_GETVERS
# define SQLX_CNX_TIMEOUT_GETVERS 0.5
# endif

/* Timeout for synchronisation requests (USE, GETVERS)
in seconds */
# ifndef SQLX_SYNC_TIMEOUT
Expand Down
31 changes: 22 additions & 9 deletions metautils/lib/gridd_client.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
OpenIO SDS metautils
Copyright (C) 2014 Worldine, original work as part of Redcurrant
Copyright (C) 2015 OpenIO, modified as part of OpenIO Software Defined Storage
Copyright (C) 2015-2017 OpenIO, modified as part of OpenIO SDS
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -96,6 +96,7 @@ static GError* _client_error(struct gridd_client_s *client);
static gboolean _client_start(struct gridd_client_s *client);
static GError* _client_set_fd(struct gridd_client_s *client, int fd);
static void _client_set_timeout(struct gridd_client_s *client, gdouble seconds);
static void _client_set_timeout_cnx(struct gridd_client_s *client, gdouble sec);
static void _client_set_keepalive(struct gridd_client_s *client, gboolean on);
static void _client_react(struct gridd_client_s *client);
static gboolean _client_expire(struct gridd_client_s *client, gint64 now);
Expand Down Expand Up @@ -123,6 +124,7 @@ struct gridd_client_vtable_s VTABLE_CLIENT =
_client_set_fd,
_client_set_keepalive,
_client_set_timeout,
_client_set_timeout_cnx,
_client_expired,
_client_finished,
_client_start,
Expand Down Expand Up @@ -527,11 +529,19 @@ _client_set_timeout(struct gridd_client_s *client, gdouble seconds)
EXTRA_ASSERT(client != NULL);
EXTRA_ASSERT(client->abstract.vtable == &VTABLE_CLIENT);

client->delay_connect = COMMON_CNX_TIMEOUT;
client->delay_single = seconds * (gdouble) G_TIME_SPAN_SECOND;
client->delay_overall = seconds * (gdouble) G_TIME_SPAN_SECOND;
}

static void
_client_set_timeout_cnx(struct gridd_client_s *client, gdouble seconds)
{
EXTRA_ASSERT(client != NULL);
EXTRA_ASSERT(client->abstract.vtable == &VTABLE_CLIENT);

client->delay_connect = seconds * (gdouble) G_TIME_SPAN_SECOND;
}

static GError*
_client_set_fd(struct gridd_client_s *client, int fd)
{
Expand Down Expand Up @@ -771,11 +781,7 @@ _factory_create_client (struct gridd_client_factory_s *factory)
EXTRA_ASSERT(factory != NULL);
EXTRA_ASSERT(factory->abstract.vtable == &VTABLE_FACTORY);
(void) factory;
struct gridd_client_s *client = gridd_client_create_empty();
if (!client)
return NULL;
gridd_client_set_timeout(client, COMMON_CLIENT_TIMEOUT);
return client;
return gridd_client_create_empty();
}

/* ------------------------------------------------------------------------- */
Expand All @@ -790,8 +796,9 @@ gridd_client_create_empty(void)
client->abstract.vtable = &VTABLE_CLIENT;
client->fd = -1;
client->step = NONE;
client->delay_overall = GRIDC_DEFAULT_TIMEOUT_OVERALL * (gdouble)G_TIME_SPAN_SECOND;
client->delay_single = GRIDC_DEFAULT_TIMEOUT_STEP * (gdouble)G_TIME_SPAN_SECOND;
client->delay_overall = COMMON_CLIENT_TIMEOUT * (gdouble)G_TIME_SPAN_SECOND;
client->delay_single = COMMON_CLIENT_TIMEOUT * (gdouble)G_TIME_SPAN_SECOND;
client->delay_connect = COMMON_CNX_TIMEOUT * (gdouble)G_TIME_SPAN_SECOND;
client->tv_start = client->tv_connect = oio_ext_monotonic_time ();

return client;
Expand Down Expand Up @@ -876,6 +883,12 @@ gridd_client_set_timeout (struct gridd_client_s *self, gdouble seconds)
GRIDD_CALL(self,set_timeout)(self,seconds);
}

void
gridd_client_set_timeout_cnx (struct gridd_client_s *self, gdouble seconds)
{
GRIDD_CALL(self,set_timeout_cnx)(self,seconds);
}

gboolean
gridd_client_expired(struct gridd_client_s *self, gint64 now)
{
Expand Down
18 changes: 7 additions & 11 deletions metautils/lib/gridd_client.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
OpenIO SDS metautils
Copyright (C) 2014 Worldine, original work as part of Redcurrant
Copyright (C) 2015 OpenIO, modified as part of OpenIO Software Defined Storage
Copyright (C) 2015-2017 OpenIO, modified as part of OpenIO SDS
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand All @@ -23,14 +23,6 @@ License along with this library.
# include <glib.h>
# include "metautils.h"

# ifndef GRIDC_DEFAULT_TIMEOUT_STEP
# define GRIDC_DEFAULT_TIMEOUT_STEP 10.0
# endif

# ifndef GRIDC_DEFAULT_TIMEOUT_OVERALL
# define GRIDC_DEFAULT_TIMEOUT_OVERALL 30.0
# endif

struct gridd_client_s;
struct gridd_client_factory_s;

Expand Down Expand Up @@ -75,10 +67,13 @@ struct gridd_client_vtable_s
// Tells to keep the connection open between requests.
void (*set_keepalive) (struct gridd_client_s *c, gboolean on);

// Force the timeout for each signel request (step), and for each request
// and its redirections.
// Force global timeout for the operation (all the request, including
// the redirections)
void (*set_timeout) (struct gridd_client_s *c, gdouble seconds);

// Force the connection timeout for each unit request
void (*set_timeout_cnx) (struct gridd_client_s *c, gdouble seconds);

// Returns if the client's last change is older than 'now'
gboolean (*expired) (struct gridd_client_s *c, gint64 now);

Expand Down Expand Up @@ -117,6 +112,7 @@ int gridd_client_fd (struct gridd_client_s *self);
GError * gridd_client_set_fd(struct gridd_client_s *self, int fd);
void gridd_client_set_keepalive(struct gridd_client_s *self, gboolean on);
void gridd_client_set_timeout (struct gridd_client_s *self, gdouble seconds);
void gridd_client_set_timeout_cnx (struct gridd_client_s *self, gdouble sec);
gboolean gridd_client_expired(struct gridd_client_s *self, gint64 now);
gboolean gridd_client_finished (struct gridd_client_s *self);
gboolean gridd_client_start (struct gridd_client_s *self);
Expand Down
4 changes: 2 additions & 2 deletions server/internals.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
OpenIO SDS server
Copyright (C) 2014 Worldine, original work as part of Redcurrant
Copyright (C) 2015 OpenIO, modified as part of OpenIO Software Defined Storage
Copyright (C) 2015-2017 OpenIO, modified as part of OpenIO SDS
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand All @@ -28,7 +28,7 @@ License along with this library.
#endif

#ifndef OIO_SERVER_UDP_QUEUE_MAXAGE
#define OIO_SERVER_UDP_QUEUE_MAXAGE COMMON_CNX_TIMEOUT
#define OIO_SERVER_UDP_QUEUE_MAXAGE (2 * G_TIME_SPAN_SECOND)
#endif

enum {
Expand Down
6 changes: 3 additions & 3 deletions server/network_server.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
OpenIO SDS server
Copyright (C) 2014 Worldine, original work as part of Redcurrant
Copyright (C) 2015 OpenIO, modified as part of OpenIO Software Defined Storage
Copyright (C) 2015-2017 OpenIO, modified as part of OpenIO SDS
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -686,8 +686,8 @@ _cb_ping(struct network_client_s *clt, struct network_server_s *srv)

const gint64 now = oio_ext_monotonic_time();

/* COMMON_CNX_TIMEOUT is arbitrary but it avoid managing pings
* that have probably been retried by the emitter. */
/* OIO_SERVER_UDP_QUEUE_MAXAGE is arbitrary but it avoids managing
* pings that have probably been retried by the emitter. */
if (now - clt->time.evt_in > OIO_SERVER_UDP_QUEUE_MAXAGE) {
GRID_DEBUG("PING %s -> %s queued for too long",
clt->peer_name, clt->local_name);
Expand Down
6 changes: 5 additions & 1 deletion sqliterepo/synchro.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
OpenIO SDS sqliterepo
Copyright (C) 2014 Worldine, original work as part of Redcurrant
Copyright (C) 2015 OpenIO, modified as part of OpenIO Software Defined Storage
Copyright (C) 2015-2017 OpenIO, modified as part of OpenIO SDS
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -481,7 +481,10 @@ _direct_use (struct sqlx_peering_s *self,
} else {
struct event_client_s *mc = g_malloc0 (sizeof(struct event_client_s));
mc->client = gridd_client_factory_create_client (p->factory);

gridd_client_set_timeout(mc->client, SQLX_SYNC_TIMEOUT);
gridd_client_set_timeout_cnx(mc->client, SQLX_CNX_TIMEOUT_USE);

GError *err = gridd_client_connect_url (mc->client, url);
if (err) {
GRID_DEBUG("USE error: (%d) %s", err->code, err->message);
Expand Down Expand Up @@ -652,6 +655,7 @@ _direct_getvers (struct sqlx_peering_s *self,
mc->vremote = NULL;

gridd_client_set_timeout(mc->ec.client, SQLX_SYNC_TIMEOUT);
gridd_client_set_timeout_cnx(mc->ec.client, SQLX_CNX_TIMEOUT_GETVERS);

GError *err = gridd_client_connect_url (mc->ec.client, url);
if (NULL != err) {
Expand Down

0 comments on commit 1809cef

Please sign in to comment.