happyfish100 / fastdfs

FastDFS is an open source high performance distributed file system (DFS). It's major functions include: file storing, file syncing and file accessing, and design for high capacity and load balance. Wechat/Weixin public account (Chinese Language): fastdfs
GNU General Public License v3.0
8.99k stars 1.98k forks source link

Tracker 服务能自己实现 集群中同组未来得及同步时,获取文件数据为空(替代fastdfs-nginx-module 功能) #577

Closed dreamwk closed 2 years ago

dreamwk commented 2 years ago

作者你好,我遇到不通过nginx 获取数据,通过API获取数据时,可能会空! 请教【Tracker 服务 是否可以实现 fastdfs-nginx-module 功能】??

happyfish100 commented 2 years ago

服务器需要对时,时间误差不能超过1秒。

dreamwk commented 2 years ago

@happyfish100 你好,非常感谢你的方案,我将集群服务器的时间做了同步处理,但下载数据还可能是null,不知还有没有是其他原因?【下面是我程序中接口使用和日志】

public static byte[] downFileToByte(String filePath) throws IOException, MyException { StorageClient1 storageClient = getTrackerClient(); // 由于 集群中存在 获取数据为空,这里做补偿操作 for (int i = 0; i < 50; i++) { if (i > 0) { try { Thread.sleep(1000L); } catch (InterruptedException e) { e.printStackTrace(); } log.error("文件服务器 不稳定,访问API次数是 {}", i + 1); } byte[] bytes = storageClient.download_file1(filePath); if (bytes != null) { return bytes; } } return null; }

日志内容: 2022-08-18 13:35:59 ERROR com.workflow.utils.FastDFSClient:95 - 文件服务器 不稳定,访问API次数是 2 2022-08-18 13:36:00 ERROR com.workflow.utils.FastDFSClient:95 - 文件服务器 不稳定,访问API次数是 3 2022-08-18 13:36:01 ERROR com.workflow.utils.FastDFSClient:95 - 文件服务器 不稳定,访问API次数是 4 2022-08-18 13:36:02 ERROR com.workflow.utils.FastDFSClient:95 - 文件服务器 不稳定,访问API次数是 5 2022-08-18 13:36:03 ERROR com.workflow.utils.FastDFSClient:95 - 文件服务器 不稳定,访问API次数是 6

happyfish100 commented 2 years ago

应该是storageClient 实例化的问题。 请使用构造函数 public StorageClient() 或 public StorageClient(TrackerServer trackerServer)

dreamwk commented 2 years ago
private static StorageClient1 getTrackerClient() throws IOException, MyException {
    TrackerClient trackerClient = new TrackerClient();
    TrackerServer trackerServer = trackerClient.getTrackerServer();
    String hostAddress = trackerClient.getStoreStorage(trackerServer).getInetSocketAddress().getAddress().getHostAddress();
    // 配置应用对应的存储路径,对应storage.conf 中store_path0中0的位置的数字  不同的应用path[n]设置n的数字
    StorageServer storageServer = new StorageServer(hostAddress, port, storePath);
    return new StorageClient1(trackerServer, storageServer);
}

这是我获取 StorageClient1 的实现,主要是想实现指定 特定的存储目录

happyfish100 commented 2 years ago

症结在此,因为你指定 storage server了 :(

dreamwk commented 2 years ago

若不指定 StorageServer storageServer = new StorageServer(hostAddress, port, storePath); ,storePath 是我指定存储目录的索引值,我怎么设置 存储目录??

dreamwk commented 2 years ago

@happyfish100 可以加下您微信么么??方便沟通 🙂

happyfish100 commented 2 years ago

上传时可以指定StorageServer,下载时不要指定StorageServer。

dreamwk commented 2 years ago
private static StorageClient1 getDownStorageClient() throws IOException {
        TrackerClient trackerClient = new TrackerClient();
        TrackerServer trackerServer = trackerClient.getTrackerServer();
        return new StorageClient1(trackerServer);
    }

谢谢!!我上传的StorageClient1 是一个实例,下载的StorageClient1 是一个实例;解决了 下载 使用错误的接口!!希望有遇到此问题的 同学 可以有参考。。再次感谢@happyfish100 帮助