@@ -358,9 +358,54 @@ bool cluster_client::get_key_for_conn(unsigned int conn_id, int iter, unsigned l
358
358
}
359
359
}
360
360
361
+
362
+ void cluster_client::create_arbitrary_request (const arbitrary_command* cmd, struct timeval & timestamp, unsigned int conn_id) {
363
+ int cmd_size = 0 ;
364
+
365
+ benchmark_debug_log (" %s [%s]:\n " , cmd->command_name .c_str (), cmd->command .c_str ());
366
+
367
+ for (unsigned int i = 0 ; i < cmd->command_args .size (); i++) {
368
+ const command_arg* arg = &cmd->command_args [i];
369
+
370
+ if (arg->type == const_type) {
371
+ cmd_size += m_connections[conn_id]->send_arbitrary_command (arg);
372
+ } else if (arg->type == key_type) {
373
+ unsigned long long key_index;
374
+
375
+ // get key
376
+ if (!get_key_for_conn (conn_id, get_arbitrary_obj_iter_type (cmd, m_executed_command_index), &key_index)) {
377
+ return ;
378
+ }
379
+
380
+ assert (key_index >= 0 );
381
+ assert (m_key_len > 0 );
382
+
383
+ cmd_size += m_connections[conn_id]->send_arbitrary_command (arg, m_key_buffer, m_key_len);
384
+ } else if (arg->type == data_type) {
385
+ unsigned int value_len;
386
+ const char *value = m_obj_gen->get_value (0 , &value_len);
387
+
388
+ assert (value != NULL );
389
+ assert (value_len > 0 );
390
+
391
+ cmd_size += m_connections[conn_id]->send_arbitrary_command (arg, value, value_len);
392
+ }
393
+ }
394
+
395
+ m_connections[conn_id]->send_arbitrary_command_end (m_executed_command_index, ×tamp, cmd_size);
396
+ }
397
+
361
398
// This function could use some urgent TLC -- but we need to do it without altering the behavior
362
399
void cluster_client::create_request (struct timeval timestamp, unsigned int conn_id)
363
400
{
401
+ // are we using arbitrary command?
402
+ if (m_config->arbitrary_commands ->is_defined ()) {
403
+ const arbitrary_command* executed_command = m_config->arbitrary_commands ->get_next_executed_command (m_arbitrary_command_ratio_count,
404
+ m_executed_command_index);
405
+ create_arbitrary_request (executed_command, timestamp, conn_id);
406
+ return ;
407
+ }
408
+
364
409
// If the Set:Wait ratio is not 0, start off with WAITs
365
410
if (m_config->wait_ratio .b &&
366
411
(m_tot_wait_ops == 0 ||
@@ -416,16 +461,28 @@ void cluster_client::create_request(struct timeval timestamp, unsigned int conn_
416
461
void cluster_client::handle_moved (unsigned int conn_id, struct timeval timestamp,
417
462
request *request, protocol_response *response) {
418
463
// update stats
419
- if (request->m_type == rt_get) {
420
- m_stats.update_moved_get_op (×tamp,
464
+ switch (request->m_type ) {
465
+ case rt_get:
466
+ m_stats.update_moved_get_op (×tamp,
421
467
request->m_size + response->get_total_len (),
422
468
ts_diff (request->m_sent_time , timestamp));
423
- } else if (request->m_type == rt_set) {
424
- m_stats.update_moved_set_op (×tamp,
469
+ break ;
470
+ case rt_set:
471
+ m_stats.update_moved_set_op (×tamp,
425
472
request->m_size + response->get_total_len (),
426
473
ts_diff (request->m_sent_time , timestamp));
427
- } else {
428
- assert (0 );
474
+ break ;
475
+ case rt_arbitrary: {
476
+ arbitrary_request *ar = static_cast <arbitrary_request *>(request);
477
+ m_stats.update_moved_arbitrary_op (×tamp,
478
+ request->m_size + response->get_total_len (),
479
+ ts_diff (request->m_sent_time , timestamp),
480
+ ar->index );
481
+ break ;
482
+ }
483
+ default :
484
+ assert (0 );
485
+ break ;
429
486
}
430
487
431
488
// connection already issued 'cluster slots' command, wait for slots mapping to be updated
@@ -444,16 +501,28 @@ void cluster_client::handle_moved(unsigned int conn_id, struct timeval timestamp
444
501
void cluster_client::handle_ask (unsigned int conn_id, struct timeval timestamp,
445
502
request *request, protocol_response *response) {
446
503
// update stats
447
- if (request->m_type == rt_get) {
448
- m_stats.update_ask_get_op (×tamp,
449
- request->m_size + response->get_total_len (),
450
- ts_diff (request->m_sent_time , timestamp));
451
- } else if (request->m_type == rt_set) {
452
- m_stats.update_ask_set_op (×tamp,
453
- request->m_size + response->get_total_len (),
454
- ts_diff (request->m_sent_time , timestamp));
455
- } else {
456
- assert (0 );
504
+ switch (request->m_type ) {
505
+ case rt_get:
506
+ m_stats.update_ask_get_op (×tamp,
507
+ request->m_size + response->get_total_len (),
508
+ ts_diff (request->m_sent_time , timestamp));
509
+ break ;
510
+ case rt_set:
511
+ m_stats.update_ask_set_op (×tamp,
512
+ request->m_size + response->get_total_len (),
513
+ ts_diff (request->m_sent_time , timestamp));
514
+ break ;
515
+ case rt_arbitrary: {
516
+ arbitrary_request *ar = static_cast <arbitrary_request *>(request);
517
+ m_stats.update_ask_arbitrary_op (×tamp,
518
+ request->m_size + response->get_total_len (),
519
+ ts_diff (request->m_sent_time , timestamp),
520
+ ar->index );
521
+ break ;
522
+ }
523
+ default :
524
+ assert (0 );
525
+ break ;
457
526
}
458
527
}
459
528
0 commit comments