getQueryChecker returns an ephemeral query checker from indices 1+. Uses request affinity, then file affinity, then finds/creates. Blocks on querySem if all query slots are in use.
(ctx context.Context, requestID string, file *ast.SourceFile)
| 250 | // Uses request affinity, then file affinity, then finds/creates. |
| 251 | // Blocks on querySem if all query slots are in use. |
| 252 | func (p *checkerPool) getQueryChecker(ctx context.Context, requestID string, file *ast.SourceFile) (*checker.Checker, func()) { |
| 253 | if c, release, ok := p.tryReacquireForRequest(requestID, p.querySem, false); ok { |
| 254 | return c, release |
| 255 | } |
| 256 | |
| 257 | // Token consumed — proceed with normal acquisition. |
| 258 | p.mu.Lock() |
| 259 | defer p.mu.Unlock() |
| 260 | |
| 261 | // Try file affinity. |
| 262 | if file != nil { |
| 263 | if index, ok := p.fileAssociations[file]; ok && index > 0 { |
| 264 | if c := p.checkers[index]; c != nil && p.heldBy[index] == "" { |
| 265 | p.heldBy[index] = holdTag(requestID) |
| 266 | if requestID != "" { |
| 267 | if _, alreadyRegistered := p.requestAssociations[requestID]; !alreadyRegistered { |
| 268 | p.requestAssociations[requestID] = index |
| 269 | p.registerRequestCleanup(ctx, requestID) |
| 270 | } |
| 271 | } |
| 272 | return c, p.createRelease(requestID, index, c) |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | // Find any available query checker or create one. |
| 278 | c, index := p.findOrCreateQueryCheckerLocked() |
| 279 | p.heldBy[index] = holdTag(requestID) |
| 280 | p.log(fmt.Sprintf("checkerpool: Acquired query checker %d for request %s", index, holdTag(requestID))) |
| 281 | if requestID != "" { |
| 282 | if _, alreadyRegistered := p.requestAssociations[requestID]; !alreadyRegistered { |
| 283 | p.requestAssociations[requestID] = index |
| 284 | p.registerRequestCleanup(ctx, requestID) |
| 285 | } |
| 286 | } |
| 287 | if file != nil { |
| 288 | p.fileAssociations[file] = index |
| 289 | } |
| 290 | return c, p.createRelease(requestID, index, c) |
| 291 | } |
| 292 | |
| 293 | // findOrCreateQueryCheckerLocked returns an idle query checker or creates one |
| 294 | // in the first empty slot. The semaphore guarantees at least one slot is |
no test coverage detected