Skip to content

HubSpot Edit (not yet upstreamed): Preserve WAL edit order - #215

Merged
hgromer merged 5 commits into
hubspot-2.6from
preserve-wal-edit-order
Nov 7, 2025
Merged

hgromer merged 5 commits into
hubspot-2.6from
preserve-wal-edit-order

Conversation

@hgromer

@hgromer hgromer commented Nov 6, 2025

Copy link
Copy Markdown
Collaborator

We've discovered that inter-put edits lose their ordering when we convert WAL files to HFiles using a MR job. The reducer doesn't provide any ordering guarantees of the values being sorted lexigraphically. That means if the client does

Put put = new Put(row);
put.setColumnValue(CF, QF, "aaa", 123L);
put.setColumnValue(CF, QF, "zzz", 123L);
client.put(put);

Even though their "latest" edit for CF + CQ is "zzz", a snapshot scan over an incremental backup (and if we restore the table prior to the next full backup) will return "aaa". When you query HBase, though, it returns "aaa".

This PR aims to address this problem by encoding the ordering into the cell value. This has been branch-deployed and has resolved data inconsistencies when comparing snapshot scans from a full backup vs a modern backup

}

private MapReduceExtendedCell wrapCell(ExtendedCell cell, int order) {
if (this.diskBasedSortingEnabled) {

@hgromer hgromer Nov 6, 2025 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This check here (and in other places in the code) ensures this order preservation is only on for incremental backup. That being said -- I wonder if we also want to think about implementing for our WAL replay logic in the restore process

Comment on lines +39 to +40
TreeSet<OrderPreservedMapReduceExtendedCell> cells =
new TreeSet<>(Comparator.comparingInt(OrderPreservedMapReduceExtendedCell::getOrder));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I was looking through the code with claude, and it reckons multiple cells with the same timestamp could get erroneously deduplicated here. I'm not sure — something to investigate before we ship. It recommended something like this instead:

  TreeSet<OrderPreservedMapReduceExtendedCell> cells = new TreeSet<>(
    Comparator.<OrderPreservedMapReduceExtendedCell>comparingInt(
      OrderPreservedMapReduceExtendedCell::getOrder)
    .thenComparingLong(OrderPreservedMapReduceExtendedCell::getSequenceId)
    .thenComparing(CellComparator.getInstance())
  );

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is a good point - I can switch off of using a Set

@hgromer
hgromer requested a review from rmdmattingly November 6, 2025 21:20
Hernan Gelaf-Romer added 2 commits November 6, 2025 16:37

for (OrderPreservedMapReduceExtendedCell cell : values) {
OrderPreservedMapReduceExtendedCell copy =
new OrderPreservedMapReduceExtendedCell(cell.deepClone(), cell.getOrder());

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We need to deep clone now b/c the Iterator can re-use these values

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.

2 participants