~drizzle-trunk/drizzle/development

1283.28.9 by Stewart Smith
basic DATA_DICTIONARY.INNODB_STATUS table_function plugin. This gets the InnoDB status and lets the user query it.
1
/*
2
  Copyright (C) 2010 Stewart Smith
3
4
  This program is free software; you can redistribute it and/or
5
  modify it under the terms of the GNU General Public License
6
  as published by the Free Software Foundation; either version 2
7
  of the License, or (at your option) any later version.
8
9
  This program is distributed in the hope that it will be useful,
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
  GNU General Public License for more details.
13
14
  You should have received a copy of the GNU General Public License
15
  along with this program; if not, write to the Free Software
16
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
*/
18
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
19
#include <config.h>
20
#include <drizzled/plugin/table_function.h>
1283.28.9 by Stewart Smith
basic DATA_DICTIONARY.INNODB_STATUS table_function plugin. This gets the InnoDB status and lets the user query it.
21
1815.2.1 by Stewart Smith
only include haildb.h in HailDB Plugin, do not even try for embedded innodb header.
22
#include <haildb.h>
1283.28.9 by Stewart Smith
basic DATA_DICTIONARY.INNODB_STATUS table_function plugin. This gets the InnoDB status and lets the user query it.
23
24
#include "status_table_function.h"
25
26
using namespace std;
27
using namespace drizzled;
28
29
class LibInnoDBStatusTool : public drizzled::plugin::TableFunction
30
{
31
public:
32
33
  LibInnoDBStatusTool();
34
35
  LibInnoDBStatusTool(const char *table_arg) :
36
    drizzled::plugin::TableFunction("data_dictionary", table_arg)
37
  { }
38
39
  ~LibInnoDBStatusTool() {}
40
41
  class Generator : public drizzled::plugin::TableFunction::Generator
42
  {
43
  private:
1815.2.2 by Stewart Smith
change HailDB status table function to use ib_status_get_all() API call - new to HailDB 2.1
44
    const char **names;
45
    uint32_t names_count;
1283.28.9 by Stewart Smith
basic DATA_DICTIONARY.INNODB_STATUS table_function plugin. This gets the InnoDB status and lets the user query it.
46
    uint32_t names_next;
47
  public:
48
    Generator(drizzled::Field **arg);
49
    ~Generator();
50
51
    bool populate();
52
  };
53
54
  LibInnoDBStatusTool::Generator *generator(drizzled::Field **arg)
55
  {
56
    return new Generator(arg);
57
  }
58
};
59
60
LibInnoDBStatusTool::LibInnoDBStatusTool() :
1787.5.11 by Stewart Smith
rename remaining things from embedded_innodb/innodb to HailDB. The only things left are now the plugin name and what name the engine appears under (so it's still CREATE TABLE.. ENGINE=INNODB and options are --innodb.foo)
61
  plugin::TableFunction("DATA_DICTIONARY", "HAILDB_STATUS")
1283.28.9 by Stewart Smith
basic DATA_DICTIONARY.INNODB_STATUS table_function plugin. This gets the InnoDB status and lets the user query it.
62
{
63
  add_field("NAME");
64
  add_field("VALUE", plugin::TableFunction::NUMBER);
65
}
66
67
LibInnoDBStatusTool::Generator::Generator(Field **arg) :
68
  plugin::TableFunction::Generator(arg),
69
  names_next(0)
70
{
1815.2.2 by Stewart Smith
change HailDB status table function to use ib_status_get_all() API call - new to HailDB 2.1
71
  ib_err_t err= ib_status_get_all(&names, &names_count);
72
  assert(err == DB_SUCCESS);
1283.28.9 by Stewart Smith
basic DATA_DICTIONARY.INNODB_STATUS table_function plugin. This gets the InnoDB status and lets the user query it.
73
}
74
75
LibInnoDBStatusTool::Generator::~Generator()
76
{
1815.2.2 by Stewart Smith
change HailDB status table function to use ib_status_get_all() API call - new to HailDB 2.1
77
  free(names);
1283.28.9 by Stewart Smith
basic DATA_DICTIONARY.INNODB_STATUS table_function plugin. This gets the InnoDB status and lets the user query it.
78
}
79
80
bool LibInnoDBStatusTool::Generator::populate()
81
{
1815.2.2 by Stewart Smith
change HailDB status table function to use ib_status_get_all() API call - new to HailDB 2.1
82
  if (names[names_next] != NULL)
1283.28.9 by Stewart Smith
basic DATA_DICTIONARY.INNODB_STATUS table_function plugin. This gets the InnoDB status and lets the user query it.
83
  {
1815.2.2 by Stewart Smith
change HailDB status table function to use ib_status_get_all() API call - new to HailDB 2.1
84
    const char* config_name= names[names_next];
1283.28.9 by Stewart Smith
basic DATA_DICTIONARY.INNODB_STATUS table_function plugin. This gets the InnoDB status and lets the user query it.
85
86
    push(config_name);
87
88
    ib_i64_t value;
89
    ib_err_t err= ib_status_get_i64(config_name, &value);
90
    assert(err == DB_SUCCESS);
91
92
    push(value);
93
94
    names_next++;
95
    return true;
96
  }
97
98
  return false; // No more rows
99
}
100
101
static LibInnoDBStatusTool *status_tool;
102
1530.2.6 by Monty Taylor
Moved plugin::Context to module::Context.
103
int status_table_function_initialize(drizzled::module::Context &context)
1283.28.9 by Stewart Smith
basic DATA_DICTIONARY.INNODB_STATUS table_function plugin. This gets the InnoDB status and lets the user query it.
104
{
105
  status_tool= new(std::nothrow)LibInnoDBStatusTool();
1283.32.9 by Stewart Smith
merge trunk
106
  context.add(status_tool);
1283.28.9 by Stewart Smith
basic DATA_DICTIONARY.INNODB_STATUS table_function plugin. This gets the InnoDB status and lets the user query it.
107
108
  return 0;
109
}