zhouxinyu commented on pull request #3848:
URL: https://github.com/apache/rocketmq/pull/3848#issuecomment-1040031406
> @zhouxinyu It may have difficulty doing the lazy mapping safely while the
mapped file is being used concurrently, which may need to introduce a lock.
>
> The current code is clear, avoiding the anxiety of concurrent error, and
is used for a long time in the production env.
>
> BTW, if you have a simple way to implement the lazy mapping, it is ok to
show it in detail.
Yeap, a lock is necessary for this lazy mapping solution, implementing it is
not too complex, we convert direct access `this.mappedByteBuffer` to a getter
method `this.getBuffer`:
```
public MappedByteBuffer getBuffer() {
if (this.mappedByteBuffer != null) {
return this.mappedByteBuffer;
}
synchronized (this) {
if (this.mappedByteBuffer == null) {
this.mappedByteBuffer = this.fileChannel.map();
}
}
return this.mappedByteBuffer;
}
```
--
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]