libhdfs的hdfsWrite上传文件最大为4G,怎么办?

满血NPC 2017-05-08 04:41:52
libhdfs的
tSize hdfsWrite(hdfsFS fs, hdfsFile file, const void* buffer, tSize length);
其中
typedef int32_t tSize;
那么该函数一次上传的最大长度为4G,难道用C++向HDFS上传文件,最大上传4G吗?
感谢各位回答,不胜感激

...全文
1342 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
满血NPC 2017-10-24
  • 打赏
  • 举报
回复

    // 2.1 打开本地文件
    QFile readFile(strFileFull);
    if(!readFile.open((QIODevice::ReadOnly)))
    {
        qDebug("Failed to open file: %s!", strFileFull.toStdString().data());
        m_pStdItemModel->item(n, 2)->setText(tr("打开本地文件失败"));
        return false;
    }

    // 3. 向HDFS中写入文件
    QString strWritePath = Global::GetConfig().GetHDFSMissionDataPath() + strFilePath;   // if there has no '/' befor missionData, the path in HDFS will be /usr/<username>/temp/<strFileName>
    // 3.1 上传前记录文件是否已存在
    bool bExist = m_operateHDFS.exists(strWritePath.toStdString().data());
    // 3.2 hdfs open file
    if(!m_operateHDFS.open(strWritePath.toStdString().data(), O_WRONLY|O_CREAT))
    {
        m_pStdItemModel->item(n, 2)->setText(tr("HDFS文件打开失败"));
        return false;
    }
    int nGB = 1024 * 1024 * 1024;
    // 3.3 从本地文件读取nGB字节,写入HDFS,并设置文件偏移量
    qDebug("写前偏移%ld", m_operateHDFS.tell());
    for (int i=0; i<fileInfo.size()/nGB; i++)
    {
        // 3.3.1 从本地文件读取nGB字节,并设置文件偏移量
        readFile.seek(i * nGB);
        QByteArray qByteArry = readFile.read(nGB);
        // 3.3.2 hdfs write
        m_operateHDFS.write(qByteArry.data(), nGB);
        qDebug("写中偏移%ld", m_operateHDFS.tell());
    }
    // 3.3.3 读取本地文件中剩下不足1G的数据,写入HDFS
    int nRemaining = readFile.size() % nGB;
    readFile.seek(fileInfo.size() / nGB * nGB);
    QByteArray qByteArry = readFile.read(nRemaining);
    if (-1 == m_operateHDFS.write(qByteArry.data(), nRemaining))
    {
        m_pStdItemModel->item(n, 2)->setText(tr("HDFS写入失败"));
        return false;
    }
    qDebug("写后偏移%ld", m_operateHDFS.tell());
    // 3.4 hdfs flush
    if (-1 == m_operateHDFS.flush())
    {
        m_pStdItemModel->item(n, 2)->setText(tr("HDFS flush失败"));
        return false;
    }
    // 3.4 hdfs close file
    m_operateHDFS.close();
    // 2.3 close file
    readFile.close();
满血NPC 2017-10-24
  • 打赏
  • 举报
回复
我自己搞定了,其中m_operateHDFS是我自己封装的读写hdfs的类的对象

    // 2.1 打开本地文件
    QFile readFile(strFileFull);
    if(!readFile.open((QIODevice::ReadOnly)))
    {
        qDebug("Failed to open file: %s!", strFileFull.toStdString().data());
        m_pStdItemModel->item(n, 2)->setText(tr("打开本地文件失败"));
        return false;
    }

    // 3. 向HDFS中写入文件
    QString strWritePath = Global::GetConfig().GetHDFSMissionDataPath() + strFilePath;   // if there is not '/' befor missionData, the path in HDFS will be /usr/<username>/temp/<strFileName>
    // 3.1 上传前记录文件是否已存在
    bool bExist = m_operateHDFS.exists(strWritePath.toStdString().data());
    // 3.2 hdfs open file
    if(!m_operateHDFS.open(strWritePath.toStdString().data(), O_WRONLY|O_CREAT))
    {
        m_pStdItemModel->item(n, 2)->setText(tr("HDFS文件打开失败"));
        return false;
    }
    // 2.2 read file
    int nGB = 1024 * 1024 * 1024;
    // 3.3 hdfs write
    qDebug("写前偏移%ld", m_operateHDFS.tell());
    for (int i=0; i<fileInfo.size()/nGB; i++)
    {
        readFile.seek(i * nGB);
        QByteArray qByteArry = readFile.read(nGB);
        m_operateHDFS.write(qByteArry.data(), nGB);
        qDebug("写中偏移%ld", m_operateHDFS.tell());
    }
    readFile.seek(fileInfo.size() / nGB * nGB);
    if (-1 == m_operateHDFS.write(readFile.read(readFile.size() % nGB), readFile.size() % nGB))
    {
        m_pStdItemModel->item(n, 2)->setText(tr("HDFS写入失败"));
        return false;
    }
    qDebug("写后偏移%ld", m_operateHDFS.tell());
    // 3.4 hdfs flush
    if (-1 == m_operateHDFS.flush())
    {
        m_pStdItemModel->item(n, 2)->setText(tr("HDFS flush失败"));
        return false;
    }
    // 3.4 hdfs close file
    m_operateHDFS.close();
    // 2.3 close file
    readFile.close();
满血NPC 2017-06-06
  • 打赏
  • 举报
回复
没人回我啊没人回我
内容概要:本文详细探讨了机组组合优化模型的构建,旨在通过合理安排各类发电机组的启停计划和优化出力分配,实现电力系统在经济性和稳定性上的最佳平衡。文章首先介绍了电力系统的四大主要组件——传统火电机组、风电机组、光伏机组和储能系统的参数及运行特性。接着,围绕最小化系统总运行成本这一目标,设计了优化目标函数,并明确了包括功率平衡约束、机组出力上下限约束、风光发电功率约束、弃风弃光约束、爬坡速率约束、储能系统荷电状态约束、充放电功率约束和充放电互斥约束在内的多项约束条件。最后,文章列出了求解机组组合优化模型所需的关键变量,如传统机组的开停状态、机组出力、启停成本、风电光伏实际出力、弃风弃光比例及储能系统的充放电功率和荷电状态,以实现系统的经济调度和可再生能源的最大化利用。 适合人群:从事电力系统研究、规划和调度工作的工程师和技术人员,以及对电力系统优化感兴趣的科研人员。 使用场景及目标:①帮助电力系统工程师理解不同类型发电机组的特点及其对系统稳定性、经济性和环保性的影响;②为制定合理的电力系统调度策略提供理论依据和技术支持;③促进可再生能源的有效整合,提高电力系统的灵活性和可靠性。 其他说明:本文提供的模型和方法不仅适用于当前的电力系统,也可为未来含高比例可再生能源接入的电力系统提供参考。文中涉及的具体数学公式和参数设定为实际应用提供了详细的指导,有助于提升电力系统的运行效率和经济效益。

932

社区成员

发帖
与我相关
我的任务
社区描述
云计算 云存储相关讨论
社区管理员
  • 云存储
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧