提交 d78e0337 authored 作者: Thomas Mueller's avatar Thomas Mueller

LOB objects are now deleted (and the empty space is reused) when the transaction is committed.

上级 fbcfd32b
...@@ -140,7 +140,7 @@ public class LobStorage { ...@@ -140,7 +140,7 @@ public class LobStorage {
prep.setInt(1, tableId); prep.setInt(1, tableId);
ResultSet rs = prep.executeQuery(); ResultSet rs = prep.executeQuery();
while (rs.next()) { while (rs.next()) {
deleteLob(rs.getLong(1)); removeLob(rs.getLong(1));
} }
reuse(sql, prep); reuse(sql, prep);
} catch (SQLException e) { } catch (SQLException e) {
...@@ -298,8 +298,17 @@ public class LobStorage { ...@@ -298,8 +298,17 @@ public class LobStorage {
prepared.put(sql, prep); prepared.put(sql, prep);
} }
private void deleteLob(long lob) throws SQLException { /**
* Delete a LOB from the database.
*
* @param lob the lob id
*/
public void removeLob(long lob) {
try {
synchronized (handler) { synchronized (handler) {
if (conn == null) {
return;
}
String sql = "SELECT BLOCK, HASH FROM " + LOB_MAP + " D WHERE D.LOB = ? " + String sql = "SELECT BLOCK, HASH FROM " + LOB_MAP + " D WHERE D.LOB = ? " +
"AND NOT EXISTS(SELECT 1 FROM " + LOB_MAP + " O " + "AND NOT EXISTS(SELECT 1 FROM " + LOB_MAP + " O " +
"WHERE O.BLOCK = D.BLOCK AND O.LOB <> ?)"; "WHERE O.BLOCK = D.BLOCK AND O.LOB <> ?)";
...@@ -335,6 +344,9 @@ public class LobStorage { ...@@ -335,6 +344,9 @@ public class LobStorage {
prep.execute(); prep.execute();
reuse(sql, prep); reuse(sql, prep);
} }
} catch (SQLException e) {
throw DbException.convert(e);
}
} }
/** /**
...@@ -416,7 +428,7 @@ public class LobStorage { ...@@ -416,7 +428,7 @@ public class LobStorage {
return registerLob(type, lobId, TABLE_TEMP, length); return registerLob(type, lobId, TABLE_TEMP, length);
} catch (IOException e) { } catch (IOException e) {
if (lobId != -1) { if (lobId != -1) {
deleteLob(lobId); removeLob(lobId);
} }
throw DbException.convertIOException(e, "adding blob"); throw DbException.convertIOException(e, "adding blob");
} }
......
...@@ -120,17 +120,17 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo ...@@ -120,17 +120,17 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo
if (tempFile != null) { if (tempFile != null) {
tempFile.stopAutoDelete(); tempFile.stopAutoDelete();
} }
deleteFile(handler, fileName);
}
}
private static synchronized void deleteFile(DataHandler handler, String fileName) {
// synchronize on the database, to avoid concurrent temp file creation / // synchronize on the database, to avoid concurrent temp file creation /
// deletion / backup // deletion / backup
synchronized (handler.getLobSyncObject()) { synchronized (handler.getLobSyncObject()) {
IOUtils.delete(fileName); IOUtils.delete(fileName);
} }
} }
if (lobStorage != null) {
lobStorage.removeLob(lobId);
lobStorage = null;
}
}
public void unlink() { public void unlink() {
if (small == null && tableId != LobStorage.TABLE_ID_SESSION_VARIABLE) { if (small == null && tableId != LobStorage.TABLE_ID_SESSION_VARIABLE) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论