Commit 7cae153
fix: bound memory usage of record queries and maintenance/upgrade scans (#4171)
* fix(storage): page through storage for paginated post-filter queries
BaseRecord.query() loaded the entire record category into memory via
find_all_records whenever a post_filter was combined with limit/offset,
then applied pagination in Python. On instances with large numbers of
records (connections, credential/presentation exchanges, mediator routes)
this caused unbounded memory growth.
Page through storage in bounded batches when a post-filter is combined
with pagination, so peak memory is bounded to a single page. Unpaginated
post-filter queries retain their existing return-all-matches behavior.
Signed-off-by: Emiliano Suñé <2395873+esune@users.noreply.github.com>
* fix(connections): filter state/their_role via indexed tag query
The connection list endpoint placed the indexed `state` and `their_role`
tags into the post-filter, which forced BaseRecord.query() to scan the
entire connection category even for the common `?state=active` query.
Push these tags into the storage tag query using $or over their
equivalent RFC 160/23 values so storage can filter and paginate them
directly. Only the non-indexed `alias` and `connection_protocol` remain
as post-filters.
Signed-off-by: Emiliano Suñé <2395873+esune@users.noreply.github.com>
* fix(mediation,revocation): paginate keylist and rev-reg listings
The mediation keylist endpoint loaded every RouteRecord (mediator scale:
clients x routed keys) and the revocation registries listing loaded every
IssuerRevRegRecord, in both cases with no pagination.
Add limit/offset/order_by/descending pagination to both endpoints. For the
revocation listing, push the STATE_INIT exclusion into the indexed tag
query ($not) so storage can filter and paginate without a post-filter.
Signed-off-by: Emiliano Suñé <2395873+esune@users.noreply.github.com>
* fix(anoncreds): page through storage in revocation recovery sweeps
The auto-recovery maintenance sweeps loaded every matching event record
into memory via find_all_records for the in-progress, failed, and
completed-event scans. A backlog of events could grow these unboundedly.
Page through storage in bounded batches. Cleanup deletes per page and
advances the offset past kept records so deletions do not skip rows.
Signed-off-by: Emiliano Suñé <2395873+esune@users.noreply.github.com>
* fix(anoncreds): page cred-rev records during anoncreds upgrade
get_rev_list_upgrade_object loaded every IssuerCredRevRecord for a
registry (up to tens of thousands) into memory, and RevListUpgradeObj
retained the full list solely to derive the maximum credential
revocation id.
Page through the records to build the revocation list and track the
maximum cred_rev_id directly, storing only that integer instead of the
full record list.
Signed-off-by: Emiliano Suñé <2395873+esune@users.noreply.github.com>
* chore: apply ruff formatting
Signed-off-by: Emiliano Suñé <2395873+esune@users.noreply.github.com>
---------
Signed-off-by: Emiliano Suñé <2395873+esune@users.noreply.github.com>
Co-authored-by: Stephen Curran <swcurran@gmail.com>1 parent 829dace commit 7cae153
12 files changed
Lines changed: 544 additions & 184 deletions
File tree
- acapy_agent
- anoncreds/revocation
- auto_recovery
- tests
- connections
- tests
- messaging/models
- tests
- protocols/coordinate_mediation/v1_0
- tests
- revocation
- tests
- wallet
- tests
Lines changed: 133 additions & 90 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
| |||
413 | 417 | | |
414 | 418 | | |
415 | 419 | | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
416 | 448 | | |
417 | 449 | | |
418 | 450 | | |
| |||
433 | 465 | | |
434 | 466 | | |
435 | 467 | | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
443 | 472 | | |
444 | 473 | | |
445 | 474 | | |
| |||
504 | 533 | | |
505 | 534 | | |
506 | 535 | | |
507 | | - | |
508 | | - | |
509 | | - | |
510 | | - | |
511 | | - | |
512 | | - | |
513 | | - | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
514 | 540 | | |
515 | 541 | | |
516 | 542 | | |
| |||
539 | 565 | | |
540 | 566 | | |
541 | 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 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
542 | 631 | | |
543 | 632 | | |
544 | 633 | | |
| |||
559 | 648 | | |
560 | 649 | | |
561 | 650 | | |
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 | | - | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
636 | | - | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
637 | 664 | | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
638 | 681 | | |
639 | 682 | | |
640 | 683 | | |
| |||
0 commit comments