forked from bluethinking/InnoSQL
-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathmysql-5.5.20.role_table_user_profiler.patch
More file actions
4983 lines (4811 loc) · 175 KB
/
mysql-5.5.20.role_table_user_profiler.patch
File metadata and controls
4983 lines (4811 loc) · 175 KB
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Index: include/my_base.h
===================================================================
--- include/my_base.h (revision 643)
+++ include/my_base.h (working copy)
@@ -449,7 +449,16 @@
#define HA_ERR_INDEX_COL_TOO_LONG 178 /* Index column length exceeds limit */
#define HA_ERR_INDEX_CORRUPT 179 /* Index corrupted */
#define HA_ERR_UNDO_REC_TOO_BIG 180 /* Undo log record too big */
-#define HA_ERR_LAST 180 /* Copy of last error nr */
+#define HA_ERR_CPU_TIMES_LIMITED 181
+#define HA_ERR_IO_READS_LIMITED 182
+#define HA_ERR_TRX_CPU_TIMES_LIMITED 183
+#define HA_ERR_TRX_IO_READS_LIMITED 184
+#define HA_ERR_PROFILER_ACCESS_DENIED 185
+#define HA_ERR_PROFILE_ALREADY_EXISTS 186
+#define HA_ERR_PROFILE_DOESNOT_EXIST 187
+#define HA_ERR_ROLE_DOESNOT_EXIST 188
+#define HA_ERR_GRANT_ROLE_TO_USER 189
+#define HA_ERR_LAST 189 /* Copy of last error nr */
/* Number of different errors */
#define HA_ERR_ERRORS (HA_ERR_LAST - HA_ERR_FIRST + 1)
Index: include/my_sys.h
===================================================================
--- include/my_sys.h (revision 643)
+++ include/my_sys.h (working copy)
@@ -150,6 +150,11 @@
#define GETDATE_FIXEDLENGTH 16
/* defines when allocating data */
+typedef void (*malloc_callback)(size_t size);
+typedef void (*free_callback)(size_t size);
+extern void set_malloc_callback(malloc_callback func);
+extern void set_free_callback(free_callback func);
+
extern void *my_malloc(size_t Size,myf MyFlags);
extern void *my_multi_malloc(myf MyFlags, ...);
extern void *my_realloc(void *oldpoint, size_t Size, myf MyFlags);
Index: include/mysql_com.h
===================================================================
--- include/mysql_com.h (revision 643)
+++ include/mysql_com.h (working copy)
@@ -145,6 +145,9 @@
#define REFRESH_QUERY_CACHE_FREE 0x20000L /* pack query cache */
#define REFRESH_DES_KEY_FILE 0x40000L
#define REFRESH_USER_RESOURCES 0x80000L
+#define REFRESH_PROFILE_IO 0x100000L
+#define REFRESH_PROFILE_CPU 0x200000L
+#define REFRESH_PROFILE_ALL 0x400000L
#define CLIENT_LONG_PASSWORD 1 /* new more secure passwords */
#define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */
Index: mysys/my_handler_errors.h
===================================================================
--- mysys/my_handler_errors.h (revision 643)
+++ mysys/my_handler_errors.h (working copy)
@@ -83,7 +83,16 @@
"Too many active concurrent transactions",
"Index column length exceeds limit",
"Index corrupted",
- "Undo record too big"
+ "Undo record too big",
+ "User's CPU resource is exhausted",
+ "User's IO resource is exhausted",
+ "Current trx CPU times is more than the user limited, the trx will be rollback",
+ "Current trx IO reads is more than the user limited, the trx will be rollback",
+ "Failed to access the user_profiler table with no super privilege",
+ "Profile already exists",
+ "Profile doesn't exist",
+ "Role doesn't exist",
+ "Grant role to user with check option error"
};
extern void my_handler_error_register(void);
Index: mysys/my_malloc.c
===================================================================
--- mysys/my_malloc.c (revision 643)
+++ mysys/my_malloc.c (working copy)
@@ -17,6 +17,22 @@
#include "mysys_err.h"
#include <m_string.h>
+
+malloc_callback malloc_callback_func = NULL;
+free_callback free_callback_func = NULL;
+#ifdef __WIN__
+#define malloc_usable_size(ptr) _msize(ptr)
+#endif
+
+void set_malloc_callback(malloc_callback func)
+{
+ malloc_callback_func = func;
+}
+
+void set_free_callback(free_callback func)
+{
+ free_callback_func = func;
+}
/**
Allocate a sized block of memory.
@@ -55,7 +71,13 @@
exit(1);
}
else if (my_flags & MY_ZEROFILL)
+ {
bzero(point, size);
+ }
+ if(malloc_callback_func && point)
+ {
+ malloc_callback_func(malloc_usable_size(point));
+ }
DBUG_PRINT("exit",("ptr: %p", point));
DBUG_RETURN(point);
}
@@ -125,6 +147,8 @@
{
DBUG_ENTER("my_free");
DBUG_PRINT("my",("ptr: %p", ptr));
+ if(free_callback_func != NULL && ptr != NULL)
+ free_callback_func(malloc_usable_size(ptr));
free(ptr);
DBUG_VOID_RETURN;
}
Index: scripts/mysql_system_tables.sql
===================================================================
--- scripts/mysql_system_tables.sql (revision 643)
+++ scripts/mysql_system_tables.sql (working copy)
@@ -28,12 +28,22 @@
CREATE TABLE IF NOT EXISTS host ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,Db) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Host privileges; Merged with database privileges';
-CREATE TABLE IF NOT EXISTS user ( Host char(60) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Password char(41) character set latin1 collate latin1_bin DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Reload_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Shutdown_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Process_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, File_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_db_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Super_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_slave_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_client_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_user_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tablespace_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, ssl_type enum('','ANY','X509', 'SPECIFIED') COLLATE utf8_general_ci DEFAULT '' NOT NULL, ssl_cipher BLOB NOT NULL, x509_issuer BLOB NOT NULL, x509_subject BLOB NOT NULL, max_questions int(11) unsigned DEFAULT 0 NOT NULL, max_updates int(11) unsigned DEFAULT 0 NOT NULL, max_connections int(11) unsigned DEFAULT 0 NOT NULL, max_user_connections int(11) unsigned DEFAULT 0 NOT NULL, plugin char(64) DEFAULT '', authentication_string TEXT, PRIMARY KEY Host (Host,User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Users and global privileges';
+CREATE TABLE IF NOT EXISTS user ( Host char(60) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Password char(41) character set latin1 collate latin1_bin DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Reload_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Shutdown_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Process_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, File_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_db_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Super_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_slave_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_client_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_user_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tablespace_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL,Profile_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, ssl_type enum('','ANY','X509', 'SPECIFIED') COLLATE utf8_general_ci DEFAULT '' NOT NULL, ssl_cipher BLOB NOT NULL, x509_issuer BLOB NOT NULL, x509_subject BLOB NOT NULL, max_questions int(11) unsigned DEFAULT 0 NOT NULL, max_updates int(11) unsigned DEFAULT 0 NOT NULL, max_connections int(11) unsigned DEFAULT 0 NOT NULL, max_user_connections int(11) unsigned DEFAULT 0 NOT NULL, plugin char(64) DEFAULT '', authentication_string TEXT, profile_name char(64) DEFAULT '' NOT NULL, role_name char(64) DEFAULT '' NOT NULL, PRIMARY KEY Host (Host,User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Users and global privileges';
-- Remember for later if user table already existed
set @had_user_table= @@warning_count != 0;
+CREATE TABLE IF NOT EXISTS roles_priv (role_name char(16) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Reload_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Shutdown_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Process_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, File_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_db_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Super_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_slave_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_client_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_user_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tablespace_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL,Profile_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY role_key (role_name) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='roles privileges';
+CREATE TABLE IF NOT EXISTS user_profiler( Profile_name char(64) binary DEFAULT '' NOT NULL, Max_cpu_times int(11) unsigned DEFAULT 0 NOT NULL, Max_io_reads int(11) unsigned DEFAULT 0 NOT NULL, Max_mem_size int(11) unsigned DEFAULT 0 NOT NULL, Max_cpu_times_per_trx int(11) unsigned DEFAULT 0 NOT NULL, Max_io_reads_per_trx int(11) unsigned DEFAULT 0 NOT NULL, PRIMARY KEY (Profile_name)) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Users profiler';
+
+-- Remember for later if user_profiler table already existed
+set @had_user_profiler_table= @@warning_count != 0;
+
+CREATE TABLE IF NOT EXISTS current_user_exhaust( Host char(60) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL,curr_cpu_times int(11) unsigned DEFAULT 0 NOT NULL,curr_io_reads int(11) unsigned DEFAULT 0 NOT NULL,PRIMARY KEY Host(Host,User)) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='current_user_exhaust';
+-- Remember for later if current_user_exhaust table already existed
+set @had_current_user_exhaust= @@warning_count != 0;
+
CREATE TABLE IF NOT EXISTS func ( name char(64) binary DEFAULT '' NOT NULL, ret tinyint(1) DEFAULT '0' NOT NULL, dl char(128) DEFAULT '' NOT NULL, type enum ('function','aggregate') COLLATE utf8_general_ci NOT NULL, PRIMARY KEY (name) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='User defined functions';
Index: scripts/mysql_system_tables_data.sql
===================================================================
--- scripts/mysql_system_tables_data.sql (revision 643)
+++ scripts/mysql_system_tables_data.sql (working copy)
@@ -36,10 +36,10 @@
-- from local machine if "users" table didn't exist before
CREATE TEMPORARY TABLE tmp_user LIKE user;
set @current_hostname= @@hostname;
-INSERT INTO tmp_user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'','');
-REPLACE INTO tmp_user SELECT @current_hostname,'root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'','' FROM dual WHERE LOWER( @current_hostname) != 'localhost';
-REPLACE INTO tmp_user VALUES ('127.0.0.1','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'','');
-REPLACE INTO tmp_user VALUES ('::1','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'','');
+INSERT INTO tmp_user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'','','','');
+REPLACE INTO tmp_user SELECT @current_hostname,'root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'','','','' FROM dual WHERE LOWER( @current_hostname) != 'localhost';
+REPLACE INTO tmp_user VALUES ('127.0.0.1','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'','','','');
+REPLACE INTO tmp_user VALUES ('::1','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'','','','');
INSERT INTO tmp_user (host,user) VALUES ('localhost','');
INSERT INTO tmp_user (host,user) SELECT @current_hostname,'' FROM dual WHERE LOWER(@current_hostname ) != 'localhost';
INSERT INTO user SELECT * FROM tmp_user WHERE @had_user_table=0;
Index: sql/CMakeLists.txt
===================================================================
--- sql/CMakeLists.txt (revision 643)
+++ sql/CMakeLists.txt (working copy)
@@ -76,6 +76,7 @@
sql_profile.cc event_parse_data.cc sql_alter.cc
sql_signal.cc rpl_handler.cc mdl.cc sql_admin.cc
transaction.cc sys_vars.cc sql_truncate.cc datadict.cc
+ resource_profiler.cc
sql_reload.cc
${GEN_SOURCES}
${MYSYS_LIBWRAP_SOURCE})
Index: sql/filesort.cc
===================================================================
--- sql/filesort.cc (revision 643)
+++ sql/filesort.cc (working copy)
@@ -33,7 +33,7 @@
#include "sql_test.h" // TEST_filesort
#include "opt_range.h" // SQL_SELECT
#include "debug_sync.h"
-
+#include "resource_profiler.h"
/// How to write record_ref.
#define WRITE_REF(file,from) \
if (my_b_write((file),(uchar*) (from),param->ref_length)) \
@@ -610,7 +610,7 @@
if (error && error != HA_ERR_RECORD_DELETED)
break;
}
-
+ resource_statistics(0);
if (*killed)
{
DBUG_PRINT("info",("Sort killed by user"));
@@ -1289,6 +1289,10 @@
}
for (;;)
{
+ if(resource_statistics(0) != 0)
+ {
+ error = 1; goto err;
+ }
buffpek= (BUFFPEK*) queue_top(&queue);
if (cmp) // Remove duplicates
{
@@ -1353,6 +1357,10 @@
do
{
+ if(resource_statistics(0) != 0)
+ {
+ error = 1; goto err;
+ }
if ((ha_rows) buffpek->mem_count > max_rows)
{ /* Don't write too many records */
buffpek->mem_count= (uint) max_rows;
Index: sql/handler.cc
===================================================================
--- sql/handler.cc (revision 643)
+++ sql/handler.cc (working copy)
@@ -40,6 +40,7 @@
#include <errno.h>
#include "probes_mysql.h"
#include "debug_sync.h" // DEBUG_SYNC
+#include "resource_profiler.h"
#ifdef WITH_PARTITION_STORAGE_ENGINE
#include "ha_partition.h"
@@ -459,6 +460,7 @@
}
hton->slot= HA_SLOT_UNDEF;
+ hton->resource_profiler_ptr = resource_statistics;
/* Historical Requirement */
plugin->data= hton; // shortcut for the future
if (plugin->plugin->init && plugin->plugin->init(hton))
@@ -2878,6 +2880,33 @@
case HA_ERR_UNDO_REC_TOO_BIG:
textno= ER_UNDO_RECORD_TOO_BIG;
break;
+ case HA_ERR_CPU_TIMES_LIMITED:
+ textno = ER_CPU_TIMES_LIMITED;
+ break;
+ case HA_ERR_IO_READS_LIMITED:
+ textno = ER_IO_READS_LIMITED;
+ break;
+ case HA_ERR_TRX_CPU_TIMES_LIMITED:
+ textno = ER_TRX_CPU_TIMES_LIMITED;
+ break;
+ case HA_ERR_TRX_IO_READS_LIMITED:
+ textno = ER_TRX_IO_READS_LIMITED;
+ break;
+ case HA_ERR_PROFILER_ACCESS_DENIED:
+ textno = ER_PROFILER_ACCESS_DENIED;
+ break;
+ case HA_ERR_PROFILE_ALREADY_EXISTS:
+ textno = ER_PROFILE_ALREADY_EXISTS;
+ break;
+ case HA_ERR_PROFILE_DOESNOT_EXIST:
+ textno = ER_PROFILE_DOESNOT_EXIST;
+ break;
+ case HA_ERR_ROLE_DOESNOT_EXIST:
+ textno = ER_ROLE_DOESNOT_EXIST;
+ break;
+ case HA_ERR_GRANT_ROLE_TO_USER:
+ textno = ER_GRANT_ROLE_TO_USER;
+ break;
default:
{
/* The error was "unknown" to this function.
Index: sql/handler.h
===================================================================
--- sql/handler.h (revision 643)
+++ sql/handler.h (working copy)
@@ -800,6 +800,7 @@
const char *wild, bool dir, List<LEX_STRING> *files);
int (*table_exists_in_engine)(handlerton *hton, THD* thd, const char *db,
const char *name);
+ int (*resource_profiler_ptr)(int with_io_read);
uint32 license; /* Flag for Engine License */
void *data; /* Location for engines to keep personal structures */
};
Index: sql/lex.h
===================================================================
--- sql/lex.h (revision 643)
+++ sql/lex.h (working copy)
@@ -333,6 +333,10 @@
{ "MASTER_HEARTBEAT_PERIOD", SYM(MASTER_HEARTBEAT_PERIOD_SYM)},
{ "MATCH", SYM(MATCH)},
{ "MAX_CONNECTIONS_PER_HOUR", SYM(MAX_CONNECTIONS_PER_HOUR)},
+ { "MAX_CPU_TIMES_PROFILE", SYM(MAX_CPU_TIMES_PROFILE)},
+ { "MAX_CPU_TIMES_PER_TRX_PROFILE", SYM(MAX_CPU_TIMES_PER_TRX_PROFILE)},
+ { "MAX_IO_READS_PROFILE", SYM(MAX_IO_READS_PROFILE)},
+ { "MAX_IO_READS_PER_TRX_PROFILE", SYM(MAX_IO_READS_PER_TRX_PROFILE)},
{ "MAX_QUERIES_PER_HOUR", SYM(MAX_QUERIES_PER_HOUR)},
{ "MAX_ROWS", SYM(MAX_ROWS)},
{ "MAX_SIZE", SYM(MAX_SIZE_SYM)},
@@ -466,6 +470,7 @@
{ "REVOKE", SYM(REVOKE)},
{ "RIGHT", SYM(RIGHT)},
{ "RLIKE", SYM(REGEXP)}, /* Like in mSQL2 */
+ { "ROLE", SYM(ROLE_SYM)},
{ "ROLLBACK", SYM(ROLLBACK_SYM)},
{ "ROLLUP", SYM(ROLLUP_SYM)},
{ "ROUTINE", SYM(ROUTINE_SYM)},
Index: sql/mysqld.cc
===================================================================
--- sql/mysqld.cc (revision 643)
+++ sql/mysqld.cc (working copy)
@@ -91,7 +91,7 @@
#include "sp_rcontext.h"
#include "sp_cache.h"
#include "sql_reload.h" // reload_acl_and_cache
-
+#include "resource_profiler.h"
#ifdef HAVE_POLL_H
#include <poll.h>
#endif
@@ -356,6 +356,8 @@
bool opt_bin_log, opt_ignore_builtin_innodb= 0;
my_bool opt_log, opt_slow_log;
+my_bool opt_use_profile_limitted, opt_use_profile_repl;
+uint opt_profiler_record;
ulonglong log_output_options;
my_bool opt_log_queries_not_using_indexes= 0;
bool opt_error_log= IF_WIN(1,0);
@@ -625,7 +627,7 @@
LOCK_delayed_insert, LOCK_delayed_status, LOCK_delayed_create,
LOCK_crypt,
LOCK_global_system_variables,
- LOCK_user_conn, LOCK_slave_list, LOCK_active_mi,
+ LOCK_user_conn, LOCK_curr_resources, LOCK_profile_resources,LOCK_slave_list, LOCK_active_mi,
LOCK_connection_count, LOCK_error_messages;
/**
The below lock protects access to two global server variables:
@@ -639,6 +641,7 @@
mysql_mutex_t LOCK_des_key_file;
#endif
mysql_rwlock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave;
+mysql_rwlock_t LOCK_profile;
mysql_rwlock_t LOCK_system_variables_hash;
mysql_cond_t COND_thread_count;
pthread_t signal_thread;
@@ -1482,6 +1485,9 @@
my_free(opt_bin_logname);
bitmap_free(&temp_pool);
free_max_user_conn();
+ free_max_curr_resources();
+ free_max_profile_resources();
+ //free_max_curr_resources();
#ifdef HAVE_REPLICATION
end_slave_list();
#endif
@@ -1551,6 +1557,7 @@
static void clean_up_mutexes()
{
+ mysql_rwlock_destroy(&LOCK_profile);
mysql_rwlock_destroy(&LOCK_grant);
mysql_mutex_destroy(&LOCK_thread_count);
mysql_mutex_destroy(&LOCK_status);
@@ -2835,9 +2842,11 @@
{"alter_event", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_EVENT]), SHOW_LONG_STATUS},
{"alter_function", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_FUNCTION]), SHOW_LONG_STATUS},
{"alter_procedure", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_PROCEDURE]), SHOW_LONG_STATUS},
+ {"alter_profile", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_PROFILE]), SHOW_LONG_STATUS},
{"alter_server", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_SERVER]), SHOW_LONG_STATUS},
{"alter_table", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_TABLE]), SHOW_LONG_STATUS},
{"alter_tablespace", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_TABLESPACE]), SHOW_LONG_STATUS},
+ {"alter_user_profile", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_USER_PROFILE]), SHOW_LONG_STATUS},
{"analyze", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ANALYZE]), SHOW_LONG_STATUS},
{"begin", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_BEGIN]), SHOW_LONG_STATUS},
{"binlog", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_BINLOG_BASE64_EVENT]), SHOW_LONG_STATUS},
@@ -2852,6 +2861,8 @@
{"create_function", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_SPFUNCTION]), SHOW_LONG_STATUS},
{"create_index", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_INDEX]), SHOW_LONG_STATUS},
{"create_procedure", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_PROCEDURE]), SHOW_LONG_STATUS},
+ {"create_profile", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_PROFILE]), SHOW_LONG_STATUS},
+ {"create_role", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_ROLE]), SHOW_LONG_STATUS},
{"create_server", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_SERVER]), SHOW_LONG_STATUS},
{"create_table", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_TABLE]), SHOW_LONG_STATUS},
{"create_trigger", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_TRIGGER]), SHOW_LONG_STATUS},
@@ -2867,6 +2878,8 @@
{"drop_function", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DROP_FUNCTION]), SHOW_LONG_STATUS},
{"drop_index", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DROP_INDEX]), SHOW_LONG_STATUS},
{"drop_procedure", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DROP_PROCEDURE]), SHOW_LONG_STATUS},
+ {"drop_profile", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DROP_PROFILE]), SHOW_LONG_STATUS},
+ {"drop_role", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DROP_ROLE]), SHOW_LONG_STATUS},
{"drop_server", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DROP_SERVER]), SHOW_LONG_STATUS},
{"drop_table", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DROP_TABLE]), SHOW_LONG_STATUS},
{"drop_trigger", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DROP_TRIGGER]), SHOW_LONG_STATUS},
@@ -2876,6 +2889,7 @@
{"execute_sql", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_EXECUTE]), SHOW_LONG_STATUS},
{"flush", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_FLUSH]), SHOW_LONG_STATUS},
{"grant", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_GRANT]), SHOW_LONG_STATUS},
+ {"grant_role", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_GRANT_ROLE]), SHOW_LONG_STATUS},
{"ha_close", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_HA_CLOSE]), SHOW_LONG_STATUS},
{"ha_open", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_HA_OPEN]), SHOW_LONG_STATUS},
{"ha_read", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_HA_READ]), SHOW_LONG_STATUS},
@@ -2901,6 +2915,7 @@
{"resignal", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_RESIGNAL]), SHOW_LONG_STATUS},
{"revoke", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_REVOKE]), SHOW_LONG_STATUS},
{"revoke_all", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_REVOKE_ALL]), SHOW_LONG_STATUS},
+ {"revoke_role", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_REVOKE_ROLE]), SHOW_LONG_STATUS},
{"rollback", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ROLLBACK]), SHOW_LONG_STATUS},
{"rollback_to_savepoint",(char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ROLLBACK_TO_SAVEPOINT]), SHOW_LONG_STATUS},
{"savepoint", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SAVEPOINT]), SHOW_LONG_STATUS},
@@ -3446,6 +3461,8 @@
&LOCK_manager, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_LOCK_crypt, &LOCK_crypt, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_LOCK_user_conn, &LOCK_user_conn, MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_LOCK_curr_resources, &LOCK_curr_resources, MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_LOCK_profile_resources, &LOCK_profile_resources, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_LOCK_active_mi, &LOCK_active_mi, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_LOCK_global_system_variables,
&LOCK_global_system_variables, MY_MUTEX_INIT_FAST);
@@ -3477,6 +3494,7 @@
mysql_rwlock_init(key_rwlock_LOCK_sys_init_connect, &LOCK_sys_init_connect);
mysql_rwlock_init(key_rwlock_LOCK_sys_init_slave, &LOCK_sys_init_slave);
mysql_rwlock_init(key_rwlock_LOCK_grant, &LOCK_grant);
+ mysql_rwlock_init(key_rwlock_LOCK_profile, &LOCK_profile);
mysql_cond_init(key_COND_thread_count, &COND_thread_count, NULL);
mysql_cond_init(key_COND_thread_cache, &COND_thread_cache, NULL);
mysql_cond_init(key_COND_flush_thread_cache, &COND_flush_thread_cache, NULL);
@@ -3989,6 +4007,8 @@
ft_init_stopwords();
init_max_user_conn();
+ init_max_curr_resources();
+ init_max_profile_resources();
init_update_queries();
DBUG_RETURN(0);
}
@@ -4425,7 +4445,8 @@
unlink(mysqld_unix_port);
exit(1);
}
-
+ set_malloc_callback(my_malloc_callback_func);
+ set_free_callback(my_free_callback_func);
if (!opt_noacl)
(void) grant_init();
@@ -6001,6 +6022,36 @@
return 0;
}
+static int show_cpu_times(THD *thd, SHOW_VAR *var, char *buff)
+{
+ var->type = SHOW_CHAR;
+ if(thd->user_connect && thd->user_connect->user_resources.profile)
+ sprintf(buff,"%llu/%llu",thd->user_connect->curr_resources->curr_cpu_times,thd->user_connect->user_resources.profile->cpu_times);
+ else
+ sprintf(buff,"%d/%d",0,0);
+ var->value = buff;
+ return 0;
+}
+
+static int show_io_used(THD *thd, SHOW_VAR *var, char *buff)
+{
+ var->type = SHOW_CHAR;
+ if(thd->user_connect && thd->user_connect->user_resources.profile)
+ sprintf(buff,"%llu/%llu",thd->user_connect->curr_resources->curr_io_reads,thd->user_connect->user_resources.profile->io_reads);
+ else
+ sprintf(buff,"%u/%u",0,0);
+ var->value = buff;
+ return 0;
+}
+
+static int show_mem_size(THD *thd, SHOW_VAR *var, char *buff)
+{
+ var->type = SHOW_CHAR;
+ sprintf(buff,"%u/%u",thd->mem_size,thd->max_mem_size);
+ var->value = buff;
+ return 0;
+}
+
#ifdef ENABLED_PROFILING
static int show_flushstatustime(THD *thd, SHOW_VAR *var, char *buff)
{
@@ -6504,6 +6555,9 @@
#ifdef ENABLED_PROFILING
{"Uptime_since_flush_status",(char*) &show_flushstatustime, SHOW_FUNC},
#endif
+ {"Threads_cpu_times_used", (char*) &show_cpu_times, SHOW_FUNC},
+ {"Threads_io_used", (char*) &show_io_used, SHOW_FUNC},
+ {"Threads_mem_size", (char*) &show_mem_size, SHOW_FUNC},
{NullS, NullS, SHOW_LONG}
};
@@ -7678,7 +7732,7 @@
key_LOCK_prepared_stmt_count,
key_LOCK_rpl_status, key_LOCK_server_started, key_LOCK_status,
key_LOCK_system_variables_hash, key_LOCK_table_share, key_LOCK_thd_data,
- key_LOCK_user_conn, key_LOCK_uuid_generator, key_LOG_LOCK_log,
+ key_LOCK_user_conn,key_LOCK_curr_resources ,key_LOCK_profile_resources, key_LOCK_uuid_generator, key_LOG_LOCK_log,
key_master_info_data_lock, key_master_info_run_lock,
key_mutex_slave_reporting_capability_err_lock, key_relay_log_info_data_lock,
key_relay_log_info_log_space_lock, key_relay_log_info_run_lock,
@@ -7723,6 +7777,8 @@
{ &key_LOCK_table_share, "LOCK_table_share", PSI_FLAG_GLOBAL},
{ &key_LOCK_thd_data, "THD::LOCK_thd_data", 0},
{ &key_LOCK_user_conn, "LOCK_user_conn", PSI_FLAG_GLOBAL},
+ { &key_LOCK_curr_resources, "LOCK_curr_resources", PSI_FLAG_GLOBAL},
+ { &key_LOCK_profile_resources, "LOCK_profile_resources", PSI_FLAG_GLOBAL},
{ &key_LOCK_uuid_generator, "LOCK_uuid_generator", PSI_FLAG_GLOBAL},
{ &key_LOG_LOCK_log, "LOG::LOCK_log", 0},
{ &key_master_info_data_lock, "Master_info::data_lock", 0},
@@ -7739,7 +7795,7 @@
{ &key_PARTITION_LOCK_auto_inc, "HA_DATA_PARTITION::LOCK_auto_inc", 0}
};
-PSI_rwlock_key key_rwlock_LOCK_grant, key_rwlock_LOCK_logger,
+PSI_rwlock_key key_rwlock_LOCK_grant, key_rwlock_LOCK_logger,key_rwlock_LOCK_profile,
key_rwlock_LOCK_sys_init_connect, key_rwlock_LOCK_sys_init_slave,
key_rwlock_LOCK_system_variables_hash, key_rwlock_query_cache_query_lock;
@@ -7749,6 +7805,7 @@
{ &key_rwlock_openssl, "CRYPTO_dynlock_value::lock", 0},
#endif
{ &key_rwlock_LOCK_grant, "LOCK_grant", PSI_FLAG_GLOBAL},
+ { &key_rwlock_LOCK_profile, "LOCK_profile", PSI_FLAG_GLOBAL},
{ &key_rwlock_LOCK_logger, "LOGGER::LOCK_logger", 0},
{ &key_rwlock_LOCK_sys_init_connect, "LOCK_sys_init_connect", PSI_FLAG_GLOBAL},
{ &key_rwlock_LOCK_sys_init_slave, "LOCK_sys_init_slave", PSI_FLAG_GLOBAL},
Index: sql/mysqld.h
===================================================================
--- sql/mysqld.h (revision 643)
+++ sql/mysqld.h (working copy)
@@ -88,7 +88,8 @@
extern MY_BITMAP temp_pool;
extern bool opt_large_files, server_id_supplied;
extern bool opt_update_log, opt_bin_log, opt_error_log;
-extern my_bool opt_log, opt_slow_log;
+extern my_bool opt_log, opt_slow_log, opt_use_profile_limitted, opt_use_profile_repl;
+extern uint opt_profiler_record;
extern my_bool opt_backup_history_log;
extern my_bool opt_backup_progress_log;
extern ulonglong log_output_options;
@@ -242,7 +243,8 @@
key_LOCK_prepared_stmt_count,
key_LOCK_rpl_status, key_LOCK_server_started, key_LOCK_status,
key_LOCK_table_share, key_LOCK_thd_data,
- key_LOCK_user_conn, key_LOCK_uuid_generator, key_LOG_LOCK_log,
+ key_LOCK_user_conn, key_LOCK_curr_resources, key_LOCK_profile_resources ,
+ key_LOCK_uuid_generator, key_LOG_LOCK_log,
key_master_info_data_lock, key_master_info_run_lock,
key_mutex_slave_reporting_capability_err_lock, key_relay_log_info_data_lock,
key_relay_log_info_log_space_lock, key_relay_log_info_run_lock,
@@ -250,7 +252,7 @@
key_LOCK_error_messages, key_LOCK_thread_count, key_PARTITION_LOCK_auto_inc;
extern PSI_mutex_key key_RELAYLOG_LOCK_index;
-extern PSI_rwlock_key key_rwlock_LOCK_grant, key_rwlock_LOCK_logger,
+extern PSI_rwlock_key key_rwlock_LOCK_grant, key_rwlock_LOCK_logger,key_rwlock_LOCK_profile,
key_rwlock_LOCK_sys_init_connect, key_rwlock_LOCK_sys_init_slave,
key_rwlock_LOCK_system_variables_hash, key_rwlock_query_cache_query_lock;
@@ -335,7 +337,7 @@
LOCK_error_log, LOCK_delayed_insert, LOCK_uuid_generator,
LOCK_delayed_status, LOCK_delayed_create, LOCK_crypt, LOCK_timezone,
LOCK_slave_list, LOCK_active_mi, LOCK_manager,
- LOCK_global_system_variables, LOCK_user_conn,
+ LOCK_global_system_variables, LOCK_user_conn,LOCK_curr_resources, LOCK_profile_resources,
LOCK_prepared_stmt_count, LOCK_error_messages, LOCK_connection_count;
extern MYSQL_PLUGIN_IMPORT mysql_mutex_t LOCK_thread_count;
#ifdef HAVE_OPENSSL
@@ -344,6 +346,7 @@
extern mysql_mutex_t LOCK_server_started;
extern mysql_cond_t COND_server_started;
extern mysql_rwlock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave;
+extern mysql_rwlock_t LOCK_profile;
extern mysql_rwlock_t LOCK_system_variables_hash;
extern mysql_cond_t COND_thread_count;
extern mysql_cond_t COND_manager;
Index: sql/resource_profiler.cc
===================================================================
--- sql/resource_profiler.cc (revision 0)
+++ sql/resource_profiler.cc (revision 0)
@@ -0,0 +1,111 @@
+#include "resource_profiler.h"
+#include "sql_class.h"
+
+//#define STATISTICS_DEBUG
+/* RETURN: the thread's user times unit 1ms*/
+static ulonglong get_thread_time(THD *thd)
+{
+ DBUG_ASSERT(thd != NULL);
+ ulonglong ret_time = 0;
+#ifdef __WIN__
+ int64 CreateTime,ExitTime,KernelTime,UserTime;
+ HANDLE handle = OpenThread(THREAD_ALL_ACCESS, FALSE, thd->real_id);
+ if (handle != INVALID_HANDLE_VALUE &&
+ GetThreadTimes(handle,(LPFILETIME)&CreateTime,(LPFILETIME)&ExitTime,(LPFILETIME)&KernelTime,(LPFILETIME)&UserTime))
+ {
+ ret_time = UserTime;
+ }
+#else
+ struct timespec tp;
+ clock_gettime(CLOCK_THREAD_CPUTIME_ID,&tp);
+ ret_time = tp.tv_sec * 10000000 + tp.tv_nsec / 100;
+#endif
+ return ret_time / 10000;
+}
+
+void start_trx_statistics(THD *thd)
+{
+ if(opt_use_profile_limitted && thd->user_connect != NULL)
+ {
+ thd->error = 0;
+ thd->conn_io_reads_per_trx = 0;
+ thd->conn_cpu_times_per_trx = 0;
+ thd->trx_start_thread_times = get_thread_time(thd);
+#ifdef STATISTICS_DEBUG
+ printf("reset !! conn_io_reads_per_trx = 0, conn_cpu_times_per_trx=%llu\n",thd->conn_cpu_times_per_trx);
+#endif
+ }
+}
+static int end_trx_statistics(THD *thd)
+{
+ if( thd->user_connect != NULL
+ && thd->user_connect->user_resources.profile != NULL)
+ {
+ if(thd->user_connect->user_resources.profile->cpu_times != 0 &&
+ thd->user_connect->curr_resources->curr_cpu_times >= thd->user_connect->user_resources.profile->cpu_times)
+ {
+ my_error(ER_CPU_TIMES_LIMITED,MYF(0),thd->user_connect->user, thd->user_connect->host);
+ return thd->error = ER_CPU_TIMES_LIMITED;
+ }
+ else if(thd->user_connect->user_resources.profile->io_reads != 0 &&
+ thd->user_connect->curr_resources->curr_io_reads >= thd->user_connect->user_resources.profile->io_reads)
+ {
+ my_error(ER_IO_READS_LIMITED,MYF(0),thd->user_connect->user, thd->user_connect->host);
+ return thd->error = ER_IO_READS_LIMITED;
+ }
+ else if(thd->user_connect->user_resources.profile->io_reads_per_trx != 0 &&
+ thd->conn_io_reads_per_trx >= thd->user_connect->user_resources.profile->io_reads_per_trx)
+ {
+ my_error(ER_TRX_IO_READS_LIMITED,MYF(0),thd->user_connect->user, thd->user_connect->host);
+ return thd->error = ER_TRX_IO_READS_LIMITED;
+ }
+ else if(thd->user_connect->user_resources.profile->cpu_times_per_trx != 0 &&
+ thd->conn_cpu_times_per_trx >= thd->user_connect->user_resources.profile->cpu_times_per_trx)
+ {
+ my_error(ER_TRX_CPU_TIMES_LIMITED,MYF(0),thd->user_connect->user, thd->user_connect->host);
+ return thd->error = ER_TRX_CPU_TIMES_LIMITED;
+ }
+ }
+ return 0;
+}
+
+int resource_statistics(int with_io_read)
+{
+ THD *thd = current_thd;
+ if( !opt_use_profile_limitted || thd == NULL || thd->user_connect == NULL) return 0;
+ if(end_trx_statistics(thd) != 0)
+ {
+ thd->awake(THD::KILL_QUERY);
+ return -1;
+ }
+ ulonglong curr_times = get_thread_time(thd);
+ ulonglong time_span = curr_times - thd->trx_start_thread_times;
+ thd->conn_cpu_times_per_trx += time_span;
+ thd->user_connect->curr_resources->curr_cpu_times += time_span;
+ thd->trx_start_thread_times = curr_times;
+ if(with_io_read)
+ {
+ thd->conn_io_reads_per_trx++;
+ thd->user_connect->curr_resources->curr_io_reads++;
+ }
+ return 0;
+}
+
+void my_malloc_callback_func(size_t size)
+{
+ THD *thd = current_thd;
+ if(thd != NULL)
+ {
+ thd->mem_size += size;
+ thd->max_mem_size = thd->max_mem_size < thd->mem_size ? thd->mem_size : thd->max_mem_size;
+ }
+}
+
+void my_free_callback_func(size_t size)
+{
+ THD *thd = current_thd;
+ if (thd != NULL)
+ {
+ thd->mem_size -= size;
+ }
+}
Index: sql/resource_profiler.h
===================================================================
--- sql/resource_profiler.h (revision 0)
+++ sql/resource_profiler.h (revision 0)
@@ -0,0 +1,21 @@
+#ifndef _RESOURCE_PROFILE_H_
+#define _RESOURCE_PROFILE_H_
+
+#ifndef __WIN__
+#include<unistd.h>
+#endif
+
+#ifdef __cplusplus
+
+class THD;
+extern "C"
+{
+#endif
+ void start_trx_statistics(THD *thd);
+ int resource_statistics(int with_io_read);
+ void my_malloc_callback_func(size_t size);
+ void my_free_callback_func(size_t size);
+#ifdef __cplusplus
+}
+#endif
+#endif
Index: sql/share/errmsg-utf8.txt
===================================================================
--- sql/share/errmsg-utf8.txt (revision 643)
+++ sql/share/errmsg-utf8.txt (working copy)
@@ -6486,3 +6486,30 @@
ER_PLUGIN_NO_INSTALL
eng "Plugin '%s' is marked as not dynamically installable. You have to stop the server to install it."
+
+ER_CPU_TIMES_LIMITED
+ eng "User '%s@%s' CPU resource is exhausted."
+
+ER_IO_READS_LIMITED
+ eng "User '%s@%s' IO resource is exhausted."
+
+ER_TRX_CPU_TIMES_LIMITED
+ eng "User '%s@%s' CPU times of the TRX limited."
+
+ER_TRX_IO_READS_LIMITED
+ eng "User '%s@%s' IO reads of the TRX limited."
+
+ER_PROFILER_ACCESS_DENIED
+ eng "Profile tables can't to be accessed by SQL."
+
+ER_PROFILE_ALREADY_EXISTS
+ eng "Profile '%s' already exists."
+
+ER_PROFILE_DOESNOT_EXIST
+ eng "Profile '%s' doesn't exist."
+
+ER_ROLE_DOESNOT_EXIST
+ eng "Role '%s' doesn't exist."
+
+ER_GRANT_ROLE_TO_USER
+ eng "grant role '%s' to user '%s'@'%s' WITH_CHECK_OPTION error, different '%s' privileges"
Index: sql/sql_acl.cc
===================================================================
--- sql/sql_acl.cc (revision 643)
+++ sql/sql_acl.cc (working copy)
@@ -208,6 +208,13 @@
char *db;
};
+class ACL_ROLE :public ACL_ACCESS
+{
+public:
+ char *role_name;
+};
+
+
class ACL_USER :public ACL_ACCESS
{
public:
@@ -221,6 +228,8 @@
const char *ssl_cipher, *x509_issuer, *x509_subject;
LEX_STRING plugin;
LEX_STRING auth_string;
+ const char *profile_name;
+ ACL_ROLE *role;
ACL_USER *copy(MEM_ROOT *root)
{
@@ -239,6 +248,8 @@
dst->plugin.str= strmake_root(root, plugin.str, plugin.length);
dst->auth_string.str= safe_strdup_root(root, auth_string.str);
dst->host.hostname= safe_strdup_root(root, host.hostname);
+ dst->profile_name = safe_strdup_root(root, profile_name);
+ dst->role = role;
return dst;
}
};
@@ -258,6 +269,7 @@
const char *ip);
static bool show_proxy_grants (THD *thd, LEX_USER *user,
char *buff, size_t buffsize);
+static ACL_ROLE* find_acl_role(const char *role_name);
class ACL_PROXY_USER :public ACL_ACCESS
{
@@ -524,7 +536,7 @@
#define AUTH_PACKET_HEADER_SIZE_PROTO_41 32
#define AUTH_PACKET_HEADER_SIZE_PROTO_40 5
-static DYNAMIC_ARRAY acl_hosts, acl_users, acl_dbs, acl_proxy_users;
+static DYNAMIC_ARRAY acl_hosts, acl_users, acl_roles, acl_dbs, acl_proxy_users;
static MEM_ROOT mem, memex;
static bool initialized=0;
static bool allow_all_hosts=1;
@@ -532,6 +544,7 @@
static DYNAMIC_ARRAY acl_wild_hosts;
static hash_filo *acl_cache;
static uint grant_version=0; /* Version of priv tables. incremented by acl_load */
+extern HASH hash_curr_resources;
static ulong get_access(TABLE *form,uint fieldnr, uint *next_field=0);
static int acl_compare(ACL_ACCESS *a,ACL_ACCESS *b);
static ulong get_sort(uint count,...);
@@ -539,12 +552,16 @@
static void rebuild_check_host(void);
static ACL_USER *find_acl_user(const char *host, const char *user,
my_bool exact);
+static bool check_role_user_priv(const char *role_name, List<LEX_USER> &list, TABLE_LIST *table_list);
static bool update_user_table(THD *thd, TABLE *table,
const char *host, const char *user,
const char *new_password, uint new_password_len);
static my_bool acl_load(THD *thd, TABLE_LIST *tables);
static my_bool grant_load(THD *thd, TABLE_LIST *tables);
static inline void get_grantor(THD *thd, char* grantor);
+static bool check_profile_exist(THD *thd, const char *profile_name);
+static bool open_profile_table(THD *thd, TABLE_LIST *tables);
+static void clear_profile_for_users(THD *thd, const char *profile_name,TABLE *table);
/*
Convert scrambled password to binary form, according to scramble type,
@@ -749,6 +766,34 @@
end_read_record(&read_record_info);
freeze_size(&acl_hosts);
+ /* for role table*/
+ if( tables[6].table)
+ {
+ init_read_record(&read_record_info, thd, table=tables[6].table,NULL,1,0,FALSE);
+ table->use_all_columns();
+ (void) my_init_dynamic_array(&acl_roles,sizeof(ACL_ROLE),50,100);
+ while (!(read_record_info.read_record(&read_record_info)))
+ {
+ ACL_ROLE role;
+ uint next_field = 0;
+ role.role_name = get_field(&mem, table->field[next_field++]);
+ role.access= get_access(table,next_field,&next_field) & GLOBAL_ACLS;
+ role.sort= get_sort(1,role.role_name);
+
+ if (push_dynamic(&acl_roles, (uchar*)&role))
+ {
+ sql_print_error("Allocation error, unable to add role for '%s'"
+ , role.role_name);
+ goto end;
+ }
+ }
+ qsort((uchar*)dynamic_element(&acl_roles, 0, ACL_ROLE*),
+ acl_roles.elements, sizeof(ACL_ROLE),(qsort_cmp)acl_compare);
+ end_read_record(&read_record_info);
+ }
+ freeze_size(&acl_roles);
+ /* role table end*/
+
init_read_record(&read_record_info,thd,table=tables[1].table,NULL,1,0,FALSE);
table->use_all_columns();
(void) my_init_dynamic_array(&acl_users,sizeof(ACL_USER),50,100);
@@ -924,7 +969,45 @@
user.auth_string.str= const_cast<char*>("");
user.auth_string.length= strlen(user.auth_string.str);
}
+ else
+ {
+ next_field++;
+ }
}
+ if (table->s->fields >=44)
+ {
+ user.profile_name = get_field(&mem, table->field[next_field++]);
+ if (!user.profile_name)
+ user.profile_name = const_cast<char *>("");
+ char *role_name = get_field(&mem, table->field[next_field++]);
+ if (role_name)
+ {
+ user.role = find_acl_role(role_name);
+ /*
+ if (user.role != NULL && user.role->access != user.access)
+ {
+ DBUG_PRINT("warning",("the user '%s' access privileges is different from the role '%s'"
+ "use the role's privileges to replace the user's privileges",user.user,role_name));
+ Field **tmp_field;
+ ulong priv;
+ for (tmp_field= table->field+3, priv = SELECT_ACL;
+ *tmp_field && (*tmp_field)->real_type() == MYSQL_TYPE_ENUM &&
+ ((Field_enum*) (*tmp_field))->typelib->count == 2 ;
+ tmp_field++, priv <<= 1)
+ {
+ if (priv & user.role->access) // set requested privileges
+ (*tmp_field)->store("Y", 1, &my_charset_latin1);
+ }
+ user.access = user.role->access;
+ }
+ */
+ }
+ else
+ user.role = NULL;
+ }
+ else{
+ next_field++;
+ }
}
else
{
@@ -1044,11 +1127,71 @@
}
freeze_size(&acl_proxy_users);
+ if(tables[4].table)
+ {
+ profile_resources_reset();
+ init_read_record(&read_record_info, thd, table= tables[4].table, NULL, 1, 0, FALSE);
+ table->use_all_columns();
+ while (!(read_record_info.read_record(&read_record_info)))
+ {
+ uint next_field = 0;
+ char *profile_name = get_field(&mem, table->field[next_field++]);
+ if( profile_name == NULL) continue;
+ ulong cpu_times,io_reads,cpu_times_per_trx,io_reads_per_trx;
+ size_t mem_size;
+ char *ptr = get_field(thd->mem_root, table->field[next_field++]);
+ cpu_times = ptr ? atol(ptr) : 0;
+ ptr = get_field(thd->mem_root, table->field[next_field++]);
+ io_reads = ptr ? atol(ptr) : 0;
+ ptr = get_field(thd->mem_root, table->field[next_field++]);
+ mem_size = ptr ? atol(ptr) : 0;
+ ptr = get_field(thd->mem_root, table->field[next_field++]);
+ cpu_times_per_trx = ptr ? atol(ptr) : 0;
+ ptr = get_field(thd->mem_root, table->field[next_field++]);
+ io_reads_per_trx = ptr ? atol(ptr) : 0;
+ create_profile_resources(profile_name,cpu_times,io_reads,cpu_times_per_trx,io_reads_per_trx,mem_size);
+ }
+ end_read_record(&read_record_info);
+ }
+
+ if(tables[5].table)
+ {
+ init_read_record(&read_record_info, thd, table= tables[5].table, NULL, 1, 0, FALSE);
+ table->use_all_columns();
+ while (!(read_record_info.read_record(&read_record_info)))
+ {
+ uint next_field = 0;
+ ulong curr_cpu_times, curr_io_reads;
+ char *host = get_field(&mem, table->field[next_field++]);
+ char *user = get_field(&mem, table->field[next_field++]);
+ if( user == NULL || host == NULL) continue;
+ char *ptr = get_field(thd->mem_root, table->field[next_field++]);
+ curr_cpu_times = ptr ? atol(ptr) : 0;
+ ptr = get_field(thd->mem_root, table->field[next_field++]);
+ curr_io_reads = ptr ? atol(ptr) : 0;
+ create_curr_resources(user,host,curr_cpu_times,curr_io_reads);
+ }
+ end_read_record(&read_record_info);
+ }
+ for (uint i=0 ; i < acl_users.elements ; i++)
+ {
+ ACL_USER *acl_user = dynamic_element(&acl_users,i,ACL_USER*);
+ CURR_RESOURCES *cr = search_curr_resources(acl_user->user,acl_user->host.hostname);
+ if(cr != NULL)
+ {
+ acl_user->user_resource.curr_cpu_times = cr->curr_cpu_times;
+ acl_user->user_resource.curr_io_reads = cr->curr_io_reads;
+ }
+ PROFILE_RESOURCES *profile = search_profile_resources(acl_user->profile_name);
+ if(profile != NULL && profile->status != DELETED)
+ acl_user->user_resource.profile = profile;
+ else
+ acl_user->user_resource.profile = NULL;
+ }
init_check_host();
initialized=1;
return_val= FALSE;
-
end:
thd->variables.sql_mode= old_sql_mode;
DBUG_RETURN(return_val);
@@ -1074,7 +1217,92 @@
acl_cache=0;
}
}