Unverified Commit 2a05c52f authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

MetadataDB: use exceptions on update()

parent b16507c4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ size_t get_metadentry_size(const std::string& path);

int update_metadentry_size(const std::string& path, size_t io_size, off_t offset, bool append, size_t& read_size);

int update_metadentry(const std::string& path, Metadata& md);
void update_metadentry(const std::string& path, Metadata& md);

int check_access_mask(const std::string& path, int mask);

+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ class MetadataDB {
        void put(const std::string& key, const std::string& val);
        void remove(const std::string& key);
        bool exists(const std::string& key);
        bool update(const std::string& old_key, const std::string& new_key, const std::string& val);
        void update(const std::string& old_key, const std::string& new_key, const std::string& val);
        bool update_size(const std::string& key, size_t size, off64_t offset, bool append);
        void iterate_all();
};
+2 −2
Original line number Diff line number Diff line
@@ -97,8 +97,8 @@ int update_metadentry_size(const string& path, size_t io_size, off64_t offset, b
    return 0;
}

int update_metadentry(const string& path, Metadata& md) {
    return ADAFS_DATA->mdb()->update(path, md.path(), md.serialize()) ? 0 : -1;
void update_metadentry(const string& path, Metadata& md) {
    ADAFS_DATA->mdb()->update(path, md.path(), md.serialize());
}

/**
+6 −2
Original line number Diff line number Diff line
@@ -78,11 +78,15 @@ bool MetadataDB::exists(const std::string& key) {
 * @param val
 * @return
 */
bool MetadataDB::update(const std::string& old_key, const std::string& new_key, const std::string& val) {
void MetadataDB::update(const std::string& old_key, const std::string& new_key, const std::string& val) {
    //TODO use rdb::Put() method
    rdb::WriteBatch batch;
    batch.Delete(old_key);
    batch.Put(new_key, val);
    return db->Write(write_opts, &batch).ok();
    auto s = db->Write(write_opts, &batch);
    if(!s.ok()){
        MetadataDB::throw_rdb_status_excpt(s);
    }
}

bool MetadataDB::update_size(const std::string& key, size_t size, off64_t offset, bool append){
+2 −2
Original line number Diff line number Diff line
@@ -185,7 +185,6 @@ static hg_return_t rpc_srv_update_metadentry(hg_handle_t handle) {
    // do update
    try {
        Metadata md = get_metadentry(in.path);
        out.err = 0;
        if (in.inode_no_flag == HG_TRUE)
            md.inode_no(in.inode_no);
        if (in.block_flag == HG_TRUE)
@@ -204,7 +203,8 @@ static hg_return_t rpc_srv_update_metadentry(hg_handle_t handle) {
            md.mtime(in.mtime);
        if (in.ctime_flag == HG_TRUE)
            md.ctime(in.ctime);
        out.err = update_metadentry(in.path, md);
        update_metadentry(in.path, md);
        out.err = 0;
    } catch (const std::exception& e){
        //TODO handle NotFoundException
        ADAFS_DATA->spdlogger()->error("{}() Failed to update entry", __func__);