Presented by, MySQL AB® & O’Reilly Media, Inc. Developing INFORMATION_SCHEMA Plugins Mark Leith Support Manager, Americas

Slides:



Advertisements
Similar presentations
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizards Guide to PHP by David Lash.
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Introduction to Rails.
C Language.
Programming Languages and Paradigms The C Programming Language.
File and I/O system calls int open(const char* path, int flags, mode_t modes) int creat(const char *path, mode_t mode) ssize_t read(int fd, void *buf,
Drop in replacement of MySQL. Agenda MySQL branch GPL licence Maria storage engine Virtual columns FederatedX storage engine PBXT storage engine XtraDB.
Operating system services Program execution I/O operations File-system manipulation Communications Error detection Resource allocation Accounting Protection.
Day 3 - Basics of MySQL What is MySQL What is MySQL How to make basic tables How to make basic tables Simple MySQL commands. Simple MySQL commands.
MySQL-Database Teppo Räisänen Oulu University of Applied Sciences School of Business and Information Management.
Let’s try Oracle. Accessing Oracle The Oracle system, like the SQL Server system, is client / server. For SQL Server, –the client is the Query Analyser.
Chapter 10.
Fall 2004 ECE569 Lecture ECE 569 Database System Engineering Fall 2004 Yanyong Zhang Course.
Operating Systems File Systems (Select parts of Ch 6)
DT211 Stage 2 Databases Lab 1. Get to know SQL Server SQL server has 2 parts: –A client, running on your machine, in the lab. You access the database.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
DB Audit Expert v1.1 for Oracle Copyright © SoftTree Technologies, Inc. This presentation is for DB Audit Expert for Oracle version 1.1 which.
SQL Basics+ Brandon Checketts. Why SQL? Structured Query Language Structured Query Language Frees programmers from dealing with specifics of data persistence.
Phil Brewster  One of the first steps – identify the proper data types  Decide how data (in columns) should be stored and used.
Copyright © Curt Hill SQL The Data Definition Language.
MySQL Dr. Hsiang-Fu Yu National Taipei University of Education
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
CS 6560 Operating System Design Lecture 13 Finish File Systems Block I/O Layer.
CSCC69: Operating Systems Assignment 3 Review. Assignment Review Implement the file-related system calls – open, close, dup2 – read, write, lseek – chdir,
If This Bar Is Light Blue – It Is Info That You Should Read! Helpful Hint There Will Often Be A Colored Title Bar At The Top Of A Slide.
Windows Object Manager CS Spring Overview The object paradigm NT Objects and the Object Manager Object Structure Object Naming Object Handles.
MySQL By Scott Halvorson WDTC/DPG ATEC Forecasters Conference Boulder Colorado 25 July 2006.
MySQL. Dept. of Computing Science, University of Aberdeen2 In this lecture you will learn The main subsystems in MySQL architecture The different storage.
The MySQL General Purpose Routine library Giuseppe Maxia.
Introduction to Internet Databases MySQL Database System Database Systems.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2015, Fred McClurg, All Rights.
IT:Network:Applications.  “Business runs on databases…” ◦ Understatement!  Requirements  Installation  Creating Databases  SIMPLE query ◦ Just enough.
Connect. Communicate. Collaborate The Installation of RRD Measurement Archive (MA) Roman Łapacz, PSNC 27 th September, 2006 SEEREN2 Summer School, Heraklion.
Introduction to MySQL MySQL Overview by Ray Williams CS 320/565 Marymount University.
Calibration and alignment database development Dmitry Romanov December 15, 2010.
MySQL More… 1. More on SQL In MySQL, the Information Schema is the “Catalog” in the SQL standard SQL has three components: Data definition Data manipulation.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
1 Chapter 20 – Data sources and datasets Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Search Overview Search Features: WSS and Office Search Architecture Content Sources and.
Apr. 8, 2002Calibration Database Browser Workshop1 Database Access Using D0OM H. Greenlee Calibration Database Browser Workshop Apr. 8, 2002.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Creating and Populating a MS SQLServer Database Presented By: Dr. Adam P. Anthony.
Jeff's Filesystem Papers Review Part I. Review of "Design and Implementation of The Second Extended Filesystem"
NCHU System & Network Lab Lab 14 File and Directory.
Lecture 19 Linux/Unix – File System
Class 3Intro to Databases Class 4 Simple Example of a Database We’re going to build a simple example of a database, which will allow us to register users.
CSCC69: Operating Systems Tutorial 10. Hints on testing Assignment 3 How to test tlb replacement algorithms? – Write a program that creates an array larger.
There are two types of MySQL instructions (Data Definition Language) DDL: Create database, create table, alter table,,,. (Data Manipulation Language) DML.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
Lecture 02 File and File system. Topics Describe the layout of a Linux file system Display and set paths Describe the most important files, including.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
Introduction to MySQL Ullman Chapter 4. Introduction MySQL most popular open-source database application Is commonly used with PHP We will learn basics.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 7 Pointers and C-Strings.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
C++ Functions A bit of review (things we’ve covered so far)
OPERATING SYSTEMS COURSE THE HEBREW UNIVERSITY SPRING FUSE File System.
APPENDIX a WRITING SUBROUTINES IN C
SQL and SQL*Plus Interaction
Programming Languages and Paradigms
Programming Paradigms
CS222P: Principles of Data Management Lecture #2 Heap Files, Page structure, Record formats Instructor: Chen Li.
INFO/CSE 100, Spring 2006 Fluency in Information Technology
Data Definition Language
MySQL Database System Installation Overview SQL summary
Programming Languages and Paradigms
Database Instructor: Bei Kang.
CS222/CS122C: Principles of Data Management UCI, Fall 2018 Notes #03 Row/Column Stores, Heap Files, Buffer Manager, Catalogs Instructor: Chen Li.
Presentation transcript:

Presented by, MySQL AB® & O’Reilly Media, Inc. Developing INFORMATION_SCHEMA Plugins Mark Leith Support Manager, Americas

Overview  INFORMATION_SCHEMA overview  Plugin Overview  Developing a simple Hello World I_S table  Building and installing  Interacting with another program  Interacting with another library

INFORMATION_SCHEMA  Specified within the SQL Standard  (ISO/IEC :2003)‏  Virtual tables which give database metadata  MySQL implements a subset of the Standard   ORMATION_SCHEMA.html ORMATION_SCHEMA.html

Plugins  A means to load shared libraries in to a running MySQL instance  Developed in C/C++  api.html api.html  User Defined Functions  Storage Engines  Fulltext parsers  Daemons  INFORMATION_SCHEMA Tables!

 Located in include/mysql/plugin.h The Plugin Interface struct st_mysql_plugin { int type; /* the plugin type (a MYSQL_XXX_PLUGIN value) */ void *info; /* pointer to type-specific plugin descriptor */ const char *name; /* plugin name */ const char *author; /* plugin author (for SHOW PLUGINS) */ const char *descr; /* general descriptive text (for SHOW PLUGINS ) */ int license; /* the plugin license (PLUGIN_LICENSE_XXX) */ int (*init)(void *); /* the function to invoke when plugin is loaded */ int (*deinit)(void *)/* the function to invoke when plugin is unloaded */ unsigned int version; /* plugin version (for SHOW PLUGINS) */ struct st_mysql_show_var *status_vars; struct st_mysql_sys_var **system_vars; void * __reserved1; /* reserved for dependency checking */ };

Plugin Types  Define the plugin type (types listed below)  Used within plugin functions such as plugin_foreach() MYSQL_UDF_PLUGIN 0 /* User-defined function */ MYSQL_STORAGE_ENGINE_PLUGIN 1 /* Storage Engine */ MYSQL_FTPARSER_PLUGIN 2 /* Full-text parser plugin */ MYSQL_DAEMON_PLUGIN 3 /* The daemon/raw plugin type */ MYSQL_INFORMATION_SCHEMA_PLUGIN 4 /* The I_S plugin type */  I_S plugins loaded within sql/sql_show.cc int schema_tables_add(THD *thd, List *files, const char *wild) { … if (plugin_foreach(thd, add_schema_table, MYSQL_INFORMATION_SCHEMA_PLUGIN, &add_data)) DBUG_RETURN(1);

Starting a HELLO_WORLD Table  Must have MySQL source tree  Create a new plugin/hello_world/hello_world.cc file  plugin.h and mysql_priv.h includes required  Add a prototype for schema_table_store_record() /* Required for schema_table_store_record() * /#include "mysql_priv.h" #include bool schema_table_store_record(THD *thd, TABLE *table);

Define the Table Structure  Uses an array of ST_FIELD_INFO structs  field_nameColumn name  field_lengthColumn length or display length  field_typeColumn datatype  valueNot used within I_S plugins  field_flagsSet NULL / UNSIGNED attributes  old_nameInternal mapping for I_S tables to SHOW output  open_methodOpen table using supplied method  Last entry in the array is an end marker ST_FIELD_INFO hello_world_fields[]= { {"HELLO", 10, MYSQL_TYPE_STRING, 0, 0, "Hello", 0}, {"WORLD", 10, MYSQL_TYPE_STRING, 0, 0, "World", 0}, {0, 0, MYSQL_TYPE_NULL, 0, 0, 0, 0} };

A Closer Look MYSQL_TYPE_STRING MYSQL_TYPE_LONG MYSQL_TYPE_LONGLONG MYSQL_TYPE_DECIMAL MYSQL_TYPE_DATETIME VARCHAR INT BIGINT DECIMAL DATETIME  Field_type  Field_flags MY_I_S_MAYBE_NULL MY_I_S_UNSIGNED  Open_method SKIP_OPEN_TABLE OPEN_FRM_ONLY OPEN_FULL_TABLE

Define Function to Fill Table  Called every time the table is accessed  Fills the virtual table with data int fill_hello_world(THD *thd, TABLE_LIST *tables, COND *cond) { DBUG_ENTER("fill_hello_world_is_plugin"); CHARSET_INFO *scs= system_charset_info; TABLE *table= tables->table; int rc= 0; table->field[0]->store("Hello", strlen("Hello"), scs); table->field[1]->store("World", strlen("World"), scs); if (schema_table_store_record(thd, table)) rc= 1; DBUG_RETURN(rc); }

Create the Init Function  Runs when the plugin is installed/loaded  ST_SCHEMA_TABLE is an internal table representation  Points to the ST_FIELD_INFO struct / table definition  Points to the function to fill the table  Manages any other init needed for the plugin int hello_world_plugin_init(void *p) { DBUG_ENTER("init_hello_world_is_plugin"); ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE*) p; schema->fields_info= hello_world_fields; schema->fill_table= fill_hello_world; DBUG_RETURN(0); }

Create the Deinit Function  Run when the plugin is unloaded  Does nothing for HELLO_WORLD  Use this function to do any clean up in your plugin int hello_world_plugin_deinit(void *p) { DBUG_ENTER("deinit_info_schema_example_plugin"); DBUG_RETURN(0); }

Create the Plugin Definition  Info struct points to the interface version built against struct st_mysql_information_schema hello_world_plugin_info= { MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION }; mysql_declare_plugin(hello_world_plugin) { MYSQL_INFORMATION_SCHEMA_PLUGIN, &hello_world_plugin_info, /* Pointer to info struct */ "HELLO_WORLD", /* Plugin Name (used in INSTALL PLUGIN) */ "Mark Leith, MySQL AB", /* Plugin Author */ "HELLO_WORLD example plugin",/* Plugin Description */ PLUGIN_LICENSE_GPL, /* _GPL, _BSD or _PROPRIETARY */ hello_world_plugin_init, /* Pointer to plugin init function */ hello_world_plugin_deinit, /* Pointer to plugin deinit function */ 0x0100, /* 1.0 */ NULL, /* status variables */ NULL, /* system variables */ NULL /* config options */ } mysql_declare_plugin_end;

Build the Plugin  Define MYSQL_DYNAMIC_PLUGIN  Make shared  Include the sql and include source directories g++ -DMYSQL_DYNAMIC_PLUGIN -shared \ > -I/home/leithal/mysql/mysql-5.1/include \ > -I/home/leithal/mysql/mysql-5.1/sql \ > -o is_hello_world.so hello_world.cc ls -l total 16 -rw-r--r-- 1 leithal leithal :20 hello_world.cc -rwxr-xr-x 1 leithal leithal :27 is_hello_world.so cp is_hello_world.so /usr/local/mysql/lib/mysql/plugin

Install and Use! mysql> INSTALL PLUGIN HELLO_WORLD SONAME 'is_hello_world.so'; Query OK, 0 rows affected (0.01 sec) mysql> USE INFORMATION_SCHEMA; Database changed mysql> SHOW TABLES LIKE 'HELL%'; | Tables_in_information_schema (HELL%) | | HELLO_WORLD | row in set (0.00 sec) mysql> SELECT * FROM HELLO_WORLD; | HELLO | WORLD | | Hello | World | row in set (0.00 sec)

So We'll Do Something Interesting  How's the disk space doing on my db server? df -h Filesystem Size Used Avail Use% Mounted on /dev/hda1 4.6G 3.5G 886M 81% / varrun 126M 84K 125M 1% /var/run varlock 126M 0 126M 0% /var/lock procbususb 10M 76K 10M 1% /proc/bus/usb udev 10M 76K 10M 1% /dev devshm 126M 0 126M 0% /dev/shm lrm 126M 18M 108M 14% /lib/modules/ generic/volatile  If I can get this in a table I can track it over time  I can also report on it easily  How about an I_S table with events to catalog?

Create Template & Table Structure  Add stdio.h,string.h and stdlib.h includes  Mirror init, deinit and info functions  Fill in the plugin declaration scruct appropriately  Define the new table: ST_FIELD_INFO fs_info_schema_fields[]= { {"FILESYSTEM", 120, MYSQL_TYPE_STRING, 0, 0, "Filesystem", 0}, {"SIZE", 8, MYSQL_TYPE_LONGLONG, 0, 0, "Mountpoint Size", 0}, {"USED", 8, MYSQL_TYPE_LONGLONG, 0, 0, "Used Space", 0}, {"AVAILABLE", 8, MYSQL_TYPE_LONGLONG, 0, 0, "Available Space", 0}, {"CAPACITY", 4, MYSQL_TYPE_STRING, 0, 0, "Percent Used", 0}, {"MOUNTED_ON", 120, MYSQL_TYPE_STRING, 0, 0, "Filesystem Mounted On", 0}, {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} };

Running Other Programs  Open with popen() and read in the results /* get filesystem information from df on linux like systems */ FILE *f; char buf[128]; char *c, *s, *size; const char delim[]= " "; unsigned long long uli; double d; if (NULL != (f= popen("/bin/df -h", "r"))) { int ln= 0; while(!feof(f)) { fgets(buf, sizeof(buf), f); switch(ln++) {

Tokenize and Push Results  Can do this how you like /* skip the header line of df */ case 0: break; default: c= buf; /* hack to stop processing when falling off the end of output */ if (strchr(c, ' ') == NULL) break; /* Filesystem */ s= strtok(c, delim); table->field[0]->store(s, strlen(s), scs); /* Size */ s= strtok(NULL, delim); d= strtod(s, &size); uli= get_bytes(d, size); table->field[1]->store(uli, TRUE); ….

Store the Row and Finish up /* Use% */ s= strtok(NULL, delim); table->field[4]->store(s, strlen(s), scs); /* Mountpoint */ s= strtok(NULL, delim); stripnl(s); table->field[5]->store(s, strlen(s), scs); /* store the row */ if (schema_table_store_record(thd, table)) rc= 1; break; } pclose(f); } else rc= 1; DBUG_RETURN(rc); }

Build, Install, Try..  Build as before and try it out! mysql> select * from file_system_mountpoints; | FILESYSTEM | SIZE | USED | AVAILABLE | CAPACITY | MOUNTED_ON | | /dev/hda1 | | | | 81% | / | | varrun | | | | 1% | /var/run | | varlock | | 0 | | 0% | /var/lock | | procbususb | | | | 1% | /proc/bus/usb | | udev | | | | 1% | /dev | | devshm | | 0 | | 0% | /dev/shm | | lrm | | | | 14% | /lib/modules/ generic/volatile | rows in set (0.06 sec) mysql> desc file_system_mountpoints; | Field | Type | Null | Key | Default | Extra | | FILESYSTEM | varchar(120) | NO | | | | | SIZE | bigint(11) | NO | | 0 | | | USED | bigint(11) | NO | | 0 | | | AVAILABLE | bigint(11) | NO | | 0 | | | CAPACITY | varchar(4) | NO | | | | | MOUNTED_ON | varchar(120) | NO | | | | rows in set (0.01 sec)

Now Let's Use another Library  The SIGAR library from Hyperic  Lets us do cross platform OS stats monitoring  Released under GPL  Again, start with the same base functions etc. as before

Include Lib Header, Use Lib in Fill sigar_t *t; sigar_open(&t); sigar_file_system_list_t fslist; sigar_file_system_list_get(t, &fslist); for (uint i = 0; i < fslist.number; i++) { sigar_file_system_t fs = fslist.data[i]; sigar_file_system_usage_t fsusage; rc= sigar_file_system_usage_get(t, fs.dir_name, &fsusage); if (fs.type == 2 || fs.type == 3) { table->field[0]->store(fs.dir_name, strlen(fs.dir_name), scs); table->field[1]->store(fsusage.total, TRUE); table->field[2]->store(fsusage.used, TRUE); table->field[3]->store(fsusage.free, TRUE); table->field[4]->store(fsusage.files, TRUE); if (schema_table_store_record(thd, table)) rc= 1; } sigar_file_system_list_destroy(t, &fslist); sigar_close(t);

Building and Including the Library g++ -DMYSQL_DYNAMIC_PLUGIN -Wall -shared \ -lsigar -Wl,-rpath -Wl,/home/leithal/os_stats_info_schema/sigar/ \ -L/home/leithal/os_stats_info_schema/sigar/ \ -I/home/leithal/os_stats_info_schema/sigar/include/ \ -I/home/leithal/mysql/mysql-5.1/include \ -I/home/leithal/mysql/mysql-5.1/sql \ -o os_stats_info_schema.so os_stats_info_schema.cc  -lsigar links the library  Use -rpath to pass in library location  This is for runtime  Can also use LD_LIBRARY_PATH  -L (linker) and -I (include) paths  -L points to the directory with the built library

Try it out! mysql> INSTALL PLUGIN os_disk_usage SONAME 'os_stats_info_schema.so'; Query OK, 0 rows affected (0.00 sec) mysql> SHOW TABLES LIKE 'OS%'; | Tables_in_information_schema (OS%) | | OS_DISK_USAGE | row in set (0.00 sec) mysql> SELECT * FROM OS_DISK_USAGE; | FILESYSTEM | SIZE | USED | FREE | FILES | | / | | | | | row in set (0.00 sec)

Resources and Questions!   information-schema-plugins-best.html information-schema-plugins-best.html  -mysql-internals-with.html (Great resource for monitoring server internals) -mysql-internals-with.html  Questions?