Commit ce75a20
committed
fix(chroma): stop the client cache invalidating on its own writes
ChromaBackend._client caches a PersistentClient per palace and keys the
cache on chroma.sqlite3's (inode, mtime) so that a write by another
process forces a rebuild rather than serving a stale HNSW segment.
Constructing a PersistentClient writes to chroma.sqlite3, and so do the
collection opens that follow it. The stamp was taken immediately after
the constructor, so it was already behind by the time the surrounding
operation finished its own writes, and the next _client() call read that
footprint as an external change.
A search opens mempalace_drawers and then mempalace_closets, so the
first open moved the mtime the second one checked and the cache missed
on essentially every request. Each miss rebuilt the client and reloaded
both HNSW segments, and the client being displaced was overwritten in
the dict without being closed, so its native index allocation
(max_elements * size_data_per_element, ~440 MB per collection on a 165k
vector palace) was never released.
Re-baseline the stat once the backend's own operation completes, so the
recorded value means "chroma.sqlite3 as this backend last left it" and a
later difference is genuinely somebody else's write. Cover writes made
through ChromaCollection as well, via its existing _write_lock context
manager, so the file-a-drawer-then-search cycle stops reloading the
index. Close the displaced client on the rebuild path.
An external write that lands while one of our own operations is in
flight is folded into the new stamp and picked up on the next change.
mtime cannot distinguish writers on its own, and PRAGMA data_version
does not help: it reports writes by any other connection, and chromadb's
connection is foreign to a probe connection, so our own opens would
register as external there too.
Eight searches against the same palace, HTTP transport:
before 951 MB -> 3522 MB
after 940 MB -> 965 MB1 parent 517a7a0 commit ce75a20
3 files changed
Lines changed: 242 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1595 | 1595 | | |
1596 | 1596 | | |
1597 | 1597 | | |
1598 | | - | |
| 1598 | + | |
1599 | 1599 | | |
1600 | 1600 | | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
1601 | 1605 | | |
1602 | 1606 | | |
1603 | 1607 | | |
1604 | 1608 | | |
1605 | 1609 | | |
1606 | 1610 | | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
1607 | 1619 | | |
1608 | 1620 | | |
1609 | 1621 | | |
| |||
1612 | 1624 | | |
1613 | 1625 | | |
1614 | 1626 | | |
1615 | | - | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
1616 | 1632 | | |
1617 | 1633 | | |
1618 | 1634 | | |
| |||
2327 | 2343 | | |
2328 | 2344 | | |
2329 | 2345 | | |
| 2346 | + | |
| 2347 | + | |
| 2348 | + | |
| 2349 | + | |
| 2350 | + | |
| 2351 | + | |
| 2352 | + | |
| 2353 | + | |
| 2354 | + | |
| 2355 | + | |
| 2356 | + | |
| 2357 | + | |
2330 | 2358 | | |
2331 | 2359 | | |
2332 | 2360 | | |
| |||
2336 | 2364 | | |
2337 | 2365 | | |
2338 | 2366 | | |
| 2367 | + | |
| 2368 | + | |
| 2369 | + | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
| 2376 | + | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + | |
| 2380 | + | |
| 2381 | + | |
| 2382 | + | |
| 2383 | + | |
| 2384 | + | |
| 2385 | + | |
| 2386 | + | |
| 2387 | + | |
| 2388 | + | |
| 2389 | + | |
| 2390 | + | |
| 2391 | + | |
| 2392 | + | |
| 2393 | + | |
| 2394 | + | |
| 2395 | + | |
| 2396 | + | |
| 2397 | + | |
| 2398 | + | |
| 2399 | + | |
| 2400 | + | |
2339 | 2401 | | |
2340 | 2402 | | |
2341 | 2403 | | |
| |||
2476 | 2538 | | |
2477 | 2539 | | |
2478 | 2540 | | |
2479 | | - | |
| 2541 | + | |
| 2542 | + | |
| 2543 | + | |
| 2544 | + | |
| 2545 | + | |
2480 | 2546 | | |
2481 | 2547 | | |
2482 | 2548 | | |
| |||
2538 | 2604 | | |
2539 | 2605 | | |
2540 | 2606 | | |
| 2607 | + | |
2541 | 2608 | | |
2542 | 2609 | | |
2543 | 2610 | | |
| |||
2550 | 2617 | | |
2551 | 2618 | | |
2552 | 2619 | | |
2553 | | - | |
| 2620 | + | |
| 2621 | + | |
2554 | 2622 | | |
2555 | 2623 | | |
2556 | 2624 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
455 | 456 | | |
456 | 457 | | |
457 | 458 | | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
458 | 627 | | |
459 | 628 | | |
460 | 629 | | |
| |||
0 commit comments