Skip to content

Commit e08d4cf

Browse files
see #238, data import broken (#240)
* see #238, data import broken The PR includes some refactoring and cleanup around the following: object_generator - generate_key(), a new function that generates a key and stores it inside internal buffer (no need for a buffer at client level) import_object_generator - Align it to object_generator APIs of getting key/value/expire - read_next_item - new function for reading the next item before creating SET command - read_next_key - new function for reading (pointing) to the next key before creating the GET command data_object - removed. We were already getting key/value/expire separately. Now that data-import and verify-data also moved to do it like that, we could remove it completely. verify_client - unify the craate_request with its base class, and derive the create_x_request functions. * Included data import test cases * Cluster mode cannot be specified when importing * Fixed merge of tests from master --------- Co-authored-by: YaacovHazan <[email protected]> Co-authored-by: filipecosta90 <[email protected]>
1 parent a5e6f19 commit e08d4cf

13 files changed

+189
-210
lines changed

client.cpp

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,14 @@ get_key_response client::get_key_for_conn(unsigned int command_index, unsigned i
256256
iter = obj_iter_type(m_config, command_index);
257257

258258
*key_index = m_obj_gen->get_key_index(iter);
259-
m_key_len = snprintf(m_key_buffer, sizeof(m_key_buffer)-1, "%s%llu", m_obj_gen->get_key_prefix(), *key_index);
259+
260+
if (!m_config->data_import || m_config->generate_keys) {
261+
m_obj_gen->generate_key(*key_index);
262+
} else {
263+
/* For SET command we already read a completes item (see create_set_request()) */
264+
if (command_index == GET_CMD_IDX)
265+
dynamic_cast<import_object_generator*>(m_obj_gen)->read_next_key(*key_index);
266+
}
260267

261268
return available_for_conn;
262269
}
@@ -277,7 +284,7 @@ bool client::create_arbitrary_request(unsigned int command_index, struct timeval
277284
get_key_response res = get_key_for_conn(command_index, conn_id, &key_index);
278285
/* If key not available for this connection, we have a bug of sending partial request */
279286
assert(res == available_for_conn);
280-
cmd_size += m_connections[conn_id]->send_arbitrary_command(arg, m_key_buffer, m_key_len);
287+
cmd_size += m_connections[conn_id]->send_arbitrary_command(arg, m_obj_gen->get_key(), m_obj_gen->get_key_len());
281288
} else if (arg->type == data_type) {
282289
unsigned int value_len;
283290
const char *value = m_obj_gen->get_value(0, &value_len);
@@ -313,7 +320,7 @@ bool client::create_set_request(struct timeval& timestamp, unsigned int conn_id)
313320
unsigned int value_len;
314321
const char *value = m_obj_gen->get_value(key_index, &value_len);
315322

316-
m_connections[conn_id]->send_set_command(&timestamp, m_key_buffer, m_key_len,
323+
m_connections[conn_id]->send_set_command(&timestamp, m_obj_gen->get_key(), m_obj_gen->get_key_len(),
317324
value, value_len, m_obj_gen->get_expiry(),
318325
m_config->data_offset);
319326
}
@@ -328,7 +335,7 @@ bool client::create_get_request(struct timeval& timestamp, unsigned int conn_id)
328335
return false;
329336

330337
if (res == available_for_conn) {
331-
m_connections[conn_id]->send_get_command(&timestamp, m_key_buffer, m_key_len, m_config->data_offset);
338+
m_connections[conn_id]->send_get_command(&timestamp, m_obj_gen->get_key(), m_obj_gen->get_key_len(), m_config->data_offset);
332339
}
333340

334341
return true;
@@ -346,7 +353,7 @@ bool client::create_mget_request(struct timeval& timestamp, unsigned int conn_id
346353
/* Not supported in cluster mode */
347354
assert(res == available_for_conn);
348355

349-
m_keylist->add_key(m_key_buffer, m_key_len);
356+
m_keylist->add_key(m_obj_gen->get_key(), m_obj_gen->get_key_len());
350357
}
351358

352359
m_connections[conn_id]->send_mget_command(&timestamp, m_keylist);
@@ -378,6 +385,11 @@ void client::create_request(struct timeval timestamp, unsigned int conn_id)
378385

379386
// are we set or get? this depends on the ratio
380387
else if (m_set_ratio_count < m_config->ratio.a) {
388+
/* Before we can create a SET request, we need to read the next imported item */
389+
if (m_config->data_import) {
390+
dynamic_cast<import_object_generator*>(m_obj_gen)->read_next_item();
391+
}
392+
381393
if (!create_set_request(timestamp, conn_id))
382394
return;
383395

@@ -482,57 +494,51 @@ unsigned long long int verify_client::get_errors(void)
482494
return m_errors;
483495
}
484496

485-
void verify_client::create_request(struct timeval timestamp, unsigned int conn_id)
486-
{
487-
// TODO: Refactor client::create_request so this can be unified.
488-
if (m_set_ratio_count < m_config->ratio.a) {
489-
// Prepare a GET request that will be compared against a previous
490-
// SET request.
491-
data_object *obj = m_obj_gen->get_object(obj_iter_type(m_config, 0));
492-
unsigned int key_len;
493-
const char *key = obj->get_key(&key_len);
497+
bool verify_client::create_wait_request(struct timeval& timestamp, unsigned int conn_id) {
498+
// Nothing to do
499+
return true;
500+
}
501+
502+
bool verify_client::create_set_request(struct timeval& timestamp, unsigned int conn_id) {
503+
unsigned long long key_index;
504+
get_key_response res = get_key_for_conn(SET_CMD_IDX, conn_id, &key_index);
505+
if (res == not_available)
506+
return false;
507+
508+
if (res == available_for_conn) {
494509
unsigned int value_len;
495-
const char *value = obj->get_value(&value_len);
510+
const char *value = m_obj_gen->get_value(key_index, &value_len);
496511

497-
m_connections[conn_id]->send_verify_get_command(&timestamp, key, key_len,
498-
value, value_len, obj->get_expiry(),
512+
m_connections[conn_id]->send_verify_get_command(&timestamp, m_obj_gen->get_key(), m_obj_gen->get_key_len(),
513+
value, value_len,
499514
m_config->data_offset);
515+
}
500516

501-
m_set_ratio_count++;
502-
} else if (m_get_ratio_count < m_config->ratio.b) {
503-
// We don't really care about GET operations, all we do here is keep
504-
// the object generator synced.
505-
int iter = obj_iter_type(m_config, 2);
506-
507-
if (m_config->multi_key_get > 0) {
508-
unsigned int keys_count;
517+
return true;
518+
}
509519

510-
keys_count = m_config->ratio.b - m_get_ratio_count;
511-
if ((int)keys_count > m_config->multi_key_get)
512-
keys_count = m_config->multi_key_get;
513-
m_keylist->clear();
514-
while (m_keylist->get_keys_count() < keys_count) {
515-
unsigned int keylen;
516-
const char *key = m_obj_gen->get_key(iter, &keylen);
520+
bool verify_client::create_get_request(struct timeval& timestamp, unsigned int conn_id) {
521+
// Just Keep object generator synced
522+
unsigned long long key_index;
523+
get_key_for_conn(GET_CMD_IDX, conn_id, &key_index);
517524

518-
assert(key != NULL);
519-
assert(keylen > 0);
525+
return true;
526+
}
520527

521-
m_keylist->add_key(key, keylen);
522-
}
528+
bool verify_client::create_mget_request(struct timeval& timestamp, unsigned int conn_id) {
529+
// Just Keep object generator synced
530+
unsigned long long key_index;
531+
unsigned int keys_count = m_config->ratio.b - m_get_ratio_count;
532+
if ((int)keys_count > m_config->multi_key_get)
533+
keys_count = m_config->multi_key_get;
523534

524-
m_get_ratio_count += keys_count;
525-
} else {
526-
unsigned int keylen;
527-
m_obj_gen->get_key(iter, &keylen);
528-
m_get_ratio_count++;
529-
}
535+
m_keylist->clear();
536+
for (unsigned int i = 0; i < keys_count; i++) {
530537

531-
// We don't really send this request, but need to count it to be in sync.
532-
m_reqs_processed++;
533-
} else {
534-
m_get_ratio_count = m_set_ratio_count = 0;
538+
get_key_for_conn(GET_CMD_IDX, conn_id, &key_index);
535539
}
540+
541+
return true;
536542
}
537543

538544
void verify_client::handle_response(unsigned int conn_id, struct timeval timestamp,

client.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class client;
4545
class client_group;
4646
struct benchmark_config;
4747
class object_generator;
48-
class data_object;
4948

5049
#define SET_CMD_IDX 0
5150
#define GET_CMD_IDX 2
@@ -61,10 +60,6 @@ class client : public connections_manager {
6160
bool m_initialized;
6261
bool m_end_set;
6362

64-
// key buffer
65-
char m_key_buffer[250];
66-
int m_key_len;
67-
6863
// test related
6964
benchmark_config* m_config;
7065
object_generator* m_obj_gen;
@@ -93,10 +88,10 @@ class client : public connections_manager {
9388

9489
virtual get_key_response get_key_for_conn(unsigned int command_index, unsigned int conn_id, unsigned long long* key_index);
9590
virtual bool create_arbitrary_request(unsigned int command_index, struct timeval& timestamp, unsigned int conn_id);
96-
bool create_wait_request(struct timeval& timestamp, unsigned int conn_id);
97-
bool create_set_request(struct timeval& timestamp, unsigned int conn_id);
98-
bool create_get_request(struct timeval& timestamp, unsigned int conn_id);
99-
bool create_mget_request(struct timeval& timestamp, unsigned int conn_id);
91+
virtual bool create_wait_request(struct timeval& timestamp, unsigned int conn_id);
92+
virtual bool create_set_request(struct timeval& timestamp, unsigned int conn_id);
93+
virtual bool create_get_request(struct timeval& timestamp, unsigned int conn_id);
94+
virtual bool create_mget_request(struct timeval& timestamp, unsigned int conn_id);
10095

10196
// client manager api's
10297
unsigned long long get_reqs_processed() {
@@ -185,7 +180,10 @@ class verify_client : public client {
185180
unsigned long long int m_errors;
186181

187182
virtual bool finished(void);
188-
virtual void create_request(struct timeval timestamp, unsigned int conn_id);
183+
virtual bool create_wait_request(struct timeval& timestamp, unsigned int conn_id);
184+
virtual bool create_set_request(struct timeval& timestamp, unsigned int conn_id);
185+
virtual bool create_get_request(struct timeval& timestamp, unsigned int conn_id);
186+
virtual bool create_mget_request(struct timeval& timestamp, unsigned int conn_id);
189187
virtual void handle_response(unsigned int conn_id, struct timeval timestamp,
190188
request *request, protocol_response *response);
191189
public:

cluster_client.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ get_key_response cluster_client::get_key_for_conn(unsigned int command_index, un
312312
// first check if we already have a key in the pool
313313
if (!m_key_index_pools[conn_id]->empty()) {
314314
*key_index = m_key_index_pools[conn_id]->front();
315-
m_key_len = snprintf(m_key_buffer, sizeof(m_key_buffer)-1, "%s%llu", m_obj_gen->get_key_prefix(), *key_index);
315+
m_obj_gen->generate_key(*key_index);
316316

317317
m_key_index_pools[conn_id]->pop();
318318
return available_for_conn;
@@ -321,11 +321,13 @@ get_key_response cluster_client::get_key_for_conn(unsigned int command_index, un
321321
// generate key
322322
client::get_key_for_conn(command_index, conn_id, key_index);
323323

324-
unsigned int hslot = calc_hslot_crc16_cluster(m_key_buffer, m_key_len);
324+
unsigned int hslot = calc_hslot_crc16_cluster(m_obj_gen->get_key(), m_obj_gen->get_key_len());
325325

326326
// check if the key match for this connection
327327
if (m_slot_to_shard[hslot] == conn_id) {
328-
benchmark_debug_log("%s generated key=[%.*s] for itself\n", m_connections[conn_id]->get_readable_id(), m_key_len, m_key_buffer);
328+
benchmark_debug_log("%s generated key=[%.*s] for itself\n",
329+
m_connections[conn_id]->get_readable_id(),
330+
m_obj_gen->get_key_len(), m_obj_gen->get_key());
329331
return available_for_conn;
330332
}
331333

@@ -347,7 +349,10 @@ get_key_response cluster_client::get_key_for_conn(unsigned int command_index, un
347349
return not_available;
348350

349351
// store command and key for the other connection
350-
benchmark_debug_log("%s generated key=[%.*s] for %s\n", m_connections[conn_id]->get_readable_id(), m_key_len, m_key_buffer, m_connections[other_conn_id]->get_readable_id());
352+
benchmark_debug_log("%s generated key=[%.*s] for %s\n",
353+
m_connections[conn_id]->get_readable_id(),
354+
m_obj_gen->get_key_len(), m_obj_gen->get_key(),
355+
m_connections[other_conn_id]->get_readable_id());
351356

352357
key_idx_pool->push(command_index);
353358
key_idx_pool->push(*key_index);

memtier_benchmark.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,11 @@ int main(int argc, char *argv[])
14851485
}
14861486
assert(obj_gen != NULL);
14871487
} else {
1488+
// oss cluster API can't be enabled
1489+
if (cfg.cluster_mode) {
1490+
fprintf(stderr, "error: Cluster mode cannot be specified when importing.\n");
1491+
exit(1);
1492+
}
14881493
// check paramters
14891494
if (cfg.data_size ||
14901495
cfg.data_size_list.is_defined() ||

0 commit comments

Comments
 (0)