@@ -40,6 +40,108 @@ class MySrvC;
40
40
class MySrvList ;
41
41
class MyHGC ;
42
42
43
+ /*
44
+ class HGM_query_errors_stats {
45
+ public:
46
+ int hid;
47
+ char *hostname;
48
+ int port;
49
+ char *username;
50
+ char *schemaname;
51
+ int error_no;
52
+ unsigned int count_star;
53
+ time_t first_seen;
54
+ time_t last_seen;
55
+ char *last_error;
56
+ HGM_query_errors_stats(int _h, char *_hn, int _p, char *u, char *s, int e, char *le) {
57
+ hid=_h;
58
+ hostname=strdup(_hn);
59
+ port=_p;
60
+ username=strdup(u);
61
+ schemaname=strdup(s);
62
+ error_no=e;
63
+ last_error=strdup(le);
64
+ count_star=0;
65
+ first_seen=0;
66
+ last_seen=0;
67
+ }
68
+ void add_time(unsigned long long n, char *le) {
69
+ count_star++;
70
+ if (first_seen==0) {
71
+ first_seen=n;
72
+ }
73
+ last_seen=n;
74
+ if (strcmp(last_error,le)){
75
+ free(last_error);
76
+ last_error=strdup(le);
77
+ }
78
+ }
79
+ ~HGM_query_errors_stats() {
80
+ if (hostname) {
81
+ free(hostname);
82
+ hostname=NULL;
83
+ }
84
+ if (username) {
85
+ free(username);
86
+ username=NULL;
87
+ }
88
+ if (schemaname) {
89
+ free(schemaname);
90
+ schemaname=NULL;
91
+ }
92
+ if (last_error) {
93
+ free(last_error);
94
+ last_error=NULL;
95
+ }
96
+ }
97
+ char **get_row() {
98
+ char buf[128];
99
+ char **pta=(char **)malloc(sizeof(char *)*10);
100
+ sprintf(buf,"%d",hid);
101
+ pta[0]=strdup(buf);
102
+ assert(hostname);
103
+ pta[1]=strdup(hostname);
104
+ sprintf(buf,"%d",port);
105
+ pta[2]=strdup(buf);
106
+ assert(username);
107
+ pta[3]=strdup(username);
108
+ assert(schemaname);
109
+ pta[4]=strdup(schemaname);
110
+ sprintf(buf,"%d",error_no);
111
+ pta[5]=strdup(buf);
112
+
113
+ sprintf(buf,"%u",count_star);
114
+ pta[6]=strdup(buf);
115
+
116
+ time_t __now;
117
+ time(&__now);
118
+ unsigned long long curtime=monotonic_time();
119
+ time_t seen_time;
120
+
121
+ seen_time= __now - curtime/1000000 + first_seen/1000000;
122
+ sprintf(buf,"%ld", seen_time);
123
+ pta[7]=strdup(buf);
124
+
125
+ seen_time= __now - curtime/1000000 + last_seen/1000000;
126
+ sprintf(buf,"%ld", seen_time);
127
+ pta[8]=strdup(buf);
128
+
129
+ assert(last_error);
130
+ pta[9]=strdup(last_error);
131
+ return pta;
132
+ }
133
+ void free_row(char **pta) {
134
+ int i;
135
+ for (i=0;i<10;i++) {
136
+ assert(pta[i]);
137
+ free(pta[i]);
138
+ }
139
+ free(pta);
140
+ }
141
+ };
142
+
143
+ */
144
+
43
145
// static struct ev_async * gtid_ev_async;
44
146
45
147
static pthread_mutex_t ev_loop_mutex;
@@ -842,6 +944,9 @@ MySQL_HostGroups_Manager::MySQL_HostGroups_Manager() {
842
944
status.frontend_init_db =0 ;
843
945
status.frontend_set_names =0 ;
844
946
status.frontend_use_db =0 ;
947
+ status.access_denied_wrong_password =0 ;
948
+ status.access_denied_max_connections =0 ;
949
+ status.access_denied_max_user_connections =0 ;
845
950
pthread_mutex_init (&readonly_mutex, NULL );
846
951
pthread_mutex_init (&Group_Replication_Info_mutex, NULL );
847
952
pthread_mutex_init (&Galera_Info_mutex, NULL );
@@ -2392,7 +2497,7 @@ void MySQL_HostGroups_Manager::replication_lag_action(int _hid, char *address, u
2392
2497
// ||
2393
2498
(current_replication_lag>=0 && ((unsigned int )current_replication_lag > mysrvc->max_replication_lag ))
2394
2499
) {
2395
- proxy_warning (" Shunning server %s:%d with replication lag of %d second\n " , address, port, current_replication_lag);
2500
+ proxy_warning (" Shunning server %s:%d from HG %u with replication lag of %d second\n " , address, port, myhgc-> hid , current_replication_lag);
2396
2501
mysrvc->status =MYSQL_SERVER_STATUS_SHUNNED_REPLICATION_LAG;
2397
2502
}
2398
2503
} else {
@@ -2403,7 +2508,7 @@ void MySQL_HostGroups_Manager::replication_lag_action(int _hid, char *address, u
2403
2508
(current_replication_lag==-2 ) // see issue 959
2404
2509
) {
2405
2510
mysrvc->status =MYSQL_SERVER_STATUS_ONLINE;
2406
- proxy_warning (" Re-enabling server %s:%d with replication lag of %d second\n " , address, port, current_replication_lag);
2511
+ proxy_warning (" Re-enabling server %s:%d from HG %u with replication lag of %d second\n " , address, port, myhgc-> hid , current_replication_lag);
2407
2512
}
2408
2513
}
2409
2514
}
@@ -4371,13 +4476,14 @@ class MySQL_Errors_stats {
4371
4476
char *hostname;
4372
4477
int port;
4373
4478
char *username;
4479
+ char *client_address;
4374
4480
char *schemaname;
4375
4481
int err_no;
4376
4482
char *last_error;
4377
4483
time_t first_seen;
4378
4484
time_t last_seen;
4379
4485
unsigned long long count_star;
4380
- MySQL_Errors_stats (int hostgroup_, char *hostname_, int port_, char *username_, char *schemaname_, int err_no_, char *last_error_, time_t tn) {
4486
+ MySQL_Errors_stats (int hostgroup_, char *hostname_, int port_, char *username_, char *address_, char * schemaname_, int err_no_, char *last_error_, time_t tn) {
4381
4487
hostgroup = hostgroup_;
4382
4488
if (hostname_) {
4383
4489
hostname = strdup (hostname_);
@@ -4390,6 +4496,11 @@ class MySQL_Errors_stats {
4390
4496
} else {
4391
4497
username = strdup ((char *)" " );
4392
4498
}
4499
+ if (address_) {
4500
+ client_address = strdup (address_);
4501
+ } else {
4502
+ client_address = strdup ((char *)" " );
4503
+ }
4393
4504
if (schemaname_) {
4394
4505
schemaname = strdup (schemaname_);
4395
4506
} else {
@@ -4405,9 +4516,88 @@ class MySQL_Errors_stats {
4405
4516
first_seen = tn;
4406
4517
count_star = 1 ;
4407
4518
}
4519
+ ~MySQL_Errors_stats () {
4520
+ if (hostname) {
4521
+ free (hostname);
4522
+ hostname=NULL ;
4523
+ }
4524
+ if (username) {
4525
+ free (username);
4526
+ username=NULL ;
4527
+ }
4528
+ if (client_address) {
4529
+ free (client_address);
4530
+ client_address=NULL ;
4531
+ }
4532
+ if (schemaname) {
4533
+ free (schemaname);
4534
+ schemaname=NULL ;
4535
+ }
4536
+ if (last_error) {
4537
+ free (last_error);
4538
+ last_error=NULL ;
4539
+ }
4540
+ }
4541
+ char **get_row () {
4542
+ char buf[128 ];
4543
+ char **pta=(char **)malloc (sizeof (char *)*11 );
4544
+ sprintf (buf," %d" ,hostgroup);
4545
+ pta[0 ]=strdup (buf);
4546
+ assert (hostname);
4547
+ pta[1 ]=strdup (hostname);
4548
+ sprintf (buf," %d" ,port);
4549
+ pta[2 ]=strdup (buf);
4550
+ assert (username);
4551
+ pta[3 ]=strdup (username);
4552
+ assert (client_address);
4553
+ pta[4 ]=strdup (client_address);
4554
+ assert (schemaname);
4555
+ pta[5 ]=strdup (schemaname);
4556
+ sprintf (buf," %d" ,err_no);
4557
+ pta[6 ]=strdup (buf);
4558
+
4559
+ sprintf (buf," %llu" ,count_star);
4560
+ pta[7 ]=strdup (buf);
4561
+
4562
+ time_t __now;
4563
+ time (&__now);
4564
+ unsigned long long curtime=monotonic_time ();
4565
+ time_t seen_time;
4566
+
4567
+ seen_time= __now - curtime/1000000 + first_seen/1000000 ;
4568
+ sprintf (buf," %ld" , seen_time);
4569
+ pta[8 ]=strdup (buf);
4570
+
4571
+ seen_time= __now - curtime/1000000 + last_seen/1000000 ;
4572
+ sprintf (buf," %ld" , seen_time);
4573
+ pta[9 ]=strdup (buf);
4574
+
4575
+ assert (last_error);
4576
+ pta[10 ]=strdup (last_error);
4577
+ return pta;
4578
+ }
4579
+ void add_time (unsigned long long n, char *le) {
4580
+ count_star++;
4581
+ if (first_seen==0 ) {
4582
+ first_seen=n;
4583
+ }
4584
+ last_seen=n;
4585
+ if (strcmp (last_error,le)){
4586
+ free (last_error);
4587
+ last_error=strdup (le);
4588
+ }
4589
+ }
4590
+ void free_row (char **pta) {
4591
+ int i;
4592
+ for (i=0 ;i<11 ;i++) {
4593
+ assert (pta[i]);
4594
+ free (pta[i]);
4595
+ }
4596
+ free (pta);
4597
+ }
4408
4598
};
4409
4599
4410
- void MySQL_HostGroups_Manager::add_mysql_errors (int hostgroup, char *hostname, int port, char *username, char *schemaname, int err_no, char *last_error) {
4600
+ void MySQL_HostGroups_Manager::add_mysql_errors (int hostgroup, char *hostname, int port, char *username, char *address, char * schemaname, int err_no, char *last_error) {
4411
4601
SpookyHash myhash;
4412
4602
uint64_t hash1;
4413
4603
uint64_t hash2;
@@ -4426,6 +4616,10 @@ void MySQL_HostGroups_Manager::add_mysql_errors(int hostgroup, char *hostname, i
4426
4616
myhash.Update (username,strlen (username));
4427
4617
}
4428
4618
myhash.Update (rand_del,rand_del_len);
4619
+ if (address) {
4620
+ myhash.Update (address,strlen (address));
4621
+ }
4622
+ myhash.Update (rand_del,rand_del_len);
4429
4623
if (schemaname) {
4430
4624
myhash.Update (schemaname,strlen (schemaname));
4431
4625
}
@@ -4442,15 +4636,48 @@ void MySQL_HostGroups_Manager::add_mysql_errors(int hostgroup, char *hostname, i
4442
4636
if (it != mysql_errors_umap.end ()) {
4443
4637
// found
4444
4638
mes=(MySQL_Errors_stats *)it->second ;
4639
+ mes->add_time (tn, last_error);
4640
+ /*
4445
4641
mes->last_seen = tn;
4446
4642
if (strcmp(mes->last_error,last_error)) {
4447
4643
free(mes->last_error);
4448
4644
mes->last_error = strdup(last_error);
4449
4645
mes->count_star++;
4450
4646
}
4647
+ */
4451
4648
} else {
4452
- mes = new MySQL_Errors_stats (hostgroup, hostname, port, username, schemaname, err_no, last_error, tn);
4649
+ mes = new MySQL_Errors_stats (hostgroup, hostname, port, username, address, schemaname, err_no, last_error, tn);
4453
4650
mysql_errors_umap.insert (std::make_pair (hash1,(void *)mes));
4454
4651
}
4455
4652
pthread_mutex_unlock (&mysql_errors_mutex);
4456
4653
}
4654
+
4655
+ SQLite3_result * MySQL_HostGroups_Manager::get_mysql_errors (bool reset) {
4656
+ SQLite3_result *result=new SQLite3_result (11 );
4657
+ pthread_mutex_lock (&mysql_errors_mutex);
4658
+ result->add_column_definition (SQLITE_TEXT," hid" );
4659
+ result->add_column_definition (SQLITE_TEXT," hostname" );
4660
+ result->add_column_definition (SQLITE_TEXT," port" );
4661
+ result->add_column_definition (SQLITE_TEXT," username" );
4662
+ result->add_column_definition (SQLITE_TEXT," client_address" );
4663
+ result->add_column_definition (SQLITE_TEXT," schemaname" );
4664
+ result->add_column_definition (SQLITE_TEXT," err_no" );
4665
+ result->add_column_definition (SQLITE_TEXT," count_star" );
4666
+ result->add_column_definition (SQLITE_TEXT," first_seen" );
4667
+ result->add_column_definition (SQLITE_TEXT," last_seen" );
4668
+ result->add_column_definition (SQLITE_TEXT," last_error" );
4669
+ for (std::unordered_map<uint64_t , void *>::iterator it=mysql_errors_umap.begin (); it!=mysql_errors_umap.end (); ++it) {
4670
+ MySQL_Errors_stats *mes=(MySQL_Errors_stats *)it->second ;
4671
+ char **pta=mes->get_row ();
4672
+ result->add_row (pta);
4673
+ mes->free_row (pta);
4674
+ if (reset) {
4675
+ delete mes;
4676
+ }
4677
+ }
4678
+ if (reset) {
4679
+ mysql_errors_umap.erase (mysql_errors_umap.begin (),mysql_errors_umap.end ());
4680
+ }
4681
+ pthread_mutex_unlock (&mysql_errors_mutex);
4682
+ return result;
4683
+ }
0 commit comments