davidwang456 / fastdfs

Automatically exported from code.google.com/p/fastdfs
GNU General Public License v3.0
0 stars 0 forks source link

java 客户端并行上传文件,出现错误 #38

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
2012-10-27 10:16:49,725 ERROR 
[com.starit.ueap.collect.worker.spi.impl.DefaultCollectDataPreserveStrategy] - 
<upload file "fileName4Test.xml" fails; nested exception is 
java.io.IOException: recv cmd: 0 is not correct, expect cmd: 100>
com.starit.ueap.collect.common.fastdfs.FileStorageException: upload file 
"fileName4Test.xml" fails; nested exception is java.io.IOException: recv cmd: 0 
is not correct, expect cmd: 100
    at com.starit.ueap.collect.common.fastdfs.FdfsStorageServiceImpl.uploadFile(FdfsStorageServiceImpl.java:72) ~[classes/:na]
    at com.starit.ueap.collect.common.fastdfs.FdfsStorageServiceImpl.uploadFile(FdfsStorageServiceImpl.java:50) ~[classes/:na]
    at com.starit.ueap.collect.worker.spi.impl.DefaultCollectDataPreserveStrategy.saveCollectData(DefaultCollectDataPreserveStrategy.java:36) ~[classes/:na]
    at com.starit.ueap.collect.worker.task.AbstractCollectTask.run(AbstractCollectTask.java:37) [classes/:na]
    at com.starit.ueap.collect.worker.support.CollectTaskManager$1.run(CollectTaskManager.java:50) [classes/:na]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [na:1.7.0]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [na:1.7.0]
    at java.lang.Thread.run(Thread.java:722) [na:1.7.0]
Caused by: java.io.IOException: recv cmd: 0 is not correct, expect cmd: 100
    at org.csource.fastdfs.ProtoCommon.recvHeader(ProtoCommon.java:214) ~[fastdfs-client-1.22.jar:na]
    at org.csource.fastdfs.ProtoCommon.recvPackage(ProtoCommon.java:245) ~[fastdfs-client-1.22.jar:na]
    at org.csource.fastdfs.TrackerClient.getStoreStorage(TrackerClient.java:143) ~[fastdfs-client-1.22.jar:na]
    at org.csource.fastdfs.StorageClient.newWritableStorageConnection(StorageClient.java:1913) ~[fastdfs-client-1.22.jar:na]
    at org.csource.fastdfs.StorageClient.do_upload_file(StorageClient.java:703) ~[fastdfs-client-1.22.jar:na]
    at org.csource.fastdfs.StorageClient.upload_file(StorageClient.java:266) ~[fastdfs-client-1.22.jar:na]
    at com.starit.ueap.collect.common.fastdfs.FdfsStorageServiceImpl.uploadFile(FdfsStorageServiceImpl.java:69) ~[classes/:na]
    ... 7 common frames omitted
2012-10-27 10:16:49,728 ERROR 
[com.starit.ueap.collect.worker.spi.impl.DefaultCollectDataPreserveStrategy] - 
<upload file "fileName4Test.xml" fails; nested exception is 
java.net.SocketException: Socket Closed>
com.starit.ueap.collect.common.fastdfs.FileStorageException: upload file 
"fileName4Test.xml" fails; nested exception is java.net.SocketException: Socket 
Closed
    at com.starit.ueap.collect.common.fastdfs.FdfsStorageServiceImpl.uploadFile(FdfsStorageServiceImpl.java:72) ~[classes/:na]
    at com.starit.ueap.collect.common.fastdfs.FdfsStorageServiceImpl.uploadFile(FdfsStorageServiceImpl.java:50) ~[classes/:na]
    at com.starit.ueap.collect.worker.spi.impl.DefaultCollectDataPreserveStrategy.saveCollectData(DefaultCollectDataPreserveStrategy.java:36) ~[classes/:na]
    at com.starit.ueap.collect.worker.task.AbstractCollectTask.run(AbstractCollectTask.java:37) [classes/:na]
    at com.starit.ueap.collect.worker.support.CollectTaskManager$1.run(CollectTaskManager.java:50) [classes/:na]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [na:1.7.0]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [na:1.7.0]
    at java.lang.Thread.run(Thread.java:722) [na:1.7.0]
Caused by: java.net.SocketException: Socket Closed
    at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.7.0]
    at java.net.SocketInputStream.read(SocketInputStream.java:150) ~[na:1.7.0]
    at java.net.SocketInputStream.read(SocketInputStream.java:121) ~[na:1.7.0]
    at org.csource.fastdfs.ProtoCommon.recvPackage(ProtoCommon.java:258) ~[fastdfs-client-1.22.jar:na]
    at org.csource.fastdfs.TrackerClient.getStoreStorage(TrackerClient.java:143) ~[fastdfs-client-1.22.jar:na]
    at org.csource.fastdfs.StorageClient.newWritableStorageConnection(StorageClient.java:1913) ~[fastdfs-client-1.22.jar:na]
    at org.csource.fastdfs.StorageClient.do_upload_file(StorageClient.java:703) ~[fastdfs-client-1.22.jar:na]
    at org.csource.fastdfs.StorageClient.upload_file(StorageClient.java:266) ~[fastdfs-client-1.22.jar:na]
    at com.starit.ueap.collect.common.fastdfs.FdfsStorageServiceImpl.uploadFile(FdfsStorageServiceImpl.java:69) ~[classes/:na]
    ... 7 common frames omitted

java 操作代码:
private TrackerServer trackerServer;
    private StorageClient1 client;

    @Override
    public void afterPropertiesSet() throws Exception {
        String classPath = FdfsStorageServiceImpl.class.getClassLoader().getResource(".").getPath();
        ClientGlobal.init(classPath + File.separator + dfsConfig);

        TrackerClient tracker = new TrackerClient();  
        trackerServer = tracker.getConnection();  
        StorageServer storageServer = null;  
        client = new StorageClient1(trackerServer, storageServer);  
    }

    @Override
    public void destroy() throws Exception {
        trackerServer.close();  
    }

    @Override
    public String uploadFile(String content, String uploadFileName) {
        byte[] buffer = content.getBytes();
        ByteArrayInputStream inStream = new ByteArrayInputStream(buffer);
        return this.uploadFile(inStream, uploadFileName, buffer.length);
    }

Original issue reported on code.google.com by libinson...@gmail.com on 27 Oct 2012 at 2:22

GoogleCodeExporter commented 8 years ago
FastDFS的TrackerClient和StorageClient对象是有状态的,需要调用方��
�证线程安全。
比如一个线程一个对象实例。

Original comment by happyfis...@gmail.com on 28 Oct 2012 at 12:45

GoogleCodeExporter commented 8 years ago
多线程任务,不可固定为线程创建TrackerClient和StorageClient,如
果是有状态的,需要提供一个连接池,类似数据库连接池缓��
�TrackerClient和StorageClient。避免每次重复创建。

Original comment by libinson...@gmail.com on 29 Oct 2012 at 2:07