Well, with something you want to do.
Okay, I think we can start.
Let's see if this works.
Yes.
So, yeah, where am I?
I am Frédéric Decaux. I'm local.
I'm from Belgium.
So, this is why I'm often here.
You can follow me on Twitter as Lefret.
So, if you have any questions, just ask me.
I'm quite old using MySQL.
I started with MySQL 3.20.
I was thinking it was 3.23, but it was 3.20.
I found the CD at home.
Yes, a CD for people who don't know what it is.
Before there was a program in it, and before that was Floppy.
I also knew the Floppy.
So, as I said, I live in Belgium, and I have a blog
where you can find a lot of information mostly related to MySQL.
So, today I'm going to talk about the component infrastructure.
I'm very sorry.
Usually we are in a very dark room where...
and I changed my slide to be dark slides,
but to make it to see them very well, but it seems not okay.
So, we will see that if you want to modify MySQL,
you have different ways, creating a storage engine.
That's one way to modify MySQL.
I want to have my own storage engine to store the data like I want.
I want to create a plugin.
Next session is about that, right?
Vinicius, and or by creating a component.
We at MySQL, we encourage you to use this component infrastructure
if you want to extend MySQL over the plugin, for example.
It's very, very not easy to read for you, sorry.
So, what is this MySQL component infrastructure?
So, it's a modular design for the MySQL server
that will allow the developers to extend the server,
like I said earlier, right, in a different way,
and such adding support for new functions,
new performance schema table, new status variable,
new system variable, all that kind of stuff
that you want to extend to MySQL,
you will be able to use the component infrastructure to do that.
And so, what does it mean?
It means that the server will provide you services
that you can use to extend MySQL.
And there is, you don't see it very well here,
but there is a component service inventory page.
The URL is here.
Yes, you will have the slide online,
so you can read them and copy the URL.
And something very nice is that this component infrastructure
is, or you say that, enhancing all the time.
So, for example, in MySQL 8028,
we had 137 services defined that you could use,
and in 8032, it's already 162 services.
So, if there is something you would like to do
and you don't know how to do it,
it's something you can ask us.
I don't say it's guaranteed that you will have it in the next version,
but it's something we are doing.
We try to improve.
And internally, it's the same.
So, when one of the teams needs something extra,
one of the teams creates now services
that we can use to make it more modular like that.
So, why do we need to use this MySQL component?
It's because the subsystem of these components
is designed because there are some issues with the plugins.
So, for example, the plugin can only talk to the server
and not with other plugins.
Here, with components, you could have some components
talking to other components.
That's something possible.
The plugins, they have access to the server symbols
and they can call them directly, but not really in consolation.
And there are some, we were discussing that,
that it is even possible maybe to create a component
and compile it and then load it for another version of it.
This is not something I would recommend to do,
but it's possible.
And you can also create these dependencies
between components, which is very nice.
So, we're going to create a component together.
I will do it, but so you can see how it works
and try to see, my plan is to show you that it's not complicated
and that you will be able to create your own component.
So, first thing, and this is for me, I think one of the most
difficult parts when we want to extend MySQL is,
oh, cool, I want to extend it, but what will I do?
And sometimes on Slack or forums, I have people say,
oh, I'm a young developer, I would like to help
MySQL community.
Yes?
What?
Yes, I need to say yes.
Yeah, but why not?
But people say, oh, I am learning C++
or I want to be in the MySQL community,
I want to create something, and what could I do?
That's the plan.
You know, like Colin was telling earlier,
we don't have like a list of features that we ask
community to do.
It's more that the community wants to enhance something,
fix something, they will do it, right?
So here, the most complicated is what will I do,
how would I extend to your needs?
So this is what we're going to define.
So the first thing is that to be able to use what we're going
to use, I want to have a specific privilege.
So not everybody will be able to use the extension we're
going to do, and I decided to use the sensitive variables
observer privilege that was added in 8029.
So you can also, if you want, it's create a new privilege
for what you are doing.
I've made, I don't know if you have seen,
I create a component in 13 block posts with,
was covering a lot of things to do it,
and one of them was to create a privilege
and use that privilege.
Then we're going to read a value of some predefined
variables on the server, and let's say,
extract the pass of it, and then create a performance
schema table with the path that we extracted from this
variable, and see if there is free space and how many
space has been used on this storage that related to the
pass.
So it's a simple, but it can be very useful that you
don't need to have access as a DBA to the file system
to check that.
So to be able to do this, we will need, of course,
to use several services that are to get the information
from the privileges, so the security of the threads,
to need to have access to the performance schema table
to create one, to create the different fields,
like here we're going to use the table,
but we want to have some begin and stuff like that.
We also need to have a log built-in to create error messages.
We need to send message to the user, for example,
oh, you don't have privilege to access this table,
so we need to subscribe and to use all these services
to do that.
Yes.
These are services, and I will show you how to do that,
so you use these services and then you call them
and you get the answer, and it's much easier than
on the plug-in, for example.
Yes, so the URL I was showing you earlier,
it's the list of all the components that you can use
and how to use them.
So which variable are we going to check?
So if you're a SQL DBA, you need how many variables
define a path that you need to check?
Do you have an ID?
One, two, three, more, less.
It's a quiz.
It's a lot, and more and more.
So, for example, we have lock bin base name.
We should put the binary locks.
We can put them somewhere.
The data here, hopefully you know what it means.
It is where the data will be.
Temdir, you know, db-undo directory, you know, db-data-own.
So all these can be different paths at a different part
that we can store data, right?
So we will need, I will use here a vector of the string
and I will put all these variables in it.
This is predefined because I know that this can be,
if there is some value in these variables,
I will check that.
Of course, if you want, you can extend that
and create, for example, a variable
where you will put the name of the variables to list.
It's possible.
It's just depending on what you want to do that.
And this is, for example, all you call,
you want to register a new variable.
For example, this variable, 2 par, I called, right?
This is how you call the MySQL service components
is variable register.
And you register your variable.
Okay?
So let's go, we are in ACA conference, right?
So our component will look like this.
So we will, in the MySQL server source directory,
there is a component folder.
And in that folder, I will create my disk size component.
So it's another folder.
I will have a CMake list.
And then a disk size, you see this size dot header
and a disk size PFS where I put the stuff for a performance schema.
If we have time, and I think we may have,
I will just show you the content of the file.
But before, I will show you what we have in this,
some part of it, how to use it.
So, for example, if you want to write in the error lock,
all our component needs to have a tag.
So I don't know if this will work.
Seems not, oops.
Where is it?
Yeah.
Yeah, it's with the, yeah.
I need to be very slow.
Very slow, yeah.
You see here?
It's not that useful.
You can, you say lock component tag and it's disk size.
So every error message that I will create will have this disk size
tag in it.
So I will require a service page.
So I need to use the lock built-ins,
lock built-in strings because I want to send strings, right?
And this is the service type I will going to use.
And I'm defining here.
And then, for example, when I will initialize my component, right?
I will here call this and initialize the lock objects.
And when I just do lock component error,
which type of error it is?
Can you be warning?
Here is information level, print message, initializing.
Just so every time I will load the plugin, the component,
I will have this.
So this is how we do it.
It's very easy.
So this is some code that you will reuse all the time.
And then in your component, this is the message if you want
to print an error message.
So usually it's much more easy than in a plugin.
To check a privilege, so I create here a function
F required privilege, right?
And I will send the THD.
And also to get the context, to get the security context of THD,
all that, our services.
And then we check, OK, do we have access to this privilege?
And if not, I will say I will print an error.
If it's OK, we can continue.
So here we check the privilege.
So this is how we do it.
And it's quite very easy to do all that kind of stuff like this.
And for example, if you want to access a global variable,
it's also again, get the variable from this variable register,
get the variable, put the name of the variable,
and you will get the data out of it.
So this is how it works.
And it's quite very easy.
And you can extend that.
Like I said, there is 161 services to create performance
to get information for plenty of stuff.
So it is very, very easy.
So how does it look like when we run this component, right?
So the first thing we do, if you can read it,
is we install the component.
So we do install component and then file component disk size.
By default, the components, they start with the name component underscore.
But you can change that if you want.
You can see it's okay.
It means it has been loaded, right?
If we check in the error lock,
because remember we were printing initializing
when we were loading the component,
we will see because in Mexico,
the error lock is also part of performance schema table.
So you don't need to go a tail file.
We can see that, okay, component disk size reported initializing,
component disk size reported,
performance schema table has been registered successfully.
So all that information comes from the component
and you can find it in the error lock.
So that's the first thing.
We were happy because we were able to load the component
and we see that in error lock, the component is written.
And then we can see also here to use it really.
So we do select start from performance schema disk size,
which is the performance schema table we created.
So it gives us all the data, the directory or the path
from which variable it comes from, right?
And the free size and the total size invites from it.
So this is quite very useful.
So you can check without having to,
after you can do whatever you want with this information,
but it was to show something relevant
and not just a yellow word to you guys.
I think this is more useful.
And for example, yeah, you can display or you can play
with the new function like the format bytes and stuff.
And you can see here the free size, total size,
how many percent are used on the disk,
depending where you want to check.
What do you see here is that everything points on the same SSD
on my laptop and this is why you have always the same numbers
because at the end it's only the same disk.
But if you use different disks,
you will have different values here.
The error, like I said earlier, I was using,
we created this, we were using this specific privilege.
So here I'm using another user, which is called Restore.
I was for Dockstore.
We were discussing about Dockstore earlier.
So I want to check in the performance schema table
with that user and you can see that user doesn't have
the privilege we want.
He says, OK, this select is denied because the user cannot,
so I don't give access to the performance schema table
to everybody, just some specific user.
So some information about the MySQL components.
It is, you can see which are the components that are loaded.
So you do select start from MySQL component.
So there is a system table called component
and you can see which are the component loaded
and sometimes a component can be part of a group
and then you will see if they're on the same group or not,
which is not the case here.
But you can see here, I have several,
so the query attribute is a component, for example.
And then other component that I'm playing with on my system
like UID, V7 and stuff like that,
that you can create if you want.
Where are these components on the disk?
It's on the plugin here, same as the plugin.
So you will see where the plugins are.
You have also the components there
and by default the name start with component.
So the disk size, we just created it here,
component disk size.
And you can see there are several components already
in MySQL by default
because we are also using our own infrastructure in MySQL.
So some question that I've heard about the component
is that is it that when we load a component
after we start of the server,
what happens with that component?
So all the components will be reloaded again, in fact.
So if you install the component,
when you restart, it will be installed.
So there is no configuration in my CNF.
You need to load it first and then it will stay loaded.
Meaning that if I remove the component that was installed
because I like to suffer, right?
And what will happen?
In fact, you will have a message that says,
oh, this component, for example,
cannot be open and there is an issue.
But that's the only thing.
It won't block the server.
It won't crash.
It will just tell you, OK, this is not there
and it won't be available for you.
So if you are interested, for example,
to see the code, the full code of the component,
it's on GitHub.
So on my GitHub, MySQL component disk size,
you can find it.
And also now it's your turn.
Please show me what you can do and what you can invent
and what you can bring to MySQL
because I think the component infrastructure
is very something cool that you can use
to add features to MySQL.
And I hope that, Vinicius, you will change your next talk
to a component for the next year
and not as a plugin, right?
So thank you very much for this.
Share your love to MySQL on the social media.
Join us on the community Slack,
so where plenty of people are there to answer questions
from development, consulting,
plenty of people from around the world,
not working for MySQL, but in the MySQL community,
are also there to answer you.
Do you have questions?