// ---------------------------------------------------------------------- // File: TapeGc.cc // Author: Steven Murray - CERN // ---------------------------------------------------------------------- /************************************************************************ * EOS - the CERN Disk Storage System * * Copyright (C) 2011 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 .* ************************************************************************/ #include "mgm/tgc/Constants.hh" #include "mgm/tgc/DummyTapeGcMgm.hh" EOSTGCNAMESPACE_BEGIN //------------------------------------------------------------------------------ // Constructor //------------------------------------------------------------------------------ DummyTapeGcMgm::DummyTapeGcMgm(): m_nbCallsToGetTapeGcSpaceConfig(0), m_nbCallsToGetSpaceStats(0), m_nbCallsToFileInNamespaceAndNotScheduledForDeletion(0), m_nbCallsToGetFileSizeBytes(0), m_nbCallsToEvictAsRoot(0) { } //---------------------------------------------------------------------------- //! @return The configuration of a tape-aware garbage collector for the //! specified space. //! @param spaceName The name of the space //---------------------------------------------------------------------------- SpaceConfig DummyTapeGcMgm::getTapeGcSpaceConfig(const std::string &spaceName) { const SpaceConfig defaultConfig; try { std::lock_guard lock(m_mutex); m_nbCallsToGetTapeGcSpaceConfig++; auto itor = m_spaceToTapeGcConfig.find(spaceName); if(itor == m_spaceToTapeGcConfig.end()) { return defaultConfig; } else { return itor->second; } } catch(...) { return defaultConfig; } } //---------------------------------------------------------------------------- // Determine if the specified file exists and is not scheduled for deletion //---------------------------------------------------------------------------- bool DummyTapeGcMgm::fileInNamespaceAndNotScheduledForDeletion(const IFileMD::id_t /* fid */) { std::lock_guard lock(m_mutex); m_nbCallsToFileInNamespaceAndNotScheduledForDeletion++; return true; } //---------------------------------------------------------------------------- // Return statistics about the specified space //---------------------------------------------------------------------------- SpaceStats DummyTapeGcMgm::getSpaceStats(const std::string &space) const { const SpaceStats defaultStats; try { std::lock_guard lock(m_mutex); m_nbCallsToGetSpaceStats++; auto itor = m_spaceToStats.find(space); if(itor == m_spaceToStats.end()) { return defaultStats; } else { return itor->second; } } catch(...) { return defaultStats; } } //---------------------------------------------------------------------------- // Return size of the specified file //---------------------------------------------------------------------------- uint64_t DummyTapeGcMgm::getFileSizeBytes(const IFileMD::id_t /* fid */) { std::lock_guard lock(m_mutex); m_nbCallsToGetFileSizeBytes++; return 1; } //---------------------------------------------------------------------------- // Execute evict as user root //---------------------------------------------------------------------------- void DummyTapeGcMgm::evictAsRoot(const IFileMD::id_t /* fid */) { std::lock_guard lock(m_mutex); m_nbCallsToEvictAsRoot++; } //---------------------------------------------------------------------------- // Return map from file system ID to EOS space name //---------------------------------------------------------------------------- std::map DummyTapeGcMgm::getFsIdToSpaceMap() { return std::map (); } //---------------------------------------------------------------------------- // Return map from EOS space name to disk replicas within that space //---------------------------------------------------------------------------- std::map > DummyTapeGcMgm::getSpaceToDiskReplicasMap(const std::set &spacesToMap, std::atomic &stop, uint64_t &nbfilesScanned) { nbfilesScanned = 0; return std::map >(); } //---------------------------------------------------------------------------- // Get the stdout of the specified shell cmd as a string //---------------------------------------------------------------------------- std::string DummyTapeGcMgm::getStdoutFromShellCmd(const std::string &cmdStr, const ssize_t maxLen) const { std::lock_guard lock(m_mutex); return m_stdoutFromShellCmd; } //---------------------------------------------------------------------------- // Set the configuration of the tape-aware garbage collector //---------------------------------------------------------------------------- void DummyTapeGcMgm::setTapeGcSpaceConfig(const std::string &space, const SpaceConfig &config) { std::lock_guard lock(m_mutex); m_spaceToTapeGcConfig[space] = config; } //---------------------------------------------------------------------------- // Set the statistics of the specified EOS space. //---------------------------------------------------------------------------- void DummyTapeGcMgm::setSpaceStats(const std::string &space, const SpaceStats &spaceStats) { std::lock_guard lock(m_mutex); m_spaceToStats[space] = spaceStats; } //------------------------------------------------------------------------------ // Return number of times getTapeGcSpaceConfig() has been called //------------------------------------------------------------------------------ uint64_t DummyTapeGcMgm::getNbCallsToGetTapeGcSpaceConfig() const { std::lock_guard lock(m_mutex); return m_nbCallsToGetTapeGcSpaceConfig; } //------------------------------------------------------------------------------ // Return number of times getSpaceStats() has been called //------------------------------------------------------------------------------ uint64_t DummyTapeGcMgm::getNbCallsToGetSpaceStats() const { std::lock_guard lock(m_mutex); return m_nbCallsToGetSpaceStats; } //------------------------------------------------------------------------------ // Return number of times fileInNamespaceAndNotScheduledForDeletion() has been // called //------------------------------------------------------------------------------ uint64_t DummyTapeGcMgm::getNbCallsToFileInNamespaceAndNotScheduledForDeletion() const { std::lock_guard lock(m_mutex); return m_nbCallsToFileInNamespaceAndNotScheduledForDeletion; } //------------------------------------------------------------------------------ // Return number of times getFileSizeBytes() has been called //------------------------------------------------------------------------------ uint64_t DummyTapeGcMgm::getNbCallsToGetFileSizeBytes() const { std::lock_guard lock(m_mutex); return m_nbCallsToGetFileSizeBytes; } //------------------------------------------------------------------------------ // Return number of times evictAsRoot() has been called //------------------------------------------------------------------------------ uint64_t DummyTapeGcMgm::getNbCallsToEvictAsRoot() const { std::lock_guard lock(m_mutex); return m_nbCallsToEvictAsRoot; } //---------------------------------------------------------------------------- // Set the stdout of the specified shell cmd as a string //---------------------------------------------------------------------------- void DummyTapeGcMgm::setStdoutFromShellCmd(const std::string &stdoutFromShellCmd) { std::lock_guard lock(m_mutex); m_stdoutFromShellCmd = stdoutFromShellCmd; } EOSTGCNAMESPACE_END