java.io.IOException: 无效参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/780543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 13:45:14  来源:igfitidea点击:

java.io.IOException: Invalid argument

javacluster-computingioexception

提问by Luixv

I have a web application running in cluster mode with a load balancer. It consists in two tomcats (T1, and T2) addressing only one DB. T2 is nfs mounted to T1. This is the only dofference between both nodes.

我有一个在集群模式下运行的带有负载均衡器的 Web 应用程序。它由两个只寻址一个 DB 的 tomcat(T1 和 T2)组成。T2 是 nfs 挂载到 T1。这是两个节点之间的唯一差异。

I have a java method generating some files. If the request runs on T1 there is no problem but if the request is running on node 2 I get an exception as follows:

我有一个生成一些文件的 java 方法。如果请求在 T1 上运行,则没有问题,但如果请求在节点 2 上运行,则会出现如下异常:

java.io.IOException: Invalid argument
        at java.io.FileOutputStream.close0(Native Method)
        at java.io.FileOutputStream.close(FileOutputStream.java:279)

The corresponding code is as follows:

对应的代码如下:

for (int i = 0; i < dataFileList.size(); i++) {
    outputFileName = outputFolder + fileNameList.get(i);
    FileOutputStream fileOut = new FileOutputStream(outputFileName);                        
    fileOut.write(dataFileList.get(i), 0, dataFileList.get(i).length);
    fileOut.flush();
    fileOut.close();
}

The exception appears at the fileOut.close()

异常出现在 fileOut.close()

Any hint?

任何提示?

Luis

路易斯

采纳答案by Luixv

Finally I found the reason. First I've notices that NOT always this exception comes at the same point.

最后我找到了原因。首先,我注意到这个异常并不总是出现在同一点。

Sometimes was a java.io.IOException: Invalid argument at java.io.FileOutputStream.close0(Native Method) at java.io.FileOutputStream.close(FileOutputStream.java:279) ^^^^^

有时是 java.io.IOException: Invalid argument at java.io.FileOutputStream.close0(Native Method) at java.io.FileOutputStream.close(FileOutputStream.java:279) ^^^^^

and sometimes was

有时是

java.io.IOException: Invalid argument
    at java.io.FileOutputStream.writeBytes(Native Method)
    at java.io.FileOutputStream.write(FileOutputStream.java:260)

Therefore the problem is NOT a java problem. Not even a NFS problem. The problem isthe underlying File System type which is an DRBD file system.

因此,问题不是 java 问题。甚至不是 NFS 问题。问题在于底层文件系统类型是 DRBD 文件系统。

Testing at a shell to write across the nodes works if one is writing a small file. I.e:

如果正在写入一个小文件,则在 shell 上进行跨节点写入的测试会起作用。IE:

at the nfs mounted node

在 nfs 挂载节点上

cd /tmp
date > /shared/path-to-some-not-mounted-dir/today

will work

but

cat myBigFile > /shared/path-to-some-not-mounted-dir/today

will deliver the following error

将提供以下错误

cat: write error: Invalid argument

Therefore the solution is to use other type of file system, gfs for example.

因此解决方案是使用其他类型的文件系统,例如 gfs。

回答by ed123

Setting this line in the .profileresolved the issue:

.profile解决问题中设置此行:

ulimit –n 2048

回答by ed123

How large do dataFileList and fileNameList get? You could be running out of file descriptors. It's odd that it happens on close(), though.

dataFileList 和 fileNameList 有多大?您可能会用完文件描述符。不过,它发生在 close() 上很奇怪。