Skip to content

MDEV-38600: Annotate the binlogging of recreating MEMORY tables#4942

Open
ParadoxV5 wants to merge 1 commit into10.11from
MDEV-38600
Open

MDEV-38600: Annotate the binlogging of recreating MEMORY tables#4942
ParadoxV5 wants to merge 1 commit into10.11from
MDEV-38600

Conversation

@ParadoxV5
Copy link
Copy Markdown
Contributor

The data in MEMORY tables is temporary and is lost when the server restarts.
Thus, it is well-intentioned to record TRUNCATE statements to the binary log when these tables are rediscovered empty.
However, as entries with no explicit user query associated (especially the lack of SHUTDOWN on crashes), those unaware of this mechanism can find them unexpected, not to mention their significance downstream in replication.

This commit adds a comment to these automatically generated TRUNCATE entries to briefly self-describe their source and purpose.
As a part of the generated query, this comment is visible together with the TRUNCATE itself in SHOW BINLOG EVENTS and mariadb-binlog, while maintaining seamlessness in replication.

There are no other changes in behaviour or storage engine API.

@ParadoxV5 ParadoxV5 requested a review from andrelkin April 14, 2026 23:57
@ParadoxV5 ParadoxV5 added MariaDB Corporation Replication Patches involved in replication labels Apr 14, 2026
Copy link
Copy Markdown
Contributor

@andrelkin andrelkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Howdy Jimmy!

While this looks good, we have had a similar pattern that I suggest to follow.

Comment thread sql/sql_base.cc Outdated
query.append(STRING_WITH_LEN("TRUNCATE TABLE "));
static const char
QUERY_START[]= "TRUNCATE TABLE ",
QUERY_COMMENT[]= " -- auto-generated for recreating memory table";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good, though please consider to make it more uniform with an existing pattern of such marking, see it for DROP TABLE specifically.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How’s this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads better. Thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new

/* generated by recreated memory table */

still reads strange to me. I think "generated by server" (from Andrei's suggested pattern) is more clear, as it makes it clear who the actor is (and not some outside source recreating the memory table). Then you can re-use that variable too 🤷

Copy link
Copy Markdown
Contributor Author

@ParadoxV5 ParadoxV5 Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

‘auto-recreated’? ‘restarted’? 🤔

I’m concerned that “generated by server” doesn’t hint at the purpose this TRUNCATE is about.
P.S. Nor that DROP Andrei mentioned… What is it?

The data in MEMORY tables is temporary and is lost when the server
restarts. Thus, it is well-intentioned to record TRUNCATE statements
to the binary log when these tables are rediscovered empty. However,
as entries with no explicit user query associated (especially the lack
of SHUTDOWN on crashes), those unaware of this mechanism can find them
unexpected, not to mention their significance downstream in replication.

This commit adds a comment to these automatically generated
TRUNCATE entries to briefly self-describe their source and purpose.
As a part of the generated query, this comment is visible together
with the TRUNCATE itself in SHOW BINLOG EVENTS and `mariadb-binlog`,
while maintaining seamlessness in replication.

There are no other changes in behaviour or storage engine API.

Reviewed-by: Andrei Elkin <andrei.elkin@mariadb.com>
Copy link
Copy Markdown
Contributor

@bnestere bnestere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @ParadoxV5 !

I left one comment on an existing thread, but Github PR pages sometimes make that hard to see, so here's the link to my comment.

Also, didn't we discuss writing a warning message to the error log if --init-rpl-role=slave? Granted, there are existing problems with --init-rpl-role, but it at least provides some additional way to get such information. And then init-rpl-role can be extended to be per-domain (or however we design it) later.

Copy link
Copy Markdown
Contributor Author

@ParadoxV5 ParadoxV5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, didn't we discuss writing a warning message to the error log if --init-rpl-role=slave?

I wonder about the value of having a warning in only the (intermediary) master’s error log, now that this SQL comment is visible directly from both binary and relay log.

  • --init-rpl-role=master (default):
    You were concerned that this is mere log clutter for (top-level) masters, where this TRUNCATE introduces no harm.
  • --init-rpl-role=slave:
    The only current purpose this setting serves is to enable semi-sync binlog truncation recovery.
    Scalability aside, I wonder whether users proactively set this as if it has a purpose beyond enabling the status variable Rpl_status.

Comment thread sql/sql_base.cc Outdated
query.append(STRING_WITH_LEN("TRUNCATE TABLE "));
static const char
QUERY_START[]= "TRUNCATE TABLE ",
QUERY_COMMENT[]= " -- auto-generated for recreating memory table";
Copy link
Copy Markdown
Contributor Author

@ParadoxV5 ParadoxV5 Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

‘auto-recreated’? ‘restarted’? 🤔

I’m concerned that “generated by server” doesn’t hint at the purpose this TRUNCATE is about.
P.S. Nor that DROP Andrei mentioned… What is it?

@ParadoxV5 ParadoxV5 self-assigned this Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MariaDB Corporation Replication Patches involved in replication

Development

Successfully merging this pull request may close these issues.

3 participants