Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

The Memcached addon now uses the proper public API for libmemcached. #215

Merged
merged 2 commits into from

2 participants

@Hamled

Unfortunately in order for this to work correctly it was necessary to decide a particular version to be compatible with, as the Memcached addon uses functionality that is implemented via two incompatible interfaces between older versions (such as libmemcached 0.39 and previous) and new versions (1.0.2 and later).
With these changes the Memcached addon is only compatible with libmemcached versions 1.0.2+.

NOTE: I have not tested these changes as I do not have any Io code that uses Memcached and there do not appear to be any unit tests.
I originally ended up making these changes due to a previous fix that broke compatibility with earlier versions of libmemcached (098921f).
Eventually I decided to make these particular changes after determining that it was not possible to use a single set of functionality from libmemcached that worked across all versions. Because these changes were primarily focused on unbreaking my own build, it is possible that the Memcached addon still has code which uses the non-official/public API of libmemcached.

Hamled added some commits
@Hamled Hamled Memcached stats method compatiblity fix
The stats method of Memcached is now compatible with libmemcached 1.0+.
fd67950
@Hamled Hamled Further Memcached compatibility fixes
The Memcached addon is now compatible with the API for libmemcached 1.0
throughout. The stats method also sets the error state if errors were
encountered.
b53b3d8
@stevedekorte

Pulling - thanks Charles :)

@stevedekorte stevedekorte merged commit e7aadca into stevedekorte:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 21, 2012
  1. @Hamled

    Memcached stats method compatiblity fix

    Hamled authored
    The stats method of Memcached is now compatible with libmemcached 1.0+.
  2. @Hamled

    Further Memcached compatibility fixes

    Hamled authored
    The Memcached addon is now compatible with the API for libmemcached 1.0
    throughout. The stats method also sets the error state if errors were
    encountered.
This page is out of date. Refresh to see the latest.
View
70 addons/Memcached/source/IoMemcached.c
@@ -105,7 +105,7 @@ Returns self.
*/
IoObject *IoMemcached_addServer(IoMemcached *self, IoObject *locals, IoMessage *m)
{
- memcached_server_st *server;
+ memcached_server_list_st server;
server = memcached_servers_parse(IoMessage_locals_cStringArgAt_(m, locals, 0));
memcached_server_push(DATA(self)->mc, server);
@@ -132,7 +132,7 @@ IoObject *IoMemcached_set(IoMemcached *self, IoObject *locals, IoMessage *m)
size_t size;
char *cvalue = IoMemcached_serialize(self, locals, value, &size, &flags);
- memcached_return rc;
+ memcached_return_t rc;
rc = memcached_set(DATA(self)->mc,
CSTRING(key), IOSEQ_LENGTH(key),
cvalue, size,
@@ -164,7 +164,7 @@ IoObject *IoMemcached_add(IoMemcached *self, IoObject *locals, IoMessage *m)
size_t size;
char *cvalue = IoMemcached_serialize(self, locals, value, &size, &flags);
- memcached_return rc;
+ memcached_return_t rc;
rc = memcached_add(DATA(self)->mc,
CSTRING(key), IOSEQ_LENGTH(key),
cvalue, size,
@@ -200,7 +200,7 @@ IoObject *IoMemcached_replace(IoMemcached *self, IoObject *locals, IoMessage *m)
size_t size;
char *cvalue = IoMemcached_serialize(self, locals, value, &size, &flags);
- memcached_return rc;
+ memcached_return_t rc;
rc = memcached_replace(DATA(self)->mc,
CSTRING(key), IOSEQ_LENGTH(key),
cvalue, size,
@@ -230,7 +230,7 @@ IoObject *IoMemcached_append(IoMemcached *self, IoObject *locals, IoMessage *m)
IoSeq *key = IoMessage_locals_seqArgAt_(m, locals, 0);
IoSeq *value = IoMessage_locals_seqArgAt_(m, locals, 1);
- memcached_return rc;
+ memcached_return_t rc;
rc = memcached_append(DATA(self)->mc,
CSTRING(key), IOSEQ_LENGTH(key),
CSTRING(value), IOSEQ_LENGTH(value),
@@ -254,7 +254,7 @@ IoObject *IoMemcached_prepend(IoMemcached *self, IoObject *locals, IoMessage *m)
IoSeq *key = IoMessage_locals_seqArgAt_(m, locals, 0);
IoSeq *value = IoMessage_locals_seqArgAt_(m, locals, 1);
- memcached_return rc;
+ memcached_return_t rc;
rc = memcached_prepend(DATA(self)->mc,
CSTRING(key), IOSEQ_LENGTH(key),
CSTRING(value), IOSEQ_LENGTH(value),
@@ -279,7 +279,7 @@ IoObject *IoMemcached_get(IoMemcached *self, IoObject *locals, IoMessage *m)
size_t size;
uint32_t flags;
- memcached_return rc;
+ memcached_return_t rc;
char *cvalue;
cvalue = memcached_get(DATA(self)->mc,
@@ -322,7 +322,7 @@ IoObject *IoMemcached_getMulti(IoMemcached *self, IoObject *locals, IoMessage *m
IOASSERT(IOSEQ_LENGTH(key) < MEMCACHED_MAX_KEY, "key is too long");
}
- char **ckeys = (char **) malloc(sizeof(char *) * keys_list_size);
+ const char **ckeys = (const char **) malloc(sizeof(const char *) * keys_list_size);
size_t *ckey_lengths = (size_t *) malloc(sizeof(size_t) * keys_list_size);
for(i = 0; i < keys_list_size; i++) {
@@ -330,7 +330,7 @@ IoObject *IoMemcached_getMulti(IoMemcached *self, IoObject *locals, IoMessage *m
ckey_lengths[i] = strlen(ckeys[i]);
}
- memcached_return rc = memcached_mget(DATA(self)->mc, ckeys, ckey_lengths, keys_list_size);
+ memcached_return_t rc = memcached_mget(DATA(self)->mc, ckeys, ckey_lengths, keys_list_size);
free(ckeys);
free(ckey_lengths);
@@ -377,7 +377,7 @@ IoObject *IoMemcached_delete(IoMemcached *self, IoObject *locals, IoMessage *m)
time_t time = IoMessage_argCount(m) == 2 ? IoMessage_locals_intArgAt_(m, locals, 1) : 0;
- memcached_return rc;
+ memcached_return_t rc;
rc = memcached_delete(DATA(self)->mc,
CSTRING(key), IOSEQ_LENGTH(key),
time
@@ -423,7 +423,7 @@ IoObject *IoMemcached_incr(IoMemcached *self, IoObject *locals, IoMessage *m)
uint64_t new_value;
- memcached_return rc;
+ memcached_return_t rc;
rc = memcached_increment(DATA(self)->mc,
CSTRING(key), IOSEQ_LENGTH(key),
offset, &new_value
@@ -451,7 +451,7 @@ IoObject *IoMemcached_decr(IoMemcached *self, IoObject *locals, IoMessage *m)
uint64_t new_value;
- memcached_return rc;
+ memcached_return_t rc;
rc = memcached_decrement(DATA(self)->mc,
CSTRING(key), IOSEQ_LENGTH(key),
offset, &new_value
@@ -473,40 +473,58 @@ IoObject *IoMemcached_stats(IoMemcached *self, IoObject *locals, IoMessage *m)
{
IoMap *results_map = IoMap_new(IOSTATE);
- int i;
- for(i = 0; i < memcached_server_list_count(DATA(self)->mc->servers); i++) {
- memcached_server_st *server = DATA(self)->mc->servers + i;
+ int errors = 0;
+ uint32_t pos = 0;
+ while(pos < memcached_server_count(DATA(self)->mc)) {
+ memcached_server_instance_st server = memcached_server_instance_by_position(DATA(self)->mc, pos);
+ if(server == NULL)
+ continue;
+
+ const char *hostname = memcached_server_name(server);
+ const in_port_t port = memcached_server_port(server);
memcached_stat_st stats;
- if(memcached_stat_servername(&stats, "", server->hostname, server->port) != 0)
+ memcached_return_t rc = memcached_stat_servername(&stats, "", hostname, port);
+ if(rc != MEMCACHED_SUCCESS) {
+ errors++;
continue;
+ }
- memcached_return rc;
char **ckeys = memcached_stat_get_keys(DATA(self)->mc, &stats, &rc);
-
- int ckeys_count = 0;
- while(ckeys[ckeys_count] != NULL)
- ckeys_count++;
+ if(rc != MEMCACHED_SUCCESS) {
+ errors++;
+ continue;
+ }
IoMap *per_server_map = IoMap_new(IOSTATE);
- int k;
- for(k = 0; k < ckeys_count; k++) {
- char *ckey = ckeys[k];
+ char *ckey = *ckeys;
+ while(ckey != NULL) {
char *cvalue = memcached_stat_get_value(DATA(self)->mc, &stats, ckey, &rc);
+ if(rc != MEMCACHED_SUCCESS) {
+ errors++;
+ continue;
+ }
+
IoMap_rawAtPut(per_server_map, IOSYMBOL(ckey), IOSYMBOL(cvalue));
free(cvalue);
+ ckey++;
}
free(ckeys);
// "127.0.0.1:11211"
- char *server_key = (char *) malloc((strlen(server->hostname) + 1 + 5 + 1) * sizeof(char));
- sprintf(server_key, "%s:%d", server->hostname, server->port);
+ char *server_key = (char *) malloc((strlen(hostname) + 1 + 5 + 1) * sizeof(char));
+ sprintf(server_key, "%s:%d", hostname, port);
IoMap_rawAtPut(results_map, IOSYMBOL(server_key), per_server_map);
free(server_key);
+
+ pos++;
}
+ if(errors > 0)
+ IoState_error_(IOSTATE, m, memcached_strerror(DATA(self)->mc, MEMCACHED_SOME_ERRORS));
+
return results_map;
}
View
2  modules/FindLibMemcached.cmake
@@ -6,7 +6,7 @@
FIND_PATH(LIBMEMCACHED_INCLUDE_DIR libmemcached/memcached.h)
-FIND_LIBRARY(LIBMEMCACHED_LIBRARY NAMES memcached PATH /usr/lib /usr/local/lib)
+FIND_LIBRARY(LIBMEMCACHED_LIBRARY NAMES memcached libmemcached PATH /usr/lib /usr/local/lib)
IF(LIBMEMCACHED_INCLUDE_DIR AND LIBMEMCACHED_LIBRARY)
SET(LIBMEMCACHED_FOUND 1)
Something went wrong with that request. Please try again.