~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
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2009 Sun Microsystems, Inc.
1273.13.1 by Brian Aker
First pass through data dictionary.
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
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
21
#include <config.h>
1273.14.5 by Monty Taylor
Merged trunk.
22
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
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
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
27
#include <drizzled/pthread_globals.h>
28
#include <drizzled/plugin/client.h>
29
#include <drizzled/plugin/authorization.h>
30
#include <drizzled/internal/my_sys.h>
31
#include <drizzled/internal/thread_var.h>
2239.1.8 by Olaf van der Spek
Refactor includes
32
#include <drizzled/session/state.h>
2269.1.4 by Olaf van der Spek
Session Times
33
#include <drizzled/session/times.h>
1273.13.51 by Brian Aker
Fix plugin definitions.
34
#include <set>
35
1273.13.1 by Brian Aker
First pass through data dictionary.
36
using namespace std;
37
using namespace drizzled;
38
1273.13.7 by Brian Aker
Updates to the classes (first pass).
39
ProcesslistTool::ProcesslistTool() :
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
40
  plugin::TableFunction("DATA_DICTIONARY", "PROCESSLIST")
1273.13.1 by Brian Aker
First pass through data dictionary.
41
{
1643.3.10 by Brian Aker
Column support, clean up of IS/DD for NULL type.
42
  add_field("ID", plugin::TableFunction::NUMBER, 0, false);
2029.1.26 by Brian Aker
Merge in work for reserved words in SQL standard.
43
  add_field("USERNAME", 16);
1273.13.19 by Brian Aker
Updated for longer hostname (aka... follow what the machine would actually
44
  add_field("HOST", NI_MAXHOST);
1993.3.1 by Andrew Hutchings
Enforce TableFunction::Generator::push() should only be used on a nullable field
45
  add_field("DB", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, true);
1273.13.19 by Brian Aker
Updated for longer hostname (aka... follow what the machine would actually
46
  add_field("COMMAND", 16);
2008.2.4 by Brian Aker
Merge in additional fixes for sign, plus alter table, plus TIME on
47
  add_field("TIME", plugin::TableFunction::SIZE, 0, false);
1726.3.2 by LinuxJedi
Stop processist from filling state down in empty states by accepting NULL.
48
  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
49
  add_field("INFO", plugin::TableFunction::STRING, PROCESS_LIST_WIDTH, true);
1999.4.11 by Brian Aker
Fix issues with some columns incorrectly reporting NULL if they were of
50
  add_field("HAS_GLOBAL_LOCK", plugin::TableFunction::BOOLEAN, 0, false);
1273.13.1 by Brian Aker
First pass through data dictionary.
51
}
52
1273.13.18 by Brian Aker
Update code, first pass through cleaner method for recursing through
53
ProcesslistTool::Generator::Generator(Field **arg) :
2015.3.1 by Brian Aker
Encapsulate client call. Also remove the need to call current_session when
54
  plugin::TableFunction::Generator(arg),
55
  session_generator(*getSession().user())
1273.13.1 by Brian Aker
First pass through data dictionary.
56
{
57
}
58
1273.13.21 by Brian Aker
Fix interface (we no longer need Fields passed around).
59
bool ProcesslistTool::Generator::populate()
1273.13.1 by Brian Aker
First pass through data dictionary.
60
{
2269.1.3 by Olaf van der Spek
Session Times
61
  while (Session* tmp= session_generator)
1861.5.2 by Brian Aker
Merge in generator for processlist.
62
  {
2269.1.3 by Olaf van der Spek
Session Times
63
    boost::shared_ptr<session::State> state(tmp->state());
2252.1.8 by Olaf van der Spek
Common fwd
64
    identifier::user::ptr tmp_sctx= tmp->user();
1861.5.2 by Brian Aker
Merge in generator for processlist.
65
66
    /* ID */
67
    push((int64_t) tmp->thread_id);
68
69
    /* USER */
2008.1.1 by Brian Aker
Adding user identifier that makes use of a shared ptr to handle concurrency
70
    if (not tmp_sctx->username().empty())
71
      push(tmp_sctx->username());
2227.4.3 by Olaf van der Spek
Remove unnecessary statement.h include
72
    else
1861.5.2 by Brian Aker
Merge in generator for processlist.
73
      push(_("no user"));
74
75
    /* HOST */
2008.1.1 by Brian Aker
Adding user identifier that makes use of a shared ptr to handle concurrency
76
    push(tmp_sctx->address());
1861.5.2 by Brian Aker
Merge in generator for processlist.
77
78
    /* DB */
2269.1.7 by Olaf van der Spek
Use util::string::ptr
79
    util::string::ptr schema(tmp->schema());
1976.5.2 by Brian Aker
This resolves the issue where one thread may be looking at schema while
80
    if (schema and not schema->empty())
1861.5.2 by Brian Aker
Merge in generator for processlist.
81
    {
1976.5.2 by Brian Aker
This resolves the issue where one thread may be looking at schema while
82
      push(*schema);
1861.5.2 by Brian Aker
Merge in generator for processlist.
83
    }
84
    else
85
    {
86
      push();
87
    }
88
89
    /* COMMAND */
2269.1.3 by Olaf van der Spek
Session Times
90
    if (tmp->getKilled() == Session::KILL_CONNECTION)
1861.5.2 by Brian Aker
Merge in generator for processlist.
91
    {
2269.1.3 by Olaf van der Spek
Session Times
92
      push("Killed");
1861.5.2 by Brian Aker
Merge in generator for processlist.
93
    }
94
    else
95
    {
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
96
      push(getCommandName(tmp->command));
1861.5.2 by Brian Aker
Merge in generator for processlist.
97
    }
98
2030.1.5 by Brian Aker
Update for moving DRIZZLE_TIME to type::Time
99
    /* type::Time */
2269.1.6 by Olaf van der Spek
Session Times
100
    boost::posix_time::time_duration duration_result= getSession().times.start_timer() - getSession().times._start_timer;
2269.1.2 by Olaf van der Spek
Session Times
101
    push(static_cast<uint64_t>(duration_result.is_negative() ? 0 : duration_result.total_seconds()));
1861.5.2 by Brian Aker
Merge in generator for processlist.
102
103
    /* STATE */
2002.1.3 by Brian Aker
This applies Monty's fix and simplifies down processlist so that you can't
104
    const char *step= tmp->get_proc_info();
2040.4.5 by Brian Aker
Merge in additional updates for time usage.
105
    step ? push(step): push();
1861.5.2 by Brian Aker
Merge in generator for processlist.
106
107
    /* INFO */
1976.5.1 by Brian Aker
This fixes the issue of a crash because of one thread touching the session
108
    if (state)
109
    {
110
      size_t length;
111
      const char *tmp_ptr= state->query(length);
112
      push(tmp_ptr, length);
113
    }
114
    else
115
    {
116
      push();
117
    }
1861.5.2 by Brian Aker
Merge in generator for processlist.
118
1948.2.7 by Brian Aker
Adding "HAS_GLOBAL_LOCK" to processlist.
119
    /* HAS_GLOBAL_LOCK */
1948.2.8 by Brian Aker
Modify how we go about getting the information about the global lock from
120
    bool has_global_lock= tmp->isGlobalReadLock();
121
    push(has_global_lock);
1948.2.7 by Brian Aker
Adding "HAS_GLOBAL_LOCK" to processlist.
122
1861.5.2 by Brian Aker
Merge in generator for processlist.
123
    return true;
124
  }
125
126
  return false;
1273.13.1 by Brian Aker
First pass through data dictionary.
127
}