Skip to content

Commit 75fb187

Browse files
author
Allen lai
committed
Bug#17214191 MEMCACHED ADD/SET ARE SLOWER THAN INSERTS
Merge from mysql-5.6 to mysql-trunk.
2 parents 256c8cf + 59da279 commit 75fb187

File tree

6 files changed

+81
-42
lines changed

6 files changed

+81
-42
lines changed

plugin/innodb_memcached/innodb_memcache/include/innodb_cb_api.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ ib_err_t
170170
ib_tpl_t ib_tpl,
171171
ib_ulint_t col_no,
172172
const void* src,
173-
ib_ulint_t len) ;
173+
ib_ulint_t len,
174+
bool need_cpy) ;
174175

175176
typedef
176177
const void*

plugin/innodb_memcached/innodb_memcache/src/innodb_api.c

+34-26
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ innodb_api_write_int(
305305
{
306306
ib_col_meta_t col_meta;
307307
ib_col_meta_t* m_col = &col_meta;
308-
void* src;
308+
void* src = NULL;
309309

310310
ib_cb_col_get_meta(tpl, field, m_col);
311311

@@ -355,7 +355,7 @@ innodb_api_write_int(
355355
}
356356
}
357357

358-
ib_cb_col_set_value(tpl, field, src, m_col->type_len);
358+
ib_cb_col_set_value(tpl, field, src, m_col->type_len, true);
359359
return(DB_SUCCESS);
360360
}
361361

@@ -546,7 +546,7 @@ innodb_api_search(
546546
srch_crsr = crsr;
547547
}
548548

549-
err = ib_cb_col_set_value(key_tpl, 0, (char*) key, len);
549+
err = ib_cb_col_set_value(key_tpl, 0, (char*) key, len, true);
550550

551551
ib_cb_cursor_set_match_mode(srch_crsr, IB_EXACT_MATCH);
552552

@@ -762,7 +762,7 @@ innodb_api_set_multi_cols(
762762
if (value[0] == *sep) {
763763
err = ib_cb_col_set_value(
764764
tpl, col_info[i].field_id,
765-
NULL, IB_SQL_NULL);
765+
NULL, IB_SQL_NULL, true);
766766
i++;
767767

768768
if (err != DB_SUCCESS) {
@@ -780,11 +780,11 @@ innodb_api_set_multi_cols(
780780
if (!col_val) {
781781
err = ib_cb_col_set_value(
782782
tpl, col_info[i].field_id,
783-
NULL, IB_SQL_NULL);
783+
NULL, IB_SQL_NULL, true);
784784
} else {
785785
err = ib_cb_col_set_value(
786786
tpl, col_info[i].field_id,
787-
col_val, strlen(col_val));
787+
col_val, strlen(col_val), true);
788788

789789
if (table) {
790790
handler_rec_setup_str(
@@ -801,7 +801,7 @@ innodb_api_set_multi_cols(
801801
for (; i < meta_info->n_extra_col; i++) {
802802
err = ib_cb_col_set_value(
803803
tpl, col_info[i].field_id,
804-
NULL, IB_SQL_NULL);
804+
NULL, IB_SQL_NULL, true);
805805

806806
if (err != DB_SUCCESS) {
807807
break;
@@ -858,12 +858,13 @@ innodb_api_set_tpl(
858858
uint64_t exp, /*!< in: expiration */
859859
uint64_t flag, /*!< in: flag */
860860
int col_to_set, /*!< in: column to set */
861-
void* table) /*!< in: MySQL TABLE* */
861+
void* table, /*!< in: MySQL TABLE* */
862+
bool need_cpy) /*!< in: if need memcpy */
862863
{
863864
ib_err_t err = DB_ERROR;
864865

865866
err = ib_cb_col_set_value(tpl, col_info[CONTAINER_KEY].field_id,
866-
key, key_len);
867+
key, key_len, need_cpy);
867868

868869
if (err != DB_SUCCESS) {
869870
return(err);
@@ -884,12 +885,13 @@ innodb_api_set_tpl(
884885
if (col_to_set == UPDATE_ALL_VAL_COL) {
885886
err = innodb_api_set_multi_cols(tpl, meta_info,
886887
(char*) value,
887-
value_len, table);
888+
value_len,
889+
table);
888890
} else {
889891
err = ib_cb_col_set_value(
890892
tpl,
891893
meta_info->extra_col_info[col_to_set].field_id,
892-
value, value_len);
894+
value, value_len, need_cpy);
893895

894896
if (table) {
895897
handler_rec_setup_str(
@@ -901,7 +903,7 @@ innodb_api_set_tpl(
901903
} else {
902904
err = ib_cb_col_set_value(
903905
tpl, col_info[CONTAINER_VALUE].field_id,
904-
value, value_len);
906+
value, value_len, need_cpy);
905907

906908
if (table) {
907909
handler_rec_setup_str(
@@ -977,7 +979,8 @@ innodb_api_insert(
977979
key + len, val_len,
978980
new_cas, exp, flags, UPDATE_ALL_VAL_COL,
979981
engine->enable_binlog
980-
? cursor_data->mysql_tbl : NULL);
982+
? cursor_data->mysql_tbl : NULL,
983+
false);
981984

982985
if (err == DB_SUCCESS) {
983986
err = ib_cb_insert_row(cursor_data->crsr, tpl);
@@ -1048,7 +1051,8 @@ innodb_api_update(
10481051
len, key + len, val_len,
10491052
new_cas, exp, flags, UPDATE_ALL_VAL_COL,
10501053
engine->enable_binlog
1051-
? cursor_data->mysql_tbl : NULL);
1054+
? cursor_data->mysql_tbl : NULL,
1055+
true);
10521056

10531057
if (err == DB_SUCCESS) {
10541058
err = ib_cb_update_row(srch_crsr, old_tpl, new_tpl);
@@ -1213,7 +1217,8 @@ innodb_api_link(
12131217
key, len, append_buf, total_len,
12141218
new_cas, exp, flags, column_used,
12151219
engine->enable_binlog
1216-
? cursor_data->mysql_tbl : NULL);
1220+
? cursor_data->mysql_tbl : NULL,
1221+
true);
12171222

12181223
if (err == DB_SUCCESS) {
12191224
err = ib_cb_update_row(srch_crsr, old_tpl, new_tpl);
@@ -1377,7 +1382,8 @@ innodb_api_arithmetic(
13771382
result.col_value[MCI_COL_FLAG].value_int,
13781383
column_used,
13791384
engine->enable_binlog
1380-
? cursor_data->mysql_tbl : NULL);
1385+
? cursor_data->mysql_tbl : NULL,
1386+
true);
13811387

13821388
if (err != DB_SUCCESS) {
13831389
ib_cb_tuple_delete(new_tpl);
@@ -1453,9 +1459,16 @@ innodb_api_store(
14531459
ENGINE_ERROR_CODE stored = ENGINE_NOT_STORED;
14541460
ib_crsr_t srch_crsr = cursor_data->crsr;
14551461

1456-
/* First check whether record with the key value exists */
1457-
err = innodb_api_search(cursor_data, &srch_crsr,
1458-
key, len, &result, &old_tpl, false);
1462+
/* Skip search for add operation. Rely on the unique index of
1463+
key to check any duplicates */
1464+
if (op == OPERATION_ADD) {
1465+
err = DB_RECORD_NOT_FOUND;
1466+
memset(&result, 0, sizeof(result));
1467+
} else {
1468+
/* First check whether record with the key value exists */
1469+
err = innodb_api_search(cursor_data, &srch_crsr,
1470+
key, len, &result, &old_tpl, false);
1471+
}
14591472

14601473
/* If the return message is not success or record not found, just
14611474
exit */
@@ -1465,13 +1478,8 @@ innodb_api_store(
14651478

14661479
switch (op) {
14671480
case OPERATION_ADD:
1468-
/* Only add if the key does not exist */
1469-
if (err != DB_SUCCESS) {
1470-
err = innodb_api_insert(engine, cursor_data, key, len,
1471-
val_len, exp, cas, flags);
1472-
} else {
1473-
err = DB_ERROR;
1474-
}
1481+
err = innodb_api_insert(engine, cursor_data, key, len,
1482+
val_len, exp, cas, flags);
14751483
break;
14761484
case OPERATION_REPLACE:
14771485
if (err == DB_SUCCESS) {

plugin/innodb_memcached/innodb_memcache/src/innodb_config.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ innodb_config_container(
653653
/* User supplied a config option name, find it */
654654
tpl = ib_cb_search_tuple_create(crsr);
655655

656-
err = ib_cb_col_set_value(tpl, 0, name, name_len);
656+
err = ib_cb_col_set_value(tpl, 0, name, name_len, true);
657657

658658
ib_cb_cursor_set_match_mode(crsr, IB_EXACT_MATCH);
659659
err = ib_cb_moveto(crsr, tpl, IB_CUR_GE);

plugin/innodb_memcached/innodb_memcache/src/innodb_engine.c

+14
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,20 @@ innodb_get(
13481348
time = mci_get_time();
13491349

13501350
if (time > result.col_value[MCI_COL_EXP].value_int) {
1351+
/* Free allocated memory. */
1352+
if (result.extra_col_value) {
1353+
for (int i = 0; i < result.n_extra_col; i++) {
1354+
free(result.extra_col_value[i].value_str);
1355+
}
1356+
1357+
free(result.extra_col_value);
1358+
}
1359+
if (result.col_value[MCI_COL_VALUE].allocated) {
1360+
free(result.col_value[MCI_COL_VALUE].value_str);
1361+
result.col_value[MCI_COL_VALUE].allocated =
1362+
false;
1363+
}
1364+
13511365
err_ret = ENGINE_KEY_ENOENT;
13521366
goto func_exit;
13531367
}

storage/innobase/api/api0api.cc

+27-13
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,8 @@ ib_cursor_insert_row(
16221622
src_tuple->index->table, q_proc->grph.ins, node->ins);
16231623
}
16241624

1625+
srv_active_wake_master_thread();
1626+
16251627
return(err);
16261628
}
16271629

@@ -1906,6 +1908,8 @@ ib_cursor_update_row(
19061908
err = ib_execute_update_query_graph(cursor, pcur);
19071909
}
19081910

1911+
srv_active_wake_master_thread();
1912+
19091913
return(err);
19101914
}
19111915

@@ -2031,6 +2035,8 @@ ib_cursor_delete_row(
20312035
err = DB_RECORD_NOT_FOUND;
20322036
}
20332037

2038+
srv_active_wake_master_thread();
2039+
20342040
return(err);
20352041
}
20362042

@@ -2289,7 +2295,8 @@ ib_col_set_value(
22892295
ib_tpl_t ib_tpl, /*!< in: tuple instance */
22902296
ib_ulint_t col_no, /*!< in: column index in tuple */
22912297
const void* src, /*!< in: data value */
2292-
ib_ulint_t len) /*!< in: data value len */
2298+
ib_ulint_t len, /*!< in: data value len */
2299+
ib_bool_t need_cpy) /*!< in: if need memcpy */
22932300
{
22942301
const dtype_t* dtype;
22952302
dfield_t* dfield;
@@ -2384,7 +2391,12 @@ ib_col_set_value(
23842391
case DATA_DECIMAL:
23852392
case DATA_VARCHAR:
23862393
case DATA_FIXBINARY:
2387-
memcpy(dst, src, len);
2394+
if (need_cpy) {
2395+
memcpy(dst, src, len);
2396+
} else {
2397+
dfield_set_data(dfield, src, len);
2398+
dst = dfield_get_data(dfield);
2399+
}
23882400
break;
23892401

23902402
case DATA_MYSQL:
@@ -3505,7 +3517,7 @@ ib_tuple_write_int(
35053517
return(DB_DATA_MISMATCH);
35063518
}
35073519

3508-
return(ib_col_set_value(ib_tpl, col_no, value, type_len));
3520+
return(ib_col_set_value(ib_tpl, col_no, value, type_len, true));
35093521
}
35103522

35113523
/*****************************************************************//**
@@ -3520,7 +3532,7 @@ ib_tuple_write_i8(
35203532
int col_no, /*!< in: column number */
35213533
ib_i8_t val) /*!< in: value to write */
35223534
{
3523-
return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val)));
3535+
return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val), true));
35243536
}
35253537

35263538
/*****************************************************************//**
@@ -3535,7 +3547,7 @@ ib_tuple_write_i16(
35353547
int col_no, /*!< in: column number */
35363548
ib_i16_t val) /*!< in: value to write */
35373549
{
3538-
return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val)));
3550+
return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val), true));
35393551
}
35403552

35413553
/*****************************************************************//**
@@ -3550,7 +3562,7 @@ ib_tuple_write_i32(
35503562
int col_no, /*!< in: column number */
35513563
ib_i32_t val) /*!< in: value to write */
35523564
{
3553-
return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val)));
3565+
return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val), true));
35543566
}
35553567

35563568
/*****************************************************************//**
@@ -3565,7 +3577,7 @@ ib_tuple_write_i64(
35653577
int col_no, /*!< in: column number */
35663578
ib_i64_t val) /*!< in: value to write */
35673579
{
3568-
return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val)));
3580+
return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val), true));
35693581
}
35703582

35713583
/*****************************************************************//**
@@ -3580,7 +3592,7 @@ ib_tuple_write_u8(
35803592
int col_no, /*!< in: column number */
35813593
ib_u8_t val) /*!< in: value to write */
35823594
{
3583-
return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val)));
3595+
return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val), true));
35843596
}
35853597

35863598
/*****************************************************************//**
@@ -3595,7 +3607,7 @@ ib_tuple_write_u16(
35953607
int col_no, /*!< in: column number */
35963608
ib_u16_t val) /*!< in: value to write */
35973609
{
3598-
return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val)));
3610+
return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val), true));
35993611
}
36003612

36013613
/*****************************************************************//**
@@ -3610,7 +3622,7 @@ ib_tuple_write_u32(
36103622
int col_no, /*!< in: column number */
36113623
ib_u32_t val) /*!< in: value to write */
36123624
{
3613-
return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val)));
3625+
return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val), true));
36143626
}
36153627

36163628
/*****************************************************************//**
@@ -3625,7 +3637,7 @@ ib_tuple_write_u64(
36253637
int col_no, /*!< in: column number */
36263638
ib_u64_t val) /*!< in: value to write */
36273639
{
3628-
return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val)));
3640+
return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val), true));
36293641
}
36303642

36313643
/*****************************************************************//**
@@ -3658,7 +3670,8 @@ ib_tuple_write_double(
36583670
dfield = ib_col_get_dfield(tuple, col_no);
36593671

36603672
if (dtype_get_mtype(dfield_get_type(dfield)) == DATA_DOUBLE) {
3661-
return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val)));
3673+
return(ib_col_set_value(ib_tpl, col_no,
3674+
&val, sizeof(val), true));
36623675
} else {
36633676
return(DB_DATA_MISMATCH);
36643677
}
@@ -3708,7 +3721,8 @@ ib_tuple_write_float(
37083721
dfield = ib_col_get_dfield(tuple, col_no);
37093722

37103723
if (dtype_get_mtype(dfield_get_type(dfield)) == DATA_FLOAT) {
3711-
return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val)));
3724+
return(ib_col_set_value(ib_tpl, col_no,
3725+
&val, sizeof(val), true));
37123726
} else {
37133727
return(DB_DATA_MISMATCH);
37143728
}

storage/innobase/include/api0api.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,9 @@ ib_col_set_value(
732732
ib_tpl_t ib_tpl, /*!< in: tuple instance */
733733
ib_ulint_t col_no, /*!< in: column index in tuple */
734734
const void* src, /*!< in: data value */
735-
ib_ulint_t len); /*!< in: data value len */
735+
ib_ulint_t len, /*!< in: data value len */
736+
ib_bool_t need_cpy); /*!< in: if need memcpy */
737+
736738

737739
/*****************************************************************//**
738740
Get the size of the data available in the column the tuple.

0 commit comments

Comments
 (0)