Skip to content

PS-11080 fix: Spoiled logical clock information in rewritten binlog (part 3)#128

Merged
percona-ysorokin merged 1 commit into
Percona-Lab:0.2from
percona-ysorokin:sequence_number_rewrite_logic
May 26, 2026
Merged

PS-11080 fix: Spoiled logical clock information in rewritten binlog (part 3)#128
percona-ysorokin merged 1 commit into
Percona-Lab:0.2from
percona-ysorokin:sequence_number_rewrite_logic

Conversation

@percona-ysorokin
Copy link
Copy Markdown
Collaborator

https://perconadev.atlassian.net/browse/PS-11080

Implemented generic event rewriting mechanism
('binsrv::events::rewriter::rewrite()' static method) that performs the following
operations.

  • For GTID_LOG /ANONYMOUS_GTID_LOG it changes 'sequence_number' /
    'last_committed' fields in the post header and relocates the event (changes
    'next_event_position' in the common header).
  • For GTID_TAGGED_LOG it changes 'sequence_number' / 'last_committed' in the
    serializer-encoded event body, which because of the variable length encoding
    of individual elements in the archive may change its size and may require
    updating 'transaction_length' in the event body and 'event_size' in the common
    header. In addition, it also performs event relocation.
  • For every other event it simply performs event relocation.
    All these changes are performed under a special guard
    ('binsrv::events::event_updatable_view::write_proxy') which guarantees that
    the event checksum will be recalculated / added upon finalizing all field value
    updates. We also make sure that all rewritten events will have a footer with
    properly calculated checksum (event if it was not present in the original event).

The logic for updating 'sequence_number' / 'last_committed' in GTID events
is encapsulated inside ('fix_sequence_number_and_last_committed()' function).

Refactored the way how several event fields can be modified in a single run via
'event_updatable_view' with guarantee that event's checksum will be properly
recalculated. Introduced 'rewriter::generic_materialize()' template function that
accepts generic field modification functor. Also introduced two simplified helper
functions (which use the generic one underneath) for the most typical cases:

  • 'rewriter::materialize()'
  • 'rewriter::materialize_and_relocate()'

…part 3)

https://perconadev.atlassian.net/browse/PS-11080

Implemented generic event rewriting mechanism
('binsrv::events::rewriter::rewrite()' static method) that performs the following
operations.
* For GTID_LOG /ANONYMOUS_GTID_LOG it changes 'sequence_number' /
  'last_committed' fields in the post header and relocates the event (changes
  'next_event_position' in the common header).
* For GTID_TAGGED_LOG it changes 'sequence_number' / 'last_committed' in the
  serializer-encoded event body, which because of the variable length encoding
  of individual elements in the archive may change its size and may require
  updating 'transaction_length' in the event body and 'event_size' in the common
  header. In addition, it also performs event relocation.
* For every other event it simply performs event relocation.
All these changes are performed under a special guard
('binsrv::events::event_updatable_view::write_proxy') which guarantees that
the event checksum will be recalculated / added upon finalizing all field value
updates. We also make sure that all rewritten events will have a footer with
properly calculated checksum (event if it was not present in the original event).

The logic for updating 'sequence_number' /  'last_committed' in GTID events
is encapsulated inside ('fix_sequence_number_and_last_committed()' function).

Refactored the way how several event fields can be modified in a single run via
'event_updatable_view' with guarantee that event's checksum will be properly
recalculated. Introduced 'rewriter::generic_materialize()' template function that
accepts generic field modification functor. Also introduced two simplified helper
functions (which use the generic one underneath) for the most typical cases:
* 'rewriter::materialize()'
* 'rewriter::materialize_and_relocate()'

Co-authored-by: Kamil Holubicki <kamil.holubicki@percona.com>
@percona-ysorokin percona-ysorokin force-pushed the sequence_number_rewrite_logic branch from b7d3a7b to 3f4af71 Compare May 26, 2026 22:26
@percona-ysorokin percona-ysorokin merged commit 945d237 into Percona-Lab:0.2 May 26, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant