miles-ton opened a new issue, #7539:
URL: https://github.com/apache/rocketmq/issues/7539

   ### Before Creating the Bug Report
   
   - [X] I found a bug, not just asking a question, which should be created in 
[GitHub Discussions](https://github.com/apache/rocketmq/discussions).
   
   - [X] I have searched the [GitHub 
Issues](https://github.com/apache/rocketmq/issues) and [GitHub 
Discussions](https://github.com/apache/rocketmq/discussions)  of this 
repository and believe that this is not a duplicate.
   
   - [X] I have confirmed that this bug belongs to the current repository, not 
other repositories of RocketMQ.
   
   
   ### Runtime platform environment
   
   windows11,idea 2023.2.4
   
   ### RocketMQ version
   
   commit id:46962c262c37554ff09afe9e02c7baf66a5ecc73
   
   ### JDK Version
   
   jdk8,java-se-8u43-ri
   
   ### Describe the Bug
   
   when i running broker, and send message to broker,  the message have beed 
sent to broker successfully, but after a while i occasionally found my disk has 
been fill up (the index file occupy my 200G disk). i try to find what happen. 
then i've found follow exception in class : 
IndexService.getAndCreateLastIndexFile 
   when we send message to broker, broker will create index file, the steps for 
index file creation as follows:
   - try to find last index file  throught `indexFileList`
   - if `indexFileList` is empty then create a `IndexFile`
   - `IndexFile` constructor contain a `DefaultMappedFile`
   - `DefaultMappedFile` will create a `RandomAccessFile`  
   - follow statement are the root problem
   `this.fileChannel = new RandomAccessFile(this.file, "rw").getChannel();
    this.mappedByteBuffer = this.fileChannel.map(MapMode.READ_WRITE, 0, 
fileSize);`
   after RandomAccessFile has been created, then will channel map to allocate 
disk space and mmap to memory, 
   but the problem is allocate disk space and mmap is not atomiclly, so if disk 
space has been allocated successfully, but mmap failed, then a exception will 
be throw, this exception will cause a useless 400M IndexFile created in disk 
and can't be used, and there's something worse, every index log exception will 
cause a useless 400M IndexFile.
   
   may be we can delete that created IndexFile after a exception if the 
IndexFile has been allocate disk space
   
   
   ### Steps to Reproduce
   
   create a IndexFile and allocate disk space successfully but mmap failed, 
like OutOfMemory
   
![image](https://github.com/apache/rocketmq/assets/77013030/465d23d5-8a6f-48d3-b201-d94903d8a73c)
   
![image](https://github.com/apache/rocketmq/assets/77013030/bba60148-6971-4c9b-b9bf-cd0f5ed90b8f)
   
![image](https://github.com/apache/rocketmq/assets/77013030/19ae84bf-36d0-4dec-849d-ce041e21d0db)
   
   
   
   ### What Did You Expect to See?
   
   delete the useless IndexFile if the file has been allocate disk space after 
a exception occur
   
   ### What Did You See Instead?
   
   many useless IndexFile occupied my 200G disk space
   
   ### Additional Context
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to