MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_hosts.cc
1 /* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15 
16 #include "my_global.h"
17 #include "my_pthread.h"
18 #include "table_hosts.h"
19 #include "pfs_instr_class.h"
20 #include "pfs_instr.h"
21 #include "pfs_account.h"
22 #include "pfs_host.h"
23 #include "pfs_visitor.h"
24 
25 THR_LOCK table_hosts::m_table_lock;
26 
27 static const TABLE_FIELD_TYPE field_types[]=
28 {
29  {
30  { C_STRING_WITH_LEN("HOST") },
31  { C_STRING_WITH_LEN("char(60)") },
32  { NULL, 0}
33  },
34  {
35  { C_STRING_WITH_LEN("CURRENT_CONNECTIONS") },
36  { C_STRING_WITH_LEN("bigint(20)") },
37  { NULL, 0}
38  },
39  {
40  { C_STRING_WITH_LEN("TOTAL_CONNECTIONS") },
41  { C_STRING_WITH_LEN("bigint(20)") },
42  { NULL, 0}
43  }
44 };
45 
47 table_hosts::m_field_def=
48 { 3, field_types };
49 
52 {
53  { C_STRING_WITH_LEN("hosts") },
56  NULL, /* write_row */
57  table_hosts::delete_all_rows,
58  NULL, /* get_row_count */
59  1000, /* records */
60  sizeof(PFS_simple_index), /* ref length */
61  &m_table_lock,
62  &m_field_def,
63  false /* checked */
64 };
65 
67 {
68  return new table_hosts();
69 }
70 
71 int
72 table_hosts::delete_all_rows(void)
73 {
85  return 0;
86 }
87 
88 table_hosts::table_hosts()
89  : cursor_by_host(& m_share),
90  m_row_exists(false)
91 {}
92 
93 void table_hosts::make_row(PFS_host *pfs)
94 {
95  pfs_lock lock;
96 
97  m_row_exists= false;
98  pfs->m_lock.begin_optimistic_lock(&lock);
99 
100  if (m_row.m_host.make_row(pfs))
101  return;
102 
104  PFS_connection_iterator::visit_host(pfs, true, true, & visitor);
105 
106  if (! pfs->m_lock.end_optimistic_lock(& lock))
107  return;
108 
109  m_row.m_connection_stat.set(& visitor.m_stat);
110  m_row_exists= true;
111 }
112 
114  unsigned char *buf,
115  Field **fields,
116  bool read_all)
117 {
118  Field *f;
119 
120  if (unlikely(! m_row_exists))
121  return HA_ERR_RECORD_DELETED;
122 
123  /* Set the null bits */
124  DBUG_ASSERT(table->s->null_bytes == 1);
125  buf[0]= 0;
126 
127  for (; (f= *fields) ; fields++)
128  {
129  if (read_all || bitmap_is_set(table->read_set, f->field_index))
130  {
131  switch(f->field_index)
132  {
133  case 0: /* HOST */
134  m_row.m_host.set_field(f);
135  break;
136  case 1: /* CURRENT_CONNECTIONS */
137  case 2: /* TOTAL_CONNECTIONS */
138  m_row.m_connection_stat.set_field(f->field_index - 1, f);
139  break;
140  default:
141  DBUG_ASSERT(false);
142  }
143  }
144  }
145  return 0;
146 }
147