From a9b1b20a51287bd59387018fcb08c29ad351b2b5 Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Tue, 30 May 2023 17:58:29 +0300 Subject: [PATCH] - Prevent running out of space, by checking the available free space and stalling the acquisition of new assignments until more free space becomes available. - Fix missing change. --- installAndRun.sh | 2 +- .../components/ScheduledTasks.java | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/installAndRun.sh b/installAndRun.sh index c0e0e1d..1359d5f 100755 --- a/installAndRun.sh +++ b/installAndRun.sh @@ -29,7 +29,7 @@ shouldBeCarefulWithMaxHeap=0 # This is NOT a cmd-arg. if [[ justRun -eq 0 ]]; then if [[ avoidReInstallingPublicationsRetriever -eq 1 ]]; then - if [[ ! -f ./libs/publications_retriever-1.0-SNAPSHOT.jar ]]; then + if [[ ! -f ./libs/publications_retriever-1.1-SNAPSHOT.jar ]]; then echo -e "\n\nThe required \"PublicationsRetriever\" software has not been installed yet, thus the script will override the user-defined value of \"avoidReInstallingPublicationsRetriever\" to FALSE..\n\n" avoidReInstallingPublicationsRetriever=0; # In case the jar-file does not exists, then make sure we follow the normal procedure, independently from what the user requested. fi diff --git a/src/main/java/eu/openaire/urls_worker/components/ScheduledTasks.java b/src/main/java/eu/openaire/urls_worker/components/ScheduledTasks.java index 8414590..bef39fa 100644 --- a/src/main/java/eu/openaire/urls_worker/components/ScheduledTasks.java +++ b/src/main/java/eu/openaire/urls_worker/components/ScheduledTasks.java @@ -38,6 +38,20 @@ public class ScheduledTasks { @Value("${workerReportsDirPath}") private String workerReportsDirPath; + private static final File rootPath = new File("/"); + private static final long oneAndHalfGB = 1_610_612_736L; // 1.5 GB free space per 1.000-assignments-batch. + private static long requiredFreeSpace; + + + public ScheduledTasks(@Value("${info.maxAssignmentsLimitPerBatch}") int maxAssignmentsLimitPerBatch) + { + if ( maxAssignmentsLimitPerBatch < 1_000 ) + requiredFreeSpace = oneAndHalfGB; + else + requiredFreeSpace = oneAndHalfGB * (maxAssignmentsLimitPerBatch / 1_000); + + logger.info("The \"requiredFreeSpace\" for the app to request new assignments, having \"maxAssignmentsLimitPerBatch\" equal to " + maxAssignmentsLimitPerBatch + " , is: " + (requiredFreeSpace / (1024 * 1024)) + " Mb"); + } @Scheduled(fixedDelay = 1) // Request the next batch immediately after the last one finishes. public void handleNewAssignments() { @@ -47,6 +61,23 @@ public class ScheduledTasks { return; } + if ( rootPath.getFreeSpace() < requiredFreeSpace ) { + // It's not safe to proceed with downloading more files and risk of "noSpaceLeft" error. + // Wait for the Controller to take the full-texts and any remaining files to be deleted, so that more free-space becomes available. + // We need to have some buffer zone for the ".tar" files which will be created from the already downloaded full-texts, when the Controller starts requesting them. + if ( GeneralController.shouldShutdownWorker ) { // Make sure the worker shuts-down, in case the user sends the relevant request, while the worker is stuck in a free-space check loop. + AssignmentsHandler.shouldNotRequestMore = true; + return; + } + logger.warn("The free space is running out (less than " + (requiredFreeSpace / (1024 * 1024)) + " Mb). Will avoid to get new assignments for the next 15 minutes."); + try { + Thread.sleep(900_000); // Sleep for 15 mins to stall the scheduler from retrying right away, thus giving time to the disk-space to be freed. + } catch (InterruptedException ie) { + logger.warn("Sleeping was interrupted!"); + } + return; // Cause this method to be called again, so that the Free-space can be checked again before proceeding with new assignments. + } + if ( AssignmentsHandler.hadConnectionErrorOnRequest ) { if ( GeneralController.shouldShutdownWorker ) { // Make sure the worker shuts-down, in case the user sends the relevant request, while the worker is stuck in a data-request error-loop. AssignmentsHandler.shouldNotRequestMore = true;