cancel signals that an acquiree no longer wants clearance to query. Any error returned is a serious internal error indicating that integrity of the internal state is corrupted by a code bug.
(dk dKey, clearance chan<- struct{})
| 198 | // cancel signals that an acquiree no longer wants clearance to query. Any error returned is a serious internal error |
| 199 | // indicating that integrity of the internal state is corrupted by a code bug. |
| 200 | func (a *Acquirer) cancel(dk dKey, clearance chan<- struct{}) error { |
| 201 | a.mu.Lock() |
| 202 | defer a.mu.Unlock() |
| 203 | d, ok := a.q[dk] |
| 204 | if !ok { |
| 205 | // this is a code error, as something removed the domain early, or cancel |
| 206 | // was called twice. |
| 207 | err := xerrors.New("cancel for domain that doesn't exist") |
| 208 | a.logger.Critical(a.ctx, "internal error", slog.Error(err)) |
| 209 | return err |
| 210 | } |
| 211 | w, ok := d.acquirees[clearance] |
| 212 | if !ok { |
| 213 | // this is a code error, as something removed the acquiree early, or cancel |
| 214 | // was called twice. |
| 215 | err := xerrors.New("cancel for an acquiree that doesn't exist") |
| 216 | a.logger.Critical(a.ctx, "internal error", slog.Error(err)) |
| 217 | return err |
| 218 | } |
| 219 | delete(d.acquirees, clearance) |
| 220 | if w.inProgress && len(d.acquirees) > 0 { |
| 221 | // this one canceled before querying, so give another acquiree a chance |
| 222 | // instead |
| 223 | for _, other := range d.acquirees { |
| 224 | if other.inProgress { |
| 225 | err := xerrors.New("more than one acquiree in progress for same key") |
| 226 | a.logger.Critical(a.ctx, "internal error", slog.Error(err)) |
| 227 | return err |
| 228 | } |
| 229 | other.inProgress = true |
| 230 | other.clearance <- struct{}{} |
| 231 | break // just one |
| 232 | } |
| 233 | } |
| 234 | if len(d.acquirees) == 0 { |
| 235 | d.cancel() |
| 236 | delete(a.q, dk) |
| 237 | } |
| 238 | return nil |
| 239 | } |
| 240 | |
| 241 | // done signals that the acquiree has completed acquiring a job (usually successfully, but we also get this call if |
| 242 | // there is a database error other than ErrNoRows). Any error returned is a serious internal error indicating that |