~drizzle-trunk/drizzle/development

1273.13.1 by Brian Aker
First pass through data dictionary.
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2009 Sun Microsystems
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
20
1273.14.5 by Monty Taylor
Merged trunk.
21
#include "config.h"
22
1273.13.55 by Brian Aker
Naming fixes.
23
#include "plugin/session_dictionary/dictionary.h"
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
24
25
#include <netdb.h>
26
27
#include "drizzled/pthread_globals.h"
1273.13.1 by Brian Aker
First pass through data dictionary.
28
#include "drizzled/plugin/client.h"
1317.2.10 by Monty Taylor
Do the check directly in processlist.
29
#include "drizzled/plugin/authorization.h"
1273.13.1 by Brian Aker
First pass through data dictionary.
30
#include "drizzled/internal/my_sys.h"
1689.2.10 by Brian Aker
Move thread_var out to its own include file.
31
#include "drizzled/internal/thread_var.h"
1273.13.1 by Brian Aker
First pass through data dictionary.
32
1273.13.51 by Brian Aker
Fix plugin definitions.
33
#include <set>
34
1273.13.1 by Brian Aker
First pass through data dictionary.
35
using namespace std;
36
using namespace drizzled;
37
1273.13.7 by Brian Aker
Updates to the classes (first pass).
38
ProcesslistTool::ProcesslistTool() :
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
39
  plugin::TableFunction("DATA_DICTIONARY", "PROCESSLIST")
1273.13.1 by Brian Aker
First pass through data dictionary.
40
{
1643.3.10 by Brian Aker
Column support, clean up of IS/DD for NULL type.
41
  add_field("ID", plugin::TableFunction::NUMBER, 0, false);
1273.13.19 by Brian Aker
Updated for longer hostname (aka... follow what the machine would actually
42
  add_field("USER", 16);
43
  add_field("HOST", NI_MAXHOST);
44
  add_field("DB");
45
  add_field("COMMAND", 16);
1643.3.10 by Brian Aker
Column support, clean up of IS/DD for NULL type.
46
  add_field("TIME", plugin::TableFunction::NUMBER, 0, false);
1726.3.2 by LinuxJedi
Stop processist from filling state down in empty states by accepting NULL.
47
  add_field("STATE", plugin::TableFunction::STRING, 256, true);
1726.3.1 by LinuxJedi
Make processlist STATE and INFO nullable since we give them null states. Stops filldown of erronous data
48
  add_field("INFO", plugin::TableFunction::STRING, PROCESS_LIST_WIDTH, true);
1948.2.8 by Brian Aker
Modify how we go about getting the information about the global lock from
49
  add_field("HAS_GLOBAL_LOCK", plugin::TableFunction::BOOLEAN);
1273.13.1 by Brian Aker
First pass through data dictionary.
50
}
51
1273.13.18 by Brian Aker
Update code, first pass through cleaner method for recursing through
52
ProcesslistTool::Generator::Generator(Field **arg) :
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
53
  plugin::TableFunction::Generator(arg)
1273.13.1 by Brian Aker
First pass through data dictionary.
54
{
55
  now= time(NULL);
56
}
57
58
ProcesslistTool::Generator::~Generator()
59
{
60
}
61
1273.13.21 by Brian Aker
Fix interface (we no longer need Fields passed around).
62
bool ProcesslistTool::Generator::populate()
1273.13.1 by Brian Aker
First pass through data dictionary.
63
{
1932.3.5 by Brian Aker
Finish change so that we use a shared_ptr for the session list.
64
  drizzled::Session::shared_ptr tmp;
1861.5.2 by Brian Aker
Merge in generator for processlist.
65
66
  while ((tmp= session_generator))
67
  {
1976.5.1 by Brian Aker
This fixes the issue of a crash because of one thread touching the session
68
    drizzled::Session::State::const_shared_ptr state(tmp->state());
1861.5.2 by Brian Aker
Merge in generator for processlist.
69
    const SecurityContext *tmp_sctx= &tmp->getSecurityContext();
70
71
    /* ID */
72
    push((int64_t) tmp->thread_id);
73
74
    /* USER */
75
    if (not tmp_sctx->getUser().empty())
76
      push(tmp_sctx->getUser());
77
    else 
78
      push(_("no user"));
79
80
    /* HOST */
81
    push(tmp_sctx->getIp());
82
83
    /* DB */
1976.5.2 by Brian Aker
This resolves the issue where one thread may be looking at schema while
84
    drizzled::util::string::const_shared_ptr schema(tmp->schema());
85
    if (schema and not schema->empty())
1861.5.2 by Brian Aker
Merge in generator for processlist.
86
    {
1976.5.2 by Brian Aker
This resolves the issue where one thread may be looking at schema while
87
      push(*schema);
1861.5.2 by Brian Aker
Merge in generator for processlist.
88
    }
89
    else
90
    {
91
      push();
92
    }
93
94
    /* COMMAND */
1976.5.2 by Brian Aker
This resolves the issue where one thread may be looking at schema while
95
    const char *val= tmp->getKilled() == Session::KILL_CONNECTION ? "Killed" : NULL;
96
    if (val)
1861.5.2 by Brian Aker
Merge in generator for processlist.
97
    {
98
      push(val);
99
    }
100
    else
101
    {
102
      push(command_name[tmp->command].str, command_name[tmp->command].length);
103
    }
104
105
    /* DRIZZLE_TIME */
106
    push(static_cast<uint64_t>(tmp->start_time ?  now - tmp->start_time : 0));
107
108
    /* STATE */
1976.5.2 by Brian Aker
This resolves the issue where one thread may be looking at schema while
109
    val= (tmp->client->isWriting() ?
110
          "Writing to net" :
111
          tmp->client->isReading() ?
112
          (tmp->command == COM_SLEEP ?
113
           NULL : "Reading from net") :
114
          tmp->get_proc_info() ? tmp->get_proc_info() :
115
          tmp->getThreadVar() &&
116
          tmp->getThreadVar()->current_cond ?
117
          "Waiting on cond" : NULL);
1861.5.2 by Brian Aker
Merge in generator for processlist.
118
    val ? push(val) : push();
119
120
    /* INFO */
1976.5.1 by Brian Aker
This fixes the issue of a crash because of one thread touching the session
121
    if (state)
122
    {
123
      size_t length;
124
      const char *tmp_ptr= state->query(length);
125
      push(tmp_ptr, length);
126
    }
127
    else
128
    {
129
      push();
130
    }
1861.5.2 by Brian Aker
Merge in generator for processlist.
131
1948.2.7 by Brian Aker
Adding "HAS_GLOBAL_LOCK" to processlist.
132
    /* HAS_GLOBAL_LOCK */
1948.2.8 by Brian Aker
Modify how we go about getting the information about the global lock from
133
    bool has_global_lock= tmp->isGlobalReadLock();
134
    push(has_global_lock);
1948.2.7 by Brian Aker
Adding "HAS_GLOBAL_LOCK" to processlist.
135
1861.5.2 by Brian Aker
Merge in generator for processlist.
136
    return true;
137
  }
138
139
  return false;
1273.13.1 by Brian Aker
First pass through data dictionary.
140
}