Skip to content

Commit 3ffd060

Browse files
committed
Move bad-files under each volume directory
The bad-files directory, currently sitting directly under the NGAS root directory and not within any of the volume directories, contains files that for one reason or another could not be archived automatically (server shutdown, client disconnected, etc). When files are moved into the bad-files directory, their original location is always the staging/ directory in the target volume where the final archiving takes place. Because volumes are usually mapped to different filesystems, this often results on slow, expensive data copies across filesystems instead of fast, simpler renames within the single filesystem. Moreover, files under bad-files are never automatically removed or picked out in any way, and therefore they simply accumulate until they are dealt with (most commonly removed). This commit moves the bad-files directory to exist within each of the volumes rather than directly under the NGAS root. This should speed up greatly the movement of files into such directories, while keeping the information of the disk they originated from. This issue was reported in #51. Signed-off-by: Rodrigo Tobar <[email protected]>
1 parent 5242738 commit 3ffd060

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

doc/changelog.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ Changelog
9696
when registration of a file
9797
with a MIME type with no configured plug-in
9898
is requested.
99+
* The ``bad-files`` directory
100+
now exists on each volume
101+
rather that there being a single one
102+
outside of any volume directory.
103+
This allows for faster movement of files
104+
into the ``bad-files`` directory,
105+
a more consistent directory structure,
106+
and better traceability of files that end up in ``bad-files``.
99107

100108
.. rubric:: 11.0.2
101109

src/ngamsCore/ngamsLib/ngamsHighLevelLib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,14 +524,14 @@ def getNewFileVersion(dbConObj,
524524
return (latestFileVersion + 1)
525525

526526

527-
def moveFile2BadDir(ngamsCfgObj, srcFilename):
527+
def moveFile2BadDir(disk, srcFilename):
528528
"""
529529
Move a file to the Bad File Directory on the destination disk.
530530
531531
Returns: Name of filename in Bad Files Area (string).
532532
"""
533533

534-
badFilesDir = os.path.join(ngamsCfgObj.getRootDirectory(), NGAMS_BAD_FILES_DIR)
534+
badFilesDir = os.path.join(disk.getMountPoint(), NGAMS_BAD_FILES_DIR)
535535
checkCreatePath(badFilesDir)
536536

537537
trgFilename = tempfile.mktemp(suffix="-" + os.path.basename(srcFilename),

src/ngamsServer/ngamsServer/ngamsArchiveUtils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ def archiveFromFile(srvObj,
769769
". Attempt failed with following error", filename)
770770
logger.warning("Moving local file: " +\
771771
filename + " to Bad Files Directory -- cannot be handled.")
772-
ngamsHighLevelLib.moveFile2BadDir(srvObj.getCfg(), filename)
772+
ngamsHighLevelLib.moveFile2BadDir(trgDiskInfo, filename)
773773
# Remove pickle file if available.
774774
pickleObjFile = filename + "." + NGAMS_PICKLE_FILE_EXT
775775
if (os.path.exists(pickleObjFile)):

src/ngamsServer/ngamsServer/ngamsSrvUtils.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -450,18 +450,13 @@ def checkStagingAreas(srvObj):
450450
getDiskInfoForMountedDisks(srvObj.getDb(), srvObj.getHostId(),
451451
srvObj.getCfg().\
452452
getRootDirectory())
453-
# Generate first a dictionary with all files in the staging areas.
454-
stagingFileDic = {}
455453
for disk in diskList:
456454
stagingArea = disk.getStagingArea()
457-
if (stagingArea != ""):
458-
fileList = glob.glob(stagingArea + "/*")
459-
fileList += glob.glob(stagingArea + "/.NGAMS*")
460-
for filename in fileList: stagingFileDic[filename] = 1
461-
# Go through all files in the staging file dictionary and move them to
462-
# the Bad Files Area.
463-
for filename in stagingFileDic.keys():
464-
ngamsHighLevelLib.moveFile2BadDir(srvObj.getCfg(), filename)
455+
if stagingArea:
456+
files_to_move = glob.glob(stagingArea + "/*")
457+
files_to_move += glob.glob(stagingArea + "/.NGAMS*")
458+
for f in files_to_move:
459+
ngamsHighLevelLib.moveFile2BadDir(disk, f)
465460

466461

467462
def genIntAuthHdr(srvObj):

test/commands/test_archive.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -966,9 +966,9 @@ def test_ArchiveRobustness_01_01(self):
966966
fo.close()
967967

968968
self.restart_last_server()
969-
badDirPat = self.ngas_path("bad-files/BAD-FILE-*-%s.fits")
969+
badDirPat = self.ngas_path("%s/bad-files/BAD-FILE-*-%s.fits")
970970
for diskName in diskList:
971-
badFile = badDirPat % diskName
971+
badFile = badDirPat % (diskName, diskName)
972972
pollForFile(badFile, 1)
973973
pollForFile("%s.%s" % (badFile, NGAMS_PICKLE_FILE_EXT), 1)
974974

@@ -1011,7 +1011,7 @@ def before_restart():
10111011
self.assertGreater(len(glob.glob(req_fname)), 0)
10121012

10131013
self.restart_last_server(before_restart=before_restart, force=True)
1014-
reqPropBadFile = self.ngas_path("bad-files/BAD-FILE-*-SmallFile.fits.pickle", port=8888)
1014+
reqPropBadFile = self.ngas_path("FitsStorage1-Main-1/bad-files/BAD-FILE-*-SmallFile.fits.pickle", port=8888)
10151015
pollForFile(reqPropBadFile, 1)
10161016

10171017

0 commit comments

Comments
 (0)