iceberg icon indicating copy to clipboard operation
iceberg copied to clipboard

CreateSnapshotEvent / CommitReport are sent prematurely when using a Transaction

Open nastra opened this issue 3 years ago • 2 comments

Apache Iceberg version

1.2.0 (latest release)

Query engine

None

Please describe the bug 🐞

Currently, a CreateSnapshotEvent or a CommitReport are both sent in SnapshotProducer#notifyListeners() right after commit was successful.

However, when using a TX, that commit is only staged and only committed when the TX itself commits. This results in premature sending of CreateSnapshotEvent / CommitReport for a table that potentially won't be committed.

This can be reproduced by adding this to TestCreateSnapshotEvent

  @Test
  public void snapshotEventAvailableAfterTransactionCommit() {
    Transaction transaction = table.newTransaction();
    transaction.newAppend().appendFile(FILE_A).commit();

    // the event should only be available after the TX was committed
    Assertions.assertThat(currentEvent).isNull();

    transaction.commitTransaction();
    Assertions.assertThat(currentEvent).isNotNull();
  }

and this to TestCommitReporting

  @Test
  public void commitReportAvailableAfterTransactionCommit() {
    String tableName = "reporting-inside-tx";
    Table table =
        TestTables.create(
            tableDir, tableName, SCHEMA, SPEC, SortOrder.unsorted(), formatVersion, reporter);

    Transaction transaction = table.newTransaction();
    transaction.newAppend().appendFile(FILE_A).commit();

    assertThat(reporter.lastCommitReport()).isNull();

    // commit report should only be available after the TX was committed
    transaction.commitTransaction();

    CommitReport report = reporter.lastCommitReport();
    assertThat(report).isNotNull();
    assertThat(report.operation()).isEqualTo("append");
    assertThat(report.snapshotId()).isEqualTo(1L);
    assertThat(report.sequenceNumber()).isEqualTo(1L);
    assertThat(report.tableName()).isEqualTo(tableName);
  }

nastra avatar Apr 04 '23 10:04 nastra

This issue has been automatically marked as stale because it has been open for 180 days with no activity. It will be closed in next 14 days if no further activity occurs. To permanently prevent this issue from being considered stale, add the label 'not-stale', but commenting on the issue is preferred when possible.

github-actions[bot] avatar Oct 02 '23 00:10 github-actions[bot]

I'd like to work on this. My plan is for snapshot producers created by a transaction to skip notifying listeners in their own commit(), and for BaseTransaction.commitTransaction() to notify them once the transaction has committed. That covers create and replace transactions too, and it stops the event and report from being sent again each time a retried transaction re-applies its updates. CatalogTests#testCatalogWithCustomMetricsReporter currently counts the report from create/replace transactions that are never committed, so that test would commit them first. Does that sound right? cc @nastra

binarybrain-009 avatar Oct 20 '26 05:10 binarybrain-009