laskoviymishka commented on code in PR #912:
URL: https://github.com/apache/iceberg-go/pull/912#discussion_r3103537658
##########
table/table.go:
##########
@@ -303,10 +326,55 @@ func (t Table) AllManifests(ctx context.Context)
iter.Seq2[iceberg.ManifestFile,
}
func (t Table) doCommit(ctx context.Context, updates []Update, reqs
[]Requirement) (*Table, error) {
- newMeta, newLoc, err := t.cat.CommitTable(ctx, t.identifier, reqs,
updates)
+ cfg := readRetryConfig(t.metadata.Properties())
+
+ // Bound total retry time with a derived context so both the wait loop
+ // and the CommitTable call itself respect the deadline uniformly.
+ retryCtx, cancel := context.WithTimeout(ctx,
time.Duration(cfg.totalTimeoutMs)*time.Millisecond)
+ defer cancel()
+
+ var (
+ newMeta Metadata
+ newLoc string
+ err error
+ )
+
+ for attempt := 0; attempt <= cfg.numRetries; attempt++ {
+ if retryCtx.Err() != nil {
+ return nil, context.Cause(retryCtx)
+ }
+
+ newMeta, newLoc, err = t.cat.CommitTable(retryCtx,
t.identifier, reqs, updates)
+ if err == nil {
+ break
+ }
+
+ // Only retry on retryable commit conflicts. Unknown-state
errors
+ // (5xx, gateway timeouts) must NOT be retried because the
commit
+ // may have actually succeeded — retrying could duplicate work.
+ if !errors.Is(err, ErrCommitFailed) {
+ return nil, err
+ }
+
+ if attempt == cfg.numRetries {
+ break
+ }
+
+ wait := backoffDuration(attempt, cfg.minWaitMs, cfg.maxWaitMs)
+ timer := time.NewTimer(wait)
+ select {
+ case <-retryCtx.Done():
+ timer.Stop()
+
+ return nil, context.Cause(retryCtx)
+ case <-timer.C:
+ }
Review Comment:
thanks, the loop does read more naturally.
--
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]