r17058 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17057‎ | r17058 | r17059 >
Date:22:17, 16 October 2006
Author:river
Status:old
Tags:
Comment:
don't crash on certain invalid headers
logging would use invalid syslog priority for WLOG_ERR
fix carp load balancing
Modified paths:
  • /trunk/willow/src/bin/willow/wbackend.c (modified) (history)
  • /trunk/willow/src/bin/willow/whttp.c (modified) (history)
  • /trunk/willow/src/bin/willow/whttp_entity.c (modified) (history)
  • /trunk/willow/src/lib/wlog/wlog.c (modified) (history)

Diff [purge]

Index: trunk/willow/src/lib/wlog/wlog.c
@@ -34,6 +34,7 @@
3535
3636 static const int syslog_pri[] = {
3737 LOG_INFO,
 38+ LOG_INFO,
3839 LOG_WARNING,
3940 LOG_ERR,
4041 };
Index: trunk/willow/src/bin/willow/wbackend.c
@@ -29,7 +29,7 @@
3030 #include "confparse.h"
3131 #include "wconfig.h"
3232
33 -#define rotl(i,r) ((i) << (r) | (i) >> sizeof(i)*CHAR_BIT-(r));
 33+#define rotl(i,r) (((i) << (r)) | ((i) >> (sizeof(i)*CHAR_BIT-(r))))
3434
3535 static struct backend **backends;
3636 int nbackends;
@@ -41,7 +41,8 @@
4242 static uint32_t carp_hosthash(const char *);
4343 static uint32_t carp_combine(const char *url, uint32_t host);
4444 static void carp_recalc(const char *url);
45 -static int becalc_cmp(const struct backend *a, const struct backend *b);
 45+static void carp_calc(void);
 46+static int becalc_cmp(const struct backend **a, const struct backend **b);
4647
4748 struct backend_cb_data {
4849 struct backend *bc_backend;
@@ -86,6 +87,7 @@
8788 if ((backends = wrealloc(backends, sizeof(struct backend*) * ++nbackends)) == NULL)
8889 outofmemory();
8990 backends[nbackends - 1] = new_backend(addr, addr, port);
 91+ carp_calc();
9092 wlog(WLOG_NOTICE, "backend: %s:%d", addr, port);
9193 }
9294
@@ -209,9 +211,13 @@
210212 static int cur = 0;
211213 int tried = 0;
212214
213 - if (config.use_carp)
 215+ if (config.use_carp) {
214216 carp_recalc(url);
 217+ // cur = 0;
 218+ }
215219
 220+ WDEBUG((WLOG_DEBUG, "next_backend: url=[%s]", url));
 221+
216222 while (tried++ <= nbackends) {
217223 time_t now = time(NULL);
218224
@@ -226,6 +232,8 @@
227233 continue;
228234 }
229235
 236+ if (config.use_carp)
 237+ cur = 0;
230238 return backends[cur++];
231239 }
232240
@@ -236,9 +244,11 @@
237245 carp_urlhash(str)
238246 const char *str;
239247 {
 248+ const char *ostr = str;
240249 uint32_t h = 0;
241250 for (; *str; ++str)
242 - h += rotl(h, 19) + *str;
 251+ h += (rotl(h, 19) + *str);
 252+ WDEBUG((WLOG_DEBUG, "hash(%s) = %d", ostr, h));
243253 return h;
244254 }
245255
@@ -267,11 +277,13 @@
268278 int i, j;
269279
270280 backends[0]->be_carp = pow((nbackends * backends[0]->be_load), 1.0 / nbackends);
 281+ backends[0]->be_carplfm = 1.0;
271282 for (i = 1; i < nbackends; ++i) {
272283 float l = 0;
273284 be = backends[i];
274285 prev = backends[i - 1];
275 - be->be_carplfm = ((nbackends-i+1) * (be->be_load - prev->be_load));
 286+ be->be_carplfm = 1.0 + ((nbackends-i+1) * (be->be_load - prev->be_load));
 287+ WDEBUG((WLOG_DEBUG, "carp_calc: %s lfm = %f", be->be_name, be->be_carplfm));
276288 for (j = 0; j < i; ++j)
277289 l *= backends[j]->be_carp;
278290 be->be_carp /= l;
@@ -291,14 +303,21 @@
292304 hash += hash * 0x62531965;
293305 hash = rotl(hash, 21);
294306 hash *= backends[i]->be_carplfm;
 307+ WDEBUG((WLOG_DEBUG, "%s: hash = %lu, lfm = %f", backends[i]->be_name, hash, backends[i]->be_carplfm));
295308 backends[i]->be_carp = hash;
296309 }
297310 qsort(backends, nbackends, sizeof(struct backend *), becalc_cmp);
 311+ WDEBUG((WLOG_DEBUG, "first backend = %s", backends[0]->be_name));
298312 }
299313
300314 static int
301315 becalc_cmp(a, b)
302 -const struct backend *a, *b;
 316+const struct backend **a, **b;
303317 {
304 - return a->be_carp - b->be_carp;
 318+ WDEBUG((WLOG_DEBUG, "compare %s(%lu)/%s(%lu)", (*a)->be_name, (*a)->be_carp, (*b)->be_name, (*b)->be_carp));
 319+ if ((*a)->be_carp < (*b)->be_carp)
 320+ return -1;
 321+ else if ((*a)->be_carp == (*b)->be_carp)
 322+ return 0;
 323+ return 1;
305324 }
Index: trunk/willow/src/bin/willow/whttp_entity.c
@@ -972,8 +972,8 @@
973973 char *line;
974974
975975 while (line = evbuffer_readline(entity->_he_frombuf->input)) {
976 - char **hdr;
977 - char *value;
 976+ char **hdr = NULL;
 977+ char *value = NULL;
978978 int error = 1;
979979
980980 if (!line)
Index: trunk/willow/src/bin/willow/whttp.c
@@ -321,7 +321,7 @@
322322 /*
323323 * Check for cached object.
324324 */
325 - if (client->cl_reqtype == REQTYPE_GET) {
 325+ if (config.ncaches && client->cl_reqtype == REQTYPE_GET) {
326326 if (cacheable)
327327 client->cl_co = wcache_find_object(client->cl_path, &client->cl_cfd,
328328 WCACHE_RDWR);