[memcached] plindner, r474: Merge 470:473 from trunk, including rea...

commits at code.sixapart.com commits at code.sixapart.com
Mon Mar 19 06:53:53 UTC 2007


Merge  470:473 from trunk, including realloc fixes, minor code cleanups etc.



U   branches/multithreaded/server/ChangeLog
U   branches/multithreaded/server/items.c
U   branches/multithreaded/server/items.h
U   branches/multithreaded/server/memcached.c
U   branches/multithreaded/server/memcached.h
U   branches/multithreaded/server/t/getset.t
A   branches/multithreaded/server/t/maxconns.t


Modified: branches/multithreaded/server/ChangeLog
===================================================================
--- branches/multithreaded/server/ChangeLog	2007-03-19 06:50:47 UTC (rev 473)
+++ branches/multithreaded/server/ChangeLog	2007-03-19 06:53:52 UTC (rev 474)
@@ -1,3 +1,21 @@
+2007-03-18  Paul Lindner  <lindner at mirth.inuus.com>
+
+
+2007-03-18  Paul Lindner  <lindner at inuus.com>
+
+	* Add more test cases using larger buffer sizes up to and greater
+	  than 1MB.
+
+	* Remove unused parameter to item_size_ok()
+
+	* Use a single printf() in usage()
+
+	* Add a failing test for conforming with maximum connections.
+
+2007-03-17
+	* crash fix from Thomas van Gulick <thomas at partyflock.nl> in
+	  conn_shrink(), passing &ptr, instead of ptr to realloc().
+
 2007-03-05  Paul Lindner  <lindner at inuus.com>
 	* Fix a number of places where (s)printf calls were using unsigned
 	  or signed formats that did not match their arguments.

Modified: branches/multithreaded/server/items.c
===================================================================
--- branches/multithreaded/server/items.c	2007-03-19 06:50:47 UTC (rev 473)
+++ branches/multithreaded/server/items.c	2007-03-19 06:53:52 UTC (rev 474)
@@ -33,8 +33,8 @@
 void item_init(void) {
     int i;
     for(i=0; i<LARGEST_ID; i++) {
-        heads[i]=0;
-        tails[i]=0;
+        heads[i]=NULL;
+        tails[i]=NULL;
         sizes[i]=0;
     }
 }
@@ -63,7 +63,7 @@
  *
  * Returns the total size of the header.
  */
-static size_t item_make_header(char *key, const uint8_t nkey, const int flags, const int nbytes,
+static size_t item_make_header(const uint8_t nkey, const int flags, const int nbytes,
                      char *suffix, uint8_t *nsuffix) {
     /* suffix is defined at 40 chars elsewhere.. */
     *nsuffix = (uint8_t) snprintf(suffix, 40, " %d %d\r\n", flags, nbytes - 2);
@@ -78,7 +78,7 @@
     unsigned int id;
     char suffix[40];
 
-    ntotal = item_make_header(key, nkey + 1, flags, nbytes, suffix, &nsuffix);
+    ntotal = item_make_header(nkey + 1, flags, nbytes, suffix, &nsuffix);
  
     id = slabs_clsid(ntotal);
     if (id == 0)
@@ -152,11 +152,11 @@
  * Returns true if an item will fit in the cache (its size does not exceed
  * the maximum for a cache entry.)
  */
-bool item_size_ok(char *key, const size_t nkey, const int flags, const int nbytes) {
+bool item_size_ok(const size_t nkey, const int flags, const int nbytes) {
     char prefix[40];
     uint8_t nsuffix;
 
-    return slabs_clsid(item_make_header(key, nkey + 1, flags, nbytes,
+    return slabs_clsid(item_make_header(nkey + 1, flags, nbytes,
                                         prefix, &nsuffix)) != 0;
 }
 
@@ -407,7 +407,7 @@
 }
 
 /* expires items that are more recent than the oldest_live setting. */
-void do_item_flush_expired() {
+void do_item_flush_expired(void) {
     int i;
     item *iter, *next;
     if (settings.oldest_live == 0)

Modified: branches/multithreaded/server/items.h
===================================================================
--- branches/multithreaded/server/items.h	2007-03-19 06:50:47 UTC (rev 473)
+++ branches/multithreaded/server/items.h	2007-03-19 06:53:52 UTC (rev 474)
@@ -3,7 +3,7 @@
 /*@null@*/
 item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_time_t exptime, const int nbytes);
 void item_free(item *it);
-bool item_size_ok(char *key, const size_t nkey, const int flags, const int nbytes);
+bool item_size_ok(const size_t nkey, const int flags, const int nbytes);
 
 int  do_item_link(item *it);    /* may fail if transgresses limits */
 void do_item_unlink(item *it);

Modified: branches/multithreaded/server/memcached.c
===================================================================
--- branches/multithreaded/server/memcached.c	2007-03-19 06:50:47 UTC (rev 473)
+++ branches/multithreaded/server/memcached.c	2007-03-19 06:53:52 UTC (rev 474)
@@ -471,7 +471,7 @@
     }
 
     if (c->isize > ITEM_LIST_HIGHWAT) {
-        item **newbuf = (item**) realloc((void*)&c->ilist, ITEM_LIST_INITIAL * sizeof(c->ilist[0]));
+        item **newbuf = (item**) realloc((void*)c->ilist, ITEM_LIST_INITIAL * sizeof(c->ilist[0]));
         if (newbuf) {
             c->ilist = newbuf;
             c->isize = ITEM_LIST_INITIAL;
@@ -480,7 +480,7 @@
     }
 
     if (c->msgsize > MSG_LIST_HIGHWAT) {
-        struct msghdr *newbuf = (struct msghdr*) realloc((void*)&c->msglist, MSG_LIST_INITIAL * sizeof(c->msglist[0]));
+        struct msghdr *newbuf = (struct msghdr*) realloc((void*)c->msglist, MSG_LIST_INITIAL * sizeof(c->msglist[0]));
         if (newbuf) {
             c->msglist = newbuf;
             c->msgsize = MSG_LIST_INITIAL;
@@ -489,7 +489,7 @@
     }
 
     if (c->iovsize > IOV_LIST_HIGHWAT) {
-        struct iovec* newbuf = (struct iovec *) realloc((void*)&c->iov, IOV_LIST_INITIAL * sizeof(c->iov[0]));
+        struct iovec* newbuf = (struct iovec *) realloc((void*)c->iov, IOV_LIST_INITIAL * sizeof(c->iov[0]));
         if (newbuf) {
             c->iov = newbuf;
             c->iovsize = IOV_LIST_INITIAL;
@@ -1114,7 +1114,7 @@
          * of tokens.
          */
         if(key_token->value != NULL) {
-           ntokens = tokenize_command(key_token->value, tokens, MAX_TOKENS);
+            ntokens = tokenize_command(key_token->value, tokens, MAX_TOKENS);
             key_token = tokens;
         }
         
@@ -1182,7 +1182,7 @@
     it = item_alloc(key, nkey, flags, realtime(exptime), vlen+2);
 
     if (it == 0) {
-        if (! item_size_ok(key, nkey, flags, vlen + 2))
+        if (! item_size_ok(nkey, flags, vlen + 2))
             out_string(c, "SERVER_ERROR object too large for cache");
         else
             out_string(c, "SERVER_ERROR out of memory");
@@ -2272,25 +2272,25 @@
 
 static void usage(void) {
     printf(PACKAGE " " VERSION "\n");
-    printf("-p <num>      TCP port number to listen on (default: 11211)\n");
-    printf("-U <num>      UDP port number to listen on (default: 0, off)\n");
-    printf("-s <file>     unix socket path to listen on (disables network support)\n");
-    printf("-l <ip_addr>  interface to listen on, default is INDRR_ANY\n");
-    printf("-d            run as a daemon\n");
-    printf("-r            maximize core file limit\n");
-    printf("-u <username> assume identity of <username> (only when run as root)\n");
-    printf("-m <num>      max memory to use for items in megabytes, default is 64 MB\n");
-    printf("-M            return error on memory exhausted (rather than removing items)\n");
-    printf("-c <num>      max simultaneous connections, default is 1024\n");
-    printf("-k            lock down all paged memory\n");
-    printf("-v            verbose (print errors/warnings while in event loop)\n");
-    printf("-vv           very verbose (also print client commands/reponses)\n");
-    printf("-h            print this help and exit\n");
-    printf("-i            print memcached and libevent license\n");
-    printf("-b            run a managed instanced (mnemonic: buckets)\n");
-    printf("-P <file>     save PID in <file>, only used with -d option\n");
-    printf("-f <factor>   chunk size growth factor, default 1.25\n");
-    printf("-n <bytes>    minimum space allocated for key+value+flags, default 48\n");
+    printf("-p <num>      TCP port number to listen on (default: 11211)\n"
+           "-U <num>      UDP port number to listen on (default: 0, off)\n"
+           "-s <file>     unix socket path to listen on (disables network support)\n"
+           "-l <ip_addr>  interface to listen on, default is INDRR_ANY\n"
+           "-d            run as a daemon\n"
+           "-r            maximize core file limit\n"
+           "-u <username> assume identity of <username> (only when run as root)\n"
+           "-m <num>      max memory to use for items in megabytes, default is 64 MB\n"
+           "-M            return error on memory exhausted (rather than removing items)\n"
+           "-c <num>      max simultaneous connections, default is 1024\n"
+           "-k            lock down all paged memory\n"
+           "-v            verbose (print errors/warnings while in event loop)\n"
+           "-vv           very verbose (also print client commands/reponses)\n"
+           "-h            print this help and exit\n"
+           "-i            print memcached and libevent license\n"
+           "-b            run a managed instanced (mnemonic: buckets)\n"
+           "-P <file>     save PID in <file>, only used with -d option\n"
+           "-f <factor>   chunk size growth factor, default 1.25\n"
+           "-n <bytes>    minimum space allocated for key+value+flags, default 48\n");
 #ifdef USE_THREADS
     printf("-t <num>      number of threads to use, default 4\n");
 #endif

Modified: branches/multithreaded/server/memcached.h
===================================================================
--- branches/multithreaded/server/memcached.h	2007-03-19 06:50:47 UTC (rev 473)
+++ branches/multithreaded/server/memcached.h	2007-03-19 06:53:52 UTC (rev 474)
@@ -31,7 +31,7 @@
 #if HAVE_STDBOOL_H
 # include <stdbool.h>
 #else
-typedef enum {false = 0, true = 1} bool;
+  typedef enum {false = 0, true = 1} bool;
 #endif
 
 #if HAVE_STDINT_H

Modified: branches/multithreaded/server/t/getset.t
===================================================================
--- branches/multithreaded/server/t/getset.t	2007-03-19 06:50:47 UTC (rev 473)
+++ branches/multithreaded/server/t/getset.t	2007-03-19 06:53:52 UTC (rev 474)
@@ -1,14 +1,16 @@
 #!/usr/bin/perl
 
 use strict;
-use Test::More tests => 14;
+use Test::More tests => 528;
 use FindBin qw($Bin);
 use lib "$Bin/lib";
 use MemcachedTest;
 
+
 my $server = new_memcached();
 my $sock = $server->sock;
 
+
 # set foo (and should get it)
 print $sock "set foo 0 0 6\r\nfooval\r\n";
 is(scalar <$sock>, "STORED\r\n", "stored foo");
@@ -48,4 +50,18 @@
 is(scalar <$sock>, "DELETED\r\n", "pipeline delete");
 
 
+# Test sets up to a large size around 1MB.
+# Everything up to 1MB - 1k should succeed, everything 1MB +1k should fail.
 
+my $len = 1024;
+while ($len < 1024*1028) {
+    my $val = "B"x$len;
+    print $sock "set foo_$len 0 0 $len\r\n$val\r\n";
+    if ($len > (1024*1024)) {
+        is(scalar <$sock>, "SERVER_ERROR object too large for cache\r\n", "failed to store size $len");
+    } else {
+        is(scalar <$sock>, "STORED\r\n", "stored size $len");
+    }
+    $len += 2048;
+}
+

Copied: branches/multithreaded/server/t/maxconns.t (from rev 473, trunk/server/t/maxconns.t)




More information about the memcached-commits mailing list