@@ -1182,75 +1182,83 @@ int ha_spider::external_lock(
1182
1182
int error_num = 0;
1183
1183
SPIDER_TRX *trx;
1184
1184
backup_error_status();
1185
+
1185
1186
DBUG_ENTER("ha_spider::external_lock");
1186
1187
DBUG_PRINT("info",("spider this=%p", this));
1187
1188
DBUG_PRINT("info",("spider lock_type=%x", lock_type));
1188
- #if MYSQL_VERSION_ID < 50500
1189
- DBUG_PRINT("info",("spider thd->options=%x", (int) thd->options));
1190
- #endif
1191
- #ifdef WITH_PARTITION_STORAGE_ENGINE
1192
- if (
1193
- wide_handler->stage == SPD_HND_STAGE_EXTERNAL_LOCK &&
1194
- wide_handler->stage_executor != this)
1189
+ DBUG_PRINT("info", ("spider sql_command=%d", thd_sql_command(thd)));
1190
+
1191
+ if (wide_handler->stage == SPD_HND_STAGE_EXTERNAL_LOCK)
1195
1192
{
1196
- DBUG_RETURN(0);
1193
+ /* Only the stage executor deals with table locks. */
1194
+ if (wide_handler->stage_executor != this)
1195
+ {
1196
+ DBUG_RETURN(0);
1197
+ }
1198
+ }
1199
+ else
1200
+ {
1201
+ /* Update the stage executor when the stage changes */
1202
+ wide_handler->stage= SPD_HND_STAGE_EXTERNAL_LOCK;
1203
+ wide_handler->stage_executor= this;
1197
1204
}
1198
- wide_handler->stage = SPD_HND_STAGE_EXTERNAL_LOCK;
1199
- wide_handler->stage_executor = this;
1200
- #endif
1201
- #ifdef HANDLER_HAS_NEED_INFO_FOR_AUTO_INC
1202
- info_auto_called = FALSE;
1203
- #endif
1204
1205
1206
+ info_auto_called = FALSE;
1207
+ wide_handler->external_lock_type= lock_type;
1205
1208
wide_handler->sql_command = thd_sql_command(thd);
1209
+
1210
+ /* We treat BEGIN as if UNLOCK TABLE. */
1206
1211
if (wide_handler->sql_command == SQLCOM_BEGIN)
1212
+ {
1207
1213
wide_handler->sql_command = SQLCOM_UNLOCK_TABLES;
1214
+ }
1215
+ if (lock_type == F_UNLCK &&
1216
+ wide_handler->sql_command != SQLCOM_UNLOCK_TABLES)
1217
+ {
1218
+ DBUG_RETURN(0);
1219
+ }
1208
1220
1209
1221
trx = spider_get_trx(thd, TRUE, &error_num);
1210
1222
if (error_num)
1223
+ {
1211
1224
DBUG_RETURN(error_num);
1225
+ }
1212
1226
wide_handler->trx = trx;
1213
1227
1214
- DBUG_PRINT("info",("spider sql_command=%d", wide_handler->sql_command));
1215
- #ifdef HA_CAN_BULK_ACCESS
1216
- wide_handler->external_lock_cnt++;
1217
- #endif
1218
- if (
1219
- lock_type == F_UNLCK &&
1220
- wide_handler->sql_command != SQLCOM_UNLOCK_TABLES
1221
- )
1222
- DBUG_RETURN(0);
1228
+ /* Question: Why the following if block is necessary? Why here? */
1223
1229
if (store_error_num)
1230
+ {
1224
1231
DBUG_RETURN(store_error_num);
1225
- wide_handler->external_lock_type = lock_type;
1226
- #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
1227
- if ((conn_kinds & SPIDER_CONN_KIND_MYSQL))
1232
+ }
1233
+
1234
+ DBUG_ASSERT(wide_handler->sql_command != SQLCOM_RENAME_TABLE &&
1235
+ wide_handler->sql_command != SQLCOM_DROP_DB);
1236
+
1237
+ if (wide_handler->sql_command == SQLCOM_DROP_TABLE ||
1238
+ wide_handler->sql_command == SQLCOM_ALTER_TABLE)
1228
1239
{
1229
- #endif
1230
- if (
1231
- /* SQLCOM_RENAME_TABLE and SQLCOM_DROP_DB don't come here */
1232
- wide_handler->sql_command == SQLCOM_DROP_TABLE ||
1233
- wide_handler->sql_command == SQLCOM_ALTER_TABLE
1234
- ) {
1235
- if (trx->locked_connections)
1236
- {
1237
- my_message(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM,
1238
- ER_SPIDER_ALTER_BEFORE_UNLOCK_STR, MYF(0));
1239
- DBUG_RETURN(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM);
1240
- }
1241
- DBUG_RETURN(0);
1240
+ if (trx->locked_connections)
1241
+ {
1242
+ my_message(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM,
1243
+ ER_SPIDER_ALTER_BEFORE_UNLOCK_STR, MYF(0));
1244
+ DBUG_RETURN(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM);
1242
1245
}
1243
- if (unlikely((error_num = spider_internal_start_trx(this))))
1246
+ DBUG_RETURN(0);
1247
+ }
1248
+
1249
+ if (lock_type != F_UNLCK)
1250
+ {
1251
+ if (unlikely((error_num= spider_internal_start_trx(this))))
1244
1252
{
1245
1253
DBUG_RETURN(error_num);
1246
1254
}
1247
- #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
1248
- } else {
1249
- trans_register_ha(trx->thd, FALSE, spider_hton_ptr);
1250
- if (thd_test_options(trx->thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
1251
- trans_register_ha(trx->thd, TRUE, spider_hton_ptr);
1255
+ if (wide_handler->sql_command != SQLCOM_SELECT &&
1256
+ wide_handler->sql_command != SQLCOM_HA_READ)
1257
+ {
1258
+ trx->updated_in_this_trx= TRUE;
1259
+ DBUG_PRINT("info", ("spider trx->updated_in_this_trx=TRUE"));
1260
+ }
1252
1261
}
1253
- #endif
1254
1262
1255
1263
if (wide_handler->lock_table_type > 0 ||
1256
1264
wide_handler->sql_command == SQLCOM_UNLOCK_TABLES)
@@ -1263,67 +1271,24 @@ int ha_spider::external_lock(
1263
1271
}
1264
1272
1265
1273
/* lock/unlock tables */
1266
- #ifdef WITH_PARTITION_STORAGE_ENGINE
1267
1274
if (partition_handler && partition_handler->handlers)
1268
1275
{
1269
- uint roop_count;
1270
- for (roop_count = 0; roop_count < partition_handler->no_parts;
1271
- ++roop_count)
1276
+ for (uint roop_count= 0; roop_count < partition_handler->no_parts;
1277
+ ++roop_count)
1272
1278
{
1273
1279
if (unlikely((error_num =
1274
1280
partition_handler->handlers[roop_count]->lock_tables())))
1275
1281
{
1276
1282
DBUG_RETURN(error_num);
1277
1283
}
1278
1284
}
1279
- } else {
1280
- #endif
1281
- if (unlikely((error_num = lock_tables())))
1282
- {
1283
- DBUG_RETURN(error_num);
1284
- }
1285
- #ifdef WITH_PARTITION_STORAGE_ENGINE
1286
1285
}
1287
- #endif
1288
- }
1289
-
1290
- DBUG_PRINT("info",("spider trx_start=%s",
1291
- trx->trx_start ? "TRUE" : "FALSE"));
1292
- /* need to check after spider_internal_start_trx() */
1293
- if (trx->trx_start)
1294
- {
1295
- switch (wide_handler->sql_command)
1286
+ else if (unlikely((error_num= lock_tables())))
1296
1287
{
1297
- case SQLCOM_SELECT:
1298
- case SQLCOM_HA_READ:
1299
- #ifdef HS_HAS_SQLCOM
1300
- case SQLCOM_HS_READ:
1301
- #endif
1302
- /* nothing to do */
1303
- break;
1304
- case SQLCOM_UPDATE:
1305
- case SQLCOM_UPDATE_MULTI:
1306
- #ifdef HS_HAS_SQLCOM
1307
- case SQLCOM_HS_UPDATE:
1308
- #endif
1309
- case SQLCOM_CREATE_TABLE:
1310
- case SQLCOM_INSERT:
1311
- case SQLCOM_INSERT_SELECT:
1312
- case SQLCOM_DELETE:
1313
- case SQLCOM_LOAD:
1314
- case SQLCOM_REPLACE:
1315
- case SQLCOM_REPLACE_SELECT:
1316
- case SQLCOM_DELETE_MULTI:
1317
- #ifdef HS_HAS_SQLCOM
1318
- case SQLCOM_HS_INSERT:
1319
- case SQLCOM_HS_DELETE:
1320
- #endif
1321
- default:
1322
- trx->updated_in_this_trx = TRUE;
1323
- DBUG_PRINT("info",("spider trx->updated_in_this_trx=TRUE"));
1324
- break;
1288
+ DBUG_RETURN(error_num);
1325
1289
}
1326
1290
}
1291
+
1327
1292
DBUG_RETURN(0);
1328
1293
}
1329
1294
0 commit comments