Changeset a57c5d
- Timestamp:
- 03/05/08 14:27:59 (4 years ago)
- 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)
- Files:
-
- 1 added
- 6 edited
-
Fast.xs (modified) (1 diff)
-
lib/Cache/Memcached/Fast.pm (modified) (3 diffs)
-
src/client.c (modified) (6 diffs)
-
src/client.h (modified) (1 diff)
-
src/dispatch_key.c (modified) (5 diffs)
-
src/dispatch_key.h (modified) (3 diffs)
-
t/hash_namespace.t (added)
Legend:
- Unmodified
- Added
- Removed
-
Fast.xs
rea3648 ra57c5d 282 282 if (ps && SvOK(*ps)) 283 283 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)); 284 288 285 289 parse_compress(memd, conf); -
lib/Cache/Memcached/Fast.pm
r34f10e ra57c5d 42 42 ketama_points => 150, 43 43 nowait => 1, 44 hash_namespace => 1, 44 45 serialize_methods => [ \&Storable::freeze, \&Storable::thaw ], 45 46 utf8 => ($^V ge v5.8.1 ? 1 : 0), … … 186 187 to the B<memcached> server. By using different namespaces clients 187 188 avoid interference with each other. 189 190 191 =item I<hash_namespace> 192 193 hash_namespace => 1 194 (default: disabled) 195 196 The value is a boolean which enables (true) or disables (false) the 197 hashing of the namespace key prefix. By default for compatibility 198 with B<Cache::Memcached> namespace prefix is not hashed along with the 199 key. Thus 200 201 namespace => 'prefix/', 202 ... 203 $memd->set('key', $val); 204 205 may use different B<memcached> server than 206 207 namespace => '', 208 ... 209 $memd->set('prefix/key', $val); 210 211 because hash values of I<'key'> and I<'prefix/key'> may be different. 212 213 However sometimes is it necessary to hash the namespace prefix, for 214 instance for interoperability with other clients that do not have the 215 notion of the namespace. When I<hash_namespace> is enabled, both 216 examples above will use the same server, the one that I<'prefix/key'> 217 is mapped to. Note that there's no performance penalty then, as 218 namespace prefix is hashed only once. See L</namespace>. 188 219 189 220 … … 446 477 namespace => 1, 447 478 nowait => 1, 479 hash_namespace => 1, 448 480 connect_timeout => 1, 449 481 io_timeout => 1, -
src/client.c
rea3648 ra57c5d 27 27 #include "parse_keyword.h" 28 28 #include "dispatch_key.h" 29 #include "compute_crc32.h" 29 30 #include <stdlib.h> 30 31 #include <unistd.h> … … 256 257 int close_on_error; 257 258 int nowait; 259 int hash_namespace; 258 260 259 261 struct array index_list; … … 352 354 c->close_on_error = 1; 353 355 c->nowait = 0; 356 c->hash_namespace = 0; 354 357 355 358 c->generation = 1; /* Different from initial command state. */ … … 442 445 { 443 446 c->nowait = enable; 447 } 448 449 450 void 451 client_set_hash_namespace(struct client *c, int enable) 452 { 453 c->hash_namespace = enable; 444 454 } 445 455 … … 487 497 c->prefix_len = 1; 488 498 } 499 500 if (c->hash_namespace) 501 dispatch_set_prefix_crc32(&c->dispatch, 0x0U); 502 489 503 return MEMCACHED_SUCCESS; 490 504 } … … 502 516 c->prefix = s; 503 517 c->prefix_len = 1 + ns_len; 518 519 if (c->hash_namespace) 520 dispatch_set_prefix_crc32(&c->dispatch, compute_crc32(ns, ns_len)); 504 521 505 522 return MEMCACHED_SUCCESS; -
src/client.h
rea3648 ra57c5d 144 144 extern 145 145 void 146 client_set_hash_namespace(struct client *c, int enable); 147 148 extern 149 void 146 150 client_reset(struct client *c, struct result_object *o, int noreply); 147 151 -
src/dispatch_key.c
rd7f244 ra57c5d 1 1 /* 2 Copyright (C) 2007 Tomash Brechko. All rights reserved.2 Copyright (C) 2007-2008 Tomash Brechko. All rights reserved. 3 3 4 4 When used to build Perl module: … … 120 120 */ 121 121 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); 123 123 unsigned int hash = ((crc32 >> 16) & 0x00007fff); 124 124 unsigned int point = hash % (unsigned int) (state->total_weight + 0.5); … … 223 223 const char *key, size_t key_len) 224 224 { 225 unsigned int point = compute_crc32 (key, key_len);225 unsigned int point = compute_crc32_add(state->prefix_crc32, key, key_len); 226 226 struct continuum_point *p = dispatch_find_bucket(state, point); 227 227 return p->index; … … 235 235 state->total_weight = 0.0; 236 236 state->ketama_points = 0; 237 state->prefix_crc32 = 0x0U; 237 238 } 238 239 … … 249 250 { 250 251 state->ketama_points = ketama_points; 252 } 253 254 255 void 256 dispatch_set_prefix_crc32(struct dispatch_state *state, unsigned int crc32) 257 { 258 state->prefix_crc32 = crc32; 251 259 } 252 260 -
src/dispatch_key.h
r626460 ra57c5d 1 1 /* 2 Copyright (C) 2007 Tomash Brechko. All rights reserved.2 Copyright (C) 2007-2008 Tomash Brechko. All rights reserved. 3 3 4 4 When used to build Perl module: … … 34 34 double total_weight; 35 35 int ketama_points; 36 unsigned int prefix_crc32; 36 37 }; 37 38 … … 50 51 51 52 extern 53 void 54 dispatch_set_prefix_crc32(struct dispatch_state *state, unsigned int crc32); 55 56 extern 52 57 int 53 58 dispatch_add_server(struct dispatch_state *state,
Note: See TracChangeset
for help on using the changeset viewer.
