Verified Commit f60f2d19 authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

Implement (f)truncate

Implemented all the logic to handle truncate operation.

Test: added truncate test
parent 63dee343
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -87,3 +87,14 @@ test directories:
  artifacts:
    paths:
     - "${LOG_PATH}"

test truncate:
  stage: test
  script:
    - mkdir -p "${LOG_PATH}"
    - ${BUILD_PATH}/bin/adafs_daemon --mount /tmp/mountdir --root /tmp/adafs_root &
    - sleep 4
    - LD_PRELOAD=${BUILD_PATH}/lib/libadafs_preload_client.so ${TESTS_BUILD_PATH}/ifs_test_truncate
  artifacts:
    paths:
     - "${LOG_PATH}"
+5 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
#define IFS_CHUNK_STORAGE_HPP

#include <abt.h>
#include <limits.h>
#include <string>
#include <memory>

@@ -32,6 +33,10 @@ class ChunkStorage {
        void read_chunk(const std::string& file_path, unsigned int chunk_id,
                         char * buff, size_t size, off64_t offset,
                         ABT_eventual& eventual) const;
        void trim_chunk_space(const std::string& file_path, unsigned int chunk_start,
                unsigned int chunk_end = UINT_MAX);
        void delete_chunk(const std::string& file_path, unsigned int chunk_id);
        void truncate_chunk(const std::string& file_path, unsigned int chunk_id, off_t length);
        void destroy_chunk_space(const std::string& file_path) const;
};

+2 −1
Original line number Diff line number Diff line
@@ -25,7 +25,8 @@ class MetadataDB {
        void remove(const std::string& key);
        bool exists(const std::string& key);
        void update(const std::string& old_key, const std::string& new_key, const std::string& val);
        void update_size(const std::string& key, size_t size, bool append);
        void increase_size(const std::string& key, size_t size, bool append);
        void decrease_size(const std::string& key, size_t size);
        std::vector<std::pair<std::string, bool>> get_dirents(const std::string& dir) const;
        void iterate_all();
};
+13 −1
Original line number Diff line number Diff line
@@ -8,7 +8,8 @@
namespace rdb = rocksdb;

enum class OperandID: char {
    increase_size = 's',
    increase_size = 'i',
    decrease_size = 'd',
    create = 'c'
};

@@ -41,6 +42,17 @@ class IncreaseSizeOperand: public MergeOperand {
        std::string serialize_params() const override;
};

class DecreaseSizeOperand: public MergeOperand {
    public:
        size_t size;

        DecreaseSizeOperand(const size_t size);
        DecreaseSizeOperand(const rdb::Slice& serialized_op);

        const OperandID id() const override;
        std::string serialize_params() const override;
};

class CreateOperand: public MergeOperand {
    public:
        std::string metadata;
+4 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ DECLARE_MARGO_RPC_HANDLER(rpc_srv_access)

DECLARE_MARGO_RPC_HANDLER(rpc_srv_stat)

DECLARE_MARGO_RPC_HANDLER(rpc_srv_decr_size)

DECLARE_MARGO_RPC_HANDLER(rpc_srv_rm_node)

DECLARE_MARGO_RPC_HANDLER(rpc_srv_update_metadentry)
@@ -33,4 +35,6 @@ DECLARE_MARGO_RPC_HANDLER(rpc_srv_read_data)

DECLARE_MARGO_RPC_HANDLER(rpc_srv_write_data)

DECLARE_MARGO_RPC_HANDLER(rpc_srv_trunc_data)

#endif //LFS_RPC_DEFS_HPP
Loading