30 #include <mysql_version.h> 
   31 #include "sql_plugin.h" 
   38         pthread_t               memcached_thread;
 
   43 static char*    mci_engine_library = NULL;
 
   44 static char*    mci_eng_lib_path = NULL; 
 
   45 static char*    mci_memcached_option = NULL;
 
   46 static unsigned int mci_r_batch_size = 1048576;
 
   47 static unsigned int mci_w_batch_size = 32;
 
   48 static my_bool  mci_enable_binlog = 
false;
 
   50 static MYSQL_SYSVAR_STR(engine_lib_name, mci_engine_library,
 
   51                         PLUGIN_VAR_READONLY | PLUGIN_VAR_MEMALLOC,
 
   52                         "memcached engine library name", NULL, NULL,
 
   55 static MYSQL_SYSVAR_STR(engine_lib_path, mci_eng_lib_path,
 
   56                         PLUGIN_VAR_READONLY | PLUGIN_VAR_MEMALLOC,
 
   57                         "memcached engine library path", NULL, NULL, NULL);
 
   59 static MYSQL_SYSVAR_STR(
option, mci_memcached_option,
 
   60                         PLUGIN_VAR_READONLY | PLUGIN_VAR_MEMALLOC,
 
   61                         "memcached option string", NULL, NULL, NULL);
 
   63 static MYSQL_SYSVAR_UINT(r_batch_size, mci_r_batch_size,
 
   65                          "read batch commit size", 0, 0, 1,
 
   68 static MYSQL_SYSVAR_UINT(w_batch_size, mci_w_batch_size,
 
   70                          "write batch commit size", 0, 0, 1,
 
   73 static MYSQL_SYSVAR_BOOL(enable_binlog, mci_enable_binlog,
 
   75                          "whether to enable binlog",
 
   79         MYSQL_SYSVAR(engine_lib_name),
 
   80         MYSQL_SYSVAR(engine_lib_path),
 
   82         MYSQL_SYSVAR(r_batch_size),
 
   83         MYSQL_SYSVAR(w_batch_size),
 
   84         MYSQL_SYSVAR(enable_binlog),
 
   88 static int daemon_memcached_plugin_deinit(
void *p)
 
   95         if (!shutdown_complete()) {
 
   99         while (!shutdown_complete() && loop_count < 25) {
 
  104         if(!shutdown_complete()) {
 
  105                 fprintf(stderr,
" InnoDB_Memcached: Waited for 50 seconds" 
  106                         " for memcached thread to exit. Now force terminating" 
  112         pthread_cancel(con->memcached_thread);
 
  114         if (con->memcached_conf.m_engine_library) {
 
  115                 my_free(con->memcached_conf.m_engine_library);
 
  123 static int daemon_memcached_plugin_init(
void *p)
 
  131         if (mci_engine_library) {
 
  132                 char*   lib_path = (mci_eng_lib_path)
 
  133                                         ? mci_eng_lib_path : opt_plugin_dir;
 
  134                 int     lib_len = strlen(lib_path)
 
  135                                   + strlen(mci_engine_library)
 
  136                                   + strlen(FN_DIRSEP) + 1;
 
  138                 con->memcached_conf.m_engine_library = (
char*) my_malloc(
 
  141                 strxmov(con->memcached_conf.m_engine_library, lib_path,
 
  142                         FN_DIRSEP, mci_engine_library, NullS);
 
  144                 con->memcached_conf.m_engine_library = NULL;
 
  147         con->memcached_conf.m_mem_option = mci_memcached_option;
 
  148         con->memcached_conf.m_innodb_api_cb = plugin->data;
 
  149         con->memcached_conf.m_r_batch_size = mci_r_batch_size;
 
  150         con->memcached_conf.m_w_batch_size = mci_w_batch_size;
 
  151         con->memcached_conf.m_enable_binlog = mci_enable_binlog;
 
  153         pthread_attr_init(&attr);
 
  154         pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
 
  157         if (pthread_create(&con->memcached_thread, &attr,
 
  158                            daemon_memcached_main,
 
  159                            (
void *)&con->memcached_conf) != 0)
 
  161                 fprintf(stderr,
"Could not create memcached daemon thread!\n");
 
  165         plugin->data= (
void *)con;
 
  171         {MYSQL_DAEMON_INTERFACE_VERSION};
 
  173 mysql_declare_plugin(daemon_memcached)
 
  176         &daemon_memcached_plugin,
 
  178         "Oracle Corporation",
 
  181         daemon_memcached_plugin_init,   
 
  182         daemon_memcached_plugin_deinit, 
 
  185         daemon_memcached_sys_var,       
 
  188 mysql_declare_plugin_end;