Copilot commented on code in PR #2673:
URL: https://github.com/apache/iceberg-go/pull/2673#discussion_r4646774948


##########
table/mor_delete_conflict_test.go:
##########
@@ -198,3 +203,166 @@ func 
TestMergeOnReadDeleteOfDataFileAddedInSameTransaction(t *testing.T) {
 
        require.Equal(t, []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12}, 
idsInTable(t, tbl))
 }
+
+type failPuffinOpenIO struct{ iceio.LocalFS }
+
+func (f failPuffinOpenIO) Open(ctx context.Context, name string) (iceio.File, 
error) {
+       if strings.HasSuffix(name, ".puffin") {
+               return nil, errors.New("puffin read failed")
+       }
+
+       return f.LocalFS.Open(ctx, name)
+}
+
+func deleteScanGoroutines() (scan, sequencer int) {
+       var b strings.Builder
+       _ = pprof.Lookup("goroutine").WriteTo(&b, 2)
+       for g := range strings.SplitSeq(b.String(), "\n\n") {
+               if strings.Contains(g, "makePositionDeleteRecordsForFilter") {
+                       scan++
+               }
+               if strings.Contains(g, "MakeSequencedChanWithDiscard") {
+                       sequencer++
+               }
+       }

Review Comment:
   The error from `WriteTo` is ignored, which can silently turn failures into 
`0` counts and make these regression tests produce false positives. Consider 
returning an `(int, int, error)` from `deleteScanGoroutines` (or passing `t 
*testing.T` in) and failing the test if `WriteTo` returns an error.



##########
table/mor_delete_conflict_test.go:
##########
@@ -198,3 +203,166 @@ func 
TestMergeOnReadDeleteOfDataFileAddedInSameTransaction(t *testing.T) {
 
        require.Equal(t, []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12}, 
idsInTable(t, tbl))
 }
+
+type failPuffinOpenIO struct{ iceio.LocalFS }
+
+func (f failPuffinOpenIO) Open(ctx context.Context, name string) (iceio.File, 
error) {
+       if strings.HasSuffix(name, ".puffin") {
+               return nil, errors.New("puffin read failed")
+       }
+
+       return f.LocalFS.Open(ctx, name)
+}
+
+func deleteScanGoroutines() (scan, sequencer int) {
+       var b strings.Builder
+       _ = pprof.Lookup("goroutine").WriteTo(&b, 2)
+       for g := range strings.SplitSeq(b.String(), "\n\n") {
+               if strings.Contains(g, "makePositionDeleteRecordsForFilter") {
+                       scan++
+               }
+               if strings.Contains(g, "MakeSequencedChanWithDiscard") {
+                       sequencer++
+               }
+       }
+
+       return scan, sequencer
+}
+
+// A v3 merge-on-read delete whose deletion-vector read fails must not leave a
+// scan behind. Not parallel, so other tests' scans don't count.
+func TestMergeOnReadDeleteDVReadErrorStopsScan(t *testing.T) {
+       ctx := t.Context()
+       tbl := appendTenRows(t, newV3MoRConflictTestTable(t))
+       tbl, err := tbl.Delete(ctx, iceberg.EqualTo(iceberg.Reference("id"), 
int64(1)), nil)
+       require.NoError(t, err)
+
+       failing := table.New(tbl.Identifier(), tbl.Metadata(), 
tbl.MetadataLocation(),
+               func(context.Context) (iceio.IO, error) { return 
failPuffinOpenIO{}, nil }, nil)
+       scanBefore, seqBefore := deleteScanGoroutines()
+       err = failing.NewTransaction().Delete(ctx, 
iceberg.EqualTo(iceberg.Reference("id"), int64(3)), nil)
+       require.ErrorContains(t, err, "puffin read failed")
+       scanAfter, seqAfter := deleteScanGoroutines()
+       require.LessOrEqual(t, scanAfter, scanBefore)
+       require.LessOrEqual(t, seqAfter, seqBefore)

Review Comment:
   These goroutine-count assertions can be timing-sensitive: even if 
cancellation is correct, goroutines may still be unwinding when 
`deleteScanGoroutines()` is called immediately after the failing operation, 
causing test flakes. Consider using `require.Eventually` (with a short timeout) 
to wait until counts drop to the expected level before asserting.



##########
table/transaction_delete.go:
##########
@@ -1121,62 +1121,65 @@ func (t *Transaction) 
makePositionDeleteRecordsForFilter(ctx context.Context, fs
                return nil, err
        }
 
-       deletesPerFile, err := readAllDeleteFiles(ctx, fs, tasks, concurrency)
-       if err != nil {
-               // readAllDeleteFiles can return a partially-populated map 
alongside
-               // the error if some goroutines completed before the failure.
-               releasePerFilePosDeletes(deletesPerFile)
+       return func(yield func(arrow.RecordBatch, error) bool) {
+               deletesPerFile, err := readAllDeleteFiles(ctx, fs, tasks, 
concurrency)
+               if err != nil {
+                       // readAllDeleteFiles can return a partially-populated 
map alongside
+                       // the error if some goroutines completed before the 
failure.
+                       releasePerFilePosDeletes(deletesPerFile)
+                       yield(nil, err)

Review Comment:
   `yield` returns a `bool` to indicate whether iteration should continue. Even 
though you return immediately here, it’s still better to honor the iterator 
contract by checking the return value (and not calling `yield` again if it 
returns false). This makes the iterator behavior consistent with other 
sequences and avoids surprising callers that treat `yield(false)` as a hard 
stop.



-- 
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