Skip to content

MDEV-21465: expose bind-address parameter via cmd options in client#2750

Merged
grooverdan merged 2 commits intoMariaDB:11.4from
yvef:11.3-client-param-bnd-addr
Nov 17, 2023
Merged

MDEV-21465: expose bind-address parameter via cmd options in client#2750
grooverdan merged 2 commits intoMariaDB:11.4from
yvef:11.3-client-param-bnd-addr

Conversation

@yvef
Copy link
Copy Markdown
Contributor

@yvef yvef commented Sep 6, 2023

  • The Jira issue number for this PR is: MDEV-21465

Description

  1. The PR is intended to provide the command line parameter to use existing functionality of address binding for outbound connections in mariadb client.
  2. __
  3. No side-effects.

How can this PR be tested?

TODO: modify the automated test suite to verify that the PR causes MariaDB to behave as intended.
Consult the documentation on "Writing good test cases".

If the changes are not amenable to automated testing, please explain why not and carefully describe how to test manually.

Basing the PR against the correct MariaDB version

  • This is a new feature and the PR is based against the latest MariaDB development branch.
  • This is a bug fix and the PR is based against the earliest maintained branch in which the bug can be reproduced.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Sep 6, 2023

CLA assistant check
All committers have signed the CLA.

@yvef yvef force-pushed the 11.3-client-param-bnd-addr branch from 328c553 to 6aa0836 Compare September 6, 2023 17:09
@vuvova vuvova requested a review from grooverdan September 6, 2023 21:00
Copy link
Copy Markdown
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.

Thanks for the contribution.

Can you also update man/mariadb.1 to include the option?

While the MDEV did include only the mysql/mariadb as the client, there are other clients that could be handled the same way.

In client:

  • mysqladmin.cc
  • mysqlbinlog.cc
  • mysqlcheck.c
  • mysqldump.c
  • mysqlimport.c
  • mysqlshow.c
  • mysqlslap.c
  • mysqltest.cc

And extra/mariabackup/backup_mysql.cc.

If you feel particular keen, and I'd appreciate it (though obviously optional), consolidate the connection methods across the client into a separate file like sql-common/connect.c and include in CMakeLists.txt like:

MYSQL_ADD_EXECUTABLE(mariadb-dump mysqldump.c ../sql-common/my_user.c ../sql-common/connect.c)

Comment thread client/client_priv.h Outdated
Comment thread sql-common/client.c Outdated
Comment thread sql-common/client.c
Comment thread client/mysql.cc Outdated
Comment thread client/mysql.cc Outdated
@grooverdan grooverdan added the need feedback Can the contributor please address the questions asked. label Sep 11, 2023
@yvef
Copy link
Copy Markdown
Contributor Author

yvef commented Sep 15, 2023

If you feel particular keen, and I'd appreciate it (though obviously optional), consolidate the connection methods across the client into a separate file like sql-common/connect.c and include in CMakeLists.txt like:

Sure, It's might be important point of refactoring and I would appreciate some hints on this. So, as far as I can see, all clients (except mariadb-backup) use the pvio plugin from connector. Once the functionality is implemented there, it is already spread across clients. But only in backup util I had to do it separately. Maybe it worth doing this the same way as it is done in other clients?

@grooverdan
Copy link
Copy Markdown
Member

mysqlcheck.cc:dbConnect
mysql.cc:do_connect
backup_mysql.cc:xb_mysql_connect

And the other functions you've added to bind to are effectively the same function.

They have a program name (which would appreciate an update to the latest version ('mysql' -> 'mariadb', mysql_dump -> mariadb-dump etc).

So an interfaces of:

bool client_connect(MYSQL *mysql, const char *clientname, const char *host, const char *user,
                          const char *password, const char *database, const char *bind_addr, ulong flags)
{

   mysql_options(&mysql_connectio ....

...
  return  mysql_real_connect(&mysql_connection,host,user,passwd,
                            NULL,opt_mysql_port,opt_mysql_unix_port, 0))


}

Callers would do their:

 mysql_init()

any items specific to that client.
ret = client_connect(..... )

any post error handling or post connection options.

Comment thread extra/mariabackup/backup_mysql.cc Outdated
Comment thread man/mariadb-admin.1 Outdated
Comment thread sql-common/client.c Outdated
Comment thread sql-common/client.c
@yvef yvef marked this pull request as draft September 30, 2023 18:45
@yvef
Copy link
Copy Markdown
Contributor Author

yvef commented Oct 2, 2023

While hiding the common infrastructure for the all clients connection is a good idea, I didn't see any meaningful reason to only use this parameters as it is ( + bind_address). As long as the code use the same own general variables, the extensibility such method is not the pleasant copy-pasting. So, I suggest using the shared options pack to distribute the shared connection method. I had to make some number of changes, that's why I marked the pr as draft.

Comment thread include/mysql.h
@yvef yvef requested a review from grooverdan October 7, 2023 10:01
@grooverdan grooverdan removed the need feedback Can the contributor please address the questions asked. label Oct 13, 2023
@grooverdan grooverdan marked this pull request as ready for review October 22, 2023 01:34
@grooverdan grooverdan force-pushed the 11.3-client-param-bnd-addr branch from aae415b to 37fb8a6 Compare October 22, 2023 01:34
Copy link
Copy Markdown
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.

Very well done. This is so much neater.

Small changes:

  • rebased and changed a few trivial conflicts where get_tty_password -> my_get_tty_password was renamed.
  • Added a couple of missing includes in libmysqld/examples/ for an embedded build.
  • squashed commits up and the commit message

Otherwise looks perfect.

I was concerned at one point there was missing my_free(cl_opts.bind_address); in mysql.cc:mysql_end, mysqlbinlog.cc:cleanup, mysqldump.cc:free_resources, and also the inconsistent my_free(cl_options.{user,password)), but it all seems correct to match the strdups that apply slightly differently in each function.

@grooverdan
Copy link
Copy Markdown
Member

@yvef how are the defined meant to work for the Windows build - its not currently.

@vuvova
Copy link
Copy Markdown
Member

vuvova commented Oct 22, 2023

Note that this is for 11.4, not 11.3.
And better wait for 11.3.1 release, when commits c8d903e and c275dc4 will be pushed, as your commit will not apply cleanly after them, there will be merge conflicts

@yvef yvef force-pushed the 11.3-client-param-bnd-addr branch from 37fb8a6 to e3c78f4 Compare November 6, 2023 09:22
@yvef
Copy link
Copy Markdown
Contributor Author

yvef commented Nov 6, 2023

@grooverdan your are right. that was fixed and included into the main commit.

@yvef yvef force-pushed the 11.3-client-param-bnd-addr branch from e3c78f4 to b4cb8ed Compare November 7, 2023 09:28
Copy link
Copy Markdown
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.

Excellent cleanup here too, approved for 11.4

Comment thread .clang-format
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
Language: Cpp
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good catch on the duplicate there too :)

yvef added 2 commits November 17, 2023 16:55
Previously, the each mariadb client used it's own
set of connection parameter, most of each were general and non-specifiic
for the utility e.g. host, user, socket etc.

Now the every caller can set up a shared CLNT_CONNECT_OPTIONS and call
do_client_connect to run the connection without redundant direct option setting.

Also:
* update man pages
* reimplement socket binding for xtrabackup
* use error code in missing section within CLI_MYSQL_REAL_CONNECT function
* adjust macro initialization for msvc
@grooverdan grooverdan force-pushed the 11.3-client-param-bnd-addr branch from b4cb8ed to 7639be7 Compare November 17, 2023 06:02
@grooverdan grooverdan changed the base branch from 11.3 to 11.4 November 17, 2023 06:02
@grooverdan grooverdan merged commit f5e038f into MariaDB:11.4 Nov 17, 2023
@grooverdan
Copy link
Copy Markdown
Member

Thank you @yvef

@vuvova
Copy link
Copy Markdown
Member

vuvova commented Dec 20, 2023

  1. I don't see it in 11.4 branch, how was it "merged"?
  2. refactoring and a feature must be in different commits
  3. sql-common is for the code common between a client and a server (thus the name). do_client_connect is client only, should be in client/
  4. could've unified more code, like command-line options could've been all defined in one place, all my_free() calls too. (optional)
  5. see comments in the code too
  6. sslopt* changes are way too complex and redundant, just keep the files are they were, only with changes like
-      opt_ssl_crl= NULL;
+      cl_opts.opt_ssl_crl= NULL;

@vuvova
Copy link
Copy Markdown
Member

vuvova commented Dec 20, 2023

So, it's not merged, needs many changes, way past the 11.4 preview deadline.
I'll try to fix it, but might not have enough time for that. Thus it likely won't be in 11.4 despite the confusing status.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants