2016-02-29 61 views
1

我使用的Jnr熔丝库(https://github.com/SerCeMan/jnr-fuse)内部使用JNR提供本地访问使用Java语言编写一个保险丝文件系统。保险丝文件系统中的Java - JVM错误双重释放或腐败

文件系统可以作为一个前端至一个Amazon S3桶,基本上使用户能够安装其桶作为一个正常的存储装置。

虽然返工我的读法,我碰到以下JVM错误传来:

*** Error in `/usr/local/bin/jdk1.8.0_65/bin/java': double free or corruption (!prev): 0x00007f3758953d80 *** 

的错误,而试图从保险丝文件系统中的文件复制到本地FS,通常在第二调用总是发生所读取的方法(用于数据的第二块128K字节)

cp /tmp/fusetest/benchmark/benchmarkFile.large /tmp 

所讨论的读出方法是:

public int read(String path, Pointer buf, @size_t long size, @off_t long offset, FuseFileInfo fi) { 
    LOGGER.debug("Reading file {}, offset = {}, read length = {}", path, offset, size); 
    S3fsNodeInfo nodeInfo; 
    try { 
     nodeInfo = this.dbHelper.getNodeInfo(S3fsPath.fromUnixPath(path)); 
    } catch (FileNotFoundException ex) { 
     LOGGER.error("Read called on non-existing node: {}", path); 
     return -ErrorCodes.ENOENT(); 
    } 
    try { 
     // *** important part start 
     InputStream is = this.s3Helper.getInputStream(nodeInfo.getPath(), offset, size); 
     byte[] data = new byte[is.available()]; 
     int numRead = is.read(data, 0, (int) size); 
     LOGGER.debug("Got {} bytes from stream, putting to buffer", numRead); 
     buf.put(offset, data, 0, numRead); 
     return numRead; 
     // *** important part end 
    } catch (IOException ex) { 
     LOGGER.error("Error while reading file {}", path, ex); 
     return -ErrorCodes.EIO(); 
    } 
} 

使用的输入流是其实上,我使用,以减少与S3 HTTP通信的缓冲器一个ByteArrayInputStream。 我现在单线程模式下运行保险丝,以避免任何并发相关问题。

有趣的是,我已经有一个工作版本,没有做任何内部缓存,但在其他方面是完全一样的,如下所示。

不幸的是,我不是真的到JVM内部,所以我不知道如何去这条底线 - 调试正常收益率没有什么作为实际的错误似乎是在C端发生。

这里的读操作的完整控制台输出通过上面的命令触发:

2016-02-29 02:08:45,652 DEBUG s3fs.fs.CacheEnabledS3fs [main] - Reading file /benchmark/benchmarkFile.large, offset = 0, read length = 131072 
unique: 7, opcode: READ (15), nodeid: 3, insize: 80, pid: 8297 
read[0] 131072 bytes from 0 flags: 0x8000 
2016-02-29 02:08:46,024 DEBUG s3fs.fs.CachedS3Helper [main] - Getting data from cache - path = /benchmark/benchmarkFile.large, offset = 0, length = 131072 
2016-02-29 02:08:46,025 DEBUG s3fs.fs.CachedS3Helper [main] - Path /benchmark/benchmarkFile.large not yet in cache, add it 
2016-02-29 02:08:57,178 DEBUG s3fs.fs.CachedS3Helper [main] - Path /benchmark/benchmarkFile.large found in cache! 
    read[0] 131072 bytes from 0 
    unique: 7, success, outsize: 131088 
2016-02-29 02:08:57,179 DEBUG s3fs.fs.CachedS3Helper [main] - Starting actual cache read for path /benchmark/benchmarkFile.large 
2016-02-29 02:08:57,179 DEBUG s3fs.fs.CachedS3Helper [main] - Reading data from cache block 0, blockOffset = 0, length = 131072 
2016-02-29 02:08:57,179 DEBUG s3fs.fs.CacheEnabledS3fs [main] - Got 131072 bytes from stream, putting to buffer 
2016-02-29 02:08:57,180 DEBUG s3fs.fs.CacheEnabledS3fs [main] - Reading file /benchmark/benchmarkFile.large, offset = 131072, read length = 131072 
unique: 8, opcode: READ (15), nodeid: 3, insize: 80, pid: 8297 
read[0] 131072 bytes from 131072 flags: 0x8000 
2016-02-29 02:08:57,570 DEBUG s3fs.fs.CachedS3Helper [main] - Getting data from cache - path = /benchmark/benchmarkFile.large, offset = 131072, length = 131072 
2016-02-29 02:08:57,570 DEBUG s3fs.fs.CachedS3Helper [main] - Path /benchmark/benchmarkFile.large found in cache! 
2016-02-29 02:08:57,570 DEBUG s3fs.fs.CachedS3Helper [main] - Starting actual cache read for path /benchmark/benchmarkFile.large 
2016-02-29 02:08:57,571 DEBUG s3fs.fs.CachedS3Helper [main] - Reading data from cache block 0, blockOffset = 131072, length = 131072 
2016-02-29 02:08:57,571 DEBUG s3fs.fs.CacheEnabledS3fs [main] - Got 131072 bytes from stream, putting to buffer 
    read[0] 131072 bytes from 131072 
    unique: 8, success, outsize: 131088 
*** Error in `/usr/local/bin/jdk1.8.0_65/bin/java': double free or corruption (!prev): 0x00007fcaa8b30c80 *** 

回答

1

好吧,这是一个愚蠢的错误真的...

buf.put(offset, data, 0, numRead); 

当然是无稽之谈 - 传递偏移量参数意味着正在读取的文件中的偏移量,而不是缓冲区中的偏移量。

作品有:

buf.put(0, data, 0, numRead); 

的,而神秘的错误只是意味着我想写的内存位置我在这种情况下,已经没有生意写入。 好奇的是,为什么它是这个错误消息,而不是我通常期望在这里的段错误。

+2

错误消息表明你正在跺脚的内存是堆结构化为块列表。这是有效映射的内存,因此您不会收到段错误,但堆管理器会检测到您已覆盖链接到上一个块的元数据。 –