[mod_memcached]: try to fail quietly after connection resets until the next connect

personal/stbuehler/wip
Stefan Bühler 12 years ago
parent d498a9fee9
commit 831cca1c59
  1. 1
      include/lighttpd/memcached.h
  2. 16
      src/common/memcached.c
  3. 8
      src/modules/mod_memcached.c

@ -38,6 +38,7 @@ LI_API GQuark li_memcached_error_quark();
typedef enum {
LI_MEMCACHED_CONNECTION,
LI_MEMCACHED_BAD_KEY,
LI_MEMCACHED_DISABLED, /* disabled right now */
LI_MEMCACHED_UNKNOWN = 0xff
} liMemcachedError;

@ -223,6 +223,9 @@ static void cancel_all_requests(liMemcachedCon *con) {
}
if (req->req.callback) req->req.callback(&req->req, LI_MEMCACHED_RESULT_ERROR, NULL, &err);
if (err1) err1->code = LI_MEMCACHED_DISABLED; /* "silent" fail */
if (con->err) con->err->code = LI_MEMCACHED_DISABLED; /* "silent" fail */
}
if (NULL != err) g_clear_error(&err);
@ -255,7 +258,14 @@ static void memcached_connect(liMemcachedCon *con) {
s = con->con_watcher.fd;
if (-1 == s) {
/* reconnect limit */
if (ev_now(con->loop) < con->last_con_start + 1) return;
if (ev_now(con->loop) < con->last_con_start + 1) {
if (con->err) {
con->err->code = LI_MEMCACHED_DISABLED;
} else {
g_set_error(&con->err, LI_MEMCACHED_ERROR, LI_MEMCACHED_DISABLED, "Disabled right now");
}
return;
}
con->last_con_start = ev_now(con->loop);
do {
@ -838,7 +848,7 @@ liMemcachedRequest* li_memcached_get(liMemcachedCon *con, GString *key, liMemcac
if (-1 == con->fd) memcached_connect(con);
if (-1 == con->fd) {
if (NULL == con->err) {
g_set_error(err, LI_MEMCACHED_ERROR, LI_MEMCACHED_CONNECTION, "Not connected");
g_set_error(err, LI_MEMCACHED_ERROR, LI_MEMCACHED_DISABLED, "Not connected");
} else if (err) {
*err = g_error_copy(con->err);
}
@ -871,7 +881,7 @@ liMemcachedRequest* li_memcached_set(liMemcachedCon *con, GString *key, guint32
if (-1 == con->fd) memcached_connect(con);
if (-1 == con->fd) {
if (NULL == con->err) {
g_set_error(err, LI_MEMCACHED_ERROR, LI_MEMCACHED_CONNECTION, "Not connected");
g_set_error(err, LI_MEMCACHED_ERROR, LI_MEMCACHED_DISABLED, "Not connected");
} else if (err) {
*err = g_error_copy(con->err);
}

@ -377,7 +377,9 @@ static liHandlerResult mc_handle_lookup(liVRequest *vr, gpointer param, gpointer
if (NULL == req->req) {
if (NULL != err) {
VR_ERROR(vr, "memcached.lookup: get failed: %s", err->message);
if (LI_MEMCACHED_DISABLED != err->code) {
VR_ERROR(vr, "memcached.lookup: get failed: %s", err->message);
}
g_clear_error(&err);
} else {
VR_ERROR(vr, "memcached.lookup: get failed: %s", "Unkown error");
@ -498,7 +500,9 @@ static liHandlerResult memcache_store_filter(liVRequest *vr, liFilter *f) {
if (NULL == req) {
if (NULL != err) {
VR_ERROR(vr, "memcached.store: set failed: %s", err->message);
if (LI_MEMCACHED_DISABLED != err->code) {
VR_ERROR(vr, "memcached.store: set failed: %s", err->message);
}
g_clear_error(&err);
} else {
VR_ERROR(vr, "memcached.store: set failed: %s", "Unkown error");

Loading…
Cancel
Save