// ---------------------------------------------------------------------- // File: FileInspector.hh // Author: Andreas-Joachim Peters - CERN // ---------------------------------------------------------------------- /************************************************************************ * EOS - the CERN Disk Storage System * * Copyright (C) 2019 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 "common/VirtualIdentity.hh" #include "common/AssistedThread.hh" #include "XrdOuc/XrdOucErrInfo.hh" #include "mgm/Namespace.hh" #include "namespace/interface/IFileMD.hh" #include "XrdOuc/XrdOucString.hh" #include #include #include namespace qclient { class QClient; } EOSMGMNAMESPACE_BEGIN //------------------------------------------------------------------------------ //! Class tracking the sanity of created files //------------------------------------------------------------------------------ class FileInspector { public: struct Options { bool enabled; //< Is FileInspector even enabled? std::chrono::seconds interval; //< Run FileInspector cleanup every this many seconds }; enum LockFsView : bool { Off = false, On = true }; //---------------------------------------------------------------------------- //! Constructor //! //! @param space_name corresponding space name //---------------------------------------------------------------------------- FileInspector(std::string_view space_name); //---------------------------------------------------------------------------- //! Constructor //---------------------------------------------------------------------------- virtual ~FileInspector(); //---------------------------------------------------------------------------- // Perform a single inspector cycle, QDB namespace //---------------------------------------------------------------------------- void performCycleQDB(ThreadAssistant& assistant) noexcept; void Dump(std::string& out, std::string_view options, const LockFsView lockfsview); Options getOptions(const LockFsView lockfsview); inline bool enabled() { return mEnabled.load(); } bool disable() { if (!enabled()) { return false; } else { mEnabled.store(0, std::memory_order_seq_cst); return true; } } bool enable() { if (enabled()) { return false; } else { mEnabled.store(1, std::memory_order_seq_cst); return true; } } const std::string currencies[6] = { "EOS", "CHF", "EUR", "USD", "AUD", "YEN" }; private: void backgroundThread(ThreadAssistant& assistant) noexcept; void Process(std::shared_ptr fmd); AssistedThread mThread; ///< thread id of the creation background tracker std::atomic mEnabled; XrdOucErrInfo mError; eos::common::VirtualIdentity mVid; std::unique_ptr mQcl; // Counters for the last and current scan by layout id std::map> lastScanStats; std::map> currentScanStats; //! Map from types of failures to pairs of fid and layoutid std::map>> lastFaultyFiles; //! Map from types of failures to pairs of fid and layoutid std::map>> currentFaultyFiles; //! Access Time Bins std::map lastAccessTimeFiles; std::map lastAccessTimeVolume; std::map currentAccessTimeFiles; std::map currentAccessTimeVolume; //! Birth Time Bins std::map lastBirthTimeFiles; std::map lastBirthTimeVolume; std::map currentBirthTimeFiles; std::map currentBirthTimeVolume; //! BirthVsAccess Time Bins std::map> lastBirthVsAccessTimeFiles; std::map> lastBirthVsAccessTimeVolume; std::map> currentBirthVsAccessTimeFiles; std::map> currentBirthVsAccessTimeVolume; //! User Cost Bins std::map lastUserCosts[2]; std::map currentUserCosts[2]; std::multimap lastCostsUsers[2]; //! Group Cost Bins std::map lastGroupCosts[2]; std::map currentGroupCosts[2]; std::multimap lastCostsGroups[2]; double lastUserTotalCosts[2] = {0}; double lastGroupTotalCosts[2] = {0}; //! User Bytes Bins std::map lastUserBytes[2]; std::map currentUserBytes[2]; std::multimap lastBytesUsers[2]; //! Group Bytes Bins std::map lastGroupBytes[2]; std::map currentGroupBytes[2]; std::multimap lastBytesGroups[2]; double lastUserTotalBytes[2] = {0}; double lastGroupTotalBytes[2] = {0}; //! Running count of number of time files have been classed faulty uint64_t currentNumFaultyFiles = 0; std::atomic PriceTbPerYearDisk; std::atomic PriceTbPerYearTape; std::string currency; std::atomic timeCurrentScan; std::atomic timeLastScan; std::atomic scanned_percent; std::atomic nfiles; std::atomic ndirs; std::mutex mutexScanStats; std::string mSpaceName; ///< Corresponding space name //! Maximum number of classifications of faulty files to record static constexpr uint64_t maxfaulty = 1'000'000; }; EOSMGMNAMESPACE_END