drizzle plugins

Download Drizzle plugins

If you can't read please download the document

Upload: andrew-hutchings

Post on 19-May-2015

1.535 views

Category:

Technology


5 download

DESCRIPTION

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

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 #include DRIZZLE_DECLARE_PLUGIN { DRIZZLE_VERSION_ID, name, plugin version, author, description, init, dependencies, init_options } DRIZZLE_DECLARE_PLUGIN_END; 15. Intialization #include #include 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("drizzle_protocol", vm["bind-address"].as(), true); protocol->addCountersToTable(); context.add(protocol); context.registerVariable(new sys_var_constrained_value_readonly("port", port)); ... return 0; } 17. Initialization static void init_options(drizzled::module::option_context &context) { context("port", po::value(&port)->default_value(DRIZZLE_TCP_PORT), N_("Port number to use for connection or 0 for default to with Drizzle/MySQL protocol.")); ... } 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 "config.h" #include #include "daemon_example.h" static int init(drizzled::module::Context&) { std::cout 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("example")); return 0; } 44. UDF Example udf_example.cc: DRIZZLE_DECLARE_PLUGIN { DRIZZLE_VERSION_ID, "Example Function", "0.1", "Andrew Hutchings", "Example Function", drizzled::PLUGIN_LICENSE_GPL, init, NULL, NULL } DRIZZLE_DECLARE_PLUGIN_END; 45. UDF Example udf_example.h: #include #include #include 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 "example"; } 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