Plugins in Drizzle
Plugins in Drizzle <ul><li>~28 types of plugins
~80 plugins already bundled
Drizzle plugins load on startup only
Drizzle plugins more object-orientated </li></ul>
Plugin Types Authentication Authorization Catalogs Error Message Event Observer Function Listen Logging Query Cache Schedu...
Plugin Loading drizzled --plugin-add=my_plugin,your_plugin drizzled --plugin-remove=unwanted_plugin
Plugin Loading Example: drizzle --plugin-remove=auth_all --plugin-add=auth_file
Plugin.ini [plugin] title= Drizzle Protocol Module description= Drizzle protocol module. Version= 0.3 author= Brian Aker l...
Variables? <ul><li>No plugin access to status variables
Options processing uses Boost::Program_Options
drizzled --plugin.option=setting
SET plugin_option=setting </li></ul>
Intialization #include <drizzled/plugin.h> #include <drizzled/plugin/*plugin_type.h*> DRIZZLE_DECLARE_PLUGIN { DRIZZLE_VER...
Intialization #include <drizzled/plugin.h> #include <drizzled/plugin/*plugin_type.h*> DRIZZLE_PLUGIN ( init, system (unuse...
Initialization static int init(drizzled::module::Context &context) { const module::option_map &vm= context.getOptions(); L...
Initialization static void init_options(drizzled::module::option_context &context) { context(&quot;port&quot;, po::value<p...
Compiling $ cp $DRIZZLE_SRC_ROOT/config/config.rpath config/ $ cp $DRIZZLE_SRC_ROOT/config/pandora-plugin config/ $ cp $DR...
Compiling $ ./config/pandora-plugin $ autoreconf -i
Compiling $ ./configure $ make $ make install
Daemon Plugins <ul><li>Bolt raw code onto Drizzle
Very similar to MySQL </li></ul>
Daemon Example Plugin.ini: [plugin] name= daemon_example module_name= daemon_example title= Daemon Example Module descript...
Daemon Example daemon_example.cc: #include &quot;config.h&quot; #include <iostream> #include &quot;daemon_example.h&quot; ...
Daemon Example daemon_example.cc: DRIZZLE_DECLARE_PLUGIN { DRIZZLE_VERSION_ID, &quot;daemon-example&quot;, &quot;0.1&quot;...
Daemon Example daemon_example.h: #include <drizzled/plugin.h> #include <drizzled/plugin/daemon.h>
TableFunction Plugins <ul><li>Very similar to MySQL INFORMATION_SCHEMA plugins
Incorporates INFORMATION_SCHEMA and DATA_DICTIONARY
In memory only, no disk used
INFORMATION_SCHEMA is SQL standards compliant tables
DATA_DICTIONARY is everything else </li></ul>
Data Dictionary Example plugin.ini: [plugin] name= getrusage module_name= getrusage title= getrusage Data Dictionary Modul...
Data Dictionary Example getrusage_plugin.cc: #include <config.h> #include &quot;getrusage_plugin.h&quot; Getrusage::Getrus...
Data Dictionary Example getrusage_plugin.cc: Getrusage::Generator::Generator(drizzled::Field **arg) : drizzled::plugin::Ta...
Data Dictionary Example getrusage_plugin.cc bool Getrusage::Generator::populate() { counter++; if (counter == 1) { push(&q...
Upcoming SlideShare
Loading in...5
×

Drizzle plugins

1,553

Published on

Drizzle part of the plugins tutorial at the 2011 O'Reilly MySQL Conference and Expo

Published in: Technology, Art & Photos
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,553
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Drizzle plugins

  1. 1. Plugins in Drizzle
  2. 2. Plugins in Drizzle <ul><li>~28 types of plugins
  3. 3. ~80 plugins already bundled
  4. 4. Drizzle plugins load on startup only
  5. 5. Drizzle plugins more object-orientated </li></ul>
  6. 6. Plugin Types Authentication Authorization Catalogs Error Message Event Observer Function Listen Logging Query Cache Scheduler Schema Engine Storage Engine Table Function Transaction Applier Transaction Replicator
  7. 7. Plugin Loading drizzled --plugin-add=my_plugin,your_plugin drizzled --plugin-remove=unwanted_plugin
  8. 8. Plugin Loading Example: drizzle --plugin-remove=auth_all --plugin-add=auth_file
  9. 9. Plugin.ini [plugin] title= Drizzle Protocol Module description= Drizzle protocol module. Version= 0.3 author= Brian Aker license= PLUGIN_LICENSE_GPL libs= drizzled/algorithm/libhash.la load_by_default= yes ldlfags= $(LIBZ) headers= drizzle_protocol.h sources= drizzle_protocol.cc static= yes
  10. 10. Variables? <ul><li>No plugin access to status variables
  11. 11. Options processing uses Boost::Program_Options
  12. 12. drizzled --plugin.option=setting
  13. 13. SET plugin_option=setting </li></ul>
  14. 14. Intialization #include <drizzled/plugin.h> #include <drizzled/plugin/*plugin_type.h*> DRIZZLE_DECLARE_PLUGIN { DRIZZLE_VERSION_ID, name, plugin version, author, description, init, dependencies, init_options } DRIZZLE_DECLARE_PLUGIN_END;
  15. 15. Intialization #include <drizzled/plugin.h> #include <drizzled/plugin/*plugin_type.h*> DRIZZLE_PLUGIN ( init, system (unused), init_options )
  16. 16. Initialization static int init(drizzled::module::Context &context) { const module::option_map &vm= context.getOptions(); ListenDrizzleProtocol *protocol=new ListenDrizzleProtocol(&quot;drizzle_protocol&quot;, vm[&quot;bind-address&quot;].as<std::string>(), true); protocol->addCountersToTable(); context.add(protocol); context.registerVariable(new sys_var_constrained_value_readonly<in_port_t>(&quot;port&quot;, port)); ... return 0; }
  17. 17. Initialization static void init_options(drizzled::module::option_context &context) { context(&quot;port&quot;, po::value<port_constraint>(&port)->default_value(DRIZZLE_TCP_PORT), N_(&quot;Port number to use for connection or 0 for default to with Drizzle/MySQL protocol.&quot;)); ... }
  18. 18. Compiling $ cp $DRIZZLE_SRC_ROOT/config/config.rpath config/ $ cp $DRIZZLE_SRC_ROOT/config/pandora-plugin config/ $ cp $DRIZZLE_SRC_ROOT/config/pandora-plugin.ini config/ $ cp -R $DRIZZLE_SRC_PORT/m4 .
  19. 19. Compiling $ ./config/pandora-plugin $ autoreconf -i
  20. 20. Compiling $ ./configure $ make $ make install
  21. 21. Daemon Plugins <ul><li>Bolt raw code onto Drizzle
  22. 22. Very similar to MySQL </li></ul>
  23. 23. Daemon Example Plugin.ini: [plugin] name= daemon_example module_name= daemon_example title= Daemon Example Module description= Daemon Example Module version= 0.1 author= Andrew Hutchings url= http://www.linuxjedi.co.uk/ license= PLUGIN_LICENSE_GPL load_by_default= no headers= daemon_example.h sources= daemon_example.cc
  24. 24. Daemon Example daemon_example.cc: #include &quot;config.h&quot; #include <iostream> #include &quot;daemon_example.h&quot; static int init(drizzled::module::Context&) { std::cout << &quot;Hello World!&quot; << std::endl; return 0; } static void init_options(drizzled::module::option_context&) { }
  25. 25. Daemon Example daemon_example.cc: DRIZZLE_DECLARE_PLUGIN { DRIZZLE_VERSION_ID, &quot;daemon-example&quot;, &quot;0.1&quot;, &quot;Andrew Hutchings&quot;, &quot;An example Daemon Plugin&quot;, drizzled::PLUGIN_LICENSE_GPL, init, /* Plugin Init */ NULL, /* depends */ init_options /* config options */ } DRIZZLE_DECLARE_PLUGIN_END;
  26. 26. Daemon Example daemon_example.h: #include <drizzled/plugin.h> #include <drizzled/plugin/daemon.h>
  27. 27. TableFunction Plugins <ul><li>Very similar to MySQL INFORMATION_SCHEMA plugins
  28. 28. Incorporates INFORMATION_SCHEMA and DATA_DICTIONARY
  29. 29. In memory only, no disk used
  30. 30. INFORMATION_SCHEMA is SQL standards compliant tables
  31. 31. DATA_DICTIONARY is everything else </li></ul>
  32. 32. Data Dictionary Example plugin.ini: [plugin] name= getrusage module_name= getrusage title= getrusage Data Dictionary Module description= getrusage Data Dictionary Module version= 0.1 author= Andrew Hutchings url= http://www.linuxjedi.co.uk/ license= PLUGIN_LICENSE_GPL load_by_default= no headers= getrusage_plugin.h sources= getrusage_plugin.cc
  33. 33. Data Dictionary Example getrusage_plugin.cc: #include <config.h> #include &quot;getrusage_plugin.h&quot; Getrusage::Getrusage() : drizzled::plugin::TableFunction(&quot;DATA_DICTIONARY&quot;, &quot;GETRUSAGE&quot;) { add_field(&quot;TYPE&quot;, drizzled::plugin::TableFunction::STRING, 7, false); add_field(&quot;TIME&quot;, drizzled::plugin::TableFunction::NUMBER, 0, false); }
  34. 34. Data Dictionary Example getrusage_plugin.cc: Getrusage::Generator::Generator(drizzled::Field **arg) : drizzled::plugin::TableFunction::Generator(arg), counter(0) { counter= 0; getrusage(RUSAGE_SELF, &usage_data); return; }
  35. 35. Data Dictionary Example getrusage_plugin.cc bool Getrusage::Generator::populate() { counter++; if (counter == 1) { push(&quot;USER&quot;); push(usage_data.ru_utime.tv_sec); return true; } if (counter == 2) { push(&quot;SYSTEM&quot;); push(usage_data.ru_stime.tv_sec); return true; } return false; }
  36. 36. Data Dictionary Example getrusage_plugin.cc static int init(drizzled::module::Context &context) { context.add(new Getrusage); return 0; } DRIZZLE_DECLARE_PLUGIN { DRIZZLE_VERSION_ID, &quot;Getrusage Dictionary&quot;, &quot;0.1&quot;, &quot;Andrew Hutchings&quot;, &quot;Data Dictionary for Getrusage&quot;, drizzled::PLUGIN_LICENSE_GPL, init, NULL, NULL } DRIZZLE_DECLARE_PLUGIN_END;
  37. 37. Data Dictionary Example getrusage_plugin.h: #include <drizzled/plugin.h> #include <drizzled/plugin/table_function.h> #include <sys/resource.h> class Getrusage : public drizzled::plugin::TableFunction { public: Getrusage();
  38. 38. Data Dictionary Example getrusage_plugin.h: class Generator : public drizzled::plugin::TableFunction::Generator { public: Generator(drizzled::Field **arg); bool populate(); int counter; rusage usage_data; }; Generator *generator(drizzled::Field **arg) { return new Generator(arg); } };
  39. 39. Function Plugins <ul><li>Similar to UDFs in MySQL, but actual plugins
  40. 40. Same API as MySQL/Drizzle internal functions </li></ul>
  41. 41. UDF Example plugin.ini: [plugin] name= udf_example module_name= udf_example title= An example UDF description= An example UDF version= 0.1 author= Andrew Hutchings url= http://www.linuxjedi.co.uk/ license= PLUGIN_LICENSE_GPL load_by_default= no headers= udf_example.h sources= udf_example.cc
  42. 42. UDF Example udf_example.cc: #include <config.h> #include <drizzled/lex_string.h> #include &quot;udf_example.h&quot; namespace drizzled { String *Item_func_example::val_str(String *str) { assert(fixed == 1); String *result= args[0]->val_str(str); null_value= args[0]->null_value; return result; } } /* namespace drizzled */
  43. 43. UDF Example udf_example.cc: static int init(drizzled::module::Context &context) { context.add(new drizzled::plugin::Create_function<drizzled::Item_func_example>(&quot;example&quot;)); return 0; }
  44. 44. UDF Example udf_example.cc: DRIZZLE_DECLARE_PLUGIN { DRIZZLE_VERSION_ID, &quot;Example Function&quot;, &quot;0.1&quot;, &quot;Andrew Hutchings&quot;, &quot;Example Function&quot;, drizzled::PLUGIN_LICENSE_GPL, init, NULL, NULL } DRIZZLE_DECLARE_PLUGIN_END;
  45. 45. UDF Example udf_example.h: #include <drizzled/plugin.h> #include <drizzled/plugin/function.h> #include <drizzled/function/str/strfunc.h> namespace drizzled {
  46. 46. UDF Example udf_example.h: class Item_func_example: public Item_str_func { public: Item_func_example() : Item_str_func() {} const char *func_name() const { return &quot;example&quot;; } String *val_str(String *); void fix_length_and_dec() { collation.set(args[0]->collation); max_length= args[0]->max_length; } bool check_argument_count(int n) { return n == 1; } }; } /* namespace drizzled */
  47. 47. Drizzle Developer Day Friday at the Hilton
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×