Drizzle plugins
Upcoming SlideShare
Loading in...5

Drizzle plugins



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



Total Views
Views on SlideShare
Embed Views



2 Embeds 4 3 1


Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Drizzle plugins Drizzle plugins Presentation Transcript

  • Plugins in Drizzle
  • Plugins in Drizzle
    • ~28 types of plugins
    • ~80 plugins already bundled
    • Drizzle plugins load on startup only
    • Drizzle plugins more object-orientated
  • 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
  • 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 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
  • Variables?
    • No plugin access to status variables
    • Options processing uses Boost::Program_Options
    • drizzled --plugin.option=setting
    • SET plugin_option=setting
  • 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;
  • Intialization #include <drizzled/plugin.h> #include <drizzled/plugin/*plugin_type.h*> DRIZZLE_PLUGIN ( init, system (unused), init_options )
  • 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; }
  • 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;)); ... }
  • 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 .
  • Compiling $ ./config/pandora-plugin $ autoreconf -i
  • Compiling $ ./configure $ make $ make install
  • Daemon Plugins
    • Bolt raw code onto Drizzle
    • Very similar to MySQL
  • 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
  • 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&) { }
  • 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;
  • Daemon Example daemon_example.h: #include <drizzled/plugin.h> #include <drizzled/plugin/daemon.h>
  • TableFunction Plugins
    • Very similar to MySQL INFORMATION_SCHEMA plugins
    • In memory only, no disk used
    • INFORMATION_SCHEMA is SQL standards compliant tables
    • DATA_DICTIONARY is everything else
  • 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
  • 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); }
  • 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; }
  • 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; }
  • 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;
  • 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();
  • 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); } };
  • Function Plugins
    • Similar to UDFs in MySQL, but actual plugins
    • Same API as MySQL/Drizzle internal functions
  • 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
  • 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 */
  • 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; }
  • 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;
  • UDF Example udf_example.h: #include <drizzled/plugin.h> #include <drizzled/plugin/function.h> #include <drizzled/function/str/strfunc.h> namespace drizzled {
  • 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 */
  • Drizzle Developer Day Friday at the Hilton