Skip to content

Commit 8416fd3

Browse files
MDEV-32627 [fixup] Spider: Fix conn key length
To avoid off-by-one in spider_get_share. And document conn key and conn key length.
1 parent 20d99f3 commit 8416fd3

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

storage/spider/spd_table.cc

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3826,6 +3826,33 @@ void spider_create_conn_key_add_one(int* counter, char** target, char* src)
38263826
}
38273827
}
38283828

3829+
/*
3830+
The conn keys are strings of the following format:
3831+
3832+
0 \<idx1> <value1> \0 \<idx2> <value2> \0 ... \<idxN> <valueN> \0
3833+
3834+
Where idx1, idx2, etc. are the index of first, second, etc. options
3835+
where the value is specified. We have the wrapper as the first
3836+
option, host as the second, port as the third, socket as the fourth,
3837+
and so on (see below for the order of all options). So here would be
3838+
a conn key where only the host and the port are specified and
3839+
nothing else:
3840+
3841+
0\002localhost\000\00303306\000
3842+
3843+
And it has length 1 + 1 + 9 + 1 + 1 + 5 + 1 = 19.
3844+
3845+
In case of HA, say we have another link with the same options
3846+
specified except that the port is 3307, then we place an extra NUL
3847+
before placing the next conn_key:
3848+
3849+
0\002localhost\000\00303306\000\0000\002localhost\000\00303307\000
3850+
^ ^
3851+
conn_keys[0] conn_keys[1]
3852+
3853+
Thus the total number of chars (share->conn_keys_charlen) needed is
3854+
(19 + 1) * 2 = 40
3855+
*/
38293856
int spider_create_conn_keys(
38303857
SPIDER_SHARE *share
38313858
) {
@@ -3904,7 +3931,7 @@ int spider_create_conn_keys(
39043931
+ (share->tgt_default_files[roop_count] ? share->tgt_default_files_lengths[roop_count] + 2 : 0)
39053932
+ (share->tgt_default_groups[roop_count] ? share->tgt_default_groups_lengths[roop_count] + 2 : 0)
39063933
+ (share->tgt_dsns[roop_count] ? share->tgt_dsns_lengths[roop_count] + 2 : 0);
3907-
share->conn_keys_charlen += conn_keys_lengths[roop_count] + 2;
3934+
share->conn_keys_charlen += conn_keys_lengths[roop_count] + 1;
39083935
}
39093936
if (!(share->conn_keys = (char **)
39103937
spider_bulk_alloc_mem(spider_current_trx, SPD_MID_CREATE_CONN_KEYS_1,
@@ -3973,6 +4000,7 @@ int spider_create_conn_keys(
39734000
spider_create_conn_key_add_one(&counter, &tmp_name, share->tgt_default_groups[roop_count]);
39744001
spider_create_conn_key_add_one(&counter, &tmp_name, share->tgt_dsns[roop_count]);
39754002
tmp_name++;
4003+
tmp_name++;
39764004
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
39774005
share->conn_keys_hash_value[roop_count] = my_calc_hash(
39784006
&spider_open_connections, (uchar*) share->conn_keys[roop_count],

0 commit comments

Comments
 (0)