MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ndb_thd_ndb.cc
1 /*
2  Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "ndb_thd_ndb.h"
19 
20 /*
21  Default value for max number of transactions createable against NDB from
22  the handler. Should really be 2 but there is a transaction to much allocated
23  when lock table is used, and one extra to used for global schema lock.
24 */
25 static const int MAX_TRANSACTIONS= 4;
26 
27 
28 Thd_ndb*
29 Thd_ndb::seize(THD* thd)
30 {
31  DBUG_ENTER("seize_thd_ndb");
32 
33  Thd_ndb* thd_ndb= new Thd_ndb(thd);
34  if (thd_ndb == NULL)
35  return NULL;
36 
37  if (thd_ndb->ndb->init(MAX_TRANSACTIONS) != 0)
38  {
39  DBUG_PRINT("error", ("Ndb::init failed, eror: %d message: %s",
40  thd_ndb->ndb->getNdbError().code,
41  thd_ndb->ndb->getNdbError().message));
42 
43  delete thd_ndb;
44  thd_ndb= NULL;
45  }
46  DBUG_RETURN(thd_ndb);
47 }
48 
49 
50 void
51 Thd_ndb::release(Thd_ndb* thd_ndb)
52 {
53  DBUG_ENTER("release_thd_ndb");
54  delete thd_ndb;
55  DBUG_VOID_RETURN;
56 }
57 
58 
59 bool
60 Thd_ndb::recycle_ndb(THD* thd)
61 {
62  DBUG_ENTER("recycle_ndb");
63  DBUG_PRINT("enter", ("ndb: 0x%lx", (long)ndb));
64 
65  DBUG_ASSERT(global_schema_lock_trans == NULL);
66  DBUG_ASSERT(trans == NULL);
67 
68  delete ndb;
69  if ((ndb= new Ndb(connection, "")) == NULL)
70  {
71  DBUG_PRINT("error",("failed to allocate Ndb object"));
72  DBUG_RETURN(false);
73  }
74 
75  if (ndb->init(MAX_TRANSACTIONS) != 0)
76  {
77  delete ndb;
78  ndb= NULL;
79  DBUG_PRINT("error", ("Ndb::init failed, %d message: %s",
80  ndb->getNdbError().code,
81  ndb->getNdbError().message));
82  DBUG_RETURN(false);
83  }
84  DBUG_RETURN(true);
85 }
86 
87 
88 bool
89 Thd_ndb::valid_ndb(void)
90 {
91  // The ndb object should be valid as long as a
92  // global schema lock transaction is ongoing
93  if (global_schema_lock_trans)
94  return true;
95 
96  // The ndb object should be valid as long as a
97  // transaction is ongoing
98  if (trans)
99  return true;
100 
101  if (unlikely(m_connect_count != connection->get_connect_count()))
102  return false;
103 
104  return true;
105 }
106 
107 
108 void
109 Thd_ndb::init_open_tables()
110 {
111  count= 0;
112  m_error= FALSE;
113  my_hash_reset(&open_tables);
114 }