Verified Commit 22eda4c1 authored by Marc Vef's avatar Marc Vef
Browse files

Client readdir cache: Base structure

parent e4245996
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ target_sources(
         preload.hpp
         preload_context.hpp
         preload_util.hpp
    cache.hpp
         rpc/rpc_types.hpp
         rpc/forward_management.hpp
         rpc/forward_metadata.hpp
@@ -68,6 +69,7 @@ target_sources(
         preload.hpp
         preload_context.hpp
         preload_util.hpp
    cache.hpp
         rpc/rpc_types.hpp
         rpc/forward_management.hpp
         rpc/forward_metadata.hpp
+65 −0
Original line number Diff line number Diff line
/*
  Copyright 2018-2024, Barcelona Supercomputing Center (BSC), Spain
  Copyright 2015-2024, Johannes Gutenberg Universitaet Mainz, Germany

  This software was partially supported by the
  EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu).

  This software was partially supported by the
  ADA-FS project under the SPPEXA project funded by the DFG.

  This file is part of GekkoFS' POSIX interface.

  GekkoFS' POSIX interface is free software: you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public License as
  published by the Free Software Foundation, either version 3 of the License,
  or (at your option) any later version.

  GekkoFS' POSIX interface 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 Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public License
  along with GekkoFS' POSIX interface.  If not, see
  <https://www.gnu.org/licenses/>.

  SPDX-License-Identifier: LGPL-3.0-or-later
*/

#ifndef GKFS_CLIENT_CACHE
#define GKFS_CLIENT_CACHE

#include <string>
#include <unordered_map>
#include <mutex>
#include <optional>

namespace gkfs::cache {

class Cache {
private:
    std::unordered_map<std::string, std::string> entries_;
    std::mutex mtx_;

public:
    Cache() = default;

    virtual ~Cache() = default;

    void
    insert(const std::string& key, const std::string& value);

    std::optional<std::string>
    get(const std::string& key);

    void
    remove(const std::string& key);

    void
    clear();
};

} // namespace gkfs::cache

#endif // GKFS_CLIENT_CACHE
+19 −0
Original line number Diff line number Diff line
@@ -55,6 +55,10 @@ namespace messagepack {
class ClientMetrics;
}

namespace cache {
class Cache;
}

namespace preload {
/*
 * Client file system config
@@ -90,6 +94,8 @@ private:
    std::shared_ptr<gkfs::filemap::OpenFileMap> ofm_;
    std::shared_ptr<gkfs::rpc::Distributor> distributor_;
    std::shared_ptr<FsConfig> fs_conf_;
    std::shared_ptr<gkfs::cache::Cache> cache_;
    bool use_cache_{false};

    std::string cwd_;
    std::vector<std::string> mountdir_components_;
@@ -229,6 +235,19 @@ public:
    const std::shared_ptr<FsConfig>&
    fs_conf() const;

    std::shared_ptr<gkfs::cache::Cache>
    cache() const;

    void
    cache(std::shared_ptr<gkfs::cache::Cache> cache);

    bool
    use_cache() const;

    void
    use_cache(bool use_cache);


    void
    enable_interception();

+2 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ target_sources(gkfs_intercept
          preload.cpp
          preload_context.cpp
          preload_util.cpp
	cache.cpp
          rpc/rpc_types.cpp
          rpc/forward_data.cpp
          rpc/forward_data_proxy.cpp
@@ -68,6 +69,7 @@ target_sources(
          preload_context.cpp
          preload_util.cpp
	malleability.cpp
	cache.cpp
          rpc/rpc_types.cpp
          rpc/forward_data.cpp
	      rpc/forward_data_proxy.cpp

src/client/cache.cpp

0 → 100644
+65 −0
Original line number Diff line number Diff line
/*
  Copyright 2018-2024, Barcelona Supercomputing Center (BSC), Spain
  Copyright 2015-2024, Johannes Gutenberg Universitaet Mainz, Germany

  This software was partially supported by the
  EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu).

  This software was partially supported by the
  ADA-FS project under the SPPEXA project funded by the DFG.

  This file is part of GekkoFS' POSIX interface.

  GekkoFS' POSIX interface is free software: you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public License as
  published by the Free Software Foundation, either version 3 of the License,
  or (at your option) any later version.

  GekkoFS' POSIX interface 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 Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public License
  along with GekkoFS' POSIX interface.  If not, see
  <https://www.gnu.org/licenses/>.

  SPDX-License-Identifier: LGPL-3.0-or-later
*/

#include <client/cache.hpp>
#include <mutex>
#include <optional>
#include <string>

namespace gkfs::cache {

void
Cache::insert(const std::string& key, const std::string& value) {
    std::lock_guard<std::mutex> const lock(mtx_);
    entries_[key] = value;
}

std::optional<std::string>
Cache::get(const std::string& key) {
    std::lock_guard<std::mutex> const lock(mtx_);
    // return key if found
    if(entries_.find(key) != entries_.end()) {
        return entries_[key];
    }
    return {};
}

void
Cache::remove(const std::string& key) {
    std::lock_guard<std::mutex> const lock(mtx_);
    entries_.erase(key);
}

void
Cache::clear() {
    std::lock_guard<std::mutex> const lock(mtx_);
    entries_.clear();
}

} // namespace gkfs::cache
Loading