Lease storage counts active leases per scope in the database #115

Open
opened 2026-10-31 12:42:09 -04:00 by claude · 0 comments
Owner
  • Draft: PQ-37
  • Priority: high (source of the leases-over-time chart)
  • Agent: storage-coder
  • Depends on: none
  • Decisions: Q-PQ-12

Why

ILeaseRepository can count all leases or one scope's leases (src/dotnet/src/Ninlil.Dhcp.Data.Abstractions/Repository/ILeaseRepository.cs:117, :143), and can list active leases (:90), but cannot count active leases for every scope in one query. The writer samples this every minute, so it must not load rows.

What changes

  • ILeaseRepository.CountActiveByScopeAsync(DateTimeOffset nowUtc, CancellationToken stoppingToken) returning IReadOnlyList<ActiveLeaseCount> (ScopeName, ProtocolVersion, Count). If #58 (leases refer to their scope by id) has landed, return ScopeId instead of ScopeName.
    • "Active" uses the rule DhcpScopeStatisticsService.IsBlocking uses with state Active: not expired at nowUtc, or no expiry (DhcpScopeStatisticsService.cs:50-52, :101-103).
    • One GROUP BY in EF; one aggregation pipeline in MongoDB.
  • EF and Mongo implementations. Add an index only if the benchmark below shows a scan that a new index removes; if so, one migration per provider.
  • A benchmark method in src/dotnet/benchmarks/Ninlil.Benchmarks/Dhcp/ at Large, on every engine.

Acceptance

  • Test fails first in src/dotnet/tests/Ninlil.Dns.Data.Integration.Tests: scope A with 2 active and 1 expired lease, and scope B with 1 active lease, return counts 2 and 1. Every engine (SQLite without Docker, the rest RequiresDocker).
  • Benchmark numbers in the PR.
  • No API or option change; schema change only if the benchmark asks for an index.

Source

Owner decision 2026-10-31 (Q-PQ-12): "leases over time".

- **Draft:** PQ-37 - **Priority:** high (source of the leases-over-time chart) - **Agent:** storage-coder - **Depends on:** none - **Decisions:** Q-PQ-12 ### Why `ILeaseRepository` can count all leases or one scope's leases (`src/dotnet/src/Ninlil.Dhcp.Data.Abstractions/Repository/ILeaseRepository.cs:117`, `:143`), and can list active leases (`:90`), but cannot count active leases for every scope in one query. The writer samples this every minute, so it must not load rows. ### What changes - `ILeaseRepository.CountActiveByScopeAsync(DateTimeOffset nowUtc, CancellationToken stoppingToken)` returning `IReadOnlyList<ActiveLeaseCount>` (`ScopeName`, `ProtocolVersion`, `Count`). If #58 (leases refer to their scope by id) has landed, return `ScopeId` instead of `ScopeName`. - "Active" uses the rule `DhcpScopeStatisticsService.IsBlocking` uses with state `Active`: not expired at `nowUtc`, or no expiry (`DhcpScopeStatisticsService.cs:50-52`, `:101-103`). - One `GROUP BY` in EF; one aggregation pipeline in MongoDB. - EF and Mongo implementations. Add an index only if the benchmark below shows a scan that a new index removes; if so, one migration per provider. - A benchmark method in `src/dotnet/benchmarks/Ninlil.Benchmarks/Dhcp/` at Large, on every engine. ### Acceptance - [ ] Test fails first in `src/dotnet/tests/Ninlil.Dns.Data.Integration.Tests`: scope A with 2 active and 1 expired lease, and scope B with 1 active lease, return counts 2 and 1. Every engine (SQLite without Docker, the rest `RequiresDocker`). - [ ] Benchmark numbers in the PR. - [ ] No API or option change; schema change only if the benchmark asks for an index. ### Source Owner decision 2026-10-31 (Q-PQ-12): "leases over time".
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
lantea-one/ninlil#115
No description provided.