Commit 3ab07f14 authored by Ramon Nou's avatar Ramon Nou
Browse files

Generalization Phase 1

parent e76adfc1
Loading
Loading
Loading
Loading
Loading
+10 −17
Original line number Diff line number Diff line
@@ -31,35 +31,27 @@

#include <memory>
#include <spdlog/spdlog.h>
#include <rocksdb/db.h>
#include <daemon/backend/exceptions.hpp>
#include <rocksdb/db.h>
#include <tuple>
extern "C" {
#include <kreon.h>
}
#include <daemon/backend/metadata/metadata_backend.hpp>
#include <daemon/backend/metadata/rocksdb_backend.hpp>
#include <daemon/backend/metadata/kreon_backend.hpp>

namespace rdb = rocksdb;

namespace gkfs::metadata {


class MetadataDB {
private:
    std::unique_ptr<rdb::DB> db;
    rdb::Options options;
    rdb::WriteOptions write_opts;
    
    std::string path;
    std::shared_ptr<spdlog::logger> log_;
    std::unique_ptr< AbstractMetadataBackend > db;

    // kreon
    klc_handle klc_db;
    klc_db_options klc_options;
    std::string klc_path;

    static void
    optimize_rocksdb_options(rdb::Options& options);

public:
    static inline void
    throw_rdb_status_excpt(const rdb::Status& s);
    
    explicit MetadataDB(const std::string& path);

@@ -96,6 +88,7 @@ public:

    void
    iterate_all();

};

} // namespace gkfs::metadata
+26 −27
Original line number Diff line number Diff line
@@ -26,8 +26,8 @@
  SPDX-License-Identifier: GPL-3.0-or-later
*/

#ifndef GEKKOFS_METADATA_DB_HPP
#define GEKKOFS_METADATA_DB_HPP
#ifndef GEKKOFS_METADATA_KREONBACKEND_HPP
#define GEKKOFS_METADATA_KREONBACKEND_HPP

#include <memory>
#include <spdlog/spdlog.h>
@@ -37,67 +37,66 @@
extern "C" {
#include <kreon.h>
}
namespace rdb = rocksdb;

namespace rdb = rocksdb;
namespace gkfs::metadata {

class MetadataDB {
class KreonBackend : public MetadataBackend<KreonBackend> {
private:
    std::unique_ptr<rdb::DB> db;
    rdb::Options options;
    rdb::WriteOptions write_opts;
    std::string path;
    std::shared_ptr<spdlog::logger> log_;

    // kreon
    klc_handle klc_db;
    klc_db_options klc_options;
    std::string klc_path;

    static void
    optimize_rocksdb_options(rdb::Options& options);
    inline void str2klc(const std::string& value,
            struct klc_value & V) const;

    inline void str2klc(const std::string& key,
            struct klc_key &K) const;

public:
    explicit KreonBackend(const std::string& path);

    static inline void
    throw_rdb_status_excpt(const rdb::Status& s);
    throw_status_excpt(const rdb::Status& s);

    explicit MetadataDB(const std::string& path);
    
    std::string
    get(const std::string& key) const;
    get(const std::string& key) const override;

    void
    put(const std::string& key, const std::string& val);
    put(const std::string& key, const std::string& val) override;

    void
    put_no_exist(const std::string& key, const std::string& val);
    put_no_exist(const std::string& key, const std::string& val) override;

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

    bool
    exists(const std::string& key);
    exists(const std::string& key) override;

    void
    update(const std::string& old_key, const std::string& new_key,
           const std::string& val);
           const std::string& val) override;

    void
    increase_size(const std::string& key, size_t size, bool append);
    increase_size(const std::string& key, size_t size, bool append) override;

    void
    decrease_size(const std::string& key, size_t size);
    decrease_size(const std::string& key, size_t size) override;

    std::vector<std::pair<std::string, bool>>
    get_dirents(const std::string& dir) const;
    get_dirents(const std::string& dir) const override;

    std::vector<std::tuple<std::string, bool, size_t, time_t>>
    get_dirents_extended(const std::string& dir) const;
    get_dirents_extended(const std::string& dir) const override;

    void
    iterate_all();
    iterate_all() override;

};

} // namespace gkfs::metadata

#endif // GEKKOFS_METADATA_DB_HPP
#endif // GEKKOFS_METADATA_KREONBACKEND_HPP
+150 −0
Original line number Diff line number Diff line
/*
  Copyright 2018-2021, Barcelona Supercomputing Center (BSC), Spain
  Copyright 2015-2021, 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.

  GekkoFS 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.

  GekkoFS 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 GekkoFS.  If not, see <https://www.gnu.org/licenses/>.

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

#ifndef GEKKOFS_METADATA_BACKEND_HPP
#define GEKKOFS_METADATA_BACKEND_HPP

#include <memory>
#include <spdlog/spdlog.h>
#include <daemon/backend/exceptions.hpp>
#include <tuple>

namespace gkfs::metadata {


class AbstractMetadataBackend {
    public:
    virtual std::string
    get(const std::string& key) const = 0;

    virtual void
    put(const std::string& key, const std::string& val) = 0;

    virtual void
    put_no_exist(const std::string& key, const std::string& val) = 0;

    virtual void
    remove(const std::string& key) = 0;

    virtual bool
    exists(const std::string& key) = 0;

    virtual void
    update(const std::string& old_key, const std::string& new_key,
           const std::string& val) = 0;

    virtual void
    increase_size(const std::string& key, size_t size, bool append) = 0;

    virtual void
    decrease_size(const std::string& key, size_t size) = 0;

    virtual std::vector<std::pair<std::string, bool>>
    get_dirents(const std::string& dir) const = 0;

    virtual std::vector<std::tuple<std::string, bool, size_t, time_t>>
    get_dirents_extended(const std::string& dir) const = 0;

    virtual void
    iterate_all() = 0;

};

template <typename T>
class MetadataBackend  : public AbstractMetadataBackend {
private:
    
    std::string path;
    std::shared_ptr<spdlog::logger> log_;
    std::unique_ptr<T> db;

public:
    
   // explicit MetadataDB(const std::string& path);

    std::string
    get(const std::string& key) const {
        return static_cast<T const&> (*this).get(key);
    }

    void
    put(const std::string& key, const std::string& val) {
        static_cast<T&> (*this).put(key,val);
    }

    void
    put_no_exist(const std::string& key, const std::string& val) {
        static_cast<T&> (*this).put_no_exist(key,val);
    }

    void
    remove(const std::string& key) {
        static_cast<T&> (*this).remove(key);
    }

    bool
    exists(const std::string& key) {
        return static_cast<T&> (*this).exists(key);
    }

    void
    update(const std::string& old_key, const std::string& new_key,
           const std::string& val) {
        static_cast<T&> (*this).update(old_key, new_key, val);
    }

    void
    increase_size(const std::string& key, size_t size, bool append) {
        static_cast<T&> (*this).increase_size(key, size, append);
    }

    void
    decrease_size(const std::string& key, size_t size) {
        static_cast<T&> (*this).decrease_size(key, size);
    }

    std::vector<std::pair<std::string, bool>>
    get_dirents(const std::string& dir) const {
        return static_cast<T const&> (*this).get_dirents(dir);
    }

    std::vector<std::tuple<std::string, bool, size_t, time_t>>
    get_dirents_extended(const std::string& dir) const {
        return static_cast<T const&> (*this).get_dirents_extended(dir);
    }

    void
    iterate_all() {
        static_cast<T&> (*this).iterate_all();
    }

};

} // namespace gkfs::metadata

#endif // GEKKOFS_METADATA_BACKEND_HPP
+96 −0
Original line number Diff line number Diff line
/*
  Copyright 2018-2021, Barcelona Supercomputing Center (BSC), Spain
  Copyright 2015-2021, 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.

  GekkoFS 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.

  GekkoFS 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 GekkoFS.  If not, see <https://www.gnu.org/licenses/>.

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

#ifndef GEKKOFS_METADATA_ROCKSDBBACKEND_HPP
#define GEKKOFS_METADATA_ROCKSDBBACKEND_HPP

#include <memory>
#include <spdlog/spdlog.h>
#include <rocksdb/db.h>
#include <daemon/backend/exceptions.hpp>
#include <tuple>

namespace rdb = rocksdb;

namespace gkfs::metadata {

class RocksDBBackend : public MetadataBackend <RocksDBBackend> { 
private:

  std::unique_ptr<rdb::DB> db;
  rdb::Options options;
  rdb::WriteOptions write_opts;

public:
    explicit RocksDBBackend(const std::string& path);

    static inline void
    throw_status_excpt(const rdb::Status& s);

    void
    optimize_database();

    std::string
    get(const std::string& key) const override;

    void
    put(const std::string& key, const std::string& val) override;

    void
    put_no_exist(const std::string& key, const std::string& val) override;

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

    bool
    exists(const std::string& key) override;

    void
    update(const std::string& old_key, const std::string& new_key,
           const std::string& val) override;

    void
    increase_size(const std::string& key, size_t size, bool append) override;

    void
    decrease_size(const std::string& key, size_t size) override;

    std::vector<std::pair<std::string, bool>>
    get_dirents(const std::string& dir) const override;

    std::vector<std::tuple<std::string, bool, size_t, time_t>>
    get_dirents_extended(const std::string& dir) const override;

    void
    iterate_all() override;

};

} // namespace gkfs::metadata

#endif // GEKKOFS_METADATA_ROCKSDBBACKEND_HPP
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ target_sources(metadata_db
    PUBLIC
    ${INCLUDE_DIR}/daemon/backend/metadata/db.hpp
    ${INCLUDE_DIR}/daemon/backend/exceptions.hpp
    ${INCLUDE_DIR}/daemon/backend/metadata/metadata_backend.hpp
    ${INCLUDE_DIR}/daemon/backend/metadata/kreon_backend.hpp
    ${INCLUDE_DIR}/daemon/backend/metadata/rocksdb_backend.hpp
    PRIVATE