diff --git a/config/connectpool/mariacpool.xml b/config/connectpool/mariacpool.xml index 30f8c804..626eb8ef 100755 --- a/config/connectpool/mariacpool.xml +++ b/config/connectpool/mariacpool.xml @@ -1,53 +1,53 @@ - host1 + host1 3306 /tmp/mariadb.sock - -ssl false - root + -ssl false + root maria tpcc - host2 + host2 3306 /tmp/mariadb.sock - -ssl false - root + -ssl false + root maria tpcc - host3 + host3 3306 /tmp/mariadb.sock - -ssl false - root + -ssl false + root maria tpcc - - c1 c2 c3 - round_robin - - - c1 c2 c3 - round_robin - - - c1 c2 c3 - round_robin - - - c1 c2 c3 - round_robin - - - c1 c2 c3 - round_robin - + + c1 c2 c3 + round_robin + + + c1 c2 c3 + round_robin + + + c1 c2 c3 + round_robin + + + c1 c2 c3 + round_robin + + + c1 c2 c3 + round_robin + diff --git a/config/connectpool/mysqlcpool.xml b/config/connectpool/mysqlcpool.xml index 4ac5abdd..8e440e2d 100755 --- a/config/connectpool/mysqlcpool.xml +++ b/config/connectpool/mysqlcpool.xml @@ -1,50 +1,53 @@ - host1 + host1 3306 /tmp/mysql.sock - root + -ssl false + root mysql tpcc - host2 + host2 3306 /tmp/mysql.sock - root + -ssl false + root mysql tpcc - host3 + host3 3306 /tmp/mysql.sock - root + -ssl false + root mysql tpcc - - c1 c2 c3 - round_robin - - - c1 c2 c3 - round_robin - - - c1 c2 c3 - round_robin - - - c1 c2 c3 - round_robin - - - c1 c2 c3 - round_robin - + + c1 c2 c3 + round_robin + + + c1 c2 c3 + round_robin + + + c1 c2 c3 + round_robin + + + c1 c2 c3 + round_robin + + + c1 c2 c3 + round_robin + diff --git a/config/generic.xml b/config/generic.xml index 94c33b10..007a7b75 100755 --- a/config/generic.xml +++ b/config/generic.xml @@ -1,9 +1,9 @@ - auto - auto - auto + auto + auto + auto TMP diff --git a/config/mariadb.xml b/config/mariadb.xml index 9c3e3b1b..08382c6d 100755 --- a/config/mariadb.xml +++ b/config/mariadb.xml @@ -3,17 +3,17 @@ 127.0.0.1 3306 - /tmp/mariadb.sock - false - false - /etc/mysql/certs - C:\mysql\certs - ca-cert.pem - client-cert.pem - client-key.pem - server + /tmp/mariadb.sock + false + false + /etc/mysql/certs + C:\mysql\certs + ca-cert.pem + client-cert.pem + client-key.pem + server - + 1 1 @@ -21,23 +21,23 @@ maria tpcc innodb - false - false + false + false 10000000 false false test - 2 + 2 5 false false - false + false 10 false 1000 - false + false @@ -47,7 +47,7 @@ maria tpch 1 - innodb + innodb 1 @@ -57,7 +57,7 @@ 1 1000 false - false + false diff --git a/config/mysql.xml b/config/mysql.xml index 2258fa9e..80b430f8 100755 --- a/config/mysql.xml +++ b/config/mysql.xml @@ -3,9 +3,17 @@ 127.0.0.1 3306 - /tmp/mysql.sock + /tmp/mysql.sock + false + false + /etc/mysql/certs + C:\mysql\certs + ca-cert.pem + client-cert.pem + client-key.pem + server - + 1 1 @@ -13,23 +21,23 @@ mysql tpcc innodb - false - false + false + false 10000000 false false test - 2 + 2 5 false false - false + false 10 false 1000 - false + false @@ -39,7 +47,7 @@ mysql tpch 1 - innodb + innodb 1 @@ -49,7 +57,7 @@ 1 1000 false - false + false diff --git a/src/generic/geninit.tcl b/src/generic/geninit.tcl index fcd9241b..fcbdba65 100755 --- a/src/generic/geninit.tcl +++ b/src/generic/geninit.tcl @@ -1,4 +1,5 @@ package require sqlite3 +global hdb_version #Get generic config data set genericdict [ ::XML::To_Dict config/generic.xml ] @@ -10,9 +11,40 @@ if { [ dict exists $genericdict sqlitedb sqlitedb_dir ] } { set sqlitedb_dir "" } +#Set hammerdb version to genericdict +set hdb_version_dict [ dict create version $hdb_version ] +dict append genericdict hdb_version $hdb_version_dict + +#Try to get generic config data from SQLite +set genericdictdb [ SQLite2Dict "generic" ] +if { $genericdictdb eq "" } { + #No SQLite found, save genericdict from XML to SQLite + Dict2SQLite "generic" $genericdict +} else { + if { [ dict exists $genericdictdb hdb_version version ] } { + set sqlite_hdb_version [ dict get $genericdictdb hdb_version version ] + } else { + set sqlite_hdb_version "unknown" + } + + #SQLite found, check whether the schema versions from SQLite and XML are consistent + if { $sqlite_hdb_version ne $hdb_version } { + puts "The existing SQLite DBs are from version $sqlite_hdb_version. SQLite DBs will be reset to $hdb_version." + foreach { dbname } { generic database db2 mariadb mssqlserver mysql oracle postgresql } { + set dbfile [ CheckSQLiteDB $dbname ] + #Remove SQLite file + file delete $dbfile + } + #After remove old SQLite, save genericdict to SQLite DB + Dict2SQLite "generic" $genericdict + } else { + #Use configration from SQLite + set genericdict $genericdictdb + } +} + #Load database config from SQLite database.db set dbdict [ SQLite2Dict "database" ] - if { $dbdict eq "" } { #Load database config from database.xml set dbdict [ ::XML::To_Dict config/database.xml ] @@ -42,16 +74,8 @@ foreach { key } [ dict keys $dbdict ] { lappend dbsrclist "$key/$prefix\opt.tcl" "$key/$prefix\oltp.tcl" "$key/$prefix\olap.tcl" "$key/$prefix\otc.tcl" "$key/$prefix\met.tcl" } -#Get generic config data -set genericdictdb [ SQLite2Dict "generic" ] -if { $genericdictdb eq "" } { - Dict2SQLite "generic" $genericdict -} else { - set genericdict $genericdictdb -} - #get_xml_data -set_globle_config $genericdict +set_global_config $genericdict #Make generics global tsv::set application genericdict $genericdict diff --git a/src/generic/geninitcli.tcl b/src/generic/geninitcli.tcl index a2d99ec7..eee27f36 100755 --- a/src/generic/geninitcli.tcl +++ b/src/generic/geninitcli.tcl @@ -1,4 +1,5 @@ package require sqlite3 +global hdb_version #Get generic config data set genericdict [ ::XML::To_Dict config/generic.xml ] @@ -10,6 +11,38 @@ if { [ dict exists $genericdict sqlitedb sqlitedb_dir ] } { set sqlitedb_dir "" } +#Set hammerdb version to genericdict +set hdb_version_dict [ dict create version $hdb_version ] +dict append genericdict hdb_version $hdb_version_dict + +#Try to get generic config data from SQLite +set genericdictdb [ SQLite2Dict "generic" ] +if { $genericdictdb eq "" } { + #No SQLite found, save genericdict from XML to SQLite + Dict2SQLite "generic" $genericdict +} else { + if { [ dict exists $genericdictdb hdb_version version ] } { + set sqlite_hdb_version [ dict get $genericdictdb hdb_version version ] + } else { + set sqlite_hdb_version "unknown" + } + + #SQLite found, check whether the schema versions from SQLite and XML are consistent + if { $sqlite_hdb_version ne $hdb_version } { + puts "The existing SQLite DBs are from version $sqlite_hdb_version. SQLite DBs will be reset to $hdb_version." + foreach { dbname } { generic database db2 mariadb mssqlserver mysql oracle postgresql } { + set dbfile [ CheckSQLiteDB $dbname ] + #Remove SQLite file + file delete $dbfile + } + #After remove old SQLite, save genericdict to SQLite DB + Dict2SQLite "generic" $genericdict + } else { + #Use configration from SQLite + set genericdict $genericdictdb + } +} + #Load database config from SQLite database.db set dbdict [ SQLite2Dict "database" ] if { $dbdict eq "" } { @@ -36,16 +69,8 @@ foreach { key } [ dict keys $dbdict ] { lappend dbsrclist "$key/$prefix\opt.tcl" "$key/$prefix\oltp.tcl" "$key/$prefix\olap.tcl" "$key/$prefix\otc.tcl" } -#Get generic config data -set genericdictdb [ SQLite2Dict "generic" ] -if { $genericdictdb eq "" } { - Dict2SQLite "generic" $genericdict -} else { - set genericdict $genericdictdb -} - #get_xml_data -set_globle_config $genericdict +set_global_config $genericdict #Make generics global tsv::set application genericdict $genericdict diff --git a/src/generic/geninitws.tcl b/src/generic/geninitws.tcl index 037ef19a..eee27f36 100755 --- a/src/generic/geninitws.tcl +++ b/src/generic/geninitws.tcl @@ -1,4 +1,5 @@ package require sqlite3 +global hdb_version #Get generic config data set genericdict [ ::XML::To_Dict config/generic.xml ] @@ -10,6 +11,38 @@ if { [ dict exists $genericdict sqlitedb sqlitedb_dir ] } { set sqlitedb_dir "" } +#Set hammerdb version to genericdict +set hdb_version_dict [ dict create version $hdb_version ] +dict append genericdict hdb_version $hdb_version_dict + +#Try to get generic config data from SQLite +set genericdictdb [ SQLite2Dict "generic" ] +if { $genericdictdb eq "" } { + #No SQLite found, save genericdict from XML to SQLite + Dict2SQLite "generic" $genericdict +} else { + if { [ dict exists $genericdictdb hdb_version version ] } { + set sqlite_hdb_version [ dict get $genericdictdb hdb_version version ] + } else { + set sqlite_hdb_version "unknown" + } + + #SQLite found, check whether the schema versions from SQLite and XML are consistent + if { $sqlite_hdb_version ne $hdb_version } { + puts "The existing SQLite DBs are from version $sqlite_hdb_version. SQLite DBs will be reset to $hdb_version." + foreach { dbname } { generic database db2 mariadb mssqlserver mysql oracle postgresql } { + set dbfile [ CheckSQLiteDB $dbname ] + #Remove SQLite file + file delete $dbfile + } + #After remove old SQLite, save genericdict to SQLite DB + Dict2SQLite "generic" $genericdict + } else { + #Use configration from SQLite + set genericdict $genericdictdb + } +} + #Load database config from SQLite database.db set dbdict [ SQLite2Dict "database" ] if { $dbdict eq "" } { @@ -36,14 +69,8 @@ foreach { key } [ dict keys $dbdict ] { lappend dbsrclist "$key/$prefix\opt.tcl" "$key/$prefix\oltp.tcl" "$key/$prefix\olap.tcl" "$key/$prefix\otc.tcl" } -#Get generic config data -set genericdict [ SQLite2Dict "generic" ] -if { $genericdict eq "" } { - set genericdict [ ::XML::To_Dict config/generic.xml ] - Dict2SQLite "generic" $genericdict -} #get_xml_data -set_globle_config $genericdict +set_global_config $genericdict #Make generics global tsv::set application genericdict $genericdict diff --git a/src/generic/genxml.tcl b/src/generic/genxml.tcl index f6b75cd6..252997b6 100755 --- a/src/generic/genxml.tcl +++ b/src/generic/genxml.tcl @@ -49,7 +49,7 @@ proc xmlopts {} { puts "This function to write out XML data for database $rdbms" } -proc set_globle_config {genericdict} { +proc set_global_config {genericdict} { global rdbms bm virtual_users maxvuser delayms conpause ntimes suppo optlog apmode apduration apsequence unique_log_name no_log_buffer log_timestamps interval hostname id agent_hostname agent_id highlight gen_count_ware gen_scale_fact gen_directory gen_num_vu if { $genericdict eq "" } { diff --git a/src/mysql/mysqlolap.tcl b/src/mysql/mysqlolap.tcl index 4217ac0d..50342014 100755 --- a/src/mysql/mysqlolap.tcl +++ b/src/mysql/mysqlolap.tcl @@ -1,5 +1,5 @@ proc build_mysqltpch {} { - global maxvuser suppo ntimes threadscreated _ED + global maxvuser suppo ntimes threadscreated _ED mysql_ssl_options upvar #0 dbdict dbdict if {[dict exists $dbdict mysql library ]} { set library [ dict get $dbdict mysql library ] @@ -7,6 +7,10 @@ proc build_mysqltpch {} { upvar #0 configmysql configmysql #set variables to values in dict setlocaltpchvars $configmysql + #If the options menu has been run under the GUI mysql_ssl_options is set + #If build is run under the GUI, CLI or WS mysql_ssl_options is not set + #Set it now if it doesn't exist + if ![ info exists mysql_ssl_options ] { check_mysql_ssl $configmysql } if { ![string match windows $::tcl_platform(platform)] && ($mysql_host eq "127.0.0.1" || [ string tolower $mysql_host ] eq "localhost") && [ string tolower $mysql_socket ] != "null" } { set mysql_connector "$mysql_host:$mysql_socket" } else { set mysql_connector "$mysql_host:$mysql_port" } if {[ tk_messageBox -title "Create Schema" -icon question -message "Ready to create a Scale Factor $mysql_scale_fact TPROC-H schema\n in host [string toupper $mysql_connector] under user [ string toupper $mysql_tpch_user ] in database [ string toupper $mysql_tpch_dbase ] with storage engine [ string toupper $mysql_tpch_storage_engine ]?" -type yesno ] == yes} { if { $mysql_num_tpch_threads eq 1 } { @@ -45,6 +49,45 @@ proc chk_socket { host socket } { } } +proc ConnectToMySQL { host port socket ssl_options user password } { + global mysqlstatus + #ssl_options is variable length so build a connectstring + if { [ chk_socket $host $socket ] eq "TRUE" } { + set use_socket "true" + append connectstring " -socket $socket" + } else { + set use_socket "false" + append connectstring " -host $host -port $port" + } + foreach key [ dict keys $ssl_options ] { + append connectstring " $key [ dict get $ssl_options $key ] " + } + append connectstring " -user $user -password $password" + set login_command "mysqlconnect [ dict get $connectstring ]" + #eval the login command + if [catch {set mysql_handler [eval $login_command]}] { + if $use_socket { + puts "the local socket connection to $socket could not be established" + } else { + puts "the tcp connection to $host:$port could not be established" + } + set connected "false" + } else { + set connected "true" + } + if {$connected} { + mysql::autocommit $mysql_handler 0 + catch {set ssl_status [ mysql::sel $mysql_handler "show session status like 'ssl_cipher'" -list ]} + if { [ info exists ssl_status ] } { + puts [ join $ssl_status ] + } + return $mysql_handler + } else { + error $mysqlstatus(message) + return + } +} + proc CreateDatabase { mysql_handler db } { puts "CREATING DATABASE $db" set sql(1) "SET FOREIGN_KEY_CHECKS = 0" @@ -410,7 +453,7 @@ proc mk_order { mysql_handler start_rows end_rows upd_num scale_factor } { return } -proc do_tpch { host port socket scale_fact user password db mysql_tpch_storage_engine num_vu } { +proc do_tpch { host port socket ssl_options scale_fact user password db mysql_tpch_storage_engine num_vu } { global mysqlstatus global dist_names dist_weights weights dists weights ############################################### @@ -462,30 +505,11 @@ proc do_tpch { host port socket scale_fact user password db mysql_tpch_storage_e } if { $threaded eq "SINGLE-THREADED" || $threaded eq "MULTI-THREADED" && $myposition eq 1 } { puts "CREATING [ string toupper $user ] SCHEMA" - if { [ chk_socket $host $socket ] eq "TRUE" } { - if [catch {mysqlconnect -socket $socket -user $user -password $password} mysql_handler] { - puts "the local socket connection to $socket could not be established" - set connected "FALSE" - } else { - set connected "TRUE" - } - } else { - if [catch {mysqlconnect -host $host -port $port -user $user -password $password} mysql_handler] { - puts "the tcp connection to $host:$port could not be established" - set connected "FALSE" - } else { - set connected "TRUE" - } - } - if {$connected} { - CreateDatabase $mysql_handler $db - mysqluse $mysql_handler $db - mysql::autocommit $mysql_handler 0 - CreateTables $mysql_handler $mysql_tpch_storage_engine - } else { - error $mysqlstatus(message) - return - } + set mysql_handler [ ConnectToMySQL $host $port $socket $ssl_options $user $password ] + CreateDatabase $mysql_handler $db + mysqluse $mysql_handler $db + mysql::autocommit $mysql_handler 0 + CreateTables $mysql_handler $mysql_tpch_storage_engine if { $threaded eq "MULTI-THREADED" } { tsv::set application load "READY" puts "Loading REGION..." @@ -536,29 +560,9 @@ proc do_tpch { host port socket scale_fact user password db mysql_tpch_storage_e } after 5000 } - if { [ chk_socket $host $socket ] eq "TRUE" } { - if [catch {mysqlconnect -socket $socket -user $user -password $password} mysql_handler] { - puts "the local socket connection to $socket could not be established" - set connected "FALSE" - } else { - set connected "TRUE" - } - } else { - if [catch {mysqlconnect -host $host -port $port -user $user -password $password} mysql_handler] { - puts "the tcp connection to $host:$port could not be established" - set connected "FALSE" - } else { - set connected "TRUE" - } - } - if {$connected} { - mysqluse $mysql_handler $db - mysql::autocommit $mysql_handler 0 - mysqlexec $mysql_handler "SET FOREIGN_KEY_CHECKS = 0" - } else { - error $mysqlstatus(message) - return - } + set mysql_handler [ ConnectToMySQL $host $port $socket $ssl_options $user $password ] + mysqluse $mysql_handler $db + mysqlexec $mysql_handler "SET FOREIGN_KEY_CHECKS = 0" if { [ expr $myposition - 1 ] > $max_threads } { puts "No Data to Create"; return } if { [ expr $num_vu + 1 ] > $max_threads } { set num_vu $max_threads } set sf_chunk [ split [ start_end $sup_rows $myposition $sf_mult $num_vu ] ":" ] @@ -594,12 +598,12 @@ proc do_tpch { host port socket scale_fact user password db mysql_tpch_storage_e } } } - .ed_mainFrame.mainwin.textFrame.left.text fastinsert end "do_tpch $mysql_host $mysql_port $mysql_socket $mysql_scale_fact $mysql_tpch_user $mysql_tpch_pass $mysql_tpch_dbase $mysql_tpch_storage_engine $mysql_num_tpch_threads" + .ed_mainFrame.mainwin.textFrame.left.text fastinsert end "do_tpch $mysql_host $mysql_port $mysql_socket {$mysql_ssl_options} $mysql_scale_fact $mysql_tpch_user $mysql_tpch_pass $mysql_tpch_dbase $mysql_tpch_storage_engine $mysql_num_tpch_threads" } else { return } } proc loadmysqltpch { } { - global _ED + global _ED mysql_ssl_options upvar #0 dbdict dbdict if {[dict exists $dbdict mysql library ]} { set library [ dict get $dbdict mysql library ] @@ -607,6 +611,10 @@ proc loadmysqltpch { } { upvar #0 configmysql configmysql #set variables to values in dict setlocaltpchvars $configmysql + #If the options menu has been run under the GUI mysql_ssl_options is set + #If build is run under the GUI, CLI or WS mysql_ssl_options is not set + #Set it now if it doesn't exist + if ![ info exists mysql_ssl_options ] { check_mysql_ssl $configmysql } ed_edit_clear .ed_mainFrame.notebook select .ed_mainFrame.mainwin set _ED(packagekeyname) "MySQL TPROC-H" @@ -620,6 +628,7 @@ set scale_factor $mysql_scale_fact ;#Scale factor of the tpc-h schema set host \"$mysql_host\" ;# Address of the server hosting MySQL set port \"$mysql_port\" ;# Port of the MySQL Server, defaults to 3306 set socket \"$mysql_socket\" ;# MySQL Socket for local connections +set ssl_options {$mysql_ssl_options} ;# MySQL SSL/TLS options set user \"$mysql_tpch_user\" ;# MySQL user set password \"$mysql_tpch_pass\" ;# Password for the MySQL user set db \"$mysql_tpch_dbase\" ;# Database containing the TPC Schema @@ -653,6 +662,47 @@ proc chk_socket { host socket } { return "FALSE" } } + +proc ConnectToMySQL { host port socket ssl_options user password db } { + global mysqlstatus + #ssl_options is variable length so build a connectstring + if { [ chk_socket $host $socket ] eq "TRUE" } { + set use_socket "true" + append connectstring " -socket $socket" + } else { + set use_socket "false" + append connectstring " -host $host -port $port" + } + foreach key [ dict keys $ssl_options ] { + append connectstring " $key [ dict get $ssl_options $key ] " + } + append connectstring " -user $user -password $password" + set login_command "mysqlconnect [ dict get $connectstring ]" + #eval the login command + if [catch {set mysql_handler [eval $login_command]}] { + if $use_socket { + puts "the local socket connection to $socket could not be established" + } else { + puts "the tcp connection to $host:$port could not be established" + } + set connected "false" + } else { + set connected "true" + } + if {$connected} { + mysqluse $mysql_handler $db + mysql::autocommit $mysql_handler 0 + catch {set ssl_status [ mysql::sel $mysql_handler "show session status like 'ssl_cipher'" -list ]} + if { [ info exists ssl_status ] } { + puts [ join $ssl_status ] + } + return $mysql_handler + } else { + error $mysqlstatus(message) + return + } +} + ######################### #TPCH REFRESH PROCEDURE proc mk_order_ref { mysql_handler upd_num scale_factor trickle_refresh REFRESH_VERBOSE } { @@ -777,29 +827,8 @@ proc del_order_ref { mysql_handler upd_num scale_factor trickle_refresh REFRESH_ mysql::commit $mysql_handler } -proc do_refresh { host port socket user password db scale_factor update_sets trickle_refresh REFRESH_VERBOSE RF_SET } { - if { [ chk_socket $host $socket ] eq "TRUE" } { - if [catch {mysqlconnect -socket $socket -user $user -password $password} mysql_handler] { - puts "the local socket connection to $socket could not be established" - set connected "FALSE" - } else { - set connected "TRUE" - } - } else { - if [catch {mysqlconnect -host $host -port $port -user $user -password $password} mysql_handler] { - puts "the tcp connection to $host:$port could not be established" - set connected "FALSE" - } else { - set connected "TRUE" - } - } - if {$connected} { - mysqluse $mysql_handler $db - mysql::autocommit $mysql_handler 0 - } else { - error $mysqlstatus(message) - return - } +proc do_refresh { host port socket ssl_options user password db scale_factor update_sets trickle_refresh REFRESH_VERBOSE RF_SET } { + set mysql_handler [ ConnectToMySQL $host $port $socket $ssl_options $user $password $db ] set upd_num 1 for { set set_counter 1 } {$set_counter <= $update_sets } {incr set_counter} { if { [ tsv::get application abort ] } { break } @@ -828,6 +857,7 @@ proc do_refresh { host port socket user password db scale_factor update_sets tri puts "Completed $update_sets update set(s)" mysqlclose $mysql_handler } + ######################### #TPCH QUERY GENERATION proc set_query { myposition } { @@ -1049,30 +1079,9 @@ proc sub_query { query_no scale_factor myposition } { } ######################### #TPCH QUERY SETS PROCEDURE -proc do_tpch { host port socket user password db scale_factor RAISEERROR VERBOSE total_querysets myposition } { +proc do_tpch { host port socket ssl_options user password db scale_factor RAISEERROR VERBOSE total_querysets myposition } { global mysqlstatus - if { [ chk_socket $host $socket ] eq "TRUE" } { - if [catch {mysqlconnect -socket $socket -user $user -password $password} mysql_handler] { - puts "the local socket connection to $socket could not be established" - set connected "FALSE" - } else { - set connected "TRUE" - } - } else { - if [catch {mysqlconnect -host $host -port $port -user $user -password $password} mysql_handler] { - puts "the tcp connection to $host:$port could not be established" - set connected "FALSE" - } else { - set connected "TRUE" - } - } - if {$connected} { - mysqluse $mysql_handler $db - mysql::autocommit $mysql_handler 0 - } else { - error $mysqlstatus(message) - return - } + set mysql_handler [ ConnectToMySQL $host $port $socket $ssl_options $user $password $db ] for {set it 0} {$it < $total_querysets} {incr it} { if { [ tsv::get application abort ] } { break } set start [ clock seconds ] @@ -1169,26 +1178,26 @@ if { $refresh_on } { set trickle_refresh 0 set update_sets 1 set REFRESH_VERBOSE "false" - do_refresh $host $port $socket $user $password $db $scale_factor $update_sets $trickle_refresh $REFRESH_VERBOSE RF1 - do_tpch $host $port $socket $user $password $db $scale_factor $RAISEERROR $VERBOSE $total_querysets 0 - do_refresh $host $port $socket $user $password $db $scale_factor $update_sets $trickle_refresh $REFRESH_VERBOSE RF2 + do_refresh $host $port $socket $ssl_options $user $password $db $scale_factor $update_sets $trickle_refresh $REFRESH_VERBOSE RF1 + do_tpch $host $port $socket $ssl_options $user $password $db $scale_factor $RAISEERROR $VERBOSE $total_querysets 0 + do_refresh $host $port $socket $ssl_options $user $password $db $scale_factor $update_sets $trickle_refresh $REFRESH_VERBOSE RF2 } else { switch $myposition { 1 { - do_refresh $host $port $socket $user $password $db $scale_factor $update_sets $trickle_refresh $REFRESH_VERBOSE BOTH + do_refresh $host $port $socket $ssl_options $user $password $db $scale_factor $update_sets $trickle_refresh $REFRESH_VERBOSE BOTH } default { - do_tpch $host $port $socket $user $password $db $scale_factor $RAISEERROR $VERBOSE $total_querysets [ expr $myposition - 1 ] + do_tpch $host $port $socket $ssl_options $user $password $db $scale_factor $RAISEERROR $VERBOSE $total_querysets [ expr $myposition - 1 ] } } } } else { - do_tpch $host $port $socket $user $password $db $scale_factor $RAISEERROR $VERBOSE $total_querysets $myposition + do_tpch $host $port $socket $ssl_options $user $password $db $scale_factor $RAISEERROR $VERBOSE $total_querysets $myposition }} } proc loadmysqlcloud {} { - global _ED + global _ED mysql_ssl_options upvar #0 dbdict dbdict if {[dict exists $dbdict mysql library ]} { set library [ dict get $dbdict mysql library ] @@ -1196,6 +1205,10 @@ proc loadmysqlcloud {} { upvar #0 configmysql configmysql #set variables to values in dict setlocaltpchvars $configmysql + #If the options menu has been run under the GUI mysql_ssl_options is set + #If build is run under the GUI, CLI or WS mysql_ssl_options is not set + #Set it now if it doesn't exist + if ![ info exists mysql_ssl_options ] { check_mysql_ssl $configmysql } ed_edit_clear .ed_mainFrame.notebook select .ed_mainFrame.mainwin set _ED(packagekeyname) "MySQL Cloud" @@ -1207,6 +1220,7 @@ set VERBOSE \"$mysql_verbose\" ;# Show query text and output set host \"$mysql_host\" ;# Address of the server hosting MySQL set port \"$mysql_port\" ;# Port of the MySQL Server, defaults to 3306 set socket \"$mysql_socket\" ;# MySQL Socket for local connections +set ssl_options {$mysql_ssl_options} ;# MySQL SSL/TLS options set user \"$mysql_tpch_user\" ;# MySQL user set password \"$mysql_tpch_pass\" ;# Password for the MySQL user set db \"$mysql_tpch_dbase\" ;# Database containing the TPC Schema @@ -1237,6 +1251,47 @@ proc chk_socket { host socket } { return "FALSE" } } + +proc ConnectToMySQL { host port socket ssl_options user password db } { + global mysqlstatus + #ssl_options is variable length so build a connectstring + if { [ chk_socket $host $socket ] eq "TRUE" } { + set use_socket "true" + append connectstring " -socket $socket" + } else { + set use_socket "false" + append connectstring " -host $host -port $port" + } + foreach key [ dict keys $ssl_options ] { + append connectstring " $key [ dict get $ssl_options $key ] " + } + append connectstring " -user $user -password $password" + set login_command "mysqlconnect [ dict get $connectstring ]" + #eval the login command + if [catch {set mysql_handler [eval $login_command]}] { + if $use_socket { + puts "the local socket connection to $socket could not be established" + } else { + puts "the tcp connection to $host:$port could not be established" + } + set connected "false" + } else { + set connected "true" + } + if {$connected} { + mysqluse $mysql_handler $db + mysql::autocommit $mysql_handler 0 + catch {set ssl_status [ mysql::sel $mysql_handler "show session status like 'ssl_cipher'" -list ]} + if { [ info exists ssl_status ] } { + puts [ join $ssl_status ] + } + return $mysql_handler + } else { + error $mysqlstatus(message) + return + } +} + ######################### #CLOUD ANALYTIC TPCH QUERY GENERATION proc set_query { } { @@ -1265,31 +1320,10 @@ proc get_query { query_no } { } ######################### #CLOUD ANALYTIC TPCH QUERY SETS PROCEDURE -proc do_cloud { host port socket user password db RAISEERROR VERBOSE } { +proc do_cloud { host port socket ssl_options user password db RAISEERROR VERBOSE } { global mysqlstatus - if { [ chk_socket $host $socket ] eq "TRUE" } { - if [catch {mysqlconnect -socket $socket -user $user -password $password} mysql_handler] { - puts "the local socket connection to $socket could not be established" - set connected "FALSE" - } else { - set connected "TRUE" - } - } else { - if [catch {mysqlconnect -host $host -port $port -user $user -password $password} mysql_handler] { - puts "the tcp connection to $host:$port could not be established" - set connected "FALSE" - } else { - set connected "TRUE" - } - } - if {$connected} { - mysqluse $mysql_handler $db - mysql::autocommit $mysql_handler 0 - mysqlexec $mysql_handler "set session group_concat_max_len = 18446744073709551615" - } else { - error $mysqlstatus(message) - return - } + set mysql_handler [ ConnectToMySQL $host $port $socket $ssl_options $user $password $db ] + mysqlexec $mysql_handler "set session group_concat_max_len = 18446744073709551615" unset -nocomplain qlist set start [ clock seconds ] for { set q 1 } { $q <= 13 } { incr q } { @@ -1315,5 +1349,5 @@ proc do_cloud { host port socket user password db RAISEERROR VERBOSE } { } ######################### #RUN CLOUD ANALYTIC TPC-H -do_cloud $host $port $socket $user $password $db $RAISEERROR $VERBOSE} +do_cloud $host $port $socket $ssl_options $user $password $db $RAISEERROR $VERBOSE} } diff --git a/src/mysql/mysqloltp.tcl b/src/mysql/mysqloltp.tcl index 9beb7e29..7a5ee339 100755 --- a/src/mysql/mysqloltp.tcl +++ b/src/mysql/mysqloltp.tcl @@ -1,12 +1,18 @@ proc build_mysqltpcc {} { - global maxvuser suppo ntimes threadscreated _ED + global maxvuser suppo ntimes threadscreated _ED mysql_ssl_options upvar #0 dbdict dbdict + if {[dict exists $dbdict mysql library ]} { set library [ dict get $dbdict mysql library ] } else { set library "mysqltcl" } + upvar #0 configmysql configmysql #set variables to values in dict setlocaltpccvars $configmysql + #If the options menu has been run under the GUI mysql_ssl_options is set + #If build is run under the GUI, CLI or WS mysql_ssl_options is not set + #Set it now if it doesn't exist + if ![ info exists mysql_ssl_options ] { check_mysql_ssl $configmysql } if { ![string match windows $::tcl_platform(platform)] && ($mysql_host eq "127.0.0.1" || [ string tolower $mysql_host ] eq "localhost") && [ string tolower $mysql_socket ] != "null" } { set mysql_connector "$mysql_host:$mysql_socket" } else { set mysql_connector "$mysql_host:$mysql_port" } if {[ tk_messageBox -title "Create Schema" -icon question -message "Ready to create a $mysql_count_ware Warehouse MySQL TPROC-C schema\nin host [string toupper $mysql_connector] under user [ string toupper $mysql_user ] in database [ string toupper $mysql_dbase ] with storage engine [ string toupper $mysql_storage_engine ]?" -type yesno ] == yes} { if { $mysql_num_vu eq 1 || $mysql_count_ware eq 1 } { @@ -439,6 +445,45 @@ proc CreateStoredProcs { mysql_handler } { return } +proc ConnectToMySQL { host port socket ssl_options user password } { + global mysqlstatus + #ssl_options is variable length so build a connectstring + if { [ chk_socket $host $socket ] eq "TRUE" } { + set use_socket "true" + append connectstring " -socket $socket" + } else { + set use_socket "false" + append connectstring " -host $host -port $port" + } + foreach key [ dict keys $ssl_options ] { + append connectstring " $key [ dict get $ssl_options $key ] " + } + append connectstring " -user $user -password $password" + set login_command "mysqlconnect [ dict get $connectstring ]" + #eval the login command + if [catch {set mysql_handler [eval $login_command]}] { + if $use_socket { + puts "the local socket connection to $socket could not be established" + } else { + puts "the tcp connection to $host:$port could not be established" + } + set connected "false" + } else { + set connected "true" + } + if {$connected} { + mysql::autocommit $mysql_handler 0 + catch {set ssl_status [ mysql::sel $mysql_handler "show session status like 'ssl_cipher'" -list ]} + if { [ info exists ssl_status ] } { + puts [ join $ssl_status ] + } + return $mysql_handler + } else { + error $mysqlstatus(message) + return + } +} + proc GatherStatistics { mysql_handler } { puts "GATHERING SCHEMA STATISTICS" set sql(1) "analyze table customer, district, history, item, new_order, orders, order_line, stock, warehouse" @@ -899,7 +944,7 @@ proc chk_socket { host socket } { } } -proc do_tpcc { host port socket count_ware user password db mysql_storage_engine partition num_vu } { +proc do_tpcc { host port socket ssl_options count_ware user password db mysql_storage_engine partition num_vu } { global mysqlstatus set MAXITEMS 100000 set CUST_PER_DIST 3000 @@ -931,39 +976,20 @@ proc do_tpcc { host port socket count_ware user password db mysql_storage_engine } if { $threaded eq "SINGLE-THREADED" || $threaded eq "MULTI-THREADED" && $myposition eq 1 } { puts "CREATING [ string toupper $db ] SCHEMA" - if { [ chk_socket $host $socket ] eq "TRUE" } { - if [catch {mysqlconnect -socket $socket -user $user -password $password} mysql_handler] { - puts "the local socket connection to $socket could not be established" - set connected "FALSE" - } else { - set connected "TRUE" - } - } else { - if [catch {mysqlconnect -host $host -port $port -user $user -password $password} mysql_handler] { - puts "the tcp connection to $host:$port could not be established" - set connected "FALSE" - } else { - set connected "TRUE" - } - } - if {$connected} { - CreateDatabase $mysql_handler $db - mysqluse $mysql_handler $db - mysql::autocommit $mysql_handler 0 - if { $partition eq "true" } { - if {$count_ware < 200} { - set num_part 0 - } else { - set num_part [ expr round($count_ware/100) ] - } - } else { + set mysql_handler [ ConnectToMySQL $host $port $socket $ssl_options $user $password ] + CreateDatabase $mysql_handler $db + mysqluse $mysql_handler $db + mysql::autocommit $mysql_handler 0 + if { $partition eq "true" } { + if {$count_ware < 200} { set num_part 0 + } else { + set num_part [ expr round($count_ware/100) ] } - CreateTables $mysql_handler $mysql_storage_engine $num_part } else { - error $mysqlstatus(message) - return + set num_part 0 } + CreateTables $mysql_handler $mysql_storage_engine $num_part if { $threaded eq "MULTI-THREADED" } { tsv::set application load "READY" LoadItems $mysql_handler $MAXITEMS @@ -984,9 +1010,11 @@ proc do_tpcc { host port socket count_ware user password db mysql_storage_engine set prevactive $lvcnt if { $dncnt eq [expr $totalvirtualusers - 1] } { break } after 10000 - }} else { + } + } else { LoadItems $mysql_handler $MAXITEMS - }} + } + } if { $threaded eq "SINGLE-THREADED" || $threaded eq "MULTI-THREADED" && $myposition != 1 } { if { $threaded eq "MULTI-THREADED" } { puts "Waiting for Monitor Thread..." @@ -1002,28 +1030,8 @@ proc do_tpcc { host port socket count_ware user password db mysql_storage_engine } after 5000 } - if { [ chk_socket $host $socket ] eq "TRUE" } { - if [catch {mysqlconnect -socket $socket -user $user -password $password} mysql_handler] { - puts "the local socket connection to $socket could not be established" - set connected "FALSE" - } else { - set connected "TRUE" - } - } else { - if [catch {mysqlconnect -host $host -port $port -user $user -password $password} mysql_handler] { - puts "the tcp connection to $host:$port could not be established" - set connected "FALSE" - } else { - set connected "TRUE" - } - } - if {$connected} { - mysqluse $mysql_handler $db - mysql::autocommit $mysql_handler 0 - } else { - error $mysqlstatus(message) - return - } + set mysql_handler [ ConnectToMySQL $host $port $socket $ssl_options $user $password ] + mysqluse $mysql_handler $db set remb [ lassign [ findchunk $num_vu $count_ware $myposition ] chunk mystart myend ] puts "Loading $chunk Warehouses start:$mystart end:$myend" tsv::lreplace common thrdlst $myposition $myposition active @@ -1050,7 +1058,7 @@ proc do_tpcc { host port socket count_ware user password db mysql_storage_engine } } } - .ed_mainFrame.mainwin.textFrame.left.text fastinsert end "do_tpcc $mysql_host $mysql_port $mysql_socket $mysql_count_ware $mysql_user $mysql_pass $mysql_dbase $mysql_storage_engine $mysql_partition $mysql_num_vu" + .ed_mainFrame.mainwin.textFrame.left.text fastinsert end "do_tpcc $mysql_host $mysql_port $mysql_socket {$mysql_ssl_options} $mysql_count_ware $mysql_user $mysql_pass $mysql_dbase $mysql_storage_engine $mysql_partition $mysql_num_vu" } else { return } } @@ -1071,13 +1079,13 @@ proc insert_mysqlconnectpool_drivescript { testtype timedtype } { #Set the parameters to variables named from the keys, this allows us to build the connect strings according to the database dict with conparams { #set MySQL connect string - set $id [ list $mysql_host $mysql_port $mysql_socket $mysql_user $mysql_pass $mysql_dbase ] + set $id [ list $mysql_host $mysql_port $mysql_socket $mysql_ssl_options $mysql_user $mysql_pass $mysql_dbase ] } } #For the connect keys c1, c2 etc make a connection foreach id [ split $conkeys ] { - lassign [ set $id ] 1 2 3 4 5 6 - dict set connlist $id [ set mysql_handler$id [ ConnectToMySQL $1 $2 $3 $4 $5 $6 ] ] + lassign [ set $id ] 1 2 3 4 5 6 7 + dict set connlist $id [ set mysql_handler$id [ ConnectToMySQL $1 $2 $3 $4 $5 $6 $7 ] ] if { [ set mysql_handler$id ] eq "Failed" } { puts "error, the database connection to $1 could not be established" } @@ -1116,7 +1124,7 @@ proc insert_mysqlconnectpool_drivescript { testtype timedtype } { #puts "sproc_cur:$st connections:[ set $cslist ] cursors:[set $cursor_list] number of cursors:[set $len] execs:[set $cnt]" } #Open standalone connect to determine highest warehouse id for all connections - set mmysql_handler [ ConnectToMySQL $host $port $socket $user $password $db ] + set mmysql_handler [ ConnectToMySQL $host $port $socket $ssl_options $user $password $db ] set w_id_input [ list [ mysql::sel $mmysql_handler "select max(w_id) from warehouse" -list ] ] #2.4.1.1 set warehouse_id stays constant for a given terminal set w_id [ RandomNumber 1 $w_id_input ] @@ -1178,18 +1186,20 @@ proc insert_mysqlconnectpool_drivescript { testtype timedtype } { if {$prepare} { foreach st {neword_st payment_st delivery_st slev_st ostat_st} { catch {mysqlexec $mysql_handler "deallocate prepare $st"} - } - } - mysqlclose $mysql_handler - } - mysqlclose $mmysql_handler - } +} +} +mysqlclose $mysql_handler +} +mysqlclose $mmysql_handler +} #Find single connection start and end points set syncdrvi(1a) [.ed_mainFrame.mainwin.textFrame.left.text search -backwards "#RUN TPC-C" end ] set syncdrvi(1b) [.ed_mainFrame.mainwin.textFrame.left.text search -backwards "mysqlclose \$mysql_handler" end ] #puts "indexes are $syncdrvi(1a) and $syncdrvi(1b)" #Delete text from start and end points + #Bug introduced by reformatting of Tcl #292 remove +1l below .ed_mainFrame.mainwin.textFrame.left.text fastdelete $syncdrvi(1a) $syncdrvi(1b)+1l + #.ed_mainFrame.mainwin.textFrame.left.text fastdelete $syncdrvi(1a) $syncdrvi(1b) #Replace with connect pool version .ed_mainFrame.mainwin.textFrame.left.text fastinsert $syncdrvi(1a) $syncdrvt(1) if { $testtype eq "timed" } { @@ -1267,10 +1277,10 @@ proc insert_mysqlconnectpool_drivescript { testtype timedtype } { .ed_mainFrame.mainwin.textFrame.left.text fastinsert $syncdrvi(3a) $syncdrvt(3) #Remove extra async connection set syncdrvi(7a) [.ed_mainFrame.mainwin.textFrame.left.text search -backwards "#Open standalone connect to determine highest warehouse id for all connections" end ] - set syncdrvi(7b) [.ed_mainFrame.mainwin.textFrame.left.text search -backwards {set mmysql_handler [ ConnectToMySQL $host $port $socket $user $password $db ]} end ] + set syncdrvi(7b) [.ed_mainFrame.mainwin.textFrame.left.text search -backwards {set mmysql_handler [ ConnectToMySQL $host $port $socket $ssl_options $user $password $db ]} end ] .ed_mainFrame.mainwin.textFrame.left.text fastdelete $syncdrvi(7a) $syncdrvi(7b)+1l #Replace individual lines for Asynch - foreach line {{set mysql_handler [ ConnectToMySQLAsynch $host $port $socket $user $password $db $clientname $async_verbose ]} {dict set connlist $id [ set mysql_handler$id [ ConnectToMySQL $1 $2 $3 $4 $5 $6 ] ]} {#puts "sproc_cur:$st connections:[ set $cslist ] cursors:[set $cursor_list] number of cursors:[set $len] execs:[set $cnt]"}} asynchline {{set mmysql_handler [ ConnectToMySQLAsynch $host $port $socket $user $password $db $clientname $async_verbose ]} {dict set connlist $id [ set mysql_handler$id [ ConnectToMySQLAsynch $1 $2 $3 $4 $5 $6 $clientname $async_verbose ] ]} {#puts "$clientname:sproc_cur:$st connections:[ set $cslist ] cursors:[set $cursor_list] number of cursors:[set $len] execs:[set $cnt]"}} { + foreach line {{set mysql_handler [ ConnectToMySQLAsynch $host $port $socket $ssl_options $user $password $db $clientname $async_verbose ]} {dict set connlist $id [ set mysql_handler$id [ ConnectToMySQL $1 $2 $3 $4 $5 $6 ] ]} {#puts "sproc_cur:$st connections:[ set $cslist ] cursors:[set $cursor_list] number of cursors:[set $len] execs:[set $cnt]"}} asynchline {{set mmysql_handler [ ConnectToMySQLAsynch $host $port $socket $user $password $db $clientname $async_verbose ]} {dict set connlist $id [ set mysql_handler$id [ ConnectToMySQLAsynch $1 $2 $3 $4 $5 $6 $clientname $async_verbose ] ]} {#puts "$clientname:sproc_cur:$st connections:[ set $cslist ] cursors:[set $cursor_list] number of cursors:[set $len] execs:[set $cnt]"}} { set index [.ed_mainFrame.mainwin.textFrame.left.text search -backwards $line end ] .ed_mainFrame.mainwin.textFrame.left.text fastdelete $index "$index lineend + 1 char" .ed_mainFrame.mainwin.textFrame.left.text fastinsert $index "$asynchline \n" @@ -1307,7 +1317,7 @@ proc insert_mysqlconnectpool_drivescript { testtype timedtype } { } proc loadmysqltpcc { } { - global _ED + global _ED mysql_ssl_options upvar #0 dbdict dbdict if {[dict exists $dbdict mysql library ]} { set library [ dict get $dbdict mysql library ] @@ -1315,6 +1325,10 @@ proc loadmysqltpcc { } { upvar #0 configmysql configmysql #set variables to values in dict setlocaltpccvars $configmysql + #If the options menu has been run under the GUI mysql_ssl_options is set + #If build is run under the GUI, CLI or WS mysql_ssl_options is not set + #Set it now if it doesn't exist + if ![ info exists mysql_ssl_options ] { check_mysql_ssl $configmysql } ed_edit_clear .ed_mainFrame.notebook select .ed_mainFrame.mainwin set _ED(packagekeyname) "MySQL TPROC-C" @@ -1328,6 +1342,7 @@ set KEYANDTHINK \"$mysql_keyandthink\" ;# Time for user thinking and keying (tru set host \"$mysql_host\" ;# Address of the server hosting MySQL set port \"$mysql_port\" ;# Port of the MySQL Server, defaults to 3306 set socket \"$mysql_socket\" ;# MySQL Socket for local connections +set ssl_options {$mysql_ssl_options} ;# MySQL SSL/TLS options set user \"$mysql_user\" ;# MySQL user set password \"$mysql_pass\" ;# Password for the MySQL user set db \"$mysql_dbase\" ;# Database containing the TPC Schema @@ -1351,26 +1366,39 @@ proc chk_socket { host socket } { } } -proc ConnectToMySQL { host port socket user password db } { +proc ConnectToMySQL { host port socket ssl_options user password db } { global mysqlstatus + #ssl_options is variable length so build a connectstring if { [ chk_socket $host $socket ] eq "TRUE" } { - if [catch {mysqlconnect -socket $socket -user $user -password $password} mysql_handler] { + set use_socket "true" + append connectstring " -socket $socket" + } else { + set use_socket "false" + append connectstring " -host $host -port $port" + } + foreach key [ dict keys $ssl_options ] { + append connectstring " $key [ dict get $ssl_options $key ] " + } + append connectstring " -user $user -password $password" + set login_command "mysqlconnect [ dict get $connectstring ]" + #eval the login command + if [catch {set mysql_handler [eval $login_command]}] { + if $use_socket { puts "the local socket connection to $socket could not be established" - set connected "FALSE" } else { - set connected "TRUE" - } - } else { - if [catch {mysqlconnect -host $host -port $port -user $user -password $password} mysql_handler] { puts "the tcp connection to $host:$port could not be established" - set connected "FALSE" - } else { - set connected "TRUE" } + set connected "false" + } else { + set connected "true" } if {$connected} { mysqluse $mysql_handler $db mysql::autocommit $mysql_handler 0 + catch {set ssl_status [ mysql::sel $mysql_handler "show session status like 'ssl_cipher'" -list ]} + if { [ info exists ssl_status ] } { + puts [ join $ssl_status ] + } return $mysql_handler } else { error $mysqlstatus(message) @@ -1550,7 +1578,7 @@ proc prep_statement { mysql_handler statement_st } { } } #RUN TPC-C -set mysql_handler [ ConnectToMySQL $host $port $socket $user $password $db ] +set mysql_handler [ ConnectToMySQL $host $port $socket $ssl_options $user $password $db ] if {$prepare} { foreach st {neword_st payment_st delivery_st slev_st ostat_st} { set $st [ prep_statement $mysql_handler $st ] } } @@ -1596,14 +1624,15 @@ if {$prepare} { catch {mysqlexec $mysql_handler "deallocate prepare $st"} } } -mysqlclose $mysql_handler} - if { $mysql_connect_pool } { - insert_mysqlconnectpool_drivescript test sync - } +mysqlclose $mysql_handler +} +if { $mysql_connect_pool } { + insert_mysqlconnectpool_drivescript test sync +} } proc loadtimedmysqltpcc { } { - global opmode _ED + global opmode _ED mysql_ssl_options upvar #0 dbdict dbdict if {[dict exists $dbdict mysql library ]} { set library [ dict get $dbdict mysql library ] @@ -1611,6 +1640,10 @@ proc loadtimedmysqltpcc { } { upvar #0 configmysql configmysql #set variables to values in dict setlocaltpccvars $configmysql + #If the options menu has been run under the GUI mysql_ssl_options is set + #If build is run under the GUI, CLI or WS mysql_ssl_options is not set + #Set it now if it doesn't exist + if ![ info exists mysql_ssl_options ] { check_mysql_ssl $configmysql } ed_edit_clear .ed_mainFrame.notebook select .ed_mainFrame.mainwin set _ED(packagekeyname) "MySQL TPROC-C Timed" @@ -1629,6 +1662,7 @@ set mode \"$opmode\" ;# HammerDB operational mode set host \"$mysql_host\" ;# Address of the server hosting MySQL set port \"$mysql_port\" ;# Port of the MySQL Server, defaults to 3306 set socket \"$mysql_socket\" ;# MySQL Socket for local connections +set ssl_options {$mysql_ssl_options} ;# MySQL SSL/TLS options set user \"$mysql_user\" ;# MySQL user set password \"$mysql_pass\" ;# Password for the MySQL user set db \"$mysql_dbase\" ;# Database containing the TPC Schema @@ -1651,26 +1685,39 @@ proc chk_socket { host socket } { } } -proc ConnectToMySQL { host port socket user password db } { +proc ConnectToMySQL { host port socket ssl_options user password db } { global mysqlstatus + #ssl_options is variable length so build a connectstring if { [ chk_socket $host $socket ] eq "TRUE" } { - if [catch {mysqlconnect -socket $socket -user $user -password $password} mysql_handler] { + set use_socket "true" + append connectstring " -socket $socket" + } else { + set use_socket "false" + append connectstring " -host $host -port $port" + } + foreach key [ dict keys $ssl_options ] { + append connectstring " $key [ dict get $ssl_options $key ] " + } + append connectstring " -user $user -password $password" + set login_command "mysqlconnect [ dict get $connectstring ]" + #eval the login command + if [catch {set mysql_handler [eval $login_command]}] { + if $use_socket { puts "the local socket connection to $socket could not be established" - set connected "FALSE" } else { - set connected "TRUE" - } - } else { - if [catch {mysqlconnect -host $host -port $port -user $user -password $password} mysql_handler] { puts "the tcp connection to $host:$port could not be established" - set connected "FALSE" - } else { - set connected "TRUE" } + set connected "false" + } else { + set connected "true" } if {$connected} { mysqluse $mysql_handler $db mysql::autocommit $mysql_handler 0 + catch {set ssl_status [ mysql::sel $mysql_handler "show session status like 'ssl_cipher'" -list ]} + if { [ info exists ssl_status ] } { + puts [ join $ssl_status ] + } return $mysql_handler } else { error $mysqlstatus(message) @@ -1682,28 +1729,8 @@ set rema [ lassign [ findvuposition ] myposition totalvirtualusers ] switch $myposition { 1 { if { $mode eq "Local" || $mode eq "Primary" } { - if { [ chk_socket $host $socket ] eq "TRUE" } { - if [catch {mysqlconnect -socket $socket -user $user -password $password} mysql_handler] { - puts "the local socket connection to $socket could not be established" - set connected "FALSE" - } else { - set connected "TRUE" - } - } else { - if [catch {mysqlconnect -host $host -port $port -user $user -password $password} mysql_handler] { - puts "the tcp connection to $host:$port could not be established" - set connected "FALSE" - } else { - set connected "TRUE" - } - } - if {$connected} { - mysqluse $mysql_handler $db - mysql::autocommit $mysql_handler 1 - } else { - error $mysqlstatus(message) - return - } + set mysql_handler [ ConnectToMySQL $host $port $socket $ssl_options $user $password $db ] + mysql::autocommit $mysql_handler 1 set ramptime 0 puts "Beginning rampup time of $rampup minutes" set rampup [ expr $rampup*60000 ] @@ -1940,7 +1967,7 @@ switch $myposition { } } #RUN TPC-C - set mysql_handler [ ConnectToMySQL $host $port $socket $user $password $db ] + set mysql_handler [ ConnectToMySQL $host $port $socket $ssl_options $user $password $db ] if {$prepare} { foreach st {neword_st payment_st delivery_st slev_st ostat_st} { set $st [ prep_statement $mysql_handler $st ] } } @@ -1981,13 +2008,13 @@ switch $myposition { catch {mysqlexec $mysql_handler "deallocate prepare $st"} } } - mysqlclose $mysql_handler - } +mysqlclose $mysql_handler +} }} - if { $mysql_connect_pool } { - insert_mysqlconnectpool_drivescript timed sync - } - } else { +if { $mysql_connect_pool } { + insert_mysqlconnectpool_drivescript timed sync +} +} else { #ASYNCHRONOUS TIMED SCRIPT .ed_mainFrame.mainwin.textFrame.left.text fastinsert end "#!/usr/local/bin/tclsh8.6 #EDITABLE OPTIONS################################################## @@ -2002,6 +2029,7 @@ set mode \"$opmode\" ;# HammerDB operational mode set host \"$mysql_host\" ;# Address of the server hosting MySQL set port \"$mysql_port\" ;# Port of the MySQL Server, defaults to 3306 set socket \"$mysql_socket\" ;# MySQL Socket for local connections +set ssl_options {$mysql_ssl_options} ;# MySQL SSL/TLS options set user \"$mysql_user\" ;# MySQL user set password \"$mysql_pass\" ;# Password for the MySQL user set db \"$mysql_dbase\" ;# Database containing the TPC Schema @@ -2028,25 +2056,84 @@ proc chk_socket { host socket } { } } -proc ConnectToMySQLAsynch { host port socket user password db clientname async_verbose } { +proc ConnectToMySQL { host port socket ssl_options user password db } { global mysqlstatus + #ssl_options is variable length so build a connectstring if { [ chk_socket $host $socket ] eq "TRUE" } { - if [catch {mysqlconnect -socket $socket -user $user -password $password} mysql_handler] { - set connected "FALSE" - puts "$clientname:socket login failed:$mysqlstatus(message)" + set use_socket "true" + append connectstring " -socket $socket" + } else { + set use_socket "false" + append connectstring " -host $host -port $port" + } + foreach key [ dict keys $ssl_options ] { + append connectstring " $key [ dict get $ssl_options $key ] " + } + append connectstring " -user $user -password $password" + set login_command "mysqlconnect [ dict get $connectstring ]" + #eval the login command + if [catch {set mysql_handler [eval $login_command]}] { + if $use_socket { + puts "the local socket connection to $socket could not be established" } else { - set connected "TRUE" + puts "the tcp connection to $host:$port could not be established" + } + set connected "false" + } else { + set connected "true" + } + if {$connected} { + mysqluse $mysql_handler $db + mysql::autocommit $mysql_handler 0 + catch {set ssl_status [ mysql::sel $mysql_handler "show session status like 'ssl_cipher'" -list ]} + if { [ info exists ssl_status ] } { + puts [ join $ssl_status ] } + return $mysql_handler + } else { + error $mysqlstatus(message) + return + } +} + +proc ConnectToMySQLAsynch { host port socket ssl_options user password db clientname async_verbose } { + global mysqlstatus + #ssl_options is variable length so build a connectstring + if { [ chk_socket $host $socket ] eq "TRUE" } { + set use_socket "true" + append connectstring " -socket $socket" } else { - if [catch {mysqlconnect -host $host -port $port -user $user -password $password} mysql_handler] { - set connected "FALSE" - puts "$clientname:tcp login failed:$mysqlstatus(message)" + set use_socket "false" + append connectstring " -host $host -port $port" + } + foreach key [ dict keys $ssl_options ] { + append connectstring " $key [ dict get $ssl_options $key ] " + } + append connectstring " -user $user -password $password" + set login_command "mysqlconnect [ dict get $connectstring ]" + #eval the login command + if [catch {set mysql_handler [eval $login_command]}] { + if $use_socket { + if $async_verbose { + puts "$clientname:socket login failed:$mysqlstatus(message)" + } } else { - set connected "TRUE" + if $async_verbose { + puts "$clientname:tcp login failed:$mysqlstatus(message)" + } } + set connected "false" + } else { + set connected "true" } if {$connected} { - if { $async_verbose } { puts "Connected $clientname:$mysql_handler" } + if { $async_verbose } { + puts "Connected $clientname:$mysql_handler" + catch {set ssl_status [ mysql::sel $mysql_handler "show session status like 'ssl_cipher'" -list ]} + if { [ info exists ssl_status ] } { + puts "$clientname:[ join $ssl_status ]" + } + } mysqluse $mysql_handler $db mysql::autocommit $mysql_handler 0 return $mysql_handler @@ -2059,28 +2146,8 @@ set rema [ lassign [ findvuposition ] myposition totalvirtualusers ] switch $myposition { 1 { if { $mode eq "Local" || $mode eq "Primary" } { - if { [ chk_socket $host $socket ] eq "TRUE" } { - if [catch {mysqlconnect -socket $socket -user $user -password $password} mysql_handler] { - puts "the local socket connection to $socket could not be established" - set connected "FALSE" - } else { - set connected "TRUE" - } - } else { - if [catch {mysqlconnect -host $host -port $port -user $user -password $password} mysql_handler] { - puts "the tcp connection to $host:$port could not be established" - set connected "FALSE" - } else { - set connected "TRUE" - } - } - if {$connected} { - mysqluse $mysql_handler $db - mysql::autocommit $mysql_handler 1 - } else { - error $mysqlstatus(message) - return - } + set mysql_handler [ ConnectToMySQL $host $port $socket $ssl_options $user $password $db ] + mysql::autocommit $mysql_handler 1 set ramptime 0 puts "Beginning rampup time of $rampup minutes" set rampup [ expr $rampup*60000 ] @@ -2322,14 +2389,14 @@ switch $myposition { } } #CONNECT ASYNC - promise::async simulate_client { clientname total_iterations host port socket user password RAISEERROR KEYANDTHINK db prepare async_verbose async_delay } { + promise::async simulate_client { clientname total_iterations host port socket ssl_options user password RAISEERROR KEYANDTHINK db prepare async_verbose async_delay } { global mysqlstatus set acno [ expr [ string trimleft [ lindex [ split $clientname ":" ] 1 ] ac ] * $async_delay ] if { $async_verbose } { puts "Delaying login of $clientname for $acno ms" } async_time $acno if { [ tsv::get application abort ] } { return "$clientname:abort before login" } if { $async_verbose } { puts "Logging in $clientname" } - set mysql_handler [ ConnectToMySQLAsynch $host $port $socket $user $password $db $clientname $async_verbose ] + set mysql_handler [ ConnectToMySQLAsynch $host $port $socket $ssl_options $user $password $db $clientname $async_verbose ] #RUN TPC-C if {$prepare} { foreach st {neword_st payment_st delivery_st slev_st ostat_st} { set $st [ prep_statement $mysql_handler $st ] } @@ -2383,18 +2450,21 @@ switch $myposition { for {set ac 1} {$ac <= $async_client} {incr ac} { set clientdesc "vuser$myposition:ac$ac" lappend clientlist $clientdesc - lappend clients [simulate_client $clientdesc $total_iterations $host $port $socket $user $password $RAISEERROR $KEYANDTHINK $db $prepare $async_verbose $async_delay] + lappend clients [simulate_client $clientdesc $total_iterations $host $port $socket $ssl_options $user $password $RAISEERROR $KEYANDTHINK $db $prepare $async_verbose $async_delay] } puts "Started asynchronous clients:$clientlist" set acprom [ promise::eventloop [ promise::all $clients ] ] puts "All asynchronous clients complete" if { $async_verbose } { foreach client $acprom { puts $client } - } - } +} +} }} - if { $mysql_connect_pool } { - insert_mysqlconnectpool_drivescript timed async - } - } +#Reformatting src causes error when inserting timeprofile +#Do not modify double close bracket above +#Close bracket of fast insert must come directly after inserted code without newline +if { $mysql_connect_pool } { +insert_mysqlconnectpool_drivescript timed async +} +} } diff --git a/src/mysql/mysqlopt.tcl b/src/mysql/mysqlopt.tcl index a51457a5..db2cf782 100755 --- a/src/mysql/mysqlopt.tcl +++ b/src/mysql/mysqlopt.tcl @@ -1,3 +1,73 @@ +proc check_mysql_ssl { configdict } { + global mysql_ssl_options + unset -nocomplain mysql_ssl_options + upvar #0 configmysql configmysql + #set local variables to dict for checking + foreach key [ dict keys [ dict get $configdict connection ] *ssl* ] { + set $key [ dict get $configdict connection $key ] + } + #Use correct directory + if {![string match windows $::tcl_platform(platform)]} { + set capath $mysql_ssl_linux_capath + } else { + set capath $mysql_ssl_windows_capath + } + #If SSL not enabled return + if { $mysql_ssl != "true" } { + #nothing to check, mysql_ssl_options is not set + set mysql_ssl_options " -ssl false " + return + } else { + #SSL is enabled, check that capath is valid + if { [ file isdirectory $capath ] } { + if { $mysql_ssl_ca eq "" && $mysql_ssl_cert eq "" && $mysql_ssl_key eq "" } { + #All of the file entries are blank, use capath only + } else { + #CApath is valid, file entires are not blank, always check CA + if { [ file readable [ file join $capath $mysql_ssl_ca ]] } { + } else { + tk_messageBox -message "[ file join $capath $mysql_ssl_ca ] is not readable, disabling SSL" + dict set configmysql connection mysql_ssl "false" + return + } + #capath and ca are readable + if { $mysql_ssl_two_way eq "true" } { + #Also check Cert and Key readable + foreach sslfile [ list $mysql_ssl_cert $mysql_ssl_key ] { + if { [ file readable [ file join $capath $sslfile ]] } { + } else { + tk_messageBox -message "[ file join $capath $sslfile ] is not readable, disabling SSL" + dict set configmysql connection mysql_ssl "false" + return + } + } + } + } + } else { + tk_messageBox -message "SSL CApath is not a valid directory, disabling SSL" + #Set SSL to false + dict set configmysql connection mysql_ssl "false" + return + } + } + #SSL is true and all files needed are readable, build options + append mysql_ssl_options " -ssl true " + if { $mysql_ssl_ca eq "" && $mysql_ssl_cert eq "" && $mysql_ssl_key eq "" } { + #No files given as an argument use -capath only + append mysql_ssl_options " -sslcapath $capath " + } else { + #for one-way use -sslca only + append mysql_ssl_options " -sslca [ file join $capath $mysql_ssl_ca ] " + if { $mysql_ssl_two_way eq "true" } { + #for two-way add -sslcert & -sslkey + append mysql_ssl_options " -sslcert [ file join $capath $mysql_ssl_cert ] " + append mysql_ssl_options " -sslkey [ file join $capath $mysql_ssl_key ] " + } + } + #if ssl_cipher has changed add the option + if { $mysql_ssl_cipher != "server" } { append mysql_ssl_options " -sslcipher $mysql_ssl_cipher " } +} + proc countmysqlopts { bm } { upvar #0 icons icons upvar #0 configmysql configmysql @@ -13,9 +83,21 @@ proc countmysqlopts { bm } { setlocaltcountvars $configmysql 1 variable myoptsfields if { $bm eq "TPC-C" } { - set myoptsfields [ dict create connection {mysql_host {.countopt.f1.e1 get} mysql_port {.countopt.f1.e2 get} mysql_socket {.countopt.f1.e2a get}} tpcc {mysql_user {.countopt.f1.e3 get} mysql_pass {.countopt.f1.e4 get}} ] + if {![string match windows $::tcl_platform(platform)]} { + set platform "lin" + set mysqloptsfields [ dict create connection {mysql_host {.countopt.f1.e1 get} mysql_port {.countopt.f1.e2 get} mysql_socket {.countopt.f1.e2a get} mysql_ssl_ca {.countopt.f1.e2d get} mysql_ssl_cert {.countopt.f1.e2e get} mysql_ssl_key {.countopt.f1.e2f get} mysql_ssl_cipher {.countopt.f1.e2g get} mysql_ssl $mysql_ssl mysql_ssl_two_way $mysql_ssl_two_way mysql_ssl_linux_capath $mysql_ssl_linux_capath} tpcc {mysql_user {.countopt.f1.e3 get} mysql_pass {.countopt.f1.e4 get}} ] + } else { + set platform "win" + set mysqloptsfields [ dict create connection {mysql_host {.countopt.f1.e1 get} mysql_port {.countopt.f1.e2 get} mysql_socket {.countopt.f1.e2a get} mysql_ssl_ca {.countopt.f1.e2d get} mysql_ssl_cert {.countopt.f1.e2e get} mysql_ssl_key {.countopt.f1.e2f get} mysql_ssl_cipher {.countopt.f1.e2g get} mysql_ssl $mysql_ssl mysql_ssl_two_way $mysql_ssl_two_way mysql_ssl_windows_capath {$mysql_ssl_windows_capath}} tpcc {mysql_user {.countopt.f1.e3 get} mysql_pass {.countopt.f1.e4 get}} ] + } } else { - set myoptsfields [ dict create connection {mysql_host {.countopt.f1.e1 get} mysql_port {.countopt.f1.e2 get} mysql_socket {.countopt.f1.e2a get}} tpch {mysql_tpch_user {.countopt.f1.e3 get} mysql_tpch_pass {.countopt.f1.e4 get}} ] + if {![string match windows $::tcl_platform(platform)]} { + set platform "lin" + set mysqloptsfields [ dict create connection {mysql_host {.countopt.f1.e1 get} mysql_port {.countopt.f1.e2 get} mysql_socket {.countopt.f1.e2a get} mysql_ssl_ca {.countopt.f1.e2d get} mysql_ssl_cert {.countopt.f1.e2e get} mysql_ssl_key {.countopt.f1.e2f get} mysql_ssl_cipher {.countopt.f1.e2g get} mysql_ssl $mysql_ssl mysql_ssl_two_way $mysql_ssl_two_way mysql_ssl_linux_capath $mysql_ssl_linux_capath} tpch {mysql_tpch_user {.countopt.f1.e3 get} mysql_tpch_pass {.countopt.f1.e4 get}} ] + } else { + set platform "win" + set mysqloptsfields [ dict create connection {mysql_host {.countopt.f1.e1 get} mysql_port {.countopt.f1.e2 get} mysql_socket {.countopt.f1.e2a get} mysql_ssl_ca {.countopt.f1.e2d get} mysql_ssl_cert {.countopt.f1.e2e get} mysql_ssl_key {.countopt.f1.e2f get} mysql_ssl_cipher {.countopt.f1.e2g get} mysql_ssl $mysql_ssl mysql_ssl_two_way $mysql_ssl_two_way mysql_ssl_windows_capath {$mysql_ssl_windows_capath}} tpch {mysql_tpch_user {.countopt.f1.e3 get} mysql_tpch_pass {.countopt.f1.e4 get}} ] + } } if { [ info exists afval ] } { after cancel $afval @@ -59,6 +141,113 @@ proc countmysqlopts { bm } { set mysql_socket "null" .countopt.f1.e2a configure -state disabled } + + set Name $Parent.f1.e2b + set Prompt $Parent.f1.p2b + ttk::label $Prompt -text "Enable SSL :" + ttk::checkbutton $Name -text "" -variable mysql_ssl -onvalue "true" -offvalue "false" + grid $Prompt -column 0 -row 4 -sticky e + grid $Name -column 1 -row 4 -sticky w + + bind .countopt.f1.e2b { + if { $mysql_ssl eq "true" } { + .countopt.f1.e2ba configure -state disabled + .countopt.f1.e2bb configure -state disabled + .countopt.f1.e2c configure -state disabled + .countopt.f1.e2d configure -state disabled + .countopt.f1.e2e configure -state disabled + .countopt.f1.e2f configure -state disabled + .countopt.f1.e2g configure -state disabled + } else { + .countopt.f1.e2ba configure -state normal + .countopt.f1.e2bb configure -state normal + .countopt.f1.e2c configure -state normal + .countopt.f1.e2d configure -state normal + if { $mysql_ssl_two_way eq "true" } { + .countopt.f1.e2e configure -state normal + .countopt.f1.e2f configure -state normal + } + .countopt.f1.e2g configure -state normal + } + } + + set Name $Parent.f1.e2ba + ttk::radiobutton $Name -value "false" -text "SSL One-Way" -variable mysql_ssl_two_way + grid $Name -column 1 -row 5 -sticky w + if { $mysql_ssl eq "false" } { + .countopt.f1.e2ba configure -state disabled + } + bind .countopt.f1.e2ba { + .countopt.f1.e2e configure -state disabled + .countopt.f1.e2f configure -state disabled + } + + set Name $Parent.f1.e2bb + ttk::radiobutton $Name -value "true" -text "SSL Two-Way" -variable mysql_ssl_two_way + grid $Name -column 1 -row 6 -sticky w + if { $mysql_ssl eq "false" } { + .countopt.f1.e2bb configure -state disabled + } + + bind .countopt.f1.e2bb { + .countopt.f1.e2e configure -state normal + .countopt.f1.e2f configure -state normal + } + + set Name $Parent.f1.e2c + set Prompt $Parent.f1.p2c + ttk::label $Prompt -text "SSL CApath :" + if { $platform eq "lin" } { + ttk::entry $Name -width 30 -textvariable mysql_ssl_linux_capath + } else { + ttk::entry $Name -width 30 -textvariable mysql_ssl_windows_capath + } + grid $Prompt -column 0 -row 7 -sticky e + grid $Name -column 1 -row 7 -sticky ew + if { $mysql_ssl == "false" } { + $Name configure -state disabled + } + + set Name $Parent.f1.e2d + set Prompt $Parent.f1.p2d + ttk::label $Prompt -text "SSL CA :" + ttk::entry $Name -width 30 -textvariable mysql_ssl_ca + grid $Prompt -column 0 -row 8 -sticky e + grid $Name -column 1 -row 8 -sticky ew + if { $mysql_ssl == "false" } { + $Name configure -state disabled + } + + set Name $Parent.f1.e2e + set Prompt $Parent.f1.p2e + ttk::label $Prompt -text "SSL Cert :" + ttk::entry $Name -width 30 -textvariable mysql_ssl_cert + grid $Prompt -column 0 -row 9 -sticky e + grid $Name -column 1 -row 9 -sticky ew + if { $mysql_ssl == "false" } { + $Name configure -state disabled + } + + set Name $Parent.f1.e2f + set Prompt $Parent.f1.p2f + ttk::label $Prompt -text "SSL Key :" + ttk::entry $Name -width 30 -textvariable mysql_ssl_key + grid $Prompt -column 0 -row 10 -sticky e + grid $Name -column 1 -row 10 -sticky ew + if { $mysql_ssl == "false" } { + $Name configure -state disabled + } + + set Name $Parent.f1.e2g + set Prompt $Parent.f1.p2g + ttk::label $Prompt -text "SSL Cipher :" + ttk::entry $Name -width 30 -textvariable mysql_ssl_cipher + grid $Prompt -column 0 -row 11 -sticky e + grid $Name -column 1 -row 11 -sticky ew + if { $mysql_ssl == "false" } { + $Name configure -state disabled + } + set Name $Parent.f1.e3 set Prompt $Parent.f1.p3 ttk::label $Prompt -text "MySQL User :" @@ -67,8 +256,8 @@ proc countmysqlopts { bm } { } else { ttk::entry $Name -width 30 -textvariable mysql_tpch_user } - grid $Prompt -column 0 -row 4 -sticky e - grid $Name -column 1 -row 4 -sticky ew + grid $Prompt -column 0 -row 12 -sticky e + grid $Name -column 1 -row 12 -sticky ew set Name $Parent.f1.e4 set Prompt $Parent.f1.p4 ttk::label $Prompt -text "MySQL User Password :" @@ -77,18 +266,18 @@ proc countmysqlopts { bm } { } else { ttk::entry $Name -width 30 -textvariable mysql_tpch_pass } - grid $Prompt -column 0 -row 5 -sticky e - grid $Name -column 1 -row 5 -sticky ew + grid $Prompt -column 0 -row 13 -sticky e + grid $Name -column 1 -row 13 -sticky ew set Name $Parent.f1.e5 set Prompt $Parent.f1.p5 ttk::label $Prompt -text "Refresh Rate(secs) :" ttk::entry $Name -width 30 -textvariable interval - grid $Prompt -column 0 -row 6 -sticky e - grid $Name -column 1 -row 6 -sticky ew + grid $Prompt -column 0 -row 14 -sticky e + grid $Name -column 1 -row 14 -sticky ew set Name $Parent.f1.e7 ttk::checkbutton $Name -text "Log Output to Temp" -variable tclog -onvalue 1 -offvalue 0 - grid $Name -column 1 -row 7 -sticky w + grid $Name -column 1 -row 15 -sticky w bind .countopt.f1.e7