117
opts []grpc.CallOption,
118
) (Res, error),
120
>
// capture trailer
121
>
var trailer metadata.MD
122
>
opts = append(slices.Clone(opts), grpc.Trailer(&trailer))
123
>
124
>
// get current idea of partition counts. if missing from the cache, this will send zeros
125
>
// for counts, which the server will always accept as not-stale.
126
>
pc := cache.lookup(pkey)
127
>
128
>
for attempt := 0; ; attempt++ {
129
>
res, err := op(pc.appendToOutgoingContext(ctx), pc, request, opts)
130
>
131
>
// update cache on trailer on both success and error. if the trailer has no data,
132
>
// this removes the key from the cache.
133
>
newPc, parseErr := parsePartitionCountsFromTrailer(trailer)
134
>
trailer = nil
135
>
if parseErr != nil {
136
logger.Info("partition count trailer parse error", tag.Error(parseErr))
137
// continue with zero value for newPc
138
}
140
cache.put(pkey, newPc)
141
pc = newPc
142
}
143
144
>
if _, ok := errors.AsType[*serviceerrors.StalePartitionCounts](err); ok && attempt == 0 {
partition_counts.go
145
// if we got a StalePartitionCounts on the first attempt, retry once
146
continue
147
}
148
150
}
151
}