修复使用mysql存储日志的情况下文件流未关闭造成的文件文件句柄不释放的bug。

(cherry picked from commit 2a9444770d227ffe46d6c700a7e8570ef3e1bc17)
This commit is contained in:
yuhan 2024-01-03 14:14:32 +08:00
parent 9b3a3cd586
commit 23d94ed46f

View File

@ -141,6 +141,7 @@ public class MySqlSeriesDfsService extends AbstractDFsService {
Map<String, Object> meta = Maps.newHashMap(); Map<String, Object> meta = Maps.newHashMap();
meta.put("_server_", NetUtils.getLocalHost()); meta.put("_server_", NetUtils.getLocalHost());
meta.put("_local_file_path_", storeRequest.getLocalFile().getAbsolutePath()); meta.put("_local_file_path_", storeRequest.getLocalFile().getAbsolutePath());
BufferedInputStream bufferedInputStream = new BufferedInputStream(Files.newInputStream(storeRequest.getLocalFile().toPath()));
Date date = new Date(System.currentTimeMillis()); Date date = new Date(System.currentTimeMillis());
@ -153,7 +154,7 @@ public class MySqlSeriesDfsService extends AbstractDFsService {
pst.setString(4, JsonUtils.toJSONString(meta)); pst.setString(4, JsonUtils.toJSONString(meta));
pst.setLong(5, storeRequest.getLocalFile().length()); pst.setLong(5, storeRequest.getLocalFile().length());
pst.setInt(6, SwitchableStatus.ENABLE.getV()); pst.setInt(6, SwitchableStatus.ENABLE.getV());
pst.setBlob(7, new BufferedInputStream(Files.newInputStream(storeRequest.getLocalFile().toPath()))); pst.setBlob(7, bufferedInputStream);
pst.setString(8, null); pst.setString(8, null);
pst.setDate(9, date); pst.setDate(9, date);
pst.setDate(10, date); pst.setDate(10, date);
@ -165,6 +166,8 @@ public class MySqlSeriesDfsService extends AbstractDFsService {
} catch (Exception e) { } catch (Exception e) {
log.error("[MySqlSeriesDfsService] store [{}] failed!", fileLocation); log.error("[MySqlSeriesDfsService] store [{}] failed!", fileLocation);
ExceptionUtils.rethrow(e); ExceptionUtils.rethrow(e);
}finally {
bufferedInputStream.close();
} }
} }