Skip to content
Snippets Groups Projects
Commit 1a6fb374 authored by Cristiano Urban's avatar Cristiano Urban
Browse files

Minor changes + fixed bug in 'setAsyncTrans()' method: ingore local nodes.

parent de1fc3cf
No related branches found
No related tags found
No related merge requests found
Pipeline #9292 passed
...@@ -1084,14 +1084,22 @@ class DbConnector(object): ...@@ -1084,14 +1084,22 @@ class DbConnector(object):
self.connPool.putconn(conn, close = False) self.connPool.putconn(conn, close = False)
def setAsyncTrans(self, nodeVOSPath, value): def setAsyncTrans(self, nodeVOSPath, value):
"""Sets the 'async_trans' flag for a VOSpace node.""" """
Sets the 'async_trans' flag recursively for a VOSpace node.
Local nodes are not considered.
"""
try: try:
conn = self.getConnection() conn = self.getConnection()
cursor = conn.cursor(cursor_factory = RealDictCursor) cursor = conn.cursor(cursor_factory = RealDictCursor)
cursor.execute(""" cursor.execute("""
UPDATE node c SET async_trans = %s UPDATE node c SET async_trans = %s
FROM node n FROM node n
WHERE c.path <@ n.path AND n.node_id = id_from_vos_path(%s); WHERE c.path <@ n.path
AND n.node_id = id_from_vos_path(%s)
AND c.location_id NOT IN
(SELECT location_id
FROM location
WHERE storage_src_id = storage_dest_id);
""", """,
(value, nodeVOSPath,)) (value, nodeVOSPath,))
conn.commit() conn.commit()
......
...@@ -10,6 +10,7 @@ import json ...@@ -10,6 +10,7 @@ import json
import logging import logging
import os import os
import shutil import shutil
import time
from config import Config from config import Config
from db_connector import DbConnector from db_connector import DbConnector
...@@ -87,21 +88,22 @@ class RetrieveCleaner(TaskExecutor): ...@@ -87,21 +88,22 @@ class RetrieveCleaner(TaskExecutor):
numNodes = len(self.nodeList) numNodes = len(self.nodeList)
self.logger.info(f"Number of VOSpace nodes involved: {numNodes}") self.logger.info(f"Number of VOSpace nodes involved: {numNodes}")
while numNodes > 0: while numNodes > 0:
i = 0 time.sleep(0.2)
while i < numNodes: vospacePath = self.nodeList[numNodes - 1]
vospacePath = self.nodeList[i] destPath = self.destPathList[numNodes - 1]
destPath = self.destPathList[i]
try: try:
busy = self.dbConn.nodeIsBusy(vospacePath) busy = self.dbConn.nodeIsBusy(vospacePath)
except Exception: except Exception:
self.logger.exception(f"FATAL: unable to check the 'busy' flag value for the VOSpace node '{vospacePath}'.") self.logger.exception(f"FATAL: unable to check the 'busy' flag value for the VOSpace node '{vospacePath}'.")
return False return False
else:
if not busy: if not busy:
try: try:
self.dbConn.setAsyncTrans(vospacePath, True) self.dbConn.setAsyncTrans(vospacePath, True)
except Exception: except Exception:
self.logger.exception(f"FATAL: unable to update the 'async_trans' flag for the VOSpace node '{vospacePath}'.") self.logger.exception(f"FATAL: unable to update the 'async_trans' flag for the VOSpace node '{vospacePath}'.")
return False return False
else:
try: try:
if os.path.isfile(destPath): if os.path.isfile(destPath):
os.remove(destPath) os.remove(destPath)
...@@ -109,6 +111,7 @@ class RetrieveCleaner(TaskExecutor): ...@@ -109,6 +111,7 @@ class RetrieveCleaner(TaskExecutor):
shutil.rmtree(destPath) shutil.rmtree(destPath)
except FileNotFoundError: except FileNotFoundError:
self.logger.exception(f"Cannot find '{destPath}', skip...") self.logger.exception(f"Cannot find '{destPath}', skip...")
# check for empty dirs and remove them # check for empty dirs and remove them
basePath = self.storageRetrievePath.replace("{username}", self.username) basePath = self.storageRetrievePath.replace("{username}", self.username)
for root, dirs, files in os.walk(basePath, topdown = False): for root, dirs, files in os.walk(basePath, topdown = False):
...@@ -116,10 +119,9 @@ class RetrieveCleaner(TaskExecutor): ...@@ -116,10 +119,9 @@ class RetrieveCleaner(TaskExecutor):
dirPath = os.path.abspath(root) + '/' + dir dirPath = os.path.abspath(root) + '/' + dir
if not os.listdir(dirPath): if not os.listdir(dirPath):
os.rmdir(dirPath) os.rmdir(dirPath)
self.nodeList.pop(i) self.nodeList.pop(numNodes - 1)
self.destPathList.pop(i) self.destPathList.pop(numNodes - 1)
numNodes -= 1 numNodes -= 1
i = 0
except Exception: except Exception:
self.logger.exception("FATAL: something went wrong while cleaning the expired data.") self.logger.exception("FATAL: something went wrong while cleaning the expired data.")
return False return False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment