projects
/
awesomized
/
libmemcached
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
Updated for custom hash functions/setting functions.
[awesomized/libmemcached]
/
libmemcached
/
get.c
diff --git
a/libmemcached/get.c
b/libmemcached/get.c
index 30682427c8d71700421e95863a7fbb442e59156b..a7d0ebc6fe457c7f9c153a514cb00fd04df5c811 100644
(file)
--- a/
libmemcached/get.c
+++ b/
libmemcached/get.c
@@
-82,9
+82,10
@@
char *memcached_get_by_key(memcached_st *ptr,
memcached_behavior_set(ptr, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1);
rc= memcached_set(ptr, key, key_length,
memcached_behavior_set(ptr, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1);
rc= memcached_set(ptr, key, key_length,
- memcached_result_value(&ptr->result),
- memcached_result_length(&ptr->result),
- 0, memcached_result_flags(&ptr->result));
+ (memcached_result_value(&ptr->result)),
+ (memcached_result_length(&ptr->result)),
+ 0,
+ (memcached_result_flags(&ptr->result)));
if (rc == MEMCACHED_BUFFERED && latch == 0)
memcached_behavior_set(ptr, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 0);
if (rc == MEMCACHED_BUFFERED && latch == 0)
memcached_behavior_set(ptr, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 0);
@@
-92,9
+93,10
@@
char *memcached_get_by_key(memcached_st *ptr,
else
{
rc= memcached_set(ptr, key, key_length,
else
{
rc= memcached_set(ptr, key, key_length,
- memcached_result_value(&ptr->result),
- memcached_result_length(&ptr->result),
- 0, memcached_result_flags(&ptr->result));
+ (memcached_result_value(&ptr->result)),
+ (memcached_result_length(&ptr->result)),
+ 0,
+ (memcached_result_flags(&ptr->result)));
}
if (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED)
}
if (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED)
@@
-127,7
+129,7
@@
memcached_return_t memcached_mget(memcached_st *ptr,
}
static memcached_return_t binary_mget_by_key(memcached_st *ptr,
}
static memcached_return_t binary_mget_by_key(memcached_st *ptr,
- u
nsigned in
t master_server_key,
+ u
int32_
t master_server_key,
bool is_master_key_set,
const char * const *keys,
const size_t *key_length,
bool is_master_key_set,
const char * const *keys,
const size_t *key_length,
@@
-153,12
+155,11
@@
static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr,
return MEMCACHED_NOT_SUPPORTED;
LIBMEMCACHED_MEMCACHED_MGET_START();
return MEMCACHED_NOT_SUPPORTED;
LIBMEMCACHED_MEMCACHED_MGET_START();
- ptr->cursor_server= 0;
if (number_of_keys == 0)
return MEMCACHED_NOTFOUND;
if (number_of_keys == 0)
return MEMCACHED_NOTFOUND;
- if (
ptr->number_of_hosts
== 0)
+ if (
memcached_server_count(ptr)
== 0)
return MEMCACHED_NO_SERVERS;
if (ptr->flags.verify_key && (memcached_key_test(keys, key_length, number_of_keys) == MEMCACHED_BAD_KEY_PROVIDED))
return MEMCACHED_NO_SERVERS;
if (ptr->flags.verify_key && (memcached_key_test(keys, key_length, number_of_keys) == MEMCACHED_BAD_KEY_PROVIDED))
@@
-178,17
+179,20
@@
static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr,
It might be optimum to bounce the connection if count > some number.
*/
It might be optimum to bounce the connection if count > some number.
*/
- for (x= 0; x <
ptr->number_of_hosts
; x++)
+ for (x= 0; x <
memcached_server_count(ptr)
; x++)
{
{
- if (memcached_server_response_count(&ptr->hosts[x]))
+ memcached_server_instance_st *instance=
+ memcached_server_instance_fetch(ptr, x);
+
+ if (memcached_server_response_count(instance))
{
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
if (ptr->flags.no_block)
{
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
if (ptr->flags.no_block)
- (void)memcached_io_write(
&ptr->hosts[x]
, NULL, 0, 1);
+ (void)memcached_io_write(
instance
, NULL, 0, 1);
- while(memcached_server_response_count(
&ptr->hosts[x]
))
- (void)memcached_response(
&ptr->hosts[x]
, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, &ptr->result);
+ while(memcached_server_response_count(
instance
))
+ (void)memcached_response(
instance
, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, &ptr->result);
}
}
}
}
@@
-208,51
+212,58
@@
static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr,
*/
for (x= 0; x < number_of_keys; x++)
{
*/
for (x= 0; x < number_of_keys; x++)
{
- unsigned int server_key;
+ memcached_server_instance_st *instance;
+ uint32_t server_key;
if (is_master_key_set)
if (is_master_key_set)
+ {
server_key= master_server_key;
server_key= master_server_key;
+ }
else
else
+ {
server_key= memcached_generate_hash(ptr, keys[x], key_length[x]);
server_key= memcached_generate_hash(ptr, keys[x], key_length[x]);
+ }
- if (memcached_server_response_count(&ptr->hosts[server_key]) == 0)
+ instance= memcached_server_instance_fetch(ptr, server_key);
+
+ if (memcached_server_response_count(instance) == 0)
{
{
- rc= memcached_connect(
&ptr->hosts[server_key]
);
+ rc= memcached_connect(
instance
);
if (rc != MEMCACHED_SUCCESS)
continue;
if (rc != MEMCACHED_SUCCESS)
continue;
- if ((memcached_io_write(
&ptr->hosts[server_key]
, get_command, get_command_length, 0)) == -1)
+ if ((memcached_io_write(
instance
, get_command, get_command_length, 0)) == -1)
{
rc= MEMCACHED_SOME_ERRORS;
continue;
}
{
rc= MEMCACHED_SOME_ERRORS;
continue;
}
- WATCHPOINT_ASSERT(
ptr->hosts[server_key].
cursor_active == 0);
- memcached_server_response_increment(
&ptr->hosts[server_key]
);
- WATCHPOINT_ASSERT(
ptr->hosts[server_key].
cursor_active == 1);
+ WATCHPOINT_ASSERT(
instance->
cursor_active == 0);
+ memcached_server_response_increment(
instance
);
+ WATCHPOINT_ASSERT(
instance->
cursor_active == 1);
}
/* Only called when we have a prefix key */
}
/* Only called when we have a prefix key */
- if (ptr->prefix_key
[0] != 0
)
+ if (ptr->prefix_key
_length
)
{
{
- if ((memcached_io_write(
&ptr->hosts[server_key]
, ptr->prefix_key, ptr->prefix_key_length, 0)) == -1)
+ if ((memcached_io_write(
instance
, ptr->prefix_key, ptr->prefix_key_length, 0)) == -1)
{
{
- memcached_server_response_reset(
&ptr->hosts[server_key]
);
+ memcached_server_response_reset(
instance
);
rc= MEMCACHED_SOME_ERRORS;
continue;
}
}
rc= MEMCACHED_SOME_ERRORS;
continue;
}
}
- if ((memcached_io_write(
&ptr->hosts[server_key]
, keys[x], key_length[x], 0)) == -1)
+ if ((memcached_io_write(
instance
, keys[x], key_length[x], 0)) == -1)
{
{
- memcached_server_response_reset(
&ptr->hosts[server_key]
);
+ memcached_server_response_reset(
instance
);
rc= MEMCACHED_SOME_ERRORS;
continue;
}
rc= MEMCACHED_SOME_ERRORS;
continue;
}
- if ((memcached_io_write(
&ptr->hosts[server_key]
, " ", 1, 0)) == -1)
+ if ((memcached_io_write(
instance
, " ", 1, 0)) == -1)
{
{
- memcached_server_response_reset(
&ptr->hosts[server_key]
);
+ memcached_server_response_reset(
instance
);
rc= MEMCACHED_SOME_ERRORS;
continue;
}
rc= MEMCACHED_SOME_ERRORS;
continue;
}
@@
-261,12
+272,15
@@
static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr,
/*
Should we muddle on if some servers are dead?
*/
/*
Should we muddle on if some servers are dead?
*/
- for (x= 0; x <
ptr->number_of_hosts
; x++)
+ for (x= 0; x <
memcached_server_count(ptr)
; x++)
{
{
- if (memcached_server_response_count(&ptr->hosts[x]))
+ memcached_server_instance_st *instance=
+ memcached_server_instance_fetch(ptr, x);
+
+ if (memcached_server_response_count(instance))
{
/* We need to do something about non-connnected hosts in the future */
{
/* We need to do something about non-connnected hosts in the future */
- if ((memcached_io_write(
&ptr->hosts[x]
, "\r\n", 2, 1)) == -1)
+ if ((memcached_io_write(
instance
, "\r\n", 2, 1)) == -1)
{
rc= MEMCACHED_SOME_ERRORS;
}
{
rc= MEMCACHED_SOME_ERRORS;
}
@@
-330,7
+344,7
@@
memcached_return_t memcached_mget_execute_by_key(memcached_st *ptr,
}
static memcached_return_t simple_binary_mget(memcached_st *ptr,
}
static memcached_return_t simple_binary_mget(memcached_st *ptr,
- u
nsigned in
t master_server_key,
+ u
int32_
t master_server_key,
bool is_master_key_set,
const char * const *keys,
const size_t *key_length,
bool is_master_key_set,
const char * const *keys,
const size_t *key_length,
@@
-347,16
+361,23
@@
static memcached_return_t simple_binary_mget(memcached_st *ptr,
*/
for (x= 0; x < number_of_keys; x++)
{
*/
for (x= 0; x < number_of_keys; x++)
{
- unsigned int server_key;
+ uint32_t server_key;
+ memcached_server_instance_st *instance;
if (is_master_key_set)
if (is_master_key_set)
+ {
server_key= master_server_key;
server_key= master_server_key;
+ }
else
else
+ {
server_key= memcached_generate_hash(ptr, keys[x], key_length[x]);
server_key= memcached_generate_hash(ptr, keys[x], key_length[x]);
+ }
+
+ instance= memcached_server_instance_fetch(ptr, server_key);
- if (memcached_server_response_count(
&ptr->hosts[server_key]
) == 0)
+ if (memcached_server_response_count(
instance
) == 0)
{
{
- rc= memcached_connect(
&ptr->hosts[server_key]
);
+ rc= memcached_connect(
instance
);
if (rc != MEMCACHED_SUCCESS)
continue;
}
if (rc != MEMCACHED_SUCCESS)
continue;
}
@@
-374,7
+395,10
@@
static memcached_return_t simple_binary_mget(memcached_st *ptr,
unlikely (vk != MEMCACHED_SUCCESS)
{
if (x > 0)
unlikely (vk != MEMCACHED_SUCCESS)
{
if (x > 0)
- memcached_io_reset(&ptr->hosts[server_key]);
+ {
+ memcached_io_reset(instance);
+ }
+
return vk;
}
return vk;
}
@@
-382,19
+406,19
@@
static memcached_return_t simple_binary_mget(memcached_st *ptr,
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
request.message.header.request.bodylen= htonl((uint32_t) key_length[x]);
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
request.message.header.request.bodylen= htonl((uint32_t) key_length[x]);
- if ((memcached_io_write(
&ptr->hosts[server_key]
, request.bytes,
+ if ((memcached_io_write(
instance
, request.bytes,
sizeof(request.bytes), 0) == -1) ||
sizeof(request.bytes), 0) == -1) ||
- (memcached_io_write(
&ptr->hosts[server_key]
, keys[x],
+ (memcached_io_write(
instance
, keys[x],
key_length[x], (char) flush) == -1))
{
key_length[x], (char) flush) == -1))
{
- memcached_server_response_reset(
&ptr->hosts[server_key]
);
+ memcached_server_response_reset(
instance
);
rc= MEMCACHED_SOME_ERRORS;
continue;
}
/* We just want one pending response per server */
rc= MEMCACHED_SOME_ERRORS;
continue;
}
/* We just want one pending response per server */
- memcached_server_response_reset(
&ptr->hosts[server_key]
);
- memcached_server_response_increment(
&ptr->hosts[server_key]
);
+ memcached_server_response_reset(
instance
);
+ memcached_server_response_increment(
instance
);
if ((x > 0 && x == ptr->io_key_prefetch) &&
memcached_flush_buffers(ptr) != MEMCACHED_SUCCESS)
rc= MEMCACHED_SOME_ERRORS;
if ((x > 0 && x == ptr->io_key_prefetch) &&
memcached_flush_buffers(ptr) != MEMCACHED_SUCCESS)
rc= MEMCACHED_SOME_ERRORS;
@@
-410,24
+434,29
@@
static memcached_return_t simple_binary_mget(memcached_st *ptr,
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_NOOP;
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_NOOP;
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
- for (x= 0; x < ptr->number_of_hosts; x++)
- if (memcached_server_response_count(&ptr->hosts[x]))
+ for (x= 0; x < memcached_server_count(ptr); x++)
+ {
+ memcached_server_instance_st *instance=
+ memcached_server_instance_fetch(ptr, x);
+
+ if (memcached_server_response_count(instance))
{
{
- if (memcached_io_write(
&ptr->hosts[x]
, NULL, 0, 1) == -1)
+ if (memcached_io_write(
instance
, NULL, 0, 1) == -1)
{
{
- memcached_server_response_reset(
&ptr->hosts[x]
);
- memcached_io_reset(
&ptr->hosts[x]
);
+ memcached_server_response_reset(
instance
);
+ memcached_io_reset(
instance
);
rc= MEMCACHED_SOME_ERRORS;
}
rc= MEMCACHED_SOME_ERRORS;
}
- if (memcached_io_write(
&ptr->hosts[x]
, request.bytes,
+ if (memcached_io_write(
instance
, request.bytes,
sizeof(request.bytes), 1) == -1)
{
sizeof(request.bytes), 1) == -1)
{
- memcached_server_response_reset(
&ptr->hosts[x]
);
- memcached_io_reset(
&ptr->hosts[x]
);
+ memcached_server_response_reset(
instance
);
+ memcached_io_reset(
instance
);
rc= MEMCACHED_SOME_ERRORS;
}
}
rc= MEMCACHED_SOME_ERRORS;
}
}
+ }
}
}
@@
-455,7
+484,9
@@
static memcached_return_t replication_binary_mget(memcached_st *ptr,
for (x= 0; x < number_of_keys; ++x)
{
for (x= 0; x < number_of_keys; ++x)
{
- if (hash[x] == ptr->number_of_hosts)
+ memcached_server_instance_st *instance;
+
+ if (hash[x] == memcached_server_count(ptr))
continue; /* Already successfully sent */
uint32_t server= hash[x] + replica;
continue; /* Already successfully sent */
uint32_t server= hash[x] + replica;
@@
-464,18
+495,20
@@
static memcached_return_t replication_binary_mget(memcached_st *ptr,
if (randomize_read && ((server + start) <= (hash[x] + ptr->number_of_replicas)))
server += start;
if (randomize_read && ((server + start) <= (hash[x] + ptr->number_of_replicas)))
server += start;
- while (server >=
ptr->number_of_hosts
)
- server -=
ptr->number_of_hosts
;
+ while (server >=
memcached_server_count(ptr)
)
+ server -=
memcached_server_count(ptr)
;
if (dead_servers[server])
continue;
if (dead_servers[server])
continue;
- if (memcached_server_response_count(&ptr->hosts[server]) == 0)
+ instance= memcached_server_instance_fetch(ptr, server);
+
+ if (memcached_server_response_count(instance) == 0)
{
{
- rc= memcached_connect(
&ptr->hosts[server]
);
+ rc= memcached_connect(
instance
);
if (rc != MEMCACHED_SUCCESS)
{
if (rc != MEMCACHED_SUCCESS)
{
- memcached_io_reset(
&ptr->hosts[server]
);
+ memcached_io_reset(
instance
);
dead_servers[server]= true;
success= false;
continue;
dead_servers[server]= true;
success= false;
continue;
@@
-502,19
+535,19
@@
static memcached_return_t replication_binary_mget(memcached_st *ptr,
* that we might have processed some of the responses etc. For now,
* just make sure we work _correctly_
*/
* that we might have processed some of the responses etc. For now,
* just make sure we work _correctly_
*/
- if ((memcached_io_write(
&ptr->hosts[server]
, request.bytes,
+ if ((memcached_io_write(
instance
, request.bytes,
sizeof(request.bytes), 0) == -1) ||
sizeof(request.bytes), 0) == -1) ||
- (memcached_io_write(
&ptr->hosts[server]
, keys[x],
+ (memcached_io_write(
instance
, keys[x],
key_length[x], 1) == -1))
{
key_length[x], 1) == -1))
{
- memcached_io_reset(
&ptr->hosts[server]
);
+ memcached_io_reset(
instance
);
dead_servers[server]= true;
success= false;
continue;
}
dead_servers[server]= true;
success= false;
continue;
}
- memcached_server_response_increment(
&ptr->hosts[server]
);
- hash[x]=
ptr->number_of_hosts
;
+ memcached_server_response_increment(
instance
);
+ hash[x]=
memcached_server_count(ptr)
;
}
if (success)
}
if (success)
@@
-525,7
+558,7
@@
static memcached_return_t replication_binary_mget(memcached_st *ptr,
}
static memcached_return_t binary_mget_by_key(memcached_st *ptr,
}
static memcached_return_t binary_mget_by_key(memcached_st *ptr,
- u
nsigned in
t master_server_key,
+ u
int32_
t master_server_key,
bool is_master_key_set,
const char * const *keys,
const size_t *key_length,
bool is_master_key_set,
const char * const *keys,
const size_t *key_length,
@@
-544,13
+577,13
@@
static memcached_return_t binary_mget_by_key(memcached_st *ptr,
uint32_t* hash;
bool* dead_servers;
uint32_t* hash;
bool* dead_servers;
- hash=
ptr->call
_malloc(ptr, sizeof(uint32_t) * number_of_keys);
- dead_servers=
ptr->call_calloc(ptr, ptr->number_of_hosts
, sizeof(bool));
+ hash=
libmemcached
_malloc(ptr, sizeof(uint32_t) * number_of_keys);
+ dead_servers=
libmemcached_calloc(ptr, memcached_server_count(ptr)
, sizeof(bool));
if (hash == NULL || dead_servers == NULL)
{
if (hash == NULL || dead_servers == NULL)
{
-
ptr->call
_free(ptr, hash);
-
ptr->call
_free(ptr, dead_servers);
+
libmemcached
_free(ptr, hash);
+
libmemcached
_free(ptr, dead_servers);
return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
}
return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
}
@@
-564,8
+597,8
@@
static memcached_return_t binary_mget_by_key(memcached_st *ptr,
rc= replication_binary_mget(ptr, hash, dead_servers, keys,
key_length, number_of_keys);
rc= replication_binary_mget(ptr, hash, dead_servers, keys,
key_length, number_of_keys);
-
ptr->call
_free(ptr, hash);
-
ptr->call
_free(ptr, dead_servers);
+
libmemcached
_free(ptr, hash);
+
libmemcached
_free(ptr, dead_servers);
return MEMCACHED_SUCCESS;
}
return MEMCACHED_SUCCESS;
}