Unverified 提交 b523811f authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #1231 from grandinj/1227_lob_growth

issue 1227: lob growth in pagestore mode
......@@ -15,7 +15,6 @@ import java.util.LinkedList;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import org.h2.api.ErrorCode;
import org.h2.command.Command;
import org.h2.command.CommandInterface;
......@@ -1313,13 +1312,14 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
* @param v the value
*/
public void removeAtCommit(Value v) {
final String key = v.toString();
if (SysProperties.CHECK && !v.isLinkedToTable()) {
DbException.throwInternalError(v.toString());
DbException.throwInternalError(key);
}
if (removeLobMap == null) {
removeLobMap = new HashMap<>();
}
removeLobMap.put(v.toString(), v);
removeLobMap.put(key, v);
}
/**
......@@ -1704,8 +1704,8 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
if (v.getType() != Value.CLOB && v.getType() != Value.BLOB) {
return;
}
if (v.getTableId() == LobStorageFrontend.TABLE_RESULT ||
v.getTableId() == LobStorageFrontend.TABLE_TEMP) {
if (v.getTableId() == LobStorageFrontend.TABLE_RESULT
|| v.getTableId() == LobStorageFrontend.TABLE_TEMP) {
if (temporaryResultLobs == null) {
temporaryResultLobs = new LinkedList<>();
}
......
......@@ -302,7 +302,7 @@ public class PageDataIndex extends PageIndex {
for (int i = 0, len = row.getColumnCount(); i < len; i++) {
Value v = row.getValue(i);
if (v.isLinkedToTable()) {
session.removeAtCommitStop(v);
session.removeAtCommit(v);
}
}
}
......
......@@ -56,6 +56,7 @@ public class TestLob extends TestDb {
public static void main(String... a) throws Exception {
TestBase test = TestBase.createCaller().init();
test.config.big = true;
test.config.mvStore = false;
test.test();
}
......@@ -112,6 +113,7 @@ public class TestLob extends TestDb {
testLob(false);
testLob(true);
testJavaObject();
testLobGrowth();
deleteDb("lob");
}
......@@ -1685,4 +1687,37 @@ public class TestLob extends TestDb {
}
return new String(buffer);
}
private void testLobGrowth() throws SQLException {
if (config.mvStore) {
return;
}
final File dbFile = new File(getBaseDir(), "lob.h2.db");
final byte[] data = new byte[2560];
deleteDb("lob");
JdbcConnection conn = (JdbcConnection) getConnection("lob;LOB_TIMEOUT=0");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID IDENTITY PRIMARY KEY, DATA BLOB)");
PreparedStatement prep = conn
.prepareStatement("INSERT INTO TEST(DATA) VALUES(?)");
for (int i = 0; i < 100; i++) {
prep.setBinaryStream(1, new ByteArrayInputStream(data));
prep.executeUpdate();
}
final long initialSize = dbFile.length();
prep = conn.prepareStatement("UPDATE test SET data=? WHERE id=?");
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 100; j++) {
data[0] = (byte)(i);
data[1] = (byte)(j);
prep.setBinaryStream(1, new ByteArrayInputStream(data));
prep.setInt(2, j);
prep.executeUpdate();
}
}
assertTrue("dbFile size " + dbFile.length() + " is > initialSize "
+ initialSize, dbFile.length() <= (initialSize * 1.5));
conn.createStatement().execute("drop table test");
conn.close();
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论