From: Date: Sat, 5 Jan 2008 08:01:45 +0000 (-0800) Subject: memcached_behavior() causes commands to be buffered until they are flushed to X-Git-Tag: 0.13~14 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=edeb3965773b750c0cf454e8b1494fd030ba0369;p=awesomized%2Flibmemcached memcached_behavior() causes commands to be buffered until they are flushed to the remote connection. --- diff --git a/ChangeLog b/ChangeLog index a8e87a7d..6260ba04 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,9 @@ * Added memcached_fetch_execute() method * Found a bug where memcached_fetch() was not null terminating the result value. + * memcached_behavior() now has the ability to set "buffering" so that + data is not automatically flushed. + * Behavior change, buffered commands now return MEMCACHED_BUFFERED 0.12 Tue Dec 11 15:20:55 PST 2007 * Updates for consistent hashing diff --git a/docs/memcached_behavior.pod b/docs/memcached_behavior.pod index e5058de3..b76ae054 100755 --- a/docs/memcached_behavior.pod +++ b/docs/memcached_behavior.pod @@ -73,6 +73,12 @@ Support CAS operations (this is not enabled by default at this point in the serv Modify the timeout value that is used by poll(). The default value is -1. An signed int pointer must be passed to memcached_behavior_set() to change this value. For memcached_behavior_get() a signed int value will be cast and returned as the unsigned long long. +=item MEMCACHED_BUFFERED + +Enabling buffered IO causes commands to "buffer" instead of being sent. Any +action that gets data causes this buffer to be be sent to the remote +connection. Quiting the connection or closing down the connection will also +cause the buffered data to be pushed to the remote connection. =back diff --git a/include/memcached.h b/include/memcached.h index 1cbdcf68..fb836284 100644 --- a/include/memcached.h +++ b/include/memcached.h @@ -69,6 +69,7 @@ typedef enum { MEMCACHED_NO_KEY_PROVIDED, MEMCACHED_FETCH_NOTFINISHED, MEMCACHED_TIMEOUT, + MEMCACHED_BUFFERED, MEMCACHED_MAXIMUM_RETURN, /* Always add new error code before */ } memcached_return; @@ -88,6 +89,7 @@ typedef enum { MEMCACHED_BEHAVIOR_SUPPORT_CAS, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, MEMCACHED_BEHAVIOR_DISTRIBUTION, + MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, } memcached_behavior; typedef enum { diff --git a/lib/common.h b/lib/common.h index 395b80ef..35775ba8 100644 --- a/lib/common.h +++ b/lib/common.h @@ -60,6 +60,7 @@ typedef enum { MEM_USE_CRC= (1 << 5), MEM_USE_CACHE_LOOKUPS= (1 << 6), MEM_SUPPORT_CAS= (1 << 7), + MEM_BUFFER_REQUESTS= (1 << 8), } memcached_flags; /* Hashing algo */ diff --git a/lib/memcached_behavior.c b/lib/memcached_behavior.c index 853a33b3..c54d93fc 100644 --- a/lib/memcached_behavior.c +++ b/lib/memcached_behavior.c @@ -31,6 +31,8 @@ memcached_return memcached_behavior_set(memcached_st *ptr, break; case MEMCACHED_BEHAVIOR_NO_BLOCK: set_behavior_flag(ptr, MEM_NO_BLOCK, data); + case MEMCACHED_BEHAVIOR_BUFFER_REQUESTS: + set_behavior_flag(ptr, MEM_BUFFER_REQUESTS, data); break; case MEMCACHED_BEHAVIOR_TCP_NODELAY: set_behavior_flag(ptr, MEM_TCP_NODELAY, data); @@ -89,6 +91,9 @@ unsigned long long memcached_behavior_get(memcached_st *ptr, case MEMCACHED_BEHAVIOR_NO_BLOCK: temp_flag= MEM_NO_BLOCK; break; + case MEMCACHED_BEHAVIOR_BUFFER_REQUESTS: + temp_flag= MEM_BUFFER_REQUESTS; + break; case MEMCACHED_BEHAVIOR_TCP_NODELAY: temp_flag= MEM_TCP_NODELAY; break; diff --git a/lib/memcached_delete.c b/lib/memcached_delete.c index 4fe29421..a7298141 100644 --- a/lib/memcached_delete.c +++ b/lib/memcached_delete.c @@ -42,18 +42,15 @@ memcached_return memcached_delete_by_key(memcached_st *ptr, goto error; } - if ((ptr->flags & MEM_NO_BLOCK)) - to_write= 0; - else - to_write= 1; + to_write= (ptr->flags & MEM_BUFFER_REQUESTS) ? 0 : 1; rc= memcached_do(ptr, server_key, buffer, send_length, to_write); if (rc != MEMCACHED_SUCCESS) goto error; - if ((ptr->flags & MEM_NO_BLOCK)) + if ((ptr->flags & MEM_BUFFER_REQUESTS)) { - rc= MEMCACHED_SUCCESS; + rc= MEMCACHED_BUFFERED; } else { @@ -118,18 +115,5 @@ memcached_return memcached_mdelete_by_key(memcached_st *ptr, (void)memcached_do(ptr, server_key, buffer, send_length, 0); } - for (x= 0; x < ptr->number_of_hosts; x++) - { - if (memcached_server_response_count(ptr, x)) - { - /* We need to do something about non-connnected hosts in the future */ - if ((memcached_io_write(ptr, x, NULL, 0, 1)) == -1) - { - rc= MEMCACHED_SOME_ERRORS; - } - } - } - - LIBMEMCACHED_MEMCACHED_DELETE_END(); - return rc; + return MEMCACHED_BUFFERED; } diff --git a/lib/memcached_storage.c b/lib/memcached_storage.c index 43a96636..38d6d0db 100644 --- a/lib/memcached_storage.c +++ b/lib/memcached_storage.c @@ -96,7 +96,7 @@ static inline memcached_return memcached_send(memcached_st *ptr, goto error; } - if ((ptr->flags & MEM_NO_BLOCK) && verb == SET_OP) + if ((ptr->flags & MEM_BUFFER_REQUESTS) && verb == SET_OP) to_write= 0; else to_write= 1; @@ -108,9 +108,9 @@ static inline memcached_return memcached_send(memcached_st *ptr, } if (to_write == 0) - rc= MEMCACHED_SUCCESS; - else - rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL, server_key); + return MEMCACHED_BUFFERED; + + rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL, server_key); if (rc == MEMCACHED_STORED) return MEMCACHED_SUCCESS; diff --git a/lib/memcached_strerror.c b/lib/memcached_strerror.c index f04f2289..8b8438bb 100644 --- a/lib/memcached_strerror.c +++ b/lib/memcached_strerror.c @@ -64,6 +64,8 @@ char *memcached_strerror(memcached_st *ptr, memcached_return rc) return "FETCH WAS NOT COMPLETED"; case MEMCACHED_NO_KEY_PROVIDED: return "A KEY LENGTH OF ZERO WAS PROVIDED"; + case MEMCACHED_BUFFERED: + return "ACTION QUEUED"; case MEMCACHED_TIMEOUT: return "A TIMEOUT OCCURRED"; case MEMCACHED_MAXIMUM_RETURN: diff --git a/tests/function.c b/tests/function.c index 54bbceaa..46005ce7 100644 --- a/tests/function.c +++ b/tests/function.c @@ -1686,6 +1686,17 @@ uint8_t generate_data(memcached_st *memc) return 0; } +uint8_t generate_buffer_data(memcached_st *memc) +{ + int latch= 0; + + latch= 1; + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, &latch); + generate_data(memc); + + return 0; +} + #ifdef NOT_DONE uint8_t mset_data(memcached_st *memc) { @@ -1809,6 +1820,22 @@ uint8_t delete_generate(memcached_st *memc) return 0; } +uint8_t delete_buffer_generate(memcached_st *memc) +{ + int latch= 0; + unsigned int x; + + latch= 1; + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, &latch); + + for (x= 0; x < GLOBAL_COUNT; x++) + { + (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0); + } + + return 0; +} + uint8_t mdelete_generate(memcached_st *memc) { memcached_return rc; @@ -2115,6 +2142,8 @@ test_st generate_tests[] ={ {"generate_data", 0, generate_data }, {"get_read", 0, get_read }, {"delete_generate", 0, delete_generate }, + {"generate_buffer_data", 0, generate_buffer_data }, + {"delete_buffer", 0, delete_buffer_generate}, {"generate_data", 0, generate_data }, {"mget_read", 0, mget_read }, {"mget_read_result", 0, mget_read_result },