forked from mariadb-corporation/MaxScale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbug587.cc
127 lines (112 loc) · 3.63 KB
/
bug587.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* Copyright (c) 2016 MariaDB Corporation Ab
* Copyright (c) 2023 MariaDB plc, Finnish Branch
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
*
* Change Date: 2027-04-10
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2 or later of the General
* Public License.
*/
/**
* @file bug587.cpp regression case for the bug 587 ( "Hint filter don't work if listed before regex filter
* in configuration file" )
*
* - Maxscale.cnf
* @verbatim
* [hints]
* type=filter
* module=hintfilter
*
* [regex]
* type=filter
* module=regexfilter
* match=fetch
* replace=select
*
* [RW Split Router]
* type=service
* router= readwritesplit
* servers=server1, server2, server3,server4
* user=skysql
* passwd=skysql
* max_slave_connections=100%
* use_sql_variables_in=all
* router_options=slave_selection_criteria=LEAST_BEHIND_MASTER
* filters=hints|regex
* @endverbatim
* - second test (bug587_1) is executed with "filters=regex|hints" (dffeent order of filters)
* - check if hints filter working by executing and comparing results:
* + via RWSPLIT: "select @@server_id; -- maxscale route to server server%d" (%d - node number)
* + directly to backend node "select @@server_id;"
* - do the same test with "filters=regex|hints" "filters=hints|regex"
*/
/*
* Vilho Raatikka 2014-10-21 19:12:33 UTC
* If filters and rwsplit are configured as follows, hints don't work.
*
* [hints]
* type=filter
* module=hintfilter
*
* [regex]
* type=filter
* module=regexfilter
* match=fetch
* replace=select
*
* [RW Split Router]
* type=service
* router=readwritesplit
* servers=server1,server2,server3,server4
* max_slave_connections=100%
* use_sql_variables_in=all
* user=maxuser
* passwd=maxpwd
* filters=hints|regex
*
* Changing filters=regex|hints makes it work. This is due to processing order. Regex filter drops hint off.
* Comment 1 Vilho Raatikka 2014-10-23 18:08:07 UTC
* buffer.c:gwbuf_make_contiguous: hint wasn't duplicated to new GWBUF struct. As a result hints were lost if
* query rewriting resulted in longer query than the original.
*/
#include <iostream>
#include <unistd.h>
#include <maxtest/testconnections.hh>
using namespace std;
int main(int argc, char* argv[])
{
TestConnections* Test = new TestConnections(argc, argv);
Test->reset_timeout();
Test->repl->connect();
Test->maxscale->connect_maxscale();
char server_id[256];
char server_id_d[256];
char hint_sql[128];
for (int i = 1; i < 25; i++)
{
for (int j = 0; j < Test->repl->N; j++)
{
Test->reset_timeout();
sprintf(hint_sql, "select @@server_id; -- maxscale route to server server%d", j + 1);
Test->tprintf("%s\n", hint_sql);
find_field(Test->maxscale->conn_rwsplit, hint_sql, (char*) "@@server_id", &server_id[0]);
find_field(Test->repl->nodes[j],
(char*) "select @@server_id;",
(char*) "@@server_id",
&server_id_d[0]);
Test->tprintf("server%d ID from Maxscale: \t%s\n", j + 1, server_id);
Test->tprintf("server%d ID directly from node: \t%s\n", j + 1, server_id_d);
Test->add_result(strcmp(server_id, server_id_d), "Hints does not work!\n");
}
}
Test->maxscale->close_maxscale_connections();
Test->repl->close_connections();
Test->check_maxscale_alive();
int rval = Test->global_result;
delete Test;
return rval;
}