xndai opened a new issue, #17358:
URL: https://github.com/apache/iceberg/issues/17358

   ### Apache Iceberg version
   
   1.11.0 (latest release)
   
   ### Query engine
   
   None
   
   ### Please describe the bug 🐞
   
   `SnapshotUtil.nullableSnapshotIdAsOfTime()` finds the time-travel snapshot 
by iterating snapshot-log and returning the last entry with timestampMillis <= 
requested. This implicitly assumes entries are in strictly ascending time order.
   However:
     - The spec does not mandate ordering of snapshot-log entries 
     - TableMetadata only validates ordering with a 1-minute clock-skew 
tolerance (line 365), meaning entries within that window can be in reverse order
     - In the reverse-order case, the loop may return the wrong snapshot — an 
earlier entry that happens to appear later in the list 
     
     Fix: Instead of relying on iteration order, find the entry with the 
maximum timestamp that is still <= requestedTimestamp. Something like:
   
     for (HistoryEntry logEntry : table.history()) {
         if (logEntry.timestampMillis() <= timestampMillis) {
             if (snapshotId == null || logEntry.timestampMillis() > 
bestTimestamp) {
                 snapshotId = logEntry.snapshotId();
                 bestTimestamp = logEntry.timestampMillis();
             }
         }
     }
   
     This makes the behavior correct regardless of entry ordering.
   
   ### Willingness to contribute
   
   - [x] I can contribute a fix for this bug independently
   - [ ] I would be willing to contribute a fix for this bug with guidance from 
the Iceberg community
   - [ ] I cannot contribute a fix for this bug at this time


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to