Issues stale=false view queries to determine when view indexing is complete. Retries on timeout
(ctx context.Context, viewStore sgbucket.ViewStore, bucketName string, ddocName string, viewName string)
| 677 | |
| 678 | // Issues stale=false view queries to determine when view indexing is complete. Retries on timeout |
| 679 | func waitForViewIndexing(ctx context.Context, viewStore sgbucket.ViewStore, bucketName string, ddocName string, viewName string) error { |
| 680 | opts := map[string]interface{}{"stale": false, "key": fmt.Sprintf("view_%s_ready_check", viewName), "limit": 1} |
| 681 | |
| 682 | // Not using standard retry loop here, because we want to retry indefinitely on view timeout (since view indexing could potentially take hours), and |
| 683 | // we don't need to sleep between attempts. Using manual exponential backoff retry processing for non-timeout related errors, waits up to ~5 min |
| 684 | errRetryCount := 0 |
| 685 | retrySleep := float64(100) |
| 686 | maxRetry := 18 |
| 687 | for { |
| 688 | results, err := viewStore.ViewQuery(ctx, ddocName, viewName, opts) |
| 689 | if results != nil { |
| 690 | _ = results.Close() |
| 691 | } |
| 692 | if err == nil { |
| 693 | return nil |
| 694 | } |
| 695 | |
| 696 | // Retry on timeout or undefined view errors , otherwise return the error |
| 697 | if err == base.ErrViewTimeoutError { |
| 698 | base.InfofCtx(ctx, base.KeyAll, "Timeout waiting for view %q to be ready for bucket %q - retrying...", viewName, base.UD(bucketName)) |
| 699 | } else { |
| 700 | // For any other error, retry up to maxRetry, to wait for view initialization on the server |
| 701 | errRetryCount++ |
| 702 | if errRetryCount > maxRetry { |
| 703 | return err |
| 704 | } |
| 705 | base.WarnfCtx(ctx, "Error waiting for view %q to be ready for bucket %q - retrying...(%d/%d)", viewName, bucketName, errRetryCount, maxRetry) |
| 706 | time.Sleep(time.Duration(retrySleep) * time.Millisecond) |
| 707 | retrySleep *= float64(1.5) |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | } |
| 712 | |
| 713 | func removeObsoleteDesignDocs(ctx context.Context, viewStore sgbucket.ViewStore, previewOnly bool, useViews bool) (removedDesignDocs []string, err error) { |
| 714 |