登录
注册
开源
企业版
高校版
搜索
帮助中心
使用条款
关于我们
开源
企业版
高校版
私有云
模力方舟
AI 队友
登录
注册
11月29日 Gitee Talk | 模力方舟 AI 沙龙深圳站:看懂算力到应用的下一个主战场!点击立即报名~
代码拉取完成,页面将自动刷新
开源项目
>
服务器应用
>
分布式存储系统
&&
捐赠
捐赠前请先登录
取消
前往登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
Watch
不关注
关注所有动态
仅关注版本发行动态
关注但不提醒动态
9
Star
48
Fork
30
happyfish100
/
fastdfs-client-java
代码
Issues
7
Pull Requests
0
Wiki
统计
流水线
服务
JavaDoc
质量分析
Jenkins for Gitee
腾讯云托管
腾讯云 Serverless
悬镜安全
阿里云 SAE
Codeblitz
SBOM
我知道了,不再自动展开
更新失败,请稍后重试!
移除标识
内容风险标识
本任务被
标识为内容中包含有代码安全 Bug 、隐私泄露等敏感信息,仓库外成员不可访问
[疑问]StorageClient中,GetFileInfo方法,为什么文件类型为slave file或者appender file时返回的时候文件类型被配置为ileInfo.FILE_TYPE_NORMAL
待办的
#ID5AJ6
tanxiaoxiao
创建于
2025-11-06 11:54
``` /** * get file info decoded from the filename, fetch from the storage if necessary * * @param group_name the group name * @param remote_filename the filename * @return FileInfo object for success, return null for fail */ public FileInfo get_file_info(String group_name, String remote_filename) throws IOException, MyException { if (remote_filename.length() < ProtoCommon.FDFS_FILE_PATH_LEN + ProtoCommon.FDFS_FILENAME_BASE64_LENGTH + ProtoCommon.FDFS_FILE_EXT_NAME_MAX_LEN + 1) { this.errno = ProtoCommon.ERR_NO_EINVAL; return null; } byte[] buff = base64.decodeAuto(remote_filename.substring(ProtoCommon.FDFS_FILE_PATH_LEN, ProtoCommon.FDFS_FILE_PATH_LEN + ProtoCommon.FDFS_FILENAME_BASE64_LENGTH)); short file_type; long file_size = ProtoCommon.buff2long(buff, 4 * 2); if (((file_size & ProtoCommon.APPENDER_FILE_SIZE) != 0)) { file_type = FileInfo.FILE_TYPE_APPENDER; } else if ((remote_filename.length() > ProtoCommon.TRUNK_LOGIC_FILENAME_LENGTH) || ((remote_filename.length() > ProtoCommon.NORMAL_LOGIC_FILENAME_LENGTH) && ((file_size & ProtoCommon.TRUNK_FILE_MARK_SIZE) == 0))) { file_type = FileInfo.FILE_TYPE_SLAVE; } else { file_type = FileInfo.FILE_TYPE_NORMAL; } if (file_type == FileInfo.FILE_TYPE_SLAVE || file_type == FileInfo.FILE_TYPE_APPENDER) { //slave file or appender file FileInfo fi = this.query_file_info(group_name, remote_filename); if (fi == null) { return null; } fi.setFileType(file_type); return fi; } int create_timestamp = ProtoCommon.buff2int(buff, 4); if ((file_size >> 63) != 0) { file_size &= 0xFFFFFFFFL; //low 32 bits is file size } int crc32 = ProtoCommon.buff2int(buff, 4 * 4); return new FileInfo(false, file_type, file_size, create_timestamp, crc32, ProtoCommon.getIpAddress(buff, 0)); } /** * get file info from storage server * * @param group_name the group name of storage server * @param remote_filename filename on storage server * @return FileInfo object for success, return null for fail */ public FileInfo query_file_info(String group_name, String remote_filename) throws IOException, MyException { boolean bNewStorageServer = this.newUpdatableStorageConnection(group_name, remote_filename); Connection connection = this.storageServer.getConnection(); try { byte[] header; byte[] groupBytes; byte[] filenameBytes; byte[] bs; int groupLen; ProtoCommon.RecvPackageInfo pkgInfo; filenameBytes = remote_filename.getBytes(ClientGlobal.g_charset); groupBytes = new byte[ProtoCommon.FDFS_GROUP_NAME_MAX_LEN]; bs = group_name.getBytes(ClientGlobal.g_charset); Arrays.fill(groupBytes, (byte) 0); if (bs.length <= groupBytes.length) { groupLen = bs.length; } else { groupLen = groupBytes.length; } System.arraycopy(bs, 0, groupBytes, 0, groupLen); header = ProtoCommon.packHeader(ProtoCommon.STORAGE_PROTO_CMD_QUERY_FILE_INFO, +groupBytes.length + filenameBytes.length, (byte) 0); OutputStream out = connection.getOutputStream(); byte[] wholePkg = new byte[header.length + groupBytes.length + filenameBytes.length]; System.arraycopy(header, 0, wholePkg, 0, header.length); System.arraycopy(groupBytes, 0, wholePkg, header.length, groupBytes.length); System.arraycopy(filenameBytes, 0, wholePkg, header.length + groupBytes.length, filenameBytes.length); out.write(wholePkg); pkgInfo = ProtoCommon.recvPackage(connection.getInputStream(), ProtoCommon.STORAGE_PROTO_CMD_RESP, -1); this.errno = pkgInfo.errno; if (pkgInfo.errno != 0) { return null; } int front_len = 3 * ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE; int ip_size; if (pkgInfo.body.length == front_len + ProtoCommon.FDFS_IPV6_SIZE) { //IPv6 ip_size = ProtoCommon.FDFS_IPV6_SIZE; } else if (pkgInfo.body.length == front_len + ProtoCommon.FDFS_IPV4_SIZE) { //IPv4 ip_size = ProtoCommon.FDFS_IPV4_SIZE; } else { this.errno = ProtoCommon.ERR_NO_EINVAL; throw new IOException("Invalid body length: " + pkgInfo.body.length); } long file_size = ProtoCommon.buff2long(pkgInfo.body, 0); int create_timestamp = (int) ProtoCommon.buff2long(pkgInfo.body, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE); int crc32 = (int) ProtoCommon.buff2long(pkgInfo.body, 2 * ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE); String source_ip_addr = (new String(pkgInfo.body, front_len, ip_size)).trim(); return new FileInfo(true, FileInfo.FILE_TYPE_NORMAL, file_size, create_timestamp, crc32, source_ip_addr); } catch (IOException ex) { try { connection.close(); } catch (IOException ex1) { ex1.printStackTrace(); } finally { connection = null; } throw ex; } finally { releaseConnection(connection, bNewStorageServer); } } ``` 在这两个方法中,为什么在GetFileInfo时,如果文件类型为slave file或者appender file时需要调用QueryFileInfo,但是返回的时候文件类型被配置为ileInfo.FILE_TYPE_NORMAL
``` /** * get file info decoded from the filename, fetch from the storage if necessary * * @param group_name the group name * @param remote_filename the filename * @return FileInfo object for success, return null for fail */ public FileInfo get_file_info(String group_name, String remote_filename) throws IOException, MyException { if (remote_filename.length() < ProtoCommon.FDFS_FILE_PATH_LEN + ProtoCommon.FDFS_FILENAME_BASE64_LENGTH + ProtoCommon.FDFS_FILE_EXT_NAME_MAX_LEN + 1) { this.errno = ProtoCommon.ERR_NO_EINVAL; return null; } byte[] buff = base64.decodeAuto(remote_filename.substring(ProtoCommon.FDFS_FILE_PATH_LEN, ProtoCommon.FDFS_FILE_PATH_LEN + ProtoCommon.FDFS_FILENAME_BASE64_LENGTH)); short file_type; long file_size = ProtoCommon.buff2long(buff, 4 * 2); if (((file_size & ProtoCommon.APPENDER_FILE_SIZE) != 0)) { file_type = FileInfo.FILE_TYPE_APPENDER; } else if ((remote_filename.length() > ProtoCommon.TRUNK_LOGIC_FILENAME_LENGTH) || ((remote_filename.length() > ProtoCommon.NORMAL_LOGIC_FILENAME_LENGTH) && ((file_size & ProtoCommon.TRUNK_FILE_MARK_SIZE) == 0))) { file_type = FileInfo.FILE_TYPE_SLAVE; } else { file_type = FileInfo.FILE_TYPE_NORMAL; } if (file_type == FileInfo.FILE_TYPE_SLAVE || file_type == FileInfo.FILE_TYPE_APPENDER) { //slave file or appender file FileInfo fi = this.query_file_info(group_name, remote_filename); if (fi == null) { return null; } fi.setFileType(file_type); return fi; } int create_timestamp = ProtoCommon.buff2int(buff, 4); if ((file_size >> 63) != 0) { file_size &= 0xFFFFFFFFL; //low 32 bits is file size } int crc32 = ProtoCommon.buff2int(buff, 4 * 4); return new FileInfo(false, file_type, file_size, create_timestamp, crc32, ProtoCommon.getIpAddress(buff, 0)); } /** * get file info from storage server * * @param group_name the group name of storage server * @param remote_filename filename on storage server * @return FileInfo object for success, return null for fail */ public FileInfo query_file_info(String group_name, String remote_filename) throws IOException, MyException { boolean bNewStorageServer = this.newUpdatableStorageConnection(group_name, remote_filename); Connection connection = this.storageServer.getConnection(); try { byte[] header; byte[] groupBytes; byte[] filenameBytes; byte[] bs; int groupLen; ProtoCommon.RecvPackageInfo pkgInfo; filenameBytes = remote_filename.getBytes(ClientGlobal.g_charset); groupBytes = new byte[ProtoCommon.FDFS_GROUP_NAME_MAX_LEN]; bs = group_name.getBytes(ClientGlobal.g_charset); Arrays.fill(groupBytes, (byte) 0); if (bs.length <= groupBytes.length) { groupLen = bs.length; } else { groupLen = groupBytes.length; } System.arraycopy(bs, 0, groupBytes, 0, groupLen); header = ProtoCommon.packHeader(ProtoCommon.STORAGE_PROTO_CMD_QUERY_FILE_INFO, +groupBytes.length + filenameBytes.length, (byte) 0); OutputStream out = connection.getOutputStream(); byte[] wholePkg = new byte[header.length + groupBytes.length + filenameBytes.length]; System.arraycopy(header, 0, wholePkg, 0, header.length); System.arraycopy(groupBytes, 0, wholePkg, header.length, groupBytes.length); System.arraycopy(filenameBytes, 0, wholePkg, header.length + groupBytes.length, filenameBytes.length); out.write(wholePkg); pkgInfo = ProtoCommon.recvPackage(connection.getInputStream(), ProtoCommon.STORAGE_PROTO_CMD_RESP, -1); this.errno = pkgInfo.errno; if (pkgInfo.errno != 0) { return null; } int front_len = 3 * ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE; int ip_size; if (pkgInfo.body.length == front_len + ProtoCommon.FDFS_IPV6_SIZE) { //IPv6 ip_size = ProtoCommon.FDFS_IPV6_SIZE; } else if (pkgInfo.body.length == front_len + ProtoCommon.FDFS_IPV4_SIZE) { //IPv4 ip_size = ProtoCommon.FDFS_IPV4_SIZE; } else { this.errno = ProtoCommon.ERR_NO_EINVAL; throw new IOException("Invalid body length: " + pkgInfo.body.length); } long file_size = ProtoCommon.buff2long(pkgInfo.body, 0); int create_timestamp = (int) ProtoCommon.buff2long(pkgInfo.body, ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE); int crc32 = (int) ProtoCommon.buff2long(pkgInfo.body, 2 * ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE); String source_ip_addr = (new String(pkgInfo.body, front_len, ip_size)).trim(); return new FileInfo(true, FileInfo.FILE_TYPE_NORMAL, file_size, create_timestamp, crc32, source_ip_addr); } catch (IOException ex) { try { connection.close(); } catch (IOException ex1) { ex1.printStackTrace(); } finally { connection = null; } throw ex; } finally { releaseConnection(connection, bNewStorageServer); } } ``` 在这两个方法中,为什么在GetFileInfo时,如果文件类型为slave file或者appender file时需要调用QueryFileInfo,但是返回的时候文件类型被配置为ileInfo.FILE_TYPE_NORMAL
评论 (
1
)
登录
后才可以发表评论
状态
待办的
待办的
进行中
已完成
已关闭
负责人
未设置
标签
未设置
标签管理
里程碑
未关联里程碑
未关联里程碑
Pull Requests
未关联
未关联
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
未关联
分支 (2)
标签 (11)
master
feature_add_connect_pool_20191205
V1.37
V1.36
V1.35
V1.34
V1.33
V1.32
V1.31
V1.30
V1.28
V1.27
V1.26
开始日期   -   截止日期
-
置顶选项
不置顶
置顶等级:高
置顶等级:中
置顶等级:低
优先级
不指定
严重
主要
次要
不重要
参与者(1)
Java
1
https://gitee.com/fastdfs100/fastdfs-client-java.git
[email protected]
:fastdfs100/fastdfs-client-java.git
fastdfs100
fastdfs-client-java
fastdfs-client-java
点此查找更多帮助
搜索帮助
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册