size_t number_of_keys,
bool mget_mode)
{
- memcached_return_t rc= MEMCACHED_NOTFOUND;
+ bool failures_occured_in_sending= false;
const char *get_command= "get ";
uint8_t get_command_length= 4;
unsigned int master_server_key= (unsigned int)-1; /* 0 is a valid server id! */
bool is_master_key_set= false;
+ memcached_return_t rc;
+ if ((rc= initialize_query(ptr)) != MEMCACHED_SUCCESS)
+ {
+ return rc;
+ }
+
unlikely (ptr->flags.use_udp)
return MEMCACHED_NOT_SUPPORTED;
if (number_of_keys == 0)
return MEMCACHED_NOTFOUND;
- 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_BAD_KEY_PROVIDED;
If a server fails we warn about errors and start all over with sending keys
to the server.
*/
+ WATCHPOINT_ASSERT(rc == MEMCACHED_SUCCESS);
+ size_t hosts_connected= 0;
for (uint32_t x= 0; x < number_of_keys; x++)
{
memcached_server_write_instance_st instance;
struct libmemcached_io_vector_st vector[]=
{
{ .length= get_command_length, .buffer= get_command },
- { .length= ptr->prefix_key_length, .buffer= ptr->prefix_key },
+ { .length= memcached_array_size(ptr->prefix_key), .buffer= memcached_array_string(ptr->prefix_key) },
{ .length= key_length[x], .buffer= keys[x] },
{ .length= 1, .buffer= " " }
};
rc= memcached_connect(instance);
if (rc != MEMCACHED_SUCCESS)
+ {
continue;
+ }
+ hosts_connected++;
if ((memcached_io_writev(instance, vector, 4, false)) == -1)
{
- fprintf(stderr, "%s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout);
- rc= MEMCACHED_SOME_ERRORS;
+ failures_occured_in_sending= true;
continue;
}
WATCHPOINT_ASSERT(instance->cursor_active == 0);
if ((memcached_io_writev(instance, (vector + 1), 3, false)) == -1)
{
memcached_server_response_reset(instance);
- fprintf(stderr, "%s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout);
- rc= MEMCACHED_SOME_ERRORS;
+ failures_occured_in_sending= true;
continue;
}
}
}
+ if (hosts_connected == 0)
+ {
+ LIBMEMCACHED_MEMCACHED_MGET_END();
+
+ if (rc != MEMCACHED_SUCCESS)
+ return rc;
+
+ return MEMCACHED_NO_SERVERS;
+ }
+
+
/*
Should we muddle on if some servers are dead?
*/
+ bool success_happened= false;
for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
{
memcached_server_write_instance_st instance=
/* We need to do something about non-connnected hosts in the future */
if ((memcached_io_write(instance, "\r\n", 2, true)) == -1)
{
- fprintf(stderr, "%s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout);
- rc= MEMCACHED_SOME_ERRORS;
+ failures_occured_in_sending= true;
+ }
+ else
+ {
+ success_happened= true;
}
}
}
LIBMEMCACHED_MEMCACHED_MGET_END();
- return rc;
+
+ if (failures_occured_in_sending && success_happened)
+ return MEMCACHED_SOME_ERRORS;
+
+ if (success_happened)
+ return MEMCACHED_SUCCESS;
+
+ return MEMCACHED_FAILURE;
}
memcached_return_t memcached_mget_by_key(memcached_st *ptr,
{
memcached_return_t rc= MEMCACHED_NOTFOUND;
- int flush= number_of_keys == 1;
+ bool flush= (number_of_keys == 1);
/*
If a server fails we warn about errors and start all over with sending keys
return vk;
}
- request.message.header.request.keylen= htons((uint16_t)(key_length[x] + ptr->prefix_key_length));
+ request.message.header.request.keylen= htons((uint16_t)(key_length[x] + memcached_array_size(ptr->prefix_key)));
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
- request.message.header.request.bodylen= htonl((uint32_t)( key_length[x] + ptr->prefix_key_length));
+ request.message.header.request.bodylen= htonl((uint32_t)( key_length[x] + memcached_array_size(ptr->prefix_key)));
struct libmemcached_io_vector_st vector[]=
{
{ .length= sizeof(request.bytes), .buffer= request.bytes },
- { .length= ptr->prefix_key_length, .buffer= ptr->prefix_key },
+ { .length= memcached_array_size(ptr->prefix_key), .buffer= memcached_array_string(ptr->prefix_key) },
{ .length= key_length[x], .buffer= keys[x] }
};
if (memcached_io_writev(instance, vector, 3, flush) == -1)
{
memcached_server_response_reset(instance);
- fprintf(stderr, "%s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout);
rc= MEMCACHED_SOME_ERRORS;
continue;
}
memcached_server_response_increment(instance);
if ((x > 0 && x == ptr->io_key_prefetch) && memcached_flush_buffers(ptr) != MEMCACHED_SUCCESS)
{
- fprintf(stderr, "%s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout);
rc= MEMCACHED_SOME_ERRORS;
}
}
{
memcached_server_response_reset(instance);
memcached_io_reset(instance);
- fprintf(stderr, "%s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout);
rc= MEMCACHED_SOME_ERRORS;
}
{
memcached_server_response_reset(instance);
memcached_io_reset(instance);
- fprintf(stderr, "%s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout);
rc= MEMCACHED_SOME_ERRORS;
}
}
.message.header.request= {
.magic= PROTOCOL_BINARY_REQ,
.opcode= PROTOCOL_BINARY_CMD_GETK,
- .keylen= htons((uint16_t)(key_length[x] + ptr->prefix_key_length)),
+ .keylen= htons((uint16_t)(key_length[x] + memcached_array_size(ptr->prefix_key))),
.datatype= PROTOCOL_BINARY_RAW_BYTES,
- .bodylen= htonl((uint32_t)(key_length[x] + ptr->prefix_key_length))
+ .bodylen= htonl((uint32_t)(key_length[x] + memcached_array_size(ptr->prefix_key)))
}
};
struct libmemcached_io_vector_st vector[]=
{
{ .length= sizeof(request.bytes), .buffer= request.bytes },
- { .length= ptr->prefix_key_length, .buffer= ptr->prefix_key },
+ { .length= memcached_array_size(ptr->prefix_key), .buffer= memcached_array_string(ptr->prefix_key) },
{ .length= key_length[x], .buffer= keys[x] }
};