← Back to team overview

maria-developers team mailing list archive

Re: Help with running a transaction inside the server

 

Hi, Kristian!

On Feb 14, Kristian Nielsen wrote:
> Sergei Golubchik <serg@xxxxxxxxxxxx> writes:
> >> Right. In fact, I think perhaps I am doing it in a single statement already:
> >> 
> >>   mysql_reset_thd_for_next_command(thd, 0);
> >>   open_and_lock_tables(thd, &tlist, FALSE, 0);
> >>   table->file->ha_write_row(table->record[0]);
> >>   table->file->ha_rnd_pos_by_record(table->record[0]));
> >>   table->file->ha_delete_row(table->record[0]);
> >>   ha_commit_trans(thd, FALSE);
> >>   close_thread_tables(thd);
> >>   if (!in_transaction)
> >>     ha_commit_trans(thd, TRUE);
> 
> Indeed, the whole point of this is to be part of the running
> transaction. So that slave state becomes crash-safe, unlike now where
> we first commit and then write to the file relay-log.info - and a
> crash in the middle makes us inconsistent, etc.

Okay, I see.

> > If you're in the middle of the already running transaction, you probably
> > shouldn't commit it after your changes, but wait till the end -
> > arbitrary adding commits in the middle of a transaction is no good.
> 
> So this is what I try to address with this code:
> 
> >>   ha_commit_trans(thd, FALSE);
> >>   close_thread_tables(thd);
> >>   if (!in_transaction)
> >>     ha_commit_trans(thd, TRUE);
> 
> My intension was - first commit the "statement" (all=FALSE). Then, if I am
> part of a larger transaction, do not commit the transaction, postpone that to
> later. But if not part of a transaction, I have to commit it here.

Ah, okay. I didn't check what "in_transaction" means in the 
rpl_slave_state.

Regards,
Sergei


References