/
04_show_host_cache.patch
243 lines (229 loc) · 9.5 KB
/
04_show_host_cache.patch
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
diff -Nur mysql-5.0.25-nightly-20060823.host_cache03/client/mysql_priv.h mysql-5.0.25-nightly-20060823.host_cache04/client/mysql_priv.h
--- mysql-5.0.25-nightly-20060823.host_cache03/client/mysql_priv.h 2006-09-25 21:18:51.000000000 -0700
+++ mysql-5.0.25-nightly-20060823.host_cache04/client/mysql_priv.h 2006-09-25 21:38:21.000000000 -0700
@@ -35,6 +35,7 @@
#include <my_base.h> /* Needed by field.h */
#include "sql_bitmap.h"
#include "sql_array.h"
+#include "hash_filo.h"
#ifdef __EMX__
#undef write /* remove pthread.h macro definition for EMX */
@@ -854,6 +855,7 @@
bool append_escaped(String *to_str, String *from_str);
/* sql_show.cc */
+int mysqld_show_host_cache(THD *thd);
bool mysqld_show_open_tables(THD *thd,const char *wild);
bool mysqld_show_logs(THD *thd);
void append_identifier(THD *thd, String *packet, const char *name,
@@ -1475,6 +1477,14 @@
int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *wildstr);
/* from hostname.cc */
+class host_entry :public hash_filo_element
+{
+public:
+ uint32 ip;
+ uint errors;
+ char *hostname;
+};
+extern hash_filo *hostname_cache;
struct in_addr;
my_string ip_to_hostname(struct in_addr *in,uint *errors);
void hostname_cache_inc_errors(struct in_addr *in);
diff -Nur mysql-5.0.25-nightly-20060823.host_cache03/sql/hostname.cc mysql-5.0.25-nightly-20060823.host_cache04/sql/hostname.cc
--- mysql-5.0.25-nightly-20060823.host_cache03/sql/hostname.cc 2006-09-25 21:18:09.000000000 -0700
+++ mysql-5.0.25-nightly-20060823.host_cache04/sql/hostname.cc 2006-09-26 11:07:19.000000000 -0700
@@ -39,15 +39,7 @@
#endif
-class host_entry :public hash_filo_element
-{
-public:
- uint32 ip;
- uint errors;
- char *hostname;
-};
-
-static hash_filo *hostname_cache;
+hash_filo *hostname_cache;
/*
A simple inline function to return the hash key for a given entry.
@@ -307,7 +299,7 @@
DBUG_PRINT("error", ("In reverse lookup: my_gethostbyaddr_r returned %d",
tmp_errno));
my_gethostbyaddr_r_free();
- return 0;
+ DBUG_RETURN(0);
}
/*
diff -Nur mysql-5.0.25-nightly-20060823.host_cache03/sql/lex.h mysql-5.0.25-nightly-20060823.host_cache04/sql/lex.h
--- mysql-5.0.25-nightly-20060823.host_cache03/sql/lex.h 2006-09-25 21:16:07.000000000 -0700
+++ mysql-5.0.25-nightly-20060823.host_cache04/sql/lex.h 2006-09-25 21:36:51.000000000 -0700
@@ -223,6 +223,7 @@
{ "HAVING", SYM(HAVING)},
{ "HELP", SYM(HELP_SYM)},
{ "HIGH_PRIORITY", SYM(HIGH_PRIORITY)},
+ { "HOST", SYM(HOST_SYM)},
{ "HOSTS", SYM(HOSTS_SYM)},
{ "HOUR", SYM(HOUR_SYM)},
{ "HOUR_MICROSECOND", SYM(HOUR_MICROSECOND_SYM)},
diff -Nur mysql-5.0.25-nightly-20060823.host_cache03/sql/mysqld.cc mysql-5.0.25-nightly-20060823.host_cache04/sql/mysqld.cc
--- mysql-5.0.25-nightly-20060823.host_cache03/sql/mysqld.cc 2006-09-25 21:19:17.000000000 -0700
+++ mysql-5.0.25-nightly-20060823.host_cache04/sql/mysqld.cc 2006-09-25 21:50:34.000000000 -0700
@@ -6042,6 +6042,7 @@
{"Com_ha_open", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_HA_OPEN]), SHOW_LONG_STATUS},
{"Com_ha_read", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_HA_READ]), SHOW_LONG_STATUS},
{"Com_help", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_HELP]), SHOW_LONG_STATUS},
+ {"Com_show_host_cache", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_HOST_CACHE]), SHOW_LONG_STATUS},
{"Com_insert", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_INSERT]), SHOW_LONG_STATUS},
{"Com_insert_select", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_INSERT_SELECT]), SHOW_LONG_STATUS},
{"Com_kill", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_KILL]), SHOW_LONG_STATUS},
diff -Nur mysql-5.0.25-nightly-20060823.host_cache03/sql/mysql_priv.h mysql-5.0.25-nightly-20060823.host_cache04/sql/mysql_priv.h
--- mysql-5.0.25-nightly-20060823.host_cache03/sql/mysql_priv.h 2006-09-25 21:18:51.000000000 -0700
+++ mysql-5.0.25-nightly-20060823.host_cache04/sql/mysql_priv.h 2006-09-25 21:38:21.000000000 -0700
@@ -35,6 +35,7 @@
#include <my_base.h> /* Needed by field.h */
#include "sql_bitmap.h"
#include "sql_array.h"
+#include "hash_filo.h"
#ifdef __EMX__
#undef write /* remove pthread.h macro definition for EMX */
@@ -854,6 +855,7 @@
bool append_escaped(String *to_str, String *from_str);
/* sql_show.cc */
+int mysqld_show_host_cache(THD *thd);
bool mysqld_show_open_tables(THD *thd,const char *wild);
bool mysqld_show_logs(THD *thd);
void append_identifier(THD *thd, String *packet, const char *name,
@@ -1475,6 +1477,14 @@
int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *wildstr);
/* from hostname.cc */
+class host_entry :public hash_filo_element
+{
+public:
+ uint32 ip;
+ uint errors;
+ char *hostname;
+};
+extern hash_filo *hostname_cache;
struct in_addr;
my_string ip_to_hostname(struct in_addr *in,uint *errors);
void hostname_cache_inc_errors(struct in_addr *in);
diff -Nur mysql-5.0.25-nightly-20060823.host_cache03/sql/sql_lex.h mysql-5.0.25-nightly-20060823.host_cache04/sql/sql_lex.h
--- mysql-5.0.25-nightly-20060823.host_cache03/sql/sql_lex.h 2006-09-25 21:16:06.000000000 -0700
+++ mysql-5.0.25-nightly-20060823.host_cache04/sql/sql_lex.h 2006-09-25 21:39:54.000000000 -0700
@@ -95,6 +95,7 @@
SQLCOM_XA_START, SQLCOM_XA_END, SQLCOM_XA_PREPARE,
SQLCOM_XA_COMMIT, SQLCOM_XA_ROLLBACK, SQLCOM_XA_RECOVER,
SQLCOM_SHOW_PROC_CODE, SQLCOM_SHOW_FUNC_CODE,
+ SQLCOM_SHOW_HOST_CACHE,
/* This should be the last !!! */
SQLCOM_END
diff -Nur mysql-5.0.25-nightly-20060823.host_cache03/sql/sql_parse.cc mysql-5.0.25-nightly-20060823.host_cache04/sql/sql_parse.cc
--- mysql-5.0.25-nightly-20060823.host_cache03/sql/sql_parse.cc 2006-09-25 21:16:06.000000000 -0700
+++ mysql-5.0.25-nightly-20060823.host_cache04/sql/sql_parse.cc 2006-09-25 21:41:05.000000000 -0700
@@ -2687,6 +2687,10 @@
}
#endif
+ case SQLCOM_SHOW_HOST_CACHE:
+ res= mysqld_show_host_cache(thd);
+ break;
+
case SQLCOM_BACKUP_TABLE:
{
DBUG_ASSERT(first_table == all_tables && first_table != 0);
diff -Nur mysql-5.0.25-nightly-20060823.host_cache03/sql/sql_prepare.cc mysql-5.0.25-nightly-20060823.host_cache04/sql/sql_prepare.cc
--- mysql-5.0.25-nightly-20060823.host_cache03/sql/sql_prepare.cc 2006-09-25 21:16:06.000000000 -0700
+++ mysql-5.0.25-nightly-20060823.host_cache04/sql/sql_prepare.cc 2006-09-25 21:36:51.000000000 -0700
@@ -1735,6 +1735,7 @@
case SQLCOM_SHOW_VARIABLES:
case SQLCOM_SHOW_LOGS:
case SQLCOM_SHOW_TABLES:
+ case SQLCOM_SHOW_HOST_CACHE:
case SQLCOM_SHOW_OPEN_TABLES:
case SQLCOM_SHOW_CHARSETS:
case SQLCOM_SHOW_COLLATIONS:
diff -Nur mysql-5.0.25-nightly-20060823.host_cache03/sql/sql_show.cc mysql-5.0.25-nightly-20060823.host_cache04/sql/sql_show.cc
--- mysql-5.0.25-nightly-20060823.host_cache03/sql/sql_show.cc 2006-09-25 21:16:07.000000000 -0700
+++ mysql-5.0.25-nightly-20060823.host_cache04/sql/sql_show.cc 2006-09-26 10:47:41.000000000 -0700
@@ -47,6 +47,53 @@
view_store_create_info(THD *thd, TABLE_LIST *table, String *buff);
static bool schema_table_store_record(THD *thd, TABLE *table);
+int mysqld_show_host_cache(THD *thd)
+{
+ List<Item> field_list;
+ Protocol *protocol= thd->protocol;
+ Item *item;
+
+ char ip[16];
+ host_entry *cur;
+
+ DBUG_ENTER("mysqld_show_host_cache");
+
+ field_list.push_back(new Item_empty_string("IP", 15));
+ field_list.push_back(item= new Item_empty_string("Hostname", 255));
+ item->maybe_null= 1;
+ field_list.push_back(new Item_return_int("Errors", 10,
+ MYSQL_TYPE_LONG));
+
+ if (protocol->send_fields(&field_list,
+ Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
+ DBUG_RETURN(TRUE);
+
+ (void) pthread_mutex_lock(&hostname_cache->lock);
+
+ for(cur= (host_entry *) hostname_cache->newest_element();
+ cur; cur= (host_entry *) cur->older_element())
+ {
+ uint32 nip = htonl(cur->ip);
+ sprintf(ip, "%u.%u.%u.%u",
+ (unsigned char)(nip>>24), (unsigned char)(nip>>16),
+ (unsigned char)(nip>> 8), (unsigned char)(nip));
+ protocol->prepare_for_resend();
+ protocol->store(ip, system_charset_info);
+ if(cur->hostname)
+ protocol->store(cur->hostname, system_charset_info);
+ else
+ protocol->store_null();
+ protocol->store((uint)cur->errors);
+ if(protocol->write())
+ DBUG_RETURN(TRUE);
+ }
+
+ (void) pthread_mutex_unlock(&hostname_cache->lock);
+
+ send_eof(thd);
+ DBUG_RETURN(FALSE);
+}
+
/***************************************************************************
** List all table types supported
diff -Nur mysql-5.0.25-nightly-20060823.host_cache03/sql/sql_yacc.yy mysql-5.0.25-nightly-20060823.host_cache04/sql/sql_yacc.yy
--- mysql-5.0.25-nightly-20060823.host_cache03/sql/sql_yacc.yy 2006-09-25 21:16:06.000000000 -0700
+++ mysql-5.0.25-nightly-20060823.host_cache04/sql/sql_yacc.yy 2006-09-25 21:44:07.000000000 -0700
@@ -314,6 +314,7 @@
%token HELP_SYM
%token HEX_NUM
%token HIGH_PRIORITY
+%token HOST_SYM
%token HOSTS_SYM
%token HOUR_MICROSECOND_SYM
%token HOUR_MINUTE_SYM
@@ -6412,6 +6413,11 @@
if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLES))
YYABORT;
}
+ | HOST_SYM CACHE_SYM
+ {
+ LEX *lex= Lex;
+ lex->sql_command= SQLCOM_SHOW_HOST_CACHE;
+ }
| OPEN_SYM TABLES opt_db wild_and_where
{
LEX *lex= Lex;
@@ -7619,6 +7625,7 @@
| GRANTS {}
| GLOBAL_SYM {}
| HASH_SYM {}
+ | HOST_SYM {}
| HOSTS_SYM {}
| HOUR_SYM {}
| IDENTIFIED_SYM {}