149
149
share->tmp_table= INTERNAL_TMP_TABLE; // for intern_close_table()
152
table->cursor->close();
153
table->db_stat= 0; // Mark cursor closed
152
table->file->close();
153
table->db_stat= 0; // Mark file closed
154
154
TableShare::release(table->s);
156
table->cursor->change_table_ptr(table, table->s);
156
table->file->change_table_ptr(table, table->s);
240
240
void Table::intern_close_table()
241
241
{ // Free all structures
243
if (cursor) // Not true if name lock
244
closefrm(true); // close cursor
243
if (file) // Not true if name lock
244
closefrm(true); // close file
466
466
safe_mutex_assert_owner(&LOCK_open);
467
467
assert(table->key_read == 0);
468
assert(!table->cursor || table->cursor->inited == Cursor::NONE);
468
assert(!table->file || table->file->inited == Cursor::NONE);
470
470
open_tables= table->next;
923
923
We want to prevent other connections from opening this table until end
924
924
of statement as it is likely that modifications of table's metadata are
925
not yet finished (for example CREATE TRIGGER have to change .TRG cursor,
925
not yet finished (for example CREATE TRIGGER have to change .TRG file,
926
926
or we might want to drop table if CREATE TABLE ... SELECT fails).
927
927
This also allows us to assume that no other connection will sneak in
928
928
before we will get table-level lock on this table.
1469
1469
tmp.next= table->next;
1470
1470
tmp.prev= table->prev;
1473
table->closefrm(true); // close cursor, free everything
1473
table->closefrm(true); // close file, free everything
1476
1476
table->default_column_bitmaps();
1477
table->cursor->change_table_ptr(table, table->s);
1477
table->file->change_table_ptr(table, table->s);
1479
1479
assert(table->alias != 0);
1480
1480
for (field=table->field ; *field ; field++)
1952
1952
HA_TRY_READ_ONLY),
1953
1953
(EXTRA_RECORD),
1954
session->open_options, entry)))
1954
session->open_options, entry, OTM_OPEN)))
1956
1956
if (error == 7) // Table def changed
1994
1994
if (!entry->s || !entry->s->crashed)
1996
// Code below is for repairing a crashed cursor
1996
// Code below is for repairing a crashed file
1997
1997
if ((error= lock_table_name(session, table_list, true)))
2013
2013
HA_TRY_READ_ONLY),
2015
2015
ha_open_options | HA_OPEN_FOR_REPAIR,
2016
entry) || ! entry->cursor)
2016
entry, OTM_OPEN) || ! entry->file)
2018
2018
/* Give right error message */
2019
2019
session->clear_error();
2020
2020
my_error(ER_NOT_KEYFILE, MYF(0), share->table_name.str, my_errno);
2021
2021
errmsg_printf(ERRMSG_LVL_ERROR, _("Couldn't repair table: %s.%s"), share->db.str,
2022
2022
share->table_name.str);
2024
2024
entry->closefrm(false);
2038
2038
If we are here, there was no fatal error (but error may be still
2041
if (unlikely(entry->cursor->implicit_emptied))
2041
if (unlikely(entry->file->implicit_emptied))
2043
2043
ReplicationServices &replication_services= ReplicationServices::singleton();
2044
entry->cursor->implicit_emptied= 0;
2044
entry->file->implicit_emptied= 0;
2046
2046
char *query, *end;
2047
2047
uint32_t query_buf_size= 20 + share->db.length + share->table_name.length +1;
2349
2349
Table *Session::open_temporary_table(const char *path, const char *db_arg,
2350
const char *table_name_arg, bool link_in_list)
2350
const char *table_name_arg, bool link_in_list,
2351
open_table_mode open_mode)
2352
2353
Table *new_tmp_table;
2353
2354
TableShare *share;
2378
2379
if (open_table_def(*this, share) ||
2379
2380
open_table_from_share(this, share, table_name_arg,
2381
(open_mode == OTM_ALTER) ? 0 :
2380
2382
(uint32_t) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE |
2384
(open_mode == OTM_ALTER) ?
2385
(EXTRA_RECORD | OPEN_FRM_FILE_ONLY)
2383
2387
ha_open_options,
2388
new_tmp_table, open_mode))
2386
2390
/* No need to lock share->mutex as this is not needed for tmp tables */
2387
2391
share->free_table_share();
2392
2396
new_tmp_table->reginfo.lock_type= TL_WRITE; // Simulate locked
2393
share->tmp_table= (new_tmp_table->cursor->has_transactions() ?
2394
TRANSACTIONAL_TMP_TABLE : NON_TRANSACTIONAL_TMP_TABLE);
2397
if (open_mode == OTM_ALTER)
2400
Temporary table has been created with frm_only
2401
and has not been created in any storage engine
2403
share->tmp_table= TMP_TABLE_FRM_FILE_ONLY;
2406
share->tmp_table= (new_tmp_table->file->has_transactions() ?
2407
TRANSACTIONAL_TMP_TABLE : NON_TRANSACTIONAL_TMP_TABLE);
2396
2409
if (link_in_list)
4527
4541
session->thread_stack= (char*) &session;
4528
4542
session->storeGlobals();
4530
plugin::StorageEngine::removeLostTemporaryTables(*session, drizzle_tmpdir);
4544
CachedDirectory dir(drizzle_tmpdir);
4548
my_errno= dir.getError();
4549
my_error(ER_CANT_READ_DIR, MYF(0), drizzle_tmpdir, my_errno);
4553
CachedDirectory::Entries files= dir.getEntries();
4554
CachedDirectory::Entries::iterator fileIter= files.begin();
4556
/* Remove all temp tables in the tmpdir */
4557
while (fileIter != files.end())
4559
CachedDirectory::Entry *entry= *fileIter;
4560
string prefix= entry->filename.substr(0, TMP_FILE_PREFIX_LENGTH);
4562
if (prefix == TMP_FILE_PREFIX)
4564
char *ext= fn_ext(entry->filename.c_str());
4565
uint32_t ext_len= strlen(ext);
4566
uint32_t filePath_len= snprintf(filePath, sizeof(filePath),
4567
"%s%c%s", drizzle_tmpdir, FN_LIBCHAR,
4568
entry->filename.c_str());
4570
if (ext_len && !memcmp(drizzled::plugin::DEFAULT_DEFINITION_FILE_EXT.c_str(), ext, ext_len))
4573
/* We should cut file extention before deleting of table */
4574
memcpy(filePathCopy, filePath, filePath_len - ext_len);
4575
filePathCopy[filePath_len - ext_len]= 0;
4576
share.init(NULL, filePathCopy);
4577
if (!open_table_def(*session, &share))
4579
share.db_type()->doDropTable(*session, filePathCopy);
4581
share.free_table_share();
4584
File can be already deleted by tmp_table.file->delete_table().
4585
So we hide error messages which happnes during deleting of these
4588
my_delete(filePath, MYF(0));
4532
4594
delete session;