openfest15 mysql plugin development

26
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | MySQL Plugin Development Getting started Georgi “Joro” Kodinov Team Lead, MySQL Server General Team

Upload: georgi-kodinov

Post on 12-Apr-2017

354 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Openfest15 MySQL Plugin Development

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

MySQL PluginDevelopmentGetting started

Georgi “Joro” KodinovTeam Lead, MySQL Server General Team

Page 2: Openfest15 MySQL Plugin Development

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, [email protected]

About Me

Page 3: Openfest15 MySQL Plugin Development

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 3

MySQL 5.7Just Released !“New version of the world’s most popular open source database is up to 3x faster than MySQL 5.6 in benchmark tests”

Page 4: Openfest15 MySQL Plugin Development

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 4

Technical level: advanced developer !

Page 5: Openfest15 MySQL Plugin Development

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 5

What will I cover ?

• 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

Page 6: Openfest15 MySQL Plugin Development

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 6

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

Due to lack of time and complexity

Page 7: Openfest15 MySQL Plugin Development

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 7

Plugins: The Big Picture

MySQL server binary

Server CodeType A Plugins

Type B Plugins

Plugin A API

Plugin … API

Plugin B API

Plugin binary 1

Type A Plugins

Plugin A API

Services

Clients

Page 8: Openfest15 MySQL Plugin Development

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 8

A lifecycle of a pluginPhase What triggers it ?Initialization • INSTALL PLUGIN

• Server startup• --plugin-load[-add] options• mysql.plugin table

OPTIONAL: API call(s) Server events, mostly query executionDe-initialization • UNINSTALL PLUGIN

• Server shutdown• User session end

Page 9: Openfest15 MySQL Plugin Development

9Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

What plugin typesdoes the server support ?

Page 10: Openfest15 MySQL Plugin Development

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 10

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

Page 11: Openfest15 MySQL Plugin Development

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 11

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

Page 12: Openfest15 MySQL Plugin Development

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 12

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)

Page 13: Openfest15 MySQL Plugin Development

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 13

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

Page 14: Openfest15 MySQL Plugin Development

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 14

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.

Page 15: Openfest15 MySQL Plugin Development

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 15

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 !

Page 16: Openfest15 MySQL Plugin Development

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 16

Miscellaneous other pluginsPlugin type What is it ? Full text parser plugin Parse full text syntax and convert to full text filtersReplication Support for single master replication enginesGroup replication Support for group replication enginesUDF plugin Not implemented

Page 17: Openfest15 MySQL Plugin Development

17Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

What plugin linkagedoes the server support ?As in MySQL 5.7

Page 18: Openfest15 MySQL Plugin Development

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 18

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

Page 19: Openfest15 MySQL Plugin Development

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 19

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

Page 20: Openfest15 MySQL Plugin Development

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 20

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

Page 21: Openfest15 MySQL Plugin Development

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 21

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

Page 22: Openfest15 MySQL Plugin Development

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 22

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

Page 23: Openfest15 MySQL Plugin Development

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 23

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

Page 24: Openfest15 MySQL Plugin Development

24Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Questions ?

Page 25: Openfest15 MySQL Plugin Development

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 25

Safe Harbor StatementThe 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.

Page 26: Openfest15 MySQL Plugin Development