mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-22 07:39:53 +01:00
Compact the DB at shutdown, and at startup if not closed cleanly.
This commit is contained in:
@@ -85,12 +85,17 @@ class H2Database extends JdbcDatabase {
|
|||||||
public void close() throws DbException {
|
public void close() throws DbException {
|
||||||
// H2 will close the database when the last connection closes
|
// H2 will close the database when the last connection closes
|
||||||
Connection c = null;
|
Connection c = null;
|
||||||
|
Statement s = null;
|
||||||
try {
|
try {
|
||||||
c = createConnection();
|
c = createConnection();
|
||||||
super.closeAllConnections();
|
closeAllConnections();
|
||||||
setDirty(c, false);
|
setDirty(c, false);
|
||||||
|
s = c.createStatement();
|
||||||
|
s.execute("SHUTDOWN COMPACT");
|
||||||
|
s.close();
|
||||||
c.close();
|
c.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
tryToClose(s, LOG, WARNING);
|
||||||
tryToClose(c, LOG, WARNING);
|
tryToClose(c, LOG, WARNING);
|
||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,11 +79,11 @@ class HyperSqlDatabase extends JdbcDatabase {
|
|||||||
Connection c = null;
|
Connection c = null;
|
||||||
Statement s = null;
|
Statement s = null;
|
||||||
try {
|
try {
|
||||||
super.closeAllConnections();
|
closeAllConnections();
|
||||||
c = createConnection();
|
c = createConnection();
|
||||||
setDirty(c, false);
|
setDirty(c, false);
|
||||||
s = c.createStatement();
|
s = c.createStatement();
|
||||||
s.executeQuery("SHUTDOWN");
|
s.executeQuery("SHUTDOWN COMPACT");
|
||||||
s.close();
|
s.close();
|
||||||
c.close();
|
c.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -106,7 +106,7 @@ class HyperSqlDatabase extends JdbcDatabase {
|
|||||||
Connection c = null;
|
Connection c = null;
|
||||||
Statement s = null;
|
Statement s = null;
|
||||||
try {
|
try {
|
||||||
super.closeAllConnections();
|
closeAllConnections();
|
||||||
c = createConnection();
|
c = createConnection();
|
||||||
s = c.createStatement();
|
s = c.createStatement();
|
||||||
s.executeQuery("SHUTDOWN COMPACT");
|
s.executeQuery("SHUTDOWN COMPACT");
|
||||||
|
|||||||
@@ -405,7 +405,9 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
if (reopen) {
|
if (reopen) {
|
||||||
Settings s = getSettings(txn, DB_SETTINGS_NAMESPACE);
|
Settings s = getSettings(txn, DB_SETTINGS_NAMESPACE);
|
||||||
wasDirtyOnInitialisation = isDirty(s);
|
wasDirtyOnInitialisation = isDirty(s);
|
||||||
compact = migrateSchema(txn, s, listener) || isCompactionDue(s);
|
boolean migrated = migrateSchema(txn, s, listener);
|
||||||
|
compact = wasDirtyOnInitialisation || migrated
|
||||||
|
|| isCompactionDue(s);
|
||||||
} else {
|
} else {
|
||||||
wasDirtyOnInitialisation = false;
|
wasDirtyOnInitialisation = false;
|
||||||
createTables(txn);
|
createTables(txn);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
app:layout_constraintVertical_bias="0.5"
|
app:layout_constraintVertical_bias="0.5"
|
||||||
app:layout_constraintVertical_chainStyle="packed"
|
app:layout_constraintVertical_chainStyle="packed"
|
||||||
app:srcCompat="@drawable/startup_lock"
|
app:srcCompat="@drawable/startup_lock"
|
||||||
app:tint="@color/briar_primary"
|
app:tint="@color/briar_accent"
|
||||||
tools:ignore="ContentDescription" />
|
tools:ignore="ContentDescription" />
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
|
|||||||
Reference in New Issue
Block a user