SIENTIAPDE-988

Refactor ingestor lease management and update Docker configurations

- Updated CMD in Dockerfile to use the correct application entry point.
- Added docker compose command to remove volumes in README.
- Removed unnecessary restart policy from ingestor service in docker-compose.yaml.
- Refactored manage_leases method in Ingestor class to improve clarity and parameter naming.
- Added get_number_of_leases method in IngestorManager to retrieve active leases.
- Implemented get_all_leases method in ResourceManager to fetch active leases from Redis.
- Enhanced unit tests for lease management in test_ingestor_manager and test_resource_manager.
This commit is contained in:
vitor-aignosi
2025-04-24 08:42:56 -03:00
parent b9ef69a865
commit da079c6320
9 changed files with 87 additions and 31 deletions

View File

@@ -134,37 +134,38 @@ class Ingestor:
self.handle_acquired_tags(acquired)
def manage_leases(self, ingestor_diff: int, slot_diff: int):
def manage_leases(self, available_slots: int, lacking_ingestors: int, slot_diff: int):
"""
Manages the allocation and deallocation of slot leases based on the
differences in the number of active ingestors and available slots.
Manages the allocation and deallocation of slot leases for ingestors based on
the number of available slots, lacking ingestors, and slot differences.
Args:
ingestor_diff (int): The difference between the required and available
ingestors. A positive value indicates that there are inactive
ingestors and available slots.
slot_diff (int): The difference between the required and available
slots. A positive value indicates that there are active ingestors
without assigned slots.
available_slots (int): The number of slots currently available for allocation.
lacking_ingestors (int): The number of ingestors that are active and without slots.
slot_diff (int): The difference between the total slots and the required slots.
Behavior:
- If `ingestor_diff` is greater than 0, it means there are available
slots due to inactive ingestors. The method will acquire slot leases
for the available slots and handle the acquired tags.
- If `slot_diff` is greater than 0, it means there are active ingestors
without slots. The method will drop slot leases for the excess
managed tags.
- If there are available slots and lacking ingestors, attempts to acquire slot leases
for the available slots and processes the acquired tags.
- If there are no lacking ingestors but there are extra slots (slot_diff > 0),
releases the extra slot leases to ensure proper allocation.
Logs:
- Logs the number of available slots when attempting to acquire leases.
- Logs the number of extra slots when releasing leases.
"""
if ingestor_diff > 0:
# Some ingestors are innactive, so theres "ingestor_diff" slots available
self.logger.info(f"Slots available: {ingestor_diff}")
if available_slots > 0 and lacking_ingestors > 0:
# Some ingestors are innactive, so theres "available_slots" slots available
self.logger.info(f"Slots available: {available_slots}")
# Get slot lease
acquired = self.ingestor_manager.get_slot_leases(ingestor_diff)
acquired = self.ingestor_manager.get_slot_leases(available_slots)
self.handle_acquired_tags(acquired)
elif slot_diff > 0:
# Some ingestors are active and without slots, so we need to drop
elif lacking_ingestors == 0 and slot_diff > 0:
self.logger.info(f"Extra slots available: {slot_diff}")
# There's enough slots for all ingestors, but this ingestor has more than one slot
# So we need to drop the extra leases
overleases = list(self.ingestor_manager.managed_tags.keys())[1:]
@@ -194,19 +195,23 @@ class Ingestor:
self.logger.info("Polling for slot updates...")
# Get active ingestors
ingestors = self.ingestor_manager.get_active_ingestors()
number_of_ingestors = len(ingestors)
number_of_leases = self.ingestor_manager.get_number_of_leases()
number_of_slots = self.ingestor_manager.get_number_of_slots()
# Handle no slots
self.manage_no_slots(number_of_slots)
ingestor_diff = number_of_slots - len(ingestors)
available_slots = number_of_slots - number_of_leases
lacking_ingestors = number_of_slots - number_of_ingestors
slot_diff = len(self.ingestor_manager.managed_tags) - 1
self.manage_leases(ingestor_diff, slot_diff)
self.manage_leases(available_slots, lacking_ingestors, slot_diff)
self.logger.info(
f"Active ingestors: {ingestors}, "
f"Number of slots: {number_of_slots}, "
f"Number of leases: {number_of_leases}, "
f"Managed tags: {self.ingestor_manager.managed_tags}"
f"Managed servers: {self.ingestor_manager.opc_managers}"
)