| 206 | */ |
| 207 | |
| 208 | int ha_sequence::write_row(const uchar *buf) |
| 209 | { |
| 210 | int error; |
| 211 | sequence_definition tmp_seq; |
| 212 | bool sequence_locked; |
| 213 | THD *thd= table->in_use; |
| 214 | DBUG_ENTER("ha_sequence::write_row"); |
| 215 | DBUG_ASSERT(table->record[0] == buf); |
| 216 | |
| 217 | /* |
| 218 | Log to binary log even if this function has been called before |
| 219 | (The function ends by setting row_logging to 0) |
| 220 | */ |
| 221 | row_logging= row_logging_init; |
| 222 | if (unlikely(sequence->initialized == SEQUENCE::SEQ_IN_PREPARE)) |
| 223 | { |
| 224 | /* This calls is from ha_open() as part of create table */ |
| 225 | DBUG_RETURN(file->write_row(buf)); |
| 226 | } |
| 227 | if (unlikely(sequence->initialized == SEQUENCE::SEQ_IN_ALTER)) |
| 228 | { |
| 229 | int error= 0; |
| 230 | /* This is called from alter table */ |
| 231 | tmp_seq.read_fields(table); |
| 232 | if (tmp_seq.check_and_adjust(thd, 0)) |
| 233 | DBUG_RETURN(HA_ERR_SEQUENCE_INVALID_DATA); |
| 234 | sequence->copy(&tmp_seq); |
| 235 | if (likely(!(error= file->write_row(buf)))) |
| 236 | sequence->initialized= SEQUENCE::SEQ_READY_TO_USE; |
| 237 | row_logging= 0; |
| 238 | DBUG_RETURN(error); |
| 239 | } |
| 240 | if (unlikely(sequence->initialized != SEQUENCE::SEQ_READY_TO_USE)) |
| 241 | DBUG_RETURN(HA_ERR_WRONG_COMMAND); |
| 242 | |
| 243 | sequence_locked= write_locked; |
| 244 | if (!write_locked) // If not from next_value() |
| 245 | { |
| 246 | /* |
| 247 | User tries to write a full row directly to the sequence table with |
| 248 | INSERT or LOAD DATA. |
| 249 | |
| 250 | - Get an exclusive lock for the table. This is needed to ensure that |
| 251 | we excute all full inserts (same as ALTER SEQUENCE) in same order |
| 252 | on master and slaves |
| 253 | - Check that the new row is an accurate SEQUENCE object |
| 254 | */ |
| 255 | /* mark a full binlog image insert to force non-parallel slave */ |
| 256 | thd->transaction->stmt.mark_trans_did_ddl(); |
| 257 | if (table->s->tmp_table == NO_TMP_TABLE && |
| 258 | thd->mdl_context.upgrade_shared_lock(table->mdl_ticket, |
| 259 | MDL_EXCLUSIVE, |
| 260 | thd->variables. |
| 261 | lock_wait_timeout)) |
| 262 | DBUG_RETURN(ER_LOCK_WAIT_TIMEOUT); |
| 263 | |
| 264 | tmp_seq.read_fields(table); |
| 265 | if (tmp_seq.check_and_adjust(thd, 0)) |
nothing calls this directly
no test coverage detected