Commit 0e7686a9 authored by Ramon Nou's avatar Ramon Nou
Browse files

migrate inline if exceeds size

parent 33f50f78
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -1081,6 +1081,27 @@ gkfs_do_write(gkfs::filemap::OpenFile& file, const char* buf, size_t count,
        }
    }

    // If we are here, we are writing to chunks.
    // Check if we need to migrate existing inline data to chunks.
    // This is necessary if the file has inline data but we are now writing
    // beyond the inline limit (or appending).
    if(gkfs::config::metadata::use_inline_data && (is_append || offset > 0)) {
        auto md = gkfs::utils::get_metadata(*path);
        if(md && !md->inline_data().empty()) {
            LOG(DEBUG, "{}() Migrating inline data to chunks. Size: {}",
                __func__, md->size());
            // Write inline data to chunks
            auto err_migration = gkfs::rpc::forward_write(
                    *path, md->inline_data().c_str(), 0, md->size(), 0);
            if(err_migration.first) {
                LOG(ERROR, "{}() Failed to migrate inline data to chunks",
                    __func__);
                errno = err_migration.first;
                return -1;
            }
        }
    }

    if(is_append) {
        auto ret_offset =
                gkfs::utils::update_file_size(*path, count, offset, is_append);