[memcached] plindner, r506: Merge in latest changes from trunk.

commits at code.sixapart.com commits at code.sixapart.com
Mon Apr 16 14:02:38 UTC 2007


Merge in latest changes from trunk.

svn merge -r 500:505 http://code.sixapart.com/svn/memcached/trunk



U   branches/multithreaded/server/daemon.c
U   branches/multithreaded/server/items.c
U   branches/multithreaded/server/memcached.c
U   branches/multithreaded/server/scripts/memcached-tool
U   branches/multithreaded/server/slabs.c


Modified: branches/multithreaded/server/daemon.c
===================================================================
--- branches/multithreaded/server/daemon.c	2007-04-13 20:20:07 UTC (rev 505)
+++ branches/multithreaded/server/daemon.c	2007-04-16 14:02:37 UTC (rev 506)
@@ -38,9 +38,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 
-int
-daemon(nochdir, noclose)
-    int nochdir, noclose;
+int daemon(int nochdir, int noclose)
 {
     int fd;
 
@@ -56,10 +54,10 @@
     if (setsid() == -1)
         return (-1);
 
-    if (!nochdir)
+    if (nochdir == 0)
         (void)chdir("/");
 
-    if (!noclose && (fd = open("/dev/null", O_RDWR, 0)) != -1) {
+    if (noclose==0 && (fd = open("/dev/null", O_RDWR, 0)) != -1) {
         (void)dup2(fd, STDIN_FILENO);
         (void)dup2(fd, STDOUT_FILENO);
         (void)dup2(fd, STDERR_FILENO);

Modified: branches/multithreaded/server/items.c
===================================================================
--- branches/multithreaded/server/items.c	2007-04-13 20:20:07 UTC (rev 505)
+++ branches/multithreaded/server/items.c	2007-04-16 14:02:37 UTC (rev 506)
@@ -292,7 +292,7 @@
         it = it->next;
     }
 
-    strcpy(buffer + bufcurr, "END\r\n");
+    memcpy(buffer + bufcurr, "END\r\n", 6);
     bufcurr += 5;
 
     *bytes = bufcurr;
@@ -314,7 +314,7 @@
             bufcurr += snprintf(bufcurr, (size_t)buflen, "STAT items:%d:number %u\r\nSTAT items:%d:age %u\r\n",
                                i, sizes[i], i, now - tails[i]->time);
     }
-    strcpy(bufcurr, "END");
+    memcpy(bufcurr, "END", 4);
     return;
 }
 

Modified: branches/multithreaded/server/memcached.c
===================================================================
--- branches/multithreaded/server/memcached.c	2007-04-13 20:20:07 UTC (rev 505)
+++ branches/multithreaded/server/memcached.c	2007-04-16 14:02:37 UTC (rev 506)
@@ -668,7 +668,7 @@
     }
 
     memcpy(c->wbuf, str, len);
-    memcpy(c->wbuf + len, "\r\n", 2);
+    memcpy(c->wbuf + len, "\r\n", 3);
     c->wbytes = len + 2;
     c->wcurr = c->wbuf;
 
@@ -963,7 +963,7 @@
             free(wbuf); close(fd);
             return;
         }
-        strcpy(wbuf + res, "END\r\n");
+        memcpy(wbuf + res, "END\r\n", 6);
         c->write_and_free = wbuf;
         c->wcurr = wbuf;
         c->wbytes = res + 5; // Don't write the terminal '\0'
@@ -1315,7 +1315,7 @@
             return "SERVER_ERROR out of memory";
         }
         memcpy(ITEM_data(new_it), buf, res);
-        memcpy(ITEM_data(new_it) + res, "\r\n", 2);
+        memcpy(ITEM_data(new_it) + res, "\r\n", 3);
         do_item_replace(it, new_it);
         do_item_remove(new_it);       /* release our reference */
     } else { /* replace in-place */
@@ -2430,7 +2430,7 @@
 
 static void save_pid(const pid_t pid, const char *pid_file) {
     FILE *fp;
-    if (!pid_file)
+    if (pid_file == NULL)
         return;
 
     if (!(fp = fopen(pid_file, "w"))) {
@@ -2446,7 +2446,7 @@
 }
 
 static void remove_pidfile(const char *pid_file) {
-  if (!pid_file)
+  if (pid_file == NULL)
       return;
 
   if (unlink(pid_file) != 0) {

Modified: branches/multithreaded/server/scripts/memcached-tool
===================================================================
--- branches/multithreaded/server/scripts/memcached-tool	2007-04-13 20:20:07 UTC (rev 505)
+++ branches/multithreaded/server/scripts/memcached-tool	2007-04-16 14:02:37 UTC (rev 506)
@@ -26,6 +26,8 @@
     undef $mode if $from < 6 || $from > 17;
     undef $mode if $to   < 6 || $to   > 17;
     print STDERR "ERROR: parameters out of range\n\n" unless $mode;
+} elsif ($mode eq 'dump') {
+    ;
 } else {
     undef $mode;
 }
@@ -78,6 +80,53 @@
     exit;
 }
 
+if ($mode eq 'dump') {
+    my %items;
+    my $totalitems;
+
+    print $sock "stats items\r\n";
+
+    while (<$sock>) {
+        last if /^END/;
+        if (/^STAT items:(\d*):number (\d*)/) {
+            $items{$1} = $2;
+            $totalitems += $2;
+        }
+    }
+    print STDERR "Dumping memcache contents\n";
+    print STDERR "  Number of buckets: " . scalar(keys(%items)) . "\n";
+    print STDERR "  Number of items  : $totalitems\n";
+
+    foreach my $bucket (sort(keys(%items))) {
+        print STDERR "Dumping bucket $bucket - " . $items{$bucket} . " total items\n";
+        print $sock "stats cachedump $bucket $items{$bucket} 1\r\n";
+        my %keyexp;
+        while (<$sock>) {
+            last if /^END/;
+            # return format looks like this
+            # ITEM foo [6 b; 1176415152 s]
+            if (/^ITEM (\w+) \[.* (\d+) s\]/) {
+                $keyexp{$1} = $2;
+            }
+        }
+
+        foreach my $k (keys(%keyexp)) {
+            my $val;
+            print $sock "get $k\r\n";
+            my $response = <$sock>;
+            $response =~ /VALUE (\w+) (\d+) (\d+)/;
+            my $flags = $2;
+            my $len = $3;
+            read $sock, $val , $len;
+            # get the END
+            $_ = <$sock>;
+            $_ = <$sock>;
+            print "add $k $flags $keyexp{$k} $len\r\n$val\r\n";
+        }
+    }
+    exit;
+}
+
 # display mode:
 
 my %items;  # class -> { number, age, chunk_size, chunks_per_page,

Modified: branches/multithreaded/server/slabs.c
===================================================================
--- branches/multithreaded/server/slabs.c	2007-04-13 20:20:07 UTC (rev 505)
+++ branches/multithreaded/server/slabs.c	2007-04-16 14:02:37 UTC (rev 506)
@@ -21,6 +21,7 @@
 #include <unistd.h>
 #include <errno.h>
 #include <assert.h>
+#include <stdbool.h>
 
 #define POWER_SMALLEST 1
 #define POWER_LARGEST  200
@@ -80,7 +81,7 @@
 unsigned int slabs_clsid(const size_t size) {
     int res = POWER_SMALLEST;
 
-    if(size == 0)
+    if (size == 0)
         return 0;
     while (size > slabclass[res].size)
         if (res++ == power_largest)     /* won't fit in the biggest slab */
@@ -316,7 +317,7 @@
     void *slab, *slab_end;
     slabclass_t *p, *dp;
     void *iter;
-    int was_busy = 0;
+    bool was_busy = false;
 
     if (srcid < POWER_SMALLEST || srcid > power_largest ||
         dstid < POWER_SMALLEST || dstid > power_largest)
@@ -341,7 +342,7 @@
     for (iter = slab; iter < slab_end; iter += p->size) {
         item *it = (item *)iter;
         if (it->slabs_clsid) {
-            if (it->refcount) was_busy = 1;
+            if (it->refcount) was_busy = true;
             item_unlink(it);
         }
     }




More information about the memcached-commits mailing list