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

Lob in database: after the process was killed while adding a lob, inserting a…

Lob in database: after the process was killed while adding a lob, inserting a lob could throw an exception (primary key violation in LOB_MAP).
上级 457a63ea
...@@ -107,7 +107,7 @@ public class LobStorage { ...@@ -107,7 +107,7 @@ public class LobStorage {
} }
private long getNextLobId() throws SQLException { private long getNextLobId() throws SQLException {
PreparedStatement prep = prepare("SELECT MAX(ID) FROM " + LOBS); PreparedStatement prep = prepare("SELECT MAX(LOB) FROM " + LOB_MAP);
ResultSet rs = prep.executeQuery(); ResultSet rs = prep.executeQuery();
rs.next(); rs.next();
return rs.getLong(1) + 1; return rs.getLong(1) + 1;
......
...@@ -50,6 +50,7 @@ public class TestPowerOff extends TestBase { ...@@ -50,6 +50,7 @@ public class TestPowerOff extends TestBase {
url = "memFS:/" + dbName; url = "memFS:/" + dbName;
} }
url += ";FILE_LOCK=NO;TRACE_LEVEL_FILE=0"; url += ";FILE_LOCK=NO;TRACE_LEVEL_FILE=0";
testLobCrash();
testSummaryCrash(); testSummaryCrash();
testCrash(); testCrash();
testShutdown(); testShutdown();
...@@ -58,6 +59,40 @@ public class TestPowerOff extends TestBase { ...@@ -58,6 +59,40 @@ public class TestPowerOff extends TestBase {
deleteDb(dir, dbName); deleteDb(dir, dbName);
} }
private void testLobCrash() throws SQLException {
if (config.networked) {
return;
}
deleteDb(dir, dbName);
Connection conn = getConnection(url);
Statement stat = conn.createStatement();
stat.execute("create table test(id identity, data clob)");
conn.close();
conn = getConnection(url);
stat = conn.createStatement();
stat.execute("set write_delay 0");
((JdbcConnection) conn).setPowerOffCount(Integer.MAX_VALUE);
stat.execute("insert into test values(null, space(11000))");
int max = Integer.MAX_VALUE - ((JdbcConnection) conn).getPowerOffCount();
for (int i = 0; i < max + 10; i++) {
conn = getConnection(url);
stat = conn.createStatement();
stat.execute("insert into test values(null, space(11000))");
stat.execute("set write_delay 0");
((JdbcConnection) conn).setPowerOffCount(i);
try {
stat.execute("insert into test values(null, space(11000))");
} catch (SQLException e) {
// ignore
}
try {
conn.close();
} catch (SQLException e) {
// ignore
}
}
}
private void testSummaryCrash() throws SQLException { private void testSummaryCrash() throws SQLException {
if (config.networked) { if (config.networked) {
return; return;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论