From 3abcccd3d1b5bd2f7e9bdab4b415968710050db9 Mon Sep 17 00:00:00 2001 From: Andreas Joachim Peters Date: Tue, 7 Jan 2025 14:10:34 +0100 Subject: [PATCH] MGM: refactor conversion tag file creation --- mgm/LRU.cc | 11 ++----- mgm/convert/ConversionTag.hh | 64 ++++++++++++++++++++++++++++++++++++ mgm/proc/user/File.cc | 35 ++++---------------- 3 files changed, 73 insertions(+), 37 deletions(-) create mode 100644 mgm/convert/ConversionTag.hh diff --git a/mgm/LRU.cc b/mgm/LRU.cc index 1389ac4417..3b4a021684 100644 --- a/mgm/LRU.cc +++ b/mgm/LRU.cc @@ -33,6 +33,7 @@ #include "mgm/Stat.hh" #include "mgm/XrdMgmOfs.hh" #include "mgm/convert/ConverterDriver.hh" +#include "mgm/convert/ConversionTag.hh" #include "namespace/interface/IView.hh" #include "namespace/interface/ContainerIterators.hh" #include "namespace/Prefetcher.hh" @@ -775,15 +776,7 @@ LRU::ConvertMatch(const char* dir, space = cenv.Get("eos.space"); } - snprintf(conversiontagfile, sizeof(conversiontagfile) - 1, - "%s/%016llx:%s#%s%s", - gOFS->MgmProcConversionPath.c_str(), it->first, space.c_str(), - conversion.c_str(), plctplcy.c_str()); - std::string conv_tag = conversiontagfile; - conv_tag.erase(0, gOFS->MgmProcConversionPath.length() + 1); - // For the new converted we need to tell it explicitly that we want the - // ctime to be updated since this doesn't happen by default - conv_tag += eos::mgm::ConversionInfo::UPDATE_CTIME; + std::string conv_tag = ConversionTag::Get(it->first, space.c_str(), conversion, plctplcy); if (gOFS->mConverterDriver->ScheduleJob(fid, conv_tag)) { eos_static_info("msg=\"LRU scheduled conversion job\" tag=\"%s\"", diff --git a/mgm/convert/ConversionTag.hh b/mgm/convert/ConversionTag.hh new file mode 100644 index 0000000000..c7fd9b1877 --- /dev/null +++ b/mgm/convert/ConversionTag.hh @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +// File: ConversionInfo.hh +// Author: Andreas-Joachim Peters - CERN +//------------------------------------------------------------------------------ + +/************************************************************************ + * EOS - the CERN Disk Storage System * + * Copyright (C) 2025 CERN/Switzerland * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see .* + ************************************************************************/ + +#pragma once +#include "mgm/Namespace.hh" +#include "mgm/XrdMgmOfs.hh" +#include "mgm/convert/ConverterDriver.hh" + +#include + +EOSMGMNAMESPACE_BEGIN + +class ConversionTag { +public: + static std::string + Get(unsigned long long fid, std::string space, unsigned int layoutid, + std::string plctplcy, bool ctime_update = true) + { + char conversion[1024]; + snprintf(conversion,sizeof(conversion)-1,"%08lx", layoutid); + return Get(fid, space, conversion, plctplcy, ctime_update); + } + + static std::string + Get(unsigned long long fid, std::string space, std::string conversion, + std::string plctplcy, bool ctime_update = true) + { + char conversiontagfile[4096]; + if (plctplcy.length()) { + // requires a ~ separator + plctplcy.insert(0, "~"); + } + snprintf(conversiontagfile, sizeof(conversiontagfile) - 1, + "%016llx:%s#%s%s", fid, + space.c_str(), conversion.c_str(), plctplcy.c_str()); + std::string conv_tag = conversiontagfile; + if (ctime_update) { + conv_tag += eos::mgm::ConversionInfo::UPDATE_CTIME; + } + return conv_tag; + } +}; + +EOSMGMNAMESPACE_END \ No newline at end of file diff --git a/mgm/proc/user/File.cc b/mgm/proc/user/File.cc index 8f8617d11e..ee45096f03 100644 --- a/mgm/proc/user/File.cc +++ b/mgm/proc/user/File.cc @@ -30,6 +30,7 @@ #include "mgm/Policy.hh" #include "mgm/Stat.hh" #include "mgm/convert/ConverterDriver.hh" +#include "mgm/convert/ConversionTag.hh" #include "mgm/XattrLock.hh" #include "common/Utils.hh" #include "common/Path.hh" @@ -1137,7 +1138,7 @@ ProcCommand::File() stdErr += spath.c_str(); retc = errno; } else { - char conversiontagfile[1024]; + std::string conversiontag; if (option == "rewrite") { if (layout.length() == 0) { @@ -1177,14 +1178,8 @@ ProcCommand::File() } if (eos::common::StringConversion::IsHexNumber(layout.c_str(), "%08x")) { - // we hand over as an conversion layout ID - snprintf(conversiontagfile, - sizeof(conversiontagfile) - 1, - "%s/%016llx:%s#%s", - gOFS->MgmProcConversionPath.c_str(), - fileid, - space.c_str(), - layout.c_str()); + + conversiontag = ConversionTag::Get(fileid, space.c_str(), layout.c_str(), std::string(""), false); stdOut += "info: conversion based on hexadecimal layout id\n"; } else { unsigned long layout_type = 0; @@ -1228,34 +1223,18 @@ ProcCommand::File() eos::common::LayoutId::k4M, eos::common::LayoutId::kCRC32C, eos::common::LayoutId::GetRedundancyStripeNumber(layoutid)); - snprintf(conversiontagfile, - sizeof(conversiontagfile) - 1, - "%s/%016llx:%s#%08lx%s", - gOFS->MgmProcConversionPath.c_str(), - fileid, - space.c_str(), - (unsigned long) layoutid, - plctplcy.c_str()); + conversiontag = ConversionTag::Get(fileid, space.c_str(), layoutid, plctplcy.c_str(), false); + stdOut += "info: conversion based layout+stripe arguments\n"; } else { // assume this is the name of an attribute - snprintf(conversiontagfile, - sizeof(conversiontagfile) - 1, - "%s/%016llx:%s#%s%s", - gOFS->MgmProcConversionPath.c_str(), - fileid, - space.c_str(), - layout.c_str(), - plctplcy.c_str()); + conversiontag = ConversionTag::Get(fileid, space.c_str(), layout.c_str(), plctplcy.c_str(), false); stdOut += "info: conversion based conversion attribute name\n"; } } eos::common::VirtualIdentity rootvid = eos::common::VirtualIdentity::Root(); // Push conversion job to QuarkDB - std::string conversiontag = conversiontagfile; - conversiontag.erase(0, gOFS->MgmProcConversionPath.length() + 1); - if (gOFS->mConverterDriver->ScheduleJob(fmd->getId(), conversiontag)) { stdOut += "success: pushed conversion job '"; stdOut += conversiontag.c_str();