From 445ddc42298c4e62879becaea333133c6b0b3efc Mon Sep 17 00:00:00 2001 From: yuyang733 Date: Thu, 1 Sep 2022 20:09:13 +0800 Subject: [PATCH] fix: Try to create the temporary directory if it does not exits Try to create the temporary directory if it does not exits when running. --- .../fs/cosn/buffer/CosNMappedBufferFactory.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/hadoop/fs/cosn/buffer/CosNMappedBufferFactory.java b/src/main/java/org/apache/hadoop/fs/cosn/buffer/CosNMappedBufferFactory.java index 5ced9889..5a1017fc 100644 --- a/src/main/java/org/apache/hadoop/fs/cosn/buffer/CosNMappedBufferFactory.java +++ b/src/main/java/org/apache/hadoop/fs/cosn/buffer/CosNMappedBufferFactory.java @@ -60,7 +60,14 @@ public CosNByteBuffer create(int size) { } if (!this.tmpDir.exists()) { - LOG.error("The tmp dir does not exist."); + LOG.warn("The tmp dir does not exist."); + // try to create the tmp directory. + try { + CosNMappedBufferFactory.createDir(this.tmpDir.getAbsolutePath()); + } catch (IOException e) { + LOG.error("Try to create the tmp dir [{}] failed.", this.tmpDir.getAbsolutePath(), e); + return null; + } } try { @@ -79,7 +86,7 @@ public CosNByteBuffer create(int size) { randomAccessFile.setLength(size); MappedByteBuffer buf = randomAccessFile.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, size); - return new CosNMappedBuffer(buf, randomAccessFile, tmpFile); + return (null != buf) ? new CosNMappedBuffer(buf, randomAccessFile, tmpFile) : null; } catch (IOException e) { LOG.error("Create tmp file failed. Tmp dir: {}", this.tmpDir, e); return null;