1360
1365
Session *session __attribute__((unused)))
1362
1367
/* Grab the error message */
1363
strmake(buff, message, sizeof(buff)-1);
1368
strncpy(buff, message, sizeof(buff)-1);
1373
struct handlerton_delete_table_args {
1380
static bool deletetable_handlerton(Session *unused1 __attribute__((unused)),
1384
struct handlerton_delete_table_args *dtargs= (struct handlerton_delete_table_args *) args;
1386
Session *session= dtargs->session;
1387
const char *path= dtargs->path;
1390
char tmp_path[FN_REFLEN];
1392
if(dtargs->error!=ENOENT) /* already deleted table */
1395
handlerton *table_type= plugin_data(plugin, handlerton *);
1400
if(!(table_type->state == SHOW_OPTION_YES && table_type->create))
1403
if ((file= table_type->create(table_type, NULL, session->mem_root)))
1408
path= check_lowercase_names(file, path, tmp_path);
1409
int error= file->ha_delete_table(path);
1413
dtargs->error= error;
1415
delete dtargs->file;
1369
1424
This should return ENOENT if the file doesn't exists.
1370
1425
The .frm file will be deleted only if we return 0 or ENOENT
1372
int ha_delete_table(Session *session, handlerton *table_type, const char *path,
1427
int ha_delete_table(Session *session, const char *path,
1373
1428
const char *db, const char *alias, bool generate_warning)
1376
char tmp_path[FN_REFLEN];
1430
TABLE_SHARE dummy_share;
1378
1431
Table dummy_table;
1379
TABLE_SHARE dummy_share;
1433
struct handlerton_delete_table_args dtargs;
1434
dtargs.error= ENOENT;
1435
dtargs.session= session;
1439
plugin_foreach(NULL, deletetable_handlerton, DRIZZLE_STORAGE_ENGINE_PLUGIN,
1381
1442
memset(&dummy_table, 0, sizeof(dummy_table));
1382
1443
memset(&dummy_share, 0, sizeof(dummy_share));
1383
1444
dummy_table.s= &dummy_share;
1385
/* DB_TYPE_UNKNOWN is used in ALTER Table when renaming only .frm files */
1386
if (table_type == NULL ||
1387
! (file=get_new_handler((TABLE_SHARE*)0, session->mem_root, table_type)))
1390
path= check_lowercase_names(file, path, tmp_path);
1391
if ((error= file->ha_delete_table(path)) && generate_warning)
1446
if (dtargs.error && generate_warning)
1394
1449
Because file->print_error() use my_error() to generate the error message
2323
static bool update_frm_version(Table *table)
2325
char path[FN_REFLEN];
2330
No need to update frm version in case table was created or checked
2331
by server with the same version. This also ensures that we do not
2332
update frm version for temporary tables as this code doesn't support
2335
if (table->s->mysql_version == DRIZZLE_VERSION_ID)
2338
strxmov(path, table->s->normalized_path.str, reg_ext, NULL);
2340
if ((file= my_open(path, O_RDWR, MYF(MY_WME))) >= 0)
2342
unsigned char version[4];
2343
char *key= table->s->table_cache_key.str;
2344
uint32_t key_length= table->s->table_cache_key.length;
2346
HASH_SEARCH_STATE state;
2348
int4store(version, DRIZZLE_VERSION_ID);
2350
if (pwrite(file, (unsigned char*)version, 4, 51L) == 0)
2356
for (entry=(Table*) hash_first(&open_cache,(unsigned char*) key,key_length, &state);
2358
entry= (Table*) hash_next(&open_cache,(unsigned char*) key,key_length, &state))
2359
entry->s->mysql_version= DRIZZLE_VERSION_ID;
2363
my_close(file,MYF(MY_WME));
2371
2378
key if error because of duplicated keys
4279
4286
- table is not mysql.event
4282
static bool check_table_binlog_row_based(Session *session, Table *table)
4284
if (table->s->cached_row_logging_check == -1)
4286
int const check(table->s->tmp_table == NO_TMP_TABLE &&
4287
binlog_filter->db_ok(table->s->db.str));
4288
table->s->cached_row_logging_check= check;
4291
assert(table->s->cached_row_logging_check == 0 ||
4292
table->s->cached_row_logging_check == 1);
4294
return (session->current_stmt_binlog_row_based &&
4295
table->s->cached_row_logging_check &&
4296
(session->options & OPTION_BIN_LOG) &&
4297
mysql_bin_log.is_open());
4302
Write table maps for all (manually or automatically) locked tables
4305
This function will generate and write table maps for all tables
4306
that are locked by the thread 'session'. Either manually locked
4307
(stored in Session::locked_tables) and automatically locked (stored
4308
in Session::lock) are considered.
4310
@param session Pointer to Session structure
4313
@retval 1 Failed to write all table maps
4317
Session::locked_tables
4320
static int write_locked_table_maps(Session *session)
4322
if (session->get_binlog_table_maps() == 0)
4324
DRIZZLE_LOCK *locks[3];
4325
locks[0]= session->extra_lock;
4326
locks[1]= session->lock;
4327
locks[2]= session->locked_tables;
4328
for (uint32_t i= 0 ; i < sizeof(locks)/sizeof(*locks) ; ++i )
4330
DRIZZLE_LOCK const *const lock= locks[i];
4334
Table **const end_ptr= lock->table + lock->table_count;
4335
for (Table **table_ptr= lock->table ;
4336
table_ptr != end_ptr ;
4339
Table *const table= *table_ptr;
4340
if (table->current_lock == F_WRLCK &&
4341
check_table_binlog_row_based(session, table))
4343
int const has_trans= table->file->has_transactions();
4344
int const error= session->binlog_write_table_map(table, has_trans);
4346
If an error occurs, it is the responsibility of the caller to
4347
roll back the transaction.
4349
if (unlikely(error))
4359
typedef bool Log_func(Session*, Table*, bool, const unsigned char*, const unsigned char*);
4361
static int binlog_log_row(Table* table,
4362
const unsigned char *before_record,
4363
const unsigned char *after_record,
4366
if (table->no_replicate)
4289
static bool binlog_log_row(Table* table,
4290
const unsigned char *before_record,
4291
const unsigned char *after_record)
4369
4294
Session *const session= table->in_use;
4371
if (check_table_binlog_row_based(session, table))
4374
If there are no table maps written to the binary log, this is
4375
the first row handled in this statement. In that case, we need
4376
to write table maps for all locked tables to the binary log.
4296
if (table->no_replicate)
4299
if (session->getReplicationData() == NULL)
4301
error= replicator_session_init(session);
4304
switch (session->lex->sql_command)
4306
case SQLCOM_REPLACE:
4308
case SQLCOM_REPLACE_SELECT:
4309
case SQLCOM_INSERT_SELECT:
4310
error= replicator_write_row(session, table);
4314
case SQLCOM_UPDATE_MULTI:
4315
error= replicator_update_row(session, table, before_record, after_record);
4319
case SQLCOM_DELETE_MULTI:
4320
error= replicator_delete_row(session, table);
4324
For everything else we ignore the event (since it just involves a temp table)
4378
if (likely(!(error= write_locked_table_maps(session))))
4380
bool const has_trans= table->file->has_transactions();
4381
error= (*log_func)(session, table, has_trans, before_record, after_record);
4384
return error ? HA_ERR_RBR_LOGGING_FAILED : 0;
4387
4333
int handler::ha_external_lock(Session *session, int lock_type)
4460
4406
if (unlikely(error= update_row(old_data, new_data)))
4462
if (unlikely(error= binlog_log_row(table, old_data, new_data, log_func)))
4409
if (unlikely(binlog_log_row(table, old_data, new_data)))
4410
return HA_ERR_RBR_LOGGING_FAILED;
4467
4415
int handler::ha_delete_row(const unsigned char *buf)
4470
Log_func *log_func= Delete_rows_log_event::binlog_row_logging_function;
4472
4419
mark_trx_read_write();
4474
4421
if (unlikely(error= delete_row(buf)))
4476
if (unlikely(error= binlog_log_row(table, buf, 0, log_func)))
4424
if (unlikely(binlog_log_row(table, buf, 0)))
4425
return HA_ERR_RBR_LOGGING_FAILED;