提交 2fd7815c authored 作者: Thomas Mueller's avatar Thomas Mueller

New connection setting "REUSE_SPACE".

上级 c722ed60
......@@ -17,7 +17,11 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>Issue 587: MVStore: concurrent compaction and store operations could result in an IllegalStateException.
<ul><li>New connection setting "REUSE_SPACE" (default: true). If disabled,
all changes are appended to the database file, and existing content is never overwritten.
This allows to rollback to a previous state of the database by truncating
the database file.
</li><li>Issue 587: MVStore: concurrent compaction and store operations could result in an IllegalStateException.
</li><li>Issue 594: Profiler.copyInThread does not work properly.
</li><li>Script tool: Now, SCRIPT ... TO is always used (for higher speed and lower disk space usage).
</li><li>Script tool: Fix parsing of BLOCKSIZE parameter, original patch by Ken Jorissen.
......
......@@ -282,6 +282,13 @@ public class DbSettings extends SettingsBase {
*/
public final int reconnectCheckDelay = get("RECONNECT_CHECK_DELAY", 200);
/**
* Database setting <code>REUSE_SPACE</code> (default: true).<br />
* If disabled, all changes are appended to the database file, and existing
* content is never overwritten. This setting has no effect if the database is already open.
*/
public final boolean reuseSpace = get("REUSE_SPACE", true);
/**
* Database setting <code>ROWID</code> (default: true).<br />
* If set, each table has a pseudo-column _ROWID_.
......
......@@ -160,6 +160,9 @@ public class MVTableEngine implements TableEngine {
public Store(Database db, MVStore.Builder builder) {
this.store = builder.open();
if (!db.getSettings().reuseSpace) {
store.setReuseSpace(false);
}
this.transactionStore = new TransactionStore(
store,
new ValueDataType(null, db, null));
......
......@@ -9,6 +9,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.nio.channels.FileChannel;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
......@@ -48,6 +49,7 @@ public class TestMVTableEngine extends TestBase {
@Override
public void test() throws Exception {
testAppendOnly();
testLowRetentionTime();
testOldAndNew();
testTemporaryTables();
......@@ -80,6 +82,48 @@ public class TestMVTableEngine extends TestBase {
testSimple();
}
private void testAppendOnly() throws Exception {
deleteDb("testAppendOnly");
Connection conn = getConnection(
"testAppendOnly");
Statement stat = conn.createStatement();
stat.execute("set retention_time 0");
for (int i = 0; i < 10; i++) {
stat.execute("create table dummy" + i +
" as select x, space(100) from system_range(1, 1000)");
stat.execute("checkpoint");
}
stat.execute("create table test as select x from system_range(1, 1000)");
conn.close();
String fileName = getBaseDir() + "/testAppendOnly" + Constants.SUFFIX_MV_FILE;
long fileSize = FileUtils.size(fileName);
conn = getConnection(
"testAppendOnly;reuse_space=false");
stat = conn.createStatement();
stat.execute("set retention_time 0");
for (int i = 0; i < 10; i++) {
stat.execute("drop table dummy" + i);
stat.execute("checkpoint");
}
stat.execute("alter table test alter column x rename to y");
stat.execute("select y from test where 1 = 0");
stat.execute("create table test2 as select x from system_range(1, 1000)");
conn.close();
FileChannel fc = FileUtils.open(fileName, "rw");
// undo all changes
fc.truncate(fileSize);
conn = getConnection(
"testAppendOnly");
stat = conn.createStatement();
stat.execute("select * from dummy0 where 1 = 0");
stat.execute("select * from dummy9 where 1 = 0");
stat.execute("select x from test where 1 = 0");
conn.close();
}
private void testLowRetentionTime() throws SQLException {
deleteDb("testLowRetentionTime");
Connection conn = getConnection(
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论