LCOV - code coverage report
Current view: top level - src/daemon/ops - metadentry.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 33 35 94.3 %
Date: 2024-04-23 00:09:24 Functions: 9 9 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   Copyright 2018-2024, Barcelona Supercomputing Center (BSC), Spain
       3             :   Copyright 2015-2024, Johannes Gutenberg Universitaet Mainz, Germany
       4             : 
       5             :   This software was partially supported by the
       6             :   EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu).
       7             : 
       8             :   This software was partially supported by the
       9             :   ADA-FS project under the SPPEXA project funded by the DFG.
      10             : 
      11             :   This file is part of GekkoFS.
      12             : 
      13             :   GekkoFS is free software: you can redistribute it and/or modify
      14             :   it under the terms of the GNU General Public License as published by
      15             :   the Free Software Foundation, either version 3 of the License, or
      16             :   (at your option) any later version.
      17             : 
      18             :   GekkoFS is distributed in the hope that it will be useful,
      19             :   but WITHOUT ANY WARRANTY; without even the implied warranty of
      20             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      21             :   GNU General Public License for more details.
      22             : 
      23             :   You should have received a copy of the GNU General Public License
      24             :   along with GekkoFS.  If not, see <https://www.gnu.org/licenses/>.
      25             : 
      26             :   SPDX-License-Identifier: GPL-3.0-or-later
      27             : */
      28             : 
      29             : #include <daemon/ops/metadentry.hpp>
      30             : #include <daemon/backend/metadata/db.hpp>
      31             : #include <daemon/backend/data/chunk_storage.hpp>
      32             : #include <daemon/backend/metadata/metadata_module.hpp>
      33             : 
      34             : using namespace std;
      35             : 
      36             : namespace gkfs::metadata {
      37             : 
      38             : Metadata
      39          44 : get(const std::string& path) {
      40          88 :     return Metadata(get_str(path));
      41             : }
      42             : 
      43             : std::string
      44        1403 : get_str(const std::string& path) {
      45        1403 :     return GKFS_DATA->mdb()->get(path);
      46             : }
      47             : 
      48             : size_t
      49           5 : get_size(const string& path) {
      50          10 :     return get(path).size();
      51             : }
      52             : 
      53             : std::vector<std::pair<std::string, bool>>
      54          25 : get_dirents(const std::string& dir) {
      55          25 :     return GKFS_DATA->mdb()->get_dirents(dir);
      56             : }
      57             : 
      58             : std::vector<std::tuple<std::string, bool, size_t, time_t>>
      59           4 : get_dirents_extended(const std::string& dir) {
      60           4 :     return GKFS_DATA->mdb()->get_dirents_extended(dir);
      61             : }
      62             : 
      63             : void
      64        1100 : create(const std::string& path, Metadata& md) {
      65             : 
      66             :     // update metadata object based on what metadata is needed
      67        1100 :     if(GKFS_DATA->atime_state() || GKFS_DATA->mtime_state() ||
      68           0 :        GKFS_DATA->ctime_state()) {
      69        1100 :         std::time_t time;
      70        1100 :         std::time(&time);
      71        2200 :         auto time_s = fmt::format_int(time).str();
      72        1100 :         if(GKFS_DATA->atime_state())
      73        1100 :             md.atime(time);
      74        1100 :         if(GKFS_DATA->mtime_state())
      75        1100 :             md.mtime(time);
      76        1100 :         if(GKFS_DATA->ctime_state())
      77        1100 :             md.ctime(time);
      78             :     }
      79        1100 :     if constexpr(gkfs::config::metadata::create_exist_check) {
      80        1100 :         GKFS_DATA->mdb()->put_no_exist(path, md.serialize());
      81             :     } else {
      82             :         GKFS_DATA->mdb()->put(path, md.serialize());
      83             :     }
      84        1097 : }
      85             : 
      86             : void
      87          31 : update(const string& path, Metadata& md) {
      88          31 :     GKFS_DATA->mdb()->update(path, path, md.serialize());
      89          31 : }
      90             : 
      91             : /**
      92             :  * @internal
      93             :  * Updates a metadentry's size atomically and returns the starting offset
      94             :  * for the I/O operation.
      95             :  * This is primarily necessary for parallel write operations,
      96             :  * e.g., with O_APPEND, where the EOF might have changed since opening the file.
      97             :  * Therefore, we use update_size to assign a safe write interval to each
      98             :  * parallel write operation.
      99             :  * @endinternal
     100             :  */
     101             : off_t
     102          41 : update_size(const string& path, size_t io_size, off64_t offset, bool append) {
     103          41 :     return GKFS_DATA->mdb()->increase_size(path, io_size, offset, append);
     104             : }
     105             : 
     106             : void
     107           8 : remove(const string& path) {
     108             :     /*
     109             :      * try to remove metadata from kv store but catch NotFoundException which is
     110             :      * not an error in this case because removes can be broadcast to catch all
     111             :      * data chunks but only one node will hold the kv store entry.
     112             :      */
     113           8 :     try {
     114           8 :         GKFS_DATA->mdb()->remove(path); // remove metadata from KV store
     115           0 :     } catch(const NotFoundException& e) {
     116             :     }
     117           8 : }
     118             : 
     119             : } // namespace gkfs::metadata

Generated by: LCOV version 1.16