Commit 2c02aab8 authored by Marc Vef's avatar Marc Vef
Browse files

Cleanup and added new dir cache env variable `LIBGKFS_ENABLE_DIR_CACHE`

parent 525ca153
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ static constexpr auto METRICS_IP_PORT = ADD_PREFIX("METRICS_IP_PORT");

static constexpr auto NUM_REPL = ADD_PREFIX("NUM_REPL");
static constexpr auto PROXY_PID_FILE = ADD_PREFIX("PROXY_PID_FILE");
static constexpr auto DIR_CACHE = ADD_PREFIX("ENABLE_DIR_CACHE");

} // namespace gkfs::env

+13 −7
Original line number Diff line number Diff line
@@ -1296,7 +1296,6 @@ gkfs_readv(int fd, const struct iovec* iov, int iovcnt) {
 */
int
gkfs_opendir(const std::string& path) {
    LOG(INFO, "{}(): XXX Path '{}'", __func__, path);
    auto md = gkfs::utils::get_metadata(path);
    if(!md) {
        return -1;
@@ -1314,7 +1313,17 @@ gkfs_opendir(const std::string& path) {
        ret.second = make_shared<gkfs::filemap::OpenDir>(path);
        // TODO parallelize
        for(uint64_t i = 0; i < CTX->hosts().size(); i++) {
            auto res = gkfs::rpc::forward_get_dirents_single(path, i);
            pair<int, unique_ptr<vector<tuple<const basic_string<char>, bool,
                                              size_t, time_t>>>>
                    res{};
            if(gkfs::config::proxy::fwd_get_dirents_single &&
               CTX->use_proxy()) {
                res = gkfs::rpc::forward_get_dirents_single_proxy(path, i);
            } else {
                res = gkfs::rpc::forward_get_dirents_single(path, i);
            }
            //            auto res = gkfs::rpc::forward_get_dirents_single(path,
            //            i);
            auto& open_dir = *res.second;
            for(auto& dentry : open_dir) {
                // type returns as a boolean. true if it is a directory
@@ -1332,7 +1341,7 @@ gkfs_opendir(const std::string& path) {
            }
            ret.first = res.first;
        }
        CTX->cache()->dump_cache_to_log(path);
        //        CTX->cache()->dump_cache_to_log(path);
    } else {
        ret = gkfs::rpc::forward_get_dirents(path);
    }
@@ -1398,7 +1407,6 @@ gkfs_rmdir(const std::string& path) {
 */
int
gkfs_getdents(unsigned int fd, struct linux_dirent* dirp, unsigned int count) {
    LOG(INFO, "{}(): XXX fd '{}' count '{}'", __func__, fd, count);
    // Get opendir object (content was downloaded with opendir() call)
    auto open_dir = CTX->file_map()->get_dir(fd);
    if(open_dir == nullptr) {
@@ -1473,7 +1481,6 @@ gkfs_getdents(unsigned int fd, struct linux_dirent* dirp, unsigned int count) {
int
gkfs_getdents64(unsigned int fd, struct linux_dirent64* dirp,
                unsigned int count) {
    LOG(INFO, "{}(): XXX enter fd '{}' count '{}'", __func__, fd, count);
    auto open_dir = CTX->file_map()->get_dir(fd);
    if(open_dir == nullptr) {
        // Cast did not succeeded: open_file is a regular file
@@ -1548,9 +1555,8 @@ gkfs_close(unsigned int fd) {
               gkfs::filemap::FileType::directory) {
                CTX->cache()->clear_dir(CTX->file_map()->get(fd)->path());
            }
            CTX->cache()->dump_cache_to_log(CTX->file_map()->get(fd)->path());
            //            CTX->cache()->dump_cache_to_log(CTX->file_map()->get(fd)->path());
        }
        LOG(INFO, "{}(): XXX fd '{}'", __func__, fd);
        // No call to the daemon is required
        CTX->file_map()->remove(fd);
        return 0;
+11 −9
Original line number Diff line number Diff line
@@ -258,6 +258,7 @@ init_environment() {
#endif
        CTX->distributor(distributor);
    }
    if(gkfs::env::var_is_set(gkfs::env::DIR_CACHE)) {
        try {
            LOG(INFO, "Initializing client caching...");
            auto cache = std::make_shared<gkfs::cache::Cache>();
@@ -268,6 +269,7 @@ init_environment() {
            exit_error_msg(EXIT_FAILURE,
                           "Failed to initialize cache: "s + e.what());
        }
    }

    LOG(INFO, "Retrieving file system configuration...");

+7 −4
Original line number Diff line number Diff line
@@ -205,22 +205,25 @@ namespace gkfs::utils {
 */
optional<gkfs::metadata::Metadata>
get_metadata(const string& path, bool follow_links) {
    LOG(INFO, "{}(): XXX Path '{}'", __func__, path);
    std::string attr;
    int err{};
    if(CTX->use_cache()) {
        std::filesystem::path p(path);
        auto parent = p.parent_path().string();
        auto filename = p.filename().string();
        LOG(INFO, "{}(): for path '{}' -> parent path '{}' leaf name '{}'",
            __func__, path, p.parent_path().string(), p.filename().string());
        //        LOG(INFO, "{}(): for path '{}' -> parent path '{}' leaf name
        //        '{}'",
        //            __func__, path, p.parent_path().string(),
        //            p.filename().string());
        auto cache_entry = CTX->cache()->get(parent, filename);
        if(cache_entry) {
            LOG(INFO, "{}(): Cache hit for path '{}'", __func__, path);
            //            LOG(INFO, "{}(): Cache hit for path '{}'", __func__,
            //            path);
            // TOOD something like this:
            //            struct stat st{};
            //            metadata_to_stat(path, *cache_entry, st);
            //            return gkfs::metadata::Metadata{st};
            // TODO add mode to extended RPC
            mode_t mode = 33188;
            if(cache_entry->file_type == gkfs::filemap::FileType::directory) {
                mode = 16895;
+0 −2
Original line number Diff line number Diff line
@@ -765,8 +765,6 @@ forward_get_dirents(const string& path) {
            names_ptr += name.size() + 1;

            open_dir->add(name, ftype);
            LOG(INFO, "{}(): XXX parentpath '{}' name '{}'", __func__, path,
                name);
        }
    }
    return make_pair(err, open_dir);