~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/memcached_stats/memcached_stats.cc

  • Committer: Stewart Smith
  • Date: 2008-11-21 16:06:07 UTC
  • mto: This revision was merged to the branch mainline in revision 593.
  • Revision ID: stewart@flamingspork.com-20081121160607-n6gdlt013spuo54r
remove mysql_frm_type
and fix engines to return correct value from delete_table when table doesn't exist.
(it should be ENOENT).

Also fix up some tests that manipulated frm files by hand. These tests are no longer valid and will need to be rewritten in the not too distant future.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
2
 
 * Copyright (c) 2009, Padraig O'Sullivan
3
 
 * All rights reserved.
4
 
 *
5
 
 * Redistribution and use in source and binary forms, with or without
6
 
 * modification, are permitted provided that the following conditions are met:
7
 
 *
8
 
 *   * Redistributions of source code must retain the above copyright notice,
9
 
 *     this list of conditions and the following disclaimer.
10
 
 *   * Redistributions in binary form must reproduce the above copyright notice,
11
 
 *     this list of conditions and the following disclaimer in the documentation
12
 
 *     and/or other materials provided with the distribution.
13
 
 *   * Neither the name of Padraig O'Sullivan nor the names of its contributors
14
 
 *     may be used to endorse or promote products derived from this software
15
 
 *     without specific prior written permission.
16
 
 *
17
 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
 
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21
 
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
 
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
 
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
 
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
 
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
 
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27
 
 * THE POSSIBILITY OF SUCH DAMAGE.
28
 
 */
29
 
 
30
 
#include "config.h"
31
 
#include "drizzled/show.h"
32
 
#include "drizzled/gettext.h"
33
 
#include <boost/program_options.hpp>
34
 
#include <drizzled/module/option_map.h>
35
 
#include "stats_table.h"
36
 
#include "analysis_table.h"
37
 
#include "sysvar_holder.h"
38
 
 
39
 
#include <string>
40
 
#include <map>
41
 
 
42
 
namespace po=boost::program_options;
43
 
using namespace std;
44
 
using namespace drizzled;
45
 
 
46
 
/*
47
 
 * DATA_DICTIONARY tables.
48
 
 */
49
 
static AnalysisTableTool *analysis_table_tool; 
50
 
 
51
 
static StatsTableTool *stats_table_tool;
52
 
 
53
 
/*
54
 
 * System variable related variables.
55
 
 */
56
 
static char *sysvar_memcached_servers= NULL;
57
 
 
58
 
/**
59
 
 * Initialize the memcached stats plugin.
60
 
 *
61
 
 * @param[in] registry the drizzled::plugin::Registry singleton
62
 
 * @return false on success; true on failure.
63
 
 */
64
 
static int init(module::Context &context)
65
 
{
66
 
  const module::option_map &vm= context.getOptions();
67
 
 
68
 
  if(vm.count("servers"))
69
 
  {
70
 
    sysvar_memcached_servers= strdup(vm["servers"].as<string>().c_str());
71
 
  }
72
 
 
73
 
  else
74
 
  {
75
 
    sysvar_memcached_servers= strdup("");
76
 
  }
77
 
 
78
 
  SysvarHolder &sysvar_holder= SysvarHolder::singleton();
79
 
  sysvar_holder.setServersString(sysvar_memcached_servers);
80
 
  sysvar_holder.setMemoryPtr(sysvar_memcached_servers);
81
 
 
82
 
  /* we are good to go */
83
 
  stats_table_tool= new(std::nothrow)StatsTableTool; 
84
 
  context.add(stats_table_tool);
85
 
 
86
 
  analysis_table_tool= new(std::nothrow)AnalysisTableTool;
87
 
  context.add(analysis_table_tool);
88
 
 
89
 
  return 0;
90
 
}
91
 
 
92
 
static int check_memc_servers(Session *,
93
 
                              drizzle_sys_var *,
94
 
                              void *save,
95
 
                              drizzle_value *value)
96
 
{
97
 
  char buff[STRING_BUFFER_USUAL_SIZE];
98
 
  int len= sizeof(buff);
99
 
  const char *input= value->val_str(value, buff, &len);
100
 
 
101
 
  if (input)
102
 
  {
103
 
    SysvarHolder &sysvar_holder= SysvarHolder::singleton();
104
 
    sysvar_holder.setServersStringVar(input);
105
 
    *(bool *) save= (bool) true;
106
 
    return 0;
107
 
  }
108
 
 
109
 
  *(bool *) save= (bool) false;
110
 
  return 1;
111
 
}
112
 
 
113
 
static void set_memc_servers(Session *,
114
 
                             drizzle_sys_var *,
115
 
                             void *var_ptr,
116
 
                             const void *save)
117
 
{
118
 
  if (*(bool *) save != false)
119
 
  {
120
 
    SysvarHolder &sysvar_holder= SysvarHolder::singleton();
121
 
    sysvar_holder.updateServersSysvar((const char **) var_ptr);
122
 
  }
123
 
}
124
 
 
125
 
static DRIZZLE_SYSVAR_STR(servers,
126
 
                          sysvar_memcached_servers,
127
 
                          PLUGIN_VAR_OPCMDARG,
128
 
                          N_("List of memcached servers."),
129
 
                          check_memc_servers, /* check func */
130
 
                          set_memc_servers, /* update func */
131
 
                          ""); /* default value */
132
 
 
133
 
static void init_options(drizzled::module::option_context &context)
134
 
{
135
 
  context("servers",
136
 
          po::value<string>(),
137
 
          N_("List of memcached servers."));
138
 
}
139
 
 
140
 
static drizzle_sys_var *system_variables[]=
141
 
{
142
 
  DRIZZLE_SYSVAR(servers),
143
 
  NULL
144
 
};
145
 
 
146
 
DRIZZLE_DECLARE_PLUGIN
147
 
{
148
 
  DRIZZLE_VERSION_ID,
149
 
  "memcached_stats",
150
 
  "1.0",
151
 
  "Padraig O'Sullivan",
152
 
  N_("Memcached Stats as I_S tables"),
153
 
  PLUGIN_LICENSE_BSD,
154
 
  init,   /* Plugin Init      */
155
 
  system_variables, /* system variables */
156
 
  init_options    /* config options   */
157
 
}
158
 
DRIZZLE_DECLARE_PLUGIN_END;