Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
MySQL Plugin
Development
Getting started
Georgi “Joro” Kodinov
Team Lead, MySQL Server General Team
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
• Background in banking IT
• Veteran software developer
• Leading the MySQL Server General development team
• With MySQL since 2006
• Working out of Plovdiv, Bulgaria
• NOT a professional speaker
• @gkodinov, georgi.kodinov@oracle.com
About Me
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
MySQL 5.7
Just Released !
“New version of the world’s most
popular open source database is up
to 3x faster than MySQL 5.6 in
benchmark tests”
3
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Technical level: advanced developer !
4
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
What will I cover ?
5
• The lifecycle of a server plugin
• What plugin types does the server support
• What plugin linkage does the server support
• What are plugin services
• Where to find examples to copy from
• Further reading
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
What will not be covered ?
• A complete start-to-finish plugin development cycle
• Adding plugin services to the server code
• Complex plugin API details
• UDF functions
• Non-server plugins
6
Due to lack of time and complexity
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Plugins: The Big Picture
7
MySQL server binary
Server Code
Type A
Plugins
Type B
Plugins
…
Plugin B API
Plugin binary 1
Type A
Plugins
…
Plugin A API
Services
Clients
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
A lifecycle of a plugin
Phase What triggers it ?
Initialization • INSTALL PLUGIN
• Server startup
• --plugin-load[-add] options
• mysql.plugin table
OPTIONAL: API call(s) Server events, mostly query execution
De-initialization • UNINSTALL PLUGIN
• Server shutdown
• User session end
8
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
What plugin types
does the server support ?
9
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Daemon plugins
• The simplest: No plugin API !
• When is the API called
– No API to call
• Good for
– Doing stuff on server startup/shutdown
– Spawning a daemon thread that can call plugin services
• Limitations
– No APIs to call
10
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
INFORMATION_SCHEMA plugins
• Used to return read-only data in tabular format
• When is the API called ?
– When somebody selects from the table
• Good for
– Returning plugin data to the server as ephemeral tables
• Limitations
– Fills in a temporary table
– Not a lot of query condition pushdown
– One table per plugin definition
11
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Authentication plugins
• Verify user account credentials
• When is the API called
– Whenever credentials need to be checked (login time, sudo)
• Good for
– Hooking up into enterprise directories
– Limiting user access
• Limitations
– No session yet (not all plugin services work)
12
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Audit plugins
• Process various auditing events
• When is the API called
– In a LOT of occasions: server start, query start/end, session start/end, events logged,
etc.
• Good for
– Logging, preventing or reacting to various server events
– Can handle high volume of calls through event pre-filtering
• Limitations
– Can go into infinite recursion (plugin services can trigger audit events too)
– References are cached, so unloading a plugin is not immediate
13
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Password validation plugins
• Enforce password strength policies
• When is the API called
– When a new user password hash is set for a user account
– Explicitly (through a SQL function)
• Good for
– Enforcing custom password strength policies
• Limitations
– No backing store provided. Password reuse can’t be controlled.
14
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Storage engine plugins
• Implement table backing storage
• When is the API called
– When the server needs to open, read data, write data or close a table.
– Explicitly (through the HANDLER SQL interface)
• Good for
– Implementing different types of backing storage for MySQL tables
• Limitations
– VERY complex !
15
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Miscellaneous other plugins
16
Plugin type What is it ?
Full text parser plugin Parse full text syntax and convert to full text filters
Replication Support for single master replication engines
Group replication Support for group replication engines
UDF plugin Not implemented
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
What plugin linkage
does the server support ?
As in MySQL 5.7
17
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Internal plugins
• Examples
– MyISAM storage engine, InnoDB storage engine, native authentication plugin, etc. …
• The server can’t operate properly without these
• Statically linked into the server
• Part of the server’s code repository
• ABI compatibility not needed
18
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Static plugins
• Examples:
– sha256 authentication plugin
• Required only when used.
• Statically linked into the server binary for availability
• Can be dynamically added in the plugin/ source directory
• Require the server’s source code to compile
• ABI compatibility is optional
19
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Dynamic plugins
• Examples:
– windows authentication plugin, enterprise audit plugin
• Required only when used.
• Separate binaries, dynamically loaded into the server
• Can be dynamically added in the plugin/ source directory
• Do not require the server’s source code to compile
– a binary installation is enough
• ABI compatibility is highly recommended
20
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Plugin services at a glance
• Plugins use services to call the server
– Vs. server calling the plugins in all other cases
• Can be added only as part of the server
• A plugin based C structure with function pointers filled in by the server
when the plugin is loaded
• A constantly growing number of services provided
21
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Where to find examples to copy from ?
• Not easy to code plugins from scratch
– Nontrivial amount of boilerplate code needed
• Where are the sample plugins ?
– Subdirectories of the plugin/ and storage/ source directories
• Usage patterns in the documentation and mysql-test/
• Notable examples:
– Audit_null, Daemon_example, example storage engine, federated
22
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Further reading
• http://dev.mysql.com/doc/refman/5.7/en/extending-mysql.html
– The best reference there is !
• The “MySQL 5.1 Plugin Development” book
– ISBN-13: 978-1849510608
• http://forums.mysql.com
– User discussions on various MySQL related topics
• Your favorite search engine
– With MySQL being so popular a lot of people have tried developing plugins
23
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Questions ?
24
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Safe Harbor Statement
The preceding is intended to outline our general product direction. It is intended for
information purposes only, and may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or functionality, and should not be relied upon
in making purchasing decisions. The development, release, and timing of any features or
functionality described for Oracle’s products remains at the sole discretion of Oracle.
25
Openfest15 MySQL Plugin Development

Openfest15 MySQL Plugin Development

  • 1.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | MySQL Plugin Development Getting started Georgi “Joro” Kodinov Team Lead, MySQL Server General Team
  • 2.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | • Background in banking IT • Veteran software developer • Leading the MySQL Server General development team • With MySQL since 2006 • Working out of Plovdiv, Bulgaria • NOT a professional speaker • @gkodinov, georgi.kodinov@oracle.com About Me
  • 3.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | MySQL 5.7 Just Released ! “New version of the world’s most popular open source database is up to 3x faster than MySQL 5.6 in benchmark tests” 3
  • 4.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | Technical level: advanced developer ! 4
  • 5.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | What will I cover ? 5 • The lifecycle of a server plugin • What plugin types does the server support • What plugin linkage does the server support • What are plugin services • Where to find examples to copy from • Further reading
  • 6.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | What will not be covered ? • A complete start-to-finish plugin development cycle • Adding plugin services to the server code • Complex plugin API details • UDF functions • Non-server plugins 6 Due to lack of time and complexity
  • 7.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | Plugins: The Big Picture 7 MySQL server binary Server Code Type A Plugins Type B Plugins … Plugin B API Plugin binary 1 Type A Plugins … Plugin A API Services Clients
  • 8.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | A lifecycle of a plugin Phase What triggers it ? Initialization • INSTALL PLUGIN • Server startup • --plugin-load[-add] options • mysql.plugin table OPTIONAL: API call(s) Server events, mostly query execution De-initialization • UNINSTALL PLUGIN • Server shutdown • User session end 8
  • 9.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | What plugin types does the server support ? 9
  • 10.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | Daemon plugins • The simplest: No plugin API ! • When is the API called – No API to call • Good for – Doing stuff on server startup/shutdown – Spawning a daemon thread that can call plugin services • Limitations – No APIs to call 10
  • 11.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | INFORMATION_SCHEMA plugins • Used to return read-only data in tabular format • When is the API called ? – When somebody selects from the table • Good for – Returning plugin data to the server as ephemeral tables • Limitations – Fills in a temporary table – Not a lot of query condition pushdown – One table per plugin definition 11
  • 12.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | Authentication plugins • Verify user account credentials • When is the API called – Whenever credentials need to be checked (login time, sudo) • Good for – Hooking up into enterprise directories – Limiting user access • Limitations – No session yet (not all plugin services work) 12
  • 13.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | Audit plugins • Process various auditing events • When is the API called – In a LOT of occasions: server start, query start/end, session start/end, events logged, etc. • Good for – Logging, preventing or reacting to various server events – Can handle high volume of calls through event pre-filtering • Limitations – Can go into infinite recursion (plugin services can trigger audit events too) – References are cached, so unloading a plugin is not immediate 13
  • 14.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | Password validation plugins • Enforce password strength policies • When is the API called – When a new user password hash is set for a user account – Explicitly (through a SQL function) • Good for – Enforcing custom password strength policies • Limitations – No backing store provided. Password reuse can’t be controlled. 14
  • 15.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | Storage engine plugins • Implement table backing storage • When is the API called – When the server needs to open, read data, write data or close a table. – Explicitly (through the HANDLER SQL interface) • Good for – Implementing different types of backing storage for MySQL tables • Limitations – VERY complex ! 15
  • 16.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | Miscellaneous other plugins 16 Plugin type What is it ? Full text parser plugin Parse full text syntax and convert to full text filters Replication Support for single master replication engines Group replication Support for group replication engines UDF plugin Not implemented
  • 17.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | What plugin linkage does the server support ? As in MySQL 5.7 17
  • 18.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | Internal plugins • Examples – MyISAM storage engine, InnoDB storage engine, native authentication plugin, etc. … • The server can’t operate properly without these • Statically linked into the server • Part of the server’s code repository • ABI compatibility not needed 18
  • 19.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | Static plugins • Examples: – sha256 authentication plugin • Required only when used. • Statically linked into the server binary for availability • Can be dynamically added in the plugin/ source directory • Require the server’s source code to compile • ABI compatibility is optional 19
  • 20.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | Dynamic plugins • Examples: – windows authentication plugin, enterprise audit plugin • Required only when used. • Separate binaries, dynamically loaded into the server • Can be dynamically added in the plugin/ source directory • Do not require the server’s source code to compile – a binary installation is enough • ABI compatibility is highly recommended 20
  • 21.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | Plugin services at a glance • Plugins use services to call the server – Vs. server calling the plugins in all other cases • Can be added only as part of the server • A plugin based C structure with function pointers filled in by the server when the plugin is loaded • A constantly growing number of services provided 21
  • 22.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | Where to find examples to copy from ? • Not easy to code plugins from scratch – Nontrivial amount of boilerplate code needed • Where are the sample plugins ? – Subdirectories of the plugin/ and storage/ source directories • Usage patterns in the documentation and mysql-test/ • Notable examples: – Audit_null, Daemon_example, example storage engine, federated 22
  • 23.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | Further reading • http://dev.mysql.com/doc/refman/5.7/en/extending-mysql.html – The best reference there is ! • The “MySQL 5.1 Plugin Development” book – ISBN-13: 978-1849510608 • http://forums.mysql.com – User discussions on various MySQL related topics • Your favorite search engine – With MySQL being so popular a lot of people have tried developing plugins 23
  • 24.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | Questions ? 24
  • 25.
    Copyright © 2015,Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 25