Changeset 474

Show
Ignore:
Timestamp:
03/19/07 06:53:52 (2 years ago)
Author:
plindner
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/multithreaded/server/ChangeLog

    r469 r474  
     12007-03-18  Paul Lindner  <lindner@mirth.inuus.com> 
     2 
     3 
     42007-03-18  Paul Lindner  <lindner@inuus.com> 
     5 
     6        * Add more test cases using larger buffer sizes up to and greater 
     7          than 1MB. 
     8 
     9        * Remove unused parameter to item_size_ok() 
     10 
     11        * Use a single printf() in usage() 
     12 
     13        * Add a failing test for conforming with maximum connections. 
     14 
     152007-03-17 
     16        * crash fix from Thomas van Gulick <thomas@partyflock.nl> in 
     17          conn_shrink(), passing &ptr, instead of ptr to realloc(). 
     18 
    1192007-03-05  Paul Lindner  <lindner@inuus.com> 
    220        * Fix a number of places where (s)printf calls were using unsigned 
  • branches/multithreaded/server/items.c

    r469 r474  
    3434    int i; 
    3535    for(i=0; i<LARGEST_ID; i++) { 
    36         heads[i]=0
    37         tails[i]=0
     36        heads[i]=NULL
     37        tails[i]=NULL
    3838        sizes[i]=0; 
    3939    } 
     
    6464 * Returns the total size of the header. 
    6565 */ 
    66 static size_t item_make_header(char *key, const uint8_t nkey, const int flags, const int nbytes, 
     66static size_t item_make_header(const uint8_t nkey, const int flags, const int nbytes, 
    6767                     char *suffix, uint8_t *nsuffix) { 
    6868    /* suffix is defined at 40 chars elsewhere.. */ 
     
    7979    char suffix[40]; 
    8080 
    81     ntotal = item_make_header(key, nkey + 1, flags, nbytes, suffix, &nsuffix); 
     81    ntotal = item_make_header(nkey + 1, flags, nbytes, suffix, &nsuffix); 
    8282  
    8383    id = slabs_clsid(ntotal); 
     
    153153 * the maximum for a cache entry.) 
    154154 */ 
    155 bool item_size_ok(char *key, const size_t nkey, const int flags, const int nbytes) { 
     155bool item_size_ok(const size_t nkey, const int flags, const int nbytes) { 
    156156    char prefix[40]; 
    157157    uint8_t nsuffix; 
    158158 
    159     return slabs_clsid(item_make_header(key, nkey + 1, flags, nbytes, 
     159    return slabs_clsid(item_make_header(nkey + 1, flags, nbytes, 
    160160                                        prefix, &nsuffix)) != 0; 
    161161} 
     
    408408 
    409409/* expires items that are more recent than the oldest_live setting. */ 
    410 void do_item_flush_expired() { 
     410void do_item_flush_expired(void) { 
    411411    int i; 
    412412    item *iter, *next; 
  • branches/multithreaded/server/items.h

    r469 r474  
    44item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_time_t exptime, const int nbytes); 
    55void item_free(item *it); 
    6 bool item_size_ok(char *key, const size_t nkey, const int flags, const int nbytes); 
     6bool item_size_ok(const size_t nkey, const int flags, const int nbytes); 
    77 
    88int  do_item_link(item *it);    /* may fail if transgresses limits */ 
  • branches/multithreaded/server/memcached.c

    r469 r474  
    472472 
    473473    if (c->isize > ITEM_LIST_HIGHWAT) { 
    474         item **newbuf = (item**) realloc((void*)&c->ilist, ITEM_LIST_INITIAL * sizeof(c->ilist[0])); 
     474        item **newbuf = (item**) realloc((void*)c->ilist, ITEM_LIST_INITIAL * sizeof(c->ilist[0])); 
    475475        if (newbuf) { 
    476476            c->ilist = newbuf; 
     
    481481 
    482482    if (c->msgsize > MSG_LIST_HIGHWAT) { 
    483         struct msghdr *newbuf = (struct msghdr*) realloc((void*)&c->msglist, MSG_LIST_INITIAL * sizeof(c->msglist[0])); 
     483        struct msghdr *newbuf = (struct msghdr*) realloc((void*)c->msglist, MSG_LIST_INITIAL * sizeof(c->msglist[0])); 
    484484        if (newbuf) { 
    485485            c->msglist = newbuf; 
     
    490490 
    491491    if (c->iovsize > IOV_LIST_HIGHWAT) { 
    492         struct iovec* newbuf = (struct iovec *) realloc((void*)&c->iov, IOV_LIST_INITIAL * sizeof(c->iov[0])); 
     492        struct iovec* newbuf = (struct iovec *) realloc((void*)c->iov, IOV_LIST_INITIAL * sizeof(c->iov[0])); 
    493493        if (newbuf) { 
    494494            c->iov = newbuf; 
     
    11151115         */ 
    11161116        if(key_token->value != NULL) { 
    1117            ntokens = tokenize_command(key_token->value, tokens, MAX_TOKENS); 
     1117            ntokens = tokenize_command(key_token->value, tokens, MAX_TOKENS); 
    11181118            key_token = tokens; 
    11191119        } 
     
    11831183 
    11841184    if (it == 0) { 
    1185         if (! item_size_ok(key, nkey, flags, vlen + 2)) 
     1185        if (! item_size_ok(nkey, flags, vlen + 2)) 
    11861186            out_string(c, "SERVER_ERROR object too large for cache"); 
    11871187        else 
     
    22732273static void usage(void) { 
    22742274    printf(PACKAGE " " VERSION "\n"); 
    2275     printf("-p <num>      TCP port number to listen on (default: 11211)\n"); 
    2276     printf("-U <num>      UDP port number to listen on (default: 0, off)\n"); 
    2277     printf("-s <file>     unix socket path to listen on (disables network support)\n"); 
    2278     printf("-l <ip_addr>  interface to listen on, default is INDRR_ANY\n"); 
    2279     printf("-d            run as a daemon\n"); 
    2280     printf("-r            maximize core file limit\n"); 
    2281     printf("-u <username> assume identity of <username> (only when run as root)\n"); 
    2282     printf("-m <num>      max memory to use for items in megabytes, default is 64 MB\n"); 
    2283     printf("-M            return error on memory exhausted (rather than removing items)\n"); 
    2284     printf("-c <num>      max simultaneous connections, default is 1024\n"); 
    2285     printf("-k            lock down all paged memory\n"); 
    2286     printf("-v            verbose (print errors/warnings while in event loop)\n"); 
    2287     printf("-vv           very verbose (also print client commands/reponses)\n"); 
    2288     printf("-h            print this help and exit\n"); 
    2289     printf("-i            print memcached and libevent license\n"); 
    2290     printf("-b            run a managed instanced (mnemonic: buckets)\n"); 
    2291     printf("-P <file>     save PID in <file>, only used with -d option\n"); 
    2292     printf("-f <factor>   chunk size growth factor, default 1.25\n"); 
    2293     printf("-n <bytes>    minimum space allocated for key+value+flags, default 48\n"); 
     2275    printf("-p <num>      TCP port number to listen on (default: 11211)\n" 
     2276           "-U <num>      UDP port number to listen on (default: 0, off)\n" 
     2277           "-s <file>     unix socket path to listen on (disables network support)\n" 
     2278           "-l <ip_addr>  interface to listen on, default is INDRR_ANY\n" 
     2279           "-d            run as a daemon\n" 
     2280           "-r            maximize core file limit\n" 
     2281           "-u <username> assume identity of <username> (only when run as root)\n" 
     2282           "-m <num>      max memory to use for items in megabytes, default is 64 MB\n" 
     2283           "-M            return error on memory exhausted (rather than removing items)\n" 
     2284           "-c <num>      max simultaneous connections, default is 1024\n" 
     2285           "-k            lock down all paged memory\n" 
     2286           "-v            verbose (print errors/warnings while in event loop)\n" 
     2287           "-vv           very verbose (also print client commands/reponses)\n" 
     2288           "-h            print this help and exit\n" 
     2289           "-i            print memcached and libevent license\n" 
     2290           "-b            run a managed instanced (mnemonic: buckets)\n" 
     2291           "-P <file>     save PID in <file>, only used with -d option\n" 
     2292           "-f <factor>   chunk size growth factor, default 1.25\n" 
     2293           "-n <bytes>    minimum space allocated for key+value+flags, default 48\n"); 
    22942294#ifdef USE_THREADS 
    22952295    printf("-t <num>      number of threads to use, default 4\n"); 
  • branches/multithreaded/server/memcached.h

    r469 r474  
    3232# include <stdbool.h> 
    3333#else 
    34 typedef enum {false = 0, true = 1} bool; 
     34  typedef enum {false = 0, true = 1} bool; 
    3535#endif 
    3636 
  • branches/multithreaded/server/t/getset.t

    r340 r474  
    22 
    33use strict; 
    4 use Test::More tests => 14
     4use Test::More tests => 528
    55use FindBin qw($Bin); 
    66use lib "$Bin/lib"; 
    77use MemcachedTest; 
    88 
     9 
    910my $server = new_memcached(); 
    1011my $sock = $server->sock; 
     12 
    1113 
    1214# set foo (and should get it) 
     
    4951 
    5052 
     53# Test sets up to a large size around 1MB. 
     54# Everything up to 1MB - 1k should succeed, everything 1MB +1k should fail. 
    5155 
     56my $len = 1024; 
     57while ($len < 1024*1028) { 
     58    my $val = "B"x$len; 
     59    print $sock "set foo_$len 0 0 $len\r\n$val\r\n"; 
     60    if ($len > (1024*1024)) { 
     61        is(scalar <$sock>, "SERVER_ERROR object too large for cache\r\n", "failed to store size $len"); 
     62    } else { 
     63        is(scalar <$sock>, "STORED\r\n", "stored size $len"); 
     64    } 
     65    $len += 2048; 
     66} 
     67