Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MDEV-14978] Client programs to use $MARIADB_HOST consistently #2556

Open
wants to merge 1 commit into
base: 11.5
Choose a base branch
from

Conversation

oceanli-hub
Copy link

@oceanli-hub oceanli-hub commented Mar 16, 2023

Description

Note: mysql_upgrade already uses environment variable as default. This feature was not added in for mysql_plugin and mysqltest

Only mysql client program was using $MYSQL_HOST as the default host.
Add the same feature in most other client programs but using $MARIADB_HOST instead.

How can this PR be tested?

Set up environment variable export MARIADB_HOST=your_test_server

Run each client program with the following commands:

client/mysqlslap -h another_test_server -P 3306 -u admin -p

client/mysqlslap -P 3306 -u admin -p

Verify that $MARIADB_HOST is used when -h is not specified. Also verify $MARIADB_HOST does not override command line argument.

Basing the PR against the correct MariaDB version

  • This is a new feature and the PR is based against the latest MariaDB development branch

Copyright

All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.

@CLAassistant
Copy link

CLAassistant commented Mar 16, 2023

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@ottok
Copy link
Contributor

ottok commented Mar 18, 2023

This is an improved take on #1067. Please review and merge, thanks!

Copy link
Member

@grooverdan grooverdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're able to update the man pages for these client utilities too that would be appreciated.

client/mysqladmin.cc Outdated Show resolved Hide resolved
client/mysqladmin.cc Outdated Show resolved Hide resolved
client/mysqladmin.cc Outdated Show resolved Hide resolved
--let MYSQLDUMP = $MYSQL_BINDIR/client//mariadb-dump
--let MYSQLIMPORT = $MYSQL_BINDIR/client//mariadb-import
--let MYSQLSHOW = $MYSQL_BINDIR/client//mariadb-show
--let MYSQLSLAP = $MYSQL_BINDIR/client//mariadb-slap
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all set in mysql-test/mariadb-test-run.pl, though usually as with underscore like $MYSQL_CHECK.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The environment variables for the client programs have a default options file argument in them. The options file was stopping me from testing the client programs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, they should probably be things like MARIABINLOG, etc...

mysql-test/suite/client/client-env-variable.test Outdated Show resolved Hide resolved

--echo ****************
--echo # Setting MYSQL_HOST environment variable
--let MYSQL_HOST=nonexistent-sever
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling "server"

--exec $MYSQLIMPORT $options env_variable --local $MYSQL_TMP_DIR/pet > /dev/null 2>&1
--exec $MYSQLSHOW $options env_variable > /dev/null 2>&1
--exec $MYSQLSLAP $options > /dev/null 2>&1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there positive test examples using MYSQL_HOST MARIADB_HOST maybe with --protocol tcp?

@grooverdan grooverdan self-assigned this Mar 29, 2023
@grooverdan grooverdan added license-bsd-new Contributed under BSD-new license need feedback Can the contributor please address the questions asked. labels Mar 29, 2023
@oceanli-hub oceanli-hub requested a review from ottok as a code owner April 18, 2023 00:03
@oceanli-hub oceanli-hub changed the base branch from 11.0 to 11.1 April 18, 2023 00:05
@oceanli-hub oceanli-hub changed the title [MDEV-14978] Client programs to use $MYSQL_HOST consistently [MDEV-14978] Client programs to use $MARIADB_HOST consistently Apr 18, 2023
@oceanli-hub
Copy link
Author

Hi @grooverdan I updated my pull requested based off your feedback. I also updated the help function to include $MARIADB_HOST. In mysqlbinlog and mysqldump the memory is freed at the end during clean up so I was getting SIGSEV error when trying to use assignment. Assignments work for all the other client programs.

For mysql client program would you like me to change it to $MARIADB_HOST in this pr also?

Thanks for the review!

# Clean up
--echo Done
DROP TABLE pet;
--exec rm $MYSQL_TMP_DIR/tmp.sql
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--remove_file for windows compatibility

Copy link
Member

@grooverdan grooverdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For mysql client program would you like me to change it to $MARIADB_HOST in this pr also?

Sure, but in this case $MARIADB_HOST will be preferred over $MYSQL_HOST so:

if (!(tmp= getenv("MARIADB_HOST"))
  tmp= getenv("MYSQL_HOST")
...

@@ -437,6 +437,9 @@ static int get_options(int *argc, char ***argv)
int ho_error;
DBUG_ENTER("get_options");

if (current_host == NULL)
current_host = getenv("MARIADB_HOST");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style fix (applies to all other code too),

current_host= getenv...

No space between var and =.

EOF

# Options for client program
--let $options = --user=root --port=16000 --socket=$MYSQL_TMP_DIR/mysqld.1.sock
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

port and socket aren't fixed.

$MASTER_MYPORT and $MASTER_MYSOCK (from mysql-test/include/default_my.cnf - no include required - its a default).

Or, if you create a client-env-variable.cnf like:

!include include/default_my.cnf

[ENV]
MARIADB_HOST=localhost

This is a true environment variable.

Then $options to be --port=$MASTER_MYPORT (opmit socket so it doesn't get used) and use a positive test (no more --error) to ensure the connection is there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no more --error

I am not sure if you want to remove the negative test case with --error. I added the positive test case but kept the negative test case in the new revision.

@oceanli-hub
Copy link
Author

I pushed a new revision based off feedback. $MARIADB_HOST is added the mysql client program. For the MTR test, I created client-env-variable.cnf and added positive tests to show the connection is there.

Copy link
Contributor

@LinuxJedi LinuxJedi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, one more final cleanup pass and I think we are there.

@@ -374,6 +373,9 @@ int main(int argc,char *argv[])
MYSQL mysql;
char **commands, **save_argv, **temp_argv;

if (host==NULL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor style thing, spaces around ==.

client/mysql.cc Outdated
@@ -1704,8 +1704,8 @@ static struct my_option my_long_options[] =
&opt_local_infile, &opt_local_infile, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"no-beep", 'b', "Turn off beep on error.", &opt_nobeep,
&opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"host", 'h', "Connect to host.", &current_host,
&current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"host", 'h', "Connect to host. If host is not specified, connect to localhost by default or $MARIADB_HOST",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect it would read better if this said something along the lines of "Defaults in the following order: environment variables MARIADB_HOST, MYSQL_HOST, and then localhost."

client/mysql.cc Outdated
@@ -1704,8 +1704,8 @@ static struct my_option my_long_options[] =
&opt_local_infile, &opt_local_infile, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"no-beep", 'b', "Turn off beep on error.", &opt_nobeep,
&opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"host", 'h', "Connect to host.", &current_host,
&current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"host", 'h', "Connect to host. If host is not specified, connect to localhost by default or $MARIADB_HOST",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, as a style thing, line is longer than 80 chars.

--let MYSQLDUMP = $MYSQL_BINDIR/client//mariadb-dump
--let MYSQLIMPORT = $MYSQL_BINDIR/client//mariadb-import
--let MYSQLSHOW = $MYSQL_BINDIR/client//mariadb-show
--let MYSQLSLAP = $MYSQL_BINDIR/client//mariadb-slap
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, they should probably be things like MARIABINLOG, etc...

@oceanli-hub oceanli-hub changed the base branch from 11.1 to 11.5 April 9, 2024 22:44
Only `mysql` client program was using $MYSQL_HOST as the default host.
Add the same feature in most other client programs but using
$MARIADB_HOST instead.

All new code of the whole pull request, including one or several files that are
either new files or modified ones, are contributed under the BSD-new license. I
am contributing on behalf of my employer Amazon Web Services, Inc.
@oceanli-hub
Copy link
Author

@LinuxJedi thanks for the feedback, I pushed a new revision based off your comments. Please review again.

Copy link
Contributor

@LinuxJedi LinuxJedi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is the bases covered now, many thanks.

Copy link
Member

@grooverdan grooverdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. Ready for 11.6 testing.

optional improvement of manual pages welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
license-bsd-new Contributed under BSD-new license need feedback Can the contributor please address the questions asked.
5 participants