Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-42252

Galera: after a session's first binlog write with wsrep disabled (RSU DDL or wsrep_on=OFF), its later write sets carry CRC32 trailers; receivers fail Write_rows and the originator is evicted

    XMLWordPrintable

Details

    • Q1/2027 Replic. Maintenance

    Description

      Summary

      Since precomputed binlog checksums were added (MDEV-31273, 11.4.1), each session decides only once whether its binlog caches precompute CRC32: when the cache manager is created at the session's first binlog write. The condition excludes Galera through WSREP_NNULL(thd), and that macro depends on thd->variables.wsrep_on.

      If the session's first binlog write happens with wsrep disabled for that session, the caches are built with checksum precompute ON and keep it for the life of the connection. Two triggers do this: DDL under wsrep_OSU_method=RSU (the server sets wsrep_on=0 for it), and an explicit SET SESSION wsrep_on=OFF.

      Every later replicated transaction from that session puts events with CRC32 trailers into the write set. The receivers treat the write set as checksum OFF (its Format_description event says OFF), so they read the 4 CRC bytes as row data. The originator commits with no client error. Every receiver fails Write_rows, votes, and the originator leaves the cluster.

      Expected behaviour

      A replicated transaction applies on all nodes, whatever ran earlier in the same session. Write-set events either carry no checksum or match what the Format_description event declares.

      Actual behaviour

      • The originating node commits, and the client gets no error or warning.
      • All receivers fail to apply the Write_rows_v1 event. With the lab's CRC values that means 1048, 1048, then 1062 on an empty value. The exact errors depend on the CRC bytes: an earlier run on 11.8.6 Enterprise gave 1610/171 instead.
      • The receivers vote. The originator logs Vote 0 (success) ... is inconsistent with group. Leaving cluster. and ends Inconsistent, with wsrep_cluster_size 0. The other nodes continue without the row.

      How to reproduce

      The reproduction package (attached) has the scripts and the lab outputs. Steps, on a 3-node 11.8.6 Galera cluster with default binlog settings (log_bin ON, ROW, CRC32, encrypt_binlog=OFF, binlog_legacy_event_pos=OFF):

      1. On node-1 (normal TOI):

        CREATE DATABASE schema1;
        CREATE TABLE schema1.table1 (col1 varchar(255) NOT NULL, UNIQUE KEY uk1 (col1))
          ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
        CREATE TABLE schema1.table2 (id int PRIMARY KEY, col2 varchar(255)) ENGINE=InnoDB;
        INSERT INTO schema1.table2 VALUES (1,'a@example1.com'),(2,'b@example1.com');
        

      2. Optional, to mimic a rolling schema change: on node-3, then node-2, each in its own connection, run the RSU ALTER below and disconnect.
      3. Test A, on node-1 in ONE new connection (the RSU DDL is the session's first binlogged statement):

        USE schema1;
        SET SESSION wsrep_OSU_method=RSU;
        ALTER TABLE table2 ADD INDEX idx1 (col2), ALGORITHM=INPLACE, LOCK=NONE;
        SET SESSION wsrep_OSU_method=TOI;
        INSERT INTO table1 (col1) VALUES ('20260724120000');
        

      4. Test B, a variant that does not use RSU, on node-1 in ONE new connection (after restoring the cluster):

        USE schema1;
        SET SESSION wsrep_on=OFF;
        INSERT INTO table2 VALUES (4,'d@example1.com');
        SET SESSION wsrep_on=ON;
        INSERT INTO table1 (col1) VALUES ('20260724120001');
        

      5. Check the error logs of all nodes. Node-1 is now Inconsistent.

      Both tests reproduced every time they were run in the lab. Controls that did not fail:

      • the same INSERT in a new connection after the RSU ALTER;
      • the same session with a replicated statement first (an INSERT before the RSU ALTER);
      • Test A with binlog_legacy_event_pos=ON on node-1 (set in the config file, then a restart);
      • Test A with encrypt_binlog=ON (file_key_management) on node-1 (set in the config file, then a restart).

      Evidence

      Lab, Community 11.8.6, Test A. Node-2 error log (node-3 logged the same):

      [ERROR] Slave SQL: Could not execute Write_rows_v1 event on table schema1.table1; Column 'col1' cannot be null, Error_code: 1048; Column 'col1' cannot be null, Error_code: 1048; Duplicate entry '' for key 'uk1', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log FIRST, end_log_pos 0, Internal
      [Warning] WSREP: Event 3 Write_rows_v1 apply failed: 121, seqno 38
      [Note] WSREP: Member 1(node-2) initiates vote on <uuid>:38,...
      

      Node-1:

      [ERROR] WSREP: Vote 0 (success) on <uuid>:38 is inconsistent with group. Leaving cluster.
      

      Test B gave the same errors at seqno 43, and node-1 left the cluster again.

      The receiver's GRA file for seqno 38 (GRA_*_38_v2.log, 434 bytes) shows the mismatch:

      • the Format_description event's checksum_alg byte (offset 251) is 0x00 (OFF);
      • Annotate_rows, Table_map and Write_rows each end with a 4-byte CRC32 trailer (Write_rows: 6f 27 33 75);
      • mariadb-binlog -vv --base64-output=DECODE-ROWS decodes row 1 = '20260724120000', then 4 more rows with @1=NULL (the CRC bytes), Number of rows: 5.

      The production incident (Enterprise 11.8.6, Galera 26.4.26) had the same receiver error sequence (1048, 1048, 1062 on '', apply failed: 121), the originator logged "Vote 0 (success) ... inconsistent with group. Leaving cluster.", and its GRA file showed the same FDE-OFF / CRC32-trailer mismatch. The trigger there was a rolling RSU ALTER followed by an INSERT on the same connection.

      Analysis

      sql/log.cc @ mariadb-11.8.6, lines 6479-6493:

        /*
          Don't attempt to precompute checksums if:
           - Disabled by user request, --binlog-legacy-event-pos
           - Binlog is encrypted, cannot use precomputed checksums
           - WSREP/Galera.
        */
        bool precompute_checksums=
          !WSREP_NNULL(thd) && !encrypt_binlog && !opt_binlog_legacy_event_pos;
        cache_mngr= new (cache_mngr)
                binlog_cache_mngr(..., precompute_checksums);
      

      sql/wsrep_on.h @ mariadb-11.8.6:

      #define WSREP_NNULL(thd) \
        (WSREP_PROVIDER_EXISTS_ && thd->variables.wsrep_on)
      

      binlog_cache_data keeps the flag (sql/log_cache.h:44-56, :122, :319) and uses it to choose checksum_opt.

      The cache manager is created once per THD, at the first binlog write, and is not rebuilt. So the Galera exclusion holds only if wsrep_on is 1 at that moment. RSU DDL runs with wsrep_on=0, and so does an explicit SET SESSION wsrep_on=OFF. Either one as the first binlog write leaves the session precomputing checksums for good.

      All four controls agree with this condition: a new THD, wsrep_on=1 at the first write, the legacy option, and encryption. 11.8.9 has the same condition in its source (read in an earlier analysis of this case; not tested).

      Suggested fix

      Do not depend on the session's wsrep_on at cache creation. Some options:

      • exclude precomputation whenever a wsrep provider is loaded (WSREP_PROVIDER_EXISTS_ / WSREP_ON, not the session variable);
      • or re-check and reset the caches' checksum mode at transaction start, or when wsrep_on changes for the session;
      • and/or make the write set's Format_description event match the checksum actually used.

      Related issues

      • MDEV-31273 (Optimize write to binlog, 11.4.1): added precompute_checksums, with the per-session Galera exclusion that fails here.
      • MENT-2620: backport of MDEV-31273 to 10.6-ES. Whether that branch is affected was not tested.

      Workarounds

      Each of these avoided the failure in the lab:

      • Run RSU DDL (or any wsrep_on=OFF work) in a dedicated connection, and close it before any replicated write.
      • binlog_legacy_event_pos=ON on all nodes (the server help text warns it "can hurt binlog scalability"). Tested only by setting it in the config file and restarting. Whether SET GLOBAL without a restart protects new sessions was not tested.
      • encrypt_binlog=ON (tested on the originator only).

      Attachments

        Activity

          People

            seppo Seppo Jaakola
            claudio.nanni Claudio Nanni
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.