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

SHUTDOWN COMPACT now fully compacts the database.

上级 9a695218
......@@ -517,10 +517,10 @@ public class Parser {
int type = TransactionCommand.SHUTDOWN;
if (readIf("IMMEDIATELY")) {
type = TransactionCommand.SHUTDOWN_IMMEDIATELY;
} else if (readIf("COMPACT")) {
type = TransactionCommand.SHUTDOWN_COMPACT;
} else {
if (!readIf("COMPACT")) {
readIf("SCRIPT");
}
readIf("SCRIPT");
}
return new TransactionCommand(session, type);
}
......
......@@ -85,10 +85,15 @@ public class TransactionCommand extends Prepared {
*/
public static final int SHUTDOWN_IMMEDIATELY = 13;
/**
* The type of a SHUTDOWN COMPACT statement.
*/
public static final int SHUTDOWN_COMPACT = 14;
/**
* The type of a BEGIN {WORK|TRANSACTION} statement.
*/
public static final int BEGIN = 14;
public static final int BEGIN = 15;
private int type;
private String savepointName;
......@@ -149,9 +154,13 @@ public class TransactionCommand extends Prepared {
session.getUser().checkAdmin();
session.getDatabase().shutdownImmediately();
break;
case SHUTDOWN: {
case SHUTDOWN:
case SHUTDOWN_COMPACT: {
session.getUser().checkAdmin();
session.commit(false);
if (type == SHUTDOWN_COMPACT) {
session.getDatabase().setCompactFully(true);
}
// close the database, but don't update the persistent setting
session.getDatabase().setCloseDelay(0);
Database db = session.getDatabase();
......
......@@ -15,7 +15,6 @@ import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
import org.h2.api.DatabaseEventListener;
import org.h2.command.ddl.CreateTableData;
import org.h2.command.dml.SetTypes;
......@@ -55,6 +54,7 @@ import org.h2.table.TableData;
import org.h2.table.TableLinkConnection;
import org.h2.table.TableView;
import org.h2.tools.DeleteDbFiles;
import org.h2.tools.Recover;
import org.h2.tools.Server;
import org.h2.util.BitField;
import org.h2.util.ByteUtils;
......@@ -174,6 +174,8 @@ public class Database implements DataHandler {
private int cacheSize;
private boolean compactFully;
public Database(String name, ConnectionInfo ci, String cipher) throws SQLException {
this.compareMode = CompareMode.getInstance(null, 0);
this.persistent = ci.isPersistent();
......@@ -550,10 +552,17 @@ public class Database implements DataHandler {
private synchronized void open(int traceLevelFile, int traceLevelSystemOut) throws SQLException {
if (persistent) {
String pageFileName = databaseName + Constants.SUFFIX_PAGE_FILE;
boolean existsPage = FileUtils.exists(pageFileName);
String dataFileName = databaseName + Constants.SUFFIX_DATA_FILE;
boolean existsData = FileUtils.exists(dataFileName);
String pageFileName = databaseName + Constants.SUFFIX_PAGE_FILE;
boolean existsPage = FileUtils.exists(pageFileName);
if (usePageStoreSet && usePageStore && existsData && !existsPage) {
String dir = FileUtils.getParent(databaseName);
String db = FileUtils.getFileName(databaseName);
Recover.convert(dir, db);
existsData = FileUtils.exists(dataFileName);
existsPage = FileUtils.exists(pageFileName);
}
if (!usePageStoreSet) {
// if the URL flag is not set
if (existsData && !existsPage) {
......@@ -1278,7 +1287,7 @@ public class Database implements DataHandler {
try {
pageStore.checkpoint();
if (!readOnly) {
pageStore.trim();
pageStore.compact(compactFully);
}
} catch (Throwable e) {
// TODO don't ignore exceptions
......@@ -2480,4 +2489,8 @@ public class Database implements DataHandler {
this.readOnly = readOnly;
}
public void setCompactFully(boolean compactFully) {
this.compactFully = compactFully;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论