~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/memcached_stats/memcached_stats.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-13 01:03:01 UTC
  • mto: (1126.9.2 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090913010301-tcvvezipx1124acy
Added calls to the dtrace delete begin/end probes.

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
 
 
34
 
#include "stats_table.h"
35
 
#include "analysis_table.h"
36
 
#include "sysvar_holder.h"
37
 
 
38
 
#include <string>
39
 
#include <map>
40
 
 
41
 
using namespace std;
42
 
using namespace drizzled;
43
 
 
44
 
/*
45
 
 * DATA_DICTIONARY tables.
46
 
 */
47
 
static AnalysisTableTool *analysis_table_tool; 
48
 
 
49
 
static StatsTableTool *stats_table_tool;
50
 
 
51
 
/*
52
 
 * System variable related variables.
53
 
 */
54
 
static char *sysvar_memcached_servers= NULL;
55
 
 
56
 
/**
57
 
 * Initialize the memcached stats plugin.
58
 
 *
59
 
 * @param[in] registry the drizzled::plugin::Registry singleton
60
 
 * @return false on success; true on failure.
61
 
 */
62
 
static int init(plugin::Context &context)
63
 
{
64
 
 
65
 
  SysvarHolder &sysvar_holder= SysvarHolder::singleton();
66
 
  sysvar_holder.setServersString(sysvar_memcached_servers);
67
 
 
68
 
  /* we are good to go */
69
 
  stats_table_tool= new(std::nothrow)StatsTableTool; 
70
 
  context.add(stats_table_tool);
71
 
 
72
 
  analysis_table_tool= new(std::nothrow)AnalysisTableTool;
73
 
  context.add(analysis_table_tool);
74
 
 
75
 
  return 0;
76
 
}
77
 
 
78
 
static int check_memc_servers(Session *,
79
 
                              drizzle_sys_var *,
80
 
                              void *save,
81
 
                              drizzle_value *value)
82
 
{
83
 
  char buff[STRING_BUFFER_USUAL_SIZE];
84
 
  int len= sizeof(buff);
85
 
  const char *input= value->val_str(value, buff, &len);
86
 
 
87
 
  if (input)
88
 
  {
89
 
    SysvarHolder &sysvar_holder= SysvarHolder::singleton();
90
 
    sysvar_holder.setServersStringVar(input);
91
 
    *(bool *) save= (bool) true;
92
 
    return 0;
93
 
  }
94
 
 
95
 
  *(bool *) save= (bool) false;
96
 
  return 1;
97
 
}
98
 
 
99
 
static void set_memc_servers(Session *,
100
 
                             drizzle_sys_var *,
101
 
                             void *var_ptr,
102
 
                             const void *save)
103
 
{
104
 
  if (*(bool *) save != false)
105
 
  {
106
 
    SysvarHolder &sysvar_holder= SysvarHolder::singleton();
107
 
    sysvar_holder.updateServersSysvar((const char **) var_ptr);
108
 
  }
109
 
}
110
 
 
111
 
static DRIZZLE_SYSVAR_STR(servers,
112
 
                          sysvar_memcached_servers,
113
 
                          PLUGIN_VAR_OPCMDARG,
114
 
                          N_("List of memcached servers."),
115
 
                          check_memc_servers, /* check func */
116
 
                          set_memc_servers, /* update func */
117
 
                          ""); /* default value */
118
 
 
119
 
static drizzle_sys_var *system_variables[]=
120
 
{
121
 
  DRIZZLE_SYSVAR(servers),
122
 
  NULL
123
 
};
124
 
 
125
 
DRIZZLE_DECLARE_PLUGIN
126
 
{
127
 
  DRIZZLE_VERSION_ID,
128
 
  "memcached_stats",
129
 
  "1.0",
130
 
  "Padraig O'Sullivan",
131
 
  N_("Memcached Stats as I_S tables"),
132
 
  PLUGIN_LICENSE_BSD,
133
 
  init,   /* Plugin Init      */
134
 
  system_variables, /* system variables */
135
 
  NULL    /* config options   */
136
 
}
137
 
DRIZZLE_DECLARE_PLUGIN_END;