~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/memcached_stats/memcached_stats.cc

  • Committer: Jay Pipes
  • Date: 2010-03-09 20:02:29 UTC
  • mto: This revision was merged to the branch mainline in revision 1339.
  • Revision ID: jpipes@serialcoder-20100309200229-dfrliy4fads9vyf4
Fixes Bug #535296 by only incrementing ha_commit_count when its a normal transaction commit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* 
2
 
 * Copyright (C) 2009, Padraig O'Sullivan
 
2
 * Copyright (c) 2009, Padraig O'Sullivan
3
3
 * All rights reserved.
4
4
 *
5
5
 * Redistribution and use in source and binary forms, with or without
27
27
 * THE POSSIBILITY OF SUCH DAMAGE.
28
28
 */
29
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>
 
30
#include "config.h"
 
31
#include "drizzled/show.h"
 
32
#include "drizzled/gettext.h"
 
33
#include "drizzled/plugin/info_schema_table.h"
 
34
 
35
35
#include "stats_table.h"
36
36
#include "analysis_table.h"
37
37
#include "sysvar_holder.h"
39
39
#include <string>
40
40
#include <map>
41
41
 
42
 
namespace po=boost::program_options;
43
 
 
44
 
namespace drizzle_plugin
45
 
{
46
 
 
 
42
using namespace std;
 
43
using namespace drizzled;
47
44
 
48
45
/*
49
46
 * DATA_DICTIONARY tables.
55
52
/*
56
53
 * System variable related variables.
57
54
 */
58
 
static std::string sysvar_memcached_servers;
 
55
static char *sysvar_memcached_servers= NULL;
59
56
 
60
57
/**
61
58
 * Initialize the memcached stats plugin.
63
60
 * @param[in] registry the drizzled::plugin::Registry singleton
64
61
 * @return false on success; true on failure.
65
62
 */
66
 
static int init(drizzled::module::Context &context)
 
63
static int init(plugin::Registry &registry)
67
64
{
68
 
  const drizzled::module::option_map &vm= context.getOptions();
 
65
 
 
66
  SysvarHolder &sysvar_holder= SysvarHolder::singleton();
 
67
  sysvar_holder.setServersString(sysvar_memcached_servers);
69
68
 
70
69
  /* we are good to go */
71
 
  stats_table_tool= new StatsTableTool; 
72
 
  context.add(stats_table_tool);
73
 
 
74
 
  analysis_table_tool= new AnalysisTableTool;
75
 
  context.add(analysis_table_tool);
76
 
 
77
 
  context.registerVariable(new sys_var_std_string("servers",
78
 
                                                  sysvar_memcached_servers));
79
 
                          
80
 
  return 0;
81
 
}
82
 
 
83
 
static void init_options(drizzled::module::option_context &context)
84
 
{
85
 
  context("servers",
86
 
          po::value<std::string>()->default_value(""),
87
 
          _("List of memcached servers."));
88
 
}
89
 
 
90
 
} /* namespace drizzle_plugin */
 
70
  stats_table_tool= new(std::nothrow)StatsTableTool; 
 
71
  registry.add(stats_table_tool);
 
72
 
 
73
  analysis_table_tool= new(std::nothrow)AnalysisTableTool;
 
74
  registry.add(analysis_table_tool);
 
75
 
 
76
  return 0;
 
77
}
 
78
 
 
79
/**
 
80
 * Clean up the memcached stats plugin.
 
81
 *
 
82
 * @param[in] registry the drizzled::plugin::Registry singleton
 
83
 * @return false on success; true on failure
 
84
 */
 
85
static int deinit(plugin::Registry &registry)
 
86
{
 
87
  registry.remove(stats_table_tool);
 
88
  delete stats_table_tool;
 
89
  registry.remove(analysis_table_tool);
 
90
  delete analysis_table_tool;
 
91
  return 0;
 
92
}
 
93
 
 
94
static int check_memc_servers(Session *,
 
95
                              drizzle_sys_var *,
 
96
                              void *save,
 
97
                              drizzle_value *value)
 
98
{
 
99
  char buff[STRING_BUFFER_USUAL_SIZE];
 
100
  int len= sizeof(buff);
 
101
  const char *input= value->val_str(value, buff, &len);
 
102
 
 
103
  if (input)
 
104
  {
 
105
    SysvarHolder &sysvar_holder= SysvarHolder::singleton();
 
106
    sysvar_holder.setServersStringVar(input);
 
107
    *(bool *) save= (bool) true;
 
108
    return 0;
 
109
  }
 
110
 
 
111
  *(bool *) save= (bool) false;
 
112
  return 1;
 
113
}
 
114
 
 
115
static void set_memc_servers(Session *,
 
116
                             drizzle_sys_var *,
 
117
                             void *var_ptr,
 
118
                             const void *save)
 
119
{
 
120
  if (*(bool *) save != false)
 
121
  {
 
122
    SysvarHolder &sysvar_holder= SysvarHolder::singleton();
 
123
    sysvar_holder.updateServersSysvar((const char **) var_ptr);
 
124
  }
 
125
}
 
126
 
 
127
static DRIZZLE_SYSVAR_STR(servers,
 
128
                          sysvar_memcached_servers,
 
129
                          PLUGIN_VAR_OPCMDARG,
 
130
                          N_("List of memcached servers."),
 
131
                          check_memc_servers, /* check func */
 
132
                          set_memc_servers, /* update func */
 
133
                          ""); /* default value */
 
134
 
 
135
static drizzle_sys_var *system_variables[]=
 
136
{
 
137
  DRIZZLE_SYSVAR(servers),
 
138
  NULL
 
139
};
91
140
 
92
141
DRIZZLE_DECLARE_PLUGIN
93
142
{
97
146
  "Padraig O'Sullivan",
98
147
  N_("Memcached Stats as I_S tables"),
99
148
  PLUGIN_LICENSE_BSD,
100
 
  drizzle_plugin::init,   /* Plugin Init      */
101
 
  NULL, /* depends */
102
 
  drizzle_plugin::init_options    /* config options   */
 
149
  init,   /* Plugin Init      */
 
150
  deinit, /* Plugin Deinit    */
 
151
  system_variables, /* system variables */
 
152
  NULL    /* config options   */
103
153
}
104
154
DRIZZLE_DECLARE_PLUGIN_END;