Make sure generateMemoryMappingFilePath always return the full file path
Summary: As of now, the first call to generateMemoryMappingFilePath() will get the full file path, but subsequent ones will only get the file name.
@@ -50,19 +50,25 @@ public class Buffer {
if (!isFileBacked()) {
return null;
}
- String memoryMappingFilename = getMemoryMappingFilename();
- if (memoryMappingFilename != null) {
- return memoryMappingFilename;
+ String filePath = getCurrentMemoryMappingFilePath();
+ if (filePath == null) {
+ MmapBufferFileHelper helper = new MmapBufferFileHelper(getBufferContainingFolder());
+ String fileName = MmapBufferFileHelper.getMemoryMappingFilename(UUID.randomUUID().toString());
+ updateMemoryMappingFilename(fileName);
+ filePath = helper.ensureFilePath(fileName);
}
- String fileName = MmapBufferFileHelper.getMemoryMappingFilename(UUID.randomUUID().toString());
- MmapBufferFileHelper helper = new MmapBufferFileHelper(getBufferContainingFolder());
- String filePath = helper.ensureFilePath(fileName);
- if (filePath == null) {
- return null;
+ return filePath;
}
- updateMemoryMappingFilename(fileName);
+ @Nullable
+ public synchronized String getCurrentMemoryMappingFilePath() {
+ MmapBufferFileHelper helper = new MmapBufferFileHelper(getBufferContainingFolder());
+ String memoryMappingFilename = getMemoryMappingFilename();
+ String filePath = null;
+ if (memoryMappingFilename != null) {
+ filePath = helper.ensureFilePath(memoryMappingFilename);
+ }
return filePath;
}
