memcached 1.2.6 → 1.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Manifest +206 -12
- data/Rakefile +32 -1
- data/ext/extconf.rb +10 -35
- data/ext/libmemcached-0.32/AUTHORS +7 -0
- data/ext/libmemcached-0.32/COPYING +32 -0
- data/ext/libmemcached-0.32/ChangeLog +303 -0
- data/ext/libmemcached-0.32/INSTALL +302 -0
- data/ext/libmemcached-0.32/Makefile.am +36 -0
- data/ext/libmemcached-0.32/Makefile.in +828 -0
- data/ext/libmemcached-0.32/NEWS +1 -0
- data/ext/libmemcached-0.32/README +33 -0
- data/ext/libmemcached-0.32/THANKS +14 -0
- data/ext/libmemcached-0.32/TODO +11 -0
- data/ext/libmemcached-0.32/aclocal.m4 +1852 -0
- data/ext/libmemcached-0.32/clients/Makefile.am +73 -0
- data/ext/libmemcached-0.32/clients/Makefile.in +770 -0
- data/ext/libmemcached-0.32/clients/client_options.h +32 -0
- data/ext/libmemcached-0.32/clients/execute.c +64 -0
- data/ext/libmemcached-0.32/clients/execute.h +5 -0
- data/ext/libmemcached-0.32/clients/generator.c +74 -0
- data/ext/libmemcached-0.32/clients/generator.h +20 -0
- data/ext/libmemcached-0.32/clients/memcat.c +178 -0
- data/ext/libmemcached-0.32/clients/memcp.c +251 -0
- data/ext/libmemcached-0.32/clients/memdump.c +170 -0
- data/ext/libmemcached-0.32/clients/memerror.c +80 -0
- data/ext/libmemcached-0.32/clients/memflush.c +143 -0
- data/ext/libmemcached-0.32/clients/memrm.c +160 -0
- data/ext/libmemcached-0.32/clients/memslap.c +441 -0
- data/ext/libmemcached-0.32/clients/memstat.c +326 -0
- data/ext/libmemcached-0.32/clients/utilities.c +207 -0
- data/ext/libmemcached-0.32/clients/utilities.h +41 -0
- data/ext/libmemcached-0.32/config.h.in +252 -0
- data/ext/libmemcached-0.32/config/compile +143 -0
- data/ext/libmemcached-0.32/config/config.guess +1561 -0
- data/ext/libmemcached-0.32/config/config.rpath +666 -0
- data/ext/libmemcached-0.32/config/config.sub +1686 -0
- data/ext/libmemcached-0.32/config/depcomp +630 -0
- data/ext/libmemcached-0.32/config/install-sh +520 -0
- data/ext/libmemcached-0.32/config/ltmain.sh +8406 -0
- data/ext/libmemcached-0.32/config/missing +376 -0
- data/ext/libmemcached-0.32/configure +23048 -0
- data/ext/libmemcached-0.32/configure.ac +122 -0
- data/ext/libmemcached-0.32/docs/Makefile.am +415 -0
- data/ext/libmemcached-0.32/docs/Makefile.in +918 -0
- data/ext/libmemcached-0.32/docs/libmemcached.pod +123 -0
- data/ext/libmemcached-0.32/docs/libmemcached_examples.pod +115 -0
- data/ext/libmemcached-0.32/docs/libmemcachedutil.pod +40 -0
- data/ext/libmemcached-0.32/docs/memcached_analyze.pod +52 -0
- data/ext/libmemcached-0.32/docs/memcached_auto.pod +97 -0
- data/ext/libmemcached-0.32/docs/memcached_behavior.pod +224 -0
- data/ext/libmemcached-0.32/docs/memcached_callback.pod +123 -0
- data/ext/libmemcached-0.32/docs/memcached_create.pod +61 -0
- data/ext/libmemcached-0.32/docs/memcached_delete.pod +54 -0
- data/ext/libmemcached-0.32/docs/memcached_dump.pod +53 -0
- data/ext/libmemcached-0.32/docs/memcached_flush.pod +46 -0
- data/ext/libmemcached-0.32/docs/memcached_flush_buffers.pod +42 -0
- data/ext/libmemcached-0.32/docs/memcached_generate_hash_value.pod +57 -0
- data/ext/libmemcached-0.32/docs/memcached_get.pod +161 -0
- data/ext/libmemcached-0.32/docs/memcached_memory_allocators.pod +73 -0
- data/ext/libmemcached-0.32/docs/memcached_pool.pod +77 -0
- data/ext/libmemcached-0.32/docs/memcached_quit.pod +47 -0
- data/ext/libmemcached-0.32/docs/memcached_sasl.pod +63 -0
- data/ext/libmemcached-0.32/docs/memcached_server_st.pod +75 -0
- data/ext/libmemcached-0.32/docs/memcached_servers.pod +102 -0
- data/ext/libmemcached-0.32/docs/memcached_set.pod +187 -0
- data/ext/libmemcached-0.32/docs/memcached_stats.pod +82 -0
- data/ext/libmemcached-0.32/docs/memcached_strerror.pod +46 -0
- data/ext/libmemcached-0.32/docs/memcached_user_data.pod +49 -0
- data/ext/libmemcached-0.32/docs/memcached_verbosity.pod +41 -0
- data/ext/libmemcached-0.32/docs/memcached_version.pod +56 -0
- data/ext/libmemcached-0.32/docs/memcat.pod +37 -0
- data/ext/libmemcached-0.32/docs/memcp.pod +40 -0
- data/ext/libmemcached-0.32/docs/memdump.pod +31 -0
- data/ext/libmemcached-0.32/docs/memerror.pod +30 -0
- data/ext/libmemcached-0.32/docs/memflush.pod +35 -0
- data/ext/libmemcached-0.32/docs/memrm.pod +34 -0
- data/ext/libmemcached-0.32/docs/memslap.pod +33 -0
- data/ext/libmemcached-0.32/docs/memstat.pod +35 -0
- data/ext/libmemcached-0.32/libmemcached/Makefile.am +107 -0
- data/ext/libmemcached-0.32/libmemcached/Makefile.in +1050 -0
- data/ext/libmemcached-0.32/libmemcached/byteorder.c +31 -0
- data/ext/libmemcached-0.32/libmemcached/common.h +183 -0
- data/ext/libmemcached-0.32/libmemcached/crc.c +86 -0
- data/ext/libmemcached-0.32/libmemcached/hsieh_hash.c +68 -0
- data/ext/libmemcached-0.32/libmemcached/jenkins_hash.c +213 -0
- data/ext/libmemcached-0.32/libmemcached/libmemcached.ver +1 -0
- data/ext/libmemcached-0.32/libmemcached/libmemcached_probes.d +28 -0
- data/ext/libmemcached-0.32/libmemcached/libmemcached_probes.h +78 -0
- data/ext/libmemcached-0.32/libmemcached/md5.c +354 -0
- data/ext/libmemcached-0.32/libmemcached/memcached.c +152 -0
- data/ext/libmemcached-0.32/libmemcached/memcached.h +302 -0
- data/ext/libmemcached-0.32/libmemcached/memcached.hpp +799 -0
- data/ext/libmemcached-0.32/libmemcached/memcached/README.txt +7 -0
- data/ext/libmemcached-0.32/libmemcached/memcached/protocol_binary.h +366 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_allocators.c +72 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_analyze.c +100 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_auto.c +207 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_behavior.c +285 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_callback.c +175 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_configure.h.in +23 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_connect.c +361 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_constants.h +145 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_delete.c +0 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_do.c +34 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_dump.c +79 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_fetch.c +102 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_flush.c +89 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_flush_buffers.c +22 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_get.c +495 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_get.h +87 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_hash.c +252 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_hosts.c +510 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_internal.h +31 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_io.c +547 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_io.h +59 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_key.c +28 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_parse.c +74 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_pool.h +38 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_purge.c +76 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_quit.c +75 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_response.c +528 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_result.c +57 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_result.h +59 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_sasl.c +225 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_sasl.h +44 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_server.c +159 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_server.h +93 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_stats.c +454 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_storage.c +514 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_storage.h +107 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_strerror.c +92 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_string.c +138 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_string.h +53 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_types.h +44 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_util.h +15 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_verbosity.c +36 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_version.c +112 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_watchpoint.h +38 -0
- data/ext/libmemcached-0.32/libmemcached/murmur_hash.c +76 -0
- data/ext/libmemcached-0.32/libmemcached/visibility.h +51 -0
- data/ext/libmemcached-0.32/libmemcachedutil/Makefile.am +11 -0
- data/ext/libmemcached-0.32/libmemcachedutil/Makefile.in +602 -0
- data/ext/libmemcached-0.32/libmemcachedutil/libmemcachedutil.ver +1 -0
- data/ext/libmemcached-0.32/libmemcachedutil/memcached_pool.c +170 -0
- data/ext/libmemcached-0.32/m4/ac_cxx_compile_stdcxx_0x.m4 +103 -0
- data/ext/libmemcached-0.32/m4/ac_cxx_header_stdcxx_98.m4 +67 -0
- data/ext/libmemcached-0.32/m4/acx_pthread.m4 +276 -0
- data/ext/libmemcached-0.32/m4/byteorder.m4 +40 -0
- data/ext/libmemcached-0.32/m4/deprecated.m4 +17 -0
- data/ext/libmemcached-0.32/m4/enable_utillib.m4 +16 -0
- data/ext/libmemcached-0.32/m4/extensions.m4 +94 -0
- data/ext/libmemcached-0.32/m4/hsieh.m4 +18 -0
- data/ext/libmemcached-0.32/m4/lib-prefix.m4 +221 -0
- data/ext/libmemcached-0.32/m4/libtool.m4 +7360 -0
- data/ext/libmemcached-0.32/m4/ltoptions.m4 +368 -0
- data/ext/libmemcached-0.32/m4/ltsugar.m4 +123 -0
- data/ext/libmemcached-0.32/m4/ltversion.m4 +23 -0
- data/ext/libmemcached-0.32/m4/lt~obsolete.m4 +92 -0
- data/ext/libmemcached-0.32/m4/memcached.m4 +30 -0
- data/ext/libmemcached-0.32/m4/pandora_64bit.m4 +55 -0
- data/ext/libmemcached-0.32/m4/pandora_canonical.m4 +151 -0
- data/ext/libmemcached-0.32/m4/pandora_check_compiler_version.m4 +37 -0
- data/ext/libmemcached-0.32/m4/pandora_check_cxx_standard.m4 +16 -0
- data/ext/libmemcached-0.32/m4/pandora_enable_dtrace.m4 +41 -0
- data/ext/libmemcached-0.32/m4/pandora_ensure_gcc_version.m4 +36 -0
- data/ext/libmemcached-0.32/m4/pandora_have_better_malloc.m4 +54 -0
- data/ext/libmemcached-0.32/m4/pandora_have_sasl.m4 +133 -0
- data/ext/libmemcached-0.32/m4/pandora_header_assert.m4 +23 -0
- data/ext/libmemcached-0.32/m4/pandora_libtool.m4 +15 -0
- data/ext/libmemcached-0.32/m4/pandora_optimize.m4 +79 -0
- data/ext/libmemcached-0.32/m4/pandora_shared_ptr.m4 +56 -0
- data/ext/libmemcached-0.32/m4/pandora_vc_build.m4 +32 -0
- data/ext/libmemcached-0.32/m4/pandora_warnings.m4 +262 -0
- data/ext/libmemcached-0.32/m4/pod2man.m4 +7 -0
- data/ext/libmemcached-0.32/m4/protocol_binary.m4 +23 -0
- data/ext/libmemcached-0.32/m4/setsockopt.m4 +57 -0
- data/ext/libmemcached-0.32/m4/visibility.m4 +52 -0
- data/ext/libmemcached-0.32/support/Makefile.am +4 -0
- data/ext/libmemcached-0.32/support/Makefile.in +485 -0
- data/ext/libmemcached-0.32/support/libmemcached-fc.spec.in +105 -0
- data/ext/libmemcached-0.32/support/libmemcached.pc.in +10 -0
- data/ext/libmemcached-0.32/support/libmemcached.spec +105 -0
- data/ext/libmemcached-0.32/support/libmemcached.spec.in +105 -0
- data/ext/libmemcached-0.32/support/set_benchmark.sh +5 -0
- data/ext/libmemcached-0.32/tests/Makefile.am +105 -0
- data/ext/libmemcached-0.32/tests/Makefile.in +748 -0
- data/ext/libmemcached-0.32/tests/atomsmasher.c +245 -0
- data/ext/libmemcached-0.32/tests/function.c +4781 -0
- data/ext/libmemcached-0.32/tests/ketama_test_cases.h +108 -0
- data/ext/libmemcached-0.32/tests/output.cmp +7 -0
- data/ext/libmemcached-0.32/tests/output.res +7 -0
- data/ext/libmemcached-0.32/tests/output2.res +46 -0
- data/ext/libmemcached-0.32/tests/plus.cpp +293 -0
- data/ext/libmemcached-0.32/tests/r/memcat.res +19 -0
- data/ext/libmemcached-0.32/tests/r/memcp.res +27 -0
- data/ext/libmemcached-0.32/tests/r/memrm.res +19 -0
- data/ext/libmemcached-0.32/tests/r/memslap.res +33 -0
- data/ext/libmemcached-0.32/tests/r/memstat.res +33 -0
- data/ext/libmemcached-0.32/tests/server.c +118 -0
- data/ext/libmemcached-0.32/tests/server.h +25 -0
- data/ext/libmemcached-0.32/tests/start.c +16 -0
- data/ext/libmemcached-0.32/tests/t/memcat.test +4 -0
- data/ext/libmemcached-0.32/tests/t/memcp.test +3 -0
- data/ext/libmemcached-0.32/tests/t/memrm.test +3 -0
- data/ext/libmemcached-0.32/tests/t/memslap.test +5 -0
- data/ext/libmemcached-0.32/tests/t/memstat.test +3 -0
- data/ext/libmemcached-0.32/tests/test.c +137 -0
- data/ext/libmemcached-0.32/tests/test.h +46 -0
- data/ext/libmemcached-0.32/tests/udp.c +76 -0
- data/memcached.gemspec +4 -4
- data/test/unit/memcached_test.rb +30 -0
- metadata +213 -16
- data/ext/libmemcached-0.32.tar.gz +0 -0
- data/ext/libmemcached-1.patch +0 -270
- data/ext/libmemcached-10.patch +0 -12
- data/ext/libmemcached-2.patch +0 -116
- data/ext/libmemcached-3.patch +0 -8
- data/ext/libmemcached-4.patch +0 -40
- data/ext/libmemcached-5.patch +0 -832
- data/ext/libmemcached-6.patch +0 -20
- data/ext/libmemcached-7.patch +0 -2989
- data/ext/libmemcached-8.patch +0 -137
- data/ext/libmemcached-9.patch +0 -13
- data/ext/sasl.patch +0 -29283
@@ -0,0 +1,87 @@
|
|
1
|
+
/*
|
2
|
+
* Summary: Get functions for libmemcached
|
3
|
+
*
|
4
|
+
* Copy: See Copyright for the status of this software.
|
5
|
+
*
|
6
|
+
* Author: Brian Aker
|
7
|
+
*/
|
8
|
+
|
9
|
+
#ifndef __MEMCACHED_GET_H__
|
10
|
+
#define __MEMCACHED_GET_H__
|
11
|
+
|
12
|
+
#ifdef __cplusplus
|
13
|
+
extern "C" {
|
14
|
+
#endif
|
15
|
+
|
16
|
+
#define GET_LEN_ARG_UNSPECIFIED -1U
|
17
|
+
#define GET_LEN_BUFSZ 32
|
18
|
+
|
19
|
+
/* Public defines */
|
20
|
+
LIBMEMCACHED_API
|
21
|
+
char *memcached_get(memcached_st *ptr,
|
22
|
+
const char *key, size_t key_length,
|
23
|
+
size_t *value_length,
|
24
|
+
uint32_t *flags,
|
25
|
+
memcached_return *error);
|
26
|
+
|
27
|
+
LIBMEMCACHED_API
|
28
|
+
char *memcached_get_len(memcached_st *ptr,
|
29
|
+
const char *key, size_t key_length,
|
30
|
+
uint32_t user_spec_len,
|
31
|
+
size_t *value_length,
|
32
|
+
uint32_t *flags,
|
33
|
+
memcached_return *error);
|
34
|
+
|
35
|
+
LIBMEMCACHED_API
|
36
|
+
memcached_return memcached_mget(memcached_st *ptr,
|
37
|
+
const char **keys, size_t *key_length,
|
38
|
+
size_t number_of_keys);
|
39
|
+
|
40
|
+
LIBMEMCACHED_API
|
41
|
+
memcached_return memcached_mget_len(memcached_st *ptr,
|
42
|
+
const char **keys, size_t *key_length,
|
43
|
+
size_t number_of_keys, uint32_t user_spec_len);
|
44
|
+
|
45
|
+
LIBMEMCACHED_API
|
46
|
+
char *memcached_get_by_key(memcached_st *ptr,
|
47
|
+
const char *master_key,
|
48
|
+
size_t master_key_length,
|
49
|
+
const char *key, size_t key_length,
|
50
|
+
uint32_t user_spec_len,
|
51
|
+
size_t *value_length,
|
52
|
+
uint32_t *flags,
|
53
|
+
memcached_return *error);
|
54
|
+
|
55
|
+
LIBMEMCACHED_API
|
56
|
+
memcached_return memcached_mget_by_key(memcached_st *ptr,
|
57
|
+
const char *master_key, size_t
|
58
|
+
master_key_length,
|
59
|
+
const char **keys,
|
60
|
+
size_t *key_length,
|
61
|
+
size_t number_of_keys,
|
62
|
+
uint32_t user_spec_len);
|
63
|
+
|
64
|
+
LIBMEMCACHED_API
|
65
|
+
char *memcached_fetch(memcached_st *ptr,
|
66
|
+
char *key, size_t *key_length,
|
67
|
+
size_t *value_length, uint32_t *flags,
|
68
|
+
memcached_return *error);
|
69
|
+
|
70
|
+
LIBMEMCACHED_API
|
71
|
+
memcached_result_st *memcached_fetch_result(memcached_st *ptr,
|
72
|
+
memcached_result_st *result,
|
73
|
+
memcached_return *error);
|
74
|
+
|
75
|
+
LIBMEMCACHED_API
|
76
|
+
char *memcached_get_from_last(memcached_st *ptr,
|
77
|
+
const char *key,
|
78
|
+
size_t key_length,
|
79
|
+
size_t *value_length,
|
80
|
+
uint32_t *flags,
|
81
|
+
memcached_return *error);
|
82
|
+
|
83
|
+
#ifdef __cplusplus
|
84
|
+
}
|
85
|
+
#endif
|
86
|
+
|
87
|
+
#endif /* __MEMCACHED_GET_H__ */
|
@@ -0,0 +1,252 @@
|
|
1
|
+
#include "common.h"
|
2
|
+
|
3
|
+
|
4
|
+
/* Defines */
|
5
|
+
static uint64_t FNV_64_INIT= UINT64_C(0xcbf29ce484222325);
|
6
|
+
static uint64_t FNV_64_PRIME= UINT64_C(0x100000001b3);
|
7
|
+
|
8
|
+
static uint32_t FNV_32_INIT= 2166136261UL;
|
9
|
+
static uint32_t FNV_32_PRIME= 16777619;
|
10
|
+
|
11
|
+
/* Prototypes */
|
12
|
+
static uint32_t internal_generate_hash(const char *key, size_t key_length);
|
13
|
+
static uint32_t internal_generate_md5(const char *key, size_t key_length);
|
14
|
+
uint32_t memcached_live_host_index(memcached_st *ptr, uint32_t num);
|
15
|
+
|
16
|
+
uint32_t memcached_generate_hash_value(const char *key, size_t key_length, memcached_hash hash_algorithm)
|
17
|
+
{
|
18
|
+
uint32_t hash= 1; /* Just here to remove compile warning */
|
19
|
+
uint32_t x= 0;
|
20
|
+
|
21
|
+
switch (hash_algorithm)
|
22
|
+
{
|
23
|
+
case MEMCACHED_HASH_DEFAULT:
|
24
|
+
hash= internal_generate_hash(key, key_length);
|
25
|
+
break;
|
26
|
+
case MEMCACHED_HASH_MD5:
|
27
|
+
hash= internal_generate_md5(key, key_length);
|
28
|
+
break;
|
29
|
+
case MEMCACHED_HASH_CRC:
|
30
|
+
hash= ((hash_crc32(key, key_length) >> 16) & 0x7fff);
|
31
|
+
if (hash == 0)
|
32
|
+
hash= 1;
|
33
|
+
break;
|
34
|
+
/* FNV hash'es lifted from Dustin Sallings work */
|
35
|
+
case MEMCACHED_HASH_FNV1_64:
|
36
|
+
{
|
37
|
+
/* Thanks to pierre@demartines.com for the pointer */
|
38
|
+
uint64_t temp_hash;
|
39
|
+
|
40
|
+
temp_hash= FNV_64_INIT;
|
41
|
+
for (x= 0; x < key_length; x++)
|
42
|
+
{
|
43
|
+
temp_hash *= FNV_64_PRIME;
|
44
|
+
temp_hash ^= (uint64_t)key[x];
|
45
|
+
}
|
46
|
+
hash= (uint32_t)temp_hash;
|
47
|
+
}
|
48
|
+
break;
|
49
|
+
case MEMCACHED_HASH_FNV1A_64:
|
50
|
+
{
|
51
|
+
hash= (uint32_t) FNV_64_INIT;
|
52
|
+
for (x= 0; x < key_length; x++)
|
53
|
+
{
|
54
|
+
uint32_t val= (uint32_t)key[x];
|
55
|
+
hash ^= val;
|
56
|
+
hash *= (uint32_t) FNV_64_PRIME;
|
57
|
+
}
|
58
|
+
}
|
59
|
+
break;
|
60
|
+
case MEMCACHED_HASH_FNV1_32:
|
61
|
+
{
|
62
|
+
hash= FNV_32_INIT;
|
63
|
+
for (x= 0; x < key_length; x++)
|
64
|
+
{
|
65
|
+
uint32_t val= (uint32_t)key[x];
|
66
|
+
hash *= FNV_32_PRIME;
|
67
|
+
hash ^= val;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
break;
|
71
|
+
case MEMCACHED_HASH_FNV1A_32:
|
72
|
+
{
|
73
|
+
hash= FNV_32_INIT;
|
74
|
+
for (x= 0; x < key_length; x++)
|
75
|
+
{
|
76
|
+
uint32_t val= (uint32_t)key[x];
|
77
|
+
hash ^= val;
|
78
|
+
hash *= FNV_32_PRIME;
|
79
|
+
}
|
80
|
+
}
|
81
|
+
break;
|
82
|
+
case MEMCACHED_HASH_HSIEH:
|
83
|
+
{
|
84
|
+
#ifdef HAVE_HSIEH_HASH
|
85
|
+
hash= hsieh_hash(key, key_length);
|
86
|
+
#endif
|
87
|
+
break;
|
88
|
+
}
|
89
|
+
case MEMCACHED_HASH_MURMUR:
|
90
|
+
{
|
91
|
+
hash= murmur_hash(key, key_length);
|
92
|
+
break;
|
93
|
+
}
|
94
|
+
case MEMCACHED_HASH_JENKINS:
|
95
|
+
{
|
96
|
+
hash=jenkins_hash(key, key_length, 13);
|
97
|
+
break;
|
98
|
+
}
|
99
|
+
case MEMCACHED_HASH_NONE:
|
100
|
+
{
|
101
|
+
hash= 1;
|
102
|
+
break;
|
103
|
+
}
|
104
|
+
default:
|
105
|
+
{
|
106
|
+
WATCHPOINT_ASSERT(hash_algorithm);
|
107
|
+
break;
|
108
|
+
}
|
109
|
+
}
|
110
|
+
return hash;
|
111
|
+
}
|
112
|
+
|
113
|
+
uint32_t generate_hash(memcached_st *ptr, const char *key, size_t key_length)
|
114
|
+
{
|
115
|
+
uint32_t hash= 1; /* Just here to remove compile warning */
|
116
|
+
|
117
|
+
|
118
|
+
WATCHPOINT_ASSERT(ptr->number_of_hosts);
|
119
|
+
|
120
|
+
if (ptr->number_of_hosts == 1)
|
121
|
+
return 0;
|
122
|
+
|
123
|
+
hash= memcached_generate_hash_value(key, key_length, ptr->hash);
|
124
|
+
WATCHPOINT_ASSERT(hash);
|
125
|
+
return hash;
|
126
|
+
}
|
127
|
+
|
128
|
+
static uint32_t dispatch_host(memcached_st *ptr, uint32_t hash)
|
129
|
+
{
|
130
|
+
switch (ptr->distribution)
|
131
|
+
{
|
132
|
+
case MEMCACHED_DISTRIBUTION_CONSISTENT:
|
133
|
+
case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA:
|
134
|
+
{
|
135
|
+
uint32_t num= ptr->continuum_points_counter;
|
136
|
+
WATCHPOINT_ASSERT(ptr->continuum);
|
137
|
+
|
138
|
+
hash= hash;
|
139
|
+
memcached_continuum_item_st *begin, *end, *left, *right, *middle;
|
140
|
+
begin= left= ptr->continuum;
|
141
|
+
end= right= ptr->continuum + num;
|
142
|
+
|
143
|
+
while (left < right)
|
144
|
+
{
|
145
|
+
middle= left + (right - left) / 2;
|
146
|
+
if (middle->value < hash)
|
147
|
+
left= middle + 1;
|
148
|
+
else
|
149
|
+
right= middle;
|
150
|
+
}
|
151
|
+
if (right == end)
|
152
|
+
right= begin;
|
153
|
+
return right->index;
|
154
|
+
}
|
155
|
+
case MEMCACHED_DISTRIBUTION_MODULA:
|
156
|
+
return memcached_live_host_index(ptr, hash);
|
157
|
+
case MEMCACHED_DISTRIBUTION_RANDOM:
|
158
|
+
return memcached_live_host_index(ptr, (uint32_t) random());
|
159
|
+
default:
|
160
|
+
WATCHPOINT_ASSERT(0); /* We have added a distribution without extending the logic */
|
161
|
+
return hash % ptr->number_of_hosts;
|
162
|
+
}
|
163
|
+
|
164
|
+
/* NOTREACHED */
|
165
|
+
}
|
166
|
+
|
167
|
+
/*
|
168
|
+
One day make this public, and have it return the actual memcached_server_st
|
169
|
+
to the calling application.
|
170
|
+
*/
|
171
|
+
uint32_t memcached_generate_hash(memcached_st *ptr, const char *key, size_t key_length)
|
172
|
+
{
|
173
|
+
uint32_t hash= 1; /* Just here to remove compile warning */
|
174
|
+
|
175
|
+
WATCHPOINT_ASSERT(ptr->number_of_hosts);
|
176
|
+
|
177
|
+
if (ptr->number_of_hosts == 1)
|
178
|
+
return 0;
|
179
|
+
|
180
|
+
if (ptr->flags & MEM_HASH_WITH_PREFIX_KEY)
|
181
|
+
{
|
182
|
+
size_t temp_length= ptr->prefix_key_length + key_length;
|
183
|
+
char temp[temp_length];
|
184
|
+
|
185
|
+
if (temp_length > MEMCACHED_MAX_KEY -1)
|
186
|
+
return 0;
|
187
|
+
|
188
|
+
strncpy(temp, ptr->prefix_key, ptr->prefix_key_length);
|
189
|
+
strncpy(temp + ptr->prefix_key_length, key, key_length);
|
190
|
+
hash= generate_hash(ptr, temp, temp_length);
|
191
|
+
}
|
192
|
+
else
|
193
|
+
{
|
194
|
+
hash= generate_hash(ptr, key, key_length);
|
195
|
+
}
|
196
|
+
|
197
|
+
WATCHPOINT_ASSERT(hash);
|
198
|
+
|
199
|
+
if (memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS) && ptr->next_distribution_rebuild) {
|
200
|
+
struct timeval now;
|
201
|
+
|
202
|
+
if (gettimeofday(&now, NULL) == 0 &&
|
203
|
+
now.tv_sec > ptr->next_distribution_rebuild)
|
204
|
+
run_distribution(ptr);
|
205
|
+
}
|
206
|
+
|
207
|
+
return dispatch_host(ptr, hash);
|
208
|
+
}
|
209
|
+
|
210
|
+
uint32_t memcached_live_host_index(memcached_st *ptr, uint32_t num)
|
211
|
+
{
|
212
|
+
if (memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS)) {
|
213
|
+
if (ptr->number_of_live_hosts > 0) {
|
214
|
+
return ptr->live_host_indices[num % ptr->number_of_live_hosts];
|
215
|
+
} else {
|
216
|
+
return 0; /* FIXME: we should do something different if every server's dead, but I dunno what. */
|
217
|
+
}
|
218
|
+
} else {
|
219
|
+
return num % ptr->number_of_hosts;
|
220
|
+
}
|
221
|
+
}
|
222
|
+
|
223
|
+
static uint32_t internal_generate_hash(const char *key, size_t key_length)
|
224
|
+
{
|
225
|
+
const char *ptr= key;
|
226
|
+
uint32_t value= 0;
|
227
|
+
|
228
|
+
while (key_length--)
|
229
|
+
{
|
230
|
+
uint32_t val= (uint32_t) *ptr++;
|
231
|
+
value += val;
|
232
|
+
value += (value << 10);
|
233
|
+
value ^= (value >> 6);
|
234
|
+
}
|
235
|
+
value += (value << 3);
|
236
|
+
value ^= (value >> 11);
|
237
|
+
value += (value << 15);
|
238
|
+
|
239
|
+
return value == 0 ? 1 : (uint32_t) value;
|
240
|
+
}
|
241
|
+
|
242
|
+
static uint32_t internal_generate_md5(const char *key, size_t key_length)
|
243
|
+
{
|
244
|
+
unsigned char results[16];
|
245
|
+
|
246
|
+
md5_signature((unsigned char*)key, (unsigned int)key_length, results);
|
247
|
+
|
248
|
+
return ((uint32_t) (results[3] & 0xFF) << 24)
|
249
|
+
| ((uint32_t) (results[2] & 0xFF) << 16)
|
250
|
+
| ((uint32_t) (results[1] & 0xFF) << 8)
|
251
|
+
| (results[0] & 0xFF);
|
252
|
+
}
|
@@ -0,0 +1,510 @@
|
|
1
|
+
#include "common.h"
|
2
|
+
#include <math.h>
|
3
|
+
|
4
|
+
/* Protoypes (static) */
|
5
|
+
static memcached_return server_add(memcached_st *ptr, const char *hostname,
|
6
|
+
unsigned int port,
|
7
|
+
uint32_t weight,
|
8
|
+
memcached_connection type);
|
9
|
+
memcached_return update_continuum(memcached_st *ptr);
|
10
|
+
memcached_return update_live_host_indices(memcached_st *ptr);
|
11
|
+
|
12
|
+
static int compare_servers(const void *p1, const void *p2)
|
13
|
+
{
|
14
|
+
int return_value;
|
15
|
+
memcached_server_st *a= (memcached_server_st *)p1;
|
16
|
+
memcached_server_st *b= (memcached_server_st *)p2;
|
17
|
+
|
18
|
+
return_value= strcmp(a->hostname, b->hostname);
|
19
|
+
|
20
|
+
if (return_value == 0)
|
21
|
+
{
|
22
|
+
return_value= (int) (a->port - b->port);
|
23
|
+
}
|
24
|
+
|
25
|
+
return return_value;
|
26
|
+
}
|
27
|
+
|
28
|
+
static void sort_hosts(memcached_st *ptr)
|
29
|
+
{
|
30
|
+
if (ptr->number_of_hosts)
|
31
|
+
{
|
32
|
+
qsort(ptr->hosts, ptr->number_of_hosts, sizeof(memcached_server_st), compare_servers);
|
33
|
+
ptr->hosts[0].count= (uint16_t) ptr->number_of_hosts;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
|
38
|
+
memcached_return run_distribution(memcached_st *ptr)
|
39
|
+
{
|
40
|
+
switch (ptr->distribution)
|
41
|
+
{
|
42
|
+
case MEMCACHED_DISTRIBUTION_CONSISTENT:
|
43
|
+
case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA:
|
44
|
+
return update_continuum(ptr);
|
45
|
+
case MEMCACHED_DISTRIBUTION_MODULA:
|
46
|
+
if (ptr->flags & MEM_USE_SORT_HOSTS)
|
47
|
+
sort_hosts(ptr);
|
48
|
+
if (memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS))
|
49
|
+
update_live_host_indices(ptr);
|
50
|
+
break;
|
51
|
+
case MEMCACHED_DISTRIBUTION_RANDOM:
|
52
|
+
if (memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS))
|
53
|
+
update_live_host_indices(ptr);
|
54
|
+
break;
|
55
|
+
default:
|
56
|
+
WATCHPOINT_ASSERT(0); /* We have added a distribution without extending the logic */
|
57
|
+
}
|
58
|
+
|
59
|
+
return MEMCACHED_SUCCESS;
|
60
|
+
}
|
61
|
+
|
62
|
+
void server_list_free(memcached_st *ptr, memcached_server_st *servers)
|
63
|
+
{
|
64
|
+
unsigned int x;
|
65
|
+
|
66
|
+
if (servers == NULL)
|
67
|
+
return;
|
68
|
+
|
69
|
+
for (x= 0; x < servers->count; x++)
|
70
|
+
if (servers[x].address_info)
|
71
|
+
{
|
72
|
+
freeaddrinfo(servers[x].address_info);
|
73
|
+
servers[x].address_info= NULL;
|
74
|
+
}
|
75
|
+
|
76
|
+
if (ptr)
|
77
|
+
ptr->call_free(ptr, servers);
|
78
|
+
else
|
79
|
+
free(servers);
|
80
|
+
}
|
81
|
+
|
82
|
+
static uint32_t ketama_server_hash(const char *key, unsigned int key_length, int alignment)
|
83
|
+
{
|
84
|
+
unsigned char results[16];
|
85
|
+
|
86
|
+
md5_signature((unsigned char*)key, key_length, results);
|
87
|
+
return ((uint32_t) (results[3 + alignment * 4] & 0xFF) << 24)
|
88
|
+
| ((uint32_t) (results[2 + alignment * 4] & 0xFF) << 16)
|
89
|
+
| ((uint32_t) (results[1 + alignment * 4] & 0xFF) << 8)
|
90
|
+
| (results[0 + alignment * 4] & 0xFF);
|
91
|
+
}
|
92
|
+
|
93
|
+
memcached_return update_live_host_indices(memcached_st *ptr)
|
94
|
+
{
|
95
|
+
uint32_t host_index;
|
96
|
+
struct timeval now;
|
97
|
+
uint32_t i = 0;
|
98
|
+
memcached_server_st *list;
|
99
|
+
|
100
|
+
if (gettimeofday(&now, NULL) != 0)
|
101
|
+
{
|
102
|
+
ptr->cached_errno = errno;
|
103
|
+
return MEMCACHED_ERRNO;
|
104
|
+
}
|
105
|
+
|
106
|
+
if (ptr->live_host_indices == NULL) {
|
107
|
+
ptr->live_host_indices = (uint32_t *)ptr->call_malloc(ptr, sizeof(uint32_t) * ptr->number_of_hosts);
|
108
|
+
ptr->live_host_indices_size = ptr->number_of_live_hosts;
|
109
|
+
}
|
110
|
+
|
111
|
+
/* somehow we added some hosts. Shouldn't get here much, if at all. */
|
112
|
+
if (ptr->live_host_indices_size < ptr->number_of_hosts ) {
|
113
|
+
ptr->live_host_indices = (uint32_t *)ptr->call_realloc(ptr, ptr->live_host_indices, sizeof(uint32_t) * ptr->number_of_hosts);
|
114
|
+
ptr->live_host_indices_size = ptr->number_of_live_hosts;
|
115
|
+
}
|
116
|
+
|
117
|
+
if (ptr->live_host_indices == NULL)
|
118
|
+
return MEMCACHED_FAILURE;
|
119
|
+
|
120
|
+
list = ptr->hosts;
|
121
|
+
for (host_index= 0; host_index < ptr->number_of_hosts; ++host_index)
|
122
|
+
{
|
123
|
+
if (list[host_index].next_retry <= now.tv_sec) {
|
124
|
+
ptr->live_host_indices[i++] = host_index;
|
125
|
+
} else if (ptr->next_distribution_rebuild == 0 || list[host_index].next_retry < ptr->next_distribution_rebuild) {
|
126
|
+
ptr->next_distribution_rebuild= list[host_index].next_retry;
|
127
|
+
}
|
128
|
+
}
|
129
|
+
ptr->number_of_live_hosts = i;
|
130
|
+
return MEMCACHED_SUCCESS;
|
131
|
+
}
|
132
|
+
|
133
|
+
static int continuum_item_cmp(const void *t1, const void *t2)
|
134
|
+
{
|
135
|
+
memcached_continuum_item_st *ct1= (memcached_continuum_item_st *)t1;
|
136
|
+
memcached_continuum_item_st *ct2= (memcached_continuum_item_st *)t2;
|
137
|
+
|
138
|
+
/* Why 153? Hmmm... */
|
139
|
+
WATCHPOINT_ASSERT(ct1->value != 153);
|
140
|
+
if (ct1->value == ct2->value)
|
141
|
+
return 0;
|
142
|
+
else if (ct1->value > ct2->value)
|
143
|
+
return 1;
|
144
|
+
else
|
145
|
+
return -1;
|
146
|
+
}
|
147
|
+
|
148
|
+
memcached_return update_continuum(memcached_st *ptr)
|
149
|
+
{
|
150
|
+
uint32_t host_index;
|
151
|
+
uint32_t continuum_index= 0;
|
152
|
+
uint32_t value;
|
153
|
+
memcached_server_st *list;
|
154
|
+
uint32_t pointer_index;
|
155
|
+
uint32_t pointer_counter= 0;
|
156
|
+
uint32_t pointer_per_server= MEMCACHED_POINTS_PER_SERVER;
|
157
|
+
uint32_t pointer_per_hash= 1;
|
158
|
+
uint64_t total_weight= 0;
|
159
|
+
uint32_t is_ketama_weighted= 0;
|
160
|
+
uint32_t is_auto_ejecting= 0;
|
161
|
+
uint32_t points_per_server= 0;
|
162
|
+
uint32_t live_servers= 0;
|
163
|
+
struct timeval now;
|
164
|
+
|
165
|
+
if (gettimeofday(&now, NULL) != 0)
|
166
|
+
{
|
167
|
+
ptr->cached_errno = errno;
|
168
|
+
return MEMCACHED_ERRNO;
|
169
|
+
}
|
170
|
+
|
171
|
+
list = ptr->hosts;
|
172
|
+
|
173
|
+
/* count live servers (those without a retry delay set) */
|
174
|
+
is_auto_ejecting= memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS);
|
175
|
+
if (is_auto_ejecting)
|
176
|
+
{
|
177
|
+
live_servers= 0;
|
178
|
+
ptr->next_distribution_rebuild= 0;
|
179
|
+
for (host_index= 0; host_index < ptr->number_of_hosts; ++host_index)
|
180
|
+
{
|
181
|
+
if (list[host_index].next_retry <= now.tv_sec)
|
182
|
+
live_servers++;
|
183
|
+
else
|
184
|
+
{
|
185
|
+
if (ptr->next_distribution_rebuild == 0 || list[host_index].next_retry < ptr->next_distribution_rebuild)
|
186
|
+
ptr->next_distribution_rebuild= list[host_index].next_retry;
|
187
|
+
}
|
188
|
+
}
|
189
|
+
}
|
190
|
+
else
|
191
|
+
live_servers= ptr->number_of_hosts;
|
192
|
+
|
193
|
+
is_ketama_weighted= memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED);
|
194
|
+
points_per_server= (uint32_t) (is_ketama_weighted ? MEMCACHED_POINTS_PER_SERVER_KETAMA : MEMCACHED_POINTS_PER_SERVER);
|
195
|
+
|
196
|
+
if (live_servers == 0)
|
197
|
+
return MEMCACHED_SUCCESS;
|
198
|
+
|
199
|
+
if (live_servers > ptr->continuum_count)
|
200
|
+
{
|
201
|
+
memcached_continuum_item_st *new_ptr;
|
202
|
+
|
203
|
+
new_ptr= ptr->call_realloc(ptr, ptr->continuum,
|
204
|
+
sizeof(memcached_continuum_item_st) * (live_servers + MEMCACHED_CONTINUUM_ADDITION) * points_per_server);
|
205
|
+
|
206
|
+
if (new_ptr == 0)
|
207
|
+
return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
|
208
|
+
|
209
|
+
ptr->continuum= new_ptr;
|
210
|
+
ptr->continuum_count= live_servers + MEMCACHED_CONTINUUM_ADDITION;
|
211
|
+
}
|
212
|
+
|
213
|
+
if (is_ketama_weighted)
|
214
|
+
{
|
215
|
+
for (host_index = 0; host_index < ptr->number_of_hosts; ++host_index)
|
216
|
+
{
|
217
|
+
if (list[host_index].weight == 0)
|
218
|
+
{
|
219
|
+
list[host_index].weight = 1;
|
220
|
+
}
|
221
|
+
if (!is_auto_ejecting || list[host_index].next_retry <= now.tv_sec)
|
222
|
+
total_weight += list[host_index].weight;
|
223
|
+
}
|
224
|
+
}
|
225
|
+
|
226
|
+
for (host_index = 0; host_index < ptr->number_of_hosts; ++host_index)
|
227
|
+
{
|
228
|
+
if (is_auto_ejecting && list[host_index].next_retry > now.tv_sec)
|
229
|
+
continue;
|
230
|
+
|
231
|
+
if (is_ketama_weighted)
|
232
|
+
{
|
233
|
+
float pct = (float)list[host_index].weight / (float)total_weight;
|
234
|
+
pointer_per_server= (uint32_t) ((floorf((float) (pct * MEMCACHED_POINTS_PER_SERVER_KETAMA / 4 * (float)live_servers + 0.0000000001))) * 4);
|
235
|
+
pointer_per_hash= 4;
|
236
|
+
#ifdef DEBUG
|
237
|
+
printf("ketama_weighted:%s|%d|%llu|%u\n",
|
238
|
+
list[host_index].hostname,
|
239
|
+
list[host_index].port,
|
240
|
+
(unsigned long long)list[host_index].weight,
|
241
|
+
pointer_per_server);
|
242
|
+
#endif
|
243
|
+
}
|
244
|
+
for (pointer_index= 1;
|
245
|
+
pointer_index <= pointer_per_server / pointer_per_hash;
|
246
|
+
++pointer_index)
|
247
|
+
{
|
248
|
+
char sort_host[MEMCACHED_MAX_HOST_SORT_LENGTH]= "";
|
249
|
+
size_t sort_host_length;
|
250
|
+
|
251
|
+
if (list[host_index].port == MEMCACHED_DEFAULT_PORT)
|
252
|
+
{
|
253
|
+
sort_host_length= (size_t) snprintf(sort_host, MEMCACHED_MAX_HOST_SORT_LENGTH,
|
254
|
+
"%s-%d",
|
255
|
+
list[host_index].hostname,
|
256
|
+
pointer_index - 1);
|
257
|
+
|
258
|
+
}
|
259
|
+
else
|
260
|
+
{
|
261
|
+
sort_host_length= (size_t) snprintf(sort_host, MEMCACHED_MAX_HOST_SORT_LENGTH,
|
262
|
+
"%s:%d-%d",
|
263
|
+
list[host_index].hostname,
|
264
|
+
list[host_index].port, pointer_index - 1);
|
265
|
+
}
|
266
|
+
WATCHPOINT_ASSERT(sort_host_length);
|
267
|
+
|
268
|
+
if (is_ketama_weighted)
|
269
|
+
{
|
270
|
+
unsigned int i;
|
271
|
+
for (i = 0; i < pointer_per_hash; i++)
|
272
|
+
{
|
273
|
+
value= ketama_server_hash(sort_host, (uint32_t) sort_host_length, (int) i);
|
274
|
+
ptr->continuum[continuum_index].index= host_index;
|
275
|
+
ptr->continuum[continuum_index++].value= value;
|
276
|
+
}
|
277
|
+
}
|
278
|
+
else
|
279
|
+
{
|
280
|
+
value= memcached_generate_hash_value(sort_host, sort_host_length, ptr->hash_continuum);
|
281
|
+
ptr->continuum[continuum_index].index= host_index;
|
282
|
+
ptr->continuum[continuum_index++].value= value;
|
283
|
+
}
|
284
|
+
}
|
285
|
+
pointer_counter+= pointer_per_server;
|
286
|
+
}
|
287
|
+
|
288
|
+
WATCHPOINT_ASSERT(ptr);
|
289
|
+
WATCHPOINT_ASSERT(ptr->continuum);
|
290
|
+
WATCHPOINT_ASSERT(ptr->number_of_hosts * MEMCACHED_POINTS_PER_SERVER <= MEMCACHED_CONTINUUM_SIZE);
|
291
|
+
ptr->continuum_points_counter= pointer_counter;
|
292
|
+
qsort(ptr->continuum, ptr->continuum_points_counter, sizeof(memcached_continuum_item_st), continuum_item_cmp);
|
293
|
+
|
294
|
+
#ifdef DEBUG
|
295
|
+
for (pointer_index= 0; ptr->number_of_hosts && pointer_index < ((live_servers * MEMCACHED_POINTS_PER_SERVER) - 1); pointer_index++)
|
296
|
+
{
|
297
|
+
WATCHPOINT_ASSERT(ptr->continuum[pointer_index].value <= ptr->continuum[pointer_index + 1].value);
|
298
|
+
}
|
299
|
+
#endif
|
300
|
+
|
301
|
+
return MEMCACHED_SUCCESS;
|
302
|
+
}
|
303
|
+
|
304
|
+
|
305
|
+
memcached_return memcached_server_push(memcached_st *ptr, memcached_server_st *list)
|
306
|
+
{
|
307
|
+
unsigned int x;
|
308
|
+
uint16_t count;
|
309
|
+
memcached_server_st *new_host_list;
|
310
|
+
|
311
|
+
if (!list)
|
312
|
+
return MEMCACHED_SUCCESS;
|
313
|
+
|
314
|
+
count= list[0].count;
|
315
|
+
new_host_list= ptr->call_realloc(ptr, ptr->hosts,
|
316
|
+
sizeof(memcached_server_st) * (count + ptr->number_of_hosts));
|
317
|
+
|
318
|
+
if (!new_host_list)
|
319
|
+
return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
|
320
|
+
|
321
|
+
ptr->hosts= new_host_list;
|
322
|
+
|
323
|
+
for (x= 0; x < count; x++)
|
324
|
+
{
|
325
|
+
if ((ptr->flags & MEM_USE_UDP && list[x].type != MEMCACHED_CONNECTION_UDP)
|
326
|
+
|| ((list[x].type == MEMCACHED_CONNECTION_UDP)
|
327
|
+
&& ! (ptr->flags & MEM_USE_UDP)) )
|
328
|
+
return MEMCACHED_INVALID_HOST_PROTOCOL;
|
329
|
+
|
330
|
+
WATCHPOINT_ASSERT(list[x].hostname[0] != 0);
|
331
|
+
memcached_server_create(ptr, &ptr->hosts[ptr->number_of_hosts]);
|
332
|
+
/* TODO check return type */
|
333
|
+
(void)memcached_server_create_with(ptr, &ptr->hosts[ptr->number_of_hosts], list[x].hostname,
|
334
|
+
list[x].port, list[x].weight, list[x].type);
|
335
|
+
ptr->number_of_hosts++;
|
336
|
+
}
|
337
|
+
ptr->hosts[0].count= (uint16_t) ptr->number_of_hosts;
|
338
|
+
|
339
|
+
return run_distribution(ptr);
|
340
|
+
}
|
341
|
+
|
342
|
+
memcached_return memcached_server_add_unix_socket(memcached_st *ptr,
|
343
|
+
const char *filename)
|
344
|
+
{
|
345
|
+
return memcached_server_add_unix_socket_with_weight(ptr, filename, 0);
|
346
|
+
}
|
347
|
+
|
348
|
+
memcached_return memcached_server_add_unix_socket_with_weight(memcached_st *ptr,
|
349
|
+
const char *filename,
|
350
|
+
uint32_t weight)
|
351
|
+
{
|
352
|
+
if (!filename)
|
353
|
+
return MEMCACHED_FAILURE;
|
354
|
+
|
355
|
+
return server_add(ptr, filename, 0, weight, MEMCACHED_CONNECTION_UNIX_SOCKET);
|
356
|
+
}
|
357
|
+
|
358
|
+
memcached_return memcached_server_add_udp(memcached_st *ptr,
|
359
|
+
const char *hostname,
|
360
|
+
unsigned int port)
|
361
|
+
{
|
362
|
+
return memcached_server_add_udp_with_weight(ptr, hostname, port, 0);
|
363
|
+
}
|
364
|
+
|
365
|
+
memcached_return memcached_server_add_udp_with_weight(memcached_st *ptr,
|
366
|
+
const char *hostname,
|
367
|
+
unsigned int port,
|
368
|
+
uint32_t weight)
|
369
|
+
{
|
370
|
+
if (!port)
|
371
|
+
port= MEMCACHED_DEFAULT_PORT;
|
372
|
+
|
373
|
+
if (!hostname)
|
374
|
+
hostname= "localhost";
|
375
|
+
|
376
|
+
return server_add(ptr, hostname, port, weight, MEMCACHED_CONNECTION_UDP);
|
377
|
+
}
|
378
|
+
|
379
|
+
memcached_return memcached_server_add(memcached_st *ptr,
|
380
|
+
const char *hostname,
|
381
|
+
unsigned int port)
|
382
|
+
{
|
383
|
+
return memcached_server_add_with_weight(ptr, hostname, port, 0);
|
384
|
+
}
|
385
|
+
|
386
|
+
memcached_return memcached_server_add_with_weight(memcached_st *ptr,
|
387
|
+
const char *hostname,
|
388
|
+
unsigned int port,
|
389
|
+
uint32_t weight)
|
390
|
+
{
|
391
|
+
if (!port)
|
392
|
+
port= MEMCACHED_DEFAULT_PORT;
|
393
|
+
|
394
|
+
if (!hostname)
|
395
|
+
hostname= "localhost";
|
396
|
+
|
397
|
+
return server_add(ptr, hostname, port, weight, MEMCACHED_CONNECTION_TCP);
|
398
|
+
}
|
399
|
+
|
400
|
+
static memcached_return server_add(memcached_st *ptr, const char *hostname,
|
401
|
+
unsigned int port,
|
402
|
+
uint32_t weight,
|
403
|
+
memcached_connection type)
|
404
|
+
{
|
405
|
+
memcached_server_st *new_host_list;
|
406
|
+
|
407
|
+
if ( (ptr->flags & MEM_USE_UDP && type != MEMCACHED_CONNECTION_UDP)
|
408
|
+
|| ( (type == MEMCACHED_CONNECTION_UDP) && !(ptr->flags & MEM_USE_UDP) ) )
|
409
|
+
return MEMCACHED_INVALID_HOST_PROTOCOL;
|
410
|
+
|
411
|
+
new_host_list= ptr->call_realloc(ptr, ptr->hosts,
|
412
|
+
sizeof(memcached_server_st) * (ptr->number_of_hosts+1));
|
413
|
+
|
414
|
+
if (new_host_list == NULL)
|
415
|
+
return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
|
416
|
+
|
417
|
+
ptr->hosts= new_host_list;
|
418
|
+
|
419
|
+
/* TODO: Check return type */
|
420
|
+
(void)memcached_server_create_with(ptr, &ptr->hosts[ptr->number_of_hosts], hostname, port, weight, type);
|
421
|
+
ptr->number_of_hosts++;
|
422
|
+
ptr->hosts[0].count= (uint16_t) ptr->number_of_hosts;
|
423
|
+
|
424
|
+
return run_distribution(ptr);
|
425
|
+
}
|
426
|
+
|
427
|
+
memcached_return memcached_server_remove(memcached_server_st *st_ptr)
|
428
|
+
{
|
429
|
+
uint32_t x, host_index;
|
430
|
+
memcached_st *ptr= st_ptr->root;
|
431
|
+
memcached_server_st *list= ptr->hosts;
|
432
|
+
|
433
|
+
for (x= 0, host_index= 0; x < ptr->number_of_hosts; x++)
|
434
|
+
{
|
435
|
+
if (strncmp(list[x].hostname, st_ptr->hostname, MEMCACHED_MAX_HOST_LENGTH) != 0 || list[x].port != st_ptr->port)
|
436
|
+
{
|
437
|
+
if (host_index != x)
|
438
|
+
memcpy(list+host_index, list+x, sizeof(memcached_server_st));
|
439
|
+
host_index++;
|
440
|
+
}
|
441
|
+
}
|
442
|
+
ptr->number_of_hosts= host_index;
|
443
|
+
|
444
|
+
if (st_ptr->address_info)
|
445
|
+
{
|
446
|
+
freeaddrinfo(st_ptr->address_info);
|
447
|
+
st_ptr->address_info= NULL;
|
448
|
+
}
|
449
|
+
run_distribution(ptr);
|
450
|
+
|
451
|
+
return MEMCACHED_SUCCESS;
|
452
|
+
}
|
453
|
+
|
454
|
+
memcached_server_st *memcached_server_list_append(memcached_server_st *ptr,
|
455
|
+
const char *hostname, unsigned int port,
|
456
|
+
memcached_return *error)
|
457
|
+
{
|
458
|
+
return memcached_server_list_append_with_weight(ptr, hostname, port, 0, error);
|
459
|
+
}
|
460
|
+
|
461
|
+
memcached_server_st *memcached_server_list_append_with_weight(memcached_server_st *ptr,
|
462
|
+
const char *hostname, unsigned int port,
|
463
|
+
uint32_t weight,
|
464
|
+
memcached_return *error)
|
465
|
+
{
|
466
|
+
unsigned int count;
|
467
|
+
memcached_server_st *new_host_list;
|
468
|
+
|
469
|
+
if (hostname == NULL || error == NULL)
|
470
|
+
return NULL;
|
471
|
+
|
472
|
+
if (!port)
|
473
|
+
port= MEMCACHED_DEFAULT_PORT;
|
474
|
+
|
475
|
+
/* Increment count for hosts */
|
476
|
+
count= 1;
|
477
|
+
if (ptr != NULL)
|
478
|
+
{
|
479
|
+
count+= ptr[0].count;
|
480
|
+
}
|
481
|
+
|
482
|
+
new_host_list= (memcached_server_st *)realloc(ptr, sizeof(memcached_server_st) * count);
|
483
|
+
if (!new_host_list)
|
484
|
+
{
|
485
|
+
*error= MEMCACHED_MEMORY_ALLOCATION_FAILURE;
|
486
|
+
return NULL;
|
487
|
+
}
|
488
|
+
|
489
|
+
/* TODO: Check return type */
|
490
|
+
memcached_server_create_with(NULL, &new_host_list[count-1], hostname, port, weight, MEMCACHED_CONNECTION_TCP);
|
491
|
+
|
492
|
+
/* Backwards compatibility hack */
|
493
|
+
new_host_list[0].count= (uint16_t) count;
|
494
|
+
|
495
|
+
*error= MEMCACHED_SUCCESS;
|
496
|
+
return new_host_list;
|
497
|
+
}
|
498
|
+
|
499
|
+
unsigned int memcached_server_list_count(memcached_server_st *ptr)
|
500
|
+
{
|
501
|
+
if (ptr == NULL)
|
502
|
+
return 0;
|
503
|
+
|
504
|
+
return ptr[0].count;
|
505
|
+
}
|
506
|
+
|
507
|
+
void memcached_server_list_free(memcached_server_st *ptr)
|
508
|
+
{
|
509
|
+
server_list_free(NULL, ptr);
|
510
|
+
}
|