Changeset a57c5d


Ignore:
Timestamp:
03/05/08 14:27:59 (4 years ago)
Author:
Tomash Brechko <tomash.brechko@…>
Branches:
master, ketama-compat
Children:
6ab120
Parents:
ed67ff
git-author:
Tomash Brechko <tomash.brechko@…> (03/05/08 14:27:59)
git-committer:
Tomash Brechko <tomash.brechko@…> (03/05/08 14:27:59)
Message:

Add hash_namespace parameter.

The test t/hash_namespace.t is not added to MANIFEST intentionally.

Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • Fast.xs

    rea3648 ra57c5d  
    282282  if (ps && SvOK(*ps)) 
    283283    client_set_nowait(c, SvTRUE(*ps)); 
     284 
     285  ps = hv_fetch(conf, "hash_namespace", 14, 0); 
     286  if (ps && SvOK(*ps)) 
     287    client_set_hash_namespace(c, SvTRUE(*ps)); 
    284288 
    285289  parse_compress(memd, conf); 
  • lib/Cache/Memcached/Fast.pm

    r34f10e ra57c5d  
    4242      ketama_points => 150, 
    4343      nowait => 1, 
     44      hash_namespace => 1, 
    4445      serialize_methods => [ \&Storable::freeze, \&Storable::thaw ], 
    4546      utf8 => ($^V ge v5.8.1 ? 1 : 0), 
     
    186187to the B<memcached> server.  By using different namespaces clients 
    187188avoid interference with each other. 
     189 
     190 
     191=item I<hash_namespace> 
     192 
     193  hash_namespace => 1 
     194  (default: disabled) 
     195 
     196The value is a boolean which enables (true) or disables (false) the 
     197hashing of the namespace key prefix.  By default for compatibility 
     198with B<Cache::Memcached> namespace prefix is not hashed along with the 
     199key.  Thus 
     200 
     201  namespace => 'prefix/', 
     202  ... 
     203  $memd->set('key', $val); 
     204 
     205may use different B<memcached> server than 
     206 
     207  namespace => '', 
     208  ... 
     209  $memd->set('prefix/key', $val); 
     210 
     211because hash values of I<'key'> and I<'prefix/key'> may be different. 
     212 
     213However sometimes is it necessary to hash the namespace prefix, for 
     214instance for interoperability with other clients that do not have the 
     215notion of the namespace.  When I<hash_namespace> is enabled, both 
     216examples above will use the same server, the one that I<'prefix/key'> 
     217is mapped to.  Note that there's no performance penalty then, as 
     218namespace prefix is hashed only once.  See L</namespace>. 
    188219 
    189220 
     
    446477    namespace => 1, 
    447478    nowait => 1, 
     479    hash_namespace => 1, 
    448480    connect_timeout => 1, 
    449481    io_timeout => 1, 
  • src/client.c

    rea3648 ra57c5d  
    2727#include "parse_keyword.h" 
    2828#include "dispatch_key.h" 
     29#include "compute_crc32.h" 
    2930#include <stdlib.h> 
    3031#include <unistd.h> 
     
    256257  int close_on_error; 
    257258  int nowait; 
     259  int hash_namespace; 
    258260 
    259261  struct array index_list; 
     
    352354  c->close_on_error = 1; 
    353355  c->nowait = 0; 
     356  c->hash_namespace = 0; 
    354357 
    355358  c->generation = 1;            /* Different from initial command state.  */ 
     
    442445{ 
    443446  c->nowait = enable; 
     447} 
     448 
     449 
     450void 
     451client_set_hash_namespace(struct client *c, int enable) 
     452{ 
     453  c->hash_namespace = enable; 
    444454} 
    445455 
     
    487497          c->prefix_len = 1; 
    488498        } 
     499 
     500      if (c->hash_namespace) 
     501        dispatch_set_prefix_crc32(&c->dispatch, 0x0U); 
     502 
    489503      return MEMCACHED_SUCCESS; 
    490504    } 
     
    502516  c->prefix = s; 
    503517  c->prefix_len = 1 + ns_len; 
     518 
     519  if (c->hash_namespace) 
     520    dispatch_set_prefix_crc32(&c->dispatch, compute_crc32(ns, ns_len)); 
    504521 
    505522  return MEMCACHED_SUCCESS; 
  • src/client.h

    rea3648 ra57c5d  
    144144extern 
    145145void 
     146client_set_hash_namespace(struct client *c, int enable); 
     147 
     148extern 
     149void 
    146150client_reset(struct client *c, struct result_object *o, int noreply); 
    147151 
  • src/dispatch_key.c

    rd7f244 ra57c5d  
    11/* 
    2   Copyright (C) 2007 Tomash Brechko.  All rights reserved. 
     2  Copyright (C) 2007-2008 Tomash Brechko.  All rights reserved. 
    33 
    44  When used to build Perl module: 
     
    120120  */ 
    121121  struct continuum_point *p; 
    122   unsigned int crc32 = compute_crc32(key, key_len); 
     122  unsigned int crc32 = compute_crc32_add(state->prefix_crc32, key, key_len); 
    123123  unsigned int hash = ((crc32 >> 16) & 0x00007fff); 
    124124  unsigned int point = hash % (unsigned int) (state->total_weight + 0.5); 
     
    223223                        const char *key, size_t key_len) 
    224224{ 
    225   unsigned int point = compute_crc32(key, key_len); 
     225  unsigned int point = compute_crc32_add(state->prefix_crc32, key, key_len); 
    226226  struct continuum_point *p = dispatch_find_bucket(state, point); 
    227227  return p->index; 
     
    235235  state->total_weight = 0.0; 
    236236  state->ketama_points = 0; 
     237  state->prefix_crc32 = 0x0U; 
    237238} 
    238239 
     
    249250{ 
    250251  state->ketama_points = ketama_points; 
     252} 
     253 
     254 
     255void 
     256dispatch_set_prefix_crc32(struct dispatch_state *state, unsigned int crc32) 
     257{ 
     258  state->prefix_crc32 = crc32; 
    251259} 
    252260 
  • src/dispatch_key.h

    r626460 ra57c5d  
    11/* 
    2   Copyright (C) 2007 Tomash Brechko.  All rights reserved. 
     2  Copyright (C) 2007-2008 Tomash Brechko.  All rights reserved. 
    33 
    44  When used to build Perl module: 
     
    3434  double total_weight; 
    3535  int ketama_points; 
     36  unsigned int prefix_crc32; 
    3637}; 
    3738 
     
    5051 
    5152extern 
     53void 
     54dispatch_set_prefix_crc32(struct dispatch_state *state, unsigned int crc32); 
     55 
     56extern 
    5257int 
    5358dispatch_add_server(struct dispatch_state *state, 
Note: See TracChangeset for help on using the changeset viewer.