00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include <sys/types.h>
00024 #include <sys/stat.h>
00025 #include <fcntl.h>
00026
00027 #include <drizzled/session.h>
00028 #include <plugin/myisam/myisam.h>
00029 #include <drizzled/open_tables_state.h>
00030 #include <drizzled/plugin/transactional_storage_engine.h>
00031 #include <drizzled/table/instance.h>
00032 #include <drizzled/table.h>
00033 #include <drizzled/table_list.h>
00034
00035 namespace drizzled {
00036 namespace table {
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 bool Concurrent::reopen_name_locked_table(TableList* table_list, Session *session)
00062 {
00063 safe_mutex_assert_owner(table::Cache::mutex().native_handle());
00064
00065 if (session->getKilled())
00066 return true;
00067
00068 identifier::Table identifier(table_list->getSchemaName(), table_list->getTableName());
00069 if (open_unireg_entry(session, table_list->getTableName(), identifier))
00070 {
00071 intern_close_table();
00072 return true;
00073 }
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 getMutableShare()->resetVersion();
00084 in_use = session;
00085
00086 tablenr= session->open_tables.current_tablenr++;
00087 used_fields= 0;
00088 const_table= 0;
00089 null_row= false;
00090 maybe_null= false;
00091 force_index= false;
00092 status= STATUS_NO_RECORD;
00093
00094 return false;
00095 }
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 int table::Concurrent::open_unireg_entry(Session *session,
00120 const char *alias,
00121 identifier::Table &identifier)
00122 {
00123 int error;
00124 TableShare::shared_ptr share;
00125 uint32_t discover_retry_count= 0;
00126
00127 safe_mutex_assert_owner(table::Cache::mutex().native_handle());
00128 retry:
00129 if (not (share= table::instance::Shared::make_shared(session, identifier, error)))
00130 {
00131 return 1;
00132 }
00133
00134 while ((error= share->open_table_from_share(session,
00135 identifier,
00136 alias,
00137 (uint32_t) (HA_OPEN_KEYFILE |
00138 HA_OPEN_RNDFILE |
00139 HA_GET_INDEX |
00140 HA_TRY_READ_ONLY),
00141 session->open_options, *this)))
00142 {
00143 if (error == 7)
00144 {
00145 share->resetVersion();
00146 if (discover_retry_count++)
00147 {
00148 table::instance::release(share);
00149 return 1;
00150 }
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 if (share->getTableCount() != 1)
00172 {
00173 table::instance::release(share);
00174 return 1;
00175 }
00176
00177
00178 table::instance::release(share);
00179
00180 if (not session->getKilled())
00181 {
00182 drizzle_reset_errors(*session, true);
00183 session->clear_error();
00184 goto retry;
00185 }
00186
00187 return 1;
00188 }
00189
00190 table::instance::release(share);
00191
00192 return 1;
00193 }
00194
00195 return 0;
00196 }
00197
00198 void table::Concurrent::release(void)
00199 {
00200
00201
00202
00203
00204 if (getShare()->getType() == message::Table::STANDARD)
00205 {
00206 table::instance::release(getMutableShare());
00207 }
00208 else
00209 {
00210 delete _share;
00211 }
00212 _share= NULL;
00213 }
00214
00215 }
00216 }