Drizzle plugins

  • 1,426 views
Uploaded on

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

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

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,426
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
8
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Plugins in Drizzle
  • 2. Plugins in Drizzle
    • ~28 types of plugins
    • 3. ~80 plugins already bundled
    • 4. Drizzle plugins load on startup only
    • 5. Drizzle plugins more object-orientated
  • 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. Plugin Loading drizzled --plugin-add=my_plugin,your_plugin drizzled --plugin-remove=unwanted_plugin
  • 8. Plugin Loading Example: drizzle --plugin-remove=auth_all --plugin-add=auth_file
  • 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. Variables?
    • No plugin access to status variables
    • 11. Options processing uses Boost::Program_Options
    • 12. drizzled --plugin.option=setting
    • 13. SET plugin_option=setting
  • 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. Intialization #include <drizzled/plugin.h> #include <drizzled/plugin/*plugin_type.h*> DRIZZLE_PLUGIN ( init, system (unused), init_options )
  • 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. 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. 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. Compiling $ ./config/pandora-plugin $ autoreconf -i
  • 20. Compiling $ ./configure $ make $ make install
  • 21. Daemon Plugins
    • Bolt raw code onto Drizzle
    • 22. Very similar to MySQL
  • 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. 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. 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. Daemon Example daemon_example.h: #include <drizzled/plugin.h> #include <drizzled/plugin/daemon.h>
  • 27. TableFunction Plugins
    • Very similar to MySQL INFORMATION_SCHEMA plugins
    • 28. Incorporates INFORMATION_SCHEMA and DATA_DICTIONARY
    • 29. In memory only, no disk used
    • 30. INFORMATION_SCHEMA is SQL standards compliant tables
    • 31. DATA_DICTIONARY is everything else
  • 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. 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. 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. 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. 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. 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. 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. Function Plugins
    • Similar to UDFs in MySQL, but actual plugins
    • 40. Same API as MySQL/Drizzle internal functions
  • 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. 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. 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. 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. UDF Example udf_example.h: #include <drizzled/plugin.h> #include <drizzled/plugin/function.h> #include <drizzled/function/str/strfunc.h> namespace drizzled {
  • 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. Drizzle Developer Day Friday at the Hilton