[memcached] plindner, r473: * Remove unused parameter to item_size_o...

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


* Remove unused parameter to item_size_ok()
* Use a single printf() in usage()
* Add a failing test for conforming with maximum connections.


U   trunk/server/ChangeLog
U   trunk/server/items.c
U   trunk/server/items.h
U   trunk/server/memcached.c
U   trunk/server/memcached.h
A   trunk/server/t/maxconns.t


Modified: trunk/server/ChangeLog
===================================================================
--- trunk/server/ChangeLog	2007-03-19 06:41:00 UTC (rev 472)
+++ trunk/server/ChangeLog	2007-03-19 06:50:47 UTC (rev 473)
@@ -1,3 +1,17 @@
+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().

Modified: trunk/server/items.c
===================================================================
--- trunk/server/items.c	2007-03-19 06:41:00 UTC (rev 472)
+++ trunk/server/items.c	2007-03-19 06:50:47 UTC (rev 473)
@@ -38,8 +38,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;
     }
 }
@@ -57,7 +57,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);
@@ -72,7 +72,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)
@@ -144,11 +144,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;
 }
 
@@ -339,7 +339,7 @@
 }
 
 /* expires items that are more recent than the oldest_live setting. */
-void item_flush_expired() {
+void item_flush_expired(void) {
     int i;
     item *iter, *next;
     if (settings.oldest_live == 0)

Modified: trunk/server/items.h
===================================================================
--- trunk/server/items.h	2007-03-19 06:41:00 UTC (rev 472)
+++ trunk/server/items.h	2007-03-19 06:50:47 UTC (rev 473)
@@ -3,7 +3,7 @@
 /*@null@*/
 item *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 item_link(item *it);    /* may fail if transgresses limits */
 void item_unlink(item *it);

Modified: trunk/server/memcached.c
===================================================================
--- trunk/server/memcached.c	2007-03-19 06:41:00 UTC (rev 472)
+++ trunk/server/memcached.c	2007-03-19 06:50:47 UTC (rev 473)
@@ -1057,7 +1057,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;
         }
         
@@ -1121,7 +1121,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");
@@ -2168,25 +2168,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");
     return;
 }
 

Modified: trunk/server/memcached.h
===================================================================
--- trunk/server/memcached.h	2007-03-19 06:41:00 UTC (rev 472)
+++ trunk/server/memcached.h	2007-03-19 06:50:47 UTC (rev 473)
@@ -25,7 +25,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

Added: trunk/server/t/maxconns.t
===================================================================
--- trunk/server/t/maxconns.t	2007-03-19 06:41:00 UTC (rev 472)
+++ trunk/server/t/maxconns.t	2007-03-19 06:50:47 UTC (rev 473)
@@ -0,0 +1,32 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 10;
+
+use FindBin qw($Bin);
+use lib "$Bin/lib";
+use MemcachedTest;
+
+
+# start up a server with 10 maximum connections
+my $server = new_memcached('-c 10');
+my $sock = $server->sock;
+my @sockets;
+
+ok(defined($sock), 'Connection 0');
+push (@sockets, $sock);
+
+foreach my $conn (1..20) {
+  $sock = $server->new_sock;
+  if ($conn > 10) {
+    ok(!defined($sock), "Failed Connection $conn $sock");
+  } else {
+    ok(defined($sock), "Connection $conn");
+    push(@sockets, $sock);
+  }    
+}
+
+mem_stats($sock, '');
+sleep(100);


Property changes on: trunk/server/t/maxconns.t
___________________________________________________________________
Name: svn:executable
   + *




More information about the memcached-commits mailing list