MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_file_instances.cc
Go to the documentation of this file.
1 /* Copyright (c) 2008, 2010, 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 
21 #include "my_global.h"
22 #include "my_pthread.h"
23 #include "pfs_instr.h"
24 #include "pfs_column_types.h"
25 #include "pfs_column_values.h"
26 #include "table_file_instances.h"
27 #include "pfs_global.h"
28 
29 THR_LOCK table_file_instances::m_table_lock;
30 
31 static const TABLE_FIELD_TYPE field_types[]=
32 {
33  {
34  { C_STRING_WITH_LEN("FILE_NAME") },
35  { C_STRING_WITH_LEN("varchar(512)") },
36  { NULL, 0}
37  },
38  {
39  { C_STRING_WITH_LEN("EVENT_NAME") },
40  { C_STRING_WITH_LEN("varchar(128)") },
41  { NULL, 0}
42  },
43  {
44  { C_STRING_WITH_LEN("OPEN_COUNT") },
45  { C_STRING_WITH_LEN("int(10)") },
46  { NULL, 0}
47  }
48 };
49 
51 table_file_instances::m_field_def=
52 { 3, field_types };
53 
56 {
57  { C_STRING_WITH_LEN("file_instances") },
59  &table_file_instances::create,
60  NULL, /* write_row */
61  NULL, /* delete_all_rows */
62  NULL, /* get_row_count */
63  1000, /* records */
64  sizeof(PFS_simple_index),
65  &m_table_lock,
66  &m_field_def,
67  false /* checked */
68 };
69 
70 PFS_engine_table* table_file_instances::create(void)
71 {
72  return new table_file_instances();
73 }
74 
75 table_file_instances::table_file_instances()
76  : PFS_engine_table(&m_share, &m_pos),
77  m_row_exists(false), m_pos(0), m_next_pos(0)
78 {}
79 
81 {
82  m_pos.m_index= 0;
83  m_next_pos.m_index= 0;
84 }
85 
87 {
88  PFS_file *pfs;
89 
90  for (m_pos.set_at(&m_next_pos);
91  m_pos.m_index < file_max;
92  m_pos.next())
93  {
94  pfs= &file_array[m_pos.m_index];
95  if (pfs->m_lock.is_populated())
96  {
97  make_row(pfs);
98  m_next_pos.set_after(&m_pos);
99  return 0;
100  }
101  }
102 
103  return HA_ERR_END_OF_FILE;
104 }
105 
106 int table_file_instances::rnd_pos(const void *pos)
107 {
108  PFS_file *pfs;
109 
110  set_position(pos);
111  DBUG_ASSERT(m_pos.m_index < file_max);
112  pfs= &file_array[m_pos.m_index];
113 
114  if (! pfs->m_lock.is_populated())
115  return HA_ERR_RECORD_DELETED;
116 
117  make_row(pfs);
118  return 0;
119 }
120 
121 void table_file_instances::make_row(PFS_file *pfs)
122 {
123  pfs_lock lock;
124  PFS_file_class *safe_class;
125 
126  m_row_exists= false;
127 
128  /* Protect this reader against a file delete */
129  pfs->m_lock.begin_optimistic_lock(&lock);
130 
131  safe_class= sanitize_file_class(pfs->m_class);
132  if (unlikely(safe_class == NULL))
133  return;
134 
135  m_row.m_filename= pfs->m_filename;
137  m_row.m_event_name= safe_class->m_name;
138  m_row.m_event_name_length= safe_class->m_name_length;
140 
141  if (pfs->m_lock.end_optimistic_lock(&lock))
142  m_row_exists= true;
143 }
144 
145 int table_file_instances::read_row_values(TABLE *table,
146  unsigned char *,
147  Field **fields,
148  bool read_all)
149 {
150  Field *f;
151 
152  if (unlikely(! m_row_exists))
153  return HA_ERR_RECORD_DELETED;
154 
155  /* Set the null bits */
156  DBUG_ASSERT(table->s->null_bytes == 0);
157 
158  for (; (f= *fields) ; fields++)
159  {
160  if (read_all || bitmap_is_set(table->read_set, f->field_index))
161  {
162  switch(f->field_index)
163  {
164  case 0: /* FILENAME */
166  break;
167  case 1: /* EVENT_NAME */
169  m_row.m_event_name_length);
170  break;
171  case 2: /* OPEN_COUNT */
172  set_field_ulong(f, m_row.m_open_count);
173  break;
174  default:
175  DBUG_ASSERT(false);
176  }
177  }
178  }
179 
180  return 0;
181 }
182