Skip to content

Conversation

@jhiemstrawisc
Copy link
Member

Summary

This PR implements a new API function lotman_get_max_mpas_for_period() that calculates the maximum cumulative Management Policy Attributes (MPAs) across all overlapping lots during a specified time period. This feature enables capacity planning and resource scheduling by allowing systems to determine peak resource allocation at any point in time. HOWEVER, this is a WIP as it currently lacks any way to actually reserve that space atomically (i.e. the info a caller gets may become stale before a reservation/new lot can be added).

Implementation Details

The implementation uses a sweep line algorithm (a classic interval scheduling solution) to efficiently compute maximum resource usage across overlapping lot lifetimes.

Key Design Decisions

  • Root Lots Only: The function only counts root lots (self-parent lots) to avoid double-counting in lot hierarchies. Child lots consume quota from their parents, so including both would incorrectly inflate capacity calculations.
  • Inclusive Time Intervals: Lot lifetimes are treated as inclusive intervals [creation_time, end_time], meaning a lot is considered active at both its start and end timestamps.
  • Flexible Endpoint Selection: The include_deletion parameter allows callers to choose whether lots are considered active until expiration_time (recommended for capacity planning) or deletion_time (for cases where expired lots still consume resources).

Comprehensive Metrics: Returns four key metrics:

  • max_dedicated_GB: Maximum cumulative dedicated storage
  • max_opportunistic_GB: Maximum cumulative opportunistic storage
  • max_combined_GB: Maximum total storage (dedicated + opportunistic)
  • max_num_objects: Maximum cumulative object count

Files Modified

  • src/lotman.h: Added public API function declaration with comprehensive documentation
  • src/lotman.cpp: Implemented public API wrapper with JSON output formatting and error handling
  • src/lotman_internal.h: Added MaxMPAResult struct and internal function declaration
  • src/lotman_internal.cpp: Implemented core sweep line algorithm with detailed inline documentation
  • test/main.cpp: Added 11 comprehensive test cases covering various scenarios including overlapping lots, hierarchies, edge cases, and error conditions

Use Case Example

This API enables questions like: "Can I create a new lot with 50GB dedicated storage from time A to time B without overcommitting resources?" by checking if max_dedicated_GB + 50GB exceeds system capacity.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements a new API function lotman_get_max_mpas_for_period() that calculates maximum cumulative Management Policy Attributes (MPAs) across overlapping lots during a specified time period using an efficient sweep line algorithm. The feature enables capacity planning by determining peak resource allocation.

Key Changes

  • Implements sweep line algorithm to find maximum overlapping resource usage across time periods
  • Only counts root lots (self-parent lots) to avoid double-counting in lot hierarchies
  • Returns comprehensive metrics: max dedicated storage, max opportunistic storage, max combined storage, and max object count
  • Provides flexible endpoint selection via include_deletion parameter

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/lotman.h Added public API function declaration with comprehensive documentation
src/lotman.cpp Implemented public API wrapper with JSON output formatting and error handling
src/lotman_internal.h Added MaxMPAResult struct and internal function declaration with algorithm documentation
src/lotman_internal.cpp Implemented core sweep line algorithm with SQL query for root lot detection and event-based sweep
test/main.cpp Added 11 comprehensive test cases covering overlapping lots, hierarchies, edge cases, and error conditions; updated default lot times to avoid test interference

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

specified period
- max_combined_GB sums over both opportunistic and dedicated storage, representing the total maximum storage
Lotman has allocated to lots during the specified period
- max_opportunistic_GB and max_combined_GB may be produced by different sets of overlapping lots
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The note should clarify that max_dedicated_GB, max_opportunistic_GB, and max_combined_GB can all occur at different times. The current wording only mentions that max_opportunistic_GB and max_combined_GB may be produced by different sets, but max_dedicated_GB can also occur at a different time than the others. Consider rephrasing to: "max_dedicated_GB, max_opportunistic_GB, and max_combined_GB may each be produced by different sets of overlapping lots at different points in time".

Suggested change
- max_opportunistic_GB and max_combined_GB may be produced by different sets of overlapping lots
- max_dedicated_GB, max_opportunistic_GB, and max_combined_GB may each be produced by different sets of overlapping lots at different points in time

Copilot uses AI. Check for mistakes.
Comment on lines +961 to +964
- When false: lots are considered active until their expiration_time
- When true: lots are considered active until their deletion_time
For most capacity planning scenarios, false is recommended since expired lots may still
consume resources even if they become opportunistic.
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation is internally inconsistent regarding the include_deletion parameter. Line 963-964 states "false is recommended since expired lots may still consume resources even if they become opportunistic" - but if expired lots still consume resources, then true (using deletion_time) would be more accurate for capacity planning, not false. This contradicts the PR description which states expiration_time is "recommended for capacity planning". Please clarify the intended semantics: if lots stop consuming dedicated resources at expiration_time but continue consuming opportunistic resources until deletion_time, or if they continue consuming all resources until deletion_time.

Suggested change
- When false: lots are considered active until their expiration_time
- When true: lots are considered active until their deletion_time
For most capacity planning scenarios, false is recommended since expired lots may still
consume resources even if they become opportunistic.
- When false: lots are considered active until their expiration_time. After expiration, lots stop consuming dedicated resources, but may continue to consume opportunistic resources until deletion_time.
- When true: lots are considered active until their deletion_time, including both dedicated and opportunistic resource consumption.
For most capacity planning scenarios, true is recommended, since expired lots may still consume resources (opportunistic or otherwise) until deletion_time. Use true to ensure all resource consumption is accounted for.
Use false only if you wish to exclude opportunistic resource usage after expiration_time.

Copilot uses AI. Check for mistakes.
// Only add if the lot ends before the query period ends
if (end_time < end_ms) {
// Schedule removal at end_time + 1 (first moment lot is no longer active)
events.push_back({end_time + 1, -dedicated, -opportunistic, -objects, false});
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential integer overflow when calculating end_time + 1. If end_time is INT64_MAX (or close to it), adding 1 will cause overflow. While this is unlikely in practice with Unix millisecond timestamps (INT64_MAX represents year 292,277,026), consider adding a check or documenting this limitation. The overflow would cause incorrect behavior where the removal event is scheduled at a negative timestamp.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant