Commit 476e2933 authored by Marc Vef's avatar Marc Vef
Browse files

Client readdir cache: Base structure

parent 7c7cffe6
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 −1
Original line number Diff line number Diff line
@@ -84,7 +84,8 @@ forward_get_metadentry_size(const std::string& path, const int copy);
std::pair<int, std::shared_ptr<gkfs::filemap::OpenDir>>
forward_get_dirents(const std::string& path);

std::pair<int, std::vector<std::tuple<const std::string, bool, size_t, time_t>>>
std::pair<int, std::unique_ptr<std::vector<
                       std::tuple<const std::string, bool, size_t, time_t>>>>
forward_get_dirents_single(const std::string& path, int server);

#ifdef HAS_SYMLINKS
+2 −1
Original line number Diff line number Diff line
@@ -36,7 +36,8 @@ forward_update_metadentry_size_proxy(const std::string& path, const size_t size,
std::pair<int, off64_t>
forward_get_metadentry_size_proxy(const std::string& path);

std::pair<int, std::vector<std::tuple<const std::string, bool, size_t, time_t>>>
std::pair<int, std::unique_ptr<std::vector<
                       std::tuple<const std::string, bool, size_t, time_t>>>>
forward_get_dirents_single_proxy(const std::string& path, int server);

} // namespace gkfs::rpc
Loading