pvary commented on code in PR #18717:
URL: https://github.com/apache/iceberg/pull/18717#discussion_r4468699543
##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/maintenance/operator/EqualityConvertPlanner.java:
##########
@@ -366,34 +370,203 @@ private void ensureIndexCurrent(Snapshot mainSnapshot) {
}
/**
- * Returns whether the index reflects {@code mainSnapshot}.
+ * Returns the commits after the indexed snapshot that this converter did
not make, newest first,
+ * or {@code null} if the index needs a rebuild. The conversion commit of
the planned staging
+ * snapshot is not among them, as its cycle already updated the index.
*
- * <p>Planning a staging snapshot changes the index before its conversion
commit exists: its eq
- * deletes consume the entries they match and its data files are added. So
with a snapshot
- * planned, the index reflects the head only if that snapshot's conversion
commit sits directly on
- * top of the indexed snapshot. Without one, the head must be the indexed
snapshot. Any other head
- * holds commits the index never saw (external commits, rollbacks, a restore
from before a
- * conversion commit) or follows a cycle that did not commit.
- *
- * <p>After a restore, the conversion commit can come from a retry of the
planned cycle. A cycle
- * that only failed to commit leaves the same index as its retry. A rebuild
that fails part way
+ * <p>After a restore, the conversion commit can come from a retry that ran
on an index rebuilt at
+ * a later head. The restored index plus the delta then also holds the rows
the external commits
+ * added and the retry's eq deletes matched. The conversion commit deleted
those rows, so
+ * resolving them again only adds a position the DV already holds. A rebuild
that fails part way
* clears {@link #indexSnapshotId}, and the committer does not commit a
conversion on a generation
* whose update failed downstream.
*/
- private boolean indexReflects(Snapshot mainSnapshot) {
+ private List<Snapshot> externalCommitsSinceIndex(Snapshot mainSnapshot) {
if (indexSnapshotId == null) {
+ return null;
+ }
+
+ List<Snapshot> externalCommits = Lists.newArrayList();
+ boolean plannedSnapshotCommitted = false;
+ Snapshot current = mainSnapshot;
+ while (current != null && current.snapshotId() != indexSnapshotId) {
+ String committedStaging =
+
current.summary().get(EqualityConvertCommitter.COMMITTED_STAGING_SNAPSHOT_PROPERTY);
+ if (committedStaging == null) {
+ externalCommits.add(current);
+ } else if (pendingStagingSnapshotId != null
+ && Long.parseLong(committedStaging) == pendingStagingSnapshotId) {
+ plannedSnapshotCommitted = true;
+ } else {
+ return null;
+ }
+
+ current = parentOf(current);
+ }
+
+ // A null current means the walk passed the root, or an expired parent,
without reaching the
+ // indexed snapshot.
+ if (current == null || (pendingStagingSnapshotId != null &&
!plannedSnapshotCommitted)) {
+ return null;
+ }
+
+ return externalCommits;
+ }
+
+ private boolean deltaReadsMoreThanRebuild(Snapshot mainSnapshot,
List<Snapshot> externalCommits) {
+ // The manifest list counts bound the delta before any manifest is read or
any DataFile is held.
+ // A file added and removed within the range counts twice, although the
delta skips it.
+ long deltaRows = 0L;
+ for (Snapshot snapshot : externalCommits) {
+ for (ManifestFile manifest : snapshot.dataManifests(table.io())) {
+ if (Objects.equals(manifest.snapshotId(), snapshot.snapshotId())) {
+ if (!hasRowCounts(manifest)) {
+ return true;
+ }
+
+ deltaRows += manifest.addedRowsCount() + manifest.deletedRowsCount();
+ }
+ }
+ }
+
+ if (deltaRows == 0L) {
return false;
}
- if (pendingStagingSnapshotId == null) {
- return mainSnapshot.snapshotId() == indexSnapshotId;
+ long rebuildRows = 0L;
+ for (ManifestFile manifest : mainSnapshot.dataManifests(table.io())) {
+ if (!hasRowCounts(manifest)) {
+ return true;
+ }
+
+ rebuildRows += manifest.addedRowsCount() + manifest.existingRowsCount();
+ }
+
+ if (deltaRows <= rebuildRows) {
+ return false;
+ }
+
+ LOG.info(
Review Comment:
Minimally for the reindex numbers?
--
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]