mirror of
https://github.com/restic/restic.git
synced 2025-10-29 13:08:45 +00:00
Update vendored library cloud.google.com/go
This commit is contained in:
135
vendor/cloud.google.com/go/pubsub/service.go
generated
vendored
135
vendor/cloud.google.com/go/pubsub/service.go
generated
vendored
@@ -61,104 +61,6 @@ func trunc32(i int64) int32 {
|
||||
return int32(i)
|
||||
}
|
||||
|
||||
// func newStreamingPuller(ctx context.Context, subc *vkit.SubscriberClient, subName string, ackDeadlineSecs int32) *streamingPuller {
|
||||
// p := &streamingPuller{
|
||||
// ctx: ctx,
|
||||
// subName: subName,
|
||||
// ackDeadlineSecs: ackDeadlineSecs,
|
||||
// subc: subc,
|
||||
// }
|
||||
// p.c = sync.NewCond(&p.mu)
|
||||
// return p
|
||||
// }
|
||||
|
||||
// type streamingPuller struct {
|
||||
// ctx context.Context
|
||||
// subName string
|
||||
// ackDeadlineSecs int32
|
||||
// subc *vkit.SubscriberClient
|
||||
|
||||
// mu sync.Mutex
|
||||
// c *sync.Cond
|
||||
// inFlight bool
|
||||
// closed bool // set after CloseSend called
|
||||
// spc pb.Subscriber_StreamingPullClient
|
||||
// err error
|
||||
// }
|
||||
|
||||
// // open establishes (or re-establishes) a stream for pulling messages.
|
||||
// // It takes care that only one RPC is in flight at a time.
|
||||
// func (p *streamingPuller) open() error {
|
||||
// p.c.L.Lock()
|
||||
// defer p.c.L.Unlock()
|
||||
// p.openLocked()
|
||||
// return p.err
|
||||
// }
|
||||
|
||||
// func (p *streamingPuller) openLocked() {
|
||||
// if p.inFlight {
|
||||
// // Another goroutine is opening; wait for it.
|
||||
// for p.inFlight {
|
||||
// p.c.Wait()
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
// // No opens in flight; start one.
|
||||
// // Keep the lock held, to avoid a race where we
|
||||
// // close the old stream while opening a new one.
|
||||
// p.inFlight = true
|
||||
// spc, err := p.subc.StreamingPull(p.ctx, gax.WithGRPCOptions(grpc.MaxCallRecvMsgSize(maxSendRecvBytes)))
|
||||
// if err == nil {
|
||||
// err = spc.Send(&pb.StreamingPullRequest{
|
||||
// Subscription: p.subName,
|
||||
// StreamAckDeadlineSeconds: p.ackDeadlineSecs,
|
||||
// })
|
||||
// }
|
||||
// p.spc = spc
|
||||
// p.err = err
|
||||
// p.inFlight = false
|
||||
// p.c.Broadcast()
|
||||
// }
|
||||
|
||||
// func (p *streamingPuller) call(f func(pb.Subscriber_StreamingPullClient) error) error {
|
||||
// p.c.L.Lock()
|
||||
// defer p.c.L.Unlock()
|
||||
// // Wait for an open in flight.
|
||||
// for p.inFlight {
|
||||
// p.c.Wait()
|
||||
// }
|
||||
// var err error
|
||||
// var bo gax.Backoff
|
||||
// for {
|
||||
// select {
|
||||
// case <-p.ctx.Done():
|
||||
// p.err = p.ctx.Err()
|
||||
// default:
|
||||
// }
|
||||
// if p.err != nil {
|
||||
// return p.err
|
||||
// }
|
||||
// spc := p.spc
|
||||
// // Do not call f with the lock held. Only one goroutine calls Send
|
||||
// // (streamingMessageIterator.sender) and only one calls Recv
|
||||
// // (streamingMessageIterator.receiver). If we locked, then a
|
||||
// // blocked Recv would prevent a Send from happening.
|
||||
// p.c.L.Unlock()
|
||||
// err = f(spc)
|
||||
// p.c.L.Lock()
|
||||
// if !p.closed && err != nil && isRetryable(err) {
|
||||
// // Sleep with exponential backoff. Normally we wouldn't hold the lock while sleeping,
|
||||
// // but here it can't do any harm, since the stream is broken anyway.
|
||||
// gax.Sleep(p.ctx, bo.Pause())
|
||||
// p.openLocked()
|
||||
// continue
|
||||
// }
|
||||
// // Not an error, or not a retryable error; stop retrying.
|
||||
// p.err = err
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
|
||||
// Logic from https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/StatusUtil.java.
|
||||
func isRetryable(err error) bool {
|
||||
s, ok := status.FromError(err)
|
||||
@@ -175,43 +77,6 @@ func isRetryable(err error) bool {
|
||||
}
|
||||
}
|
||||
|
||||
// func (p *streamingPuller) fetchMessages() ([]*Message, error) {
|
||||
// var res *pb.StreamingPullResponse
|
||||
// err := p.call(func(spc pb.Subscriber_StreamingPullClient) error {
|
||||
// var err error
|
||||
// res, err = spc.Recv()
|
||||
// return err
|
||||
// })
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return convertMessages(res.ReceivedMessages)
|
||||
// }
|
||||
|
||||
// func (p *streamingPuller) send(req *pb.StreamingPullRequest) error {
|
||||
// // Note: len(modAckIDs) == len(modSecs)
|
||||
// var rest *pb.StreamingPullRequest
|
||||
// for len(req.AckIds) > 0 || len(req.ModifyDeadlineAckIds) > 0 {
|
||||
// req, rest = splitRequest(req, maxPayload)
|
||||
// err := p.call(func(spc pb.Subscriber_StreamingPullClient) error {
|
||||
// x := spc.Send(req)
|
||||
// return x
|
||||
// })
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// req = rest
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// func (p *streamingPuller) closeSend() {
|
||||
// p.mu.Lock()
|
||||
// p.closed = true
|
||||
// p.spc.CloseSend()
|
||||
// p.mu.Unlock()
|
||||
// }
|
||||
|
||||
// Split req into a prefix that is smaller than maxSize, and a remainder.
|
||||
func splitRequest(req *pb.StreamingPullRequest, maxSize int) (prefix, remainder *pb.StreamingPullRequest) {
|
||||
const int32Bytes = 4
|
||||
|
||||
Reference in New Issue
Block a user