Verified Commit 26e015da authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

Each file has its own unique ID

The OpenFile and Metadata class have now a fuid field that is a unique file identifier. The fuid is generated by a metadata daemon when the new node is created.
parent f353afe8
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -2,12 +2,14 @@
#ifndef LFS_FS_DATA_H
#define LFS_FS_DATA_H

#include "daemon/classes/uids_manager.hpp"
#include <daemon/adafs_daemon.hpp>

/* Forward declarations */
class MetadataDB;
class ChunkStorage;
class Distributor;
class UidsManager;

#include <unordered_map>
#include <map>
@@ -46,6 +48,8 @@ private:
    std::shared_ptr<ChunkStorage> storage_;
    // Distributor
    std::shared_ptr<Distributor> distributor_;
    // FUIDs manager
    std::shared_ptr<UidsManager> fuids_manager_;

    // configurable metadata
    bool atime_state_;
@@ -114,6 +118,10 @@ public:

    std::shared_ptr<Distributor> distributor() const;

    void fuids_manager(std::shared_ptr<UidsManager> fuids_manager);

    std::shared_ptr<UidsManager> fuids_manager() const;

    const std::string& hosts_raw() const;

    void hosts_raw(const std::string& hosts_raw);
+25 −0
Original line number Diff line number Diff line
#ifndef FS_UIDS_MANAGER_HPP
#define FS_UIDS_MANAGER_HPP
#pragma once

#include <cstdint> // uint64_t def
#include <atomic>


typedef uint64_t UID;

class UidsManager {
    private:
       const UID slots_num_; // number of total slots
       const UID my_slot_;   // slot number assigned to this manager
       const UID uids_max_;   // number of uids available for this manager
       const UID uids_offset_; // mask that have the first slot_num_bits_ to 0 and the rest 1
       std::atomic<UID> uids_count_; // number of UIDs generated till now

    public:
       UidsManager(const UID slots_num, const UID my_slot);
       UID generate_uid();
};


#endif //FS_UIDS_MANAGER_HPP
+3 −1
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
#define IFS_GLOBAL_DEFS_HPP

#include <type_traits> // underlying_type
#include <cstdint> // fuid_t

// These constexpr set the RPC's identity and which handler the receiver end should use
namespace hg_tag {
@@ -24,6 +25,7 @@ namespace hg_tag {

// typedefs
typedef unsigned long rpc_chnk_id_t;
typedef uint_fast64_t fuid_t;

template<typename E>
constexpr typename std::underlying_type<E>::type to_underlying(E e) {
+6 −0
Original line number Diff line number Diff line
@@ -8,8 +8,12 @@
#include <string>


typedef uint64_t fuid_t; // File Unique ID


class Metadata {
private:
    fuid_t fuid_;
    time_t atime_;         // access time. gets updated on file access unless mounted with noatime
    time_t mtime_;         // modify time. gets updated when file content is modified.
    time_t ctime_;         // change time. gets updated when the file attributes are changed AND when file content is modified.
@@ -32,6 +36,8 @@ public:
    void update_ACM_time(bool a, bool c, bool m);

    //Getter and Setter
    fuid_t fuid() const;
    void fuid(fuid_t fuid);
    time_t atime() const;
    void atime(time_t atime_);
    time_t mtime() const;
+6 −0
Original line number Diff line number Diff line
@@ -15,6 +15,12 @@ MERCURY_GEN_PROC(rpc_minimal_out_t, ((int32_t) (output)))
// misc generic rpc types
MERCURY_GEN_PROC(rpc_err_out_t, ((hg_int32_t) (err)))


MERCURY_GEN_PROC(rpc_fuid_out_t,
        ((uint64_t) (fuid)) \
        ((int32_t) (err))  \
)

// Metadentry
MERCURY_GEN_PROC(rpc_mk_node_in_t,
                 ((hg_const_string_t) (path))\
Loading