hcrosse commented on code in PR #2784:
URL: https://github.com/apache/iceberg-go/pull/2784#discussion_r4764019059


##########
table/compaction/compaction.go:
##########
@@ -65,8 +66,8 @@ type Config struct {
        DeleteRatioThreshold float64
 
        // PackingLookback controls how many open bins the packer considers
-       // before evicting. Higher values produce better packing at the cost
-       // of memory. Default: DefaultPackingLookback.
+       // before evicting. Must be at least 1. Higher values produce better
+       // packing at the cost of memory. Default: DefaultPackingLookback.

Review Comment:
   Thanks for the review. Updated the comment to `DefaultConfig sets 
DefaultPackingLookback`.



##########
table/compaction/compaction.go:
##########
@@ -171,6 +172,12 @@ func (cfg Config) Validate() error {
                return fmt.Errorf("max group size (%d) must be zero or at least 
the target file size (%d)",
                        cfg.MaxGroupSizeBytes, cfg.TargetFileSizeBytes)
        }
+       if cfg.PackingLookback == 0 {
+               return fmt.Errorf("packing lookback must be >= 1, got %d", 
cfg.PackingLookback)
+       }
+       if cfg.PackingLookback > math.MaxInt {
+               return fmt.Errorf("packing lookback (%d) exceeds max int (%d)", 
cfg.PackingLookback, math.MaxInt)

Review Comment:
   Changed the error to `packing lookback must be <= %d, got %d` and updated 
both test assertions.



##########
table/compaction/compaction_test.go:
##########
@@ -249,6 +264,43 @@ func TestConfig_Validate(t *testing.T) {
        }
 }
 
+func TestPlanCompaction_InvalidPackingLookback(t *testing.T) {
+       newCfg := func(lookback uint) compaction.Config {
+               return compaction.Config{
+                       TargetFileSizeBytes: 100 * 1024 * 1024,
+                       MinFileSizeBytes:    75 * 1024 * 1024,
+                       MaxFileSizeBytes:    180 * 1024 * 1024,
+                       MinInputFiles:       2,
+                       DeleteFileThreshold: 5,
+                       PackingLookback:     lookback,
+               }
+       }
+       tasks := make([]table.FileScanTask, 0, 4)
+       for i := range 4 {
+               tasks = append(tasks, 
makeTask(newDataFile(fmt.Sprintf("file-%d.parquet", i), 10), 0, 0))
+       }
+
+       t.Run("zero lookback", func(t *testing.T) {
+               _, err := newCfg(0).PlanCompaction(tasks)
+               require.Error(t, err)
+               assert.Contains(t, err.Error(), "packing lookback must be >= 1")
+       })
+
+       t.Run("lookback above max int", func(t *testing.T) {
+               _, err := newCfg(math.MaxInt + 1).PlanCompaction(tasks)
+               require.Error(t, err)
+               assert.Contains(t, err.Error(), "exceeds max int")
+       })
+
+       t.Run("minimum lookback packs every candidate", func(t *testing.T) {

Review Comment:
   Bumped the four test files to 40 MiB each so lookback 1 evicts the first bin 
(`len(bins) == 2`) and returns two groups of two.



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