Merge lp:~andrefcruz/libmemcached/recover-gracefully into lp:~tangent-org/libmemcached/trunk

Proposed by André Cruz
Status: Merged
Merged at revision: not available
Proposed branch: lp:~andrefcruz/libmemcached/recover-gracefully
Merge into: lp:~tangent-org/libmemcached/trunk
Diff against target: 232 lines (+64/-11)
7 files modified
docs/memcached_behavior.pod (+11/-4)
libmemcached/behavior.c (+15/-3)
libmemcached/connect.c (+26/-1)
libmemcached/constants.h (+2/-0)
libmemcached/memcached.c (+6/-2)
libmemcached/memcached.h (+2/-0)
libmemcached/storage.c (+2/-1)
To merge this branch: bzr merge lp:~andrefcruz/libmemcached/recover-gracefully
Reviewer Review Type Date Requested Status
Libmemcached-developers Pending
Review via email: mp+20532@code.launchpad.net
To post a comment you must log in.
Revision history for this message
André Cruz (andrefcruz) wrote :

memcached_io_reset on a dead server keeps him from ever coming back.

802. By André Cruz

Added option to enable TCP_KEEPALIVE on created sockets.

803. By André Cruz

Implement flag retrieval for new keepalive flag.

804. By André Cruz

Implemented the TCP_KEEPIDLE tcp option. This is only available on Linux.

805. By André Cruz

Added missing constant.
Set keepalive before keepidle.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'docs/memcached_behavior.pod'
2--- docs/memcached_behavior.pod 2010-01-15 00:35:02 +0000
3+++ docs/memcached_behavior.pod 2010-03-08 17:26:35 +0000
4@@ -211,11 +211,11 @@
5
6 =item MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ
7
8-Allows randomizing the replica reads starting point. Normally the read is
9+Allows randomizing the replica reads starting point. Normally the read is
10 done from primary server and in case of miss the read is done from primary
11-+ 1, then primary + 2 all the way to 'n' replicas. If this option is set
12++ 1, then primary + 2 all the way to 'n' replicas. If this option is set
13 on the starting point of the replica reads is randomized between the servers.
14-This allows distributing read load to multiple servers with the expense of
15+This allows distributing read load to multiple servers with the expense of
16 more write traffic.
17
18 =item MEMCACHED_BEHAVIOR_CORK
19@@ -224,9 +224,16 @@
20 MEMCACHED_NO_SERVERS is returned if no servers are available to test with.
21 MEMCACHED_NOT_SUPPORTED is returned if we were not able to determine
22 if support was available. All other responses then MEMCACHED_SUCCESS
23-report an error of some sort. This behavior also enables
24+report an error of some sort. This behavior also enables
25 MEMCACHED_BEHAVIOR_TCP_NODELAY when set.
26
27+=item MEMCACHED_BEHAVIOR_KEEPALIVE
28+
29+Enable TCP_KEEPALIVE behavior.
30+
31+=item MEMCACHED_BEHAVIOR_KEEPALIVE_IDLE
32+
33+Specify time, in seconds, to mark a connection as idle. This is only available as an option Linux.
34
35 =item MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
36
37
38=== modified file 'libmemcached/behavior.c'
39--- libmemcached/behavior.c 2010-02-13 02:23:49 +0000
40+++ libmemcached/behavior.c 2010-03-08 17:26:35 +0000
41@@ -87,6 +87,10 @@
42 ptr->flags.tcp_nodelay= set_flag(data);
43 memcached_quit(ptr);
44 break;
45+ case MEMCACHED_BEHAVIOR_TCP_KEEPALIVE:
46+ ptr->flags.tcp_keepalive= set_flag(data);
47+ memcached_quit(ptr);
48+ break;
49 case MEMCACHED_BEHAVIOR_DISTRIBUTION:
50 return memcached_behavior_set_distribution(ptr, (memcached_server_distribution_t)data);
51 case MEMCACHED_BEHAVIOR_KETAMA:
52@@ -114,7 +118,7 @@
53 /**
54 @note We try to keep the same distribution going. This should be deprecated and rewritten.
55 */
56- return memcached_behavior_set_distribution(ptr, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA);
57+ return memcached_behavior_set_distribution(ptr, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA);
58 }
59 case MEMCACHED_BEHAVIOR_HASH:
60 return memcached_behavior_set_key_hash(ptr, (memcached_hash_t)(data));
61@@ -153,6 +157,10 @@
62 ptr->recv_size= (int32_t)data;
63 memcached_quit(ptr);
64 break;
65+ case MEMCACHED_BEHAVIOR_TCP_KEEPIDLE:
66+ ptr->tcp_keepidle= (uint32_t)data;
67+ memcached_quit(ptr);
68+ break;
69 case MEMCACHED_BEHAVIOR_USER_DATA:
70 return MEMCACHED_FAILURE;
71 case MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY:
72@@ -288,6 +296,8 @@
73 return (uint64_t)ptr->snd_timeout;
74 case MEMCACHED_BEHAVIOR_RCV_TIMEOUT:
75 return (uint64_t)ptr->rcv_timeout;
76+ case MEMCACHED_BEHAVIOR_TCP_KEEPIDLE:
77+ return (uint64_t)ptr->tcp_keepidle;
78 case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE:
79 {
80 int sock_size= 0;
81@@ -324,8 +334,8 @@
82
83 instance= memcached_server_instance_fetch(ptr, 0);
84
85- /**
86- @note REFACTOR
87+ /**
88+ @note REFACTOR
89 */
90 if (instance)
91 {
92@@ -353,6 +363,8 @@
93 return ptr->flags.randomize_replica_read;
94 case MEMCACHED_BEHAVIOR_CORK:
95 return ptr->flags.cork;
96+ case MEMCACHED_BEHAVIOR_TCP_KEEPALIVE:
97+ return ptr->flags.tcp_keepalive;
98 case MEMCACHED_BEHAVIOR_MAX:
99 default:
100 WATCHPOINT_ASSERT(0); /* Programming mistake if it gets this far */
101
102=== modified file 'libmemcached/connect.c'
103--- libmemcached/connect.c 2010-02-13 02:23:49 +0000
104+++ libmemcached/connect.c 2010-03-08 17:26:35 +0000
105@@ -111,6 +111,31 @@
106 return MEMCACHED_FAILURE;
107 }
108
109+ if (ptr->root->flags.tcp_keepalive)
110+ {
111+ int flag= 1;
112+ int error;
113+
114+ error= setsockopt(ptr->fd, SOL_SOCKET, SO_KEEPALIVE,
115+ &flag, (socklen_t)sizeof(int));
116+ WATCHPOINT_ASSERT(error == 0);
117+ if (error)
118+ return MEMCACHED_FAILURE;
119+ }
120+
121+#ifdef TCP_KEEPIDLE
122+ if (ptr->root->tcp_keepidle > 0)
123+ {
124+ int error;
125+
126+ error= setsockopt(ptr->fd, IPPROTO_TCP, TCP_KEEPIDLE,
127+ &ptr->root->tcp_keepidle, (socklen_t)sizeof(int));
128+ WATCHPOINT_ASSERT(error == 0);
129+ if (error)
130+ return MEMCACHED_FAILURE;
131+ }
132+#endif
133+
134 if (ptr->root->send_size > 0)
135 {
136 int error;
137@@ -368,7 +393,7 @@
138 WATCHPOINT_ASSERT(0);
139 }
140
141- unlikely ( rc != MEMCACHED_SUCCESS)
142+ unlikely ( rc != MEMCACHED_SUCCESS)
143 {
144 //@todo create interface around last_discontected_server
145 memcached_st *root= (memcached_st *)ptr->root;
146
147=== modified file 'libmemcached/constants.h'
148--- libmemcached/constants.h 2010-02-05 01:15:17 +0000
149+++ libmemcached/constants.h 2010-03-08 17:26:35 +0000
150@@ -115,6 +115,8 @@
151 MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS,
152 MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ,
153 MEMCACHED_BEHAVIOR_CORK,
154+ MEMCACHED_BEHAVIOR_TCP_KEEPALIVE,
155+ MEMCACHED_BEHAVIOR_TCP_KEEPIDLE,
156 MEMCACHED_BEHAVIOR_MAX
157 } memcached_behavior_t;
158
159
160=== modified file 'libmemcached/memcached.c'
161--- libmemcached/memcached.c 2010-02-17 01:58:35 +0000
162+++ libmemcached/memcached.c 2010-03-08 17:26:35 +0000
163@@ -5,7 +5,7 @@
164 * Use and distribution licensed under the BSD license. See
165 * the COPYING file in the parent directory for full text.
166 *
167- * Summary:
168+ * Summary:
169 *
170 */
171
172@@ -32,7 +32,8 @@
173 .use_cache_lookups= false,
174 .use_sort_hosts= false,
175 .use_udp= false,
176- .verify_key= false
177+ .verify_key= false,
178+ .tcp_keepalive= false
179 }
180 };
181
182@@ -62,6 +63,8 @@
183 self->io_msg_watermark= 500;
184 self->io_bytes_watermark= 65 * 1024;
185
186+ self->tcp_keepidle= 0;
187+
188 self->io_key_prefetch= 0;
189 self->cached_errno= 0;
190 self->poll_timeout= MEMCACHED_DEFAULT_TIMEOUT;
191@@ -225,6 +228,7 @@
192 new_clone->io_bytes_watermark= source->io_bytes_watermark;
193 new_clone->io_key_prefetch= source->io_key_prefetch;
194 new_clone->number_of_replicas= source->number_of_replicas;
195+ new_clone->tcp_keepidle= source->tcp_keepidle;
196
197 if (memcached_server_count(source))
198 rc= memcached_push(new_clone, source);
199
200=== modified file 'libmemcached/memcached.h'
201--- libmemcached/memcached.h 2010-02-17 01:58:35 +0000
202+++ libmemcached/memcached.h 2010-03-08 17:26:35 +0000
203@@ -80,6 +80,7 @@
204 bool use_sort_hosts MEMCACHED_BITFIELD;
205 bool use_udp MEMCACHED_BITFIELD;
206 bool verify_key MEMCACHED_BITFIELD;
207+ bool tcp_keepalive MEMCACHED_BITFIELD;
208 } flags;
209 memcached_server_distribution_t distribution;
210 hashkit_st hashkit;
211@@ -93,6 +94,7 @@
212 uint32_t io_msg_watermark;
213 uint32_t io_bytes_watermark;
214 uint32_t io_key_prefetch;
215+ uint32_t tcp_keepidle;
216 int cached_errno;
217 int32_t poll_timeout;
218 int32_t connect_timeout;
219
220=== modified file 'libmemcached/storage.c'
221--- libmemcached/storage.c 2010-02-13 02:23:49 +0000
222+++ libmemcached/storage.c 2010-03-08 17:26:35 +0000
223@@ -189,7 +189,8 @@
224 return rc;
225
226 error:
227- memcached_io_reset(instance);
228+ if (rc == MEMCACHED_WRITE_FAILURE)
229+ memcached_io_reset(instance);
230
231 return rc;
232 }

Subscribers

People subscribed via source and target branches

to all changes: